|
Lines 38-44
Link Here
|
| 38 |
import org.eclipse.pde.internal.core.util.CoreUtility; |
38 |
import org.eclipse.pde.internal.core.util.CoreUtility; |
| 39 |
import org.eclipse.pde.internal.ui.PDEPlugin; |
39 |
import org.eclipse.pde.internal.ui.PDEPlugin; |
| 40 |
import org.eclipse.pde.internal.ui.PDEUIMessages; |
40 |
import org.eclipse.pde.internal.ui.PDEUIMessages; |
| 41 |
import org.eclipse.swt.widgets.Display; |
|
|
| 42 |
import org.eclipse.team.core.RepositoryProvider; |
41 |
import org.eclipse.team.core.RepositoryProvider; |
| 43 |
import org.eclipse.team.core.TeamException; |
42 |
import org.eclipse.team.core.TeamException; |
| 44 |
import org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider; |
43 |
import org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider; |
|
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-108
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) { |
| 88 |
fModels = models; |
84 |
fModels = models; |
| 89 |
fImportType = importType; |
85 |
fImportType = importType; |
| 90 |
fReplaceQuery = replaceQuery; |
86 |
fReplaceQuery = replaceQuery; |
| 91 |
fExecutionQuery = executionQuery; |
87 |
fExecutionQuery = executionQuery; |
| 92 |
fUnableToDeletePlugins = new ArrayList(); |
88 |
fForceAutobuild = forceAutobuild; |
| 93 |
} |
89 |
} |
| 94 |
|
90 |
|
| 95 |
/** |
91 |
/** |
| 96 |
* Constructor |
92 |
* Sets whether some of the plug-ins being imported are currently in use by a launched |
| 97 |
* @param models models of plugins to import |
93 |
* 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 |
94 |
* a plug-in. |
| 99 |
* @param replaceQuery defines what to do if the project already exists in the workspace |
95 |
* @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 |
*/ |
96 |
*/ |
| 103 |
public PluginImportOperation(IPluginModelBase[] models, int importType, IImportQuery replaceQuery, IImportQuery executionQuery, boolean forceAutobuild) { |
97 |
public void setPluginsInUse(boolean pluginsInUse) { |
| 104 |
this(models, importType, replaceQuery, executionQuery); |
98 |
// TODO Determine if this is actually necessary. |
| 105 |
fForceAutobuild = forceAutobuild; |
99 |
fPluginsAreInUse = pluginsInUse; |
| 106 |
} |
100 |
} |
| 107 |
|
101 |
|
| 108 |
/* (non-Javadoc) |
102 |
/* (non-Javadoc) |
|
Lines 123-177
Link Here
|
| 123 |
multiStatus.merge(e.getStatus()); |
117 |
multiStatus.merge(e.getStatus()); |
| 124 |
} |
118 |
} |
| 125 |
if (monitor.isCanceled()) { |
119 |
if (monitor.isCanceled()) { |
|
|
120 |
// TODO Set classpaths individually |
| 126 |
setClasspaths(new SubProgressMonitor(monitor, 1)); |
121 |
setClasspaths(new SubProgressMonitor(monitor, 1)); |
| 127 |
throw new OperationCanceledException(); |
122 |
throw new OperationCanceledException(); |
| 128 |
} |
123 |
} |
| 129 |
} |
124 |
} |
|
|
125 |
// TODO Set classpaths individually? |
| 130 |
setClasspaths(new SubProgressMonitor(monitor, 1)); |
126 |
setClasspaths(new SubProgressMonitor(monitor, 1)); |
| 131 |
if (!ResourcesPlugin.getWorkspace().isAutoBuilding() && fForceAutobuild) |
127 |
if (!ResourcesPlugin.getWorkspace().isAutoBuilding() && fForceAutobuild) |
| 132 |
runBuildJob(); |
128 |
runBuildJob(); |
|
|
129 |
// TODO Test that non-deleted plug-ins throw nice error status |
| 133 |
if (!multiStatus.isOK()) |
130 |
if (!multiStatus.isOK()) |
| 134 |
throw new CoreException(multiStatus); |
131 |
throw new CoreException(multiStatus); |
| 135 |
} finally { |
132 |
} finally { |
| 136 |
monitor.done(); |
133 |
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 |
} |
134 |
} |
| 151 |
} |
135 |
} |
| 152 |
|
136 |
|
| 153 |
/** |
137 |
/** |
| 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 |
138 |
* Sets the raw classpath of projects that need to be updated |
| 176 |
* @param monitor |
139 |
* @param monitor |
| 177 |
* @throws JavaModelException if a classpath could not be set |
140 |
* @throws JavaModelException if a classpath could not be set |
|
Lines 197-250
Link Here
|
| 197 |
*/ |
160 |
*/ |
| 198 |
private void importPlugin(IPluginModelBase model, IProgressMonitor monitor) throws CoreException { |
161 |
private void importPlugin(IPluginModelBase model, IProgressMonitor monitor) throws CoreException { |
| 199 |
String id = model.getPluginBase().getId(); |
162 |
String id = model.getPluginBase().getId(); |
| 200 |
monitor.beginTask(NLS.bind(PDEUIMessages.ImportWizard_operation_creating2, id), 6); |
|
|
| 201 |
try { |
163 |
try { |
| 202 |
BundleDescription desc = model.getBundleDescription(); |
164 |
monitor.beginTask(NLS.bind(PDEUIMessages.ImportWizard_operation_creating2, id), 6); |
| 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 |
|
| 220 |
IProject project = findProject(id); |
| 221 |
|
165 |
|
| 222 |
if (project.exists() || new File(project.getParent().getLocation().toFile(), project.getName()).exists()) { |
166 |
// Test is the required execution environment is supported |
| 223 |
if (!queryReplace(project)) |
167 |
if (!testExecutionEnvironment(model)) { |
| 224 |
return; |
168 |
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 |
} |
169 |
} |
|
|
170 |
// Create the project or ask to overwrite if project exists |
| 171 |
IProject project = createProject(model, new SubProgressMonitor(monitor, 1)); |
| 240 |
|
172 |
|
| 241 |
project.create(monitor); |
173 |
// 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()) { |
174 |
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()); |
175 |
File location = new File(model.getInstallLocation()); |
| 249 |
if (location.isDirectory()) { |
176 |
if (location.isDirectory()) { |
| 250 |
File classpathFile = new File(location, ".classpath"); //$NON-NLS-1$ |
177 |
File classpathFile = new File(location, ".classpath"); //$NON-NLS-1$ |
|
Lines 256-286
Link Here
|
| 256 |
} |
183 |
} |
| 257 |
} |
184 |
} |
| 258 |
|
185 |
|
|
|
186 |
// Perform the import |
| 187 |
Map sourceMap = null; |
| 259 |
switch (fImportType) { |
188 |
switch (fImportType) { |
| 260 |
case IMPORT_BINARY : |
189 |
case IMPORT_BINARY : |
| 261 |
importAsBinary(project, model, true, new SubProgressMonitor(monitor, 4)); |
190 |
sourceMap = importAsBinary(project, model, new SubProgressMonitor(monitor, 4)); |
| 262 |
break; |
191 |
break; |
| 263 |
case IMPORT_BINARY_WITH_LINKS : |
192 |
case IMPORT_BINARY_WITH_LINKS : |
| 264 |
if (id.startsWith("org.eclipse.swt") && !isJARd(model)) { //$NON-NLS-1$ |
193 |
if (id.startsWith("org.eclipse.swt") && !isJARd(model)) { //$NON-NLS-1$ |
| 265 |
importAsBinary(project, model, true, monitor); |
194 |
importAsBinary(project, model, monitor); |
| 266 |
} else { |
195 |
} else { |
| 267 |
importAsBinaryWithLinks(project, model, new SubProgressMonitor(monitor, 4)); |
196 |
importAsBinaryWithLinks(project, model, new SubProgressMonitor(monitor, 4)); |
| 268 |
} |
197 |
} |
| 269 |
break; |
198 |
break; |
| 270 |
case IMPORT_WITH_SOURCE : |
199 |
case IMPORT_WITH_SOURCE : |
| 271 |
if (isExempt(model)) { |
200 |
if (isExempt(model)) { |
| 272 |
importAsBinary(project, model, true, new SubProgressMonitor(monitor, 4)); |
201 |
importAsBinary(project, model, new SubProgressMonitor(monitor, 4)); |
| 273 |
} else { |
202 |
} else { |
| 274 |
importAsSource(project, model, new SubProgressMonitor(monitor, 4)); |
203 |
importAsSource(project, model, new SubProgressMonitor(monitor, 4)); |
| 275 |
} |
204 |
} |
| 276 |
} |
205 |
} |
| 277 |
|
206 |
|
| 278 |
setProjectDescription(project, model); |
207 |
setProjectNatures(project, model); |
| 279 |
|
208 |
|
|
|
209 |
// Set the classpath |
| 280 |
if (project.hasNature(JavaCore.NATURE_ID) && project.findMember(".classpath") == null) //$NON-NLS-1$ |
210 |
if (project.hasNature(JavaCore.NATURE_ID) && project.findMember(".classpath") == null) //$NON-NLS-1$ |
| 281 |
fProjectClasspaths.put(project, ClasspathComputer.getClasspath(project, model, true, false)); |
211 |
fProjectClasspaths.put(project, ClasspathComputer.getClasspath(project, model, sourceMap, true, false)); |
| 282 |
} catch (CoreException e) { |
212 |
} finally { |
| 283 |
PDEPlugin.logException(e); |
213 |
monitor.done(); |
|
|
214 |
} |
| 215 |
} |
| 216 |
|
| 217 |
/** |
| 218 |
* Creates the project to add to the workspace. If the project already exists in |
| 219 |
* the workspace ask the user if it is ok to overwrite. Will return <code>null</code> |
| 220 |
* if no project could be created for the import (i.e. the user chooses to not overwrite). |
| 221 |
* |
| 222 |
* @param model plug-in being imported |
| 223 |
* @param monitor progress monitor |
| 224 |
* @return the project to use or <code>null</code> if no project could be created/overwritten |
| 225 |
* @throws TeamException if an existing project is shared and an error occurs disconnecting it |
| 226 |
* @throws CoreException if an error occurs when working with the project |
| 227 |
*/ |
| 228 |
private IProject createProject(IPluginModelBase model, IProgressMonitor monitor) throws TeamException, CoreException { |
| 229 |
try { |
| 230 |
monitor.beginTask("Creating the project", 2); |
| 231 |
IProject project = findProject(model.getPluginBase().getId()); |
| 232 |
if (project.exists() || new File(project.getParent().getLocation().toFile(), project.getName()).exists()) { |
| 233 |
// Query the user to see if we should overwrite |
| 234 |
switch (fReplaceQuery.doQuery(NLS.bind(PDEUIMessages.ImportWizard_messages_exists, project.getName()))) { |
| 235 |
case IImportQuery.CANCEL : |
| 236 |
throw new OperationCanceledException(); |
| 237 |
case IImportQuery.NO : |
| 238 |
return null; |
| 239 |
} |
| 240 |
if (RepositoryProvider.isShared(project)) |
| 241 |
RepositoryProvider.unmap(project); |
| 242 |
if (!project.exists()) |
| 243 |
project.create(new SubProgressMonitor(monitor, 1)); |
| 244 |
if (!safeDeleteCheck(project, monitor)) { |
| 245 |
throw new CoreException(new Status(IStatus.ERROR, PDEPlugin.getPluginId(), NLS.bind(PDEUIMessages.PluginImportOperation_could_not_delete_project, project.getName()))); |
| 246 |
} |
| 247 |
project.delete(true, true, monitor); |
| 248 |
} |
| 249 |
|
| 250 |
project.create(monitor); |
| 251 |
if (!project.isOpen()) |
| 252 |
project.open(monitor); |
| 253 |
monitor.worked(1); |
| 254 |
|
| 255 |
return project; |
| 256 |
|
| 284 |
} finally { |
257 |
} finally { |
| 285 |
monitor.done(); |
258 |
monitor.done(); |
| 286 |
} |
259 |
} |
|
Lines 305-314
Link Here
|
| 305 |
return id + "_" + version; //$NON-NLS-1$ |
278 |
return id + "_" + version; //$NON-NLS-1$ |
| 306 |
} |
279 |
} |
| 307 |
|
280 |
|
| 308 |
// returns true if it is safe to delete the project. It is not safe to delete if |
281 |
/** |
| 309 |
// one of its libraries is locked by a running launch configuration. |
282 |
* Returns true if it is safe to delete the project. It is not safe to delete if |
|
|
283 |
* one of its libraries is locked by a running launch configuration. |
| 284 |
* |
| 285 |
* @param project project to test |
| 286 |
* @param monitor progress monitor |
| 287 |
* @return true is it is safe to delete the project, false otherwise |
| 288 |
*/ |
| 310 |
private boolean safeDeleteCheck(IProject project, IProgressMonitor monitor) { |
289 |
private boolean safeDeleteCheck(IProject project, IProgressMonitor monitor) { |
| 311 |
if (!fLaunchedConfigurations) |
290 |
if (!fPluginsAreInUse) |
| 312 |
return true; |
291 |
return true; |
| 313 |
IPluginModelBase base = PluginRegistry.findModel(project); |
292 |
IPluginModelBase base = PluginRegistry.findModel(project); |
| 314 |
if (base != null) { |
293 |
if (base != null) { |
|
Lines 372-412
Link Here
|
| 372 |
* Imports the contents of the plugin and imports source files as binary files that will not be compiled. |
351 |
* Imports the contents of the plugin and imports source files as binary files that will not be compiled. |
| 373 |
* @param project destination project of the import |
352 |
* @param project destination project of the import |
| 374 |
* @param model model representing the plugin to import |
353 |
* @param model model representing the plugin to import |
| 375 |
* @param markAsBinary whether to mark the project as a binary project |
|
|
| 376 |
* @param monitor progress monitor |
354 |
* @param monitor progress monitor |
|
|
355 |
* @return a mapping of libraries to source locations to use in the classpath |
| 377 |
* @throws CoreException if there is a problem completing the import |
356 |
* @throws CoreException if there is a problem completing the import |
| 378 |
*/ |
357 |
*/ |
| 379 |
private void importAsBinary(IProject project, IPluginModelBase model, boolean markAsBinary, IProgressMonitor monitor) throws CoreException { |
358 |
private Map importAsBinary(IProject project, IPluginModelBase model, IProgressMonitor monitor) throws CoreException { |
| 380 |
monitor.beginTask("", 4); //$NON-NLS-1$ |
359 |
|
| 381 |
if (isJARd(model)) { |
360 |
try { |
| 382 |
extractJARdPlugin(project, model, new SubProgressMonitor(monitor, 3)); |
361 |
monitor.beginTask(NLS.bind("Importing {0}", model.getPluginBase().getId()), 4); |
| 383 |
} else { |
362 |
|
| 384 |
importContent(new File(model.getInstallLocation()), project.getFullPath(), FileSystemStructureProvider.INSTANCE, null, new SubProgressMonitor(monitor, 1)); |
363 |
// Import the plug-in content |
| 385 |
importSourceArchives(project, model, new SubProgressMonitor(monitor, 1)); |
364 |
File srcFile = new File(model.getInstallLocation()); |
|
|
365 |
if (isJARd(model)) { |
| 366 |
importArchive(project, srcFile, new Path(srcFile.getName())); |
| 367 |
} else { |
| 368 |
importContent(new File(model.getInstallLocation()), project.getFullPath(), FileSystemStructureProvider.INSTANCE, null, new SubProgressMonitor(monitor, 1)); |
| 369 |
} |
| 370 |
|
| 371 |
// Import source from known source locations |
| 372 |
Map sourceMap = copySourceArchives(project, model, new SubProgressMonitor(monitor, 1)); |
| 386 |
|
373 |
|
| 387 |
// make sure all libraries have been imported |
374 |
// Import missing libraries from fragments |
| 388 |
// if any are missing, check in fragments |
375 |
// TODO Needs testing, might be obsolete |
| 389 |
IFragment[] fragments = getFragmentsFor(model); |
376 |
IFragment[] fragments = getFragmentsFor(model); |
| 390 |
IPluginLibrary[] libraries = model.getPluginBase().getLibraries(); |
377 |
IPluginLibrary[] libraries = model.getPluginBase().getLibraries(); |
| 391 |
|
378 |
|
| 392 |
IProgressMonitor fragmentMonitor = new SubProgressMonitor(monitor, 1); |
|
|
| 393 |
fragmentMonitor.beginTask("", libraries.length); //$NON-NLS-1$ |
| 394 |
for (int i = 0; i < libraries.length; i++) { |
379 |
for (int i = 0; i < libraries.length; i++) { |
| 395 |
String libraryName = libraries[i].getName(); |
380 |
String libraryName = ClasspathUtilCore.expandLibraryName(libraries[i].getName()); |
| 396 |
if (ClasspathUtilCore.containsVariables(libraryName) && !project.exists(new Path(ClasspathUtilCore.expandLibraryName(libraryName)))) { |
381 |
Path libPath = new Path(libraryName); |
|
|
382 |
if (!project.exists(libPath)) { |
| 397 |
for (int j = 0; j < fragments.length; j++) { |
383 |
for (int j = 0; j < fragments.length; j++) { |
| 398 |
importJarFromFragment(project, fragments[j], libraryName); |
384 |
// TODO Fragments are always a specific shape? |
| 399 |
importSourceFromFragment(project, fragments[j], libraryName, new SubProgressMonitor(monitor, 1)); |
385 |
// Import the fragment |
|
|
386 |
File jar = new File(fragments[i].getModel().getInstallLocation(), libPath.toString()); |
| 387 |
if (jar.exists()) { |
| 388 |
importArchive(project, jar, libPath); |
| 389 |
} |
| 390 |
// Import the source |
| 391 |
// TODO Edit copySourceArchives to handle fragments to save the code duplication, don't forget the source map |
| 392 |
SourceLocationManager manager = PDECore.getDefault().getSourceLocationManager(); |
| 393 |
String zipName = ClasspathUtilCore.getSourceZipName(libraryName); |
| 394 |
IPath srcPath = manager.findSourcePath(fragments[i], new Path(zipName)); |
| 395 |
if (srcPath != null) { |
| 396 |
// TODO Determine the best way to make the name, can be just the source location. |
| 397 |
if ("src.zip".equals(zipName) && isJARd(model)) { //$NON-NLS-1$ |
| 398 |
// We want a more meaningful name than src.zip |
| 399 |
zipName = ClasspathUtilCore.getSourceZipName(new File(model.getInstallLocation()).getName()); |
| 400 |
} |
| 401 |
IPath dstPath = new Path(zipName); |
| 402 |
sourceMap.put(libraries[i], dstPath); |
| 403 |
if (project.findMember(dstPath) == null) { |
| 404 |
importArchive(project, new File(srcPath.toOSString()), dstPath); |
| 405 |
} |
| 406 |
} |
| 400 |
} |
407 |
} |
| 401 |
} else { |
|
|
| 402 |
monitor.worked(1); |
| 403 |
} |
408 |
} |
| 404 |
} |
409 |
} |
| 405 |
} |
410 |
monitor.worked(1); |
| 406 |
if (markAsBinary) { |
411 |
|
|
|
412 |
// Mark the project as binary |
| 407 |
project.setPersistentProperty(PDECore.EXTERNAL_PROJECT_PROPERTY, PDECore.BINARY_PROJECT_VALUE); |
413 |
project.setPersistentProperty(PDECore.EXTERNAL_PROJECT_PROPERTY, PDECore.BINARY_PROJECT_VALUE); |
| 408 |
importAdditionalResources(project, model, new SubProgressMonitor(monitor, 1)); |
414 |
|
| 409 |
} else { |
415 |
// TODO Test if schema extraction is necessary |
|
|
416 |
// importAdditionalResources(project, model, new SubProgressMonitor(monitor, 1)); |
| 417 |
|
| 418 |
return sourceMap; |
| 419 |
|
| 420 |
} finally { |
| 410 |
monitor.done(); |
421 |
monitor.done(); |
| 411 |
} |
422 |
} |
| 412 |
} |
423 |
} |
|
Lines 420-426
Link Here
|
| 420 |
*/ |
431 |
*/ |
| 421 |
private void importAsSource(IProject project, IPluginModelBase model, SubProgressMonitor monitor) throws CoreException { |
432 |
private void importAsSource(IProject project, IPluginModelBase model, SubProgressMonitor monitor) throws CoreException { |
| 422 |
monitor.beginTask("", 4); //$NON-NLS-1$ |
433 |
monitor.beginTask("", 4); //$NON-NLS-1$ |
| 423 |
importAsBinary(project, model, false, new SubProgressMonitor(monitor, 2)); |
434 |
// importAsBinary(project, model, false, new SubProgressMonitor(monitor, 2)); |
| 424 |
List list = importAdditionalResources(project, model, new SubProgressMonitor(monitor, 1)); |
435 |
List list = importAdditionalResources(project, model, new SubProgressMonitor(monitor, 1)); |
| 425 |
WorkspaceBuildModel buildModel = new WorkspaceBuildModel(project.getFile("build.properties")); //$NON-NLS-1$ |
436 |
WorkspaceBuildModel buildModel = new WorkspaceBuildModel(project.getFile("build.properties")); //$NON-NLS-1$ |
| 426 |
if (!isJARd(model) || containsCode(new File(model.getInstallLocation()))) { |
437 |
if (!isJARd(model) || containsCode(new File(model.getInstallLocation()))) { |
|
Lines 739-812
Link Here
|
| 739 |
monitor.done(); |
750 |
monitor.done(); |
| 740 |
} |
751 |
} |
| 741 |
|
752 |
|
| 742 |
private void importSourceArchives(IProject project, IPluginModelBase model, IProgressMonitor monitor) throws CoreException { |
753 |
private Map copySourceArchives(IProject project, IPluginModelBase model, IProgressMonitor monitor) throws CoreException { |
| 743 |
String[] libraries = getLibraryNames(model, true); |
754 |
String[] libraries = getLibraryNames(model, true); |
| 744 |
monitor.beginTask(PDEUIMessages.ImportWizard_operation_copyingSource, libraries.length); |
755 |
try { |
| 745 |
|
756 |
monitor.beginTask(PDEUIMessages.ImportWizard_operation_copyingSource, libraries.length); |
| 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 |
|
757 |
|
| 780 |
// Extract folders containing java source |
758 |
Map sourceMap = new HashMap(libraries.length); |
| 781 |
extractJavaSource(new File(sourceLocation.toOSString()), rootsToExclude, dest, monitor); |
759 |
SourceLocationManager manager = PDECore.getDefault().getSourceLocationManager(); |
| 782 |
} else { |
760 |
for (int i = 0; i < libraries.length; i++) { |
| 783 |
// Extract the specific library from it's folder |
761 |
String zipName = ClasspathUtilCore.getSourceZipName(libraries[i]); |
| 784 |
extractResourcesFromFolder(new File(sourceLocation.toOSString()), new Path(currentRoot), project, monitor); |
762 |
IPath srcPath = manager.findSourcePath(model.getPluginBase(), new Path(zipName)); |
| 785 |
} |
763 |
if (srcPath != null) { |
| 786 |
} |
764 |
zipName = srcPath.lastSegment(); |
| 787 |
} else { |
765 |
// TODO Determine the best way to make the name, can be just the source location. |
| 788 |
IPath srcPath = manager.findSourcePath(model.getPluginBase(), path); |
766 |
if ("src.zip".equals(zipName)) { //$NON-NLS-1$ |
| 789 |
if (srcPath != null) { |
767 |
// We want a more meaningful name than src.zip |
| 790 |
if ("src.zip".equals(zipName) && isJARd(model)) { //$NON-NLS-1$ |
768 |
zipName = ClasspathUtilCore.getSourceZipName(new File(model.getInstallLocation()).getName()); |
| 791 |
path = getDefaultSourceNameForProject(model); |
769 |
} |
| 792 |
} |
770 |
IPath dstPath = new Path(zipName); |
| 793 |
importArchive(project, new File(srcPath.toOSString()), path); |
771 |
sourceMap.put(libraries[i], dstPath); |
|
|
772 |
if (project.findMember(dstPath) == null) { |
| 773 |
importArchive(project, new File(srcPath.toOSString()), dstPath); |
| 794 |
} |
774 |
} |
|
|
775 |
|
| 795 |
} |
776 |
} |
|
|
777 |
monitor.worked(1); |
| 796 |
} |
778 |
} |
| 797 |
monitor.worked(1); |
779 |
return sourceMap; |
|
|
780 |
} finally { |
| 781 |
monitor.done(); |
| 798 |
} |
782 |
} |
| 799 |
monitor.done(); |
|
|
| 800 |
} |
| 801 |
|
| 802 |
/** |
| 803 |
* Creates a path representing a zip file that is named based on the plugin install location. |
| 804 |
* Used to replace src.zip with a more unique and meaningful name. |
| 805 |
* @param model model that the src.zip containg source for |
| 806 |
* @return a new path describing the zip file |
| 807 |
*/ |
| 808 |
private IPath getDefaultSourceNameForProject(IPluginModelBase model) { |
| 809 |
return new Path(ClasspathUtilCore.getSourceZipName(new File(model.getInstallLocation()).getName())); |
| 810 |
} |
783 |
} |
| 811 |
|
784 |
|
| 812 |
private String[] getLibraryNames(IPluginModelBase model, boolean expand) { |
785 |
private String[] getLibraryNames(IPluginModelBase model, boolean expand) { |
|
Lines 854-860
Link Here
|
| 854 |
if (fImportType == IMPORT_BINARY_WITH_LINKS) { |
827 |
if (fImportType == IMPORT_BINARY_WITH_LINKS) { |
| 855 |
linkSourceArchives(project, model, new SubProgressMonitor(monitor, 1)); |
828 |
linkSourceArchives(project, model, new SubProgressMonitor(monitor, 1)); |
| 856 |
} else { |
829 |
} else { |
| 857 |
importSourceArchives(project, model, new SubProgressMonitor(monitor, 1)); |
830 |
copySourceArchives(project, model, new SubProgressMonitor(monitor, 1)); |
| 858 |
} |
831 |
} |
| 859 |
} |
832 |
} |
| 860 |
} |
833 |
} |
|
Lines 926-952
Link Here
|
| 926 |
return PDEPlugin.getWorkspace().getRoot().getProject(id); |
899 |
return PDEPlugin.getWorkspace().getRoot().getProject(id); |
| 927 |
} |
900 |
} |
| 928 |
|
901 |
|
| 929 |
private boolean queryReplace(IProject project) throws OperationCanceledException { |
902 |
/** |
| 930 |
switch (fReplaceQuery.doQuery(NLS.bind(PDEUIMessages.ImportWizard_messages_exists, project.getName()))) { |
903 |
* Tests whether the required execution environment of the given plugin is supported by |
| 931 |
case IImportQuery.CANCEL : |
904 |
* the current known JREs. If not, ask the user whether to continue. |
| 932 |
throw new OperationCanceledException(); |
905 |
* @param model the plug-in model to test |
| 933 |
case IImportQuery.NO : |
906 |
* @return true is the import should continue, false if the plug-in should be skipped |
| 934 |
return false; |
907 |
* @throws OperationCanceledException if the user chooses to cancel the operation |
| 935 |
} |
908 |
*/ |
| 936 |
return true; |
909 |
private boolean testExecutionEnvironment(IPluginModelBase model) throws OperationCanceledException { |
| 937 |
} |
910 |
BundleDescription desc = model.getBundleDescription(); |
| 938 |
|
911 |
if (desc != null) { |
| 939 |
private boolean queryExecutionEnvironment(String message) throws OperationCanceledException { |
912 |
IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager(); |
| 940 |
switch (fExecutionQuery.doQuery(message)) { |
913 |
String[] envs = desc.getExecutionEnvironments(); |
| 941 |
case IImportQuery.CANCEL : |
914 |
boolean found = false; |
| 942 |
throw new OperationCanceledException(); |
915 |
for (int i = 0; i < envs.length; i++) { |
| 943 |
case IImportQuery.NO : |
916 |
if (manager.getEnvironment(envs[i]) != null) { |
| 944 |
return false; |
917 |
found = true; |
|
|
918 |
break; |
| 919 |
} |
| 920 |
} |
| 921 |
if (envs.length > 0 && !found) { |
| 922 |
switch (fExecutionQuery.doQuery(NLS.bind(PDEUIMessages.PluginImportOperation_executionEnvironment, model.getPluginBase().getId(), envs[0]))) { |
| 923 |
case IImportQuery.CANCEL : |
| 924 |
throw new OperationCanceledException(); |
| 925 |
case IImportQuery.NO : |
| 926 |
return false; |
| 927 |
} |
| 928 |
} |
| 945 |
} |
929 |
} |
| 946 |
return true; |
930 |
return true; |
| 947 |
} |
931 |
} |
| 948 |
|
932 |
|
| 949 |
private void setProjectDescription(IProject project, IPluginModelBase model) throws CoreException { |
933 |
private void setProjectNatures(IProject project, IPluginModelBase model) throws CoreException { |
| 950 |
IProjectDescription desc = project.getDescription(); |
934 |
IProjectDescription desc = project.getDescription(); |
| 951 |
if (!desc.hasNature(PDE.PLUGIN_NATURE)) |
935 |
if (!desc.hasNature(PDE.PLUGIN_NATURE)) |
| 952 |
CoreUtility.addNatureToProject(project, PDE.PLUGIN_NATURE, null); |
936 |
CoreUtility.addNatureToProject(project, PDE.PLUGIN_NATURE, null); |
|
Lines 1027-1069
Link Here
|
| 1027 |
return (IFragment[]) result.toArray(new IFragment[result.size()]); |
1011 |
return (IFragment[]) result.toArray(new IFragment[result.size()]); |
| 1028 |
} |
1012 |
} |
| 1029 |
|
1013 |
|
| 1030 |
private void importJarFromFragment(IProject project, IFragment fragment, String name) throws CoreException { |
1014 |
// private void importJarFromFragment(IProject project, IFragment fragment, String name) throws CoreException { |
| 1031 |
IPath jarPath = new Path(ClasspathUtilCore.expandLibraryName(name)); |
1015 |
// IPath jarPath = new Path(ClasspathUtilCore.expandLibraryName(name)); |
| 1032 |
File jar = new File(fragment.getModel().getInstallLocation(), jarPath.toString()); |
1016 |
// File jar = new File(fragment.getModel().getInstallLocation(), jarPath.toString()); |
| 1033 |
if (jar.exists()) { |
1017 |
// if (jar.exists()) { |
| 1034 |
importArchive(project, jar, jarPath); |
1018 |
// importArchive(project, jar, jarPath); |
| 1035 |
} |
1019 |
// } |
| 1036 |
} |
1020 |
// } |
| 1037 |
|
1021 |
|
| 1038 |
/** |
1022 |
// /** |
| 1039 |
* Imports the source for a library from a fragment. |
1023 |
// * Imports the source for a library from a fragment. |
| 1040 |
* @param project destination project of the import |
1024 |
// * @param project destination project of the import |
| 1041 |
* @param fragment fragment to import the library from |
1025 |
// * @param fragment fragment to import the library from |
| 1042 |
* @param libraryName name of the library to import, |
1026 |
// * @param libraryName name of the library to import, |
| 1043 |
* @param monitor progress monitor |
1027 |
// * @param monitor progress monitor |
| 1044 |
* @throws CoreException if there is a problem completing the import |
1028 |
// * @throws CoreException if there is a problem completing the import |
| 1045 |
*/ |
1029 |
// */ |
| 1046 |
private void importSourceFromFragment(IProject project, IFragment fragment, String libraryName, IProgressMonitor monitor) throws CoreException { |
1030 |
// private void importSourceFromFragment(IProject project, IFragment fragment, String libraryName, IProgressMonitor monitor) throws CoreException { |
| 1047 |
try { |
1031 |
// try { |
| 1048 |
IPath jarPath = new Path(ClasspathUtilCore.expandLibraryName(libraryName)); |
1032 |
// IPath jarPath = new Path(ClasspathUtilCore.expandLibraryName(libraryName)); |
| 1049 |
String zipName = ClasspathUtilCore.getSourceZipName(jarPath.toString()); |
1033 |
// String zipName = ClasspathUtilCore.getSourceZipName(jarPath.toString()); |
| 1050 |
IPath path = new Path(zipName); |
1034 |
// IPath path = new Path(zipName); |
| 1051 |
if (project.findMember(path) == null) { |
1035 |
// if (project.findMember(path) == null) { |
| 1052 |
SourceLocationManager manager = PDECore.getDefault().getSourceLocationManager(); |
1036 |
// SourceLocationManager manager = PDECore.getDefault().getSourceLocationManager(); |
| 1053 |
IPath srcPath = manager.findSourcePath(fragment, path); |
1037 |
// IPath srcPath = manager.findSourcePath(fragment, path); |
| 1054 |
if (srcPath != null) { |
1038 |
// if (srcPath != null) { |
| 1055 |
if (manager.hasBundleManifestLocation(fragment)) { |
1039 |
// if (manager.hasBundleManifestLocation(fragment)) { |
| 1056 |
// Extract the specific library from it's folder |
1040 |
// // Extract the specific library from it's folder |
| 1057 |
extractResourcesFromFolder(new File(srcPath.toOSString()), path.removeFileExtension(), project, monitor); |
1041 |
// extractResourcesFromFolder(new File(srcPath.toOSString()), path.removeFileExtension(), project, monitor); |
| 1058 |
} else { |
1042 |
// } else { |
| 1059 |
importArchive(project, new File(srcPath.toOSString()), path); |
1043 |
// importArchive(project, new File(srcPath.toOSString()), path); |
| 1060 |
} |
1044 |
// } |
| 1061 |
} |
1045 |
// } |
| 1062 |
} |
1046 |
// } |
| 1063 |
} finally { |
1047 |
// } finally { |
| 1064 |
monitor.done(); |
1048 |
// monitor.done(); |
| 1065 |
} |
1049 |
// } |
| 1066 |
} |
1050 |
// } |
| 1067 |
|
1051 |
|
| 1068 |
protected void collectAdditionalResources(ZipFileStructureProvider provider, Object element, ArrayList collected, IProject project) { |
1052 |
protected void collectAdditionalResources(ZipFileStructureProvider provider, Object element, ArrayList collected, IProject project) { |
| 1069 |
collectAdditionalResources(provider, element, collected); |
1053 |
collectAdditionalResources(provider, element, collected); |
|
Lines 1093-1100
Link Here
|
| 1093 |
} |
1077 |
} |
| 1094 |
} |
1078 |
} |
| 1095 |
|
1079 |
|
| 1096 |
public void setLaunchedConfiguration(boolean launchedConfiguration) { |
1080 |
/** |
| 1097 |
fLaunchedConfigurations = launchedConfiguration; |
1081 |
* Starts a job that will build the workspace |
|
|
1082 |
*/ |
| 1083 |
private void runBuildJob() { |
| 1084 |
Job buildJob = new Job(PDEUIMessages.CompilersConfigurationBlock_building) { |
| 1085 |
public boolean belongsTo(Object family) { |
| 1086 |
return ResourcesPlugin.FAMILY_AUTO_BUILD == family; |
| 1087 |
} |
| 1088 |
|
| 1089 |
protected IStatus run(IProgressMonitor monitor) { |
| 1090 |
try { |
| 1091 |
PDEPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor); |
| 1092 |
} catch (CoreException e) { |
| 1093 |
} |
| 1094 |
return Status.OK_STATUS; |
| 1095 |
} |
| 1096 |
}; |
| 1097 |
buildJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule()); |
| 1098 |
buildJob.schedule(); |
| 1098 |
} |
1099 |
} |
| 1099 |
|
1100 |
|
| 1100 |
} |
1101 |
} |