Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2010 EclipseSource Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
8 |
* Contributors: |
9 |
* Chris Aniszczyk <caniszczyk@gmail.com> - initial API and implementation |
10 |
* Ian Bull <irbull@eclipsesource.com> - initial API and implementation |
11 |
*******************************************************************************/ |
12 |
package org.eclipse.pde.internal.ui.wizards.exports; |
13 |
|
14 |
import java.net.URI; |
15 |
import org.eclipse.core.filesystem.*; |
16 |
import org.eclipse.core.runtime.*; |
17 |
import org.eclipse.core.runtime.jobs.Job; |
18 |
import org.eclipse.equinox.p2.engine.IProfile; |
19 |
import org.eclipse.pde.core.plugin.IPluginModelBase; |
20 |
import org.eclipse.pde.core.plugin.PluginRegistry; |
21 |
import org.eclipse.pde.internal.core.FeatureModelManager; |
22 |
import org.eclipse.pde.internal.core.PDECore; |
23 |
import org.eclipse.pde.internal.core.feature.ExternalFeatureModel; |
24 |
import org.eclipse.pde.internal.core.ifeature.IFeatureModel; |
25 |
import org.eclipse.pde.internal.core.target.TargetDefinition; |
26 |
import org.eclipse.pde.internal.core.target.TargetPlatformService; |
27 |
import org.eclipse.pde.internal.ui.PDEPlugin; |
28 |
import org.eclipse.pde.internal.ui.PDEUIMessages; |
29 |
|
30 |
/** |
31 |
* This job exports the bundles and features that make up your target. |
32 |
*/ |
33 |
public class ExportActiveTargetJob extends Job { |
34 |
|
35 |
private URI fDestination; |
36 |
private boolean fclearDestinationDirectory = false; |
37 |
|
38 |
public ExportActiveTargetJob(URI destination, boolean clearDestinationDirectory) { |
39 |
super("Export Current Target Definition Job"); //$NON-NLS-1$ |
40 |
fDestination = destination; |
41 |
fclearDestinationDirectory = clearDestinationDirectory; |
42 |
} |
43 |
|
44 |
protected IStatus run(IProgressMonitor monitor) { |
45 |
|
46 |
IFileSystem fileSystem = EFS.getLocalFileSystem(); |
47 |
if (!fileSystem.canWrite()) { |
48 |
return new Status(IStatus.ERROR, PDEPlugin.getPluginId(), "Destination directory not writable."); //$NON-NLS-1$ |
49 |
} |
50 |
IFileStore destination = fileSystem.getStore(fDestination); |
51 |
|
52 |
FeatureModelManager featureManager = PDECore.getDefault().getFeatureModelManager(); |
53 |
IFeatureModel[] featureModels = featureManager.getModels(); |
54 |
IPluginModelBase[] pluginModels = PluginRegistry.getExternalModels(); |
55 |
|
56 |
IFileStore featureDir = destination.getChild("features"); //$NON-NLS-1$ |
57 |
IFileStore pluginDir = destination.getChild("plugins"); //$NON-NLS-1$ |
58 |
IFileStore metadataXML = destination.getChild("content.xml"); //$NON-NLS-1$ |
59 |
IFileStore metadataJAR = destination.getChild("content.jar"); //$NON-NLS-1$ |
60 |
|
61 |
int totalWork = featureModels.length + pluginModels.length; |
62 |
|
63 |
try { |
64 |
monitor.beginTask(PDEUIMessages.ExportTargetDefinition_task, totalWork); |
65 |
if (fclearDestinationDirectory) { |
66 |
monitor.subTask(PDEUIMessages.ExportTargetDeleteOldData); //Deleting old data... |
67 |
} |
68 |
|
69 |
try { |
70 |
if (fclearDestinationDirectory) { |
71 |
ExportTargetMetadata.getDefault().clearExporedRepository(fDestination); |
72 |
|
73 |
if (featureDir.fetchInfo().exists()) { |
74 |
featureDir.delete(EFS.NONE, new NullProgressMonitor()); |
75 |
} |
76 |
if (pluginDir.fetchInfo().exists()) { |
77 |
pluginDir.delete(EFS.NONE, new NullProgressMonitor()); |
78 |
} |
79 |
if (metadataJAR.fetchInfo().exists()) { |
80 |
metadataJAR.delete(EFS.NONE, new NullProgressMonitor()); |
81 |
} |
82 |
if (metadataXML.fetchInfo().exists()) { |
83 |
metadataXML.delete(EFS.NONE, new NullProgressMonitor()); |
84 |
} |
85 |
} |
86 |
|
87 |
if (!featureDir.fetchInfo().exists()) { |
88 |
featureDir.mkdir(EFS.NONE, new NullProgressMonitor()); |
89 |
} |
90 |
if (!pluginDir.fetchInfo().exists()) { |
91 |
pluginDir.mkdir(EFS.NONE, new NullProgressMonitor()); |
92 |
} |
93 |
} catch (CoreException e1) { |
94 |
return new Status(IStatus.ERROR, PDEPlugin.getPluginId(), "Failed to create destination directory.", e1); //$NON-NLS-1$ |
95 |
} |
96 |
|
97 |
monitor.subTask(PDEUIMessages.ExportTargetExportFeatures); |
98 |
for (int i = 0; i < featureModels.length; i++) { |
99 |
IFeatureModel model = featureModels[i]; |
100 |
if (model.isEnabled() && model instanceof ExternalFeatureModel) { |
101 |
copy(model.getInstallLocation(), featureDir, fileSystem, monitor); |
102 |
} |
103 |
} |
104 |
|
105 |
monitor.subTask(PDEUIMessages.ExportTargetExportPlugins); |
106 |
for (int i = 0; i < pluginModels.length; i++) { |
107 |
IPluginModelBase model = pluginModels[i]; |
108 |
//if (model.isEnabled()) { |
109 |
copy(model.getInstallLocation(), pluginDir, fileSystem, monitor); |
110 |
//} |
111 |
} |
112 |
|
113 |
try { |
114 |
TargetDefinition definition = ((TargetDefinition) TargetPlatformService.getDefault().getWorkspaceTargetHandle().getTargetDefinition()); |
115 |
IProfile profile = definition.getProfile(); |
116 |
ExportTargetMetadata component = ExportTargetMetadata.getDefault(); |
117 |
IStatus status = component.exportMetadata(profile, fDestination, definition.getName()); |
118 |
if (status.isOK()) |
119 |
return status; |
120 |
} catch (CoreException e) { |
121 |
return new Status(IStatus.ERROR, PDEPlugin.getPluginId(), "Failed to export the target", e); //$NON-NLS-1$ |
122 |
} |
123 |
} catch (CoreException e) { |
124 |
return new Status(IStatus.ERROR, PDEPlugin.getPluginId(), "Failed to export the target", e); //$NON-NLS-1$ |
125 |
} |
126 |
|
127 |
finally { |
128 |
monitor.done(); |
129 |
} |
130 |
return Status.OK_STATUS; |
131 |
} |
132 |
|
133 |
private IStatus copy(String src, IFileStore destinationParent, IFileSystem fileSystem, IProgressMonitor monitor) throws CoreException { |
134 |
Path srcPath = new Path(src); |
135 |
IFileStore source = fileSystem.getStore(srcPath); |
136 |
String elementName = srcPath.segment(srcPath.segmentCount() - 1); |
137 |
IFileStore destinationDirectory = destinationParent.getChild(elementName); |
138 |
if (destinationDirectory.fetchInfo().exists()) { |
139 |
monitor.worked(1); |
140 |
return Status.OK_STATUS; |
141 |
} |
142 |
if (source.fetchInfo().isDirectory()) { |
143 |
destinationDirectory.mkdir(EFS.NONE, new NullProgressMonitor()); |
144 |
} |
145 |
source.copy(destinationDirectory, EFS.OVERWRITE, new SubProgressMonitor(monitor, 1)); |
146 |
return Status.OK_STATUS; |
147 |
} |
148 |
|
149 |
} |