Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvlorenzo2012-09-03 14:43:02 +0000
committervlorenzo2012-09-03 14:43:02 +0000
commit9f81d96165e90a69d1e31c43fa718d690a0d10f9 (patch)
tree03fad3ceb54285756f7a06cbfde8bcfb1664a1dc /sandbox
parentf3ef67054282e5f3cd19e92c5c7191b1be962c18 (diff)
downloadorg.eclipse.papyrus-9f81d96165e90a69d1e31c43fa718d690a0d10f9.tar.gz
org.eclipse.papyrus-9f81d96165e90a69d1e31c43fa718d690a0d10f9.tar.xz
org.eclipse.papyrus-9f81d96165e90a69d1e31c43fa718d690a0d10f9.zip
A save of my work on oep.eclipse.projects.editors
Diffstat (limited to 'sandbox')
-rw-r--r--sandbox/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/ManifestEditor.java125
-rw-r--r--sandbox/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IFeatureProjectEditor.java4
-rw-r--r--sandbox/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IManifestEditor.java2
-rw-r--r--sandbox/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/FeatureProjectEditor.java75
4 files changed, 122 insertions, 84 deletions
diff --git a/sandbox/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/ManifestEditor.java b/sandbox/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/ManifestEditor.java
index 370e32e76b8..2c93f7ba872 100644
--- a/sandbox/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/ManifestEditor.java
+++ b/sandbox/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/ManifestEditor.java
@@ -24,7 +24,6 @@ import org.eclipse.core.internal.resources.Folder;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.papyrus.eclipse.project.editors.Activator;
@@ -71,15 +70,15 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
@Override
public void init() {
super.init();
- if((manifest != null) && (manifestFile != null)) {
+ if((this.manifest != null) && (this.manifestFile != null)) {
return;
}
- if(manifestFile == null) {
- manifestFile = getManifestFile();
+ if(this.manifestFile == null) {
+ this.manifestFile = getManifestFile();
}
- if(manifestFile != null) {
+ if(this.manifestFile != null) {
try {
- manifest = new Manifest(manifestFile.getContents());
+ this.manifest = new Manifest(this.manifestFile.getContents());
} catch (final IOException e) {
Activator.log.error(e);
} catch (final CoreException e) {
@@ -97,7 +96,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 = manifest.getMainAttributes().getValue(rqBundle);
+ String requireBundle = this.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)
@@ -117,33 +116,36 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
requireBundle += ";" + version; //$NON-NLS-1$
}
}
- manifest.getMainAttributes().put(rqBundle, requireBundle);
+ this.manifest.getMainAttributes().put(rqBundle, requireBundle);
}
public void setDependenciesVersion(final String dependencyPattern, final String newVersion) {
final Name rqBundle = new Name(REQUIRED_BUNDLE);
- final String requireBundle = manifest.getMainAttributes().getValue(rqBundle);
- final String[] bundles = requireBundle.split(",");
- String newBundleRequired = "";
- for(int ii = 0; ii < bundles.length; ii++) {
- final String[] dependency = bundles[ii].split(";");
- Assert.isTrue(dependency.length <= 2);
- if(dependency[0].contains(dependencyPattern)) {
- final String newBundleVersion = "bundle-version=" + '"' + newVersion + '"';
- newBundleRequired += dependency[0] + ";" + newBundleVersion;
- } else {
- for(int i = 0; i < dependency.length; i++) {
- newBundleRequired += dependency[i];
- if(i < (dependency.length - 1)) {
- newBundleRequired += ";";
+ final String requireBundles = this.manifest.getMainAttributes().getValue(rqBundle);
+ final String[] bundles = requireBundles.split(",");
+ String newRequiredBundles = "";
+ for(int ii = 0; ii < bundles.length; ii++) {//we iterate on the declared dependencies
+ final String currentDependency = bundles[ii];
+ final String[] dependencyValue = currentDependency.split(";");
+ if(dependencyValue[0].contains(dependencyPattern)) {
+ final String newBundleVersion = BUNDLE_VERSION + "=" + '"' + newVersion + '"';
+ newRequiredBundles += dependencyValue[0] + ";" + newBundleVersion;
+ for(int i = 1; i < dependencyValue.length; i++) {
+ final String declaration = dependencyValue[i];
+ if(declaration.contains(BUNDLE_VERSION + "=")) {
+ //we ignore it
+ } else {
+ newRequiredBundles += ";" + dependencyValue[i];//we add the others declaration
}
}
+ } else {
+ newRequiredBundles += currentDependency;//we copy the existing declaration
}
if(ii < (bundles.length - 1)) {
- newBundleRequired += ",";
+ newRequiredBundles += ",";
}
}
- setValue(REQUIRED_BUNDLE, newBundleRequired);
+ setValue(REQUIRED_BUNDLE, newRequiredBundles);
}
@@ -164,7 +166,7 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
* {@inheritDoc}
*/
public void setValue(final String key, final String name, final String value) {
- manifest.getMainAttributes().putValue(key, value);
+ this.manifest.getMainAttributes().putValue(key, value);
// this.manifest.getAttributes(key).put(name, value);
}
@@ -185,7 +187,7 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
* {@inheritDoc}
*/
public void removeValue(final String key) {
- manifest.getAttributes(key).remove(key);
+ this.manifest.getAttributes(key).remove(key);
}
/**
@@ -223,10 +225,10 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
final ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
- manifest.write(os);
+ this.manifest.write(os);
final StringReader reader = new StringReader(os.toString("UTF-8")); //$NON-NLS-1$
- manifestFile.setContents(new InputStream() {
+ this.manifestFile.setContents(new InputStream() {
@Override
public int read() throws IOException {
@@ -235,7 +237,12 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
}, true, true, null);
//Use the PDE formatter for ManifestFiles
- FormatOperation.format(manifestFile, new NullProgressMonitor());
+ try {
+ FormatOperation.format(this.manifestFile, new NullProgressMonitor());
+ } catch (final Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
} catch (final IOException ex) {
Activator.log.error(ex);
} catch (final CoreException ex) {
@@ -262,22 +269,22 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
@Override
public void createFiles(final Set<String> files) {
if(files.contains(MANIFEST_PATH)) {
- manifestFile = getProject().getFile(MANIFEST_PATH);
- if(!manifestFile.exists()) {
+ this.manifestFile = getProject().getFile(MANIFEST_PATH);
+ if(!this.manifestFile.exists()) {
try {
final String input = "Manifest-Version: 1.0\n"; //without the "/n", it doesn't work!!!!! //$NON-NLS-1$
- if(!manifestFile.getParent().exists()) {
- final IContainer parent = manifestFile.getParent();
+ if(!this.manifestFile.getParent().exists()) {
+ final IContainer parent = this.manifestFile.getParent();
if(parent instanceof Folder) {
if(!parent.exists()) {
((Folder)parent).create(true, false, null);
}
}
}
- manifestFile.create(getInputStream(input), true, null);
- manifestFile = getProject().getFile(MANIFEST_PATH);
+ this.manifestFile.create(getInputStream(input), true, null);
+ this.manifestFile = getProject().getFile(MANIFEST_PATH);
- manifest = new Manifest(manifestFile.getContents());
+ this.manifest = new Manifest(this.manifestFile.getContents());
final int i;
// InputStream is = this.manifestFile.getContents();
@@ -316,7 +323,7 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
newName = "noName"; //$NON-NLS-1$
}
final Name symbolicName = new Name(BUNDLE_SYMBOLIC_NAME);
- manifest.getMainAttributes().put(symbolicName, newName);
+ this.manifest.getMainAttributes().put(symbolicName, newName);
}
/**
@@ -326,9 +333,9 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
* {@inheritDoc}
*/
public String getSymbolicBundleName() {
- if(manifest != null) {
+ if(this.manifest != null) {
final Name symbolicName = new Name(BUNDLE_SYMBOLIC_NAME);
- final String name = manifest.getMainAttributes().getValue(symbolicName);
+ final String name = this.manifest.getMainAttributes().getValue(symbolicName);
return name;
}
return null;
@@ -341,9 +348,9 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
* {@inheritDoc}
*/
public String getBundleVersion() {
- if(manifest != null) {
+ if(this.manifest != null) {
final Name symbolicName = new Name(BUNDLE_VERSION);
- final String version = manifest.getMainAttributes().getValue(symbolicName);
+ final String version = this.manifest.getMainAttributes().getValue(symbolicName);
return version;
}
return null;
@@ -355,12 +362,12 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
* {@inheritDoc}
*/
public void setBundleVersion(final String version) {
- if(manifest != null) {
+ if(this.manifest != null) {
final Name bundleVersion = new Name(BUNDLE_VERSION);
if(version == null) {
- manifest.getMainAttributes().remove(bundleVersion);
+ this.manifest.getMainAttributes().remove(bundleVersion);
} else {
- manifest.getMainAttributes().put(bundleVersion, version);
+ this.manifest.getMainAttributes().put(bundleVersion, version);
}
}
}
@@ -371,9 +378,9 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
* {@inheritDoc}
*/
public String getBundleVendor() {
- if(manifest != null) {
+ if(this.manifest != null) {
final Name bundleVendor = new Name(BUNDLE_VENDOR);
- return manifest.getMainAttributes().getValue(bundleVendor);
+ return this.manifest.getMainAttributes().getValue(bundleVendor);
}
return null;
}
@@ -384,21 +391,21 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
* {@inheritDoc}
*/
public void setBundleVendor(final String vendor) {
- if(manifest != null) {
+ if(this.manifest != null) {
final Name bundleVendor = new Name(BUNDLE_VENDOR);
if(vendor == null) {
- manifest.getMainAttributes().remove(bundleVendor);
+ this.manifest.getMainAttributes().remove(bundleVendor);
} else {
- manifest.getMainAttributes().put(bundleVendor, vendor);
+ this.manifest.getMainAttributes().put(bundleVendor, vendor);
}
}
}
public String getValue(final String key) {
- if(manifest != null) {
- String value = manifest.getMainAttributes().getValue(key);
+ if(this.manifest != null) {
+ String value = this.manifest.getMainAttributes().getValue(key);
if(value == null) {
- final Attributes attributes = manifest.getAttributes(key);
+ final Attributes attributes = this.manifest.getAttributes(key);
if(attributes != null) {
value = attributes.getValue(key);
}
@@ -409,9 +416,9 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
}
public String getBundleName() {
- if(manifest != null) {
+ if(this.manifest != null) {
final Name bundleName = new Name(BUNDLE_NAME);
- final String name = manifest.getMainAttributes().getValue(bundleName);
+ final String name = this.manifest.getMainAttributes().getValue(bundleName);
return name;
}
return null;
@@ -422,21 +429,21 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
newName = "noName"; //$NON-NLS-1$
}
final Name bundleNameName = new Name(BUNDLE_SYMBOLIC_NAME);
- manifest.getMainAttributes().put(bundleNameName, newName);
+ this.manifest.getMainAttributes().put(bundleNameName, newName);
}
public String getBundleLocalization() {
- if(manifest != null) {
+ if(this.manifest != null) {
final Name bundleLocalization = new Name(BUNDLE_LOCALIZATION);
- final String name = manifest.getMainAttributes().getValue(bundleLocalization);
+ final String name = this.manifest.getMainAttributes().getValue(bundleLocalization);
return name;
}
return null;
}
public void setSingleton(final boolean singleton) {
- String value = manifest.getMainAttributes().getValue("bundle-symbolicName");
+ String value = this.manifest.getMainAttributes().getValue("bundle-symbolicName");
final String[] directives = value.split(";");
if(directives.length == 0) {
@@ -457,6 +464,6 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
}
}
- manifest.getMainAttributes().putValue("bundle-symbolicName", value);
+ this.manifest.getMainAttributes().putValue("bundle-symbolicName", value);
}
}
diff --git a/sandbox/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IFeatureProjectEditor.java b/sandbox/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IFeatureProjectEditor.java
index f269109d2fd..186764ae7d5 100644
--- a/sandbox/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IFeatureProjectEditor.java
+++ b/sandbox/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IFeatureProjectEditor.java
@@ -39,7 +39,9 @@ public interface IFeatureProjectEditor { //TODo use interface inheritance
public String getProviderName();
- public String getCopyright();
+ public String getCopyrightText();
+
+ public String getCopyrightURL();
public String getLicense();
diff --git a/sandbox/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IManifestEditor.java b/sandbox/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IManifestEditor.java
index 2e8489c7d87..e8677841b73 100644
--- a/sandbox/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IManifestEditor.java
+++ b/sandbox/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$
diff --git a/sandbox/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/FeatureProjectEditor.java b/sandbox/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/FeatureProjectEditor.java
index e3f23483b78..8b341fbc39d 100644
--- a/sandbox/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/FeatureProjectEditor.java
+++ b/sandbox/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/FeatureProjectEditor.java
@@ -4,6 +4,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.util.Collections;
+import java.util.Properties;
import java.util.Set;
import javax.xml.parsers.DocumentBuilder;
@@ -62,18 +63,18 @@ public class FeatureProjectEditor extends ProjectEditor implements IFeatureProje
@Override
public void init() {
this.fragmentFile = getPlugin();
- if(this.fragmentFile != null && this.fragmentFile.exists()) {
- DocumentBuilderFactory documentFactory = DocumentBuilderFactory.newInstance();
+ if((this.fragmentFile != null) && this.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();
- } catch (ParserConfigurationException e) {
+ } catch (final ParserConfigurationException e) {
Activator.log.error(e);
- } catch (SAXException e) {
+ } catch (final SAXException e) {
Activator.log.error(e);
- } catch (IOException e) {
+ } catch (final IOException e) {
Activator.log.error(e);
}
}
@@ -100,7 +101,7 @@ public class FeatureProjectEditor extends ProjectEditor implements IFeatureProje
*/
@Override
public boolean exists() {
- IFile plugin = getProject().getFile(FRAGMENT_XML_FILE);
+ final IFile plugin = getProject().getFile(FRAGMENT_XML_FILE);
return plugin.exists() && super.exists();
}
@@ -125,7 +126,7 @@ public class FeatureProjectEditor extends ProjectEditor implements IFeatureProje
* the plugin file if it exists
*/
private IFile getPlugin() {
- IFile plugin = getProject().getFile(FRAGMENT_XML_FILE);
+ final IFile plugin = getProject().getFile(FRAGMENT_XML_FILE);
if(plugin.exists()) {
return plugin;
}
@@ -143,18 +144,18 @@ public class FeatureProjectEditor extends ProjectEditor implements IFeatureProje
public void save() {
if(exists()) {
try {
- TransformerFactory transformerFactory = TransformerFactory.newInstance();
- Transformer transformer = transformerFactory.newTransformer();
+ final TransformerFactory transformerFactory = TransformerFactory.newInstance();
+ final Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); //$NON-NLS-1$
- StreamResult result = new StreamResult(new StringWriter());
- DOMSource source = new DOMSource(this.fragmentXML);
+ final StreamResult result = new StreamResult(new StringWriter());
+ final DOMSource source = new DOMSource(this.fragmentXML);
transformer.transform(source, result);
- InputStream inputStream = getInputStream(result.getWriter().toString());
+ final InputStream inputStream = getInputStream(result.getWriter().toString());
this.fragmentFile.setContents(inputStream, true, true, null);
- } catch (TransformerException ex) {
+ } catch (final TransformerException ex) {
Activator.log.error(ex);
- } catch (CoreException ex) {
+ } catch (final CoreException ex) {
Activator.log.error(ex);
}
}
@@ -203,20 +204,20 @@ public class FeatureProjectEditor extends ProjectEditor implements IFeatureProje
* @see PluginProjectEditor#create()
*/
public Document getDocument() {
- return fragmentXML;
+ return this.fragmentXML;
}
- public void setLabel(String label) {
+ public void setLabel(final String label) {
this.fragmentRoot.setAttribute(LABEL, label);
}
- public void setVersion(String version) {
+ public void setVersion(final String version) {
this.fragmentRoot.setAttribute(VERSION, version);
}
- public void setProviderName(String providerName) {
+ public void setProviderName(final String providerName) {
this.fragmentRoot.setAttribute(PROVIDER, providerName);
}
@@ -281,8 +282,36 @@ public class FeatureProjectEditor extends ProjectEditor implements IFeatureProje
setURLNode(COPYRIGHT, copyrightURL, copyrightDesc);
}
- public String getCopyright() {
- // TODO Auto-generated method stub
+ 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);
+ if(copyrightNode != null) {
+ return copyrightNode.getTextContent();
+ }
return null;
}
@@ -299,11 +328,11 @@ public class FeatureProjectEditor extends ProjectEditor implements IFeatureProje
*/
public Element getNode(final String nodeName) {
if(exists()) {
- NodeList nodes = this.fragmentRoot.getChildNodes();
+ final NodeList nodes = this.fragmentRoot.getChildNodes();
for(int i = 0; i < nodes.getLength(); i++) {
- Node item = nodes.item(i);
+ final Node item = nodes.item(i);
if(item instanceof NodeList) {
- String name = item.getNodeName();
+ final String name = item.getNodeName();
if(name.equals(nodeName)) {
if(item instanceof Element) {
return (Element)item;

Back to the top