|
Lines 14-20
Link Here
|
| 14 |
import java.io.IOException; |
14 |
import java.io.IOException; |
| 15 |
import java.util.*; |
15 |
import java.util.*; |
| 16 |
import java.util.jar.JarFile; |
16 |
import java.util.jar.JarFile; |
| 17 |
import java.util.zip.ZipEntry; |
|
|
| 18 |
import java.util.zip.ZipFile; |
17 |
import java.util.zip.ZipFile; |
| 19 |
import org.eclipse.core.resources.*; |
18 |
import org.eclipse.core.resources.*; |
| 20 |
import org.eclipse.core.runtime.*; |
19 |
import org.eclipse.core.runtime.*; |
|
Lines 22-30
Link Here
|
| 22 |
import org.eclipse.jdt.core.*; |
21 |
import org.eclipse.jdt.core.*; |
| 23 |
import org.eclipse.jdt.launching.JavaRuntime; |
22 |
import org.eclipse.jdt.launching.JavaRuntime; |
| 24 |
import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager; |
23 |
import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager; |
| 25 |
import org.eclipse.osgi.service.environment.Constants; |
|
|
| 26 |
import org.eclipse.osgi.service.resolver.BundleDescription; |
24 |
import org.eclipse.osgi.service.resolver.BundleDescription; |
| 27 |
import org.eclipse.osgi.service.resolver.HostSpecification; |
|
|
| 28 |
import org.eclipse.osgi.util.ManifestElement; |
25 |
import org.eclipse.osgi.util.ManifestElement; |
| 29 |
import org.eclipse.osgi.util.NLS; |
26 |
import org.eclipse.osgi.util.NLS; |
| 30 |
import org.eclipse.pde.core.build.IBuild; |
27 |
import org.eclipse.pde.core.build.IBuild; |
|
Lines 38-44
Link Here
|
| 38 |
import org.eclipse.pde.internal.core.util.CoreUtility; |
35 |
import org.eclipse.pde.internal.core.util.CoreUtility; |
| 39 |
import org.eclipse.pde.internal.ui.PDEPlugin; |
36 |
import org.eclipse.pde.internal.ui.PDEPlugin; |
| 40 |
import org.eclipse.pde.internal.ui.PDEUIMessages; |
37 |
import org.eclipse.pde.internal.ui.PDEUIMessages; |
| 41 |
import org.eclipse.swt.widgets.Display; |
|
|
| 42 |
import org.eclipse.team.core.RepositoryProvider; |
38 |
import org.eclipse.team.core.RepositoryProvider; |
| 43 |
import org.eclipse.team.core.TeamException; |
39 |
import org.eclipse.team.core.TeamException; |
| 44 |
import org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider; |
40 |
import org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider; |
|
Lines 46-61
Link Here
|
| 46 |
import org.osgi.framework.BundleException; |
42 |
import org.osgi.framework.BundleException; |
| 47 |
|
43 |
|
| 48 |
/** |
44 |
/** |
| 49 |
* Imports one or more plugins into the workspace. There are three different |
45 |
* Imports one or more plug-ins into the workspace. There are three different |
| 50 |
* ways to import a plugin: as binary, as binary with linked source, |
46 |
* ways to import a plugin: as binary, as binary with linked source, |
| 51 |
* and as source. |
47 |
* and as source. |
| 52 |
*/ |
48 |
*/ |
| 53 |
public class PluginImportOperation extends JarImportOperation { |
49 |
public class PluginImportOperation extends Job { |
| 54 |
|
50 |
|
| 55 |
public static final int IMPORT_BINARY = 1; |
51 |
public static final int IMPORT_BINARY = 1; |
| 56 |
public static final int IMPORT_BINARY_WITH_LINKS = 2; |
52 |
public static final int IMPORT_BINARY_WITH_LINKS = 2; |
| 57 |
public static final int IMPORT_WITH_SOURCE = 3; |
53 |
public static final int IMPORT_WITH_SOURCE = 3; |
| 58 |
|
54 |
|
|
|
55 |
private static final String DEFAULT_SOURCE_DIR = "src"; //$NON-NLS-1$ |
| 56 |
private static final String DEFAULT_LIBRARY_NAME = "."; //$NON-NLS-1$ |
| 57 |
|
| 59 |
private IPluginModelBase[] fModels; |
58 |
private IPluginModelBase[] fModels; |
| 60 |
private int fImportType; |
59 |
private int fImportType; |
| 61 |
private IImportQuery fReplaceQuery; |
60 |
private IImportQuery fReplaceQuery; |
|
Lines 63-73
Link Here
|
| 63 |
private boolean fForceAutobuild; |
62 |
private boolean fForceAutobuild; |
| 64 |
private IImportQuery fExecutionQuery; |
63 |
private IImportQuery fExecutionQuery; |
| 65 |
|
64 |
|
| 66 |
private boolean fLaunchedConfigurations = false; |
65 |
private boolean fPluginsAreInUse = false; |
| 67 |
/** |
|
|
| 68 |
* A list of plugins that were unable to be deleted |
| 69 |
*/ |
| 70 |
private ArrayList fUnableToDeletePlugins; |
| 71 |
|
66 |
|
| 72 |
public interface IImportQuery { |
67 |
public interface IImportQuery { |
| 73 |
public static final int CANCEL = 0; |
68 |
public static final int CANCEL = 0; |
|
Lines 83-189
Link Here
|
| 83 |
* @param importType one of three types specified by constants, binary, binary with links, source |
78 |
* @param importType one of three types specified by constants, binary, binary with links, source |
| 84 |
* @param replaceQuery defines what to do if the project already exists in the workspace |
79 |
* @param replaceQuery defines what to do if the project already exists in the workspace |
| 85 |
* @param executionQuery defines what to do if the project requires an unsupported execution environment |
80 |
* @param executionQuery defines what to do if the project requires an unsupported execution environment |
|
|
81 |
* @param forceAutobuild whether to force a build after the import |
| 86 |
*/ |
82 |
*/ |
| 87 |
public PluginImportOperation(IPluginModelBase[] models, int importType, IImportQuery replaceQuery, IImportQuery executionQuery) { |
83 |
public PluginImportOperation(IPluginModelBase[] models, int importType, IImportQuery replaceQuery, IImportQuery executionQuery, boolean forceAutobuild) { |
|
|
84 |
super(PDEUIMessages.ImportWizard_title); |
| 88 |
fModels = models; |
85 |
fModels = models; |
| 89 |
fImportType = importType; |
86 |
fImportType = importType; |
| 90 |
fReplaceQuery = replaceQuery; |
87 |
fReplaceQuery = replaceQuery; |
| 91 |
fExecutionQuery = executionQuery; |
88 |
fExecutionQuery = executionQuery; |
| 92 |
fUnableToDeletePlugins = new ArrayList(); |
89 |
fForceAutobuild = forceAutobuild; |
| 93 |
} |
90 |
} |
| 94 |
|
91 |
|
| 95 |
/** |
92 |
/** |
| 96 |
* Constructor |
93 |
* Sets whether some of the plug-ins being imported are currently in use by a launched |
| 97 |
* @param models models of plugins to import |
94 |
* Eclipse instance. Setting this to true will force an additional check before deleting |
| 98 |
* @param importType one of three types specified by constants, binary, binary with links, source |
95 |
* a plug-in. |
| 99 |
* @param replaceQuery defines what to do if the project already exists in the workspace |
96 |
* @param pluginsInUse |
| 100 |
* @param executionQuery defines what to do if the project requires an unsupported execution environment |
|
|
| 101 |
* @param forceAutobuild whether to force a build after the import |
| 102 |
*/ |
97 |
*/ |
| 103 |
public PluginImportOperation(IPluginModelBase[] models, int importType, IImportQuery replaceQuery, IImportQuery executionQuery, boolean forceAutobuild) { |
98 |
public void setPluginsInUse(boolean pluginsInUse) { |
| 104 |
this(models, importType, replaceQuery, executionQuery); |
99 |
fPluginsAreInUse = pluginsInUse; |
| 105 |
fForceAutobuild = forceAutobuild; |
|
|
| 106 |
} |
100 |
} |
| 107 |
|
101 |
|
| 108 |
/* (non-Javadoc) |
102 |
/* (non-Javadoc) |
| 109 |
* @see org.eclipse.core.resources.IWorkspaceRunnable#run(org.eclipse.core.runtime.IProgressMonitor) |
103 |
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) |
| 110 |
*/ |
104 |
*/ |
| 111 |
public void run(IProgressMonitor monitor) throws CoreException, OperationCanceledException { |
105 |
protected IStatus run(IProgressMonitor monitor) { |
| 112 |
if (monitor == null) { |
|
|
| 113 |
monitor = new NullProgressMonitor(); |
| 114 |
} |
| 115 |
monitor.beginTask(PDEUIMessages.ImportWizard_operation_creating, fModels.length + 1); |
| 116 |
try { |
106 |
try { |
|
|
107 |
monitor.beginTask(PDEUIMessages.ImportWizard_operation_creating, fModels.length + 1); |
| 117 |
MultiStatus multiStatus = new MultiStatus(PDEPlugin.getPluginId(), IStatus.OK, PDEUIMessages.ImportWizard_operation_multiProblem, null); |
108 |
MultiStatus multiStatus = new MultiStatus(PDEPlugin.getPluginId(), IStatus.OK, PDEUIMessages.ImportWizard_operation_multiProblem, null); |
| 118 |
|
109 |
|
| 119 |
for (int i = 0; i < fModels.length; i++) { |
110 |
for (int i = 0; i < fModels.length; i++) { |
|
|
111 |
monitor.setTaskName(NLS.bind(PDEUIMessages.PluginImportOperation_Importing_plugin, fModels[i].getPluginBase().getId())); |
| 120 |
try { |
112 |
try { |
| 121 |
importPlugin(fModels[i], new SubProgressMonitor(monitor, 1)); |
113 |
importPlugin(fModels[i], new SubProgressMonitor(monitor, 1)); |
| 122 |
} catch (CoreException e) { |
114 |
} catch (CoreException e) { |
| 123 |
multiStatus.merge(e.getStatus()); |
115 |
multiStatus.merge(e.getStatus()); |
| 124 |
} |
116 |
} |
| 125 |
if (monitor.isCanceled()) { |
117 |
if (monitor.isCanceled()) { |
| 126 |
setClasspaths(new SubProgressMonitor(monitor, 1)); |
118 |
try { |
| 127 |
throw new OperationCanceledException(); |
119 |
setClasspaths(new SubProgressMonitor(monitor, 1)); |
|
|
120 |
} catch (JavaModelException e) { |
| 121 |
/* Do nothing as we are already cancelled */ |
| 122 |
} |
| 123 |
return Status.CANCEL_STATUS; |
| 128 |
} |
124 |
} |
| 129 |
} |
125 |
} |
| 130 |
setClasspaths(new SubProgressMonitor(monitor, 1)); |
126 |
try { |
|
|
127 |
setClasspaths(new SubProgressMonitor(monitor, 1)); |
| 128 |
} catch (JavaModelException e) { |
| 129 |
multiStatus.merge(e.getStatus()); |
| 130 |
} |
| 131 |
if (!ResourcesPlugin.getWorkspace().isAutoBuilding() && fForceAutobuild) |
131 |
if (!ResourcesPlugin.getWorkspace().isAutoBuilding() && fForceAutobuild) |
| 132 |
runBuildJob(); |
132 |
runBuildJob(); |
| 133 |
if (!multiStatus.isOK()) |
133 |
return multiStatus; |
| 134 |
throw new CoreException(multiStatus); |
|
|
| 135 |
} finally { |
134 |
} finally { |
| 136 |
monitor.done(); |
135 |
monitor.done(); |
| 137 |
if (!fUnableToDeletePlugins.isEmpty()) { |
|
|
| 138 |
final Display display = Display.getDefault(); |
| 139 |
display.syncExec(new Runnable() { |
| 140 |
public void run() { |
| 141 |
PluginImportFinishDialog dialog = new PluginImportFinishDialog(display.getActiveShell()); |
| 142 |
dialog.setTitle(PDEUIMessages.PluginImportInfoDialog_title); |
| 143 |
dialog.setMessage(PDEUIMessages.PluginImportInfoDialog_message); |
| 144 |
dialog.setInput(fUnableToDeletePlugins); |
| 145 |
dialog.open(); |
| 146 |
} |
| 147 |
|
| 148 |
}); |
| 149 |
} |
| 150 |
} |
136 |
} |
| 151 |
} |
137 |
} |
| 152 |
|
138 |
|
| 153 |
/** |
139 |
/** |
| 154 |
* Starts a job that will build the workspace |
|
|
| 155 |
*/ |
| 156 |
private void runBuildJob() { |
| 157 |
Job buildJob = new Job(PDEUIMessages.CompilersConfigurationBlock_building) { |
| 158 |
public boolean belongsTo(Object family) { |
| 159 |
return ResourcesPlugin.FAMILY_AUTO_BUILD == family; |
| 160 |
} |
| 161 |
|
| 162 |
protected IStatus run(IProgressMonitor monitor) { |
| 163 |
try { |
| 164 |
PDEPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor); |
| 165 |
} catch (CoreException e) { |
| 166 |
} |
| 167 |
return Status.OK_STATUS; |
| 168 |
} |
| 169 |
}; |
| 170 |
buildJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule()); |
| 171 |
buildJob.schedule(); |
| 172 |
} |
| 173 |
|
| 174 |
/** |
| 175 |
* Sets the raw classpath of projects that need to be updated |
140 |
* Sets the raw classpath of projects that need to be updated |
| 176 |
* @param monitor |
141 |
* @param monitor |
| 177 |
* @throws JavaModelException if a classpath could not be set |
142 |
* @throws JavaModelException if a classpath could not be set |
| 178 |
*/ |
143 |
*/ |
| 179 |
private void setClasspaths(IProgressMonitor monitor) throws JavaModelException { |
144 |
private void setClasspaths(IProgressMonitor monitor) throws JavaModelException { |
| 180 |
monitor.beginTask("", fProjectClasspaths.size()); //$NON-NLS-1$ |
145 |
try { |
| 181 |
Enumeration keys = fProjectClasspaths.keys(); |
146 |
monitor.beginTask("", fProjectClasspaths.size()); //$NON-NLS-1$ |
| 182 |
while (keys.hasMoreElements()) { |
147 |
Enumeration keys = fProjectClasspaths.keys(); |
| 183 |
IProject project = (IProject) keys.nextElement(); |
148 |
while (keys.hasMoreElements()) { |
| 184 |
IClasspathEntry[] classpath = (IClasspathEntry[]) fProjectClasspaths.get(project); |
149 |
IProject project = (IProject) keys.nextElement(); |
| 185 |
monitor.subTask(project.getName()); |
150 |
IClasspathEntry[] classpath = (IClasspathEntry[]) fProjectClasspaths.get(project); |
| 186 |
JavaCore.create(project).setRawClasspath(classpath, new SubProgressMonitor(monitor, 1)); |
151 |
monitor.subTask(project.getName()); |
|
|
152 |
JavaCore.create(project).setRawClasspath(classpath, new SubProgressMonitor(monitor, 1)); |
| 153 |
} |
| 154 |
} finally { |
| 155 |
monitor.done(); |
| 187 |
} |
156 |
} |
| 188 |
} |
157 |
} |
| 189 |
|
158 |
|
|
Lines 196-314
Link Here
|
| 196 |
* @throws CoreException if a problem occurs while importing a plugin |
165 |
* @throws CoreException if a problem occurs while importing a plugin |
| 197 |
*/ |
166 |
*/ |
| 198 |
private void importPlugin(IPluginModelBase model, IProgressMonitor monitor) throws CoreException { |
167 |
private void importPlugin(IPluginModelBase model, IProgressMonitor monitor) throws CoreException { |
| 199 |
String id = model.getPluginBase().getId(); |
|
|
| 200 |
monitor.beginTask(NLS.bind(PDEUIMessages.ImportWizard_operation_creating2, id), 6); |
| 201 |
try { |
168 |
try { |
| 202 |
BundleDescription desc = model.getBundleDescription(); |
169 |
monitor.beginTask("", 5); //$NON-NLS-1$ |
| 203 |
if (desc != null) { |
|
|
| 204 |
IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager(); |
| 205 |
String[] envs = desc.getExecutionEnvironments(); |
| 206 |
boolean found = false; |
| 207 |
for (int i = 0; i < envs.length; i++) { |
| 208 |
if (manager.getEnvironment(envs[i]) != null) { |
| 209 |
found = true; |
| 210 |
break; |
| 211 |
} |
| 212 |
} |
| 213 |
if (envs.length > 0 && !found) { |
| 214 |
String message = NLS.bind(PDEUIMessages.PluginImportOperation_executionEnvironment, id, envs[0]); |
| 215 |
if (!queryExecutionEnvironment(message)) |
| 216 |
return; |
| 217 |
} |
| 218 |
} |
| 219 |
|
170 |
|
| 220 |
IProject project = findProject(id); |
171 |
// Test is the required execution environment is supported |
| 221 |
|
172 |
if (!testExecutionEnvironment(model)) { |
| 222 |
if (project.exists() || new File(project.getParent().getLocation().toFile(), project.getName()).exists()) { |
173 |
return; |
| 223 |
if (!queryReplace(project)) |
|
|
| 224 |
return; |
| 225 |
if (RepositoryProvider.isShared(project)) |
| 226 |
RepositoryProvider.unmap(project); |
| 227 |
if (!project.exists()) |
| 228 |
project.create(new SubProgressMonitor(monitor, 1)); |
| 229 |
if (!safeDeleteCheck(project, monitor)) { |
| 230 |
fUnableToDeletePlugins.add(model); |
| 231 |
return; |
| 232 |
} |
| 233 |
try { |
| 234 |
project.delete(true, true, monitor); |
| 235 |
} catch (CoreException e) { |
| 236 |
fUnableToDeletePlugins.add(model); |
| 237 |
return; |
| 238 |
} |
| 239 |
} |
174 |
} |
|
|
175 |
// Create the project or ask to overwrite if project exists |
| 176 |
IProject project = createProject(model, new SubProgressMonitor(monitor, 1)); |
| 240 |
|
177 |
|
| 241 |
project.create(monitor); |
178 |
// Target Weaving: if we are importing plug-ins in the runtime workbench from the host workbench, import everything as-is and return |
| 242 |
if (!project.isOpen()) |
|
|
| 243 |
project.open(monitor); |
| 244 |
monitor.worked(1); |
| 245 |
|
| 246 |
if (Platform.inDevelopmentMode()) { |
179 |
if (Platform.inDevelopmentMode()) { |
| 247 |
// if we are importing plug-ins in the runtime workbench from the host workbench, import everything as-is and return |
|
|
| 248 |
File location = new File(model.getInstallLocation()); |
180 |
File location = new File(model.getInstallLocation()); |
| 249 |
if (location.isDirectory()) { |
181 |
if (location.isDirectory()) { |
| 250 |
File classpathFile = new File(location, ".classpath"); //$NON-NLS-1$ |
182 |
File classpathFile = new File(location, ".classpath"); //$NON-NLS-1$ |
| 251 |
File projectFile = new File(location, ".project"); //$NON-NLS-1$ |
183 |
File projectFile = new File(location, ".project"); //$NON-NLS-1$ |
| 252 |
if (classpathFile.exists() && classpathFile.isFile() && projectFile.exists() && projectFile.isFile()) { |
184 |
if (classpathFile.exists() && classpathFile.isFile() && projectFile.exists() && projectFile.isFile()) { |
| 253 |
importContent(location, project.getFullPath(), FileSystemStructureProvider.INSTANCE, null, new SubProgressMonitor(monitor, 1)); |
185 |
PluginImportHelper.importContent(location, project.getFullPath(), FileSystemStructureProvider.INSTANCE, null, new SubProgressMonitor(monitor, 4)); |
| 254 |
return; |
186 |
return; |
| 255 |
} |
187 |
} |
| 256 |
} |
188 |
} |
| 257 |
} |
189 |
} |
| 258 |
|
190 |
|
| 259 |
switch (fImportType) { |
191 |
// Perform the import |
| 260 |
case IMPORT_BINARY : |
192 |
Map sourceMap = null; |
| 261 |
importAsBinary(project, model, true, new SubProgressMonitor(monitor, 4)); |
193 |
if (fImportType == IMPORT_BINARY || isExempt(model)) { |
| 262 |
break; |
194 |
sourceMap = importAsBinary(project, model, new SubProgressMonitor(monitor, 4)); |
| 263 |
case IMPORT_BINARY_WITH_LINKS : |
195 |
} else if (fImportType == IMPORT_BINARY_WITH_LINKS) { |
| 264 |
if (id.startsWith("org.eclipse.swt") && !isJARd(model)) { //$NON-NLS-1$ |
196 |
sourceMap = importAsBinaryWithLinks(project, model, new SubProgressMonitor(monitor, 4)); |
| 265 |
importAsBinary(project, model, true, monitor); |
197 |
} else if (fImportType == IMPORT_WITH_SOURCE) { |
| 266 |
} else { |
198 |
importAsSource(project, model, new SubProgressMonitor(monitor, 4)); |
| 267 |
importAsBinaryWithLinks(project, model, new SubProgressMonitor(monitor, 4)); |
|
|
| 268 |
} |
| 269 |
break; |
| 270 |
case IMPORT_WITH_SOURCE : |
| 271 |
if (isExempt(model)) { |
| 272 |
importAsBinary(project, model, true, new SubProgressMonitor(monitor, 4)); |
| 273 |
} else { |
| 274 |
importAsSource(project, model, new SubProgressMonitor(monitor, 4)); |
| 275 |
} |
| 276 |
} |
199 |
} |
| 277 |
|
200 |
|
| 278 |
setProjectDescription(project, model); |
201 |
setProjectNatures(project, model); |
| 279 |
|
202 |
|
|
|
203 |
// Set the classpath |
| 280 |
if (project.hasNature(JavaCore.NATURE_ID) && project.findMember(".classpath") == null) //$NON-NLS-1$ |
204 |
if (project.hasNature(JavaCore.NATURE_ID) && project.findMember(".classpath") == null) //$NON-NLS-1$ |
| 281 |
fProjectClasspaths.put(project, ClasspathComputer.getClasspath(project, model, true, false)); |
205 |
fProjectClasspaths.put(project, ClasspathComputer.getClasspath(project, model, sourceMap, true, false)); |
| 282 |
} catch (CoreException e) { |
|
|
| 283 |
PDEPlugin.logException(e); |
| 284 |
} finally { |
206 |
} finally { |
| 285 |
monitor.done(); |
207 |
monitor.done(); |
| 286 |
} |
208 |
} |
| 287 |
} |
209 |
} |
| 288 |
|
210 |
|
| 289 |
// Returns the name of any projects the currently exist with same id and version. Otherwise it returns a default naming convention |
211 |
/** |
| 290 |
protected String getProjectName(IPluginModelBase model) { |
212 |
* Imports the contents of the plugin and imports source files as binary files that will not be compiled. |
| 291 |
String id = model.getPluginBase().getId(); |
213 |
* @param project destination project of the import |
| 292 |
String version = model.getPluginBase().getVersion(); |
214 |
* @param model model representing the plugin to import |
| 293 |
ModelEntry entry = PluginRegistry.findEntry(id); |
215 |
* @param monitor progress monitor |
| 294 |
if (entry != null) { |
216 |
* @return a mapping of libraries to source locations to use in the classpath |
| 295 |
IPluginModelBase[] existingModels = entry.getWorkspaceModels(); |
217 |
* @throws CoreException if there is a problem completing the import |
| 296 |
for (int i = 0; i < existingModels.length; i++) { |
218 |
*/ |
| 297 |
String existingVersion = existingModels[i].getPluginBase().getVersion(); |
219 |
private Map importAsBinary(IProject project, IPluginModelBase model, IProgressMonitor monitor) throws CoreException { |
| 298 |
if (version.equals(existingVersion)) { |
220 |
try { |
| 299 |
IResource res = existingModels[i].getUnderlyingResource(); |
221 |
monitor.beginTask("", 3); //$NON-NLS-1$ |
| 300 |
if (res != null) |
222 |
|
| 301 |
return res.getProject().getName(); |
223 |
// Import the plug-in content |
|
|
224 |
File srcFile = new File(model.getInstallLocation()); |
| 225 |
if (isJARd(model)) { |
| 226 |
PluginImportHelper.copyArchive(srcFile, project.getFile(srcFile.getName()), new SubProgressMonitor(monitor, 1)); |
| 227 |
} else { |
| 228 |
PluginImportHelper.importContent(new File(model.getInstallLocation()), project.getFullPath(), FileSystemStructureProvider.INSTANCE, null, new SubProgressMonitor(monitor, 1)); |
| 229 |
} |
| 230 |
|
| 231 |
// Import source from known source locations |
| 232 |
Map sourceMap = importSourceArchives(project, model, IMPORT_BINARY, new SubProgressMonitor(monitor, 1)); |
| 233 |
|
| 234 |
// Extract the required bundle files and modify the imported manifest to have the correct classpath |
| 235 |
importRequiredPluginFiles(project, model, new SubProgressMonitor(monitor, 1)); |
| 236 |
modifyBundleClasspathHeader(project, model); |
| 237 |
|
| 238 |
// Mark the project as binary |
| 239 |
project.setPersistentProperty(PDECore.EXTERNAL_PROJECT_PROPERTY, PDECore.BINARY_PROJECT_VALUE); |
| 240 |
RepositoryProvider.map(project, PDECore.BINARY_REPOSITORY_PROVIDER); |
| 241 |
|
| 242 |
return sourceMap; |
| 243 |
|
| 244 |
} finally { |
| 245 |
monitor.done(); |
| 246 |
} |
| 247 |
} |
| 248 |
|
| 249 |
/** |
| 250 |
* Creates links to remote plugin and source locations and sets up the project |
| 251 |
* @param project destination project of the import |
| 252 |
* @param model model representing the plugin to import |
| 253 |
* @param monitor progress monitor |
| 254 |
* @return mapping of library name to path to source library (relative to project) |
| 255 |
* @throws CoreException if there is a problem completing the import |
| 256 |
*/ |
| 257 |
private Map importAsBinaryWithLinks(IProject project, IPluginModelBase model, IProgressMonitor monitor) throws CoreException { |
| 258 |
try { |
| 259 |
monitor.beginTask("", 3); //$NON-NLS-1$ |
| 260 |
|
| 261 |
// Link the plug-in content |
| 262 |
File srcFile = new File(model.getInstallLocation()); |
| 263 |
IFile dstFile = project.getFile(new Path(srcFile.getName())); |
| 264 |
dstFile.createLink(srcFile.toURI(), IResource.NONE, new SubProgressMonitor(monitor, 1)); |
| 265 |
|
| 266 |
// Link source from known source locations |
| 267 |
Map sourceMap = importSourceArchives(project, model, IMPORT_BINARY_WITH_LINKS, new SubProgressMonitor(monitor, 1)); |
| 268 |
|
| 269 |
// Extract the required bundle files and modify the imported manifest to have the correct classpath |
| 270 |
importRequiredPluginFiles(project, model, new SubProgressMonitor(monitor, 1)); |
| 271 |
modifyBundleClasspathHeader(project, model); |
| 272 |
|
| 273 |
// Mark the project as binary |
| 274 |
project.setPersistentProperty(PDECore.EXTERNAL_PROJECT_PROPERTY, PDECore.BINARY_PROJECT_VALUE); |
| 275 |
RepositoryProvider.map(project, PDECore.BINARY_REPOSITORY_PROVIDER); |
| 276 |
|
| 277 |
return sourceMap; |
| 278 |
|
| 279 |
} finally { |
| 280 |
monitor.done(); |
| 281 |
} |
| 282 |
} |
| 283 |
|
| 284 |
/** |
| 285 |
* Imports the contents of the plugin and imports source files to source folders that will be compiled. |
| 286 |
* @param project destination project of the import |
| 287 |
* @param model model representing the plugin to import |
| 288 |
* @param monitor progress monitor |
| 289 |
* @throws CoreException if there is a problem completing the import |
| 290 |
*/ |
| 291 |
private void importAsSource(IProject project, IPluginModelBase model, SubProgressMonitor monitor) throws CoreException { |
| 292 |
try { |
| 293 |
monitor.beginTask("", 4); //$NON-NLS-1$ |
| 294 |
|
| 295 |
// Extract the source |
| 296 |
WorkspaceBuildModel buildModel = extractSourceFolders(project, model, new SubProgressMonitor(monitor, 1)); |
| 297 |
|
| 298 |
// Extract additional non-java files from the source bundles |
| 299 |
importAdditionalSourceFiles(project, model, new SubProgressMonitor(monitor, 1)); |
| 300 |
|
| 301 |
// Extract the binary plug-in (for non-class files) |
| 302 |
File srcFile = new File(model.getInstallLocation()); |
| 303 |
if (isJARd(model)) { |
| 304 |
PluginImportHelper.extractArchive(srcFile, project.getFullPath(), new SubProgressMonitor(monitor, 1)); |
| 305 |
} else { |
| 306 |
// TODO This might put everything into a folder, which is bad |
| 307 |
PluginImportHelper.importContent(new File(model.getInstallLocation()), project.getFullPath(), FileSystemStructureProvider.INSTANCE, null, new SubProgressMonitor(monitor, 1)); |
| 308 |
} |
| 309 |
|
| 310 |
// Create the build.properties file |
| 311 |
configureBinIncludes(buildModel, model, project); |
| 312 |
buildModel.save(); |
| 313 |
monitor.worked(1); |
| 314 |
|
| 315 |
} finally { |
| 316 |
monitor.done(); |
| 317 |
} |
| 318 |
|
| 319 |
} |
| 320 |
|
| 321 |
/** |
| 322 |
* Creates the project to add to the workspace. If the project already exists in |
| 323 |
* the workspace ask the user if it is ok to overwrite. Will return <code>null</code> |
| 324 |
* if no project could be created for the import (i.e. the user chooses to not overwrite). |
| 325 |
* |
| 326 |
* @param model plug-in being imported |
| 327 |
* @param monitor progress monitor |
| 328 |
* @return the project to use or <code>null</code> if no project could be created/overwritten |
| 329 |
* @throws TeamException if an existing project is shared and an error occurs disconnecting it |
| 330 |
* @throws CoreException if an error occurs when working with the project |
| 331 |
*/ |
| 332 |
private IProject createProject(IPluginModelBase model, IProgressMonitor monitor) throws TeamException, CoreException { |
| 333 |
try { |
| 334 |
monitor.beginTask("", 2); //$NON-NLS-1$ |
| 335 |
IProject project = findProject(model.getPluginBase().getId()); |
| 336 |
if (project.exists() || new File(project.getParent().getLocation().toFile(), project.getName()).exists()) { |
| 337 |
// Query the user to see if we should overwrite |
| 338 |
switch (fReplaceQuery.doQuery(NLS.bind(PDEUIMessages.ImportWizard_messages_exists, project.getName()))) { |
| 339 |
case IImportQuery.CANCEL : |
| 340 |
throw new OperationCanceledException(); |
| 341 |
case IImportQuery.NO : |
| 342 |
return null; |
| 302 |
} |
343 |
} |
|
|
344 |
if (RepositoryProvider.isShared(project)) |
| 345 |
RepositoryProvider.unmap(project); |
| 346 |
if (!project.exists()) |
| 347 |
project.create(new SubProgressMonitor(monitor, 1)); |
| 348 |
if (!safeDeleteCheck(project, monitor)) { |
| 349 |
throw new CoreException(new Status(IStatus.ERROR, PDEPlugin.getPluginId(), NLS.bind(PDEUIMessages.PluginImportOperation_could_not_delete_project, project.getName()))); |
| 350 |
} |
| 351 |
project.delete(true, true, monitor); |
| 303 |
} |
352 |
} |
|
|
353 |
|
| 354 |
project.create(monitor); |
| 355 |
if (!project.isOpen()) |
| 356 |
project.open(monitor); |
| 357 |
monitor.worked(1); |
| 358 |
|
| 359 |
return project; |
| 360 |
|
| 361 |
} finally { |
| 362 |
monitor.done(); |
| 304 |
} |
363 |
} |
| 305 |
return id + "_" + version; //$NON-NLS-1$ |
|
|
| 306 |
} |
364 |
} |
| 307 |
|
365 |
|
| 308 |
// returns true if it is safe to delete the project. It is not safe to delete if |
366 |
private IProject findProject(String id) { |
| 309 |
// one of its libraries is locked by a running launch configuration. |
367 |
IPluginModelBase model = PluginRegistry.findModel(id); |
|
|
368 |
if (model != null) { |
| 369 |
IResource resource = model.getUnderlyingResource(); |
| 370 |
if (resource != null) |
| 371 |
return resource.getProject(); |
| 372 |
} |
| 373 |
return PDEPlugin.getWorkspace().getRoot().getProject(id); |
| 374 |
} |
| 375 |
|
| 376 |
/** |
| 377 |
* Returns true if it is safe to delete the project. It is not safe to delete if |
| 378 |
* one of its libraries is locked by a running launch configuration. |
| 379 |
* |
| 380 |
* @param project project to test |
| 381 |
* @param monitor progress monitor |
| 382 |
* @return true is it is safe to delete the project, false otherwise |
| 383 |
*/ |
| 310 |
private boolean safeDeleteCheck(IProject project, IProgressMonitor monitor) { |
384 |
private boolean safeDeleteCheck(IProject project, IProgressMonitor monitor) { |
| 311 |
if (!fLaunchedConfigurations) |
385 |
if (!fPluginsAreInUse) |
| 312 |
return true; |
386 |
return true; |
| 313 |
IPluginModelBase base = PluginRegistry.findModel(project); |
387 |
IPluginModelBase base = PluginRegistry.findModel(project); |
| 314 |
if (base != null) { |
388 |
if (base != null) { |
|
Lines 328-622
Link Here
|
| 328 |
} |
402 |
} |
| 329 |
|
403 |
|
| 330 |
/** |
404 |
/** |
| 331 |
* Imports the contents of the plugin and adds links to the source location(s). |
405 |
* Tests whether the required execution environment of the given plugin is supported by |
| 332 |
* @param project destination project of the import |
406 |
* the current known JREs. If not, ask the user whether to continue. |
| 333 |
* @param model model representing the plugin to import |
407 |
* @param model the plug-in model to test |
| 334 |
* @param monitor progress monitor |
408 |
* @return true is the import should continue, false if the plug-in should be skipped |
| 335 |
* @throws CoreException if there is a problem completing the import |
409 |
* @throws OperationCanceledException if the user chooses to cancel the operation |
| 336 |
*/ |
410 |
*/ |
| 337 |
private void importAsBinaryWithLinks(IProject project, IPluginModelBase model, IProgressMonitor monitor) throws CoreException { |
411 |
private boolean testExecutionEnvironment(IPluginModelBase model) throws OperationCanceledException { |
| 338 |
if (isJARd(model)) { |
412 |
BundleDescription desc = model.getBundleDescription(); |
| 339 |
extractJARdPlugin(project, model, monitor); |
413 |
if (desc != null) { |
| 340 |
} else { |
414 |
IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager(); |
| 341 |
File installLocation = new File(model.getInstallLocation()); |
415 |
String[] envs = desc.getExecutionEnvironments(); |
| 342 |
File[] items = installLocation.listFiles(); |
416 |
boolean found = false; |
| 343 |
if (items != null) { |
417 |
for (int i = 0; i < envs.length; i++) { |
| 344 |
monitor.beginTask(PDEUIMessages.PluginImportOperation_linking, items.length + 1); |
418 |
if (manager.getEnvironment(envs[i]) != null) { |
| 345 |
for (int i = 0; i < items.length; i++) { |
419 |
found = true; |
| 346 |
File sourceFile = items[i]; |
420 |
break; |
| 347 |
String name = sourceFile.getName(); |
421 |
} |
| 348 |
if (sourceFile.isDirectory()) { |
422 |
} |
| 349 |
project.getFolder(name).createLink(new Path(sourceFile.getPath()), IResource.NONE, new SubProgressMonitor(monitor, 1)); |
423 |
if (envs.length > 0 && !found) { |
| 350 |
} else { |
424 |
switch (fExecutionQuery.doQuery(NLS.bind(PDEUIMessages.PluginImportOperation_executionEnvironment, model.getPluginBase().getId(), envs[0]))) { |
| 351 |
if (!name.equals(".project")) { //$NON-NLS-1$ |
425 |
case IImportQuery.CANCEL : |
| 352 |
project.getFile(name).createLink(new Path(sourceFile.getPath()), IResource.NONE, new SubProgressMonitor(monitor, 1)); |
426 |
throw new OperationCanceledException(); |
| 353 |
} else { |
427 |
case IImportQuery.NO : |
| 354 |
// if the binary project with links has a .project file, copy it instead of linking (allows us to edit it) |
428 |
return false; |
| 355 |
ArrayList filesToImport = new ArrayList(1); |
|
|
| 356 |
filesToImport.add(sourceFile); |
| 357 |
importContent(installLocation, project.getFullPath(), FileSystemStructureProvider.INSTANCE, filesToImport, new SubProgressMonitor(monitor, 1)); |
| 358 |
} |
| 359 |
} |
| 360 |
} |
429 |
} |
| 361 |
} |
430 |
} |
| 362 |
linkSourceArchives(project, model, new SubProgressMonitor(monitor, 1)); |
|
|
| 363 |
} |
| 364 |
try { |
| 365 |
RepositoryProvider.map(project, PDECore.BINARY_REPOSITORY_PROVIDER); |
| 366 |
} catch (TeamException e) { |
| 367 |
PDECore.logException(e); |
| 368 |
} |
431 |
} |
|
|
432 |
return true; |
| 369 |
} |
433 |
} |
| 370 |
|
434 |
|
| 371 |
/** |
435 |
/** |
| 372 |
* Imports the contents of the plugin and imports source files as binary files that will not be compiled. |
436 |
* Returns true if the given plugin must be imported as |
| 373 |
* @param project destination project of the import |
437 |
* binary instead of the setting defined by fImportType |
| 374 |
* @param model model representing the plugin to import |
438 |
* @param model |
| 375 |
* @param markAsBinary whether to mark the project as a binary project |
439 |
* @return true is the plugin must be imported as binary, false otherwise |
| 376 |
* @param monitor progress monitor |
|
|
| 377 |
* @throws CoreException if there is a problem completing the import |
| 378 |
*/ |
440 |
*/ |
| 379 |
private void importAsBinary(IProject project, IPluginModelBase model, boolean markAsBinary, IProgressMonitor monitor) throws CoreException { |
441 |
private boolean isExempt(IPluginModelBase model) { |
| 380 |
monitor.beginTask("", 4); //$NON-NLS-1$ |
442 |
String id = model.getPluginBase().getId(); |
| 381 |
if (isJARd(model)) { |
443 |
if (fImportType == IMPORT_WITH_SOURCE) { |
| 382 |
extractJARdPlugin(project, model, new SubProgressMonitor(monitor, 3)); |
444 |
if ("org.apache.ant".equals(id) //$NON-NLS-1$ |
| 383 |
} else { |
445 |
|| "org.eclipse.osgi.util".equals(id) //$NON-NLS-1$ |
| 384 |
importContent(new File(model.getInstallLocation()), project.getFullPath(), FileSystemStructureProvider.INSTANCE, null, new SubProgressMonitor(monitor, 1)); |
446 |
|| "org.eclipse.osgi.services".equals(id) //$NON-NLS-1$ |
| 385 |
importSourceArchives(project, model, new SubProgressMonitor(monitor, 1)); |
447 |
|| "org.eclipse.core.runtime.compatibility.registry".equals(id)) { //$NON-NLS-1$ |
|
|
448 |
return true; |
| 449 |
} |
| 450 |
} |
| 451 |
|
| 452 |
if ("org.eclipse.swt".equals(id) && !isJARd(model)) //$NON-NLS-1$ |
| 453 |
return true; |
| 454 |
return false; |
| 455 |
} |
| 386 |
|
456 |
|
| 387 |
// make sure all libraries have been imported |
457 |
/** |
| 388 |
// if any are missing, check in fragments |
458 |
* Starts a job that will build the workspace |
| 389 |
IFragment[] fragments = getFragmentsFor(model); |
459 |
*/ |
| 390 |
IPluginLibrary[] libraries = model.getPluginBase().getLibraries(); |
460 |
private void runBuildJob() { |
|
|
461 |
Job buildJob = new Job(PDEUIMessages.CompilersConfigurationBlock_building) { |
| 462 |
public boolean belongsTo(Object family) { |
| 463 |
return ResourcesPlugin.FAMILY_AUTO_BUILD == family; |
| 464 |
} |
| 391 |
|
465 |
|
| 392 |
IProgressMonitor fragmentMonitor = new SubProgressMonitor(monitor, 1); |
466 |
protected IStatus run(IProgressMonitor monitor) { |
| 393 |
fragmentMonitor.beginTask("", libraries.length); //$NON-NLS-1$ |
467 |
try { |
| 394 |
for (int i = 0; i < libraries.length; i++) { |
468 |
PDEPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor); |
| 395 |
String libraryName = libraries[i].getName(); |
469 |
} catch (CoreException e) { |
| 396 |
if (ClasspathUtilCore.containsVariables(libraryName) && !project.exists(new Path(ClasspathUtilCore.expandLibraryName(libraryName)))) { |
|
|
| 397 |
for (int j = 0; j < fragments.length; j++) { |
| 398 |
importJarFromFragment(project, fragments[j], libraryName); |
| 399 |
importSourceFromFragment(project, fragments[j], libraryName, new SubProgressMonitor(monitor, 1)); |
| 400 |
} |
| 401 |
} else { |
| 402 |
monitor.worked(1); |
| 403 |
} |
470 |
} |
|
|
471 |
return Status.OK_STATUS; |
| 404 |
} |
472 |
} |
| 405 |
} |
473 |
}; |
| 406 |
if (markAsBinary) { |
474 |
buildJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule()); |
| 407 |
project.setPersistentProperty(PDECore.EXTERNAL_PROJECT_PROPERTY, PDECore.BINARY_PROJECT_VALUE); |
475 |
buildJob.schedule(); |
| 408 |
importAdditionalResources(project, model, new SubProgressMonitor(monitor, 1)); |
|
|
| 409 |
} else { |
| 410 |
monitor.done(); |
| 411 |
} |
| 412 |
} |
476 |
} |
| 413 |
|
477 |
|
| 414 |
/** |
478 |
/** |
| 415 |
* Imports the contents of the plugin and imports source files to source folders that will be compiled. |
479 |
* Imports the source archives required by the project either by copying or linking, based on the mode |
| 416 |
* @param project destination project of the import |
480 |
* constant that is passed to the method (IMPORT_BINARY or IMPORT_BINARY_WITH_LINKS). |
| 417 |
* @param model model representing the plugin to import |
481 |
* @param project project destination |
|
|
482 |
* @param model model we are importing |
| 483 |
* @param mode either IMPORT_BINARY (copies source) or MPORT_BINARY_WITH_LINKS (links source) |
| 418 |
* @param monitor progress monitor |
484 |
* @param monitor progress monitor |
| 419 |
* @throws CoreException if there is a problem completing the import |
485 |
* @return mapping of library name to the source location |
|
|
486 |
* @throws CoreException if there are problems importing an archive |
| 420 |
*/ |
487 |
*/ |
| 421 |
private void importAsSource(IProject project, IPluginModelBase model, SubProgressMonitor monitor) throws CoreException { |
488 |
private Map importSourceArchives(IProject project, IPluginModelBase model, int mode, IProgressMonitor monitor) throws CoreException { |
| 422 |
monitor.beginTask("", 4); //$NON-NLS-1$ |
489 |
String[] libraries = getLibraryNames(model); |
| 423 |
importAsBinary(project, model, false, new SubProgressMonitor(monitor, 2)); |
490 |
try { |
| 424 |
List list = importAdditionalResources(project, model, new SubProgressMonitor(monitor, 1)); |
491 |
monitor.beginTask(PDEUIMessages.ImportWizard_operation_importingSource, libraries.length); |
| 425 |
WorkspaceBuildModel buildModel = new WorkspaceBuildModel(project.getFile("build.properties")); //$NON-NLS-1$ |
492 |
|
| 426 |
if (!isJARd(model) || containsCode(new File(model.getInstallLocation()))) { |
493 |
Map sourceMap = new HashMap(libraries.length); |
| 427 |
String[] libraries = getLibraryNames(model, false); |
494 |
SourceLocationManager manager = PDECore.getDefault().getSourceLocationManager(); |
| 428 |
if (libraries.length == 0) |
|
|
| 429 |
libraries = new String[] {"."}; //$NON-NLS-1$ |
| 430 |
for (int i = 0; i < libraries.length; i++) { |
495 |
for (int i = 0; i < libraries.length; i++) { |
| 431 |
if (ClasspathUtilCore.containsVariables(libraries[i])) |
496 |
String zipName = ClasspathUtilCore.getSourceZipName(libraries[i]); |
| 432 |
continue; |
497 |
IPath srcPath = manager.findSourcePath(model.getPluginBase(), new Path(zipName)); |
| 433 |
String name = ClasspathUtilCore.expandLibraryName(libraries[i]); |
498 |
if (srcPath != null) { |
| 434 |
IPath libraryPath = (name.equals(".") && isJARd(model)) //$NON-NLS-1$ |
499 |
zipName = srcPath.lastSegment(); |
| 435 |
? new Path(new File(model.getInstallLocation()).getName()) |
500 |
IPath dstPath = new Path(zipName); |
| 436 |
: new Path(name); |
501 |
sourceMap.put(libraries[i], dstPath); |
| 437 |
IResource jarFile = project.findMember(libraryPath); |
502 |
if (project.findMember(dstPath) == null) { |
| 438 |
if (jarFile != null) { |
503 |
if (mode == IMPORT_BINARY) { |
| 439 |
String srcName = ClasspathUtilCore.getSourceZipName(libraryPath.lastSegment()); |
504 |
PluginImportHelper.copyArchive(new File(srcPath.toOSString()), project.getFile(dstPath), new SubProgressMonitor(monitor, 1)); |
| 440 |
IResource srcZip = jarFile.getProject().findMember(srcName); |
505 |
} else if (mode == IMPORT_BINARY_WITH_LINKS) { |
| 441 |
if (srcZip == null) { |
506 |
IFile dstFile = project.getFile(dstPath); |
| 442 |
int extIndex = srcName.lastIndexOf('.'); |
507 |
dstFile.createLink(srcPath, IResource.NONE, new SubProgressMonitor(monitor, 1)); |
| 443 |
if (extIndex != -1) { |
|
|
| 444 |
srcZip = jarFile.getProject().findMember(srcName.substring(0, extIndex)); |
| 445 |
} |
| 446 |
} |
| 447 |
// srcZip == null if plug-in has embedded source |
| 448 |
// if it jarred, all necessary files already in src folder |
| 449 |
if (srcZip == null && libraries[i].equals(".") && !isJARd(model)) //$NON-NLS-1$ |
| 450 |
// if src does not exist (and returns null), then must not be plug-in with embedded source |
| 451 |
srcZip = jarFile.getProject().findMember("src"); //$NON-NLS-1$ |
| 452 |
if (srcZip != null) { |
| 453 |
String jarName = libraries[i].equals(".") ? "" : libraryPath.removeFileExtension().lastSegment(); //$NON-NLS-1$ //$NON-NLS-2$ |
| 454 |
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$ |
| 455 |
IFolder dest = jarFile.getProject().getFolder(folder); |
| 456 |
|
| 457 |
if (srcZip instanceof IFolder) { |
| 458 |
// if the source (srcZip) equals the destination folder (dest), then we don't want to delete/copy since every |
| 459 |
// is already where it needs to be. This happens when importing source bundles in folder format declaring source with ext. point. (bug 214542) |
| 460 |
if (!srcZip.equals(dest)) { |
| 461 |
if (dest.exists()) { |
| 462 |
dest.delete(true, null); |
| 463 |
} |
| 464 |
((IFolder) srcZip).move(dest.getFullPath(), true, new SubProgressMonitor(monitor, 1)); |
| 465 |
} |
| 466 |
} else if (srcZip instanceof IFile) { |
| 467 |
if (!dest.exists()) { |
| 468 |
dest.create(true, true, null); |
| 469 |
} |
| 470 |
extractZipFile(srcZip.getLocation().toFile(), dest.getFullPath(), new SubProgressMonitor(monitor, 1)); |
| 471 |
srcZip.delete(true, null); |
| 472 |
} else |
| 473 |
monitor.worked(1); |
| 474 |
|
| 475 |
if (jarFile instanceof IFile) { |
| 476 |
if (isJARd(model)) { |
| 477 |
extractJavaResources(jarFile.getLocation().toFile(), dest, new SubProgressMonitor(monitor, 1)); |
| 478 |
} else { |
| 479 |
extractResources(jarFile.getLocation().toFile(), dest, new SubProgressMonitor(monitor, 1)); |
| 480 |
} |
| 481 |
jarFile.delete(true, null); |
| 482 |
} else { |
| 483 |
moveBinaryContents((IContainer) jarFile, dest, new SubProgressMonitor(monitor, 1)); |
| 484 |
} |
508 |
} |
| 485 |
} |
509 |
} |
| 486 |
} else if (name.equals(".") && project.getFolder("src").exists()) { //$NON-NLS-1$ //$NON-NLS-2$ |
|
|
| 487 |
addBuildEntry(buildModel, "source..", "src/"); //$NON-NLS-1$ //$NON-NLS-2$ |
| 488 |
} |
510 |
} |
| 489 |
} |
511 |
} |
|
|
512 |
return sourceMap; |
| 513 |
} finally { |
| 514 |
monitor.done(); |
| 490 |
} |
515 |
} |
| 491 |
configureBinIncludes(buildModel, model, project); |
|
|
| 492 |
if (list.size() > 0) |
| 493 |
configureSrcIncludes(buildModel, list); |
| 494 |
buildModel.save(); |
| 495 |
} |
516 |
} |
| 496 |
|
517 |
|
| 497 |
/** |
518 |
/** |
| 498 |
* Moves the binary files from the source container to the folder destination. |
519 |
* Looks up the source locations for the plug-in and imports the source for each library. Each source root is |
| 499 |
* Moves any file that isn't a .class file |
520 |
* extracted to a source folder in the project and a build model containing the source entries is returned. |
| 500 |
* @param srcFolder container to move from |
521 |
* |
| 501 |
* @param dest folder to move to |
522 |
* @param project destination project |
|
|
523 |
* @param model plug-in being imported |
| 502 |
* @param monitor progress monitor |
524 |
* @param monitor progress monitor |
|
|
525 |
* @return a workspace build model containing entries for each created source folder |
| 526 |
* @throws CoreException if there is a problem extracting the source or creating a build entry |
| 503 |
*/ |
527 |
*/ |
| 504 |
private void moveBinaryContents(IContainer srcFolder, IFolder dest, IProgressMonitor monitor) { |
528 |
private WorkspaceBuildModel extractSourceFolders(IProject project, IPluginModelBase model, IProgressMonitor monitor) throws CoreException { |
| 505 |
try { |
529 |
try { |
| 506 |
// get all the folders for which we want to search |
530 |
String[] libraries = getLibraryNames(model); |
| 507 |
IResource[] children = dest.members(); |
531 |
monitor.beginTask(PDEUIMessages.ImportWizard_operation_importingSource, libraries.length); |
| 508 |
ArrayList validFolders = new ArrayList(); |
|
|
| 509 |
for (int i = 0; i < children.length; i++) |
| 510 |
if (children[i] instanceof IFolder) { |
| 511 |
String folderName = children[i].getName(); |
| 512 |
IResource folder = srcFolder.findMember(folderName); |
| 513 |
if (folder != null && folder instanceof IFolder) |
| 514 |
validFolders.add(folder); |
| 515 |
} |
| 516 |
|
532 |
|
| 517 |
monitor.beginTask(new String(), validFolders.size()); |
533 |
WorkspaceBuildModel buildModel = new WorkspaceBuildModel(project.getFile("build.properties")); //$NON-NLS-1$ |
|
|
534 |
SourceLocationManager manager = PDECore.getDefault().getSourceLocationManager(); |
| 518 |
|
535 |
|
| 519 |
ListIterator li = validFolders.listIterator(); |
536 |
// Need to do different things based on whether we have a individual source bundle or the old style separated zips |
| 520 |
while (li.hasNext()) { |
537 |
if (manager.hasBundleManifestLocation(model.getPluginBase())) { |
| 521 |
IFolder folder = (IFolder) li.next(); |
538 |
File srcFile = manager.findSourcePlugin(model.getPluginBase()); |
| 522 |
int pathSegments = folder.getProjectRelativePath().segmentCount() - 1; |
539 |
Set sourceRoots = manager.findSourceRoots(model.getPluginBase()); |
| 523 |
Stack stack = new Stack(); |
540 |
for (int i = 0; i < libraries.length; i++) { |
| 524 |
IResource[] resources = folder.members(); |
541 |
if (libraries[i].equals(DEFAULT_LIBRARY_NAME)) { |
| 525 |
for (int i = 0; i < resources.length; i++) |
542 |
// Need to pull out any java source that is not in another source root |
| 526 |
stack.push(resources[i]); |
543 |
IResource destination = project.getFolder(DEFAULT_SOURCE_DIR); |
| 527 |
|
544 |
if (!destination.exists()) { |
| 528 |
while (!stack.isEmpty()) { |
545 |
List excludeFolders = new ArrayList(sourceRoots.size()); |
| 529 |
IResource res = (IResource) stack.pop(); |
546 |
for (Iterator iterator = sourceRoots.iterator(); iterator.hasNext();) { |
| 530 |
if (res instanceof IFile) { |
547 |
String root = (String) iterator.next(); |
| 531 |
if (!res.getName().endsWith(".class")) { //$NON-NLS-1$ |
548 |
if (!root.equals(DEFAULT_LIBRARY_NAME)) { |
| 532 |
String pathName = res.getProjectRelativePath().removeFirstSegments(pathSegments).toString(); |
549 |
excludeFolders.add(new Path(root)); |
| 533 |
IFile destFile = dest.getFile(pathName); |
550 |
} |
| 534 |
if (!destFile.getParent().exists()) { |
|
|
| 535 |
CoreUtility.createFolder((IFolder) destFile.getParent()); |
| 536 |
} |
551 |
} |
| 537 |
// file might exist if previous project was deleted without removing underlying resources |
552 |
PluginImportHelper.extractJavaSourceFromArchive(srcFile, excludeFolders, destination.getFullPath(), new SubProgressMonitor(monitor, 1)); |
| 538 |
if (destFile.exists()) |
553 |
addBuildEntry(buildModel, "source." + DEFAULT_LIBRARY_NAME, DEFAULT_SOURCE_DIR + "/"); //$NON-NLS-1$ //$NON-NLS-2$ |
| 539 |
destFile.delete(true, null); |
554 |
} |
| 540 |
res.move(destFile.getFullPath(), true, null); |
555 |
} else if (sourceRoots.contains(getSourceDirName(libraries[i]))) { |
|
|
556 |
IPath sourceDir = new Path(getSourceDirName(libraries[i])); |
| 557 |
IResource destination = project.getFolder(sourceDir); |
| 558 |
if (!destination.exists()) { |
| 559 |
PluginImportHelper.extractFolderFromArchive(srcFile, sourceDir, destination.getFullPath(), new SubProgressMonitor(monitor, 1)); |
| 560 |
addBuildEntry(buildModel, "source." + libraries[i], sourceDir.toString()); //$NON-NLS-1$ |
| 561 |
} |
| 562 |
} |
| 563 |
} |
| 564 |
} else { |
| 565 |
// Old style, zips in folders, determine the source zip name/location and extract it to the project |
| 566 |
for (int i = 0; i < libraries.length; i++) { |
| 567 |
String zipName = ClasspathUtilCore.getSourceZipName(libraries[i]); |
| 568 |
IPath srcPath = manager.findSourcePath(model.getPluginBase(), new Path(zipName)); |
| 569 |
if (srcPath != null) { |
| 570 |
IPath dstPath = new Path(getSourceDirName(libraries[i])); |
| 571 |
IResource destination = project.getFolder(dstPath); |
| 572 |
if (!destination.exists()) { |
| 573 |
PluginImportHelper.extractArchive(new File(srcPath.toOSString()), destination.getFullPath(), new SubProgressMonitor(monitor, 1)); |
| 574 |
addBuildEntry(buildModel, "source." + libraries[i], dstPath.toString()); //$NON-NLS-1$ |
| 541 |
} |
575 |
} |
| 542 |
} else { |
|
|
| 543 |
resources = ((IFolder) res).members(); |
| 544 |
for (int i = 0; i < resources.length; i++) |
| 545 |
stack.push(resources[i]); |
| 546 |
} |
576 |
} |
| 547 |
} |
577 |
} |
| 548 |
folder.delete(true, null); |
|
|
| 549 |
monitor.worked(1); |
| 550 |
} |
578 |
} |
| 551 |
} catch (CoreException e) { |
579 |
return buildModel; |
|
|
580 |
} finally { |
| 581 |
monitor.done(); |
| 552 |
} |
582 |
} |
| 553 |
} |
583 |
} |
| 554 |
|
584 |
|
| 555 |
/** |
585 |
/** |
| 556 |
* Searches source locations for files to import to the new project, will ignore |
586 |
* Extracts any additional files and folders that exist in the source location |
| 557 |
* src.zip. |
587 |
* @param project the destination project |
| 558 |
* @param project destination project of the import |
588 |
* @param model the plugin being imported |
| 559 |
* @param model model representing the plugin to import |
|
|
| 560 |
* @param monitor progress monitor |
589 |
* @param monitor progress monitor |
| 561 |
* @return list of imported files |
590 |
* @throws CoreException is there is a problem importing the files |
| 562 |
* @throws CoreException if there is a problem completing the import |
|
|
| 563 |
*/ |
591 |
*/ |
| 564 |
private List importAdditionalResources(IProject project, IPluginModelBase model, SubProgressMonitor monitor) throws CoreException { |
592 |
private void importAdditionalSourceFiles(IProject project, IPluginModelBase model, SubProgressMonitor monitor) throws CoreException { |
| 565 |
SourceLocationManager manager = PDECore.getDefault().getSourceLocationManager(); |
593 |
File sourceLocation = PDECore.getDefault().getSourceLocationManager().findSourcePlugin(model.getPluginBase()); |
| 566 |
File location = manager.findSourcePlugin(model.getPluginBase()); |
594 |
if (sourceLocation != null) { |
| 567 |
if (location != null) { |
595 |
if (sourceLocation.isFile()) { |
| 568 |
ArrayList list = new ArrayList(); |
596 |
ArrayList collected = new ArrayList(); |
| 569 |
if (location.isDirectory()) { |
597 |
ZipFileStructureProvider provider = null; |
| 570 |
Object root = location; |
|
|
| 571 |
File[] children = location.listFiles(); |
| 572 |
if (children != null) { |
| 573 |
for (int i = 0; i < children.length; i++) { |
| 574 |
String name = children[i].getName(); |
| 575 |
if (!project.exists(new Path(name)) && !"src.zip".equals(name)) { //$NON-NLS-1$ |
| 576 |
list.add(children[i]); |
| 577 |
} |
| 578 |
} |
| 579 |
importContent(root, project.getFullPath(), FileSystemStructureProvider.INSTANCE, list, monitor); |
| 580 |
ArrayList srcEntryList = new ArrayList(list.size()); |
| 581 |
for (ListIterator iterator = list.listIterator(); iterator.hasNext();) { |
| 582 |
File current = (File) iterator.next(); |
| 583 |
String entry = current.getName(); |
| 584 |
if (current.isDirectory()) { |
| 585 |
entry += "/"; //$NON-NLS-1$ |
| 586 |
} |
| 587 |
srcEntryList.add(entry); |
| 588 |
} |
| 589 |
return srcEntryList; |
| 590 |
} |
| 591 |
} else if (location.isFile()) { |
| 592 |
ZipFile zipFile = null; |
| 593 |
try { |
598 |
try { |
| 594 |
zipFile = new ZipFile(location); |
599 |
provider = new ZipFileStructureProvider(new ZipFile(sourceLocation)); |
| 595 |
ZipFileStructureProvider zipProvider = new ZipFileStructureProvider(zipFile); |
|
|
| 596 |
Object root = zipProvider.getRoot(); |
| 597 |
collectAdditionalResources(zipProvider, root, list, project); |
| 598 |
importContent(root, project.getFullPath(), zipProvider, list, monitor); |
| 599 |
ArrayList srcEntryList = new ArrayList(list.size()); |
| 600 |
for (Iterator iterator = list.iterator(); iterator.hasNext();) { |
| 601 |
ZipEntry current = (ZipEntry) iterator.next(); |
| 602 |
String entry = current.getName(); |
| 603 |
srcEntryList.add(entry); |
| 604 |
} |
| 605 |
return srcEntryList; |
| 606 |
} catch (IOException e) { |
600 |
} catch (IOException e) { |
| 607 |
IStatus status = new Status(IStatus.ERROR, PDEPlugin.getPluginId(), IStatus.ERROR, e.getMessage(), e); |
601 |
IStatus status = new Status(IStatus.ERROR, PDEPlugin.getPluginId(), IStatus.ERROR, e.getMessage(), e); |
| 608 |
throw new CoreException(status); |
602 |
throw new CoreException(status); |
| 609 |
} finally { |
|
|
| 610 |
if (zipFile != null) { |
| 611 |
try { |
| 612 |
zipFile.close(); |
| 613 |
} catch (IOException e) { |
| 614 |
} |
| 615 |
} |
| 616 |
} |
603 |
} |
|
|
604 |
PluginImportHelper.collectNonJavaFiles(provider, provider.getRoot(), collected); |
| 605 |
PluginImportHelper.importContent(provider.getRoot(), project.getFullPath(), provider, collected, monitor); |
| 606 |
} else { |
| 607 |
// TODO Test how to do directories |
| 608 |
ArrayList collected = new ArrayList(); |
| 609 |
PluginImportHelper.collectNonJavaFiles(FileSystemStructureProvider.INSTANCE, sourceLocation, collected); |
| 610 |
PluginImportHelper.importContent(sourceLocation, project.getFullPath(), FileSystemStructureProvider.INSTANCE, collected, monitor); |
| 617 |
} |
611 |
} |
| 618 |
} |
612 |
} |
| 619 |
return new ArrayList(0); |
613 |
} |
|
|
614 |
|
| 615 |
/** |
| 616 |
* Imports files from the plug-in that are necessary to make the created project a plug-in project. |
| 617 |
* Specifically the manifest and related file are extracted. |
| 618 |
* @param project |
| 619 |
* @param model |
| 620 |
* @param monitor |
| 621 |
* @throws CoreException if there is a problem importing the content |
| 622 |
*/ |
| 623 |
private void importRequiredPluginFiles(IProject project, IPluginModelBase model, IProgressMonitor monitor) throws CoreException { |
| 624 |
if (isJARd(model)) { |
| 625 |
ArrayList collected = new ArrayList(); |
| 626 |
ZipFileStructureProvider provider = null; |
| 627 |
try { |
| 628 |
provider = new ZipFileStructureProvider(new ZipFile(new File(model.getInstallLocation()))); |
| 629 |
} catch (IOException e) { |
| 630 |
IStatus status = new Status(IStatus.ERROR, PDEPlugin.getPluginId(), IStatus.ERROR, e.getMessage(), e); |
| 631 |
throw new CoreException(status); |
| 632 |
} |
| 633 |
PluginImportHelper.collectRequiredBundleFiles(provider, provider.getRoot(), collected); |
| 634 |
PluginImportHelper.importContent(provider.getRoot(), project.getFullPath(), provider, collected, monitor); |
| 635 |
} else { |
| 636 |
ArrayList collected = new ArrayList(); |
| 637 |
File file = new File(model.getInstallLocation()); |
| 638 |
PluginImportHelper.collectRequiredBundleFiles(FileSystemStructureProvider.INSTANCE, file, collected); |
| 639 |
PluginImportHelper.importContent(file, project.getFullPath(), FileSystemStructureProvider.INSTANCE, collected, monitor); |
| 640 |
} |
| 641 |
} |
| 642 |
|
| 643 |
private String addBuildEntry(WorkspaceBuildModel model, String key, String value) throws CoreException { |
| 644 |
IBuild build = model.getBuild(true); |
| 645 |
IBuildEntry entry = build.getEntry(key); |
| 646 |
if (entry == null) { |
| 647 |
entry = model.getFactory().createEntry(key); |
| 648 |
entry.addToken(value); |
| 649 |
build.add(entry); |
| 650 |
} |
| 651 |
String[] tokens = entry.getTokens(); |
| 652 |
return (tokens.length > 0) ? tokens[0] : "src/"; //$NON-NLS-1$ |
| 620 |
} |
653 |
} |
| 621 |
|
654 |
|
| 622 |
private void configureBinIncludes(WorkspaceBuildModel buildModel, IPluginModelBase model, IProject project) throws CoreException { |
655 |
private void configureBinIncludes(WorkspaceBuildModel buildModel, IPluginModelBase model, IProject project) throws CoreException { |
|
Lines 640-646
Link Here
|
| 640 |
entry.addToken(token); |
673 |
entry.addToken(token); |
| 641 |
} |
674 |
} |
| 642 |
} else { |
675 |
} else { |
| 643 |
String[] tokens = getTopLevelResources(location); |
676 |
String[] tokens = PluginImportHelper.getTopLevelResources(location); |
| 644 |
for (int i = 0; i < tokens.length; i++) { |
677 |
for (int i = 0; i < tokens.length; i++) { |
| 645 |
IResource res = project.findMember(tokens[i]); |
678 |
IResource res = project.findMember(tokens[i]); |
| 646 |
if ((res == null) && (build.getEntry(IBuildEntry.JAR_PREFIX + tokens[i]) == null)) |
679 |
if ((res == null) && (build.getEntry(IBuildEntry.JAR_PREFIX + tokens[i]) == null)) |
|
Lines 670-882
Link Here
|
| 670 |
return set; |
703 |
return set; |
| 671 |
} |
704 |
} |
| 672 |
|
705 |
|
| 673 |
private void configureSrcIncludes(WorkspaceBuildModel buildModel, List list) throws CoreException { |
|
|
| 674 |
IBuildEntry entry = buildModel.getBuild(true).getEntry("src.includes"); //$NON-NLS-1$ |
| 675 |
if (entry == null) { |
| 676 |
entry = buildModel.getFactory().createEntry("src.includes"); //$NON-NLS-1$ |
| 677 |
for (int i = 0; i < list.size(); i++) { |
| 678 |
entry.addToken(list.get(i).toString()); |
| 679 |
} |
| 680 |
buildModel.getBuild().add(entry); |
| 681 |
} |
| 682 |
} |
| 683 |
|
| 684 |
private String addBuildEntry(WorkspaceBuildModel model, String key, String value) throws CoreException { |
| 685 |
IBuild build = model.getBuild(true); |
| 686 |
IBuildEntry entry = build.getEntry(key); |
| 687 |
if (entry == null) { |
| 688 |
entry = model.getFactory().createEntry(key); |
| 689 |
entry.addToken(value); |
| 690 |
build.add(entry); |
| 691 |
} |
| 692 |
String[] tokens = entry.getTokens(); |
| 693 |
return (tokens.length > 0) ? tokens[0] : "src/"; //$NON-NLS-1$ |
| 694 |
} |
| 695 |
|
| 696 |
/** |
| 697 |
* Creates links in the project to the source locations for the various libraries. |
| 698 |
* If the source for all libraries is in a single bundle, one link is created |
| 699 |
* @param project destination project of the import |
| 700 |
* @param model model representing the plugin to import |
| 701 |
* @param monitor progress monitor |
| 702 |
* @throws CoreException if there is a problem completing the import |
| 703 |
*/ |
| 704 |
private void linkSourceArchives(IProject project, IPluginModelBase model, IProgressMonitor monitor) throws CoreException { |
| 705 |
String[] libraries = getLibraryNames(model, true); |
| 706 |
monitor.beginTask(PDEUIMessages.ImportWizard_operation_copyingSource, libraries.length); |
| 707 |
|
| 708 |
SourceLocationManager manager = PDECore.getDefault().getSourceLocationManager(); |
| 709 |
if (manager.hasBundleManifestLocation(model.getPluginBase())) { |
| 710 |
IPath srcPath = manager.findSourcePath(model.getPluginBase(), null); |
| 711 |
if (srcPath != null) { |
| 712 |
// Source for all libraries is in the same bundle, just create one link to the source bundle |
| 713 |
IPath path = new Path(project.getName() + "src.zip"); //$NON-NLS-1$ |
| 714 |
IFile srcFile = project.getFile(path.lastSegment()); |
| 715 |
if (!srcFile.exists()) { |
| 716 |
srcFile.createLink(srcPath, IResource.NONE, new SubProgressMonitor(monitor, 1)); |
| 717 |
} |
| 718 |
} |
| 719 |
monitor.worked(libraries.length); |
| 720 |
} else { |
| 721 |
for (int i = 0; i < libraries.length; i++) { |
| 722 |
String zipName = ClasspathUtilCore.getSourceZipName(libraries[i]); |
| 723 |
IPath path = new Path(zipName); |
| 724 |
if (project.findMember(path) == null) { |
| 725 |
IPath srcPath = manager.findSourcePath(model.getPluginBase(), path); |
| 726 |
if (srcPath != null) { |
| 727 |
if ("src.zip".equals(zipName) && isJARd(model)) { //$NON-NLS-1$ |
| 728 |
path = new Path(ClasspathUtilCore.getSourceZipName(new File(model.getInstallLocation()).getName())); |
| 729 |
} |
| 730 |
IFile zipFile = project.getFile(path.lastSegment()); |
| 731 |
if (!zipFile.exists()) { |
| 732 |
zipFile.createLink(srcPath, IResource.NONE, new SubProgressMonitor(monitor, 1)); |
| 733 |
} |
| 734 |
} |
| 735 |
} |
| 736 |
monitor.worked(1); |
| 737 |
} |
| 738 |
} |
| 739 |
monitor.done(); |
| 740 |
} |
| 741 |
|
| 742 |
private void importSourceArchives(IProject project, IPluginModelBase model, IProgressMonitor monitor) throws CoreException { |
| 743 |
String[] libraries = getLibraryNames(model, true); |
| 744 |
monitor.beginTask(PDEUIMessages.ImportWizard_operation_copyingSource, libraries.length); |
| 745 |
|
| 746 |
SourceLocationManager manager = PDECore.getDefault().getSourceLocationManager(); |
| 747 |
|
| 748 |
Set roots = null; |
| 749 |
if (manager.hasBundleManifestLocation(model.getPluginBase())) |
| 750 |
roots = manager.findSourceRoots(model.getPluginBase()); |
| 751 |
|
| 752 |
for (int i = 0; i < libraries.length; i++) { |
| 753 |
String zipName = ClasspathUtilCore.getSourceZipName(libraries[i]); |
| 754 |
IPath path = new Path(zipName); |
| 755 |
if (project.findMember(path) == null) { |
| 756 |
// if we are importing the source through a sourceBundle header... |
| 757 |
if (roots != null) { |
| 758 |
IPath sourceLocation = manager.findSourcePath(model.getPluginBase(), null); |
| 759 |
String currentRoot = ".".equals(libraries[i]) ? "." : path.removeFileExtension().toString(); //$NON-NLS-1$ //$NON-NLS-2$ |
| 760 |
if (roots.contains(currentRoot)) { |
| 761 |
if (".".equals(currentRoot)) { //$NON-NLS-1$ |
| 762 |
// Save to a special folder name based on the install location |
| 763 |
IPath sourceName = getDefaultSourceNameForProject(model); |
| 764 |
sourceName = sourceName.removeFileExtension(); |
| 765 |
IFolder dest = project.getFolder(sourceName); |
| 766 |
if (!dest.exists()) { |
| 767 |
dest.create(true, true, null); |
| 768 |
} |
| 769 |
|
| 770 |
// List all of the other source roots so they are not included when importing source from the root, ".", of the jar |
| 771 |
Set allBundleRoots = manager.findAllSourceRootsInSourceLocation(model.getPluginBase()); |
| 772 |
List rootsToExclude = new ArrayList(allBundleRoots.size() - 1); |
| 773 |
for (Iterator iterator2 = allBundleRoots.iterator(); iterator2.hasNext();) { |
| 774 |
String rootString = (String) iterator2.next(); |
| 775 |
if (!".".equals(rootString)) { //$NON-NLS-1$ |
| 776 |
rootsToExclude.add(new Path(rootString)); |
| 777 |
} |
| 778 |
} |
| 779 |
|
| 780 |
// Extract folders containing java source |
| 781 |
extractJavaSource(new File(sourceLocation.toOSString()), rootsToExclude, dest, monitor); |
| 782 |
} else { |
| 783 |
// Extract the specific library from it's folder |
| 784 |
extractResourcesFromFolder(new File(sourceLocation.toOSString()), new Path(currentRoot), project, monitor); |
| 785 |
} |
| 786 |
} |
| 787 |
} else { |
| 788 |
IPath srcPath = manager.findSourcePath(model.getPluginBase(), path); |
| 789 |
if (srcPath != null) { |
| 790 |
if ("src.zip".equals(zipName) && isJARd(model)) { //$NON-NLS-1$ |
| 791 |
path = getDefaultSourceNameForProject(model); |
| 792 |
} |
| 793 |
importArchive(project, new File(srcPath.toOSString()), path); |
| 794 |
} |
| 795 |
} |
| 796 |
} |
| 797 |
monitor.worked(1); |
| 798 |
} |
| 799 |
monitor.done(); |
| 800 |
} |
| 801 |
|
| 802 |
/** |
706 |
/** |
| 803 |
* Creates a path representing a zip file that is named based on the plugin install location. |
707 |
* Creates a model for an existing manifest file, replacing the classpath entry with the |
| 804 |
* Used to replace src.zip with a more unique and meaningful name. |
708 |
* new location of the referenced library. Also removes any extra entries such as signing |
| 805 |
* @param model model that the src.zip containg source for |
709 |
* headers. |
| 806 |
* @return a new path describing the zip file |
710 |
* @param project |
|
|
711 |
* @param base |
| 807 |
*/ |
712 |
*/ |
| 808 |
private IPath getDefaultSourceNameForProject(IPluginModelBase model) { |
|
|
| 809 |
return new Path(ClasspathUtilCore.getSourceZipName(new File(model.getInstallLocation()).getName())); |
| 810 |
} |
| 811 |
|
| 812 |
private String[] getLibraryNames(IPluginModelBase model, boolean expand) { |
| 813 |
IPluginLibrary[] libraries = model.getPluginBase().getLibraries(); |
| 814 |
ArrayList list = new ArrayList(); |
| 815 |
for (int i = 0; i < libraries.length; i++) { |
| 816 |
if (expand) |
| 817 |
list.add(ClasspathUtilCore.expandLibraryName(libraries[i].getName())); |
| 818 |
else |
| 819 |
list.add(libraries[i].getName()); |
| 820 |
} |
| 821 |
if (libraries.length == 0 && isJARd(model)) |
| 822 |
list.add("."); //$NON-NLS-1$ |
| 823 |
return (String[]) list.toArray(new String[list.size()]); |
| 824 |
} |
| 825 |
|
| 826 |
private void extractJARdPlugin(IProject project, IPluginModelBase model, IProgressMonitor monitor) throws CoreException { |
| 827 |
ZipFile zipFile = null; |
| 828 |
try { |
| 829 |
zipFile = new ZipFile(model.getInstallLocation()); |
| 830 |
ZipFileStructureProvider provider = new ZipFileStructureProvider(zipFile); |
| 831 |
if (!containsCode(provider)) { |
| 832 |
extractZipFile(new File(model.getInstallLocation()), project.getFullPath(), monitor); |
| 833 |
return; |
| 834 |
} |
| 835 |
ArrayList collected = new ArrayList(); |
| 836 |
collectNonJavaResources(provider, provider.getRoot(), collected); |
| 837 |
importContent(provider.getRoot(), project.getFullPath(), provider, collected, monitor); |
| 838 |
|
| 839 |
File file = new File(model.getInstallLocation()); |
| 840 |
if (hasEmbeddedSource(provider) && fImportType == IMPORT_WITH_SOURCE) { |
| 841 |
collected = new ArrayList(); |
| 842 |
collectJavaFiles(provider, provider.getRoot(), collected); |
| 843 |
importContent(provider.getRoot(), project.getFullPath(), provider, collected, monitor); |
| 844 |
collected = new ArrayList(); |
| 845 |
collectJavaResources(provider, provider.getRoot(), collected); |
| 846 |
importContent(provider.getRoot(), project.getFullPath().append("src"), provider, collected, monitor); //$NON-NLS-1$ |
| 847 |
} else { |
| 848 |
if (fImportType == IMPORT_BINARY_WITH_LINKS) { |
| 849 |
project.getFile(file.getName()).createLink(new Path(file.getAbsolutePath()), IResource.NONE, null); |
| 850 |
} else { |
| 851 |
importArchive(project, file, new Path(file.getName())); |
| 852 |
} |
| 853 |
if (!hasEmbeddedSource(provider)) { |
| 854 |
if (fImportType == IMPORT_BINARY_WITH_LINKS) { |
| 855 |
linkSourceArchives(project, model, new SubProgressMonitor(monitor, 1)); |
| 856 |
} else { |
| 857 |
importSourceArchives(project, model, new SubProgressMonitor(monitor, 1)); |
| 858 |
} |
| 859 |
} |
| 860 |
} |
| 861 |
if (fImportType != IMPORT_WITH_SOURCE) { |
| 862 |
modifyBundleClasspathHeader(project, model); |
| 863 |
} else { |
| 864 |
removeSignedHeaders(project); |
| 865 |
} |
| 866 |
setPermissions(model, project); |
| 867 |
} catch (IOException e) { |
| 868 |
IStatus status = new Status(IStatus.ERROR, PDEPlugin.getPluginId(), IStatus.ERROR, e.getMessage(), e); |
| 869 |
throw new CoreException(status); |
| 870 |
} finally { |
| 871 |
if (zipFile != null) { |
| 872 |
try { |
| 873 |
zipFile.close(); |
| 874 |
} catch (IOException e) { |
| 875 |
} |
| 876 |
} |
| 877 |
} |
| 878 |
} |
| 879 |
|
| 880 |
private void modifyBundleClasspathHeader(IProject project, IPluginModelBase base) { |
713 |
private void modifyBundleClasspathHeader(IProject project, IPluginModelBase base) { |
| 881 |
IFile file = project.getFile(JarFile.MANIFEST_NAME); |
714 |
IFile file = project.getFile(JarFile.MANIFEST_NAME); |
| 882 |
if (file.exists()) { |
715 |
if (file.exists()) { |
|
Lines 908-959
Link Here
|
| 908 |
} |
741 |
} |
| 909 |
} |
742 |
} |
| 910 |
|
743 |
|
| 911 |
private void removeSignedHeaders(IProject project) { |
|
|
| 912 |
IFile file = project.getFile(JarFile.MANIFEST_NAME); |
| 913 |
if (!file.exists()) |
| 914 |
return; |
| 915 |
WorkspaceBundleModel model = new WorkspaceBundleModel(file); |
| 916 |
model.save(); |
| 917 |
} |
| 918 |
|
| 919 |
private IProject findProject(String id) { |
| 920 |
IPluginModelBase model = PluginRegistry.findModel(id); |
| 921 |
if (model != null) { |
| 922 |
IResource resource = model.getUnderlyingResource(); |
| 923 |
if (resource != null) |
| 924 |
return resource.getProject(); |
| 925 |
} |
| 926 |
return PDEPlugin.getWorkspace().getRoot().getProject(id); |
| 927 |
} |
| 928 |
|
| 929 |
private boolean queryReplace(IProject project) throws OperationCanceledException { |
| 930 |
switch (fReplaceQuery.doQuery(NLS.bind(PDEUIMessages.ImportWizard_messages_exists, project.getName()))) { |
| 931 |
case IImportQuery.CANCEL : |
| 932 |
throw new OperationCanceledException(); |
| 933 |
case IImportQuery.NO : |
| 934 |
return false; |
| 935 |
} |
| 936 |
return true; |
| 937 |
} |
| 938 |
|
| 939 |
private boolean queryExecutionEnvironment(String message) throws OperationCanceledException { |
| 940 |
switch (fExecutionQuery.doQuery(message)) { |
| 941 |
case IImportQuery.CANCEL : |
| 942 |
throw new OperationCanceledException(); |
| 943 |
case IImportQuery.NO : |
| 944 |
return false; |
| 945 |
} |
| 946 |
return true; |
| 947 |
} |
| 948 |
|
| 949 |
private void setProjectDescription(IProject project, IPluginModelBase model) throws CoreException { |
| 950 |
IProjectDescription desc = project.getDescription(); |
| 951 |
if (!desc.hasNature(PDE.PLUGIN_NATURE)) |
| 952 |
CoreUtility.addNatureToProject(project, PDE.PLUGIN_NATURE, null); |
| 953 |
if (needsJavaNature(project, model) && !desc.hasNature(JavaCore.NATURE_ID)) |
| 954 |
CoreUtility.addNatureToProject(project, JavaCore.NATURE_ID, null); |
| 955 |
} |
| 956 |
|
| 957 |
private boolean needsJavaNature(IProject project, IPluginModelBase model) { |
744 |
private boolean needsJavaNature(IProject project, IPluginModelBase model) { |
| 958 |
if (model.getPluginBase().getLibraries().length > 0) |
745 |
if (model.getPluginBase().getLibraries().length > 0) |
| 959 |
return true; |
746 |
return true; |
|
Lines 970-1100
Link Here
|
| 970 |
return false; |
757 |
return false; |
| 971 |
} |
758 |
} |
| 972 |
|
759 |
|
| 973 |
private boolean isExempt(IPluginModelBase model) { |
760 |
private void setProjectNatures(IProject project, IPluginModelBase model) throws CoreException { |
| 974 |
String id = model.getPluginBase().getId(); |
761 |
IProjectDescription desc = project.getDescription(); |
| 975 |
if ("org.apache.ant".equals(id) //$NON-NLS-1$ |
762 |
if (!desc.hasNature(PDE.PLUGIN_NATURE)) |
| 976 |
|| "org.eclipse.osgi.util".equals(id) //$NON-NLS-1$ |
763 |
CoreUtility.addNatureToProject(project, PDE.PLUGIN_NATURE, null); |
| 977 |
|| "org.eclipse.osgi.services".equals(id) //$NON-NLS-1$ |
764 |
if (needsJavaNature(project, model) && !desc.hasNature(JavaCore.NATURE_ID)) |
| 978 |
|| "org.eclipse.core.runtime.compatibility.registry".equals(id)) //$NON-NLS-1$ |
765 |
CoreUtility.addNatureToProject(project, JavaCore.NATURE_ID, null); |
| 979 |
return true; |
|
|
| 980 |
|
| 981 |
if ("org.eclipse.swt".equals(id) && !isJARd(model)) //$NON-NLS-1$ |
| 982 |
return true; |
| 983 |
return false; |
| 984 |
} |
| 985 |
|
| 986 |
private boolean isJARd(IPluginModelBase model) { |
| 987 |
return new File(model.getInstallLocation()).isFile(); |
| 988 |
} |
| 989 |
|
| 990 |
private void setPermissions(IPluginModelBase model, IProject project) { |
| 991 |
try { |
| 992 |
if (!Platform.getOS().equals(Constants.OS_WIN32) && model instanceof IFragmentModel) { |
| 993 |
IFragment fragment = ((IFragmentModel) model).getFragment(); |
| 994 |
if ("org.eclipse.swt".equals(fragment.getPluginId())) { //$NON-NLS-1$ |
| 995 |
IResource[] children = project.members(); |
| 996 |
for (int i = 0; i < children.length; i++) { |
| 997 |
if (children[i] instanceof IFile && isInterestingResource(children[i].getName())) { |
| 998 |
Runtime.getRuntime().exec(new String[] {"chmod", "755", children[i].getLocation().toOSString()}).waitFor(); //$NON-NLS-1$ //$NON-NLS-2$ |
| 999 |
} |
| 1000 |
} |
| 1001 |
} |
| 1002 |
} |
| 1003 |
} catch (CoreException e) { |
| 1004 |
} catch (InterruptedException e) { |
| 1005 |
} catch (IOException e) { |
| 1006 |
} |
| 1007 |
} |
| 1008 |
|
| 1009 |
private boolean isInterestingResource(String name) { |
| 1010 |
return name.endsWith(".jnilib") //$NON-NLS-1$ |
| 1011 |
|| name.endsWith(".sl") //$NON-NLS-1$ |
| 1012 |
|| name.endsWith(".a") //$NON-NLS-1$ |
| 1013 |
|| name.indexOf(".so") != -1; //$NON-NLS-1$ |
| 1014 |
} |
| 1015 |
|
| 1016 |
private IFragment[] getFragmentsFor(IPluginModelBase model) { |
| 1017 |
ArrayList result = new ArrayList(); |
| 1018 |
for (int i = 0; i < fModels.length; i++) { |
| 1019 |
if (fModels[i] instanceof IFragmentModel) { |
| 1020 |
HostSpecification spec = fModels[i].getBundleDescription().getHost(); |
| 1021 |
BundleDescription host = spec == null ? null : (BundleDescription) spec.getSupplier(); |
| 1022 |
if (model.getBundleDescription().equals(host)) { |
| 1023 |
result.add(((IFragmentModel) fModels[i]).getFragment()); |
| 1024 |
} |
| 1025 |
} |
| 1026 |
} |
| 1027 |
return (IFragment[]) result.toArray(new IFragment[result.size()]); |
| 1028 |
} |
| 1029 |
|
| 1030 |
private void importJarFromFragment(IProject project, IFragment fragment, String name) throws CoreException { |
| 1031 |
IPath jarPath = new Path(ClasspathUtilCore.expandLibraryName(name)); |
| 1032 |
File jar = new File(fragment.getModel().getInstallLocation(), jarPath.toString()); |
| 1033 |
if (jar.exists()) { |
| 1034 |
importArchive(project, jar, jarPath); |
| 1035 |
} |
| 1036 |
} |
766 |
} |
| 1037 |
|
767 |
|
| 1038 |
/** |
768 |
/** |
| 1039 |
* Imports the source for a library from a fragment. |
769 |
* Gets the list of libraries from the model and returns an array of their expanded |
| 1040 |
* @param project destination project of the import |
770 |
* names. Will add the default library name if no libraries are specified. |
| 1041 |
* @param fragment fragment to import the library from |
771 |
* @param model |
| 1042 |
* @param libraryName name of the library to import, |
772 |
* @return list of library names |
| 1043 |
* @param monitor progress monitor |
|
|
| 1044 |
* @throws CoreException if there is a problem completing the import |
| 1045 |
*/ |
773 |
*/ |
| 1046 |
private void importSourceFromFragment(IProject project, IFragment fragment, String libraryName, IProgressMonitor monitor) throws CoreException { |
774 |
private String[] getLibraryNames(IPluginModelBase model) { |
| 1047 |
try { |
775 |
IPluginLibrary[] libraries = model.getPluginBase().getLibraries(); |
| 1048 |
IPath jarPath = new Path(ClasspathUtilCore.expandLibraryName(libraryName)); |
776 |
ArrayList list = new ArrayList(); |
| 1049 |
String zipName = ClasspathUtilCore.getSourceZipName(jarPath.toString()); |
777 |
for (int i = 0; i < libraries.length; i++) { |
| 1050 |
IPath path = new Path(zipName); |
778 |
list.add(ClasspathUtilCore.expandLibraryName(libraries[i].getName())); |
| 1051 |
if (project.findMember(path) == null) { |
|
|
| 1052 |
SourceLocationManager manager = PDECore.getDefault().getSourceLocationManager(); |
| 1053 |
IPath srcPath = manager.findSourcePath(fragment, path); |
| 1054 |
if (srcPath != null) { |
| 1055 |
if (manager.hasBundleManifestLocation(fragment)) { |
| 1056 |
// Extract the specific library from it's folder |
| 1057 |
extractResourcesFromFolder(new File(srcPath.toOSString()), path.removeFileExtension(), project, monitor); |
| 1058 |
} else { |
| 1059 |
importArchive(project, new File(srcPath.toOSString()), path); |
| 1060 |
} |
| 1061 |
} |
| 1062 |
} |
| 1063 |
} finally { |
| 1064 |
monitor.done(); |
| 1065 |
} |
| 1066 |
} |
| 1067 |
|
| 1068 |
protected void collectAdditionalResources(ZipFileStructureProvider provider, Object element, ArrayList collected, IProject project) { |
| 1069 |
collectAdditionalResources(provider, element, collected); |
| 1070 |
ListIterator li = collected.listIterator(); |
| 1071 |
while (li.hasNext()) { |
| 1072 |
ZipEntry ze = (ZipEntry) li.next(); |
| 1073 |
String name = ze.getName(); |
| 1074 |
// only import the entries that don't already exist |
| 1075 |
if (project.findMember(name) != null) { |
| 1076 |
li.remove(); |
| 1077 |
} |
| 1078 |
} |
779 |
} |
|
|
780 |
if (libraries.length == 0 && isJARd(model)) |
| 781 |
list.add(DEFAULT_LIBRARY_NAME); |
| 782 |
return (String[]) list.toArray(new String[list.size()]); |
| 1079 |
} |
783 |
} |
| 1080 |
|
784 |
|
| 1081 |
protected void collectNonJavaResources(ZipFileStructureProvider provider, Object element, ArrayList collected) { |
785 |
/** |
| 1082 |
super.collectNonJavaResources(provider, element, collected); |
786 |
* Returns the standard source directory name for a library name. |
| 1083 |
if (fImportType != IMPORT_WITH_SOURCE) |
787 |
* Used to get the source root name for a library as well as the |
| 1084 |
return; |
788 |
* standard destination name. |
| 1085 |
// filter the resources we get back to include only relevant resource files |
789 |
* @param libraryName |
| 1086 |
ListIterator li = collected.listIterator(); |
790 |
* @return source dir name |
| 1087 |
while (li.hasNext()) { |
791 |
*/ |
| 1088 |
ZipEntry ze = (ZipEntry) li.next(); |
792 |
private String getSourceDirName(String libraryName) { |
| 1089 |
String name = ze.getName(); |
793 |
int dot = libraryName.lastIndexOf('.'); |
| 1090 |
// filter out signature files - bug 175756 |
794 |
return (dot != -1) ? libraryName.substring(0, dot) + DEFAULT_SOURCE_DIR : libraryName; |
| 1091 |
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$ |
|
|
| 1092 |
li.remove(); |
| 1093 |
} |
| 1094 |
} |
795 |
} |
| 1095 |
|
796 |
|
| 1096 |
public void setLaunchedConfiguration(boolean launchedConfiguration) { |
797 |
/** |
| 1097 |
fLaunchedConfigurations = launchedConfiguration; |
798 |
* Returns whether the install location of the plug-in is a jar file or a folder |
|
|
799 |
* @param model |
| 800 |
* @return true if the install location is a jar, false if it is a folder |
| 801 |
*/ |
| 802 |
private boolean isJARd(IPluginModelBase model) { |
| 803 |
return new File(model.getInstallLocation()).isFile(); |
| 1098 |
} |
804 |
} |
| 1099 |
|
805 |
|
| 1100 |
} |
806 |
} |