Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/infra')
-rw-r--r--plugins/infra/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/ManifestEditor.java194
-rw-r--r--plugins/infra/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IFeatureProjectEditor.java103
-rw-r--r--plugins/infra/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IManifestEditor.java35
-rw-r--r--plugins/infra/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/FeatureProjectEditor.java503
4 files changed, 589 insertions, 246 deletions
diff --git a/plugins/infra/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/ManifestEditor.java b/plugins/infra/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/ManifestEditor.java
index 1c67da07c9f..3ccb481a373 100644
--- a/plugins/infra/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/ManifestEditor.java
+++ b/plugins/infra/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/ManifestEditor.java
@@ -42,7 +42,11 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
private static final String ASSIGN = "="; //$NON-NLS-1$
- private static final String BUNDLE_SYMBOLIC_NAME = "bundle-symbolicName"; //$NON-NLS-1$
+ private static final String BUNDLE_SYMBOLIC_NAME = "Bundle-SymbolicName"; //$NON-NLS-1$
+
+ private static final String IMPORT_PACKAGE = "Import-Package";
+
+ private static final String EXPORT_PACKAGE = "Export-Package";
private static final String SINGLETON = "singleton:="; //$NON-NLS-1$
@@ -71,7 +75,7 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
* {@inheritDoc}
*/
public boolean initOk() {
- return (manifest != null) && (manifestFile != null);
+ return manifest != null && manifestFile != null;
}
/**
@@ -93,15 +97,15 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
@Override
public void init() {
super.init();
- if ((this.manifest != null) && (this.manifestFile != null)) {
+ if (manifest != null && manifestFile != null) {
return;
}
- if (this.manifestFile == null) {
- this.manifestFile = getManifestFile();
+ if (manifestFile == null) {
+ manifestFile = getManifestFile();
}
- if (this.manifestFile != null) {
+ if (manifestFile != null) {
try {
- this.manifest = new Manifest(this.manifestFile.getContents());
+ manifest = new Manifest(manifestFile.getContents());
} catch (final IOException e) {
Activator.log.error(e);
// assure that exception is not silently captured (for users not examining the error log)
@@ -123,7 +127,7 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
*/
public void addDependency(final String dependency, final String version) {
final Name rqBundle = new Name(REQUIRED_BUNDLE);
- String requireBundle = this.manifest.getMainAttributes().getValue(rqBundle);
+ String requireBundle = manifest.getMainAttributes().getValue(rqBundle);
// TODO : Improve the detection of existing dependency
// If a.b.c exists, then a.b cannot be added (Because it is already contained)
@@ -134,17 +138,16 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
if (requireBundle == null) {
requireBundle = dependency;
+
if (version != null) {
- requireBundle += SEMICOLON + version;
+ requireBundle += SEMICOLON + "bundle-version=\"" + version + "\"";
}
} else if (!requireBundle.contains(dependency)) {
requireBundle += COMMA + dependency;
- if (version != null) {
- requireBundle += SEMICOLON + version;
- }
+ // TODO: Update version
}
- this.manifest.getMainAttributes().put(rqBundle, requireBundle);
+ manifest.getMainAttributes().put(rqBundle, requireBundle);
}
/**
@@ -155,13 +158,13 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
*/
public boolean hasDependency(final String dependency) {
final Name rqBundle = new Name(REQUIRED_BUNDLE);
- String requireBundle = this.manifest.getMainAttributes().getValue(rqBundle);
- return (requireBundle != null) && requireBundle.contains(dependency);
+ String requireBundle = manifest.getMainAttributes().getValue(rqBundle);
+ return requireBundle != null && requireBundle.contains(dependency);
}
-
+
public void setDependenciesVersion(final String dependencyPattern, final String newVersion) {
final Name rqBundle = new Name(REQUIRED_BUNDLE);
- final String requireBundles = this.manifest.getMainAttributes().getValue(rqBundle);
+ final String requireBundles = manifest.getMainAttributes().getValue(rqBundle);
final String[] bundles = requireBundles.split(COMMA);
String newRequiredBundles = ""; //$NON-NLS-1$
for (int ii = 0; ii < bundles.length; ii++) {// we iterate on the declared dependencies
@@ -181,7 +184,7 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
} else {
newRequiredBundles += currentDependency;// we copy the existing declaration
}
- if (ii < (bundles.length - 1)) {
+ if (ii < bundles.length - 1) {
newRequiredBundles += COMMA;
}
}
@@ -206,7 +209,7 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
* {@inheritDoc}
*/
public void setValue(final String key, final String name, final String value) {
- this.manifest.getMainAttributes().putValue(key, value);
+ manifest.getMainAttributes().putValue(key, value);
// this.manifest.getAttributes(key).put(name, value);
}
@@ -227,7 +230,7 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
* {@inheritDoc}
*/
public void removeValue(final String key) {
- this.manifest.getAttributes(key).remove(key);
+ manifest.getAttributes(key).remove(key);
}
/**
@@ -250,7 +253,7 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
*/
@Override
public boolean exists() {
- return super.exists() && (getManifestFile() != null) && (getSymbolicBundleName() != null) && (getBundleVersion() != null);
+ return super.exists() && getManifestFile() != null && getSymbolicBundleName() != null && getBundleVersion() != null;
}
/**
@@ -265,10 +268,10 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
final ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
- this.manifest.write(os);
+ manifest.write(os);
final StringReader reader = new StringReader(format(os.toString("UTF-8"))); //$NON-NLS-1$
- this.manifestFile.setContents(new InputStream() {
+ manifestFile.setContents(new InputStream() {
@Override
public int read() throws IOException {
@@ -325,22 +328,20 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
@Override
public void createFiles(final Set<String> files) {
if (files.contains(MANIFEST_PATH)) {
- this.manifestFile = getProject().getFile(MANIFEST_PATH);
- if (!this.manifestFile.exists()) {
+ manifestFile = getProject().getFile(MANIFEST_PATH);
+ if (!manifestFile.exists()) {
try {
final String input = "Manifest-Version: 1.0\n"; //without the "/n", it doesn't work!!!!! //$NON-NLS-1$
- if (!this.manifestFile.getParent().exists()) {
- final IContainer parent = this.manifestFile.getParent();
+ if (!manifestFile.getParent().exists()) {
+ final IContainer parent = manifestFile.getParent();
if (parent instanceof IFolder) {
if (!parent.exists()) {
((IFolder) parent).create(true, false, null);
}
}
}
- this.manifestFile.create(getInputStream(input), true, null);
- this.manifestFile = getProject().getFile(MANIFEST_PATH);
-
- this.manifest = new Manifest(this.manifestFile.getContents());
+ manifestFile.create(getInputStream(input), true, null);
+ manifestFile = getProject().getFile(MANIFEST_PATH);
// final int i;
// InputStream is = this.manifestFile.getContents();
@@ -351,13 +352,18 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
} catch (final CoreException ex) {
Activator.log.error(ex);
- } catch (final IOException e) {
- Activator.log.error(e);
}
-
}
}
+ try {
+ manifest = new Manifest(manifestFile.getContents());
+ } catch (IOException e) {
+ Activator.log.error(e);
+ } catch (CoreException e) {
+ Activator.log.error(e);
+ }
+
if (getSymbolicBundleName() == null) {
setSymbolicBundleName(getProject().getName());
}
@@ -378,7 +384,7 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
newName = "noName"; //$NON-NLS-1$
}
final Name symbolicName = new Name(BUNDLE_SYMBOLIC_NAME);
- this.manifest.getMainAttributes().put(symbolicName, newName);
+ manifest.getMainAttributes().put(symbolicName, newName);
}
/**
@@ -388,17 +394,16 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
* {@inheritDoc}
*/
public String getSymbolicBundleName() {
- if (this.manifest != null) {
+ if (manifest != null) {
final Name symbolicName = new Name(BUNDLE_SYMBOLIC_NAME);
- final String name = this.manifest.getMainAttributes().getValue(symbolicName);
- int semiColon = name.indexOf(SEMICOLON);
- if (semiColon != -1) {
- return name.substring(0, semiColon);
- }
- else {
- return name;
+ final String name = manifest.getMainAttributes().getValue(symbolicName);
+
+ if (name != null) {
+ int semiColon = name.indexOf(SEMICOLON);
+ return semiColon != -1 ? name.substring(0, semiColon) : name;
}
}
+
return null;
}
@@ -409,9 +414,9 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
* {@inheritDoc}
*/
public String getBundleVersion() {
- if (this.manifest != null) {
+ if (manifest != null) {
final Name symbolicName = new Name(BUNDLE_VERSION);
- final String version = this.manifest.getMainAttributes().getValue(symbolicName);
+ final String version = manifest.getMainAttributes().getValue(symbolicName);
return version;
}
return null;
@@ -423,12 +428,12 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
* {@inheritDoc}
*/
public void setBundleVersion(final String version) {
- if (this.manifest != null) {
+ if (manifest != null) {
final Name bundleVersion = new Name(BUNDLE_VERSION);
if (version == null) {
- this.manifest.getMainAttributes().remove(bundleVersion);
+ manifest.getMainAttributes().remove(bundleVersion);
} else {
- this.manifest.getMainAttributes().put(bundleVersion, version);
+ manifest.getMainAttributes().put(bundleVersion, version);
}
}
}
@@ -439,9 +444,9 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
* {@inheritDoc}
*/
public String getBundleVendor() {
- if (this.manifest != null) {
+ if (manifest != null) {
final Name bundleVendor = new Name(BUNDLE_VENDOR);
- return this.manifest.getMainAttributes().getValue(bundleVendor);
+ return manifest.getMainAttributes().getValue(bundleVendor);
}
return null;
}
@@ -452,21 +457,21 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
* {@inheritDoc}
*/
public void setBundleVendor(final String vendor) {
- if (this.manifest != null) {
+ if (manifest != null) {
final Name bundleVendor = new Name(BUNDLE_VENDOR);
if (vendor == null) {
- this.manifest.getMainAttributes().remove(bundleVendor);
+ manifest.getMainAttributes().remove(bundleVendor);
} else {
- this.manifest.getMainAttributes().put(bundleVendor, vendor);
+ manifest.getMainAttributes().put(bundleVendor, vendor);
}
}
}
public String getValue(final String key) {
- if (this.manifest != null) {
- String value = this.manifest.getMainAttributes().getValue(key);
+ if (manifest != null) {
+ String value = manifest.getMainAttributes().getValue(key);
if (value == null) {
- final Attributes attributes = this.manifest.getAttributes(key);
+ final Attributes attributes = manifest.getAttributes(key);
if (attributes != null) {
value = attributes.getValue(key);
}
@@ -477,9 +482,9 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
}
public String getBundleName() {
- if (this.manifest != null) {
+ if (manifest != null) {
final Name bundleName = new Name(BUNDLE_NAME);
- final String name = this.manifest.getMainAttributes().getValue(bundleName);
+ final String name = manifest.getMainAttributes().getValue(bundleName);
return name;
}
return null;
@@ -489,22 +494,21 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
if (newName == null) {
newName = "noName"; //$NON-NLS-1$
}
- final Name bundleNameName = new Name(BUNDLE_SYMBOLIC_NAME);
- this.manifest.getMainAttributes().put(bundleNameName, newName);
-
+ final Name bundleNameName = new Name(BUNDLE_NAME);
+ manifest.getMainAttributes().put(bundleNameName, newName);
}
public String getBundleLocalization() {
- if (this.manifest != null) {
+ if (manifest != null) {
final Name bundleLocalization = new Name(BUNDLE_LOCALIZATION);
- final String name = this.manifest.getMainAttributes().getValue(bundleLocalization);
+ final String name = manifest.getMainAttributes().getValue(bundleLocalization);
return name;
}
return null;
}
public void setSingleton(final boolean singleton) {
- String value = this.manifest.getMainAttributes().getValue(BUNDLE_SYMBOLIC_NAME);
+ String value = manifest.getMainAttributes().getValue(BUNDLE_SYMBOLIC_NAME);
final String[] directives = value.split(SEMICOLON);
if (directives.length == 0) {
@@ -525,6 +529,66 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
}
}
- this.manifest.getMainAttributes().putValue(BUNDLE_SYMBOLIC_NAME, value);
+ manifest.getMainAttributes().putValue(BUNDLE_SYMBOLIC_NAME, value);
+ }
+
+ /**
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IManifestEditor#addImportPackage(java.lang.String)
+ *
+ * @param packageName
+ */
+ public void addImportPackage(String packageName) {
+ addImportPackage(packageName, null);
+ }
+
+ public void addImportPackage(String packageName, String version) {
+ addPackage(packageName, IMPORT_PACKAGE, version);
+ }
+
+ /**
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IManifestEditor#addExportPackage(java.lang.String)
+ *
+ * @param packageName
+ */
+ public void addExportPackage(String packageName) {
+ addExportPackage(packageName, null);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IManifestEditor#addExportPackage(java.lang.String, java.lang.String)
+ *
+ * @param packageName
+ * @param version
+ */
+ public void addExportPackage(String packageName, String version) {
+ addPackage(packageName, EXPORT_PACKAGE, version);
+ }
+
+ /**
+ * Adds a package name in a manifest header type.
+ *
+ * @param packageName the package name to add
+ * @param type IMPORT_PACKAGE or EXPORT_PACKAGE
+ */
+ private void addPackage(String packageName, String type, String version) {
+ final Name manifestHeader = new Name(type);
+ String manifestHeaderValue = manifest.getMainAttributes().getValue(manifestHeader);
+
+ // TODO: Same as addDependency(final String, final String) : Improve the detection of existing packages
+
+ if (manifestHeaderValue == null) {
+ manifestHeaderValue = packageName;
+
+ if (version != null) {
+ manifestHeaderValue += SEMICOLON + "version=\"" + version + "\"";
+ }
+ } else if (!manifestHeaderValue.contains(packageName)) {
+ manifestHeaderValue += COMMA + packageName;
+
+ // TODO: Update version
+ }
+
+ manifest.getMainAttributes().put(manifestHeader, manifestHeaderValue);
}
}
diff --git a/plugins/infra/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IFeatureProjectEditor.java b/plugins/infra/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IFeatureProjectEditor.java
index 2552b8683ce..bd2a55630d3 100644
--- a/plugins/infra/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IFeatureProjectEditor.java
+++ b/plugins/infra/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IFeatureProjectEditor.java
@@ -1,51 +1,106 @@
package org.eclipse.papyrus.eclipse.project.editors.interfaces;
+import java.util.Set;
+
import org.w3c.dom.Document;
+public interface IFeatureProjectEditor {
+
+ void init();
+
+ void save();
+
+ void createFiles(final Set<String> files);
+
+ /**
+ * Retrieves the feature.xml XML Document associated to this project.
+ *
+ * @return The XML Document associated to this feature.xml file
+ */
+ Document getDocument();
+
+ /**
+ * Gets the feature's id.
+ *
+ * @return the feature's id
+ */
+ String getId();
+
+ /**
+ * Gets the feature's label.
+ *
+ * @return the feature's label
+ */
+ String getLabel();
+
+ /**
+ * Gets the feature's version.
+ *
+ * @return the feature's version
+ */
+ String getVersion();
+
+ /**
+ * Gets the feature's provider name.
+ *
+ * @return the feature's provider name
+ */
+ String getProviderName();
+
+ /**
+ * Gets the operating system of the feature
+ * @return
+ */
+ String getOS();
+
+ String getWS();
+
+ String getNL();
+
+ String getArch();
+
+ String getDescriptionText();
-public interface IFeatureProjectEditor { // TODo use interface inheritance
+ String getDescriptionURL();
- /** the name of the file plugin.xml */
- public static final String FRAGMENT_XML_FILE = "feature.xml"; //$NON-NLS-1$
+ String getCopyrightText();
- public static final String LABEL = "label"; //$NON-NLS-1$
+ String getCopyrightURL();
- public static final String VERSION = "version"; //$NON-NLS-1$
+ String getLicenseText();
- public static final String PROVIDER = "provider-name"; //$NON-NLS-1$
+ String getLicenceURL();
- public static final String URL = "url";
+ void setId(final String id);
- public static final String COPYRIGHT = "copyright";
+ void setLabel(final String label);
- public static final String LICENSE = "license";
+ void setVersion(final String version);
- /** the method to retrieve the plugin.xml XML Document associated to this project */
- public Document getDocument();
+ void setProviderName(final String providerName);
- public void setLabel(final String label);
+ void setOS(final String os);
- public void setVersion(final String version);
+ void setWS(final String ws);
- public void setProviderName(final String providerName);
+ void setNL(final String nl);
- public void setCopyright(final String copyrightURL, final String copyRightDesc);
+ void setArch(final String arch);
- public void setLicense(final String licenseURL, final String licenseDesc);
+ void setDescription(final String descriptionURL, final String descriptionDesc);
- public String getLabel();
+ void setCopyright(final String copyrightURL, final String copyrightDesc);
- public String getVersion();
+ void setLicense(final String licenseURL, final String licenseDesc);
- public String getProviderName();
+ void setUpdateURL(final String urlLabel, final String url);
- public String getCopyrightText();
+ void addPlugin(final String pluginName);
- public String getCopyrightURL();
+ void addRequiredFeature(final String featureName, final String version);
- public String getLicense();
+ void addRequiredPlugin(String pluginName);
- public void init();
+ void addInclude(String featureName, String version);
- public void save() throws Throwable;
}
diff --git a/plugins/infra/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IManifestEditor.java b/plugins/infra/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IManifestEditor.java
index a471b67f5c6..eb15371b8d0 100644
--- a/plugins/infra/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IManifestEditor.java
+++ b/plugins/infra/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IManifestEditor.java
@@ -39,7 +39,7 @@ public interface IManifestEditor extends IProjectEditor, IFileEditor {
public static final String REQUIRED_BUNDLE = "Require-Bundle"; //$NON-NLS-1$
/** the key for the bundle version */
- public static final String BUNDLE_VERSION = "bundle-version"; //$NON-NLS-1$
+ public static final String BUNDLE_VERSION = "Bundle-Version"; //$NON-NLS-1$
/** the key for the bundle vendor */
public static final String BUNDLE_VENDOR = "Bundle-Vendor"; //$NON-NLS-1$
@@ -49,7 +49,7 @@ public interface IManifestEditor extends IProjectEditor, IFileEditor {
/** the key for the bundle localization */
public static final String BUNDLE_LOCALIZATION = "Bundle-Localization"; //$NON-NLS-1$
-
+
/**
* Add a dependency to the MANIFEST
* @param dependency
@@ -195,4 +195,35 @@ public interface IManifestEditor extends IProjectEditor, IFileEditor {
* the version for the dependency
*/
public void setDependenciesVersion(final String dependencyPattern, final String newVersion);
+
+ /**
+ * Adds an import package to the MANIFEST.
+ *
+ * @param packageName the package name to add
+ */
+ public void addImportPackage(String packageName);
+
+ /**
+ * Adds an import package and its version to the MANIFEST.
+ *
+ * @param packageName the package name to add
+ * @param version the package version
+ */
+ public void addImportPackage(String packageName, String version);
+
+ /**
+ * Adds an export package to the MANFIEST.
+ *
+ * @param packageName the package name to add
+ */
+ public void addExportPackage(String packageName);
+
+ /**
+ * Adds an export package and its version to the MANIFEST.
+ *
+ * @param packageName the package name to add
+ * @param version the package version
+ */
+ public void addExportPackage(String packageName, String version);
+
}
diff --git a/plugins/infra/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/FeatureProjectEditor.java b/plugins/infra/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/FeatureProjectEditor.java
index d33deac3295..f53b3e0cd4e 100644
--- a/plugins/infra/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/FeatureProjectEditor.java
+++ b/plugins/infra/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/FeatureProjectEditor.java
@@ -41,23 +41,45 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
-
public class FeatureProjectEditor extends ProjectEditor implements IFeatureProjectEditor {
+ /** the name of the file feature.xml */
+ public static final String FRAGMENT_XML_FILE = "feature.xml"; //$NON-NLS-1$
+
+ private static final String ID = "id"; //$NON-NLS-1$
+ private static final String LABEL = "label"; //$NON-NLS-1$
+ private static final String VERSION = "version"; //$NON-NLS-1$
+ private static final String PROVIDER = "provider-name"; //$NON-NLS-1$
+
+ private static final String URL = "url"; //$NON-NLS-1$
+ private static final String COPYRIGHT = "copyright"; //$NON-NLS-1$
+ private static final String LICENSE = "license"; //$NON-NLS-1$
+ private static final String DESCRIPTION = "description"; //$NON-NLS-1$
+
+ private static final String OS = "os"; //$NON-NLS-1$
+ private static final String WS = "ws"; //$NON-NLS-1$
+ private static final String NL = "nl"; //$NON-NLS-1$
+ private static final String ARCH = "arch"; //$NON-NLS-1$
+ private static final String UPDATE = "update"; //$NON-NLS-1$
+
+ private static final String PLUGIN = "plugin"; //$NON-NLS-1$
+ private static final String IMPORT = "import"; //$NON-NLS-1$
+ private static final String INCLUDES = "includes"; //$NON-NLS-1$
+ private static final String REQUIRES = "requires"; //$NON-NLS-1$
+ private static final String FEATURE = "feature"; //$NON-NLS-1$
+
// TODO pour l'externalization : utiliser l'éditeur de Properties! dans java Utils
- private Document fragmentXML;;
+ private Document fragmentXML;
- private IFile fragmentFile;;
+ private IFile fragmentFile;
- private Element fragmentRoot;;
+ private Element fragmentRoot;
/**
- *
* Constructor.
*
- * @param project
- * the eclipse project
+ * @param project the eclipse project
* @throws ParserConfigurationException
* @throws SAXException
* @throws IOException
@@ -67,22 +89,15 @@ public class FeatureProjectEditor extends ProjectEditor implements IFeatureProje
super(project);
}
- /**
- *
- * @see org.eclipse.papyrus.eclipse.project.editors.project.ProjectEditor#init()
- *
- * {@inheritDoc}
- */
@Override
public void init() {
- this.fragmentFile = getPlugin();
- if ((this.fragmentFile != null) && this.fragmentFile.exists()) {
+ fragmentFile = getFeature();
+ if (fragmentFile != null && fragmentFile.exists()) {
final DocumentBuilderFactory documentFactory = DocumentBuilderFactory.newInstance();
- DocumentBuilder documentBuilder;
try {
- documentBuilder = documentFactory.newDocumentBuilder();
- this.fragmentXML = documentBuilder.parse(this.fragmentFile.getLocation().toOSString());
- this.fragmentRoot = this.fragmentXML.getDocumentElement();
+ DocumentBuilder documentBuilder = documentFactory.newDocumentBuilder();
+ fragmentXML = documentBuilder.parse(fragmentFile.getLocation().toOSString());
+ fragmentRoot = fragmentXML.getDocumentElement();
} catch (final ParserConfigurationException e) {
Activator.log.error(e);
} catch (final SAXException e) {
@@ -93,65 +108,44 @@ public class FeatureProjectEditor extends ProjectEditor implements IFeatureProje
}
}
- /**
- * Create the file plugin.xml
- *
- * @see org.eclipse.papyrus.eclipse.project.editors.project.ProjectEditor#createFiles(Set)
- *
- * {@inheritDoc}
- */
@Override
public void createFiles(final Set<String> files) {
- // TODO
- // throw new UnsupportedOperationException();
+ if (files.contains(FRAGMENT_XML_FILE)) {
+ fragmentFile = getProject().getFile(FRAGMENT_XML_FILE);
+ if (!fragmentFile.exists()) {
+ InputStream content = getInputStream("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<feature>\n</feature>\n\n"); //$NON-NLS-1$
+
+ try {
+ fragmentFile.create(content, true, null);
+ } catch (CoreException e) {
+ Activator.log.error(e);
+ }
+ }
+ }
}
- /**
- *
- * @see org.eclipse.papyrus.eclipse.project.editors.project.AbstractProjectEditor.plugin.AbstractEditor#exists()
- *
- * {@inheritDoc}
- */
@Override
public boolean exists() {
- final IFile plugin = getProject().getFile(FRAGMENT_XML_FILE);
- return plugin.exists() && super.exists();
+ return getFeature().exists() && super.exists();
}
-
-
-
- /**
- *
- * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IPluginProjectEditor#setAttribute(org.w3c.dom.Element, java.lang.String, java.lang.String)
- *
- * {@inheritDoc}
- */
public void setAttribute(final Element element, final String attributeName, final String attributeValue) {
element.setAttribute(attributeName, attributeValue);
}
-
/**
- *
- * @return
- * the plugin file if it exists
+ * @return the feature.xml file if it exists
*/
- private IFile getPlugin() {
- final IFile plugin = getProject().getFile(FRAGMENT_XML_FILE);
- if (plugin.exists()) {
- return plugin;
+ private IFile getFeature() {
+ final IFile fragment = getProject().getFile(FRAGMENT_XML_FILE);
+
+ if (fragment.exists()) {
+ return fragment;
}
+
return null;
}
-
- /**
- *
- * @see org.eclipse.papyrus.eclipse.project.editors.project.ProjectEditor#save()
- *
- * {@inheritDoc}
- */
@Override
public void save() {
if (exists()) {
@@ -160,11 +154,11 @@ public class FeatureProjectEditor extends ProjectEditor implements IFeatureProje
final Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); //$NON-NLS-1$
final StreamResult result = new StreamResult(new StringWriter());
- final DOMSource source = new DOMSource(this.fragmentXML);
+ final DOMSource source = new DOMSource(fragmentXML);
transformer.transform(source, result);
final InputStream inputStream = getInputStream(result.getWriter().toString());
- this.fragmentFile.setContents(inputStream, true, true, null);
+ fragmentFile.setContents(inputStream, true, true, null);
} catch (final TransformerException ex) {
Activator.log.error(ex);
} catch (final CoreException ex) {
@@ -174,102 +168,269 @@ public class FeatureProjectEditor extends ProjectEditor implements IFeatureProje
super.save();
}
- /**
- *
- * @see org.eclipse.papyrus.eclipse.project.editors.project.ProjectEditor#getMissingNature()
- *
- * {@inheritDoc}
- */
@Override
public Set<String> getMissingNature() {
- return Collections.EMPTY_SET;
// TODO
+ return Collections.emptySet();
}
- /**
- *
- * @see org.eclipse.papyrus.eclipse.project.editors.project.ProjectEditor#getMissingFiles()
- *
- * {@inheritDoc}
- */
@Override
public Set<String> getMissingFiles() {
- return Collections.EMPTY_SET;
// TODO
+ return Collections.emptySet();
}
- /**
- *
- * @see org.eclipse.papyrus.eclipse.project.editors.file.AbstractFileEditor#getMissingBuildCommand()
- *
- * {@inheritDoc}
- */
@Override
public Set<String> getMissingBuildCommand() {
- return Collections.emptySet();
// TODO
+ return Collections.emptySet();
}
- /**
- * @return The XML Document associated to this plugin.xml file
- * @see PluginProjectEditor#init()
- * @see PluginProjectEditor#create()
- */
public Document getDocument() {
- return this.fragmentXML;
+ return fragmentXML;
}
- public void setLabel(final String label) {
- this.fragmentRoot.setAttribute(LABEL, label);
+ public String getId() {
+ return fragmentRoot.getAttribute(ID);
+ }
+ public String getLabel() {
+ return fragmentRoot.getAttribute(LABEL);
}
- public void setVersion(final String version) {
- this.fragmentRoot.setAttribute(VERSION, version);
+ public String getVersion() {
+ return fragmentRoot.getAttribute(VERSION);
+ }
+ public String getProviderName() {
+ return fragmentRoot.getAttribute(PROVIDER);
}
- public void setProviderName(final String providerName) {
- this.fragmentRoot.setAttribute(PROVIDER, providerName);
+ public String getDescriptionText() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getDescriptionURL() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getCopyrightURL() {
+ final Element copyrightNode = getNode(COPYRIGHT);
+ if (copyrightNode != null) {
+ final String value = copyrightNode.getAttribute("url");
+ if (value != null && value.startsWith("%")) {
+ final IFile file = getProject().getFile("feature.properties");
+ final Properties prop = new Properties(); // TODO create a method to use Properties for others fields too
+ try {
+ prop.load(file.getContents());
+ } catch (final IOException e) {
+ Activator.log.error(e);
+ } catch (final CoreException e) {
+ Activator.log.error(e);
+ }
+ final Object val = prop.get("url");
+ if (val != null) {
+ return (String) val;
+ }
+ }
+ return copyrightNode.getAttribute("url");
+ }
+ return null;
+ }
+
+ public String getCopyrightText() {
+ final Element copyrightNode = getNode(COPYRIGHT);
+ return copyrightNode != null ? copyrightNode.getTextContent() : null;
}
- public static final String DESCRIPTION = "description";
+ public String getLicenseText() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getLicenceURL() {
+ // TODO Auto-generated method stub
+ return null;
+ }
- public static final String URL = "url";
+ public String getOS() {
+ return fragmentRoot.getAttribute(OS);
+ }
- public void setDescription(final String copyrightURL, final String copyrightDesc) {
+ public String getWS() {
+ return fragmentRoot.getAttribute(WS);
+ }
+
+ public String getNL() {
+ return fragmentRoot.getAttribute(NL);
+ }
+
+ public String getArch() {
+ return fragmentRoot.getAttribute(ARCH);
+ }
+
+ public void setId(final String id) {
+ fragmentRoot.setAttribute(ID, id);
+ }
+
+ public void setLabel(final String label) {
+ fragmentRoot.setAttribute(LABEL, label);
+ }
+
+ public void setVersion(final String version) {
+ fragmentRoot.setAttribute(VERSION, version);
+ }
+
+ public void setProviderName(final String providerName) {
+ fragmentRoot.setAttribute(PROVIDER, providerName);
+ }
+
+ public void setDescription(final String descriptionURL, final String description) {
if (exists()) {
- // this.fragmentRoot.getChildNodes():AttributeNode(name)
- // getDescriptionNode(DESCRIPTION);
Element extension = getNode(DESCRIPTION);
- ;// this.fragmentXML.getgetElementById(DESCRIPTION);
+
if (extension == null) {
- extension = this.fragmentXML.createElement(DESCRIPTION);
- extension.setAttribute(URL, copyrightURL);
- extension.setTextContent(copyrightDesc);
- this.fragmentRoot.appendChild(extension);
- } else {
- extension.setAttribute(URL, copyrightURL + "erase");
- extension.setTextContent(copyrightDesc + "erase");
+ extension = fragmentXML.createElement(DESCRIPTION);
+ fragmentRoot.appendChild(extension);
}
+
+ extension.setAttribute(URL, descriptionURL);
+ extension.setTextContent(description);
}
}
+ public void setCopyright(final String copyrightURL, final String copyrightDesc) {
+ setURLNode(COPYRIGHT, copyrightURL, copyrightDesc);
+ }
+
public void setLicense(final String licenseURL, final String licenseDesc) {
setURLNode(LICENSE, licenseURL, licenseDesc);
}
+ public void setOS(final String os) {
+ fragmentRoot.setAttribute(OS, os);
+ }
+
+ public void setWS(final String ws) {
+ fragmentRoot.setAttribute(WS, ws);
+ }
+
+ public void setNL(final String nl) {
+ fragmentRoot.setAttribute(NL, nl);
+ }
+
+ public void setArch(final String architecture) {
+ fragmentRoot.setAttribute(ARCH, architecture);
+ }
+
+ public void setUpdateURL(final String urlLabel, final String url) {
+ Element urlNode = getNode(URL);
+
+ if (urlNode == null) {
+ urlNode = createElement(URL);
+ fragmentRoot.appendChild(urlNode);
+ }
+
+ Element updateNode = getNodeChild(UPDATE, urlNode);
+ if (updateNode == null) {
+ updateNode = createElement(UPDATE);
+ urlNode.appendChild(updateNode);
+ }
+
+ updateNode.setAttribute(LABEL, urlLabel);
+ updateNode.setAttribute(URL, url);
+ }
+
+ public void addPlugin(final String pluginName) {
+ // Get the plug-in element or create it if it does not exist
+ Element pluginNode = getPlugin(pluginName);
+
+ if (pluginNode == null) {
+ pluginNode = createElement(PLUGIN);
+ fragmentRoot.appendChild(pluginNode);
+ }
+
+ // Set the id on the element
+ pluginNode.setAttribute(ID, pluginName);
+ }
+
+ public void addRequiredFeature(final String featureName, final String version) {
+ // Make sure the "requires" element exists
+ Element requires = getNode(REQUIRES);
+
+ if (requires == null) {
+ requires = createElement(REQUIRES);
+ fragmentRoot.appendChild(requires);
+ }
+
+ // Get or create the required feature element
+ Element feature = getRequiredFeature(featureName);
+
+ if (feature == null) {
+ feature = createElement(IMPORT);
+ requires.appendChild(feature);
+ }
+
+ // Set the element values
+ feature.setAttribute(FEATURE, featureName);
+ feature.setAttribute(VERSION, version);
+ }
+
+ public void addRequiredPlugin(final String pluginName) {
+ // Make sure the "requires" element exists
+ Element requires = getNode(REQUIRES);
+
+ if (requires == null) {
+ requires = createElement(REQUIRES);
+ fragmentRoot.appendChild(requires);
+ }
+
+ // Get or create the plug-in element
+ Element plugin = getRequiredPlugin(pluginName);
+
+ if (plugin == null) {
+ plugin = createElement(IMPORT);
+ requires.appendChild(plugin);
+ }
+
+ plugin.setAttribute(PLUGIN, pluginName);
+ }
+
+ public void addInclude(final String featureName, final String version) {
+ Element includeNode = getInclude(featureName);
+
+ if (includeNode == null) {
+ includeNode = createElement(INCLUDES);
+ fragmentRoot.appendChild(includeNode);
+ }
+
+ includeNode.setAttribute(ID, featureName);
+ includeNode.setAttribute(VERSION, version);
+ }
+
+ /**
+ * Creates an element and returns it.
+ *
+ * @param elementName the name of the element to create
+ * @return the created element
+ */
+ private Element createElement(String elementName) {
+ return fragmentXML.createElement(elementName);
+ }
+
protected void setURLNode(final String nodeName, final String url, final String description) {
if (exists()) {
Element extension = getNode(nodeName);
if (extension == null) {
- extension = this.fragmentXML.createElement(nodeName);
+ extension = fragmentXML.createElement(nodeName);
if (url != null) {
extension.setAttribute(URL, url);
}
extension.setTextContent(description);
- this.fragmentRoot.appendChild(extension);
+ fragmentRoot.appendChild(extension);
} else {
if (url != null) {
extension.setAttribute(URL, url);
@@ -279,69 +440,61 @@ public class FeatureProjectEditor extends ProjectEditor implements IFeatureProje
}
}
- public String getLabel() {
- return this.fragmentRoot.getAttribute(LABEL);
- }
-
- public String getVersion() {
- return this.fragmentRoot.getAttribute(VERSION);
- }
-
- public String getProviderName() {
- return this.fragmentRoot.getAttribute(PROVIDER);
- }
+ /**
+ * Gets an element inside a parent element.
+ *
+ * @param parentElement
+ * @param nodeName the node name of the element
+ * @param attributeValue the value of the element's attribute to retrieve
+ * @return the element or null if it does not exist
+ */
+ private Element getElement(final Element parentElement, final String nodeName, final String attributeName, final String attributeValue) {
+ NodeList childNodes = parentElement.getChildNodes();
- public void setCopyright(final String copyrightURL, final String copyrightDesc) {
- setURLNode(COPYRIGHT, copyrightURL, copyrightDesc);
- }
+ for (int i = 0; i < childNodes.getLength(); i++) {
+ Node item = childNodes.item(i);
- public String getCopyrightURL() {
- final Element copyrightNode = getNode(COPYRIGHT);
- if (copyrightNode != null) {
- final String value = copyrightNode.getAttribute("url");
- if ((value != null) && value.startsWith("%")) {
- final IFile file = getProject().getFile("feature.properties");
- final Properties prop = new Properties(); // TODO create a method to use Properties for others fields too
- try {
- prop.load(file.getContents());
- } catch (final IOException e) {
- Activator.log.error(e);
- } catch (final CoreException e) {
- Activator.log.error(e);
- }
- final Object val = prop.get("url");
- if (val != null) {
- return (String) val;
+ if (nodeName.equals(item.getNodeName())) {
+ if (attributeValue.equals(getNodeAttribute(item, attributeName))) {
+ if (item instanceof Element) {
+ return (Element) item;
+ }
}
}
- return copyrightNode.getAttribute("url");
}
+
return null;
}
+ private Element getNodeChild(final String childName, final Element node) {
+ NodeList childNodes = node.getChildNodes();
- public String getCopyrightText() {
- final Element copyrightNode = getNode(COPYRIGHT);
- if (copyrightNode != null) {
- return copyrightNode.getTextContent();
+ if (childNodes == null) {
+ return null;
+ }
+
+ for (int i = 0; i < childNodes.getLength(); i++) {
+ Node item = childNodes.item(i);
+
+ if (item.getNodeName().equals(childName)) {
+ if (item instanceof Element) {
+ return (Element) item;
+ }
+ }
}
- return null;
- }
- public String getLicense() {
- // TODO Auto-generated method stub
return null;
}
/**
+ * Gets a node element inside the root element.
*
- * @param nodeName
- * the node name
- * @return
+ * @param nodeName the node name
+ * @return the node element or null if it does not exist.
*/
- public Element getNode(final String nodeName) {
+ private Element getNode(final String nodeName) {
if (exists()) {
- final NodeList nodes = this.fragmentRoot.getChildNodes();
+ final NodeList nodes = fragmentRoot.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
final Node item = nodes.item(i);
if (item instanceof NodeList) {
@@ -354,6 +507,46 @@ public class FeatureProjectEditor extends ProjectEditor implements IFeatureProje
}
}
}
+
return null;
}
+
+ private Element getPlugin(String pluginName) {
+ return getElement(fragmentRoot, PLUGIN, ID, pluginName);
+ }
+
+ private Element getInclude(String featureName) {
+ return getElement(fragmentRoot, INCLUDES, ID, featureName);
+ }
+
+ /**
+ * @param pluginName
+ * @return
+ */
+ private Element getRequiredPlugin(String pluginName) {
+ Element requires = getNode(REQUIRES);
+
+ if (requires != null) {
+ return getElement(requires, IMPORT, PLUGIN, pluginName);
+ }
+
+ return null;
+ }
+
+ private String getNodeAttribute(Node node, String name) {
+ Node attribute = node.getAttributes().getNamedItem(name);
+
+ return attribute != null ? attribute.getNodeValue() : null;
+ }
+
+ private Element getRequiredFeature(String featureName) {
+ Element requires = getNode(REQUIRES);
+
+ if (requires != null) {
+ return getElement(requires, IMPORT, FEATURE, featureName);
+ }
+
+ return null;
+ }
+
}

Back to the top