Bug 351526 - [patch] Ant task for provisioning a target definition
diff --git a/ui/org.eclipse.pde.core/META-INF/MANIFEST.MF b/ui/org.eclipse.pde.core/META-INF/MANIFEST.MF
index 72c46e7..ef0e26a 100644
--- a/ui/org.eclipse.pde.core/META-INF/MANIFEST.MF
+++ b/ui/org.eclipse.pde.core/META-INF/MANIFEST.MF
@@ -74,10 +74,12 @@
org.eclipse.equinox.p2.director;bundle-version="[2.0.0,3.0.0)",
org.eclipse.equinox.p2.artifact.repository;bundle-version="[1.0.100,2.0.0)",
org.eclipse.equinox.p2.repository;bundle-version="[2.0.0,3.0.0]",
+ org.eclipse.equinox.p2.repository.tools;bundle-version="[2.0.100,3.0.0)",
org.eclipse.equinox.p2.metadata.repository;bundle-version="[1.0.100,2.0.0)",
org.eclipse.equinox.p2.garbagecollector;bundle-version="[1.0.100,2.0.0)",
org.eclipse.equinox.p2.touchpoint.eclipse;bundle-version="[2.0.0,3.0.0)",
- org.eclipse.core.expressions;bundle-version="[3.4.0,4.0.0)"
+ org.eclipse.core.expressions;bundle-version="[3.4.0,4.0.0)",
+ org.eclipse.core.filesystem;bundle-version="[1.0.0,2.0.0)"
Eclipse-LazyStart: true
Bundle-RequiredExecutionEnvironment: J2SE-1.4
Import-Package: com.ibm.icu.util
diff --git a/ui/org.eclipse.pde.core/ant_tasks/pde-ant.jar b/ui/org.eclipse.pde.core/ant_tasks/pde-ant.jar
deleted file mode 100644
index 3aa3848..0000000
--- a/ui/org.eclipse.pde.core/ant_tasks/pde-ant.jar
+++ /dev/null
Binary files differ
diff --git a/ui/org.eclipse.pde.core/build.properties b/ui/org.eclipse.pde.core/build.properties
index 11f43fc..9afc076 100644
--- a/ui/org.eclipse.pde.core/build.properties
+++ b/ui/org.eclipse.pde.core/build.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2003, 2006 IBM Corporation and others.
+# Copyright (c) 2003, 2011 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
@@ -28,4 +28,8 @@
output.ant_tasks/pde-ant.jar = binary/
jars.compile.order = .,\
ant_tasks/pde-ant.jar
-jars.extra.classpath = platform:/plugin/org.apache.ant/lib/ant.jar
+jars.extra.classpath = platform:/plugin/org.apache.ant/lib/ant.jar,\
+ platform:/plugin/org.eclipse.equinox.p2.repository.tools/lib/repository-tools-ant.jar,\
+ platform:/plugin/org.eclipse.pde.build/lib/pdebuild-ant.jar
+extra.lib/pde-ant.jar = ../org.apache.ant/ant.jar,\
+ ../org.eclipse.pde.build/lib/pdebuild-ant.jar
diff --git a/ui/org.eclipse.pde.core/plugin.xml b/ui/org.eclipse.pde.core/plugin.xml
index 8bd40b5..5a390ea 100644
--- a/ui/org.eclipse.pde.core/plugin.xml
+++ b/ui/org.eclipse.pde.core/plugin.xml
@@ -191,6 +191,11 @@
name="pde.exportFeatures"
class="org.eclipse.pde.internal.core.ant.FeatureExportTask">
</antTask>
+ <antTask
+ class="org.eclipse.pde.internal.core.ant.TargetPlatformProvisionTask"
+ library="ant_tasks/pde-ant.jar"
+ name="pde.provisionTargetDefinition">
+ </antTask>
</extension>
<extension
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDECoreMessages.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDECoreMessages.java
index 26a8dc4..0928ffa 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDECoreMessages.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDECoreMessages.java
@@ -99,7 +99,7 @@
NLS.initializeMessages(BUNDLE_NAME, PDECoreMessages.class);
}
- // Builders and natures
+ // Builders and natures
public static String Builders_updating;
public static String Builders_verifying;
@@ -335,4 +335,13 @@
public static String VMHelper_noJreForExecEnv;
+ // Target Export ########################################
+ public static String ExportTargetDefinition_task;
+ public static String ExportTargetDeleteOldData;
+ public static String ExportTargetExportFeatures;
+ public static String ExportTargetExportPlugins;
+
+ public static String ExportTargetJob_ConfiguringDestination;
+ public static String ExportTargetJob_ExportingTargetContents;
+
}
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/pderesources.properties b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/pderesources.properties
index 530d441..b56bd60 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/pderesources.properties
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/pderesources.properties
@@ -253,16 +253,24 @@
SourceEntryErrorReporter_9=Default encoding ({0}) should be specified for library "{1}" to match workspace settings.
SourceEntryErrorReporter_DifferentTargetLibrary=Source folders ''{0}'' share the same output folder but are targeted to different libraries.
-SourceEntryErrorReporter_DupeOutputFolder=Multiple entries for output folder ''{0}'' in build entry ''{1}''.
+SourceEntryErrorReporter_DupeOutputFolder=Multiple entries for output folder ''{0}'' in build entry ''{1}''.
SourceEntryErrorReporter_DupeSourceFolder=Multiple entries for source folder ''{0}'' in build entry ''{1}''.
-SourceEntryErrorReporter_ExtraOutputFolder=Redundant entry for output folder ''{0}''. It does not correspond to any source folder in ''{1}'' entry.
+SourceEntryErrorReporter_ExtraOutputFolder=Redundant entry for output folder ''{0}''. It does not correspond to any source folder in ''{1}'' entry.
SourceEntryErrorReporter_InvalidOutputFolder=''{0}'' is not an output folder.
SourceEntryErrorReporter_InvalidSourceFolder=''{0}'' is not a source folder.
SourceEntryErrorReporter_MissingLibrary=The library ''{0}'' has not been specified on the bundle classpath.
-SourceEntryErrorReporter_MissingOutputEntry=Source folder ''{0}'' does not have the output folder in corresponding output entry ''{1}''.
+SourceEntryErrorReporter_MissingOutputEntry=Source folder ''{0}'' does not have the output folder in corresponding output entry ''{1}''.
SourceEntryErrorReporter_MissingOutputLibForClassFolder=The class folder ''{0}'' is not associated to any output library entry.
SourceLocationManager_problemProcessingBundleManifestSourceHeader=Problem processing bundle manifest source header in plug-in {0} version {1} found at {2}
UpdateSiteBuilder_0=Cleaning {0}
-VMHelper_noJreForExecEnv=No installed JREs satisfy this Execution Environment: "{0}". Launch aborted.
\ No newline at end of file
+VMHelper_noJreForExecEnv=No installed JREs satisfy this Execution Environment: "{0}". Launch aborted.
+
+######### Target Export Wizard ###################################33
+ExportTargetDefinition_task = Exporting current target definition...
+ExportTargetDeleteOldData = Deleting old data...
+ExportTargetExportFeatures = Exporting features...
+ExportTargetExportPlugins = Exporting plugins...
+ExportTargetJob_ConfiguringDestination=Configuring destination
+ExportTargetJob_ExportingTargetContents=Exporting target contents
diff --git a/ui/org.eclipse.pde.core/src_ant/org/eclipse/pde/internal/core/ant/TargetPlatformProvisionTask.java b/ui/org.eclipse.pde.core/src_ant/org/eclipse/pde/internal/core/ant/TargetPlatformProvisionTask.java
new file mode 100644
index 0000000..b75b37d
--- /dev/null
+++ b/ui/org.eclipse.pde.core/src_ant/org/eclipse/pde/internal/core/ant/TargetPlatformProvisionTask.java
@@ -0,0 +1,130 @@
+/**
+ * Copyright (c) 2011 Gunnar Wagenknecht and others.
+ * All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Gunnar Wagenknecht - initial API and implementation
+ */
+package org.eclipse.pde.internal.core.ant;
+
+import java.io.File;
+import org.apache.tools.ant.*;
+import org.eclipse.core.runtime.*;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.pde.internal.build.BundleHelper;
+import org.eclipse.pde.internal.build.tasks.TaskHelper;
+import org.eclipse.pde.internal.core.PDECore;
+import org.eclipse.pde.internal.core.PDECoreMessages;
+import org.eclipse.pde.internal.core.target.ExportTargetJob;
+import org.eclipse.pde.internal.core.target.TargetPlatformService;
+import org.eclipse.pde.internal.core.target.provisional.ITargetDefinition;
+
+/**
+ * Exports the bundles and plug-ins of a target definition to a directory
+ */
+public class TargetPlatformProvisionTask extends Task {
+
+ private File targetFile;
+ private File destinationDirectory;
+ private boolean clearDestination;
+
+ /* (non-Javadoc)
+ * @see org.apache.tools.ant.Task#execute()
+ */
+ public void execute() throws BuildException {
+
+ try {
+ BundleHelper.getDefault().setLog(this);
+ run();
+ } catch (CoreException e) {
+ throw new BuildException(TaskHelper.statusToString(e.getStatus(), null).toString());
+ } finally {
+ BundleHelper.getDefault().setLog(null);
+ }
+
+ }
+
+ private void export(final ITargetDefinition targetDefinition) throws CoreException {
+ // export using Job to allow progress reporting when run inside IDE
+ ExportTargetJob exportTargetJob = new ExportTargetJob(targetDefinition, destinationDirectory.toURI(), clearDestination);
+ exportTargetJob.schedule();
+ try {
+ exportTargetJob.join();
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new CoreException(Status.CANCEL_STATUS);
+ }
+ }
+
+ private IStatus resolve(final ITargetDefinition targetDefinition) throws CoreException {
+ // resolve using Job to allow progress reporting when run inside IDE
+ final IStatus[] status = new IStatus[1];
+ Job resolveJob = new Job(NLS.bind("Resolving {0}", null != targetDefinition.getName() && targetDefinition.getName().length() > 0 ? targetDefinition.getName() : targetFile.getName())) {
+ protected IStatus run(IProgressMonitor monitor) {
+ status[0] = targetDefinition.resolve(monitor);
+ return Status.OK_STATUS;
+ }
+ };
+ resolveJob.setPriority(Job.LONG);
+ resolveJob.schedule();
+ try {
+ resolveJob.join();
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new CoreException(Status.CANCEL_STATUS);
+ }
+ return status[0];
+ }
+
+ private void run() throws CoreException {
+ if (null == targetFile)
+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, PDECoreMessages.TargetPlatformProvisionTask_ErrorDefinitionNotSet));
+ if (!targetFile.isFile() || !targetFile.canRead())
+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, NLS.bind(PDECoreMessages.TargetPlatformProvisionTask_ErrorDefinitionNotFoundAtSpecifiedLocation, targetFile)));
+ if (null == destinationDirectory)
+ throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, PDECoreMessages.TargetPlatformProvisionTask_ErrorDestinationNotSet));
+
+ final ITargetDefinition targetDefinition = TargetPlatformService.getDefault().getTarget(targetFile.toURI()).getTargetDefinition();
+
+ log("Resolving target definition...");
+ IStatus status = resolve(targetDefinition);
+ if (status.matches(IStatus.ERROR | IStatus.CANCEL))
+ throw new CoreException(status);
+ else if (!status.isOK()) {
+ log(TaskHelper.statusToString(status, null).toString(), Project.MSG_WARN);
+ }
+
+ log("Exporting target definition...");
+ export(targetDefinition);
+ }
+
+ /**
+ * Set whether the destination should be cleared prior to provisioning.
+ * @param clearDestination
+ */
+ public void setClearDestination(boolean clearDestination) {
+ this.clearDestination = clearDestination;
+ }
+
+ /**
+ * Set the folder in which the target will be provisioned.
+ * @param destinationDirectory
+ */
+ public void setDestinationDirectory(File destinationDirectory) {
+ this.destinationDirectory = destinationDirectory;
+ }
+
+ /**
+ * Set the target file to provision
+ * @param targetFile
+ */
+ public void setTargetFile(File targetFile) {
+ this.targetFile = targetFile;
+ }
+
+}
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEUIMessages.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEUIMessages.java
index 5214e18..c503159 100644
--- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEUIMessages.java
+++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEUIMessages.java
@@ -1739,24 +1739,16 @@
public static String CategorySection_newCategoryLabel;
// Target Export ########################################
- public static String ExportTargetDefinition_task;
- public static String ExportTargetDeleteOldData;
- public static String ExportTargetExportFeatures;
- public static String ExportTargetExportPlugins;
public static String ExportActiveTargetDefinition;
public static String ExportActiveTargetDefinition_message;
+ public static String ExportTargetError_ChooseDestination;
+ public static String ExportTargetError_validPath;
public static String ExportTargetCurrentTarget;
public static String ExportTargetChooseFolder;
public static String ExportTargetBrowse;
public static String ExportTargetSelectDestination;
public static String ExportTargetSpecifyDestination;
public static String ExportTargetClearDestination;
- public static String ExportTargetError_ChooseDestination;
- public static String ExportTargetError_validPath;
-
- public static String ExportTargetJob_ConfiguringDestination;
-
- public static String ExportTargetJob_ExportingTargetContents;
public static String CategoryDetails_title;
public static String CategoryDetails_sectionDescription;
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties
index aec0b21..bf483bd 100644
--- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties
+++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties
@@ -664,7 +664,7 @@
ExternalizeStringsWizardPage_subKey=Substitution Key
ExternalizeStringsResolution_label=Open Externalize Strings Wizard...
ExternalizeStringsWizardPage_keyDuplicateError=New key may not be a duplicate of another key
-ExternalizeStringsWizardPage_keySuggested=\n\tsuggested key value:
+ExternalizeStringsWizardPage_keySuggested=\n\tsuggested key value:
Preferences_TargetEnvironmentPage_os = &Operating System:
Preferences_TargetEnvironmentPage_ws = &Windowing System:
@@ -1011,7 +1011,7 @@
NewSchemaFileMainPage_missingPluginID = Specify a valid plug-in ID. No Plug-in ID specified.
NewSchemaFileMainPage_nonExistingPluginID = Specify a valid plug-in ID. Specified plug-in ID does not exist.
-NewSchemaFileMainPage_externalPluginID = Specify a valid plug-in ID. Specified plug-in ID is external to the workspace.
+NewSchemaFileMainPage_externalPluginID = Specify a valid plug-in ID. Specified plug-in ID is external to the workspace.
NewSchemaFileMainPage_missingContainer = Specify a valid container. No container specified.
NewSchemaFileMainPage_invalidContainer = Specify a valid container. Specified container is not a valid project or folder.
NewSchemaFileMainPage_nonExistingContainer = Specify a valid container. Specified container does not exist.
@@ -1243,7 +1243,7 @@
EditorUtilities_noImageData=The specified file contains no image data
EditorPreferencePage_tag=Tags
EditorPreferencePage_xml=&XML Highlighting
-EditorUtilities_icoError=The specified ICO file is missing images:
+EditorUtilities_icoError=The specified ICO file is missing images:
EditorPreferencePage_comment=Comments
EditorPreferencePage_manifest=&Manifest Highlighting
EditorUtilities_incorrectSize=The specified image is not the correct size: {0}.
@@ -1489,7 +1489,7 @@
compilers_p_not_externalized_att = Usage of non-externali&zed strings:
compilers_p_deprecated = Usage of deprecated attributes and &elements:
compilers_p_internal = Usage o&f internal extension points:
-compilers_p_exported_pkgs = Missing exported pac&kages:
+compilers_p_exported_pkgs = Missing exported pac&kages:
compilers_p_missing_exp_pkg = Missing versions on exported packages:
compilers_p_missing_imp_pkg = Missing versions on imported packages:
compilers_p_missing_require_bundle = Missing versions on required bundles:
@@ -1595,13 +1595,9 @@
CategorySection_newCategoryLabel = New Category {0}
######### Target Export Wizard ###################################33
-ExportTargetDefinition_task = Exporting current target definition...
-ExportTargetDeleteOldData = Deleting old data...
-ExportTargetExportFeatures = Exporting features...
-ExportTargetExportPlugins = Exporting plugins...
ExportActiveTargetDefinition = Exporting Target Definition
ExportActiveTargetDefinition_message = Please choose a destination directory to export all target content
-ExportTargetCurrentTarget = Active &Target:
+ExportTargetCurrentTarget = Active &Target:
ExportTargetChooseFolder = &Destination:
ExportTargetBrowse = &Browse...
ExportTargetSelectDestination = Select Destination
@@ -1609,8 +1605,6 @@
ExportTargetClearDestination = &Clear destination directory before exporting
ExportTargetError_ChooseDestination = Please choose a destination directory
ExportTargetError_validPath = Destination directory must be a valid path
-ExportTargetJob_ConfiguringDestination=Configuring destination
-ExportTargetJob_ExportingTargetContents=Exporting target contents
CategoryDetails_title = Category Properties
@@ -2076,7 +2070,7 @@
InternationalizeWizard_LocalePage_availableList = Available locales:
InternationalizeWizard_LocalePage_filter = Filter available locales:
InternationalizeWizard_LocalePage_selectionError=At least one locale must be selected.
-InternationalizeWizard_NLSFragmentGenerator_overwriteTitle = Confirm Overwrite
+InternationalizeWizard_NLSFragmentGenerator_overwriteTitle = Confirm Overwrite
InternationalizeWizard_NLSFragmentGenerator_overwriteMessage = A fragment project with the name "{0}" already exists. Overwrite?
InternationalizeWizard_NLSFragmentGenerator_errorMessage = An error occured while generating an NL Fragment.
@@ -2141,7 +2135,7 @@
OrganizeManifestsWizardPage_errorMsg=This function works only on plug-ins containing a MANIFEST.MF
OrganizeManifestsWizardPage_prefixNL=&Prefix icon paths in plug-in extensions with an $nl$ segment
OrganizeManifestsOperation_nlIconPath=checking icon paths for missing $nl$ segments... {0}
-OrganizeManifestsOperation_unusedKeys=checking for unused keys... {0}
+OrganizeManifestsOperation_unusedKeys=checking for unused keys... {0}
OrganizeManifestsWizardPage_addMissing=&Ensure that all packages appear in the MANIFEST.MF
OrganizeManifestsProcessor_rootMessage=Organize Manifest for {0}
OrganizeManifestsWizardPage_lazyStart=Remove unnecessary lazy activation headers
@@ -2327,7 +2321,7 @@
RemoveSplashHandlerBindingAction_msgProgressRemoveProductBindings=Removing product bindings from extension ''{0}'' ...
StateViewPage_requiredBundles=Required Plug-ins
StateViewPage_importedPackages=Imported Packages
-StateViewPage_suppliedBy=\ - supplied by:
+StateViewPage_suppliedBy=\ - supplied by:
StateViewPage_suppliedByJRE=\ - supplied by the JRE
StateViewPage_showLeaves=Show leaf plug-ins
StateViewPage_openItem=Open
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/exports/ExportTargetJob.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/exports/ExportTargetJob.java
deleted file mode 100644
index 95677a2..0000000
--- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/exports/ExportTargetJob.java
+++ /dev/null
@@ -1,235 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 EclipseSource Inc. and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * EclipseSource Inc. - initial API and implementation
- *******************************************************************************/
-package org.eclipse.pde.internal.ui.wizards.exports;
-
-import java.net.URI;
-import java.util.*;
-import org.eclipse.core.filesystem.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.equinox.p2.internal.repository.tools.Repo2Runnable;
-import org.eclipse.equinox.p2.internal.repository.tools.RepositoryDescriptor;
-import org.eclipse.equinox.p2.metadata.IInstallableUnit;
-import org.eclipse.equinox.p2.metadata.IProvidedCapability;
-import org.eclipse.equinox.p2.query.IQueryResult;
-import org.eclipse.pde.internal.core.feature.ExternalFeatureModel;
-import org.eclipse.pde.internal.core.ifeature.IFeatureModel;
-import org.eclipse.pde.internal.core.target.IUBundleContainer;
-import org.eclipse.pde.internal.core.target.P2TargetUtils;
-import org.eclipse.pde.internal.core.target.provisional.*;
-import org.eclipse.pde.internal.ui.PDEPlugin;
-import org.eclipse.pde.internal.ui.PDEUIMessages;
-
-/**
- * This job exports the bundles and features that make up your target.
- */
-public class ExportTargetJob extends Job {
-
- private URI fDestination;
- private boolean fclearDestinationDirectory = true;
- private IFileStore featureDir;
- private IFileStore pluginDir;
- private IFileSystem fileSystem;
- private Map filter;
- private ITargetDefinition fTarget;
-
- public ExportTargetJob(ITargetDefinition target, URI destination, boolean clearDestinationDirectory) {
- super("Export Current Target Definition Job"); //$NON-NLS-1$
- fTarget = target;
- fDestination = destination;
- fclearDestinationDirectory = clearDestinationDirectory;
- }
-
- protected IStatus run(IProgressMonitor monitor) {
- try {
- constructFilter(fTarget);
- IBundleContainer[] containers = fTarget.getBundleContainers();
- int totalWork = containers.length;
- monitor.beginTask(PDEUIMessages.ExportTargetDefinition_task, totalWork);
-
- monitor.subTask(PDEUIMessages.ExportTargetJob_ConfiguringDestination);
- setupDestination(monitor);
-
- monitor.subTask(PDEUIMessages.ExportTargetJob_ExportingTargetContents);
- for (int i = 0; i < containers.length; i++) {
- IBundleContainer container = containers[i];
- container.resolve(fTarget, monitor);
- if (!(container instanceof IUBundleContainer))
- exportContainer(container, fTarget, featureDir, pluginDir, fileSystem, monitor);
- }
- exportProfile(fTarget, fDestination, monitor);
- } catch (CoreException e) {
- return new Status(IStatus.ERROR, PDEPlugin.getPluginId(), "Failed to export the target", e); //$NON-NLS-1$
- } finally {
- monitor.done();
- }
- return Status.OK_STATUS;
- }
-
- private void constructFilter(ITargetDefinition target) {
- NameVersionDescriptor[] included = target.getIncluded();
- if (included == null)
- return;
- filter = new HashMap();
- for (int i = 0; i < included.length; i++) {
- NameVersionDescriptor inclusion = included[i];
- NameVersionDescriptor[] versions = (NameVersionDescriptor[]) filter.get(inclusion.getId());
- if (versions == null)
- filter.put(inclusion.getId(), new NameVersionDescriptor[] {inclusion});
- else {
- NameVersionDescriptor[] versions2 = new NameVersionDescriptor[versions.length + 1];
- System.arraycopy(versions, 0, versions2, 0, versions.length);
- versions2[versions.length] = inclusion;
- filter.put(inclusion.getId(), versions2);
- }
- }
- }
-
- private void setupDestination(IProgressMonitor monitor) throws CoreException {
- fileSystem = EFS.getLocalFileSystem();
- if (!fileSystem.canWrite()) {
- throw new CoreException(new Status(IStatus.ERROR, PDEPlugin.getPluginId(), "Destination directory not writable.")); //$NON-NLS-1$
- }
- IFileStore destination = fileSystem.getStore(fDestination);
- featureDir = destination.getChild("features"); //$NON-NLS-1$
- pluginDir = destination.getChild("plugins"); //$NON-NLS-1$
- if (fclearDestinationDirectory) {
- monitor.subTask(PDEUIMessages.ExportTargetDeleteOldData); //Deleting old data...
- featureDir.delete(EFS.NONE, null);
- pluginDir.delete(EFS.NONE, null);
- }
- featureDir.mkdir(EFS.NONE, null);
- pluginDir.mkdir(EFS.NONE, null);
- }
-
- private boolean shouldExport(NameVersionDescriptor descriptor) {
- // currently PDE does not selectively include/exclude features
- if (filter == null || descriptor.getType().equals(NameVersionDescriptor.TYPE_FEATURE))
- return true;
- NameVersionDescriptor[] versions = (NameVersionDescriptor[]) filter.get(descriptor.getId());
- if (versions == null)
- return false;
- for (int i = 0; i < versions.length; i++) {
- String version = versions[i].getVersion();
- if ((version == null || version.equals(descriptor.getVersion())) && descriptor.getType().equals(versions[i].getType()))
- return true;
- }
- return false;
- }
-
- private boolean shouldExport(IFeatureModel feature) {
- if (filter == null)
- return true;
- if (!feature.isEnabled() || !(feature instanceof ExternalFeatureModel))
- return false;
- NameVersionDescriptor descriptor = new NameVersionDescriptor(feature.getFeature().getId(), feature.getFeature().getVersion(), NameVersionDescriptor.TYPE_FEATURE);
- return shouldExport(descriptor);
- }
-
- private boolean shouldExport(IResolvedBundle bundle) {
- if (filter == null)
- return true;
- NameVersionDescriptor descriptor = new NameVersionDescriptor(bundle.getBundleInfo().getSymbolicName(), bundle.getBundleInfo().getVersion(), NameVersionDescriptor.TYPE_PLUGIN);
- return shouldExport(descriptor);
- }
-
- private boolean shouldExport(IInstallableUnit iu) {
- if (filter == null)
- return true;
- NameVersionDescriptor descriptor = null;
- String feature = getCapability(iu, "org.eclipse.update.feature"); //$NON-NLS-1$
- if (feature != null) {
- descriptor = new NameVersionDescriptor(feature, iu.getVersion().toString(), NameVersionDescriptor.TYPE_FEATURE);
- } else if (iu.getId().endsWith(".feature.group")) { //$NON-NLS-1$
- descriptor = new NameVersionDescriptor(iu.getId(), iu.getVersion().toString(), NameVersionDescriptor.TYPE_FEATURE);
- } else if ("bundle".equalsIgnoreCase(getCapability(iu, "org.eclipse.equinox.p2.eclipse.type"))) { //$NON-NLS-1$ //$NON-NLS-2$
- descriptor = new NameVersionDescriptor(iu.getId(), iu.getVersion().toString(), NameVersionDescriptor.TYPE_PLUGIN);
- } else if ("source".equalsIgnoreCase(getCapability(iu, "org.eclipse.equinox.p2.eclipse.type"))) { //$NON-NLS-1$ //$NON-NLS-2$
- descriptor = new NameVersionDescriptor(iu.getId(), iu.getVersion().toString(), NameVersionDescriptor.TYPE_PLUGIN);
- }
- // default to true unless we know otherwise. This ensures that random metadata bits
- // are moved over to the target as they might be needed in a future provisioning operation.
- // We could move only unknown IUs that do NOT have artifacts... Have to think about that.
- return descriptor == null ? true : shouldExport(descriptor);
- }
-
- private String getCapability(IInstallableUnit iu, String namespace) {
- for (Iterator i = iu.getProvidedCapabilities().iterator(); i.hasNext();) {
- IProvidedCapability capability = (IProvidedCapability) i.next();
- if (capability.getNamespace().equals(namespace))
- return capability.getName();
- }
- return null;
- }
-
- private void exportContainer(IBundleContainer container, ITargetDefinition target, IFileStore featureDir, IFileStore pluginDir, IFileSystem fileSystem, IProgressMonitor monitor) throws CoreException {
- IFeatureModel[] features = container.getFeatures();
- if (features != null) {
- monitor.subTask(PDEUIMessages.ExportTargetExportFeatures);
- for (int i = 0; i < features.length; i++) {
- if (shouldExport(features[i]))
- copy(features[i].getInstallLocation(), featureDir, fileSystem, monitor);
- }
- }
-
- IResolvedBundle[] bundles = container.getBundles();
- if (bundles != null) {
- monitor.subTask(PDEUIMessages.ExportTargetExportPlugins);
- for (int i = 0; i < bundles.length; i++) {
- if (shouldExport(bundles[i]))
- copy(bundles[i].getBundleInfo().getLocation().getPath(), pluginDir, fileSystem, monitor);
- }
- }
- }
-
- private IStatus copy(String src, IFileStore destinationParent, IFileSystem fileSystem, IProgressMonitor monitor) throws CoreException {
- Path srcPath = new Path(src);
- IFileStore source = fileSystem.getStore(srcPath);
- String elementName = srcPath.segment(srcPath.segmentCount() - 1);
- IFileStore destination = destinationParent.getChild(elementName);
- if (destination.fetchInfo().exists()) {
- monitor.worked(1);
- return Status.OK_STATUS;
- }
- if (source.fetchInfo().isDirectory()) {
- destination.mkdir(EFS.NONE, new NullProgressMonitor());
- }
- source.copy(destination, EFS.OVERWRITE, new SubProgressMonitor(monitor, 1));
- return Status.OK_STATUS;
- }
-
- private RepositoryDescriptor createRepoDescriptor(URI location, String name, String kind) {
- RepositoryDescriptor result = new RepositoryDescriptor();
- result.setLocation(location);
- result.setKind(kind);
- result.setName(name);
- if (fclearDestinationDirectory)
- result.setAppend(false);
- return result;
- }
-
- private void exportProfile(ITargetDefinition target, URI destination, IProgressMonitor monitor) throws CoreException {
- Repo2Runnable exporter = new Repo2Runnable();
- exporter.addDestination(createRepoDescriptor(destination, P2TargetUtils.getProfileId(target), RepositoryDescriptor.KIND_METADATA));
- exporter.addDestination(createRepoDescriptor(destination, P2TargetUtils.getProfileId(target), RepositoryDescriptor.KIND_ARTIFACT));
- exporter.addSource(createRepoDescriptor(P2TargetUtils.getBundlePool().getLocation(), null, RepositoryDescriptor.KIND_ARTIFACT));
-
- IQueryResult ius = P2TargetUtils.getIUs(target, monitor);
- ArrayList toExport = new ArrayList();
- for (Iterator i = ius.iterator(); i.hasNext();) {
- IInstallableUnit iu = (IInstallableUnit) i.next();
- if (shouldExport(iu))
- toExport.add(iu);
- }
- exporter.setSourceIUs(toExport);
- exporter.run(monitor);
- }
-}
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/exports/TargetDefinitionExportWizard.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/exports/TargetDefinitionExportWizard.java
index 3d6dd77..bfe5cbc 100644
--- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/exports/TargetDefinitionExportWizard.java
+++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/exports/TargetDefinitionExportWizard.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 EclipseSource Corporation and others.
+ * Copyright (c) 2010, 2011 EclipseSource Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -17,6 +17,7 @@
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.pde.internal.core.target.ExportTargetJob;
import org.eclipse.pde.internal.core.target.TargetPlatformService;
import org.eclipse.pde.internal.core.target.provisional.ITargetDefinition;
import org.eclipse.pde.internal.ui.*;