/**
* 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.internal.preverification.builder;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
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.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.IStreamListener;
import org.eclipse.debug.core.model.IProcess;
import org.eclipse.debug.core.model.IStreamMonitor;
import org.eclipse.debug.core.model.IStreamsProxy;
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 de.schlichtherle.io.ArchiveException;
import de.schlichtherle.io.File;
import de.schlichtherle.io.FileOutputStream;
import eclipseme.core.BuildLoggingConfiguration;
import eclipseme.core.IEclipseMECoreConstants;
import eclipseme.core.console.BuildConsoleProxy;
import eclipseme.core.console.IBuildConsoleProxy;
import eclipseme.core.internal.EclipseMECorePlugin;
import eclipseme.core.internal.PreferenceAccessor;
import eclipseme.core.internal.packaging.DeployedJADWriter;
import eclipseme.core.internal.packaging.ObfuscatorTool;
import eclipseme.core.internal.preverifier.PreverificationUtils;
import eclipseme.core.internal.utils.AbstractClasspathEntryVisitor;
import eclipseme.core.internal.utils.ColonDelimitedProperties;
import eclipseme.core.internal.utils.Utils;
import eclipseme.core.model.ApplicationDescriptor;
import eclipseme.core.model.IJADConstants;
import eclipseme.core.model.IMidletSuiteProject;
import eclipseme.core.model.MidletSuiteFactory;
import eclipseme.core.model.Version;
import eclipseme.core.model.ApplicationDescriptor.MidletDefinition;
import eclipseme.preverifier.results.PreverificationError;
/**
* Provides an incremental project builder implementation
* to do a J2ME preverification of classes. It is imperative
* that this builder follow the standard Java builder. The
* standard Java builder will generate the standard compiled
* class. The preverifier will then preverify that generated
* class.
* <p />
* Copyright (c) 2003-2007 Craig Setera<br>
* All Rights Reserved.<br>
* Licensed under the Eclipse Public License - v 1.0<p/>
* <br>
* $Revision: 1.16 $
* <br>
* $Date: 2006/11/26 21:42:00 $
* <br>
* @author Craig Setera
*/
public class PreverificationBuilder extends IncrementalProjectBuilder {
public static final String ARG_UPDATE_VERSION = "_update_version";
public static final String ARG_DO_PACKAGE = "_do_package";
public static final String ARG_DO_OBFUSCATION = "_do_obfuscation";
private static BuildLoggingConfiguration buildLoggingConfig = BuildLoggingConfiguration.instance;
// Tracks the TrueZip File instances that point to the deployed jar files
private static Map runtimeJars = new HashMap(5);
/**
* Clean the output of the specified project.
* @param project
* @param cleanDeployed Whether or not to clean the deployed directory too.
* @param monitor
*
* @throws JavaModelException
* @throws CoreException
*/
public static void cleanProject(IProject project, boolean cleanDeployed, IProgressMonitor monitor)
throws JavaModelException, CoreException
{
if (buildLoggingConfig.isPreverifierTraceEnabled()) {
BuildConsoleProxy.instance.traceln("> PreverificationBuilder.cleanProject project = " + project);
}
IJavaProject javaProject = JavaCore.create(project);
BuildInfo buildInfo =
new BuildInfo(IncrementalProjectBuilder.CLEAN_BUILD, new HashMap(), javaProject);
// Clear and remove the old verified directory and runtime folders
IFolder oldVerifiedFolder = project.getFolder(EclipseMECorePlugin.getVerifiedOutputDirectoryName());
if (oldVerifiedFolder.exists()) {
Utils.clearContainer(oldVerifiedFolder, monitor);
oldVerifiedFolder.delete(true, monitor);
}
IFolder oldRuntimeFolder = project.getFolder(IEclipseMECoreConstants.TEMP_FOLDER_NAME).getFolder("runtime");
if (oldRuntimeFolder.exists()) {
Utils.clearContainer(oldRuntimeFolder, monitor);
oldRuntimeFolder.delete(true, monitor);
}
// Clear the classes and libraries
IFolder classesPreverifyFolder = buildInfo.getVerifiedClassesFolder(monitor);
Utils.clearContainer(classesPreverifyFolder, monitor);
IFolder libsPreverifyFolder = buildInfo.getVerifiedLibsFolder(monitor);
Utils.clearContainer(libsPreverifyFolder, monitor);
// Delete the runtime JAR file
IFolder runtimeFolder = buildInfo.getRuntimeFolder(monitor);
if (runtimeFolder.exists()) {
deleteRuntimeJar(project, monitor);
Utils.clearContainer(runtimeFolder, monitor);
}
// We also delete the deployed folder
if (cleanDeployed) {
IFolder deploymentFolder = getDeploymentFolder(project, monitor);
if (deploymentFolder.exists()) {
Utils.clearContainer(deploymentFolder, monitor);
}
}
if (buildLoggingConfig.isPreverifierTraceEnabled()) {
BuildConsoleProxy.instance.traceln("< PreverificationBuilder.cleanProject project = " + project);
}
}
/**
* Return the File instance for the runtime jar file in the specified project.
*
* @param project
* @return
*/
public static File getRuntimeJar(IProject project, IProgressMonitor monitor)
throws CoreException
{
if (buildLoggingConfig.isPreverifierTraceEnabled()) {
BuildConsoleProxy.instance.traceln("> PreverificationBuilder.getRuntimeJar project = " + project);
}
File runtimeJar = (File) runtimeJars.get(project);
if (runtimeJar == null) {
if (buildLoggingConfig.isPreverifierTraceEnabled()) {
BuildConsoleProxy.instance.traceln("- PreverificationBuilder.getRuntimeJar JAR file not in cache");
}
IFolder tempFolder = project.getFolder(IEclipseMECoreConstants.TEMP_FOLDER_NAME);
IFolder runtimeFolder = tempFolder.getFolder(IEclipseMECoreConstants.EMULATION_FOLDER_NAME);
createFolders(runtimeFolder, monitor);
IJavaProject javaProject = JavaCore.create(project);
IMidletSuiteProject midletSuite =
MidletSuiteFactory.getMidletSuiteProject(javaProject);
runtimeJar = new File(runtimeFolder.getLocation().toFile(), midletSuite.getJarFilename());
runtimeJar.mkdir();
runtimeFolder.refreshLocal(IResource.DEPTH_ONE, monitor);
runtimeJars.put(project, runtimeJar);
}
if (buildLoggingConfig.isPreverifierTraceEnabled()) {
BuildConsoleProxy.instance.traceln("< PreverificationBuilder.getRuntimeJar project = " + project);
}
return runtimeJar;
}
/**
* Delete the deployed jar file instance being cached (if found).
*
* @param project
* @param monitor
* @throws CoreException
*/
private static void deleteRuntimeJar(IProject project, IProgressMonitor monitor)
throws CoreException
{
if (buildLoggingConfig.isPreverifierTraceEnabled()) {
BuildConsoleProxy.instance.traceln("> PreverificationBuilder.deleteRuntimeJar project = " + project);
}
File runtimeJar = (File) runtimeJars.remove(project);
if ((runtimeJar != null) && (runtimeJar.exists())) {
try {
if (buildLoggingConfig.isPreverifierTraceEnabled())
评论0
最新资源