View | Details | Raw Unified | Return to bug 190711 | Differences between
and this patch

Collapse All | Expand All

(-)plugin.properties (+2 lines)
Lines 77-82 Link Here
77
77
78
PluginSearchPage.label = Plug-in Search
78
PluginSearchPage.label = Plug-in Search
79
79
80
target.export.wizard.name=Target definition
81
target.export.wizard.desc=Export the currently active target definition
80
PluginExportWizard.label=Deployable plug-ins and fragments
82
PluginExportWizard.label=Deployable plug-ins and fragments
81
PluginExportWizard.description=Export the selected plug-ins and/or fragments \
83
PluginExportWizard.description=Export the selected plug-ins and/or fragments \
82
in a form suitable for deploying in an Eclipse product.
84
in a form suitable for deploying in an Eclipse product.
(-)plugin.xml (+10 lines)
Lines 312-317 Link Here
312
               class="org.eclipse.core.resources.IContainer">
312
               class="org.eclipse.core.resources.IContainer">
313
         </selection>
313
         </selection>
314
      </wizard>
314
      </wizard>
315
      <wizard
316
            category="org.eclipse.pde.ui.PluginDevelopment"
317
            class="org.eclipse.pde.internal.ui.wizards.exports.TargetDefinitionExportWizard"
318
            icon="icons/obj16/target_profile_xml_obj.gif"
319
            id="org.eclipse.pde.target.wizard"
320
            name="%target.export.wizard.name">
321
         <description>
322
            %target.export.wizard.desc
323
         </description>
324
      </wizard>
315
      <category
325
      <category
316
            id="org.eclipse.pde.ui.PluginDevelopment"
326
            id="org.eclipse.pde.ui.PluginDevelopment"
317
            name="%PluginImportExport.category"/>
327
            name="%PluginImportExport.category"/>
(-)src/org/eclipse/pde/internal/ui/PDEUIMessages.java (+14 lines)
Lines 1678-1683 Link Here
1678
	public static String CategorySection_newCategoryName;
1678
	public static String CategorySection_newCategoryName;
1679
	public static String CategorySection_newCategoryLabel;
1679
	public static String CategorySection_newCategoryLabel;
1680
1680
1681
	// Target Export ########################################
1682
	public static String ExportTargetDefinition_task;
1683
	public static String ExportTargetDeleteOldData;
1684
	public static String ExportTargetExportFeatures;
1685
	public static String ExportTargetExportPlugins;
1686
	public static String ExportActiveTargetDefinition;
1687
	public static String ExportTargetCurrentTarget;
1688
	public static String ExportTargetChooseFolder;
1689
	public static String ExportTargetBrowse;
1690
	public static String ExportTargetSelectDestination;
1691
	public static String ExportTargetSpecifyDestination;
1692
	public static String ExportTargetClearDestination;
1693
	public static String ExportTargetError_ChooseDestination;
1694
1681
	public static String CategoryDetails_title;
1695
	public static String CategoryDetails_title;
1682
	public static String CategoryDetails_sectionDescription;
1696
	public static String CategoryDetails_sectionDescription;
1683
	public static String CategoryDetails_name;
1697
	public static String CategoryDetails_name;
(-)src/org/eclipse/pde/internal/ui/pderesources.properties (+15 lines)
Lines 1553-1558 Link Here
1553
CategorySection_newCategoryName = new_category_{0}
1553
CategorySection_newCategoryName = new_category_{0}
1554
CategorySection_newCategoryLabel = New Category {0}
1554
CategorySection_newCategoryLabel = New Category {0}
1555
1555
1556
######### Target Export Wizard ###################################33
1557
ExportTargetDefinition_task = Exporting current target definition...
1558
ExportTargetDeleteOldData = Deleting old data...
1559
ExportTargetExportFeatures = Exporting features...
1560
ExportTargetExportPlugins = Exporting plugins...
1561
ExportActiveTargetDefinition = Export Active Target Definition
1562
ExportTargetCurrentTarget = Active &Target: 
1563
ExportTargetChooseFolder = &Destination:
1564
ExportTargetBrowse = &Browse...
1565
ExportTargetSelectDestination = Select Destination
1566
ExportTargetSpecifyDestination = Specify the destination directory for the current target
1567
ExportTargetClearDestination = &Clear destination directory before exporting
1568
ExportTargetError_ChooseDestination = Please choose a destination directory
1569
1570
1556
CategoryDetails_title = Category Properties
1571
CategoryDetails_title = Category Properties
1557
CategoryDetails_sectionDescription = Provide a unique id, a name and a description for each category.\n\
1572
CategoryDetails_sectionDescription = Provide a unique id, a name and a description for each category.\n\
1558
"*" denotes a required field.
1573
"*" denotes a required field.
(-)src/org/eclipse/pde/internal/ui/wizards/exports/ExportActiveTargetJob.java (+149 lines)
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
}
(-)src/org/eclipse/pde/internal/ui/wizards/exports/ExportTargetMetadata.java (+94 lines)
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
 *     Ian Bull <irbull@eclipsesource.com> - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.wizards.exports;
12
13
import java.net.URI;
14
import org.eclipse.core.runtime.*;
15
import org.eclipse.equinox.p2.core.IProvisioningAgent;
16
import org.eclipse.equinox.p2.core.ProvisionException;
17
import org.eclipse.equinox.p2.engine.IProfile;
18
import org.eclipse.equinox.p2.query.IQueryResult;
19
import org.eclipse.equinox.p2.query.QueryUtil;
20
import org.eclipse.equinox.p2.repository.IRepositoryManager;
21
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
22
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
23
import org.eclipse.pde.internal.core.PDECore;
24
import org.eclipse.pde.internal.ui.PDEPlugin;
25
26
public class ExportTargetMetadata {
27
28
	IProvisioningAgent agent = null;
29
	public static ExportTargetMetadata instance = null;
30
31
	public void start() {
32
		instance = this;
33
	}
34
35
	public void stop() {
36
		instance = null;
37
38
	}
39
40
	public static ExportTargetMetadata getDefault() {
41
		return instance;
42
	}
43
44
	public synchronized void clearExporedRepository(URI destination) {
45
		agent = (IProvisioningAgent) PDECore.getDefault().acquireService(IProvisioningAgent.SERVICE_NAME);
46
		if (agent == null)
47
			return;
48
		if (((IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME)).contains(destination))
49
			((IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME)).removeRepository(destination);
50
	}
51
52
	public synchronized IStatus exportMetadata(IProfile profile, URI destination, String targetName) {
53
		if (agent == null)
54
			return new Status(IStatus.ERROR, PDEPlugin.getPluginId(), "Failed to mirror the metadata."); //$NON-NLS-1$
55
		boolean removeRepoAfterLoad = false;
56
		try {
57
			IMetadataRepository repository = null;
58
59
			try {
60
				//TODO: There appears to be a small (5 byte) difference from when I do the load vs. the create
61
				//      The create gives the repo a version 1, while the load gives it 1.0.0
62
				//      this might be worth looking into
63
				removeRepoAfterLoad = !((IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME)).contains(destination);
64
				repository = ((IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME)).loadRepository(destination, IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, new NullProgressMonitor());
65
			} catch (ProvisionException e) {
66
				// The repository cannot be loaded
67
			}
68
			if (repository == null) {
69
				repository = ((IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME)).createRepository(destination, targetName, IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, null);
70
			}
71
72
			if (repository != null) {
73
				mirrorMetadata(profile, repository);
74
			} else {
75
				return new Status(IStatus.ERROR, PDEPlugin.getPluginId(), "Failed to mirror the metadata."); //$NON-NLS-1$
76
			}
77
78
		} catch (ProvisionException e) {
79
			return new Status(IStatus.ERROR, PDEPlugin.getPluginId(), "Failed to mirror the metadata.", e); //$NON-NLS-1$
80
		} finally {
81
			if (removeRepoAfterLoad) {
82
				((IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME)).removeRepository(destination);
83
			}
84
		}
85
86
		return Status.OK_STATUS;
87
	}
88
89
	private void mirrorMetadata(IProfile profile, IMetadataRepository repository) {
90
		IQueryResult results = profile.query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor());
91
		repository.addInstallableUnits(results.toUnmodifiableSet());
92
	}
93
94
}
(-)src/org/eclipse/pde/internal/ui/wizards/exports/TargetDefinitionExportWizard.java (+51 lines)
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.io.File;
15
import org.eclipse.core.runtime.jobs.Job;
16
import org.eclipse.jface.viewers.IStructuredSelection;
17
import org.eclipse.jface.wizard.Wizard;
18
import org.eclipse.pde.internal.ui.PDEUIMessages;
19
import org.eclipse.ui.IExportWizard;
20
import org.eclipse.ui.IWorkbench;
21
22
public class TargetDefinitionExportWizard extends Wizard implements IExportWizard {
23
24
	private TargetDefinitionExportWizardPage fPage = null;
25
26
	public TargetDefinitionExportWizard() {
27
		setNeedsProgressMonitor(true);
28
		setWindowTitle(PDEUIMessages.ExportActiveTargetDefinition);
29
	}
30
31
	public void addPages() {
32
		fPage = new TargetDefinitionExportWizardPage();
33
		addPage(fPage);
34
	}
35
36
	public boolean performFinish() {
37
		String destDir = fPage.getDestinationDirectory();
38
		boolean clearDestDir = fPage.isClearDestinationDirectory();
39
		File file = new File(destDir);
40
41
		Job job = new ExportActiveTargetJob(file.toURI(), clearDestDir);
42
		job.schedule(200);
43
44
		return true;
45
	}
46
47
	public void init(IWorkbench workbench, IStructuredSelection selection) {
48
		// do nothing atm
49
	}
50
51
}
(-)src/org/eclipse/pde/internal/ui/wizards/exports/TargetDefinitionExportWizardPage.java (+129 lines)
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 org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.IStatus;
16
import org.eclipse.jface.dialogs.Dialog;
17
import org.eclipse.jface.wizard.WizardPage;
18
import org.eclipse.pde.internal.core.target.TargetDefinition;
19
import org.eclipse.pde.internal.core.target.TargetPlatformService;
20
import org.eclipse.pde.internal.ui.PDEUIMessages;
21
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.events.*;
23
import org.eclipse.swt.layout.GridData;
24
import org.eclipse.swt.layout.GridLayout;
25
import org.eclipse.swt.widgets.*;
26
27
public class TargetDefinitionExportWizardPage extends WizardPage {
28
29
	private static final String PAGE_ID = "org.eclipse.pde.target.exportPage"; //$NON-NLS-1$
30
	private Button browseButton = null;
31
	private Text destDirText = null;
32
	private Button clearDestinationDirCheck = null;
33
34
	protected TargetDefinitionExportWizardPage() {
35
		super(PAGE_ID);
36
		setPageComplete(false);
37
		setTitle(PDEUIMessages.ExportActiveTargetDefinition);
38
		// TODO setImage(...)
39
	}
40
41
	public void createControl(Composite parent) {
42
		Composite container = new Composite(parent, SWT.NONE);
43
		GridLayout layout = new GridLayout(1, false);
44
		container.setLayout(layout);
45
		createExportDirectoryControl(container);
46
47
		//TODO initSettings();
48
49
		Dialog.applyDialogFont(container);
50
		setControl(container);
51
		setPageComplete(validate());
52
	}
53
54
	private void createExportDirectoryControl(Composite parent) {
55
		parent.setLayout(new GridLayout(3, false));
56
		parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
57
		new Label(parent, SWT.NONE).setText(PDEUIMessages.ExportTargetCurrentTarget);
58
		Label l = new Label(parent, SWT.NONE);
59
60
		try {
61
			// TODO this is a bit dirty
62
			TargetDefinition definition = ((TargetDefinition) TargetPlatformService.getDefault().getWorkspaceTargetHandle().getTargetDefinition());
63
			l.setText(definition.getName());
64
		} catch (CoreException e) {
65
			// TODO log something?
66
		}
67
68
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
69
		gd.horizontalSpan = 2;
70
		l.setLayoutData(gd);
71
		new Label(parent, SWT.NONE).setText(PDEUIMessages.ExportTargetChooseFolder);
72
73
		destDirText = new Text(parent, SWT.BORDER);
74
		destDirText.setEditable(false);
75
		destDirText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
76
		destDirText.addModifyListener(new ModifyListener() {
77
			public void modifyText(ModifyEvent e) {
78
				controlChanged();
79
			}
80
		});
81
		browseButton = new Button(parent, SWT.PUSH);
82
		browseButton.setText(PDEUIMessages.ExportTargetBrowse);
83
		browseButton.addSelectionListener(new SelectionAdapter() {
84
			public void widgetSelected(SelectionEvent e) {
85
				DirectoryDialog dialog = new DirectoryDialog(getShell());
86
				dialog.setText(PDEUIMessages.ExportTargetSelectDestination);
87
				dialog.setMessage(PDEUIMessages.ExportTargetSpecifyDestination);
88
				String dir = destDirText.getText();
89
				dialog.setFilterPath(dir);
90
				dir = dialog.open();
91
				if (dir == null || dir.equals("")) { //$NON-NLS-1$
92
					return;
93
				}
94
				destDirText.setText(dir);
95
				controlChanged();
96
			}
97
		});
98
99
		clearDestinationDirCheck = new Button(parent, SWT.CHECK);
100
		clearDestinationDirCheck.setText(PDEUIMessages.ExportTargetClearDestination);
101
		gd = new GridData();
102
		gd.horizontalSpan = 2;
103
		clearDestinationDirCheck.setLayoutData(gd);
104
	}
105
106
	public String getDestinationDirectory() {
107
		return destDirText.getText();
108
	}
109
110
	public boolean isClearDestinationDirectory() {
111
		return clearDestinationDirCheck.getSelection();
112
	}
113
114
	public void controlChanged() {
115
		setPageComplete(validate());
116
	}
117
118
	protected boolean validate() {
119
		setMessage(null);
120
121
		if (destDirText.getText().equals("")) { //$NON-NLS-1$
122
			setMessage(PDEUIMessages.ExportTargetError_ChooseDestination, IStatus.WARNING);
123
			return false;
124
		}
125
126
		return true;
127
	}
128
129
}

Return to bug 190711