001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.wizards.exports;
011:
012: import javax.xml.parsers.DocumentBuilderFactory;
013: import javax.xml.parsers.FactoryConfigurationError;
014: import javax.xml.parsers.ParserConfigurationException;
015:
016: import org.eclipse.pde.core.plugin.IPluginModelBase;
017: import org.eclipse.pde.internal.core.exports.FeatureExportInfo;
018: import org.eclipse.pde.internal.ui.PDEPluginImages;
019: import org.eclipse.pde.internal.ui.build.PluginExportJob;
020: import org.eclipse.ui.progress.IProgressConstants;
021: import org.w3c.dom.DOMException;
022: import org.w3c.dom.Document;
023: import org.w3c.dom.Element;
024:
025: public class PluginExportWizard extends AntGeneratingExportWizard {
026: private static final String STORE_SECTION = "PluginExportWizard"; //$NON-NLS-1$
027:
028: public PluginExportWizard() {
029: setDefaultPageImageDescriptor(PDEPluginImages.DESC_PLUGIN_EXPORT_WIZ);
030: }
031:
032: protected BaseExportWizardPage createPage1() {
033: return new PluginExportWizardPage(getSelection());
034: }
035:
036: protected String getSettingsSectionName() {
037: return STORE_SECTION;
038: }
039:
040: protected void scheduleExportJob() {
041: FeatureExportInfo info = new FeatureExportInfo();
042: info.toDirectory = fPage.doExportToDirectory();
043: info.useJarFormat = fPage.useJARFormat();
044: info.exportSource = fPage.doExportSource();
045: info.destinationDirectory = fPage.getDestination();
046: info.zipFileName = fPage.getFileName();
047: info.items = fPage.getSelectedItems();
048: info.signingInfo = fPage.useJARFormat() ? fPage
049: .getSigningInfo() : null;
050: info.qualifier = fPage.getQualifier();
051:
052: PluginExportJob job = new PluginExportJob(info);
053: job.setUser(true);
054: job.schedule();
055: job.setProperty(IProgressConstants.ICON_PROPERTY,
056: PDEPluginImages.DESC_PLUGIN_OBJ);
057: }
058:
059: protected Document generateAntTask() {
060: try {
061: DocumentBuilderFactory factory = DocumentBuilderFactory
062: .newInstance();
063: Document doc = factory.newDocumentBuilder().newDocument();
064: Element root = doc.createElement("project"); //$NON-NLS-1$
065: root.setAttribute("name", "build"); //$NON-NLS-1$ //$NON-NLS-2$
066: root.setAttribute("default", "plugin_export"); //$NON-NLS-1$ //$NON-NLS-2$
067: doc.appendChild(root);
068:
069: Element target = doc.createElement("target"); //$NON-NLS-1$
070: target.setAttribute("name", "plugin_export"); //$NON-NLS-1$ //$NON-NLS-2$
071: root.appendChild(target);
072:
073: Element export = doc.createElement("pde.exportPlugins"); //$NON-NLS-1$
074: export.setAttribute("plugins", getPluginIDs()); //$NON-NLS-1$
075: export.setAttribute("destination", fPage.getDestination()); //$NON-NLS-1$
076: String filename = fPage.getFileName();
077: if (filename != null)
078: export.setAttribute("filename", filename); //$NON-NLS-1$
079: export.setAttribute("exportType", getExportOperation()); //$NON-NLS-1$
080: export
081: .setAttribute(
082: "useJARFormat", Boolean.toString(fPage.useJARFormat())); //$NON-NLS-1$
083: export
084: .setAttribute(
085: "exportSource", Boolean.toString(fPage.doExportSource())); //$NON-NLS-1$
086: String qualifier = fPage.getQualifier();
087: if (qualifier != null)
088: export.setAttribute("qualifier", qualifier); //$NON-NLS-1$
089: target.appendChild(export);
090: return doc;
091: } catch (DOMException e) {
092: } catch (FactoryConfigurationError e) {
093: } catch (ParserConfigurationException e) {
094: }
095: return null;
096: }
097:
098: private String getPluginIDs() {
099: StringBuffer buffer = new StringBuffer();
100: Object[] objects = fPage.getSelectedItems();
101: for (int i = 0; i < objects.length; i++) {
102: Object object = objects[i];
103: if (object instanceof IPluginModelBase) {
104: buffer.append(((IPluginModelBase) object)
105: .getPluginBase().getId());
106: if (i < objects.length - 1)
107: buffer.append(","); //$NON-NLS-1$
108: }
109: }
110: return buffer.toString();
111: }
112:
113: }
|