📄 midletsuiteproject.java
字号:
String filename = null;
String jarUrl = getApplicationDescriptor().getMidletJarURL();
if (jarUrl != null) {
// If this is really a URL, we want to just get the name
// from the end of the URL.
int lastSlashIndex = jarUrl.lastIndexOf('/');
if (lastSlashIndex != -1) {
filename = jarUrl.substring(lastSlashIndex + 1);
} else {
filename = jarUrl;
}
}
if (filename == null) {
filename = getProjectNameWithoutSpaces() + ".jar";
}
return filename;
}
/**
* @see eclipseme.core.model.IMidletSuiteProject#getJavaProject()
*/
public IJavaProject getJavaProject() {
return javaProject;
}
/**
* Return the metadata for this midlet suite.<br/>
* NOTE: This method is not considered part of the API and
* is only available to aid the implementation.
*
* @return the metadata.
*/
public MetaData getMetaData() {
return metaData;
}
/**
* @see eclipseme.core.model.IMidletSuiteProject#getProject()
*/
public IProject getProject() {
return javaProject.getProject();
}
/**
* @see eclipseme.core.model.IMidletSuiteProject#getVerifiedClassesOutputFolder(org.eclipse.core.runtime.IProgressMonitor)
*/
public IFolder getVerifiedClassesOutputFolder(IProgressMonitor monitor)
throws CoreException
{
return getVerifiedOutputFolder(monitor).getFolder(CLASSES_DIRECTORY);
}
/**
* @see eclipseme.core.model.IMidletSuiteProject#getVerifiedLibrariesOutputFolder(org.eclipse.core.runtime.IProgressMonitor)
*/
public IFolder getVerifiedLibrariesOutputFolder(IProgressMonitor monitor)
throws CoreException
{
return getVerifiedOutputFolder(monitor).getFolder(LIBS_DIRECTORY);
}
/**
* @see eclipseme.core.model.IMidletSuiteProject#getVerifiedOutputFolder(org.eclipse.core.runtime.IProgressMonitor)
*/
public IFolder getVerifiedOutputFolder(IProgressMonitor monitor)
throws CoreException
{
IFolder tempFolder = getProject().getFolder(IEclipseMECoreConstants.TEMP_FOLDER_NAME);
return tempFolder.getFolder(IEclipseMECoreConstants.VERIFIED_FOLDER_NAME);
}
/**
* @see eclipseme.core.model.IMidletSuiteProject#isDeployedJarUpToDate()
*/
public boolean isDeployedJarUpToDate() throws CoreException {
String upToDateString = getProject().getPersistentProperty(DEPLOYMENT_UP_TO_DATE_PROP);
return (upToDateString == null) ? false : upToDateString.equals("true");
}
/**
* Return a boolean indicating whether the underlying project is a preprocessed project.
*
* @return
* @throws CoreException
*/
public boolean isPreprocessedProject()
throws CoreException
{
IProject project = getProject();
return
project.exists() &&
project.isOpen() &&
project.hasNature(IEclipseMECoreConstants.J2ME_PREPROCESSED_NATURE_ID);
}
/**
* @see eclipseme.core.model.IMidletSuiteProject#preverify(org.eclipse.core.resources.IResource[], org.eclipse.core.resources.IFolder, org.eclipse.core.runtime.IProgressMonitor)
*/
public PreverificationError[] preverify(IResource[] toVerify, IFolder outputFolder, IProgressMonitor monitor)
throws CoreException, IOException
{
return getPreverifier().preverify(
this,
toVerify,
outputFolder,
monitor);
}
/**
* @see eclipseme.core.model.IMidletSuiteProject#preverifyJarFile(java.io.File, org.eclipse.core.resources.IFolder, org.eclipse.core.runtime.IProgressMonitor)
*/
public PreverificationError[] preverifyJarFile(File jarFile, IFolder outputFolder, IProgressMonitor monitor) throws CoreException, IOException {
return getPreverifier().preverifyJarFile(
this,
jarFile,
outputFolder,
monitor);
}
/**
* @see eclipseme.core.model.IMidletSuiteProject#setDeployedJarFileUpToDate(boolean)
*/
public void setDeployedJarFileUpToDate(boolean upToDate) throws CoreException {
String value = upToDate ? "true" : "false";
getProject().setPersistentProperty(DEPLOYMENT_UP_TO_DATE_PROP, value);
}
/**
* @see eclipseme.core.model.IMidletSuiteProject#setDevice(eclipseme.core.model.device.IDevice, org.eclipse.core.runtime.IProgressMonitor)
*/
public void setDevice(IDevice device, IProgressMonitor monitor)
throws CoreException
{
if ((metaData.getDevice() == null) || (!metaData.getDevice().equals(device))) {
metaData.setDevice(device);
// Make sure that we have a place to put the
// classpath updates
addClasspathContainerIfMissing(monitor);
// Reset the classpath container for the project so the
// initializer will be called again
JavaCore.setClasspathContainer(
new Path(J2MEClasspathContainer.J2ME_CONTAINER),
new IJavaProject[] { getJavaProject() },
new IClasspathContainer[] { null },
monitor);
// Force a rebuild
getProject().build(IncrementalProjectBuilder.FULL_BUILD, monitor);
}
}
/**
* @throws CoreException
* @see eclipseme.core.model.IMidletSuiteProject#setJadFileLocation(org.eclipse.core.runtime.IPath)
*/
public void setJadFileLocation(IPath projectRelativePath)
throws CoreException
{
getMetaData().setJadFile(projectRelativePath.toString());
saveMetaData();
}
/**
* Add the J2ME classpath container to the java project
* we wrap if it is currently missing. This step provides
* migration for projects created with earlier releases
* of EclipseME as well as providing a means to fix
* projects that have lost their platform definition
* association.
*
* @param monitor
* @throws JavaModelException
*/
private void addClasspathContainerIfMissing(IProgressMonitor monitor)
throws CoreException
{
boolean hasClasspathContainer =
containsJ2MEClasspathContainer(getJavaProject());
boolean hasPreprocessingNature = isPreprocessedProject();
if (!hasClasspathContainer && !hasPreprocessingNature) {
// Create a new classpath entry for the classpath
// container
IPath entryPath =
new Path(J2MEClasspathContainer.J2ME_CONTAINER);
IClasspathEntry newEntry =
JavaCore.newContainerEntry(entryPath);
// Get the current classpath entries
IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
Set currentClasspath = new LinkedHashSet(rawClasspath.length);
for (int i = 0; i < rawClasspath.length; i++) {
IClasspathEntry entry = rawClasspath[i];
if (entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
entry = JavaCore.getResolvedClasspathEntry(entry);
}
currentClasspath.add(entry);
}
// The classpath entries that are provided by
// the platform definition currently
IClasspathEntry[] platformEntries =
getDevice().getClasspath().asClasspathEntries();
// Remove the classpath entries from the project
// if they are provided by the platform definition
for (int i = 0; i < platformEntries.length; i++) {
IClasspathEntry entry = platformEntries[i];
if (currentClasspath.contains(entry)) {
currentClasspath.remove(entry);
}
}
// Set the updated classpath
currentClasspath.add(newEntry);
IClasspathEntry[] newClasspath =
(IClasspathEntry[]) currentClasspath.toArray(
new IClasspathEntry[currentClasspath.size()]);
javaProject.setRawClasspath(newClasspath, monitor);
}
}
/**
* Return the preverifier to use for resources in this project.
*/
private IPreverifier getPreverifier() {
IPreverifier preverifier = null;
if (isEmbeddedPreverifierEnabled()) {
preverifier = new EmbeddedPreverifier();
} else {
IDevice device = getDevice();
preverifier = (device == null) ?
new EmbeddedPreverifier() : device.getPreverifier();
}
return preverifier;
}
/**
* Get the project name, replacing spaces with underscores.
*
* @return
*/
private String getProjectNameWithoutSpaces()
{
String projectName = javaProject.getProject().getName();
return projectName.replace(' ', '_');
}
/**
* Return a boolean indicating whether or not to use the embedded preverifier.
*
* @param project
* @return
*/
private boolean isEmbeddedPreverifierEnabled() {
return PreferenceAccessor.instance.getUseBuiltInPreverifier(getProject());
}
/**
* Initialize the project metadata.
*/
private void initializeMetadata() {
try {
if (isPreprocessedProject()) {
ICommand preverifierCommand = null;
ICommand[] buildCommands = getProject().getDescription().getBuildSpec();
for (int i = 0; i < buildCommands.length; i++) {
ICommand command = buildCommands[i];
if (command.getBuilderName().equals(IEclipseMECoreConstants.J2ME_PREVERIFIER_ID)) {
preverifierCommand = command;
break;
}
}
if (preverifierCommand != null) {
// Pull out the target project and use its metadata
String targetProjectName =
(String) preverifierCommand.getArguments().get(IPreverifier.BUILD_ARG_PREVERIFY_TARGET);
IProject targetProject =
ResourcesPlugin.getWorkspace().getRoot().getProject(targetProjectName);
if (targetProject != null) {
metaData = new MetaData(targetProject);
}
}
}
} catch (CoreException e) {
EclipseMECorePlugin.log(IStatus.ERROR, e);
}
if (metaData == null) {
metaData = new MetaData(this);
}
}
/**
* @see eclipseme.core.model.IMidletSuiteProject#getEnabledSymbolDefinitionSet()
*/
public SymbolDefinitionSet getEnabledSymbolDefinitionSet()
throws CoreException, PersistenceException
{
SymbolDefinitionSet set = null;
String setName = getProject().getPersistentProperty(SYMBOL_SETS_PROP);
if (setName != null) {
set = SymbolDefinitionSetRegistry.singleton.getSymbolDefinitionSet(setName);
}
return set;
}
/**
* @see eclipseme.core.model.IMidletSuiteProject#setEnabledSymbolDefinitionSet(eclipseme.core.model.SymbolDefinitionSet)
*/
public void setEnabledSymbolDefinitionSet(SymbolDefinitionSet set)
throws CoreException, PersistenceException
{
String setName = null;
if (set != null) {
setName = set.getName();
}
getProject().setPersistentProperty(SYMBOL_SETS_PROP, setName);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -