📄 midletsuiteproject.java
字号:
/**
* Copyright (c) 2003-2005 Craig Setera
* All Rights Reserved.
* Licensed under the Eclipse Public License - v 1.0
* For more information see http://www.eclipse.org/legal/epl-v10.html
*/
package eclipseme.core.model.impl;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.jdt.core.IClasspathContainer;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import eclipseme.core.IEclipseMECoreConstants;
import eclipseme.core.internal.EclipseMECorePlugin;
import eclipseme.core.internal.J2MEClasspathContainer;
import eclipseme.core.internal.PreferenceAccessor;
import eclipseme.core.internal.preverification.builder.PreverificationBuilder;
import eclipseme.core.internal.preverifier.EmbeddedPreverifier;
import eclipseme.core.internal.utils.FilteringClasspathEntryVisitor;
import eclipseme.core.internal.utils.Utils;
import eclipseme.core.model.ApplicationDescriptor;
import eclipseme.core.model.IMidletSuiteProject;
import eclipseme.core.model.IPreverifier;
import eclipseme.core.model.ISignatureProperties;
import eclipseme.core.model.SymbolDefinitionSet;
import eclipseme.core.model.SymbolDefinitionSetRegistry;
import eclipseme.core.model.device.IDevice;
import eclipseme.core.persistence.PersistenceException;
import eclipseme.preverifier.results.PreverificationError;
/**
* Implementation of the IMidletSuiteProject interface
* providing access to midlet suite specific information.
* <p>
* <b>Note:</b> This class/interface is part of an interim API that is still under development and expected to
* change before reaching stability. It is being made available at this early stage to solicit feedback
* from pioneering adopters on the understanding that any code that uses this API will almost
* certainly be broken as the API evolves.
* </p>
* Copyright (c) 2003-2005 Craig Setera<br>
* All Rights Reserved.<br>
* Licensed under the Eclipse Public License - v 1.0<p/>
* <br>
* $Revision: 1.25 $
* <br>
* $Date: 2006/11/12 01:11:03 $
* <br>
* @author Craig Setera
*/
public class MidletSuiteProject implements IMidletSuiteProject {
/** The verified subdirectory for classes */
public static final String CLASSES_DIRECTORY = "classes";
/** The verified subdirectory for libraries */
public static final String LIBS_DIRECTORY = "libs";
// The up-to-date flag for the deployed jar file
private static final QualifiedName DEPLOYMENT_UP_TO_DATE_PROP =
new QualifiedName(IEclipseMECoreConstants.PLUGIN_ID, "deployed_up_to_date");
// Storage for the symbol definition sets
private static final QualifiedName SYMBOL_SETS_PROP =
new QualifiedName(IEclipseMECoreConstants.PLUGIN_ID, "symbol_sets");
/**
* Classpath entry visitor implementation for collecting up
* the classpath.
*/
private class ClasspathCollectionVisitor extends FilteringClasspathEntryVisitor
{
private Set cpEntries;
private IPath classesPath;
private IPath libsPath;
/** Constructor */
private ClasspathCollectionVisitor(IPath classesPath, IPath libsPath) {
this.classesPath = classesPath;
this.libsPath = libsPath;
cpEntries = new LinkedHashSet();
}
/**
* @return Returns the cpEntries.
*/
public Set getCpEntries() {
return cpEntries;
}
/**
* @see eclipseme.core.internal.utils.IClasspathEntryVisitor#visitLibraryEntry(org.eclipse.jdt.core.IClasspathEntry, org.eclipse.jdt.core.IJavaProject, org.eclipse.core.runtime.IProgressMonitor)
*/
public void visitLibraryEntry(
IClasspathEntry entry,
IJavaProject javaProject,
IProgressMonitor monitor)
throws CoreException
{
File resolvedEntry = Utils.getResolvedClasspathEntryFile(entry);
if (resolvedEntry.isFile()) {
IPath libPath = libsPath.append(entry.getPath().lastSegment());
cpEntries.add(libPath);
}
}
/**
* @see eclipseme.core.internal.utils.IClasspathEntryVisitor#visitSourceEntry(org.eclipse.jdt.core.IClasspathEntry, org.eclipse.jdt.core.IJavaProject, org.eclipse.core.runtime.IProgressMonitor)
*/
public void visitSourceEntry(
IClasspathEntry entry,
IJavaProject javaProject,
IProgressMonitor monitor)
throws CoreException
{
cpEntries.add(classesPath);
}
}
/**
* Return the default JAD file name for the specified project.
*
* @param project
* @return
*/
public static String getDefaultJadFileName(IProject project) {
String projectName = project.getName();
return projectName.replace(' ', '_') + ".jad";
}
/**
* Return a boolean indicating whether the project contains the
* J2ME classpath container.
*
* @param javaProject the project to be tested
* @return whether the project has the J2ME classpath container
* @throws JavaModelException
*/
public static boolean containsJ2MEClasspathContainer(IJavaProject javaProject)
throws JavaModelException
{
boolean contains = false;
IClasspathEntry[] classpath = javaProject.getRawClasspath();
for (int i = 0; i < classpath.length; i++) {
IClasspathEntry entry = classpath[i];
if ((entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) &&
(entry.getPath().segment(0).equals(J2MEClasspathContainer.J2ME_CONTAINER)))
{
contains = true;
break;
}
}
return contains;
}
// The metadata about this project
private MetaData metaData;
// The java project on which this midlet suite is based
private IJavaProject javaProject;
private String tempKeystorePassword;
private String tempKeyPassword;
/**
* Private constructor for singleton instances of the
* class.
*/
public MidletSuiteProject(IJavaProject javaProject) {
super();
this.javaProject = javaProject;
initializeMetadata();
}
/**
* @see eclipseme.core.model.IMidletSuiteProject#getApplicationDescriptor()
*/
public ApplicationDescriptor getApplicationDescriptor() {
ApplicationDescriptor descriptor = null;
IFile jadFile = getJadFile();
if (!jadFile.exists()) {
// Create JAD file
}
try {
File jFile = jadFile.getLocation().toFile();
descriptor = new ApplicationDescriptor(jFile);
} catch (IOException e) {
EclipseMECorePlugin.log(IStatus.ERROR, "getApplicationDescriptor", e);
}
return descriptor;
}
/**
* @see eclipseme.core.model.IMidletSuiteProject#createPackage(org.eclipse.core.runtime.IProgressMonitor, boolean)
*/
public void createPackage(IProgressMonitor monitor, boolean obfuscate)
throws CoreException
{
Map args = new HashMap(2);
args.put(PreverificationBuilder.ARG_DO_PACKAGE, Boolean.TRUE);
args.put(PreverificationBuilder.ARG_DO_OBFUSCATION, new Boolean(obfuscate));
args.put(PreverificationBuilder.ARG_UPDATE_VERSION, Boolean.TRUE);
PreverificationBuilder.cleanProject(getProject(), true, monitor);
this.getProject().build(
IncrementalProjectBuilder.FULL_BUILD,
IEclipseMECoreConstants.J2ME_PREVERIFIER_ID,
args,
monitor);
}
/**
* @see eclipseme.core.model.IMidletSuiteProject#getClasspath(org.eclipse.core.runtime.IProgressMonitor)
*/
public File[] getClasspath(IProgressMonitor monitor)
throws CoreException
{
// The verified output locations
IPath classesPath = getVerifiedClassesOutputFolder(monitor).getLocation();
IPath libsPath = getVerifiedLibrariesOutputFolder(monitor).getLocation();
// Build up the list of IPath entries based on the project
// classpath setup to maintain relative ordering
ClasspathCollectionVisitor visitor =
new ClasspathCollectionVisitor(classesPath, libsPath);
visitor.getRunner().run(javaProject, visitor, monitor);
int index = 0;
Set cpEntries = visitor.getCpEntries();
File[] entries = new File[cpEntries.size()];
Iterator iterator = cpEntries.iterator();
while (iterator.hasNext()) {
IPath path = (IPath) iterator.next();
entries[index++] = path.toFile();
}
return entries;
}
/**
* Return the device referenced by this project.
*/
public IDevice getDevice() {
return metaData.getDevice();
}
public ISignatureProperties getSignatureProperties()
throws CoreException
{
return(metaData.getSignatureProperties());
}
public void setSignatureProperties(ISignatureProperties props)
{
metaData.setSignatureProperties(props);
}
public void saveMetaData()
throws CoreException
{
// Don't save the metadata if this is a preprocessed project,
// as it belongs to the base project
if (!isPreprocessedProject()) {
metaData.saveMetaData();
}
}
public String getTempKeystorePassword()
{
return(tempKeystorePassword);
}
public void setTempKeystorePassword(String pass)
{
tempKeystorePassword = pass;
}
public String getTempKeyPassword()
{
return(tempKeyPassword);
}
public void setTempKeyPassword(String pass)
{
tempKeyPassword = pass;
}
/**
* @see eclipseme.core.model.IMidletSuiteProject#getJadFile()
*/
public IFile getJadFile() {
IFile jadFile = null;
IProject project = javaProject.getProject();
String filename = getMetaData().getJadFile();
if ((filename == null) || (filename.length() == 0)) {
String defaultName = getDefaultJadFileName(project);
jadFile = project.getFile(defaultName);
} else {
jadFile = project.getFile(filename);
}
return jadFile;
}
/**
* @see eclipseme.core.model.IMidletSuiteProject#getJarFilename()
*/
public String getJarFilename() {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -