Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 117958 Details for
Bug 245565
Importing a plug-in as binary project should not extract the source bundle
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Work in progress II
clipboard.txt (text/plain), 132.81 KB, created by
Curtis Windatt
on 2008-11-14 17:31:13 EST
(
hide
)
Description:
Work in progress II
Filename:
MIME Type:
Creator:
Curtis Windatt
Created:
2008-11-14 17:31:13 EST
Size:
132.81 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.pde.ui >Index: src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportWizard.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportWizard.java,v >retrieving revision 1.52 >diff -u -r1.52 PluginImportWizard.java >--- src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportWizard.java 11 Jan 2008 20:00:06 -0000 1.52 >+++ src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportWizard.java 14 Nov 2008 22:28:56 -0000 >@@ -11,8 +11,8 @@ > package org.eclipse.pde.internal.ui.wizards.imports; > > import java.util.*; >-import org.eclipse.core.runtime.*; >-import org.eclipse.core.runtime.jobs.Job; >+import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.CoreException; > import org.eclipse.debug.core.*; > import org.eclipse.jface.dialogs.*; > import org.eclipse.jface.viewers.IStructuredSelection; >@@ -133,21 +133,9 @@ > } > > private static void doImportOperation(final Shell shell, final int importType, final IPluginModelBase[] models, final boolean forceAutobuild, final boolean launchedConfiguration) { >- PluginImportOperation.IImportQuery query = new ImportQuery(shell); >- PluginImportOperation.IImportQuery executionQuery = new ImportQuery(shell); >- final PluginImportOperation op = new PluginImportOperation(models, importType, query, executionQuery, forceAutobuild); >- op.setLaunchedConfiguration(launchedConfiguration); >- Job job = new Job(PDEUIMessages.ImportWizard_title) { >- protected IStatus run(IProgressMonitor monitor) { >- try { >- PDEPlugin.getWorkspace().run(op, monitor); >- } catch (CoreException e) { >- PDEPlugin.logException(e); >- return Status.CANCEL_STATUS; >- } >- return Status.OK_STATUS; >- } >- }; >+ PluginImportOperation job = new PluginImportOperation(models, importType, new ImportQuery(shell), new ImportQuery(shell), forceAutobuild); >+ job.setPluginsInUse(launchedConfiguration); >+ job.setRule(ResourcesPlugin.getWorkspace().getRoot()); > job.setUser(true); > job.schedule(); > } >Index: src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportOperation.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportOperation.java,v >retrieving revision 1.122 >diff -u -r1.122 PluginImportOperation.java >--- src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportOperation.java 24 Oct 2008 14:55:21 -0000 1.122 >+++ src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportOperation.java 14 Nov 2008 22:28:56 -0000 >@@ -14,7 +14,6 @@ > import java.io.IOException; > import java.util.*; > import java.util.jar.JarFile; >-import java.util.zip.ZipEntry; > import java.util.zip.ZipFile; > import org.eclipse.core.resources.*; > import org.eclipse.core.runtime.*; >@@ -22,9 +21,7 @@ > import org.eclipse.jdt.core.*; > import org.eclipse.jdt.launching.JavaRuntime; > import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager; >-import org.eclipse.osgi.service.environment.Constants; > import org.eclipse.osgi.service.resolver.BundleDescription; >-import org.eclipse.osgi.service.resolver.HostSpecification; > import org.eclipse.osgi.util.ManifestElement; > import org.eclipse.osgi.util.NLS; > import org.eclipse.pde.core.build.IBuild; >@@ -38,7 +35,6 @@ > import org.eclipse.pde.internal.core.util.CoreUtility; > import org.eclipse.pde.internal.ui.PDEPlugin; > import org.eclipse.pde.internal.ui.PDEUIMessages; >-import org.eclipse.swt.widgets.Display; > import org.eclipse.team.core.RepositoryProvider; > import org.eclipse.team.core.TeamException; > import org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider; >@@ -46,16 +42,19 @@ > import org.osgi.framework.BundleException; > > /** >- * Imports one or more plugins into the workspace. There are three different >+ * Imports one or more plug-ins into the workspace. There are three different > * ways to import a plugin: as binary, as binary with linked source, > * and as source. > */ >-public class PluginImportOperation extends JarImportOperation { >+public class PluginImportOperation extends Job { > > public static final int IMPORT_BINARY = 1; > public static final int IMPORT_BINARY_WITH_LINKS = 2; > public static final int IMPORT_WITH_SOURCE = 3; > >+ private static final String DEFAULT_SOURCE_DIR = "src"; //$NON-NLS-1$ >+ private static final String DEFAULT_LIBRARY_NAME = "."; //$NON-NLS-1$ >+ > private IPluginModelBase[] fModels; > private int fImportType; > private IImportQuery fReplaceQuery; >@@ -63,11 +62,7 @@ > private boolean fForceAutobuild; > private IImportQuery fExecutionQuery; > >- private boolean fLaunchedConfigurations = false; >- /** >- * A list of plugins that were unable to be deleted >- */ >- private ArrayList fUnableToDeletePlugins; >+ private boolean fPluginsAreInUse = false; > > public interface IImportQuery { > public static final int CANCEL = 0; >@@ -83,107 +78,81 @@ > * @param importType one of three types specified by constants, binary, binary with links, source > * @param replaceQuery defines what to do if the project already exists in the workspace > * @param executionQuery defines what to do if the project requires an unsupported execution environment >+ * @param forceAutobuild whether to force a build after the import > */ >- public PluginImportOperation(IPluginModelBase[] models, int importType, IImportQuery replaceQuery, IImportQuery executionQuery) { >+ public PluginImportOperation(IPluginModelBase[] models, int importType, IImportQuery replaceQuery, IImportQuery executionQuery, boolean forceAutobuild) { >+ super(PDEUIMessages.ImportWizard_title); > fModels = models; > fImportType = importType; > fReplaceQuery = replaceQuery; > fExecutionQuery = executionQuery; >- fUnableToDeletePlugins = new ArrayList(); >+ fForceAutobuild = forceAutobuild; > } > > /** >- * Constructor >- * @param models models of plugins to import >- * @param importType one of three types specified by constants, binary, binary with links, source >- * @param replaceQuery defines what to do if the project already exists in the workspace >- * @param executionQuery defines what to do if the project requires an unsupported execution environment >- * @param forceAutobuild whether to force a build after the import >+ * Sets whether some of the plug-ins being imported are currently in use by a launched >+ * Eclipse instance. Setting this to true will force an additional check before deleting >+ * a plug-in. >+ * @param pluginsInUse > */ >- public PluginImportOperation(IPluginModelBase[] models, int importType, IImportQuery replaceQuery, IImportQuery executionQuery, boolean forceAutobuild) { >- this(models, importType, replaceQuery, executionQuery); >- fForceAutobuild = forceAutobuild; >+ public void setPluginsInUse(boolean pluginsInUse) { >+ fPluginsAreInUse = pluginsInUse; > } > > /* (non-Javadoc) >- * @see org.eclipse.core.resources.IWorkspaceRunnable#run(org.eclipse.core.runtime.IProgressMonitor) >+ * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) > */ >- public void run(IProgressMonitor monitor) throws CoreException, OperationCanceledException { >- if (monitor == null) { >- monitor = new NullProgressMonitor(); >- } >- monitor.beginTask(PDEUIMessages.ImportWizard_operation_creating, fModels.length + 1); >+ protected IStatus run(IProgressMonitor monitor) { > try { >+ monitor.beginTask(PDEUIMessages.ImportWizard_operation_creating, fModels.length + 1); > MultiStatus multiStatus = new MultiStatus(PDEPlugin.getPluginId(), IStatus.OK, PDEUIMessages.ImportWizard_operation_multiProblem, null); > > for (int i = 0; i < fModels.length; i++) { >+ monitor.setTaskName(NLS.bind(PDEUIMessages.PluginImportOperation_Importing_plugin, fModels[i].getPluginBase().getId())); > try { > importPlugin(fModels[i], new SubProgressMonitor(monitor, 1)); > } catch (CoreException e) { > multiStatus.merge(e.getStatus()); > } > if (monitor.isCanceled()) { >- setClasspaths(new SubProgressMonitor(monitor, 1)); >- throw new OperationCanceledException(); >+ try { >+ setClasspaths(new SubProgressMonitor(monitor, 1)); >+ } catch (JavaModelException e) { >+ /* Do nothing as we are already cancelled */ >+ } >+ return Status.CANCEL_STATUS; > } > } >- setClasspaths(new SubProgressMonitor(monitor, 1)); >+ try { >+ setClasspaths(new SubProgressMonitor(monitor, 1)); >+ } catch (JavaModelException e) { >+ multiStatus.merge(e.getStatus()); >+ } > if (!ResourcesPlugin.getWorkspace().isAutoBuilding() && fForceAutobuild) > runBuildJob(); >- if (!multiStatus.isOK()) >- throw new CoreException(multiStatus); >+ return multiStatus; > } finally { > monitor.done(); >- if (!fUnableToDeletePlugins.isEmpty()) { >- final Display display = Display.getDefault(); >- display.syncExec(new Runnable() { >- public void run() { >- PluginImportFinishDialog dialog = new PluginImportFinishDialog(display.getActiveShell()); >- dialog.setTitle(PDEUIMessages.PluginImportInfoDialog_title); >- dialog.setMessage(PDEUIMessages.PluginImportInfoDialog_message); >- dialog.setInput(fUnableToDeletePlugins); >- dialog.open(); >- } >- >- }); >- } > } > } > > /** >- * Starts a job that will build the workspace >- */ >- private void runBuildJob() { >- Job buildJob = new Job(PDEUIMessages.CompilersConfigurationBlock_building) { >- public boolean belongsTo(Object family) { >- return ResourcesPlugin.FAMILY_AUTO_BUILD == family; >- } >- >- protected IStatus run(IProgressMonitor monitor) { >- try { >- PDEPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor); >- } catch (CoreException e) { >- } >- return Status.OK_STATUS; >- } >- }; >- buildJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule()); >- buildJob.schedule(); >- } >- >- /** > * Sets the raw classpath of projects that need to be updated > * @param monitor > * @throws JavaModelException if a classpath could not be set > */ > private void setClasspaths(IProgressMonitor monitor) throws JavaModelException { >- monitor.beginTask("", fProjectClasspaths.size()); //$NON-NLS-1$ >- Enumeration keys = fProjectClasspaths.keys(); >- while (keys.hasMoreElements()) { >- IProject project = (IProject) keys.nextElement(); >- IClasspathEntry[] classpath = (IClasspathEntry[]) fProjectClasspaths.get(project); >- monitor.subTask(project.getName()); >- JavaCore.create(project).setRawClasspath(classpath, new SubProgressMonitor(monitor, 1)); >+ try { >+ monitor.beginTask("", fProjectClasspaths.size()); //$NON-NLS-1$ >+ Enumeration keys = fProjectClasspaths.keys(); >+ while (keys.hasMoreElements()) { >+ IProject project = (IProject) keys.nextElement(); >+ IClasspathEntry[] classpath = (IClasspathEntry[]) fProjectClasspaths.get(project); >+ monitor.subTask(project.getName()); >+ JavaCore.create(project).setRawClasspath(classpath, new SubProgressMonitor(monitor, 1)); >+ } >+ } finally { >+ monitor.done(); > } > } > >@@ -196,119 +165,224 @@ > * @throws CoreException if a problem occurs while importing a plugin > */ > private void importPlugin(IPluginModelBase model, IProgressMonitor monitor) throws CoreException { >- String id = model.getPluginBase().getId(); >- monitor.beginTask(NLS.bind(PDEUIMessages.ImportWizard_operation_creating2, id), 6); > try { >- BundleDescription desc = model.getBundleDescription(); >- if (desc != null) { >- IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager(); >- String[] envs = desc.getExecutionEnvironments(); >- boolean found = false; >- for (int i = 0; i < envs.length; i++) { >- if (manager.getEnvironment(envs[i]) != null) { >- found = true; >- break; >- } >- } >- if (envs.length > 0 && !found) { >- String message = NLS.bind(PDEUIMessages.PluginImportOperation_executionEnvironment, id, envs[0]); >- if (!queryExecutionEnvironment(message)) >- return; >- } >- } >+ monitor.beginTask("", 5); //$NON-NLS-1$ > >- IProject project = findProject(id); >- >- if (project.exists() || new File(project.getParent().getLocation().toFile(), project.getName()).exists()) { >- if (!queryReplace(project)) >- return; >- if (RepositoryProvider.isShared(project)) >- RepositoryProvider.unmap(project); >- if (!project.exists()) >- project.create(new SubProgressMonitor(monitor, 1)); >- if (!safeDeleteCheck(project, monitor)) { >- fUnableToDeletePlugins.add(model); >- return; >- } >- try { >- project.delete(true, true, monitor); >- } catch (CoreException e) { >- fUnableToDeletePlugins.add(model); >- return; >- } >+ // Test is the required execution environment is supported >+ if (!testExecutionEnvironment(model)) { >+ return; > } >+ // Create the project or ask to overwrite if project exists >+ IProject project = createProject(model, new SubProgressMonitor(monitor, 1)); > >- project.create(monitor); >- if (!project.isOpen()) >- project.open(monitor); >- monitor.worked(1); >- >+ // Target Weaving: if we are importing plug-ins in the runtime workbench from the host workbench, import everything as-is and return > if (Platform.inDevelopmentMode()) { >- // if we are importing plug-ins in the runtime workbench from the host workbench, import everything as-is and return > File location = new File(model.getInstallLocation()); > if (location.isDirectory()) { > File classpathFile = new File(location, ".classpath"); //$NON-NLS-1$ > File projectFile = new File(location, ".project"); //$NON-NLS-1$ > if (classpathFile.exists() && classpathFile.isFile() && projectFile.exists() && projectFile.isFile()) { >- importContent(location, project.getFullPath(), FileSystemStructureProvider.INSTANCE, null, new SubProgressMonitor(monitor, 1)); >+ PluginImportHelper.importContent(location, project.getFullPath(), FileSystemStructureProvider.INSTANCE, null, new SubProgressMonitor(monitor, 4)); > return; > } > } > } > >- switch (fImportType) { >- case IMPORT_BINARY : >- importAsBinary(project, model, true, new SubProgressMonitor(monitor, 4)); >- break; >- case IMPORT_BINARY_WITH_LINKS : >- if (id.startsWith("org.eclipse.swt") && !isJARd(model)) { //$NON-NLS-1$ >- importAsBinary(project, model, true, monitor); >- } else { >- importAsBinaryWithLinks(project, model, new SubProgressMonitor(monitor, 4)); >- } >- break; >- case IMPORT_WITH_SOURCE : >- if (isExempt(model)) { >- importAsBinary(project, model, true, new SubProgressMonitor(monitor, 4)); >- } else { >- importAsSource(project, model, new SubProgressMonitor(monitor, 4)); >- } >+ // Perform the import >+ Map sourceMap = null; >+ if (fImportType == IMPORT_BINARY || isExempt(model)) { >+ sourceMap = importAsBinary(project, model, new SubProgressMonitor(monitor, 4)); >+ } else if (fImportType == IMPORT_BINARY_WITH_LINKS) { >+ sourceMap = importAsBinaryWithLinks(project, model, new SubProgressMonitor(monitor, 4)); >+ } else if (fImportType == IMPORT_WITH_SOURCE) { >+ importAsSource(project, model, new SubProgressMonitor(monitor, 4)); > } > >- setProjectDescription(project, model); >+ setProjectNatures(project, model); > >+ // Set the classpath > if (project.hasNature(JavaCore.NATURE_ID) && project.findMember(".classpath") == null) //$NON-NLS-1$ >- fProjectClasspaths.put(project, ClasspathComputer.getClasspath(project, model, true, false)); >- } catch (CoreException e) { >- PDEPlugin.logException(e); >+ fProjectClasspaths.put(project, ClasspathComputer.getClasspath(project, model, sourceMap, true, false)); > } finally { > monitor.done(); > } > } > >- // Returns the name of any projects the currently exist with same id and version. Otherwise it returns a default naming convention >- protected String getProjectName(IPluginModelBase model) { >- String id = model.getPluginBase().getId(); >- String version = model.getPluginBase().getVersion(); >- ModelEntry entry = PluginRegistry.findEntry(id); >- if (entry != null) { >- IPluginModelBase[] existingModels = entry.getWorkspaceModels(); >- for (int i = 0; i < existingModels.length; i++) { >- String existingVersion = existingModels[i].getPluginBase().getVersion(); >- if (version.equals(existingVersion)) { >- IResource res = existingModels[i].getUnderlyingResource(); >- if (res != null) >- return res.getProject().getName(); >+ /** >+ * Imports the contents of the plugin and imports source files as binary files that will not be compiled. >+ * @param project destination project of the import >+ * @param model model representing the plugin to import >+ * @param monitor progress monitor >+ * @return a mapping of libraries to source locations to use in the classpath >+ * @throws CoreException if there is a problem completing the import >+ */ >+ private Map importAsBinary(IProject project, IPluginModelBase model, IProgressMonitor monitor) throws CoreException { >+ try { >+ monitor.beginTask("", 3); //$NON-NLS-1$ >+ >+ // Import the plug-in content >+ File srcFile = new File(model.getInstallLocation()); >+ if (isJARd(model)) { >+ PluginImportHelper.copyArchive(srcFile, project.getFile(srcFile.getName()), new SubProgressMonitor(monitor, 1)); >+ } else { >+ PluginImportHelper.importContent(new File(model.getInstallLocation()), project.getFullPath(), FileSystemStructureProvider.INSTANCE, null, new SubProgressMonitor(monitor, 1)); >+ } >+ >+ // Import source from known source locations >+ Map sourceMap = importSourceArchives(project, model, IMPORT_BINARY, new SubProgressMonitor(monitor, 1)); >+ >+ // Extract the required bundle files and modify the imported manifest to have the correct classpath >+ importRequiredPluginFiles(project, model, new SubProgressMonitor(monitor, 1)); >+ modifyBundleClasspathHeader(project, model); >+ >+ // Mark the project as binary >+ project.setPersistentProperty(PDECore.EXTERNAL_PROJECT_PROPERTY, PDECore.BINARY_PROJECT_VALUE); >+ RepositoryProvider.map(project, PDECore.BINARY_REPOSITORY_PROVIDER); >+ >+ return sourceMap; >+ >+ } finally { >+ monitor.done(); >+ } >+ } >+ >+ /** >+ * Creates links to remote plugin and source locations and sets up the project >+ * @param project destination project of the import >+ * @param model model representing the plugin to import >+ * @param monitor progress monitor >+ * @return mapping of library name to path to source library (relative to project) >+ * @throws CoreException if there is a problem completing the import >+ */ >+ private Map importAsBinaryWithLinks(IProject project, IPluginModelBase model, IProgressMonitor monitor) throws CoreException { >+ try { >+ monitor.beginTask("", 3); //$NON-NLS-1$ >+ >+ // Link the plug-in content >+ File srcFile = new File(model.getInstallLocation()); >+ IFile dstFile = project.getFile(new Path(srcFile.getName())); >+ dstFile.createLink(srcFile.toURI(), IResource.NONE, new SubProgressMonitor(monitor, 1)); >+ >+ // Link source from known source locations >+ Map sourceMap = importSourceArchives(project, model, IMPORT_BINARY_WITH_LINKS, new SubProgressMonitor(monitor, 1)); >+ >+ // Extract the required bundle files and modify the imported manifest to have the correct classpath >+ importRequiredPluginFiles(project, model, new SubProgressMonitor(monitor, 1)); >+ modifyBundleClasspathHeader(project, model); >+ >+ // Mark the project as binary >+ project.setPersistentProperty(PDECore.EXTERNAL_PROJECT_PROPERTY, PDECore.BINARY_PROJECT_VALUE); >+ RepositoryProvider.map(project, PDECore.BINARY_REPOSITORY_PROVIDER); >+ >+ return sourceMap; >+ >+ } finally { >+ monitor.done(); >+ } >+ } >+ >+ /** >+ * Imports the contents of the plugin and imports source files to source folders that will be compiled. >+ * @param project destination project of the import >+ * @param model model representing the plugin to import >+ * @param monitor progress monitor >+ * @throws CoreException if there is a problem completing the import >+ */ >+ private void importAsSource(IProject project, IPluginModelBase model, SubProgressMonitor monitor) throws CoreException { >+ try { >+ monitor.beginTask("", 4); //$NON-NLS-1$ >+ >+ // Extract the source >+ WorkspaceBuildModel buildModel = extractSourceFolders(project, model, new SubProgressMonitor(monitor, 1)); >+ >+ // Extract additional non-java files from the source bundles >+ importAdditionalSourceFiles(project, model, new SubProgressMonitor(monitor, 1)); >+ >+ // Extract the binary plug-in (for non-class files) >+ File srcFile = new File(model.getInstallLocation()); >+ if (isJARd(model)) { >+ PluginImportHelper.extractArchive(srcFile, project.getFullPath(), new SubProgressMonitor(monitor, 1)); >+ } else { >+ // TODO This might put everything into a folder, which is bad >+ PluginImportHelper.importContent(new File(model.getInstallLocation()), project.getFullPath(), FileSystemStructureProvider.INSTANCE, null, new SubProgressMonitor(monitor, 1)); >+ } >+ >+ // Create the build.properties file >+ configureBinIncludes(buildModel, model, project); >+ buildModel.save(); >+ monitor.worked(1); >+ >+ } finally { >+ monitor.done(); >+ } >+ >+ } >+ >+ /** >+ * Creates the project to add to the workspace. If the project already exists in >+ * the workspace ask the user if it is ok to overwrite. Will return <code>null</code> >+ * if no project could be created for the import (i.e. the user chooses to not overwrite). >+ * >+ * @param model plug-in being imported >+ * @param monitor progress monitor >+ * @return the project to use or <code>null</code> if no project could be created/overwritten >+ * @throws TeamException if an existing project is shared and an error occurs disconnecting it >+ * @throws CoreException if an error occurs when working with the project >+ */ >+ private IProject createProject(IPluginModelBase model, IProgressMonitor monitor) throws TeamException, CoreException { >+ try { >+ monitor.beginTask("", 2); //$NON-NLS-1$ >+ IProject project = findProject(model.getPluginBase().getId()); >+ if (project.exists() || new File(project.getParent().getLocation().toFile(), project.getName()).exists()) { >+ // Query the user to see if we should overwrite >+ switch (fReplaceQuery.doQuery(NLS.bind(PDEUIMessages.ImportWizard_messages_exists, project.getName()))) { >+ case IImportQuery.CANCEL : >+ throw new OperationCanceledException(); >+ case IImportQuery.NO : >+ return null; > } >+ if (RepositoryProvider.isShared(project)) >+ RepositoryProvider.unmap(project); >+ if (!project.exists()) >+ project.create(new SubProgressMonitor(monitor, 1)); >+ if (!safeDeleteCheck(project, monitor)) { >+ throw new CoreException(new Status(IStatus.ERROR, PDEPlugin.getPluginId(), NLS.bind(PDEUIMessages.PluginImportOperation_could_not_delete_project, project.getName()))); >+ } >+ project.delete(true, true, monitor); > } >+ >+ project.create(monitor); >+ if (!project.isOpen()) >+ project.open(monitor); >+ monitor.worked(1); >+ >+ return project; >+ >+ } finally { >+ monitor.done(); > } >- return id + "_" + version; //$NON-NLS-1$ > } > >- // returns true if it is safe to delete the project. It is not safe to delete if >- // one of its libraries is locked by a running launch configuration. >+ private IProject findProject(String id) { >+ IPluginModelBase model = PluginRegistry.findModel(id); >+ if (model != null) { >+ IResource resource = model.getUnderlyingResource(); >+ if (resource != null) >+ return resource.getProject(); >+ } >+ return PDEPlugin.getWorkspace().getRoot().getProject(id); >+ } >+ >+ /** >+ * Returns true if it is safe to delete the project. It is not safe to delete if >+ * one of its libraries is locked by a running launch configuration. >+ * >+ * @param project project to test >+ * @param monitor progress monitor >+ * @return true is it is safe to delete the project, false otherwise >+ */ > private boolean safeDeleteCheck(IProject project, IProgressMonitor monitor) { >- if (!fLaunchedConfigurations) >+ if (!fPluginsAreInUse) > return true; > IPluginModelBase base = PluginRegistry.findModel(project); > if (base != null) { >@@ -328,295 +402,254 @@ > } > > /** >- * Imports the contents of the plugin and adds links to the source location(s). >- * @param project destination project of the import >- * @param model model representing the plugin to import >- * @param monitor progress monitor >- * @throws CoreException if there is a problem completing the import >+ * Tests whether the required execution environment of the given plugin is supported by >+ * the current known JREs. If not, ask the user whether to continue. >+ * @param model the plug-in model to test >+ * @return true is the import should continue, false if the plug-in should be skipped >+ * @throws OperationCanceledException if the user chooses to cancel the operation > */ >- private void importAsBinaryWithLinks(IProject project, IPluginModelBase model, IProgressMonitor monitor) throws CoreException { >- if (isJARd(model)) { >- extractJARdPlugin(project, model, monitor); >- } else { >- File installLocation = new File(model.getInstallLocation()); >- File[] items = installLocation.listFiles(); >- if (items != null) { >- monitor.beginTask(PDEUIMessages.PluginImportOperation_linking, items.length + 1); >- for (int i = 0; i < items.length; i++) { >- File sourceFile = items[i]; >- String name = sourceFile.getName(); >- if (sourceFile.isDirectory()) { >- project.getFolder(name).createLink(new Path(sourceFile.getPath()), IResource.NONE, new SubProgressMonitor(monitor, 1)); >- } else { >- if (!name.equals(".project")) { //$NON-NLS-1$ >- project.getFile(name).createLink(new Path(sourceFile.getPath()), IResource.NONE, new SubProgressMonitor(monitor, 1)); >- } else { >- // if the binary project with links has a .project file, copy it instead of linking (allows us to edit it) >- ArrayList filesToImport = new ArrayList(1); >- filesToImport.add(sourceFile); >- importContent(installLocation, project.getFullPath(), FileSystemStructureProvider.INSTANCE, filesToImport, new SubProgressMonitor(monitor, 1)); >- } >- } >+ private boolean testExecutionEnvironment(IPluginModelBase model) throws OperationCanceledException { >+ BundleDescription desc = model.getBundleDescription(); >+ if (desc != null) { >+ IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager(); >+ String[] envs = desc.getExecutionEnvironments(); >+ boolean found = false; >+ for (int i = 0; i < envs.length; i++) { >+ if (manager.getEnvironment(envs[i]) != null) { >+ found = true; >+ break; >+ } >+ } >+ if (envs.length > 0 && !found) { >+ switch (fExecutionQuery.doQuery(NLS.bind(PDEUIMessages.PluginImportOperation_executionEnvironment, model.getPluginBase().getId(), envs[0]))) { >+ case IImportQuery.CANCEL : >+ throw new OperationCanceledException(); >+ case IImportQuery.NO : >+ return false; > } > } >- linkSourceArchives(project, model, new SubProgressMonitor(monitor, 1)); >- } >- try { >- RepositoryProvider.map(project, PDECore.BINARY_REPOSITORY_PROVIDER); >- } catch (TeamException e) { >- PDECore.logException(e); > } >+ return true; > } > > /** >- * Imports the contents of the plugin and imports source files as binary files that will not be compiled. >- * @param project destination project of the import >- * @param model model representing the plugin to import >- * @param markAsBinary whether to mark the project as a binary project >- * @param monitor progress monitor >- * @throws CoreException if there is a problem completing the import >+ * Returns true if the given plugin must be imported as >+ * binary instead of the setting defined by fImportType >+ * @param model >+ * @return true is the plugin must be imported as binary, false otherwise > */ >- private void importAsBinary(IProject project, IPluginModelBase model, boolean markAsBinary, IProgressMonitor monitor) throws CoreException { >- monitor.beginTask("", 4); //$NON-NLS-1$ >- if (isJARd(model)) { >- extractJARdPlugin(project, model, new SubProgressMonitor(monitor, 3)); >- } else { >- importContent(new File(model.getInstallLocation()), project.getFullPath(), FileSystemStructureProvider.INSTANCE, null, new SubProgressMonitor(monitor, 1)); >- importSourceArchives(project, model, new SubProgressMonitor(monitor, 1)); >+ private boolean isExempt(IPluginModelBase model) { >+ String id = model.getPluginBase().getId(); >+ if (fImportType == IMPORT_WITH_SOURCE) { >+ if ("org.apache.ant".equals(id) //$NON-NLS-1$ >+ || "org.eclipse.osgi.util".equals(id) //$NON-NLS-1$ >+ || "org.eclipse.osgi.services".equals(id) //$NON-NLS-1$ >+ || "org.eclipse.core.runtime.compatibility.registry".equals(id)) { //$NON-NLS-1$ >+ return true; >+ } >+ } >+ >+ if ("org.eclipse.swt".equals(id) && !isJARd(model)) //$NON-NLS-1$ >+ return true; >+ return false; >+ } > >- // make sure all libraries have been imported >- // if any are missing, check in fragments >- IFragment[] fragments = getFragmentsFor(model); >- IPluginLibrary[] libraries = model.getPluginBase().getLibraries(); >+ /** >+ * Starts a job that will build the workspace >+ */ >+ private void runBuildJob() { >+ Job buildJob = new Job(PDEUIMessages.CompilersConfigurationBlock_building) { >+ public boolean belongsTo(Object family) { >+ return ResourcesPlugin.FAMILY_AUTO_BUILD == family; >+ } > >- IProgressMonitor fragmentMonitor = new SubProgressMonitor(monitor, 1); >- fragmentMonitor.beginTask("", libraries.length); //$NON-NLS-1$ >- for (int i = 0; i < libraries.length; i++) { >- String libraryName = libraries[i].getName(); >- if (ClasspathUtilCore.containsVariables(libraryName) && !project.exists(new Path(ClasspathUtilCore.expandLibraryName(libraryName)))) { >- for (int j = 0; j < fragments.length; j++) { >- importJarFromFragment(project, fragments[j], libraryName); >- importSourceFromFragment(project, fragments[j], libraryName, new SubProgressMonitor(monitor, 1)); >- } >- } else { >- monitor.worked(1); >+ protected IStatus run(IProgressMonitor monitor) { >+ try { >+ PDEPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor); >+ } catch (CoreException e) { > } >+ return Status.OK_STATUS; > } >- } >- if (markAsBinary) { >- project.setPersistentProperty(PDECore.EXTERNAL_PROJECT_PROPERTY, PDECore.BINARY_PROJECT_VALUE); >- importAdditionalResources(project, model, new SubProgressMonitor(monitor, 1)); >- } else { >- monitor.done(); >- } >+ }; >+ buildJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule()); >+ buildJob.schedule(); > } > > /** >- * Imports the contents of the plugin and imports source files to source folders that will be compiled. >- * @param project destination project of the import >- * @param model model representing the plugin to import >+ * Imports the source archives required by the project either by copying or linking, based on the mode >+ * constant that is passed to the method (IMPORT_BINARY or IMPORT_BINARY_WITH_LINKS). >+ * @param project project destination >+ * @param model model we are importing >+ * @param mode either IMPORT_BINARY (copies source) or MPORT_BINARY_WITH_LINKS (links source) > * @param monitor progress monitor >- * @throws CoreException if there is a problem completing the import >+ * @return mapping of library name to the source location >+ * @throws CoreException if there are problems importing an archive > */ >- private void importAsSource(IProject project, IPluginModelBase model, SubProgressMonitor monitor) throws CoreException { >- monitor.beginTask("", 4); //$NON-NLS-1$ >- importAsBinary(project, model, false, new SubProgressMonitor(monitor, 2)); >- List list = importAdditionalResources(project, model, new SubProgressMonitor(monitor, 1)); >- WorkspaceBuildModel buildModel = new WorkspaceBuildModel(project.getFile("build.properties")); //$NON-NLS-1$ >- if (!isJARd(model) || containsCode(new File(model.getInstallLocation()))) { >- String[] libraries = getLibraryNames(model, false); >- if (libraries.length == 0) >- libraries = new String[] {"."}; //$NON-NLS-1$ >+ private Map importSourceArchives(IProject project, IPluginModelBase model, int mode, IProgressMonitor monitor) throws CoreException { >+ String[] libraries = getLibraryNames(model); >+ try { >+ monitor.beginTask(PDEUIMessages.ImportWizard_operation_importingSource, libraries.length); >+ >+ Map sourceMap = new HashMap(libraries.length); >+ SourceLocationManager manager = PDECore.getDefault().getSourceLocationManager(); > for (int i = 0; i < libraries.length; i++) { >- if (ClasspathUtilCore.containsVariables(libraries[i])) >- continue; >- String name = ClasspathUtilCore.expandLibraryName(libraries[i]); >- IPath libraryPath = (name.equals(".") && isJARd(model)) //$NON-NLS-1$ >- ? new Path(new File(model.getInstallLocation()).getName()) >- : new Path(name); >- IResource jarFile = project.findMember(libraryPath); >- if (jarFile != null) { >- String srcName = ClasspathUtilCore.getSourceZipName(libraryPath.lastSegment()); >- IResource srcZip = jarFile.getProject().findMember(srcName); >- if (srcZip == null) { >- int extIndex = srcName.lastIndexOf('.'); >- if (extIndex != -1) { >- srcZip = jarFile.getProject().findMember(srcName.substring(0, extIndex)); >- } >- } >- // srcZip == null if plug-in has embedded source >- // if it jarred, all necessary files already in src folder >- if (srcZip == null && libraries[i].equals(".") && !isJARd(model)) //$NON-NLS-1$ >- // if src does not exist (and returns null), then must not be plug-in with embedded source >- srcZip = jarFile.getProject().findMember("src"); //$NON-NLS-1$ >- if (srcZip != null) { >- String jarName = libraries[i].equals(".") ? "" : libraryPath.removeFileExtension().lastSegment(); //$NON-NLS-1$ //$NON-NLS-2$ >- String folder = addBuildEntry(buildModel, "source." + libraries[i], "src" + (jarName.length() == 0 ? "/" : "-" + jarName + "/")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ >- IFolder dest = jarFile.getProject().getFolder(folder); >- >- if (srcZip instanceof IFolder) { >- // if the source (srcZip) equals the destination folder (dest), then we don't want to delete/copy since every >- // is already where it needs to be. This happens when importing source bundles in folder format declaring source with ext. point. (bug 214542) >- if (!srcZip.equals(dest)) { >- if (dest.exists()) { >- dest.delete(true, null); >- } >- ((IFolder) srcZip).move(dest.getFullPath(), true, new SubProgressMonitor(monitor, 1)); >- } >- } else if (srcZip instanceof IFile) { >- if (!dest.exists()) { >- dest.create(true, true, null); >- } >- extractZipFile(srcZip.getLocation().toFile(), dest.getFullPath(), new SubProgressMonitor(monitor, 1)); >- srcZip.delete(true, null); >- } else >- monitor.worked(1); >- >- if (jarFile instanceof IFile) { >- if (isJARd(model)) { >- extractJavaResources(jarFile.getLocation().toFile(), dest, new SubProgressMonitor(monitor, 1)); >- } else { >- extractResources(jarFile.getLocation().toFile(), dest, new SubProgressMonitor(monitor, 1)); >- } >- jarFile.delete(true, null); >- } else { >- moveBinaryContents((IContainer) jarFile, dest, new SubProgressMonitor(monitor, 1)); >+ String zipName = ClasspathUtilCore.getSourceZipName(libraries[i]); >+ IPath srcPath = manager.findSourcePath(model.getPluginBase(), new Path(zipName)); >+ if (srcPath != null) { >+ zipName = srcPath.lastSegment(); >+ IPath dstPath = new Path(zipName); >+ sourceMap.put(libraries[i], dstPath); >+ if (project.findMember(dstPath) == null) { >+ if (mode == IMPORT_BINARY) { >+ PluginImportHelper.copyArchive(new File(srcPath.toOSString()), project.getFile(dstPath), new SubProgressMonitor(monitor, 1)); >+ } else if (mode == IMPORT_BINARY_WITH_LINKS) { >+ IFile dstFile = project.getFile(dstPath); >+ dstFile.createLink(srcPath, IResource.NONE, new SubProgressMonitor(monitor, 1)); > } > } >- } else if (name.equals(".") && project.getFolder("src").exists()) { //$NON-NLS-1$ //$NON-NLS-2$ >- addBuildEntry(buildModel, "source..", "src/"); //$NON-NLS-1$ //$NON-NLS-2$ > } > } >+ return sourceMap; >+ } finally { >+ monitor.done(); > } >- configureBinIncludes(buildModel, model, project); >- if (list.size() > 0) >- configureSrcIncludes(buildModel, list); >- buildModel.save(); > } > > /** >- * Moves the binary files from the source container to the folder destination. >- * Moves any file that isn't a .class file >- * @param srcFolder container to move from >- * @param dest folder to move to >+ * Looks up the source locations for the plug-in and imports the source for each library. Each source root is >+ * extracted to a source folder in the project and a build model containing the source entries is returned. >+ * >+ * @param project destination project >+ * @param model plug-in being imported > * @param monitor progress monitor >+ * @return a workspace build model containing entries for each created source folder >+ * @throws CoreException if there is a problem extracting the source or creating a build entry > */ >- private void moveBinaryContents(IContainer srcFolder, IFolder dest, IProgressMonitor monitor) { >+ private WorkspaceBuildModel extractSourceFolders(IProject project, IPluginModelBase model, IProgressMonitor monitor) throws CoreException { > try { >- // get all the folders for which we want to search >- IResource[] children = dest.members(); >- ArrayList validFolders = new ArrayList(); >- for (int i = 0; i < children.length; i++) >- if (children[i] instanceof IFolder) { >- String folderName = children[i].getName(); >- IResource folder = srcFolder.findMember(folderName); >- if (folder != null && folder instanceof IFolder) >- validFolders.add(folder); >- } >+ String[] libraries = getLibraryNames(model); >+ monitor.beginTask(PDEUIMessages.ImportWizard_operation_importingSource, libraries.length); > >- monitor.beginTask(new String(), validFolders.size()); >+ WorkspaceBuildModel buildModel = new WorkspaceBuildModel(project.getFile("build.properties")); //$NON-NLS-1$ >+ SourceLocationManager manager = PDECore.getDefault().getSourceLocationManager(); > >- ListIterator li = validFolders.listIterator(); >- while (li.hasNext()) { >- IFolder folder = (IFolder) li.next(); >- int pathSegments = folder.getProjectRelativePath().segmentCount() - 1; >- Stack stack = new Stack(); >- IResource[] resources = folder.members(); >- for (int i = 0; i < resources.length; i++) >- stack.push(resources[i]); >- >- while (!stack.isEmpty()) { >- IResource res = (IResource) stack.pop(); >- if (res instanceof IFile) { >- if (!res.getName().endsWith(".class")) { //$NON-NLS-1$ >- String pathName = res.getProjectRelativePath().removeFirstSegments(pathSegments).toString(); >- IFile destFile = dest.getFile(pathName); >- if (!destFile.getParent().exists()) { >- CoreUtility.createFolder((IFolder) destFile.getParent()); >+ // Need to do different things based on whether we have a individual source bundle or the old style separated zips >+ if (manager.hasBundleManifestLocation(model.getPluginBase())) { >+ File srcFile = manager.findSourcePlugin(model.getPluginBase()); >+ Set sourceRoots = manager.findSourceRoots(model.getPluginBase()); >+ for (int i = 0; i < libraries.length; i++) { >+ if (libraries[i].equals(DEFAULT_LIBRARY_NAME)) { >+ // Need to pull out any java source that is not in another source root >+ IResource destination = project.getFolder(DEFAULT_SOURCE_DIR); >+ if (!destination.exists()) { >+ List excludeFolders = new ArrayList(sourceRoots.size()); >+ for (Iterator iterator = sourceRoots.iterator(); iterator.hasNext();) { >+ String root = (String) iterator.next(); >+ if (!root.equals(DEFAULT_LIBRARY_NAME)) { >+ excludeFolders.add(new Path(root)); >+ } > } >- // file might exist if previous project was deleted without removing underlying resources >- if (destFile.exists()) >- destFile.delete(true, null); >- res.move(destFile.getFullPath(), true, null); >+ PluginImportHelper.extractJavaSourceFromArchive(srcFile, excludeFolders, destination.getFullPath(), new SubProgressMonitor(monitor, 1)); >+ addBuildEntry(buildModel, "source." + DEFAULT_LIBRARY_NAME, DEFAULT_SOURCE_DIR + "/"); //$NON-NLS-1$ //$NON-NLS-2$ >+ } >+ } else if (sourceRoots.contains(getSourceDirName(libraries[i]))) { >+ IPath sourceDir = new Path(getSourceDirName(libraries[i])); >+ IResource destination = project.getFolder(sourceDir); >+ if (!destination.exists()) { >+ PluginImportHelper.extractFolderFromArchive(srcFile, sourceDir, destination.getFullPath(), new SubProgressMonitor(monitor, 1)); >+ addBuildEntry(buildModel, "source." + libraries[i], sourceDir.toString()); //$NON-NLS-1$ >+ } >+ } >+ } >+ } else { >+ // Old style, zips in folders, determine the source zip name/location and extract it to the project >+ for (int i = 0; i < libraries.length; i++) { >+ String zipName = ClasspathUtilCore.getSourceZipName(libraries[i]); >+ IPath srcPath = manager.findSourcePath(model.getPluginBase(), new Path(zipName)); >+ if (srcPath != null) { >+ IPath dstPath = new Path(getSourceDirName(libraries[i])); >+ IResource destination = project.getFolder(dstPath); >+ if (!destination.exists()) { >+ PluginImportHelper.extractArchive(new File(srcPath.toOSString()), destination.getFullPath(), new SubProgressMonitor(monitor, 1)); >+ addBuildEntry(buildModel, "source." + libraries[i], dstPath.toString()); //$NON-NLS-1$ > } >- } else { >- resources = ((IFolder) res).members(); >- for (int i = 0; i < resources.length; i++) >- stack.push(resources[i]); > } > } >- folder.delete(true, null); >- monitor.worked(1); > } >- } catch (CoreException e) { >+ return buildModel; >+ } finally { >+ monitor.done(); > } > } > > /** >- * Searches source locations for files to import to the new project, will ignore >- * src.zip. >- * @param project destination project of the import >- * @param model model representing the plugin to import >+ * Extracts any additional files and folders that exist in the source location >+ * @param project the destination project >+ * @param model the plugin being imported > * @param monitor progress monitor >- * @return list of imported files >- * @throws CoreException if there is a problem completing the import >+ * @throws CoreException is there is a problem importing the files > */ >- private List importAdditionalResources(IProject project, IPluginModelBase model, SubProgressMonitor monitor) throws CoreException { >- SourceLocationManager manager = PDECore.getDefault().getSourceLocationManager(); >- File location = manager.findSourcePlugin(model.getPluginBase()); >- if (location != null) { >- ArrayList list = new ArrayList(); >- if (location.isDirectory()) { >- Object root = location; >- File[] children = location.listFiles(); >- if (children != null) { >- for (int i = 0; i < children.length; i++) { >- String name = children[i].getName(); >- if (!project.exists(new Path(name)) && !"src.zip".equals(name)) { //$NON-NLS-1$ >- list.add(children[i]); >- } >- } >- importContent(root, project.getFullPath(), FileSystemStructureProvider.INSTANCE, list, monitor); >- ArrayList srcEntryList = new ArrayList(list.size()); >- for (ListIterator iterator = list.listIterator(); iterator.hasNext();) { >- File current = (File) iterator.next(); >- String entry = current.getName(); >- if (current.isDirectory()) { >- entry += "/"; //$NON-NLS-1$ >- } >- srcEntryList.add(entry); >- } >- return srcEntryList; >- } >- } else if (location.isFile()) { >- ZipFile zipFile = null; >+ private void importAdditionalSourceFiles(IProject project, IPluginModelBase model, SubProgressMonitor monitor) throws CoreException { >+ File sourceLocation = PDECore.getDefault().getSourceLocationManager().findSourcePlugin(model.getPluginBase()); >+ if (sourceLocation != null) { >+ if (sourceLocation.isFile()) { >+ ArrayList collected = new ArrayList(); >+ ZipFileStructureProvider provider = null; > try { >- zipFile = new ZipFile(location); >- ZipFileStructureProvider zipProvider = new ZipFileStructureProvider(zipFile); >- Object root = zipProvider.getRoot(); >- collectAdditionalResources(zipProvider, root, list, project); >- importContent(root, project.getFullPath(), zipProvider, list, monitor); >- ArrayList srcEntryList = new ArrayList(list.size()); >- for (Iterator iterator = list.iterator(); iterator.hasNext();) { >- ZipEntry current = (ZipEntry) iterator.next(); >- String entry = current.getName(); >- srcEntryList.add(entry); >- } >- return srcEntryList; >+ provider = new ZipFileStructureProvider(new ZipFile(sourceLocation)); > } catch (IOException e) { > IStatus status = new Status(IStatus.ERROR, PDEPlugin.getPluginId(), IStatus.ERROR, e.getMessage(), e); > throw new CoreException(status); >- } finally { >- if (zipFile != null) { >- try { >- zipFile.close(); >- } catch (IOException e) { >- } >- } > } >+ PluginImportHelper.collectNonJavaFiles(provider, provider.getRoot(), collected); >+ PluginImportHelper.importContent(provider.getRoot(), project.getFullPath(), provider, collected, monitor); >+ } else { >+ // TODO Test how to do directories >+ ArrayList collected = new ArrayList(); >+ PluginImportHelper.collectNonJavaFiles(FileSystemStructureProvider.INSTANCE, sourceLocation, collected); >+ PluginImportHelper.importContent(sourceLocation, project.getFullPath(), FileSystemStructureProvider.INSTANCE, collected, monitor); > } > } >- return new ArrayList(0); >+ } >+ >+ /** >+ * Imports files from the plug-in that are necessary to make the created project a plug-in project. >+ * Specifically the manifest and related file are extracted. >+ * @param project >+ * @param model >+ * @param monitor >+ * @throws CoreException if there is a problem importing the content >+ */ >+ private void importRequiredPluginFiles(IProject project, IPluginModelBase model, IProgressMonitor monitor) throws CoreException { >+ if (isJARd(model)) { >+ ArrayList collected = new ArrayList(); >+ ZipFileStructureProvider provider = null; >+ try { >+ provider = new ZipFileStructureProvider(new ZipFile(new File(model.getInstallLocation()))); >+ } catch (IOException e) { >+ IStatus status = new Status(IStatus.ERROR, PDEPlugin.getPluginId(), IStatus.ERROR, e.getMessage(), e); >+ throw new CoreException(status); >+ } >+ PluginImportHelper.collectRequiredBundleFiles(provider, provider.getRoot(), collected); >+ PluginImportHelper.importContent(provider.getRoot(), project.getFullPath(), provider, collected, monitor); >+ } else { >+ ArrayList collected = new ArrayList(); >+ File file = new File(model.getInstallLocation()); >+ PluginImportHelper.collectRequiredBundleFiles(FileSystemStructureProvider.INSTANCE, file, collected); >+ PluginImportHelper.importContent(file, project.getFullPath(), FileSystemStructureProvider.INSTANCE, collected, monitor); >+ } >+ } >+ >+ private String addBuildEntry(WorkspaceBuildModel model, String key, String value) throws CoreException { >+ IBuild build = model.getBuild(true); >+ IBuildEntry entry = build.getEntry(key); >+ if (entry == null) { >+ entry = model.getFactory().createEntry(key); >+ entry.addToken(value); >+ build.add(entry); >+ } >+ String[] tokens = entry.getTokens(); >+ return (tokens.length > 0) ? tokens[0] : "src/"; //$NON-NLS-1$ > } > > private void configureBinIncludes(WorkspaceBuildModel buildModel, IPluginModelBase model, IProject project) throws CoreException { >@@ -640,7 +673,7 @@ > entry.addToken(token); > } > } else { >- String[] tokens = getTopLevelResources(location); >+ String[] tokens = PluginImportHelper.getTopLevelResources(location); > for (int i = 0; i < tokens.length; i++) { > IResource res = project.findMember(tokens[i]); > if ((res == null) && (build.getEntry(IBuildEntry.JAR_PREFIX + tokens[i]) == null)) >@@ -670,213 +703,13 @@ > return set; > } > >- private void configureSrcIncludes(WorkspaceBuildModel buildModel, List list) throws CoreException { >- IBuildEntry entry = buildModel.getBuild(true).getEntry("src.includes"); //$NON-NLS-1$ >- if (entry == null) { >- entry = buildModel.getFactory().createEntry("src.includes"); //$NON-NLS-1$ >- for (int i = 0; i < list.size(); i++) { >- entry.addToken(list.get(i).toString()); >- } >- buildModel.getBuild().add(entry); >- } >- } >- >- private String addBuildEntry(WorkspaceBuildModel model, String key, String value) throws CoreException { >- IBuild build = model.getBuild(true); >- IBuildEntry entry = build.getEntry(key); >- if (entry == null) { >- entry = model.getFactory().createEntry(key); >- entry.addToken(value); >- build.add(entry); >- } >- String[] tokens = entry.getTokens(); >- return (tokens.length > 0) ? tokens[0] : "src/"; //$NON-NLS-1$ >- } >- >- /** >- * Creates links in the project to the source locations for the various libraries. >- * If the source for all libraries is in a single bundle, one link is created >- * @param project destination project of the import >- * @param model model representing the plugin to import >- * @param monitor progress monitor >- * @throws CoreException if there is a problem completing the import >- */ >- private void linkSourceArchives(IProject project, IPluginModelBase model, IProgressMonitor monitor) throws CoreException { >- String[] libraries = getLibraryNames(model, true); >- monitor.beginTask(PDEUIMessages.ImportWizard_operation_copyingSource, libraries.length); >- >- SourceLocationManager manager = PDECore.getDefault().getSourceLocationManager(); >- if (manager.hasBundleManifestLocation(model.getPluginBase())) { >- IPath srcPath = manager.findSourcePath(model.getPluginBase(), null); >- if (srcPath != null) { >- // Source for all libraries is in the same bundle, just create one link to the source bundle >- IPath path = new Path(project.getName() + "src.zip"); //$NON-NLS-1$ >- IFile srcFile = project.getFile(path.lastSegment()); >- if (!srcFile.exists()) { >- srcFile.createLink(srcPath, IResource.NONE, new SubProgressMonitor(monitor, 1)); >- } >- } >- monitor.worked(libraries.length); >- } else { >- for (int i = 0; i < libraries.length; i++) { >- String zipName = ClasspathUtilCore.getSourceZipName(libraries[i]); >- IPath path = new Path(zipName); >- if (project.findMember(path) == null) { >- IPath srcPath = manager.findSourcePath(model.getPluginBase(), path); >- if (srcPath != null) { >- if ("src.zip".equals(zipName) && isJARd(model)) { //$NON-NLS-1$ >- path = new Path(ClasspathUtilCore.getSourceZipName(new File(model.getInstallLocation()).getName())); >- } >- IFile zipFile = project.getFile(path.lastSegment()); >- if (!zipFile.exists()) { >- zipFile.createLink(srcPath, IResource.NONE, new SubProgressMonitor(monitor, 1)); >- } >- } >- } >- monitor.worked(1); >- } >- } >- monitor.done(); >- } >- >- private void importSourceArchives(IProject project, IPluginModelBase model, IProgressMonitor monitor) throws CoreException { >- String[] libraries = getLibraryNames(model, true); >- monitor.beginTask(PDEUIMessages.ImportWizard_operation_copyingSource, libraries.length); >- >- SourceLocationManager manager = PDECore.getDefault().getSourceLocationManager(); >- >- Set roots = null; >- if (manager.hasBundleManifestLocation(model.getPluginBase())) >- roots = manager.findSourceRoots(model.getPluginBase()); >- >- for (int i = 0; i < libraries.length; i++) { >- String zipName = ClasspathUtilCore.getSourceZipName(libraries[i]); >- IPath path = new Path(zipName); >- if (project.findMember(path) == null) { >- // if we are importing the source through a sourceBundle header... >- if (roots != null) { >- IPath sourceLocation = manager.findSourcePath(model.getPluginBase(), null); >- String currentRoot = ".".equals(libraries[i]) ? "." : path.removeFileExtension().toString(); //$NON-NLS-1$ //$NON-NLS-2$ >- if (roots.contains(currentRoot)) { >- if (".".equals(currentRoot)) { //$NON-NLS-1$ >- // Save to a special folder name based on the install location >- IPath sourceName = getDefaultSourceNameForProject(model); >- sourceName = sourceName.removeFileExtension(); >- IFolder dest = project.getFolder(sourceName); >- if (!dest.exists()) { >- dest.create(true, true, null); >- } >- >- // List all of the other source roots so they are not included when importing source from the root, ".", of the jar >- Set allBundleRoots = manager.findAllSourceRootsInSourceLocation(model.getPluginBase()); >- List rootsToExclude = new ArrayList(allBundleRoots.size() - 1); >- for (Iterator iterator2 = allBundleRoots.iterator(); iterator2.hasNext();) { >- String rootString = (String) iterator2.next(); >- if (!".".equals(rootString)) { //$NON-NLS-1$ >- rootsToExclude.add(new Path(rootString)); >- } >- } >- >- // Extract folders containing java source >- extractJavaSource(new File(sourceLocation.toOSString()), rootsToExclude, dest, monitor); >- } else { >- // Extract the specific library from it's folder >- extractResourcesFromFolder(new File(sourceLocation.toOSString()), new Path(currentRoot), project, monitor); >- } >- } >- } else { >- IPath srcPath = manager.findSourcePath(model.getPluginBase(), path); >- if (srcPath != null) { >- if ("src.zip".equals(zipName) && isJARd(model)) { //$NON-NLS-1$ >- path = getDefaultSourceNameForProject(model); >- } >- importArchive(project, new File(srcPath.toOSString()), path); >- } >- } >- } >- monitor.worked(1); >- } >- monitor.done(); >- } >- > /** >- * Creates a path representing a zip file that is named based on the plugin install location. >- * Used to replace src.zip with a more unique and meaningful name. >- * @param model model that the src.zip containg source for >- * @return a new path describing the zip file >+ * Creates a model for an existing manifest file, replacing the classpath entry with the >+ * new location of the referenced library. Also removes any extra entries such as signing >+ * headers. >+ * @param project >+ * @param base > */ >- private IPath getDefaultSourceNameForProject(IPluginModelBase model) { >- return new Path(ClasspathUtilCore.getSourceZipName(new File(model.getInstallLocation()).getName())); >- } >- >- private String[] getLibraryNames(IPluginModelBase model, boolean expand) { >- IPluginLibrary[] libraries = model.getPluginBase().getLibraries(); >- ArrayList list = new ArrayList(); >- for (int i = 0; i < libraries.length; i++) { >- if (expand) >- list.add(ClasspathUtilCore.expandLibraryName(libraries[i].getName())); >- else >- list.add(libraries[i].getName()); >- } >- if (libraries.length == 0 && isJARd(model)) >- list.add("."); //$NON-NLS-1$ >- return (String[]) list.toArray(new String[list.size()]); >- } >- >- private void extractJARdPlugin(IProject project, IPluginModelBase model, IProgressMonitor monitor) throws CoreException { >- ZipFile zipFile = null; >- try { >- zipFile = new ZipFile(model.getInstallLocation()); >- ZipFileStructureProvider provider = new ZipFileStructureProvider(zipFile); >- if (!containsCode(provider)) { >- extractZipFile(new File(model.getInstallLocation()), project.getFullPath(), monitor); >- return; >- } >- ArrayList collected = new ArrayList(); >- collectNonJavaResources(provider, provider.getRoot(), collected); >- importContent(provider.getRoot(), project.getFullPath(), provider, collected, monitor); >- >- File file = new File(model.getInstallLocation()); >- if (hasEmbeddedSource(provider) && fImportType == IMPORT_WITH_SOURCE) { >- collected = new ArrayList(); >- collectJavaFiles(provider, provider.getRoot(), collected); >- importContent(provider.getRoot(), project.getFullPath(), provider, collected, monitor); >- collected = new ArrayList(); >- collectJavaResources(provider, provider.getRoot(), collected); >- importContent(provider.getRoot(), project.getFullPath().append("src"), provider, collected, monitor); //$NON-NLS-1$ >- } else { >- if (fImportType == IMPORT_BINARY_WITH_LINKS) { >- project.getFile(file.getName()).createLink(new Path(file.getAbsolutePath()), IResource.NONE, null); >- } else { >- importArchive(project, file, new Path(file.getName())); >- } >- if (!hasEmbeddedSource(provider)) { >- if (fImportType == IMPORT_BINARY_WITH_LINKS) { >- linkSourceArchives(project, model, new SubProgressMonitor(monitor, 1)); >- } else { >- importSourceArchives(project, model, new SubProgressMonitor(monitor, 1)); >- } >- } >- } >- if (fImportType != IMPORT_WITH_SOURCE) { >- modifyBundleClasspathHeader(project, model); >- } else { >- removeSignedHeaders(project); >- } >- setPermissions(model, project); >- } catch (IOException e) { >- IStatus status = new Status(IStatus.ERROR, PDEPlugin.getPluginId(), IStatus.ERROR, e.getMessage(), e); >- throw new CoreException(status); >- } finally { >- if (zipFile != null) { >- try { >- zipFile.close(); >- } catch (IOException e) { >- } >- } >- } >- } >- > private void modifyBundleClasspathHeader(IProject project, IPluginModelBase base) { > IFile file = project.getFile(JarFile.MANIFEST_NAME); > if (file.exists()) { >@@ -908,52 +741,6 @@ > } > } > >- private void removeSignedHeaders(IProject project) { >- IFile file = project.getFile(JarFile.MANIFEST_NAME); >- if (!file.exists()) >- return; >- WorkspaceBundleModel model = new WorkspaceBundleModel(file); >- model.save(); >- } >- >- private IProject findProject(String id) { >- IPluginModelBase model = PluginRegistry.findModel(id); >- if (model != null) { >- IResource resource = model.getUnderlyingResource(); >- if (resource != null) >- return resource.getProject(); >- } >- return PDEPlugin.getWorkspace().getRoot().getProject(id); >- } >- >- private boolean queryReplace(IProject project) throws OperationCanceledException { >- switch (fReplaceQuery.doQuery(NLS.bind(PDEUIMessages.ImportWizard_messages_exists, project.getName()))) { >- case IImportQuery.CANCEL : >- throw new OperationCanceledException(); >- case IImportQuery.NO : >- return false; >- } >- return true; >- } >- >- private boolean queryExecutionEnvironment(String message) throws OperationCanceledException { >- switch (fExecutionQuery.doQuery(message)) { >- case IImportQuery.CANCEL : >- throw new OperationCanceledException(); >- case IImportQuery.NO : >- return false; >- } >- return true; >- } >- >- private void setProjectDescription(IProject project, IPluginModelBase model) throws CoreException { >- IProjectDescription desc = project.getDescription(); >- if (!desc.hasNature(PDE.PLUGIN_NATURE)) >- CoreUtility.addNatureToProject(project, PDE.PLUGIN_NATURE, null); >- if (needsJavaNature(project, model) && !desc.hasNature(JavaCore.NATURE_ID)) >- CoreUtility.addNatureToProject(project, JavaCore.NATURE_ID, null); >- } >- > private boolean needsJavaNature(IProject project, IPluginModelBase model) { > if (model.getPluginBase().getLibraries().length > 0) > return true; >@@ -970,131 +757,50 @@ > return false; > } > >- private boolean isExempt(IPluginModelBase model) { >- String id = model.getPluginBase().getId(); >- if ("org.apache.ant".equals(id) //$NON-NLS-1$ >- || "org.eclipse.osgi.util".equals(id) //$NON-NLS-1$ >- || "org.eclipse.osgi.services".equals(id) //$NON-NLS-1$ >- || "org.eclipse.core.runtime.compatibility.registry".equals(id)) //$NON-NLS-1$ >- return true; >- >- if ("org.eclipse.swt".equals(id) && !isJARd(model)) //$NON-NLS-1$ >- return true; >- return false; >- } >- >- private boolean isJARd(IPluginModelBase model) { >- return new File(model.getInstallLocation()).isFile(); >- } >- >- private void setPermissions(IPluginModelBase model, IProject project) { >- try { >- if (!Platform.getOS().equals(Constants.OS_WIN32) && model instanceof IFragmentModel) { >- IFragment fragment = ((IFragmentModel) model).getFragment(); >- if ("org.eclipse.swt".equals(fragment.getPluginId())) { //$NON-NLS-1$ >- IResource[] children = project.members(); >- for (int i = 0; i < children.length; i++) { >- if (children[i] instanceof IFile && isInterestingResource(children[i].getName())) { >- Runtime.getRuntime().exec(new String[] {"chmod", "755", children[i].getLocation().toOSString()}).waitFor(); //$NON-NLS-1$ //$NON-NLS-2$ >- } >- } >- } >- } >- } catch (CoreException e) { >- } catch (InterruptedException e) { >- } catch (IOException e) { >- } >- } >- >- private boolean isInterestingResource(String name) { >- return name.endsWith(".jnilib") //$NON-NLS-1$ >- || name.endsWith(".sl") //$NON-NLS-1$ >- || name.endsWith(".a") //$NON-NLS-1$ >- || name.indexOf(".so") != -1; //$NON-NLS-1$ >- } >- >- private IFragment[] getFragmentsFor(IPluginModelBase model) { >- ArrayList result = new ArrayList(); >- for (int i = 0; i < fModels.length; i++) { >- if (fModels[i] instanceof IFragmentModel) { >- HostSpecification spec = fModels[i].getBundleDescription().getHost(); >- BundleDescription host = spec == null ? null : (BundleDescription) spec.getSupplier(); >- if (model.getBundleDescription().equals(host)) { >- result.add(((IFragmentModel) fModels[i]).getFragment()); >- } >- } >- } >- return (IFragment[]) result.toArray(new IFragment[result.size()]); >- } >- >- private void importJarFromFragment(IProject project, IFragment fragment, String name) throws CoreException { >- IPath jarPath = new Path(ClasspathUtilCore.expandLibraryName(name)); >- File jar = new File(fragment.getModel().getInstallLocation(), jarPath.toString()); >- if (jar.exists()) { >- importArchive(project, jar, jarPath); >- } >+ private void setProjectNatures(IProject project, IPluginModelBase model) throws CoreException { >+ IProjectDescription desc = project.getDescription(); >+ if (!desc.hasNature(PDE.PLUGIN_NATURE)) >+ CoreUtility.addNatureToProject(project, PDE.PLUGIN_NATURE, null); >+ if (needsJavaNature(project, model) && !desc.hasNature(JavaCore.NATURE_ID)) >+ CoreUtility.addNatureToProject(project, JavaCore.NATURE_ID, null); > } > > /** >- * Imports the source for a library from a fragment. >- * @param project destination project of the import >- * @param fragment fragment to import the library from >- * @param libraryName name of the library to import, >- * @param monitor progress monitor >- * @throws CoreException if there is a problem completing the import >+ * Gets the list of libraries from the model and returns an array of their expanded >+ * names. Will add the default library name if no libraries are specified. >+ * @param model >+ * @return list of library names > */ >- private void importSourceFromFragment(IProject project, IFragment fragment, String libraryName, IProgressMonitor monitor) throws CoreException { >- try { >- IPath jarPath = new Path(ClasspathUtilCore.expandLibraryName(libraryName)); >- String zipName = ClasspathUtilCore.getSourceZipName(jarPath.toString()); >- IPath path = new Path(zipName); >- if (project.findMember(path) == null) { >- SourceLocationManager manager = PDECore.getDefault().getSourceLocationManager(); >- IPath srcPath = manager.findSourcePath(fragment, path); >- if (srcPath != null) { >- if (manager.hasBundleManifestLocation(fragment)) { >- // Extract the specific library from it's folder >- extractResourcesFromFolder(new File(srcPath.toOSString()), path.removeFileExtension(), project, monitor); >- } else { >- importArchive(project, new File(srcPath.toOSString()), path); >- } >- } >- } >- } finally { >- monitor.done(); >- } >- } >- >- protected void collectAdditionalResources(ZipFileStructureProvider provider, Object element, ArrayList collected, IProject project) { >- collectAdditionalResources(provider, element, collected); >- ListIterator li = collected.listIterator(); >- while (li.hasNext()) { >- ZipEntry ze = (ZipEntry) li.next(); >- String name = ze.getName(); >- // only import the entries that don't already exist >- if (project.findMember(name) != null) { >- li.remove(); >- } >+ private String[] getLibraryNames(IPluginModelBase model) { >+ IPluginLibrary[] libraries = model.getPluginBase().getLibraries(); >+ ArrayList list = new ArrayList(); >+ for (int i = 0; i < libraries.length; i++) { >+ list.add(ClasspathUtilCore.expandLibraryName(libraries[i].getName())); > } >+ if (libraries.length == 0 && isJARd(model)) >+ list.add(DEFAULT_LIBRARY_NAME); >+ return (String[]) list.toArray(new String[list.size()]); > } > >- protected void collectNonJavaResources(ZipFileStructureProvider provider, Object element, ArrayList collected) { >- super.collectNonJavaResources(provider, element, collected); >- if (fImportType != IMPORT_WITH_SOURCE) >- return; >- // filter the resources we get back to include only relevant resource files >- ListIterator li = collected.listIterator(); >- while (li.hasNext()) { >- ZipEntry ze = (ZipEntry) li.next(); >- String name = ze.getName(); >- // filter out signature files - bug 175756 >- if (name.startsWith("META-INF/") && (name.endsWith(".RSA") || name.endsWith(".DSA") || name.endsWith(".SF"))) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ >- li.remove(); >- } >+ /** >+ * Returns the standard source directory name for a library name. >+ * Used to get the source root name for a library as well as the >+ * standard destination name. >+ * @param libraryName >+ * @return source dir name >+ */ >+ private String getSourceDirName(String libraryName) { >+ int dot = libraryName.lastIndexOf('.'); >+ return (dot != -1) ? libraryName.substring(0, dot) + DEFAULT_SOURCE_DIR : libraryName; > } > >- public void setLaunchedConfiguration(boolean launchedConfiguration) { >- fLaunchedConfigurations = launchedConfiguration; >+ /** >+ * Returns whether the install location of the plug-in is a jar file or a folder >+ * @param model >+ * @return true if the install location is a jar, false if it is a folder >+ */ >+ private boolean isJARd(IPluginModelBase model) { >+ return new File(model.getInstallLocation()).isFile(); > } > > } >Index: src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportWizardDetailedPage.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportWizardDetailedPage.java,v >retrieving revision 1.90 >diff -u -r1.90 PluginImportWizardDetailedPage.java >--- src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportWizardDetailedPage.java 4 Nov 2008 15:14:24 -0000 1.90 >+++ src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportWizardDetailedPage.java 14 Nov 2008 22:28:56 -0000 >@@ -21,10 +21,10 @@ > import org.eclipse.jface.dialogs.IDialogSettings; > import org.eclipse.jface.layout.GridLayoutFactory; > import org.eclipse.jface.viewers.*; >+import org.eclipse.osgi.service.resolver.BundleDescription; > import org.eclipse.osgi.util.NLS; > import org.eclipse.pde.core.plugin.IPluginModelBase; >-import org.eclipse.pde.internal.core.PDECore; >-import org.eclipse.pde.internal.core.WorkspaceModelManager; >+import org.eclipse.pde.internal.core.*; > import org.eclipse.pde.internal.core.plugin.AbstractPluginModelBase; > import org.eclipse.pde.internal.core.util.PatternConstructor; > import org.eclipse.pde.internal.ui.*; >@@ -53,7 +53,8 @@ > private TableViewer fAvailableListViewer; > private Text fFilterText; > private VersionFilter fVersionFilter; >- private AvailableFilter fFilter; >+ private AvailableFilter fAvailableFilter; >+ private SourcePluginFilter fSourceFilter; > // fSelected is used to track the selection in a hash set so we can efficiently > // filter selected items out of the available item list > private Set fSelected; >@@ -65,8 +66,10 @@ > private Button fRemoveAllButton; > private Button fAddRequiredButton; > private Button fFilterOldVersionButton; >+ private Button fFilterSourcePluginsButton; > > private static final String SETTINGS_SHOW_LATEST = "showLatestPluginsOnly"; //$NON-NLS-1$ >+ private static final String SETTINGS_SHOW_SOURCE = "showSourcePlugins"; //$NON-NLS-1$ > > private class AvailableFilter extends ViewerFilter { > private Pattern fPattern; >@@ -131,7 +134,28 @@ > return true; > return hVersion.equals(plugin.getBundleDescription().getVersion()); > } >+ } > >+ /** >+ * This filter is used to remove source plug-ins from view >+ * >+ */ >+ private class SourcePluginFilter extends ViewerFilter { >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) >+ */ >+ public boolean select(Viewer viewer, Object parentElement, Object element) { >+ if (element instanceof IPluginModelBase) { >+ PDEState state = fPage1.getState(); >+ if (state != null) { >+ BundleDescription description = ((IPluginModelBase) element).getBundleDescription(); >+ if (description != null) { >+ return state.getBundleSourceEntry(description.getBundleId()) == null; >+ } >+ } >+ } >+ return true; >+ } > } > > public PluginImportWizardDetailedPage(String pageName, PluginImportWizardFirstPage firstPage) { >@@ -160,10 +184,10 @@ > Composite buttonContainer = new Composite(container, SWT.NONE); > buttonContainer.setLayout(GridLayoutFactory.fillDefaults().create()); > createComputationsOption(buttonContainer, 3); >- createFilterOption(buttonContainer, 3); >+ createFilterOptions(buttonContainer, 3); > > addViewerListeners(); >- addFilter(); >+ addFilters(); > > initialize(); > setControl(container); >@@ -171,7 +195,7 @@ > PlatformUI.getWorkbench().getHelpSystem().setHelp(container, IHelpContextIds.PLUGIN_IMPORT_SECOND_PAGE); > } > >- private void createFilterOption(Composite container, int span) { >+ private void createFilterOptions(Composite container, int span) { > Composite parent = new Composite(container, SWT.NONE); > parent.setLayout(GridLayoutFactory.swtDefaults().margins(5, 0).create()); > fFilterOldVersionButton = new Button(parent, SWT.CHECK); >@@ -188,24 +212,49 @@ > > fFilterOldVersionButton.addSelectionListener(new SelectionAdapter() { > public void widgetSelected(SelectionEvent e) { >- fAvailableListViewer.removeFilter(fVersionFilter); > if (fFilterOldVersionButton.getSelection()) { > fAvailableListViewer.addFilter(fVersionFilter); >+ } else { >+ fAvailableListViewer.removeFilter(fVersionFilter); > } >- fAvailableListViewer.getTable().setRedraw(false); >- fAvailableListViewer.refresh(); >- fAvailableListViewer.getTable().setRedraw(true); > } >+ }); > >+ fFilterSourcePluginsButton = new Button(parent, SWT.CHECK); >+ // TODO NLS this string, not done so related patches won't conflict >+ fFilterSourcePluginsButton.setText("Show source plug-ins"); >+ gData = new GridData(GridData.FILL_HORIZONTAL); >+ gData.horizontalSpan = span; >+ fFilterSourcePluginsButton.setLayoutData(gData); >+ >+ if (getDialogSettings().get(SETTINGS_SHOW_SOURCE) != null) { >+ fFilterSourcePluginsButton.setSelection(getDialogSettings().getBoolean(SETTINGS_SHOW_SOURCE)); >+ } else { >+ fFilterSourcePluginsButton.setSelection(false); >+ } >+ >+ fFilterSourcePluginsButton.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ if (fFilterSourcePluginsButton.getSelection()) { >+ fAvailableListViewer.removeFilter(fSourceFilter); >+ } else { >+ fAvailableListViewer.addFilter(fSourceFilter); >+ } >+ } > }); > } > >- private void addFilter() { >+ private void addFilters() { > fVersionFilter = new VersionFilter(); > fVersionFilter.setModel(fModels); >- fFilter = new AvailableFilter(); >- fAvailableListViewer.addFilter(fFilter); >+ fAvailableFilter = new AvailableFilter(); >+ fSourceFilter = new SourcePluginFilter(); >+ fAvailableListViewer.addFilter(fAvailableFilter); > fAvailableListViewer.addFilter(fVersionFilter); >+ if (!fFilterSourcePluginsButton.getSelection()) { >+ fAvailableListViewer.addFilter(fSourceFilter); >+ } >+ > fFilterJob = new WorkbenchJob("FilterJob") { //$NON-NLS-1$ > public IStatus runInUIThread(IProgressMonitor monitor) { > handleFilter(); >@@ -416,7 +465,7 @@ > protected void refreshPage() { > fImportListViewer.getTable().removeAll(); > fSelected.clear(); >- fFilter.setPattern("*"); //$NON-NLS-1$ >+ fAvailableFilter.setPattern("*"); //$NON-NLS-1$ > fVersionFilter.setModel(fModels); > fAvailableListViewer.refresh(); > pageChanged(); >@@ -487,8 +536,9 @@ > String newFilter; > if (fFilterText == null || (newFilter = fFilterText.getText().trim()).length() == 0) > newFilter = "*"; //$NON-NLS-1$ >- changed = fFilter.setPattern(newFilter); >+ changed = fAvailableFilter.setPattern(newFilter); > if (changed) { >+ // TODO Test whether we need to redraw/refresh > fAvailableListViewer.getTable().setRedraw(false); > fAvailableListViewer.refresh(); > fAvailableListViewer.getTable().setRedraw(true); >@@ -632,6 +682,7 @@ > public void storeSettings() { > IDialogSettings settings = getDialogSettings(); > settings.put(SETTINGS_SHOW_LATEST, fFilterOldVersionButton.getSelection()); >+ settings.put(SETTINGS_SHOW_SOURCE, fFilterSourcePluginsButton.getSelection()); > super.storeSettings(); > } > >Index: src/org/eclipse/pde/internal/ui/wizards/imports/JarImportOperation.java >=================================================================== >RCS file: src/org/eclipse/pde/internal/ui/wizards/imports/JarImportOperation.java >diff -N src/org/eclipse/pde/internal/ui/wizards/imports/JarImportOperation.java >--- src/org/eclipse/pde/internal/ui/wizards/imports/JarImportOperation.java 16 Jan 2008 17:07:39 -0000 1.6 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,479 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005, 2007 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.pde.internal.ui.wizards.imports; >- >-import java.io.*; >-import java.lang.reflect.InvocationTargetException; >-import java.util.*; >-import java.util.zip.ZipFile; >-import org.eclipse.core.resources.*; >-import org.eclipse.core.runtime.*; >-import org.eclipse.pde.internal.core.util.CoreUtility; >-import org.eclipse.pde.internal.ui.PDEPlugin; >-import org.eclipse.ui.dialogs.IOverwriteQuery; >-import org.eclipse.ui.wizards.datatransfer.*; >- >-public abstract class JarImportOperation implements IWorkspaceRunnable { >- >- protected void extractZipFile(File file, IPath destPath, IProgressMonitor monitor) throws CoreException { >- ZipFile zipFile = null; >- try { >- zipFile = new ZipFile(file); >- ZipFileStructureProvider provider = new ZipFileStructureProvider(zipFile); >- importContent(provider.getRoot(), destPath, provider, null, monitor); >- } catch (IOException e) { >- IStatus status = new Status(IStatus.ERROR, PDEPlugin.getPluginId(), IStatus.ERROR, e.getMessage(), e); >- throw new CoreException(status); >- } finally { >- if (zipFile != null) { >- try { >- zipFile.close(); >- } catch (IOException e) { >- } >- } >- } >- } >- >- protected void importContent(Object source, IPath destPath, IImportStructureProvider provider, List filesToImport, IProgressMonitor monitor) throws CoreException { >- IOverwriteQuery query = new IOverwriteQuery() { >- public String queryOverwrite(String file) { >- return ALL; >- } >- }; >- try { >- ImportOperation op = new ImportOperation(destPath, source, provider, query); >- op.setCreateContainerStructure(false); >- if (filesToImport != null) { >- op.setFilesToImport(filesToImport); >- } >- op.run(monitor); >- } catch (InvocationTargetException e) { >- IStatus status = new Status(IStatus.ERROR, PDEPlugin.getPluginId(), IStatus.ERROR, e.getMessage(), e); >- throw new CoreException(status); >- } catch (InterruptedException e) { >- throw new OperationCanceledException(e.getMessage()); >- } >- } >- >- protected void extractResources(File file, IResource dest, IProgressMonitor monitor) throws CoreException { >- ZipFile zipFile = null; >- try { >- zipFile = new ZipFile(file); >- ZipFileStructureProvider provider = new ZipFileStructureProvider(zipFile); >- ArrayList collected = new ArrayList(); >- collectResources(provider, provider.getRoot(), true, collected); >- importContent(provider.getRoot(), dest.getFullPath(), provider, collected, monitor); >- } catch (IOException e) { >- IStatus status = new Status(IStatus.ERROR, PDEPlugin.getPluginId(), IStatus.ERROR, e.getMessage(), e); >- throw new CoreException(status); >- } finally { >- if (zipFile != null) { >- try { >- zipFile.close(); >- } catch (IOException e) { >- } >- } >- } >- } >- >- /** >- * Extracts all of the files and subfolders from a single folder within an archive file. >- * @param file archive file to search for files >- * @param folderPath path to the folder to extract from >- * @param dest destination to import content to >- * @param monitor progress monitor >- * @throws CoreException if a problem occurs while extracting >- * @since 3.4 >- */ >- protected void extractResourcesFromFolder(File file, IPath folderPath, IResource dest, IProgressMonitor monitor) throws CoreException { >- ZipFile zipFile = null; >- try { >- zipFile = new ZipFile(file); >- ZipFileStructureProvider provider = new ZipFileStructureProvider(zipFile); >- ArrayList collected = new ArrayList(); >- collectResourcesFromFolder(provider, provider.getRoot(), folderPath, collected); >- importContent(provider.getRoot(), dest.getFullPath(), provider, collected, monitor); >- } catch (IOException e) { >- IStatus status = new Status(IStatus.ERROR, PDEPlugin.getPluginId(), IStatus.ERROR, e.getMessage(), e); >- throw new CoreException(status); >- } finally { >- if (zipFile != null) { >- try { >- zipFile.close(); >- } catch (IOException e) { >- } >- } >- } >- } >- >- /** >- * Searches the given archive file for java source folders. Imports the files in the >- * source folders to the specified destination unless the folder is in the list of >- * folders to exclude. >- * @param file archive file to search for source in >- * @param excludeFolders list of IPaths describing folders to ignore while searching >- * @param dest destination to put the extracted source >- * @param monitor progress monitor >- * @throws CoreException if there is a problem extracting source from the zip >- * @since 3.4 >- */ >- protected void extractJavaSource(File file, List excludeFolders, IResource dest, IProgressMonitor monitor) throws CoreException { >- ZipFile zipFile = null; >- try { >- zipFile = new ZipFile(file); >- ZipFileStructureProvider provider = new ZipFileStructureProvider(zipFile); >- ArrayList collected = new ArrayList(); >- collectJavaSourceFromRoot(provider, excludeFolders, collected); >- importContent(provider.getRoot(), dest.getFullPath(), provider, collected, monitor); >- } catch (IOException e) { >- IStatus status = new Status(IStatus.ERROR, PDEPlugin.getPluginId(), IStatus.ERROR, e.getMessage(), e); >- throw new CoreException(status); >- } finally { >- if (zipFile != null) { >- try { >- zipFile.close(); >- } catch (IOException e) { >- } >- } >- } >- } >- >- protected void extractJavaResources(File file, IResource dest, IProgressMonitor monitor) throws CoreException { >- ZipFile zipFile = null; >- try { >- zipFile = new ZipFile(file); >- ZipFileStructureProvider provider = new ZipFileStructureProvider(zipFile); >- ArrayList collected = new ArrayList(); >- collectJavaResources(provider, provider.getRoot(), collected); >- importContent(provider.getRoot(), dest.getFullPath(), provider, collected, monitor); >- } catch (IOException e) { >- IStatus status = new Status(IStatus.ERROR, PDEPlugin.getPluginId(), IStatus.ERROR, e.getMessage(), e); >- throw new CoreException(status); >- } finally { >- if (zipFile != null) { >- try { >- zipFile.close(); >- } catch (IOException e) { >- } >- } >- } >- } >- >- protected void importArchive(IProject project, File archive, IPath destPath) throws CoreException { >- try { >- if (destPath.segmentCount() > 2) >- CoreUtility.createFolder(project.getFolder(destPath.removeLastSegments(1))); >- IFile file = project.getFile(destPath); >- FileInputStream fstream = new FileInputStream(archive); >- if (file.exists()) >- file.setContents(fstream, true, false, null); >- else >- file.create(fstream, true, null); >- fstream.close(); >- } catch (IOException e) { >- IStatus status = new Status(IStatus.ERROR, PDEPlugin.getPluginId(), IStatus.OK, e.getMessage(), e); >- throw new CoreException(status); >- } >- } >- >- private void collectResources(ZipFileStructureProvider provider, Object element, boolean excludeMeta, ArrayList collected) { >- List children = provider.getChildren(element); >- if (children != null && !children.isEmpty()) { >- for (int i = 0; i < children.size(); i++) { >- Object curr = children.get(i); >- if (provider.isFolder(curr)) { >- if (!excludeMeta || !provider.getLabel(curr).equals("META-INF")) { //$NON-NLS-1$ >- collectResources(provider, curr, excludeMeta, collected); >- } >- } else if (!provider.getLabel(curr).endsWith(".class")) { //$NON-NLS-1$ >- collected.add(curr); >- } >- } >- } >- } >- >- /** >- * Recursively searches through the zip files searching for files inside of >- * the specified folder. The files found will be added to the given list. >- * @param provider zip provider >- * @param element element of the zip currently being looked at >- * @param folderPath location of the folder to get resources from >- * @param collected list of files found >- * @since 3.4 >- */ >- protected void collectResourcesFromFolder(ZipFileStructureProvider provider, Object element, IPath folderPath, ArrayList collected) { >- List children = provider.getChildren(element); >- if (children != null && !children.isEmpty()) { >- for (int i = 0; i < children.size(); i++) { >- Object curr = children.get(i); >- if (provider.isFolder(curr)) { >- if (provider.getLabel(curr).equals(folderPath.segment(0))) { >- if (folderPath.segmentCount() > 1) { >- collectResourcesFromFolder(provider, curr, folderPath.removeFirstSegments(1), collected); >- } else { >- collectResources(provider, curr, false, collected); >- } >- } >- } >- } >- } >- } >- >- /** >- * Searches through the zip file for java source folders. Collects the files >- * within the source folders. If a folder is in the list of folder paths to >- * ignore, the folder will be skipped. >- * @param provider zip provider >- * @param ignoreFolders list of IPaths describing folders to ignore >- * @param collected list that source files will be added to >- * @since 3.4 >- */ >- protected void collectJavaSourceFromRoot(ZipFileStructureProvider provider, List ignoreFolders, ArrayList collected) { >- List children = provider.getChildren(provider.getRoot()); >- if (children != null && !children.isEmpty()) { >- for (int i = 0; i < children.size(); i++) { >- Object curr = children.get(i); >- if (provider.isFolder(curr) && folderContainsFileExtension(provider, curr, ".java")) { //$NON-NLS-1$ >- // Check if we are in an ignored folder >- List ignoreSubFolders = new ArrayList(); >- boolean ignoreThisChild = false; >- for (Iterator iterator = ignoreFolders.iterator(); iterator.hasNext();) { >- IPath currentPath = (IPath) iterator.next(); >- if (provider.getLabel(curr).equals(currentPath.segment(0))) { >- if (currentPath.segmentCount() > 1) { >- // There is a subfolder that should be ignored >- ignoreSubFolders.add(currentPath.removeFirstSegments(1)); >- } else { >- // This folder should be ignored >- ignoreThisChild = true; >- break; >- } >- } >- } >- if (!ignoreThisChild) { >- collectJavaSource(provider, curr, ignoreSubFolders, collected); >- } >- } >- } >- } >- } >- >- /** >- * Recursively searches the children of the given element inside of a zip file. >- * If the folder path is in the set of folders to ignore, the folder will be skipped. >- * All files found, except for .class files, will be added. The given list will be >- * updated with the source files. >- * >- * @param provider zip provider >- * @param element current element inside the zip >- * @param ignoreFolders list of IPath folder paths to skip while searching >- * @param collected list to update with new files found to import >- * @since 3.4 >- */ >- protected void collectJavaSource(ZipFileStructureProvider provider, Object element, List ignoreFolders, ArrayList collected) { >- List children = provider.getChildren(element); >- if (children != null && !children.isEmpty()) { >- for (int i = 0; i < children.size(); i++) { >- Object curr = children.get(i); >- if (provider.isFolder(curr)) { >- // Check if we are in an ignored folder >- List ignoreSubFolders = new ArrayList(); >- boolean ignoreThisChild = false; >- for (Iterator iterator = ignoreFolders.iterator(); iterator.hasNext();) { >- IPath currentPath = (IPath) iterator.next(); >- if (provider.getLabel(curr).equals(currentPath.segment(0))) { >- if (currentPath.segmentCount() > 1) { >- // There is a subfolder that should be ignored. Remove segment referencing current folder. >- ignoreSubFolders.add(currentPath.removeFirstSegments(1)); >- } else { >- // This folder should be ignored >- ignoreThisChild = true; >- break; >- } >- } >- } >- if (!ignoreThisChild) { >- collectJavaSource(provider, curr, ignoreSubFolders, collected); >- } >- // Add the file to the list >- } else if (!provider.getLabel(curr).endsWith(".class")) { //$NON-NLS-1$ >- collected.add(curr); >- } >- } >- } >- } >- >- protected void collectNonJavaResources(ZipFileStructureProvider provider, Object element, ArrayList collected) { >- List children = provider.getChildren(element); >- if (children != null && !children.isEmpty()) { >- for (int i = 0; i < children.size(); i++) { >- Object curr = children.get(i); >- if (provider.isFolder(curr)) { >- if (!provider.getLabel(curr).equals("src") && !isClassFolder(provider, curr)) { //$NON-NLS-1$ >- ArrayList list = new ArrayList(); >- collectResources(provider, curr, false, list); >- collected.addAll(list); >- } >- } else if (!provider.getLabel(curr).endsWith(".class")) { //$NON-NLS-1$ >- collected.add(curr); >- } >- } >- } >- } >- >- protected void collectAdditionalResources(ZipFileStructureProvider provider, Object element, ArrayList collected) { >- List children = provider.getChildren(element); >- if (children != null && !children.isEmpty()) { >- for (int i = 0; i < children.size(); i++) { >- Object curr = children.get(i); >- if (provider.isFolder(curr)) { >- // ignore source folders >- if (folderContainsFileExtension(provider, curr, ".java")) //$NON-NLS-1$ >- continue; >- collected.add(curr); >- } else if (!provider.getLabel(curr).endsWith(".java")) { //$NON-NLS-1$ >- collected.add(curr); >- } >- } >- } >- } >- >- protected void collectJavaFiles(ZipFileStructureProvider provider, Object element, ArrayList collected) { >- List children = provider.getChildren(element); >- if (children != null && !children.isEmpty()) { >- for (int i = 0; i < children.size(); i++) { >- Object curr = children.get(i); >- if (provider.isFolder(curr)) { >- if (provider.getLabel(curr).equals("src")) { //$NON-NLS-1$ >- ArrayList list = new ArrayList(); >- collectResources(provider, curr, false, list); >- collected.addAll(list); >- } >- } >- } >- } >- } >- >- protected void collectJavaResources(ZipFileStructureProvider provider, Object element, ArrayList collected) { >- List children = provider.getChildren(element); >- if (children != null && !children.isEmpty()) { >- for (int i = 0; i < children.size(); i++) { >- Object curr = children.get(i); >- if (provider.isFolder(curr)) { >- if (isClassFolder(provider, curr)) { >- ArrayList list = new ArrayList(); >- collectResources(provider, curr, false, list); >- collected.addAll(list); >- } >- } >- } >- } >- } >- >- private boolean folderContainsFileExtension(ZipFileStructureProvider provider, Object element, String fileExtension) { >- List children = provider.getChildren(element); >- if (children != null && !children.isEmpty()) { >- for (int i = 0; i < children.size(); i++) { >- Object curr = children.get(i); >- if (provider.isFolder(curr)) { >- if (folderContainsFileExtension(provider, curr, fileExtension)) { >- return true; >- } >- } else if (provider.getLabel(curr).endsWith(fileExtension)) { //$NON-NLS-1$ >- return true; >- } >- } >- } >- return false; >- } >- >- private boolean isClassFolder(ZipFileStructureProvider provider, Object element) { >- return folderContainsFileExtension(provider, element, ".class"); //$NON-NLS-1$ >- } >- >- protected boolean hasEmbeddedSource(ZipFileStructureProvider provider) { >- List children = provider.getChildren(provider.getRoot()); >- if (children != null && !children.isEmpty()) { >- for (int i = 0; i < children.size(); i++) { >- Object curr = children.get(i); >- if (provider.isFolder(curr) && provider.getLabel(curr).equals("src")) { //$NON-NLS-1$ >- return true; >- } >- } >- } >- return false; >- } >- >- protected boolean containsCode(ZipFileStructureProvider provider) { >- List children = provider.getChildren(provider.getRoot()); >- if (children != null && !children.isEmpty()) { >- for (int i = 0; i < children.size(); i++) { >- Object curr = children.get(i); >- if (provider.isFolder(curr) && isClassFolder(provider, curr)) { >- return true; >- } >- } >- } >- return false; >- } >- >- protected boolean containsCode(File file) { >- ZipFile zipFile = null; >- try { >- zipFile = new ZipFile(file); >- return containsCode(new ZipFileStructureProvider(zipFile)); >- } catch (IOException e) { >- } finally { >- if (zipFile != null) { >- try { >- zipFile.close(); >- } catch (IOException e) { >- } >- } >- } >- return true; >- } >- >- protected String[] getTopLevelResources(File file) { >- ArrayList result = new ArrayList(); >- ZipFile zipFile = null; >- try { >- zipFile = new ZipFile(file); >- ZipFileStructureProvider provider = new ZipFileStructureProvider(zipFile); >- List children = provider.getChildren(provider.getRoot()); >- if (children != null && !children.isEmpty()) { >- for (int i = 0; i < children.size(); i++) { >- Object curr = children.get(i); >- if (provider.isFolder(curr)) { >- if (!isClassFolder(provider, curr)) >- result.add(provider.getLabel(curr) + "/"); //$NON-NLS-1$ >- else { >- if (!result.contains(".")) //$NON-NLS-1$ >- result.add("."); //$NON-NLS-1$ >- } >- } else { >- result.add(provider.getLabel(curr)); >- } >- } >- } >- } catch (IOException e) { >- } finally { >- if (zipFile != null) { >- try { >- zipFile.close(); >- } catch (IOException e) { >- } >- } >- } >- return (String[]) result.toArray(new String[result.size()]); >- } >- >-} >Index: src/org/eclipse/pde/internal/ui/pderesources.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties,v >retrieving revision 1.1012 >diff -u -r1.1012 pderesources.properties >--- src/org/eclipse/pde/internal/ui/pderesources.properties 11 Nov 2008 01:57:23 -0000 1.1012 >+++ src/org/eclipse/pde/internal/ui/pderesources.properties 14 Nov 2008 22:28:56 -0000 >@@ -1073,10 +1073,10 @@ > PluginSelectionDialog_title = Plug-in Selection > PluginStructureCreator_name=Plug-in Structure Compare > PluginSelectionDialog_message = &Select a Plug-in: >-PluginImportInfoDialog_message=Could not fully delete existing plug-ins with the same name.\nImporting the following plug-ins failed: >-PluginImportInfoDialog_title=Deleting Plug-ins Failed >+PluginImportOperation_could_not_delete_project=Import operation could not delete the following project: {0} > PluginImportOperation_linking=Linking content... > PluginImportOperation_executionEnvironment=Plug-in ''{0}'' requires an ''{1}'' execution environment that is not supported by any of the installed JREs. Import anyway? >+PluginImportOperation_Importing_plugin=Importing {0} > PluginImportWizard_runningConfigDesc=An application is currently running. Some of the selected plug-ins may not be imported if they are locked by it. Do you want to continue? > PluginImportWizard_runningConfigsDesc=Multiple applications are currently running. Some of the selected plug-ins may not be imported if they are locked by them. Do you want to continue? > PluginImportWizard_runningConfigsTitle=Running Applications >@@ -1141,11 +1141,9 @@ > ImportWizard_DetailedPage_filterDesc=Show latest version of plug-ins only > ImportWizard_DetailedPage_search = &ID (* = any string, ? = any character): > >-ImportWizard_operation_creating = Creating projects from plug-ins... >+ImportWizard_operation_creating = Creating projects from plug-ins > ImportWizard_operation_multiProblem = Problems detected while importing plug-ins >-ImportWizard_operation_creating2 = Creating ''{0}''... >-ImportWizard_operation_copyingSource = Copying source... >- >+ImportWizard_operation_importingSource== Importing source... > FeatureImportWizard_FirstPage_title = Import Features > FeatureImportWizard_FirstPage_desc = Create projects from features in the file system. > FeatureImportWizard_FirstPage_runtimeLocation = &Choose from features in the target platform >Index: src/org/eclipse/pde/internal/ui/PDEUIMessages.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEUIMessages.java,v >retrieving revision 1.389 >diff -u -r1.389 PDEUIMessages.java >--- src/org/eclipse/pde/internal/ui/PDEUIMessages.java 11 Nov 2008 01:57:23 -0000 1.389 >+++ src/org/eclipse/pde/internal/ui/PDEUIMessages.java 14 Nov 2008 22:28:55 -0000 >@@ -1594,9 +1594,7 @@ > > public static String PluginSelectionDialog_title; > public static String PluginSelectionDialog_message; >- public static String PluginImportInfoDialog_message; >- >- public static String PluginImportInfoDialog_title; >+ public static String PluginImportOperation_could_not_delete_project; > > public static String PluginImportOperation_linking; > public static String PluginContentPage_appQuestion; >@@ -1660,8 +1658,7 @@ > > public static String ImportWizard_operation_creating; > public static String ImportWizard_operation_multiProblem; >- public static String ImportWizard_operation_creating2; >- public static String ImportWizard_operation_copyingSource; >+ public static String ImportWizard_operation_importingSource; > > public static String FeatureImportWizard_FirstPage_title; > public static String FeatureImportWizard_FirstPage_desc; >@@ -2556,6 +2553,8 @@ > > public static String PluginImportOperation_executionEnvironment; > >+ public static String PluginImportOperation_Importing_plugin; >+ > public static String PluginImportWizard_runningConfigDesc; > > public static String PluginImportWizard_runningConfigsDesc; >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/META-INF/MANIFEST.MF,v >retrieving revision 1.66 >diff -u -r1.66 MANIFEST.MF >--- META-INF/MANIFEST.MF 7 Nov 2008 15:46:43 -0000 1.66 >+++ META-INF/MANIFEST.MF 14 Nov 2008 22:28:55 -0000 >@@ -114,7 +114,10 @@ > org.eclipse.equinox.p2.core;bundle-version="[1.0.0,2.0.0)", > org.eclipse.equinox.p2.director;bundle-version="[1.0.100,2.0.0)", > org.eclipse.equinox.p2.artifact.repository;bundle-version="[1.0.100,2.0.0)", >- org.eclipse.equinox.p2.metadata.repository;bundle-version="[1.0.100,2.0.0)" >+ org.eclipse.equinox.p2.metadata.repository;bundle-version="[1.0.100,2.0.0)", >+ org.eclipse.equinox.p2.publisher;bundle-version="[1.0.0,2.0.0)", >+ org.eclipse.equinox.frameworkadmin;bundle-version="1.0.100", >+ org.eclipse.equinox.frameworkadmin.equinox;bundle-version="1.0.100" > Eclipse-LazyStart: true > Import-Package: com.ibm.icu.text, > org.eclipse.jdt.debug.core >Index: src/org/eclipse/pde/ui/launcher/AbstractPDELaunchConfiguration.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/src/org/eclipse/pde/ui/launcher/AbstractPDELaunchConfiguration.java,v >retrieving revision 1.28 >diff -u -r1.28 AbstractPDELaunchConfiguration.java >--- src/org/eclipse/pde/ui/launcher/AbstractPDELaunchConfiguration.java 5 Nov 2008 20:50:23 -0000 1.28 >+++ src/org/eclipse/pde/ui/launcher/AbstractPDELaunchConfiguration.java 14 Nov 2008 22:28:56 -0000 >@@ -11,21 +11,35 @@ > package org.eclipse.pde.ui.launcher; > > import java.io.File; >-import java.util.ArrayList; >-import java.util.Map; >+import java.io.IOException; >+import java.util.*; > import org.eclipse.core.resources.IMarker; > import org.eclipse.core.resources.IProject; >+import org.eclipse.core.resources.IResource; > import org.eclipse.core.runtime.*; > import org.eclipse.debug.core.*; > import org.eclipse.debug.core.model.LaunchConfigurationDelegate; > import org.eclipse.jdt.core.IJavaModelMarker; >+import org.eclipse.equinox.internal.frameworkadmin.equinox.EquinoxConstants; >+import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; >+import org.eclipse.equinox.internal.p2.director.DirectorActivator; >+import org.eclipse.equinox.internal.provisional.frameworkadmin.*; >+import org.eclipse.equinox.internal.provisional.p2.engine.IProfile; >+import org.eclipse.equinox.internal.provisional.p2.engine.IProfileRegistry; >+import org.eclipse.equinox.p2.publisher.PublisherInfo; >+import org.eclipse.equinox.p2.publisher.PublisherResult; >+import org.eclipse.equinox.p2.publisher.eclipse.BundlesAction; > import org.eclipse.jdt.launching.*; > import org.eclipse.jface.dialogs.MessageDialog; >+import org.eclipse.osgi.service.resolver.BundleDescription; >+import org.eclipse.pde.core.plugin.IPluginModelBase; > import org.eclipse.pde.core.plugin.TargetPlatform; > import org.eclipse.pde.internal.core.TargetPlatformHelper; > import org.eclipse.pde.internal.core.builders.PDEMarkerFactory; > import org.eclipse.pde.internal.ui.*; > import org.eclipse.pde.internal.ui.launcher.*; >+import org.osgi.framework.*; >+import org.osgi.util.tracker.ServiceTracker; > > /** > * An abstract launch delegate for PDE-based launch configurations >@@ -62,28 +76,35 @@ > } > throw e; > } >+ > // if restarting, remove the restart flag from the launch config > if (configuration.getAttribute(IPDEUIConstants.RESTART, false) && configuration instanceof ILaunchConfigurationWorkingCopy) { > ((ILaunchConfigurationWorkingCopy) configuration).setAttribute(IPDEUIConstants.RESTART, false); > ((ILaunchConfigurationWorkingCopy) configuration).doSave(); > } >- VMRunnerConfiguration runnerConfig = new VMRunnerConfiguration(getMainClass(), getClasspath(configuration)); >- runnerConfig.setVMArguments(getVMArguments(configuration)); >- runnerConfig.setProgramArguments(getProgramArguments(configuration)); >- runnerConfig.setWorkingDirectory(getWorkingDirectory(configuration).getAbsolutePath()); >- runnerConfig.setEnvironment(getEnvironment(configuration)); >- runnerConfig.setVMSpecificAttributesMap(getVMSpecificAttributesMap(configuration)); >- >- monitor.worked(1); >- >- setDefaultSourceLocator(configuration); >- manageLaunch(launch); >- IVMRunner runner = getVMRunner(configuration, mode); >- if (runner != null) >- runner.run(runnerConfig, launch, monitor); >- else >- monitor.setCanceled(true); >- monitor.done(); >+ >+// createP2Profile(configuration, monitor); >+ >+// VMRunnerConfiguration runnerConfig = new VMRunnerConfiguration(getMainClass(), getClasspath(configuration)); >+// runnerConfig.setVMArguments(getVMArguments(configuration)); >+// runnerConfig.setProgramArguments(getProgramArguments(configuration)); >+// runnerConfig.setWorkingDirectory(getWorkingDirectory(configuration).getAbsolutePath()); >+// runnerConfig.setEnvironment(getEnvironment(configuration)); >+// runnerConfig.setVMSpecificAttributesMap(getVMSpecificAttributesMap(configuration)); >+// >+// monitor.worked(1); >+// >+// setDefaultSourceLocator(configuration); >+// manageLaunch(launch); >+// IVMRunner runner = getVMRunner(configuration, mode); >+// if (runner != null) >+// runner.run(runnerConfig, launch, monitor); >+// else >+// monitor.setCanceled(true); >+// monitor.done(); >+ >+ setupFrameworkAdmin(configuration); >+ > } catch (final CoreException e) { > monitor.setCanceled(true); > LauncherUtils.getDisplay().syncExec(new Runnable() { >@@ -95,6 +116,141 @@ > } > > /** >+ * @since 3.5 >+ */ >+ protected void createP2Profile(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException { >+ IProfileRegistry profileRegistry = (IProfileRegistry) ServiceHelper.getService(DirectorActivator.context, IProfileRegistry.class.getName()); >+ if (profileRegistry == null) >+ throw new CoreException(new Status(IStatus.ERROR, PDEPlugin.getPluginId(), "ProfileRegistry unavailable")); >+ IProfile profile = profileRegistry.addProfile("Tempy"); >+ >+ Set models = LaunchPluginValidator.parsePlugins(configuration, IPDELauncherConstants.SELECTED_WORKSPACE_PLUGINS); >+ List bundleDescriptions = new ArrayList(models.size()); >+ for (Iterator iterator = models.iterator(); iterator.hasNext();) { >+ IPluginModelBase currentModel = (IPluginModelBase) iterator.next(); >+ BundleDescription bd = currentModel.getBundleDescription(); >+ >+ // TODO Unclear if we can use the existing bundle description, or we need to recreate >+ IResource res = currentModel.getUnderlyingResource(); >+ bd = BundlesAction.createBundleDescription(new File(res.getLocationURI())); >+ >+ if (bd != null) { >+ bundleDescriptions.add(bd); >+ } >+ } >+ >+ BundlesAction bundlesAction = new BundlesAction((BundleDescription[]) bundleDescriptions.toArray(new BundleDescription[bundleDescriptions.size()])); >+ PublisherResult results = new PublisherResult(); >+ IStatus status = bundlesAction.perform(new PublisherInfo(), results, monitor); >+ >+ System.out.println(results.getIUs(null, null)); >+ >+ models = LaunchPluginValidator.parsePlugins(configuration, IPDELauncherConstants.SELECTED_TARGET_PLUGINS); >+ bundleDescriptions = new ArrayList(models.size()); >+ for (Iterator iterator = models.iterator(); iterator.hasNext();) { >+ IPluginModelBase currentModel = (IPluginModelBase) iterator.next(); >+ BundleDescription bd = currentModel.getBundleDescription(); >+ >+ // TODO Unclear if we can use the existing bundle description, or we need to recreate >+ IResource res = currentModel.getUnderlyingResource(); >+ bd = BundlesAction.createBundleDescription(new File(res.getLocationURI())); >+ >+ if (bd != null) { >+ bundleDescriptions.add(bd); >+ } >+ } >+ >+ bundlesAction = new BundlesAction((BundleDescription[]) bundleDescriptions.toArray(new BundleDescription[bundleDescriptions.size()])); >+ results = new PublisherResult(); >+ status = bundlesAction.perform(new PublisherInfo(), results, monitor); >+ >+ System.out.println(results.getIUs(null, null)); >+ >+ } >+ >+ /** >+ * @since 3.5 >+ */ >+ protected void setupFrameworkAdmin(ILaunchConfiguration configuration) throws CoreException { >+ ServiceReference serviceRef = PDEPlugin.getDefault().getBundleContext().getServiceReference(FrameworkAdmin.class.getName()); >+ PDEPlugin.getDefault().getBundleContext().getService(serviceRef); >+ >+ final String FILTER_OBJECTCLASS = "(" + Constants.OBJECTCLASS + "=" + FrameworkAdmin.class.getName() + ")"; >+ final String filterFwName = "(" + FrameworkAdmin.SERVICE_PROP_KEY_FW_NAME + "=Equinox)"; >+ final String filterLauncherName = "(" + FrameworkAdmin.SERVICE_PROP_KEY_LAUNCHER_NAME + "=Eclipse.exe)"; >+ final String filterFwAdmin = "(&" + FILTER_OBJECTCLASS + filterFwName + filterLauncherName + ")"; >+ >+ Filter filter; >+ ServiceTracker fwAdminTracker = null; >+ try { >+ filter = PDEPlugin.getDefault().getBundleContext().createFilter(filterFwAdmin); >+ fwAdminTracker = new ServiceTracker(PDEPlugin.getDefault().getBundleContext(), filter, null); >+ fwAdminTracker.open(); >+ } catch (InvalidSyntaxException e) { >+ // never happens >+ e.printStackTrace(); >+ } >+ >+ if (fwAdminTracker != null) { >+ FrameworkAdmin fwAdmin = (FrameworkAdmin) fwAdminTracker.getService(); >+ >+ Manipulator tempManipulator = fwAdmin.getRunningManipulator(); >+ >+ Manipulator manipulator = fwAdmin.getManipulator(); >+ >+ LauncherData launcherData = new LauncherData(EquinoxConstants.FW_NAME, EquinoxConstants.FW_VERSION, EquinoxConstants.LAUNCHER_NAME, EquinoxConstants.LAUNCHER_VERSION); >+ launcherData.setLauncher(new File(Platform.getInstallLocation().getURL().getFile(), "eclipse.exe")); >+ launcherData.setLauncherConfigLocation(new File(getConfigDir(configuration), "eclipse.ini")); >+ >+ launcherData.setJvmArgs(getVMArguments(configuration)); >+ // TODO Simplify how we get the VM without breaking API, #getVMRunner() will no longer be used >+ launcherData.setJvm(VMHelper.createLauncher(configuration).getInstallLocation()); >+ launcherData.setProgramArgs(getProgramArguments(configuration)); >+ >+ launcherData.setFwConfigLocation(getConfigDir(configuration)); >+ >+ // TODO What else needs to be set >+ // data.setFwJar(fwJar); >+ // data.setFwPersistentDataLocation(fwPersistentDataLocation, clean); >+// data.setHome(home); >+ >+ // TODO Need to account for the following methods >+ // VMRunnerConfiguration runnerConfig = new VMRunnerConfiguration(getMainClass(), getClasspath(configuration)); >+ // runnerConfig.setEnvironment(getEnvironment(configuration)); >+ // runnerConfig.setVMSpecificAttributesMap(getVMSpecificAttributesMap(configuration)); >+ >+ ConfigData configData = new ConfigData(EquinoxConstants.FW_NAME, EquinoxConstants.FW_VERSION, EquinoxConstants.LAUNCHER_NAME, EquinoxConstants.LAUNCHER_VERSION); >+ >+ IPluginModelBase[] plugins = LaunchPluginValidator.getPluginList(configuration); >+ List launchingBundles = new ArrayList(plugins.length); >+ for (int i = 0; i < plugins.length; i++) { >+ launchingBundles.add(new BundleInfo(plugins[i].getInstallLocation())); >+ } >+ configData.setBundles((BundleInfo[]) launchingBundles.toArray(new BundleInfo[launchingBundles.size()])); >+ >+ // TODO What else needs to be set >+ // configData.setBeginningFwStartLevel(startLevel); >+ // configData.setFwDependentProps(props); >+ // configData.setFwIndependentProps(props); >+ // configData.setInitialBundleStartLevel(startLevel); >+ >+ manipulator.setLauncherData(launcherData); >+ manipulator.setConfigData(configData); >+ >+ try { >+ >+ manipulator.save(false); >+ >+ fwAdmin.launch(manipulator, getWorkingDirectory(configuration)); >+ >+ } catch (IOException e) { >+ // TODO Translate? >+ throw new CoreException(new Status(IStatus.ERROR, PDEPlugin.getPluginId(), "Error trying to launch framework", e)); >+ } >+ } >+ } >+ >+ /** > * Returns the VM runner for the given launch mode to use when launching the > * given configuration. > * >Index: src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportHelper.java >=================================================================== >RCS file: src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportHelper.java >diff -N src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportHelper.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportHelper.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,389 @@ >+/******************************************************************************* >+ * Copyright (c) 2005, 2008 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.pde.internal.ui.wizards.imports; >+ >+import java.io.*; >+import java.lang.reflect.InvocationTargetException; >+import java.util.*; >+import java.util.zip.ZipFile; >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.runtime.*; >+import org.eclipse.pde.internal.ui.PDEPlugin; >+import org.eclipse.ui.dialogs.IOverwriteQuery; >+import org.eclipse.ui.wizards.datatransfer.*; >+ >+/** >+ * Helper class for the plugin import operation. Contains methods to assist in the copying and extracting >+ * of jar a folder files. >+ */ >+public class PluginImportHelper { >+ >+ /** >+ * Imports the contents of a zip file or folder, extracting the necessary files and >+ * putting them in the specified destination. >+ * @param source the file or folder to import from, should either be the root of the zip file or the File representing the folder >+ * @param dstPath >+ * @param provider >+ * @param filesToImport >+ * @param monitor >+ * @throws CoreException >+ */ >+ public static void importContent(Object source, IPath dstPath, IImportStructureProvider provider, List filesToImport, IProgressMonitor monitor) throws CoreException { >+ IOverwriteQuery query = new IOverwriteQuery() { >+ public String queryOverwrite(String file) { >+ return ALL; >+ } >+ }; >+ try { >+ ImportOperation op = new ImportOperation(dstPath, source, provider, query); >+ op.setCreateContainerStructure(false); >+ if (filesToImport != null) { >+ op.setFilesToImport(filesToImport); >+ } >+ op.run(monitor); >+ } catch (InvocationTargetException e) { >+ IStatus status = new Status(IStatus.ERROR, PDEPlugin.getPluginId(), IStatus.ERROR, e.getMessage(), e); >+ throw new CoreException(status); >+ } catch (InterruptedException e) { >+ throw new OperationCanceledException(e.getMessage()); >+ } >+ } >+ >+ /** >+ * Extracts the contents of the specified zip file to the specified destination >+ * @param file >+ * @param dstPath >+ * @param monitor >+ * @throws CoreException >+ */ >+ public static void extractArchive(File file, IPath dstPath, IProgressMonitor monitor) throws CoreException { >+ ZipFile zipFile = null; >+ try { >+ zipFile = new ZipFile(file); >+ ZipFileStructureProvider provider = new ZipFileStructureProvider(zipFile); >+ importContent(provider.getRoot(), dstPath, provider, null, monitor); >+ } catch (IOException e) { >+ IStatus status = new Status(IStatus.ERROR, PDEPlugin.getPluginId(), IStatus.ERROR, e.getMessage(), e); >+ throw new CoreException(status); >+ } finally { >+ if (zipFile != null) { >+ try { >+ zipFile.close(); >+ } catch (IOException e) { >+ } >+ } >+ } >+ } >+ >+ /** >+ * Extracts all of the files and subfolders from a single folder within an archive file. >+ * @param file archive file to search for files >+ * @param folderPath path to the folder to extract from >+ * @param dstPath destination to import content to >+ * @param monitor progress monitor >+ * @throws CoreException if a problem occurs while extracting >+ * @since 3.4 >+ */ >+ public static void extractFolderFromArchive(File file, IPath folderPath, IPath dstPath, IProgressMonitor monitor) throws CoreException { >+ ZipFile zipFile = null; >+ try { >+ zipFile = new ZipFile(file); >+ ZipFileStructureProvider provider = new ZipFileStructureProvider(zipFile); >+ ArrayList collected = new ArrayList(); >+ collectResourcesFromFolder(provider, provider.getRoot(), folderPath, collected); >+ importContent(provider.getRoot(), dstPath, provider, collected, monitor); >+ } catch (IOException e) { >+ IStatus status = new Status(IStatus.ERROR, PDEPlugin.getPluginId(), IStatus.ERROR, e.getMessage(), e); >+ throw new CoreException(status); >+ } finally { >+ if (zipFile != null) { >+ try { >+ zipFile.close(); >+ } catch (IOException e) { >+ } >+ } >+ } >+ } >+ >+ /** >+ * Searches the given archive file for java source folders. Imports the files in the >+ * source folders to the specified destination unless the folder is in the list of >+ * folders to exclude. >+ * @param file archive file to search for source in >+ * @param excludeFolders list of IPaths describing folders to ignore while searching >+ * @param dstPath full path to destination to put the extracted source >+ * @param monitor progress monitor >+ * @throws CoreException if there is a problem extracting source from the zip >+ */ >+ public static void extractJavaSourceFromArchive(File file, List excludeFolders, IPath dstPath, IProgressMonitor monitor) throws CoreException { >+ ZipFile zipFile = null; >+ try { >+ zipFile = new ZipFile(file); >+ ZipFileStructureProvider provider = new ZipFileStructureProvider(zipFile); >+ ArrayList collected = new ArrayList(); >+ collectJavaSourceFromRoot(provider, excludeFolders, collected); >+ importContent(provider.getRoot(), dstPath, provider, collected, monitor); >+ } catch (IOException e) { >+ IStatus status = new Status(IStatus.ERROR, PDEPlugin.getPluginId(), IStatus.ERROR, e.getMessage(), e); >+ throw new CoreException(status); >+ } finally { >+ if (zipFile != null) { >+ try { >+ zipFile.close(); >+ } catch (IOException e) { >+ } >+ } >+ } >+ } >+ >+ /** >+ * Copies an archive file to an IFile >+ * @param file >+ * @param dstFile >+ * @throws CoreException >+ */ >+ public static void copyArchive(File file, IFile dstFile, IProgressMonitor monitor) throws CoreException { >+ try { >+ FileInputStream fstream = new FileInputStream(file); >+ if (dstFile.exists()) >+ dstFile.setContents(fstream, true, false, monitor); >+ else >+ dstFile.create(fstream, true, monitor); >+ fstream.close(); >+ } catch (IOException e) { >+ IStatus status = new Status(IStatus.ERROR, PDEPlugin.getPluginId(), IStatus.OK, e.getMessage(), e); >+ throw new CoreException(status); >+ } >+ } >+ >+ public static String[] getTopLevelResources(File file) { >+ ArrayList result = new ArrayList(); >+ ZipFile zipFile = null; >+ try { >+ zipFile = new ZipFile(file); >+ ZipFileStructureProvider provider = new ZipFileStructureProvider(zipFile); >+ List children = provider.getChildren(provider.getRoot()); >+ if (children != null && !children.isEmpty()) { >+ for (int i = 0; i < children.size(); i++) { >+ Object curr = children.get(i); >+ if (provider.isFolder(curr)) { >+ if (!isClassFolder(provider, curr)) >+ result.add(provider.getLabel(curr) + "/"); //$NON-NLS-1$ >+ else { >+ if (!result.contains(".")) //$NON-NLS-1$ >+ result.add("."); //$NON-NLS-1$ >+ } >+ } else { >+ result.add(provider.getLabel(curr)); >+ } >+ } >+ } >+ } catch (IOException e) { >+ } finally { >+ if (zipFile != null) { >+ try { >+ zipFile.close(); >+ } catch (IOException e) { >+ } >+ } >+ } >+ return (String[]) result.toArray(new String[result.size()]); >+ } >+ >+ public static void collectRequiredBundleFiles(IImportStructureProvider provider, Object element, ArrayList collected) { >+ List children = provider.getChildren(element); >+ if (children != null && !children.isEmpty()) { >+ for (int i = 0; i < children.size(); i++) { >+ Object curr = children.get(i); >+ String name = provider.getLabel(curr); >+ if (provider.isFolder(curr)) { >+ if (!name.equals("src") && !isClassFolder(provider, curr)) { //$NON-NLS-1$ >+ ArrayList list = new ArrayList(); >+ collectResources(provider, curr, false, list); >+ collected.addAll(list); >+ } >+ } else if (!name.endsWith(".class")) { //$NON-NLS-1$ >+ // Ignore the bundle signing files >+ if (!(provider.getFullPath(curr).indexOf("META-INF/") != -1 && (name.endsWith(".RSA") || name.endsWith(".DSA") || name.endsWith(".SF")))) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ >+ collected.add(curr); >+ } >+ } >+ >+ } >+ } >+ } >+ >+ public static void collectNonJavaFiles(IImportStructureProvider provider, Object element, ArrayList collected) { >+ List children = provider.getChildren(element); >+ if (children != null && !children.isEmpty()) { >+ for (int i = 0; i < children.size(); i++) { >+ Object curr = children.get(i); >+ if (provider.isFolder(curr)) { >+ // ignore source folders >+ if (folderContainsFileExtension(provider, curr, ".java")) //$NON-NLS-1$ >+ continue; >+ collected.add(curr); >+ } else if (!provider.getLabel(curr).endsWith(".java")) { //$NON-NLS-1$ >+ collected.add(curr); >+ } >+ } >+ } >+ } >+ >+ private static void collectResources(IImportStructureProvider provider, Object element, boolean excludeMeta, ArrayList collected) { >+ List children = provider.getChildren(element); >+ if (children != null && !children.isEmpty()) { >+ for (int i = 0; i < children.size(); i++) { >+ Object curr = children.get(i); >+ if (provider.isFolder(curr)) { >+ if (!excludeMeta || !provider.getLabel(curr).equals("META-INF")) { //$NON-NLS-1$ >+ collectResources(provider, curr, excludeMeta, collected); >+ } >+ } else if (!provider.getLabel(curr).endsWith(".class")) { //$NON-NLS-1$ >+ collected.add(curr); >+ } >+ } >+ } >+ } >+ >+ /** >+ * Recursively searches through the zip files searching for files inside of >+ * the specified folder. The files found will be added to the given list. >+ * @param provider zip provider >+ * @param element element of the zip currently being looked at >+ * @param folderPath location of the folder to get resources from >+ * @param collected list of files found >+ * @since 3.4 >+ */ >+ private static void collectResourcesFromFolder(ZipFileStructureProvider provider, Object element, IPath folderPath, ArrayList collected) { >+ List children = provider.getChildren(element); >+ if (children != null && !children.isEmpty()) { >+ for (int i = 0; i < children.size(); i++) { >+ Object curr = children.get(i); >+ if (provider.isFolder(curr)) { >+ if (provider.getLabel(curr).equals(folderPath.segment(0))) { >+ if (folderPath.segmentCount() > 1) { >+ collectResourcesFromFolder(provider, curr, folderPath.removeFirstSegments(1), collected); >+ } else { >+ collectResources(provider, curr, false, collected); >+ } >+ } >+ } >+ } >+ } >+ } >+ >+ /** >+ * Searches through the zip file for java source folders. Collects the files >+ * within the source folders. If a folder is in the list of folder paths to >+ * ignore, the folder will be skipped. >+ * @param provider zip provider >+ * @param ignoreFolders list of IPaths describing folders to ignore >+ * @param collected list that source files will be added to >+ * @since 3.4 >+ */ >+ private static void collectJavaSourceFromRoot(ZipFileStructureProvider provider, List ignoreFolders, ArrayList collected) { >+ List children = provider.getChildren(provider.getRoot()); >+ if (children != null && !children.isEmpty()) { >+ for (int i = 0; i < children.size(); i++) { >+ Object curr = children.get(i); >+ if (provider.isFolder(curr) && folderContainsFileExtension(provider, curr, ".java")) { //$NON-NLS-1$ >+ // Check if we are in an ignored folder >+ List ignoreSubFolders = new ArrayList(); >+ boolean ignoreThisChild = false; >+ for (Iterator iterator = ignoreFolders.iterator(); iterator.hasNext();) { >+ IPath currentPath = (IPath) iterator.next(); >+ if (provider.getLabel(curr).equals(currentPath.segment(0))) { >+ if (currentPath.segmentCount() > 1) { >+ // There is a subfolder that should be ignored >+ ignoreSubFolders.add(currentPath.removeFirstSegments(1)); >+ } else { >+ // This folder should be ignored >+ ignoreThisChild = true; >+ break; >+ } >+ } >+ } >+ if (!ignoreThisChild) { >+ collectJavaSource(provider, curr, ignoreSubFolders, collected); >+ } >+ } >+ } >+ } >+ } >+ >+ /** >+ * Recursively searches the children of the given element inside of a zip file. >+ * If the folder path is in the set of folders to ignore, the folder will be skipped. >+ * All files found, except for .class files, will be added. The given list will be >+ * updated with the source files. >+ * >+ * @param provider zip provider >+ * @param element current element inside the zip >+ * @param ignoreFolders list of IPath folder paths to skip while searching >+ * @param collected list to update with new files found to import >+ * @since 3.4 >+ */ >+ private static void collectJavaSource(ZipFileStructureProvider provider, Object element, List ignoreFolders, ArrayList collected) { >+ List children = provider.getChildren(element); >+ if (children != null && !children.isEmpty()) { >+ for (int i = 0; i < children.size(); i++) { >+ Object curr = children.get(i); >+ if (provider.isFolder(curr)) { >+ // Check if we are in an ignored folder >+ List ignoreSubFolders = new ArrayList(); >+ boolean ignoreThisChild = false; >+ for (Iterator iterator = ignoreFolders.iterator(); iterator.hasNext();) { >+ IPath currentPath = (IPath) iterator.next(); >+ if (provider.getLabel(curr).equals(currentPath.segment(0))) { >+ if (currentPath.segmentCount() > 1) { >+ // There is a subfolder that should be ignored. Remove segment referencing current folder. >+ ignoreSubFolders.add(currentPath.removeFirstSegments(1)); >+ } else { >+ // This folder should be ignored >+ ignoreThisChild = true; >+ break; >+ } >+ } >+ } >+ if (!ignoreThisChild) { >+ collectJavaSource(provider, curr, ignoreSubFolders, collected); >+ } >+ // Add the file to the list >+ } else if (!provider.getLabel(curr).endsWith(".class")) { //$NON-NLS-1$ >+ collected.add(curr); >+ } >+ } >+ } >+ } >+ >+ private static boolean folderContainsFileExtension(IImportStructureProvider provider, Object element, String fileExtension) { >+ List children = provider.getChildren(element); >+ if (children != null && !children.isEmpty()) { >+ for (int i = 0; i < children.size(); i++) { >+ Object curr = children.get(i); >+ if (provider.isFolder(curr)) { >+ if (folderContainsFileExtension(provider, curr, fileExtension)) { >+ return true; >+ } >+ } else if (provider.getLabel(curr).endsWith(fileExtension)) { >+ return true; >+ } >+ } >+ } >+ return false; >+ } >+ >+ private static boolean isClassFolder(IImportStructureProvider provider, Object element) { >+ return folderContainsFileExtension(provider, element, ".class"); //$NON-NLS-1$ >+ } >+ >+} >#P org.eclipse.pde.ui.tests >Index: src/org/eclipse/pde/ui/tests/imports/BaseImportTestCase.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/imports/BaseImportTestCase.java,v >retrieving revision 1.10 >diff -u -r1.10 BaseImportTestCase.java >--- src/org/eclipse/pde/ui/tests/imports/BaseImportTestCase.java 26 Apr 2008 23:29:07 -0000 1.10 >+++ src/org/eclipse/pde/ui/tests/imports/BaseImportTestCase.java 14 Nov 2008 22:28:59 -0000 >@@ -11,12 +11,12 @@ > package org.eclipse.pde.ui.tests.imports; > > import org.eclipse.core.resources.*; >-import org.eclipse.core.runtime.*; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IStatus; > import org.eclipse.jdt.core.*; > import org.eclipse.pde.core.plugin.IPluginModelBase; > import org.eclipse.pde.core.plugin.PluginRegistry; > import org.eclipse.pde.internal.core.PDECore; >-import org.eclipse.pde.internal.ui.PDEPlugin; > import org.eclipse.pde.internal.ui.wizards.imports.PluginImportOperation; > import org.eclipse.pde.internal.ui.wizards.imports.PluginImportWizard.ImportQuery; > import org.eclipse.pde.ui.tests.PDETestCase; >@@ -69,15 +69,19 @@ > > protected void runOperation(IPluginModelBase[] models, int type) { > PluginImportOperation.IImportQuery query = new ImportQuery(getShell()); >- PluginImportOperation.IImportQuery executionQuery = new ImportQuery(getShell()); >- final PluginImportOperation op = new PluginImportOperation(models, type, query, executionQuery, false); >- >- try { >- PDEPlugin.getWorkspace().run(op, new NullProgressMonitor()); >- } catch (OperationCanceledException e) { >- fail("Import Operation failed: " + e); >- } catch (CoreException e) { >- fail("Import Operation failed: " + e); >+ PluginImportOperation.IImportQuery executionQuery = new ImportQuery(getShell()); >+ PluginImportOperation job = new PluginImportOperation(models, type, query, executionQuery, false); >+ job.setRule(ResourcesPlugin.getWorkspace().getRoot()); >+ job.setSystem(true); >+ job.schedule(); >+ try{ >+ job.join(); >+ } catch (InterruptedException e){ >+ fail("Job interupted: " + e.getMessage()); >+ } >+ IStatus status = job.getResult(); >+ if (!status.isOK()){ >+ fail("Import Operation failed: " + status.toString()); > } > } > >#P org.eclipse.pde.core >Index: src/org/eclipse/pde/internal/core/ClasspathComputer.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ClasspathComputer.java,v >retrieving revision 1.10 >diff -u -r1.10 ClasspathComputer.java >--- src/org/eclipse/pde/internal/core/ClasspathComputer.java 7 Nov 2008 21:21:45 -0000 1.10 >+++ src/org/eclipse/pde/internal/core/ClasspathComputer.java 14 Nov 2008 22:29:00 -0000 >@@ -35,11 +35,12 @@ > private static final int SEVERITY_IGNORE = 1; > > public static void setClasspath(IProject project, IPluginModelBase model) throws CoreException { >- IClasspathEntry[] entries = getClasspath(project, model, false, true); >+ IClasspathEntry[] entries = getClasspath(project, model, null, false, true); > JavaCore.create(project).setRawClasspath(entries, null); > } > >- public static IClasspathEntry[] getClasspath(IProject project, IPluginModelBase model, boolean clear, boolean overrideCompliance) throws CoreException { >+ // TODO Javadoc >+ public static IClasspathEntry[] getClasspath(IProject project, IPluginModelBase model, Map sourceLibraryMap, boolean clear, boolean overrideCompliance) throws CoreException { > IJavaProject javaProject = JavaCore.create(project); > ArrayList result = new ArrayList(); > IBuild build = getBuild(project); >@@ -53,7 +54,7 @@ > result.add(createEntryUsingPreviousEntry(javaProject, ee, PDECore.REQUIRED_PLUGINS_CONTAINER_PATH)); > > // add own libraries/source >- addSourceAndLibraries(project, model, build, clear, result); >+ addSourceAndLibraries(project, model, build, clear, sourceLibraryMap, result); > > IClasspathEntry[] entries = (IClasspathEntry[]) result.toArray(new IClasspathEntry[result.size()]); > IJavaModelStatus validation = JavaConventions.validateClasspath(javaProject, entries, javaProject.getOutputLocation()); >@@ -64,7 +65,7 @@ > return (IClasspathEntry[]) result.toArray(new IClasspathEntry[result.size()]); > } > >- public static void addSourceAndLibraries(IProject project, IPluginModelBase model, IBuild build, boolean clear, ArrayList result) throws CoreException { >+ private static void addSourceAndLibraries(IProject project, IPluginModelBase model, IBuild build, boolean clear, Map sourceLibraryMap, ArrayList result) throws CoreException { > > HashSet paths = new HashSet(); > >@@ -87,10 +88,11 @@ > if (buildEntry != null) { > addSourceFolder(buildEntry, project, paths, result); > } else { >+ IPath sourceAttachment = sourceLibraryMap != null ? (IPath) sourceLibraryMap.get(libraries[i].getName()) : null; > if (libraries[i].getName().equals(".")) //$NON-NLS-1$ >- addJARdPlugin(project, ClasspathUtilCore.getFilename(model), attrs, result); >+ addJARdPlugin(project, ClasspathUtilCore.getFilename(model), sourceAttachment, attrs, result); > else >- addLibraryEntry(project, libraries[i], attrs, result); >+ addLibraryEntry(project, libraries[i], sourceAttachment, attrs, result); > } > } > if (libraries.length == 0) { >@@ -100,7 +102,8 @@ > addSourceFolder(buildEntry, project, paths, result); > } > } else if (ClasspathUtilCore.hasBundleStructure(model)) { >- addJARdPlugin(project, ClasspathUtilCore.getFilename(model), attrs, result); >+ IPath sourceAttachment = sourceLibraryMap != null ? (IPath) sourceLibraryMap.get(".") : null; //$NON-NLS-1$ >+ addJARdPlugin(project, ClasspathUtilCore.getFilename(model), sourceAttachment, attrs, result); > } > } > } >@@ -147,7 +150,7 @@ > return (buildModel != null) ? buildModel.getBuild() : null; > } > >- private static void addLibraryEntry(IProject project, IPluginLibrary library, IClasspathAttribute[] attrs, ArrayList result) throws JavaModelException { >+ private static void addLibraryEntry(IProject project, IPluginLibrary library, IPath sourceAttachment, IClasspathAttribute[] attrs, ArrayList result) throws JavaModelException { > String name = ClasspathUtilCore.expandLibraryName(library.getName()); > IResource jarFile = project.findMember(name); > if (jarFile == null) >@@ -162,34 +165,29 @@ > } > } > >- IClasspathEntry entry = createClasspathEntry(project, jarFile, name, attrs, library.isExported()); >+ IClasspathEntry entry = createClasspathEntry(project, jarFile, name, sourceAttachment, attrs, library.isExported()); > if (!result.contains(entry)) > result.add(entry); > } > >- private static void addJARdPlugin(IProject project, String filename, IClasspathAttribute[] attrs, ArrayList result) { >+ private static void addJARdPlugin(IProject project, String filename, IPath sourceAttachment, IClasspathAttribute[] attrs, ArrayList result) { > String name = ClasspathUtilCore.expandLibraryName(filename); > IResource jarFile = project.findMember(name); > if (jarFile != null) { >- IClasspathEntry entry = createClasspathEntry(project, jarFile, filename, attrs, true); >+ IClasspathEntry entry = createClasspathEntry(project, jarFile, filename, sourceAttachment, attrs, true); > if (!result.contains(entry)) > result.add(entry); > } > } > >- private static IClasspathEntry createClasspathEntry(IProject project, IResource library, String fileName, IClasspathAttribute[] attrs, boolean isExported) { >- String sourceZipName = ClasspathUtilCore.getSourceZipName(fileName); >- IResource resource = project.findMember(sourceZipName); >- // if zip file does not exist, see if a directory with the source does. This in necessary how we import source for individual source bundles. >- if (resource == null && sourceZipName.endsWith(".zip")) { //$NON-NLS-1$ >- resource = project.findMember(sourceZipName.substring(0, sourceZipName.length() - 4)); >- if (resource == null) >- // if we can't find the the source for a library, then try to find the common source location set up to share source from one jar to all libraries. >- // see PluginImportOperation.linkSourceArchives >- resource = project.getFile(project.getName() + "src.zip"); //$NON-NLS-1$ >- } >- IPath srcAttachment = resource != null ? resource.getFullPath() : library.getFullPath(); >- return JavaCore.newLibraryEntry(library.getFullPath(), srcAttachment, null, new IAccessRule[0], attrs, isExported); >+ private static IClasspathEntry createClasspathEntry(IProject project, IResource library, String fileName, IPath sourceAttachment, IClasspathAttribute[] attrs, boolean isExported) { >+ IResource resource = sourceAttachment != null ? project.findMember(sourceAttachment) : project.findMember(ClasspathUtilCore.getSourceZipName(fileName)); >+ // TODO This case may no longer be needed as the source can be any name, the source attachment should be specified in this case >+// if (resource == null) { >+// // If a specific library zip can't be found, look for the common source jar as is may have multiple source roots >+// resource = project.getFile(project.getName() + "src.zip"); //$NON-NLS-1$ >+// } >+ return JavaCore.newLibraryEntry(library.getFullPath(), resource == null ? null : resource.getFullPath(), null, new IAccessRule[0], attrs, isExported); > } > > private static String getExecutionEnvironment(BundleDescription bundleDescription) {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 245565
:
117150
|
117151
| 117958 |
118301