Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2009-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 <zx@eclipsesource.com> - initial API and implementation |
10 |
* Ian Bull <irbull@eclipsesource.com> - initial API and implementation |
11 |
*******************************************************************************/ |
12 |
package org.eclipse.pde.internal.ui.target; |
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 |
*/ |
34 |
public class ExportActiveTargetJob extends Job { |
35 |
|
36 |
private URI fDestination; |
37 |
private boolean fclearDestinationDirectory = false; |
38 |
|
39 |
public ExportActiveTargetJob(URI destination, boolean clearDestinationDirectory) { |
40 |
super("Export Current Target Definition Job"); //$NON-NLS-1$ |
41 |
fDestination = destination; |
42 |
fclearDestinationDirectory = clearDestinationDirectory; |
43 |
} |
44 |
|
45 |
protected IStatus run(IProgressMonitor monitor) { |
46 |
|
47 |
IFileSystem fileSystem = EFS.getLocalFileSystem(); |
48 |
if (!fileSystem.canWrite()) { |
49 |
return new Status(IStatus.ERROR, PDEPlugin.getPluginId(), "Destination directory not writable."); //$NON-NLS-1$ |
50 |
} |
51 |
IFileStore destination = fileSystem.getStore(fDestination); |
52 |
|
53 |
FeatureModelManager featureManager = PDECore.getDefault().getFeatureModelManager(); |
54 |
IFeatureModel[] featureModels = featureManager.getModels(); |
55 |
IPluginModelBase[] pluginModels = PluginRegistry.getExternalModels(); |
56 |
|
57 |
IFileStore featureDir = destination.getChild("features"); //$NON-NLS-1$ |
58 |
IFileStore pluginDir = destination.getChild("plugins"); //$NON-NLS-1$ |
59 |
IFileStore metadataXML = destination.getChild("content.xml"); //$NON-NLS-1$ |
60 |
IFileStore metadataJAR = destination.getChild("content.jar"); //$NON-NLS-1$ |
61 |
|
62 |
int totalWork = featureModels.length + pluginModels.length; |
63 |
|
64 |
try { |
65 |
monitor.beginTask(PDEUIMessages.ExportTargetDefinition_task, totalWork); |
66 |
if (fclearDestinationDirectory) { |
67 |
monitor.subTask(PDEUIMessages.ExportTargetDeleteOldData); //Deleting old data... |
68 |
} |
69 |
|
70 |
try { |
71 |
if (fclearDestinationDirectory) { |
72 |
ExportTargetMetadata.getDefault().clearExporedRepository(fDestination); |
73 |
|
74 |
if (featureDir.fetchInfo().exists()) { |
75 |
featureDir.delete(EFS.NONE, new NullProgressMonitor()); |
76 |
} |
77 |
if (pluginDir.fetchInfo().exists()) { |
78 |
pluginDir.delete(EFS.NONE, new NullProgressMonitor()); |
79 |
} |
80 |
if (metadataJAR.fetchInfo().exists()) { |
81 |
metadataJAR.delete(EFS.NONE, new NullProgressMonitor()); |
82 |
} |
83 |
if (metadataXML.fetchInfo().exists()) { |
84 |
metadataXML.delete(EFS.NONE, new NullProgressMonitor()); |
85 |
} |
86 |
} |
87 |
|
88 |
if (!featureDir.fetchInfo().exists()) { |
89 |
featureDir.mkdir(EFS.NONE, new NullProgressMonitor()); |
90 |
} |
91 |
if (!pluginDir.fetchInfo().exists()) { |
92 |
pluginDir.mkdir(EFS.NONE, new NullProgressMonitor()); |
93 |
} |
94 |
} catch (CoreException e1) { |
95 |
return new Status(IStatus.ERROR, PDEPlugin.getPluginId(), "Failed to create destination directory.", e1); //$NON-NLS-1$ |
96 |
} |
97 |
|
98 |
monitor.subTask(PDEUIMessages.ExportTargetExportFeatures); |
99 |
for (int i = 0; i < featureModels.length; i++) { |
100 |
IFeatureModel model = featureModels[i]; |
101 |
if (model.isEnabled() && model instanceof ExternalFeatureModel) { |
102 |
copy(model.getInstallLocation(), featureDir, fileSystem, monitor); |
103 |
} |
104 |
} |
105 |
|
106 |
monitor.subTask(PDEUIMessages.ExportTargetExportPlugins); |
107 |
for (int i = 0; i < pluginModels.length; i++) { |
108 |
IPluginModelBase model = pluginModels[i]; |
109 |
//if (model.isEnabled()) { |
110 |
copy(model.getInstallLocation(), pluginDir, fileSystem, monitor); |
111 |
//} |
112 |
} |
113 |
|
114 |
try { |
115 |
IProfile profile = ((TargetDefinition) TargetPlatformService.getDefault().getWorkspaceTargetHandle().getTargetDefinition()).getProfile(); |
116 |
ExportTargetMetadata component = ExportTargetMetadata.getDefault(); |
117 |
IStatus status = component.exportMetadata(profile, fDestination, "Get target name plz"); //TODO: Get the target name //$NON-NLS-1$ |
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 |
} |