Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2012-09-04 14:01:21 +0000
committercletavernie2012-09-04 14:01:21 +0000
commit0ffb6ecd61374bbfd181d3b74a50b8b8249948d5 (patch)
tree8b1cef91c3d54051e3f5de80d3ed43186a35bcef /incoming
parent1dc96930ea65272fa24edc3c62b0ccb40dd6e5dd (diff)
downloadorg.eclipse.papyrus-0ffb6ecd61374bbfd181d3b74a50b8b8249948d5.tar.gz
org.eclipse.papyrus-0ffb6ecd61374bbfd181d3b74a50b8b8249948d5.tar.xz
org.eclipse.papyrus-0ffb6ecd61374bbfd181d3b74a50b8b8249948d5.zip
351695: Create a new plugin to edit project files
https://bugs.eclipse.org/bugs/show_bug.cgi?id=351695 Move to Incoming
Diffstat (limited to 'incoming')
-rw-r--r--incoming/org.eclipse.papyrus.eclipse.project.editors/.classpath7
-rw-r--r--incoming/org.eclipse.papyrus.eclipse.project.editors/.project28
-rw-r--r--incoming/org.eclipse.papyrus.eclipse.project.editors/.settings/org.eclipse.jdt.core.prefs8
-rw-r--r--incoming/org.eclipse.papyrus.eclipse.project.editors/META-INF/MANIFEST.MF23
-rw-r--r--incoming/org.eclipse.papyrus.eclipse.project.editors/about.html28
-rw-r--r--incoming/org.eclipse.papyrus.eclipse.project.editors/build.properties9
-rw-r--r--incoming/org.eclipse.papyrus.eclipse.project.editors/plugin.properties3
-rw-r--r--incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/Activator.java75
-rw-r--r--incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/AbstractFileEditor.java122
-rw-r--r--incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/BuildEditor.java290
-rw-r--r--incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/BundlePropertiesEditor.java67
-rw-r--r--incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/ClasspathEditor.java260
-rw-r--r--incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/ManifestEditor.java469
-rw-r--r--incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IBuildEditor.java98
-rw-r--r--incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IClasspathEditor.java55
-rw-r--r--incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IEMFFacetProjectEditor.java77
-rw-r--r--incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IFeatureProjectEditor.java51
-rw-r--r--incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IFileEditor.java66
-rw-r--r--incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IJavaProjectEditor.java37
-rw-r--r--incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IManifestEditor.java190
-rw-r--r--incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IPluginProjectEditor.java58
-rw-r--r--incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IProjectEditor.java93
-rw-r--r--incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/AbstractProjectEditor.java195
-rw-r--r--incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/EMFFacetProjectEditor.java264
-rw-r--r--incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/FeatureProjectEditor.java346
-rw-r--r--incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/JavaProjectEditor.java251
-rw-r--r--incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/PluginProjectEditor.java305
-rw-r--r--incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/ProjectEditor.java150
28 files changed, 3625 insertions, 0 deletions
diff --git a/incoming/org.eclipse.papyrus.eclipse.project.editors/.classpath b/incoming/org.eclipse.papyrus.eclipse.project.editors/.classpath
new file mode 100644
index 00000000000..2d1a4302f04
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.eclipse.project.editors/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/incoming/org.eclipse.papyrus.eclipse.project.editors/.project b/incoming/org.eclipse.papyrus.eclipse.project.editors/.project
new file mode 100644
index 00000000000..1da496825fa
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.eclipse.project.editors/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.eclipse.project.editors</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/incoming/org.eclipse.papyrus.eclipse.project.editors/.settings/org.eclipse.jdt.core.prefs b/incoming/org.eclipse.papyrus.eclipse.project.editors/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000000..f5fc84e38e8
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.eclipse.project.editors/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+#Wed Jun 08 09:07:16 CEST 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/incoming/org.eclipse.papyrus.eclipse.project.editors/META-INF/MANIFEST.MF b/incoming/org.eclipse.papyrus.eclipse.project.editors/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..a421783e795
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.eclipse.project.editors/META-INF/MANIFEST.MF
@@ -0,0 +1,23 @@
+Manifest-Version: 1.0
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.papyrus.infra.core.log;bundle-version="0.9.0",
+ org.eclipse.core.resources,
+ org.eclipse.jdt.core,
+ org.eclipse.papyrus.infra.widgets;bundle-version="0.9.0",
+ org.eclipse.emf.facet.infra.facet,
+ org.eclipse.pde.ui;bundle-version="3.6.100"
+Export-Package: org.eclipse.papyrus.eclipse.project.editors.file,
+ org.eclipse.papyrus.eclipse.project.editors.interfaces,
+ org.eclipse.papyrus.eclipse.project.editors.project
+Bundle-Vendor: %providerName
+Bundle-ActivationPolicy: lazy
+Bundle-Version: 0.9.0.qualifier
+Bundle-Name: %pluginName
+Bundle-Localization: plugin
+Bundle-ManifestVersion: 2
+Bundle-Activator: org.eclipse.papyrus.eclipse.project.editors.Activato
+ r
+Bundle-SymbolicName: org.eclipse.papyrus.eclipse.project.editors
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+
diff --git a/incoming/org.eclipse.papyrus.eclipse.project.editors/about.html b/incoming/org.eclipse.papyrus.eclipse.project.editors/about.html
new file mode 100644
index 00000000000..82d49bf5f81
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.eclipse.project.editors/about.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 5, 2007</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
+
+</body>
+</html>
diff --git a/incoming/org.eclipse.papyrus.eclipse.project.editors/build.properties b/incoming/org.eclipse.papyrus.eclipse.project.editors/build.properties
new file mode 100644
index 00000000000..3fbd2f3c6c5
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.eclipse.project.editors/build.properties
@@ -0,0 +1,9 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ about.html,\
+ plugin.properties
+src.includes = about.html,\
+ plugin.properties,\
+ META-INF/
diff --git a/incoming/org.eclipse.papyrus.eclipse.project.editors/plugin.properties b/incoming/org.eclipse.papyrus.eclipse.project.editors/plugin.properties
new file mode 100644
index 00000000000..42abf061b63
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.eclipse.project.editors/plugin.properties
@@ -0,0 +1,3 @@
+#Properties file for org.eclipse.papyrus.eclipse.project.editors
+providerName = Eclipse Modeling Project
+pluginName = Editors for the Eclipse Project (Incubation) \ No newline at end of file
diff --git a/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/Activator.java b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/Activator.java
new file mode 100644
index 00000000000..70b9421b8f7
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/Activator.java
@@ -0,0 +1,75 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.eclipse.project.editors;
+
+import org.eclipse.papyrus.infra.core.log.LogHelper;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.eclipse.project.editors"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ public static LogHelper log;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
+ * )
+ */
+ @Override
+ public void start(final BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ log = new LogHelper(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
+ * )
+ */
+ @Override
+ public void stop(final BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+}
diff --git a/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/AbstractFileEditor.java b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/AbstractFileEditor.java
new file mode 100644
index 00000000000..bad4b1e16a2
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/AbstractFileEditor.java
@@ -0,0 +1,122 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.eclipse.project.editors.file;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringReader;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.papyrus.eclipse.project.editors.Activator;
+import org.eclipse.papyrus.eclipse.project.editors.interfaces.IFileEditor;
+
+/**
+ *
+ * An abstract class for File Editor
+ *
+ */
+public abstract class AbstractFileEditor implements IFileEditor {
+
+ /** the Eclipse Project */
+ private final IProject project;
+
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param project
+ * the eclipse project
+ */
+ public AbstractFileEditor(final IProject project) {
+ this.project = project;
+ }
+
+ /**
+ *
+ * @return
+ * the eclipse project
+ */
+ public IProject getProject() {
+ return this.project;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.project.AbstractProjectEditor#init()
+ *
+ * {@inheritDoc}
+ */
+ public void init() {
+
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IProjectEditor#getMissingFiles()
+ *
+ * {@inheritDoc}
+ */
+ public Set<String> getMissingFiles() {
+ return new HashSet<String>();
+ }
+
+ /**
+ *
+ * @param text
+ * the initial text
+ * @return
+ * an input stream
+ */
+ protected InputStream getInputStream(final String text) {
+ if(text == null) {
+ Activator.log.warn("Cannot open an input stream for a null text"); //$NON-NLS-1$
+ return null;
+ }
+
+ final StringReader sr = new StringReader(text);
+ InputStream is = new InputStream() {
+
+ @Override
+ public int read() throws IOException {
+ return sr.read();
+ }
+
+ };
+ return is;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.project.AbstractProjectEditor.plugin.AbstractEditor#exists()
+ *
+ * {@inheritDoc}
+ */
+ public boolean exists() {
+ return getMissingFiles().size() == 0;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IFileEditor#create()
+ *
+ * {@inheritDoc}
+ */
+ public void create() {
+ createFiles(getMissingFiles());
+ init();
+ }
+}
diff --git a/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/BuildEditor.java b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/BuildEditor.java
new file mode 100644
index 00000000000..ebdb5de82b0
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/BuildEditor.java
@@ -0,0 +1,290 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ * Vincent Lorenzo (CEA-LIST) vincent.lorenzo@cea.fr
+ *****************************************************************************/
+package org.eclipse.papyrus.eclipse.project.editors.file;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.papyrus.eclipse.project.editors.Activator;
+import org.eclipse.papyrus.eclipse.project.editors.interfaces.IBuildEditor;
+import org.eclipse.papyrus.infra.widgets.util.FileUtil;
+
+public class BuildEditor extends AbstractFileEditor implements IBuildEditor {
+
+ /** the build config */
+ private Properties buildConfig;
+
+ /** the buidl file */
+ private File buildFile;
+
+ /**
+ * The build key to edit
+ * Defaults to "bin.includes" (The eclipse standard binary build)
+ */
+ private String buildKey = "bin.includes"; //$NON-NLS-1$
+
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param project
+ * the eclipse project
+ */
+ public BuildEditor(final IProject project) {
+ super(project);
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param project
+ * the eclipse project
+ * @param buildKey
+ * the build key to edit. If null, the "bin.includes" key will be used
+ *
+ * @see IBuildEditor#BINARY_BUILD
+ * @see IBuildEditor#SOURCE_BUILD
+ */
+ public BuildEditor(final IProject project, String buildKey) {
+ super(project);
+ if(buildKey != null) {
+ this.buildKey = buildKey;
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.project.ProjectEditor#init()
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public void init() {
+ this.buildConfig = new Properties();
+ this.buildFile = getBuildProperties();
+ if(this.buildFile != null && this.buildFile.exists()) {
+ try {
+ this.buildConfig.load(new FileInputStream(this.buildFile));
+ } catch (FileNotFoundException e) {
+ Activator.log.error(e);
+ } catch (IOException e) {
+ Activator.log.error(e);
+ }
+ }
+ }
+
+
+ private File getBuildProperties() {
+ return this.buildFile = FileUtil.getWorkspaceFile("/" + getProject().getName() + "/" + BUILD_PROPERTIES_FILE); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IBuildEditor#addToBuild(java.lang.String)
+ *
+ * {@inheritDoc}
+ */
+ public void addToBuild(final String path) {
+ if(exists()) {
+ String currentValue = this.buildConfig.getProperty(buildKey);
+ if(Arrays.asList(getElementsInBuild()).contains(path)) {
+ return;
+ }
+ if(currentValue == null || currentValue.trim().equals("")) { //$NON-NLS-1$
+ this.buildConfig.setProperty(buildKey, path);
+ } else {
+ this.buildConfig.setProperty(buildKey, currentValue + "," + path); //$NON-NLS-1$
+ }
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IBuildEditor#removeFromBuild(java.lang.String)
+ *
+ * {@inheritDoc}
+ */
+ public void removeFromBuild(String path) {
+ if(isRegisteredSourceFolder(path)) {
+ //Get the files from the build
+ List<String> allFiles = Arrays.asList(getElementsInBuild());
+
+ //Clear the build
+ this.buildConfig.setProperty(buildKey, "");
+
+ //Recreate the build without the removed files
+ for(String filePath : allFiles) {
+ if(!filePath.equals(path)) {
+ addToBuild(filePath);
+ }
+ }
+ }
+ }
+
+ /**
+ *
+ * @throws Throwable
+ * @see org.eclipse.papyrus.eclipse.project.editors.project.ProjectEditor#save()
+ *
+ * {@inheritDoc}
+ */
+ public void save() {
+ if(exists()) {
+ try {
+ this.buildConfig.store(new FileOutputStream(this.buildFile), "");
+ } catch (FileNotFoundException ex) {
+ Activator.log.error(ex);
+ } catch (IOException ex) {
+ Activator.log.error(ex);
+ }
+ }
+ }
+
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IBuildEditor#registerSourceFolder(java.lang.String)
+ *
+ * {@inheritDoc}
+ */
+ public void registerSourceFolder(final String path) {
+ if(exists() && !isRegisteredSourceFolder(path)) {
+ String currentValue = this.buildConfig.getProperty(SOURCE_FOLDER_KEY);
+ if(currentValue == null || currentValue.trim().equals("")) { //$NON-NLS-1$
+ this.buildConfig.setProperty(SOURCE_FOLDER_KEY, path);
+ } else {
+ this.buildConfig.setProperty(SOURCE_FOLDER_KEY, currentValue + "," + path); //$NON-NLS-1$
+ }
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IBuildEditor#isRegistred(java.lang.String)
+ *
+ * {@inheritDoc}
+ */
+ public boolean isRegisteredSourceFolder(final String path) {
+ return Arrays.asList(getSourceFolders()).contains(path);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.file.AbstractFileEditor#getMissingFiles()
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<String> getMissingFiles() {
+ Set<String> files = super.getMissingFiles();
+ if(!getBuildProperties().exists()) {
+ files.add(BUILD_PROPERTIES_FILE);
+ }
+ return files;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IBuildEditor#getSourceFolders()
+ *
+ * {@inheritDoc}
+ */
+ public String[] getSourceFolders() {
+ if(exists()) {
+ String currentValue = this.buildConfig.getProperty(SOURCE_FOLDER_KEY, "").replaceAll("\t|\r|\n", "").trim();
+ String[] values = currentValue.split(","); //$NON-NLS-1$
+ return values;
+ }
+ return new String[0];
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.project.AbstractProjectEditor#exists()
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean exists() {
+ return this.buildFile.getParentFile().exists() && this.buildFile.exists() && super.exists();
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.project.ProjectEditor#createFiles(Set)
+ *
+ * {@inheritDoc}
+ */
+ public void createFiles(final Set<String> files) {
+ if(files.contains(BUILD_PROPERTIES_FILE)) {
+ if(!this.buildFile.exists()) {
+ if(!this.buildFile.getParentFile().exists()) {
+ this.buildFile.getParentFile().mkdirs();
+ }
+ try {
+ this.buildFile.createNewFile();
+ init();
+ } catch (IOException e) {
+ Activator.log.error(e);
+ }
+ }
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IBuildEditor#getElementsInBuild()
+ *
+ * {@inheritDoc}
+ */
+ public String[] getElementsInBuild() {
+ String value = this.buildConfig.getProperty(buildKey);
+ return splitValues(value);
+ }
+
+ private String[] splitValues(String value) {
+ if(value == null) {
+ return new String[0];
+ }
+ return value.replace("\t|\r|\n", "").split(","); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void registerBinFolder(String binFolder) {
+ if(isRegisteredBinFolder(binFolder)) {
+ return;
+ }
+
+ String value = this.buildConfig.getProperty(BIN_KEY, ""); //$NON-NLS-1$
+ if(value.trim().equals("")) { //$NON-NLS-1$
+ value = binFolder;
+ } else {
+ value = value + "," + binFolder;
+ }
+ this.buildConfig.setProperty(BIN_KEY, value);
+ }
+
+ public boolean isRegisteredBinFolder(String binFolder) {
+ List<String> folders = Arrays.asList(splitValues(this.buildConfig.getProperty(BIN_KEY, ""))); //$NON-NLS-1$
+ return folders.contains(binFolder);
+ }
+}
diff --git a/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/BundlePropertiesEditor.java b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/BundlePropertiesEditor.java
new file mode 100644
index 00000000000..4cc9a9e7a44
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/BundlePropertiesEditor.java
@@ -0,0 +1,67 @@
+package org.eclipse.papyrus.eclipse.project.editors.file;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Properties;
+import java.util.Set;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.papyrus.eclipse.project.editors.Activator;
+import org.eclipse.papyrus.infra.widgets.util.FileUtil;
+
+
+public class BundlePropertiesEditor extends AbstractFileEditor {
+
+ /** the build config */
+ private Properties bundleConfig;
+
+ /** the buidl file */
+ private File bundleFile;
+
+ private String filePath;
+
+ public BundlePropertiesEditor(IProject project, String filePath) {
+ super(project);
+ this.filePath = filePath;
+
+ }
+
+ @Override
+ public void init() {
+ this.bundleFile = getBundleProperties();
+ // if(this.bundleFile != null && this.bundleFile.exists()) {
+ try {
+ this.bundleConfig.load(new FileInputStream(this.bundleFile));
+ } catch (FileNotFoundException e) {
+ Activator.log.error(e);
+ } catch (IOException e) {
+ Activator.log.error(e);
+ }
+ // }
+ }
+
+ public void createFiles(Set<String> files) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void save() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public String getValue(String propertyName) {
+ return this.bundleConfig.getProperty(propertyName);
+
+ }
+
+
+
+
+
+ private File getBundleProperties() {
+ return this.bundleFile = FileUtil.getWorkspaceFile("/" + getProject().getName() + "/" + filePath + ".properties"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+}
diff --git a/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/ClasspathEditor.java b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/ClasspathEditor.java
new file mode 100644
index 00000000000..70a8d2c8b8f
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/ClasspathEditor.java
@@ -0,0 +1,260 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.eclipse.project.editors.file;
+
+
+import java.io.InputStream;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.AssertionFailedException;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.IAccessRule;
+import org.eclipse.jdt.core.IClasspathAttribute;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.core.ClasspathEntry;
+import org.eclipse.papyrus.eclipse.project.editors.Activator;
+import org.eclipse.papyrus.eclipse.project.editors.interfaces.IClasspathEditor;
+
+/**
+ *
+ * The editor for the classpath file
+ *
+ */
+public class ClasspathEditor extends AbstractFileEditor implements IClasspathEditor {
+
+ /**
+ * the edited java project
+ */
+ private final IJavaProject javaProject;
+
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param project
+ */
+ public ClasspathEditor(final IProject project) throws AssertionFailedException {
+ super(project);
+ this.javaProject = JavaCore.create(project);
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param javaProject
+ * a java project
+ */
+ public ClasspathEditor(final IJavaProject javaProject) {
+ super(javaProject.getProject());
+ this.javaProject = javaProject;
+ }
+
+ @Override
+ public void init() {
+ //nothing to do here
+ }
+
+ /**
+ * save the modification
+ *
+ * @throws Throwable
+ */
+ public void save() {
+ try {
+ this.javaProject.save(new NullProgressMonitor(), true);
+ } catch (JavaModelException ex) {
+ Activator.log.error(ex);
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IClasspathEditor#addSourceFolderToClasspath(java.lang.String)
+ *
+ * {@inheritDoc}
+ */
+ public void addSourceFolderToClasspath(final String folderPath) {
+
+ if(exists() && !isSourceFolderRegistered(folderPath)) {
+
+ //parameters for the new ClasspathEntry
+ boolean isExported = false;
+ IPath[] exclusionPatterns = new IPath[0];
+ IPath sourceAttachmentPath = null;
+ IPath specificOutputLocation = null;
+ boolean combineAccessRules = false;
+ IClasspathAttribute[] extraAttributes = new IClasspathAttribute[0];
+ IPath sourceAttachmentRootPath = null;
+ IAccessRule[] accessRules = null;
+ int contentKind = IPackageFragmentRoot.K_SOURCE;
+ IPath[] inclusionPatterns = new IPath[0];
+ int entryKind = IClasspathEntry.CPE_SOURCE;
+ IPath path2 = new Path(folderPath);
+
+ IClasspathEntry[] classpathes = null;
+ try {
+ classpathes = this.javaProject.getRawClasspath();
+ } catch (JavaModelException e) {
+ e.printStackTrace();
+ }
+
+ IClasspathEntry[] entries = new IClasspathEntry[classpathes.length + 1];
+ for(int i = 0; i < classpathes.length; i++) {
+ entries[i] = classpathes[i];
+ }
+ entries[classpathes.length] = new ClasspathEntry(contentKind, entryKind, path2, inclusionPatterns, exclusionPatterns, sourceAttachmentPath, sourceAttachmentRootPath, specificOutputLocation, isExported, accessRules, combineAccessRules, extraAttributes);
+ try {
+ this.javaProject.setRawClasspath(entries, new NullProgressMonitor());
+ } catch (JavaModelException e) {
+ Activator.log.error(e);
+ }
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IClasspathEditor#isSourceFolderRegistered(java.lang.String)
+ *
+ * {@inheritDoc}
+ */
+ public boolean isSourceFolderRegistered(final String folderPath) {
+ IClasspathEntry[] entries = null;
+ try {
+ entries = this.javaProject.getRawClasspath();
+ } catch (JavaModelException e) {
+ Activator.log.error(e);
+ }
+
+ for(int i = 0; i < entries.length; i++) {
+ IClasspathEntry entry = entries[i];
+ if(entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
+ if(entry.getPath().equals(new Path(folderPath))) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Tests if the classpath file exists
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.project.AbstractProjectEditor.plugin.AbstractEditor#exists()
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean exists() {
+ IFile classpath = getProject().getFile(CLASSPATH_FILE);
+ return classpath.exists();
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.project.ProjectEditor#getMissingFiles()
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<String> getMissingFiles() {
+ Set<String> files = super.getMissingFiles();
+ IFile classpath = getProject().getFile(CLASSPATH_FILE);
+ if(!classpath.exists()) {
+ files.add(CLASSPATH_FILE);
+ }
+ return files;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.project.ProjectEditor#createFiles(Set)
+ *
+ * {@inheritDoc}
+ */
+ public void createFiles(final Set<String> files) {
+ if(files.contains(CLASSPATH_FILE)) {
+ IFile classpath = getProject().getFile(CLASSPATH_FILE);
+ if(!classpath.exists()) {
+ InputStream is = getInputStream("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<?eclipse version=\"3.4\"?>\n" + "<classpath>\n" + "</classpath>\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+
+ try {
+ classpath.create(is, true, null);
+ } catch (CoreException ex) {
+ Activator.log.error(ex);
+ }
+ }
+ }
+ }
+
+ public String[] getSourceFolders() {
+ List<String> sourceFolders = new LinkedList<String>();
+ IClasspathEntry[] entries = null;
+ try {
+ entries = this.javaProject.getRawClasspath();
+ } catch (JavaModelException e) {
+ Activator.log.error(e);
+ }
+
+ for(int i = 0; i < entries.length; i++) {
+ IClasspathEntry entry = entries[i];
+ if(entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
+ sourceFolders.add(entry.getPath().makeRelativeTo(javaProject.getPath()).toString());
+ }
+ }
+
+ return sourceFolders.toArray(new String[sourceFolders.size()]);
+ }
+
+ public String[] getBinFolders() {
+ List<String> binFolders = new LinkedList<String>();
+ try {
+ //General bin folder
+ binFolders.add(javaProject.getOutputLocation().makeRelativeTo(javaProject.getPath()).toString());
+ } catch (JavaModelException ex) {
+ Activator.log.error(ex);
+ }
+ IClasspathEntry[] entries = null;
+ try {
+ entries = this.javaProject.getRawClasspath();
+ } catch (JavaModelException e) {
+ Activator.log.error(e);
+ }
+
+ for(int i = 0; i < entries.length; i++) {
+ IClasspathEntry entry = entries[i];
+ if(entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
+ if(entry.getOutputLocation() != null) {
+ //Bin folder associated to each source folder
+ binFolders.add(entry.getOutputLocation().makeRelativeTo(javaProject.getPath()).toString());
+ }
+ }
+ }
+
+ return binFolders.toArray(new String[binFolders.size()]);
+ }
+}
diff --git a/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/ManifestEditor.java b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/ManifestEditor.java
new file mode 100644
index 00000000000..2c93f7ba872
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/ManifestEditor.java
@@ -0,0 +1,469 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.eclipse.project.editors.file;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringReader;
+import java.util.Set;
+import java.util.jar.Attributes;
+import java.util.jar.Attributes.Name;
+import java.util.jar.Manifest;
+
+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.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.papyrus.eclipse.project.editors.Activator;
+import org.eclipse.papyrus.eclipse.project.editors.interfaces.IManifestEditor;
+import org.eclipse.papyrus.eclipse.project.editors.project.ProjectEditor;
+import org.eclipse.pde.internal.ui.editor.actions.FormatOperation;
+
+public class ManifestEditor extends ProjectEditor implements IManifestEditor {
+
+ /** the manifest file */
+ private IFile manifestFile;
+
+ /** the manifest itself */
+ private Manifest manifest;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param project
+ * @throws IOException
+ * @throws CoreException
+ */
+ public ManifestEditor(final IProject project) throws IOException, CoreException {
+ super(project);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IManifestEditor#addDependency(java.lang.String)
+ *
+ * {@inheritDoc}
+ */
+ public void addDependency(final String dependency) {
+ addDependency(dependency, null);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.project.ProjectEditor#init()
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public void init() {
+ super.init();
+ if((this.manifest != null) && (this.manifestFile != null)) {
+ return;
+ }
+ if(this.manifestFile == null) {
+ this.manifestFile = getManifestFile();
+ }
+ if(this.manifestFile != null) {
+ try {
+ this.manifest = new Manifest(this.manifestFile.getContents());
+ } catch (final IOException e) {
+ Activator.log.error(e);
+ } catch (final CoreException e) {
+ Activator.log.error(e);
+ }
+ }
+
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IManifestEditor#addDependency(java.lang.String, java.lang.String)
+ *
+ * {@inheritDoc}
+ */
+ public void addDependency(final String dependency, final String version) {
+ final Name rqBundle = new Name(REQUIRED_BUNDLE);
+ 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)
+ //Moreover, the Manifest allows newlines anywhere (Including in the
+ //middle of a word) : check if these newlines appear in this map,
+ //or if they have already been parsed. If the manifest value is copied as-is in the map,
+ //then we need to take care of newlines when parsing it
+
+ if(requireBundle == null) {
+ requireBundle = dependency;
+ if(version != null) {
+ requireBundle += ";" + version; //$NON-NLS-1$
+ }
+ } else if(!requireBundle.contains(dependency)) {
+ requireBundle += "," + dependency; //$NON-NLS-1$
+ if(version != null) {
+ requireBundle += ";" + version; //$NON-NLS-1$
+ }
+ }
+ this.manifest.getMainAttributes().put(rqBundle, requireBundle);
+ }
+
+ 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[] 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)) {
+ newRequiredBundles += ",";
+ }
+ }
+ setValue(REQUIRED_BUNDLE, newRequiredBundles);
+
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IManifestEditor#setValue(java.lang.String, java.lang.String)
+ *
+ * {@inheritDoc}
+ */
+ public void setValue(final String key, final String value) {
+ setValue(key, "", value); //$NON-NLS-1$
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IManifestEditor#setValue(java.lang.String, java.lang.String, java.lang.String)
+ *
+ * {@inheritDoc}
+ */
+ public void setValue(final String key, final String name, final String value) {
+ this.manifest.getMainAttributes().putValue(key, value);
+ // this.manifest.getAttributes(key).put(name, value);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IManifestEditor#removeValue(java.lang.String, java.lang.String)
+ *
+ * {@inheritDoc}
+ */
+ public void removeValue(final String key, final String value) {
+
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IManifestEditor#removeValue(java.lang.String)
+ *
+ * {@inheritDoc}
+ */
+ public void removeValue(final String key) {
+ this.manifest.getAttributes(key).remove(key);
+ }
+
+ /**
+ *
+ * @return
+ */
+ private IFile getManifestFile() {
+ final IFile manifest = getProject().getFile("META-INF/MANIFEST.MF"); //$NON-NLS-1$
+ if(manifest.exists()) {
+ return manifest;
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.project.AbstractProjectEditor#exists()
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean exists() {
+ return super.exists() && (getManifestFile() != null) && (getSymbolicBundleName() != null) && (getBundleVersion() != null);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.project.ProjectEditor#save()
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public void save() {
+
+ final ByteArrayOutputStream os = new ByteArrayOutputStream();
+
+ try {
+ this.manifest.write(os);
+
+ final StringReader reader = new StringReader(os.toString("UTF-8")); //$NON-NLS-1$
+ this.manifestFile.setContents(new InputStream() {
+
+ @Override
+ public int read() throws IOException {
+ return reader.read();
+ }
+ }, true, true, null);
+
+ //Use the PDE formatter for ManifestFiles
+ 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) {
+ Activator.log.error(ex);
+ }
+ }
+
+ @Override
+ public Set<String> getMissingFiles() {
+ final Set<String> files = super.getMissingFiles();
+ final IFile classpath = getProject().getFile(MANIFEST_PATH);
+ if(!classpath.exists()) {
+ files.add(MANIFEST_PATH);
+ }
+ return files;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.project.ProjectEditor#createFiles(java.util.Set)
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public void createFiles(final Set<String> files) {
+ if(files.contains(MANIFEST_PATH)) {
+ 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(!this.manifestFile.getParent().exists()) {
+ final IContainer parent = this.manifestFile.getParent();
+ if(parent instanceof Folder) {
+ if(!parent.exists()) {
+ ((Folder)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());
+
+ final int i;
+ // InputStream is = this.manifestFile.getContents();
+ // while((i = is.read()) > 0) {
+
+ // System.out.println(i);
+ // }
+ // this.manifest = new Manifest(this.manifestFile.getContents());
+
+ } catch (final CoreException ex) {
+ Activator.log.error(ex);
+ } catch (final IOException e) {
+ Activator.log.error(e);
+ }
+
+ }
+ }
+
+ if(getSymbolicBundleName() == null) {
+ setSymbolicBundleName(getProject().getName());
+ }
+
+ if(getBundleVersion() == null) {
+ setBundleVersion("0.0.1"); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IManifestEditor#setSymbolicBundleName(java.lang.String)
+ *
+ * {@inheritDoc}
+ */
+ public void setSymbolicBundleName(String newName) {
+ if(newName == null) {
+ newName = "noName"; //$NON-NLS-1$
+ }
+ final Name symbolicName = new Name(BUNDLE_SYMBOLIC_NAME);
+ this.manifest.getMainAttributes().put(symbolicName, newName);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IManifestEditor#getSymbolicBundleName()
+ *
+ * {@inheritDoc}
+ */
+ public String getSymbolicBundleName() {
+ if(this.manifest != null) {
+ final Name symbolicName = new Name(BUNDLE_SYMBOLIC_NAME);
+ final String name = this.manifest.getMainAttributes().getValue(symbolicName);
+ return name;
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IManifestEditor#getBundleVersion()
+ *
+ * {@inheritDoc}
+ */
+ public String getBundleVersion() {
+ if(this.manifest != null) {
+ final Name symbolicName = new Name(BUNDLE_VERSION);
+ final String version = this.manifest.getMainAttributes().getValue(symbolicName);
+ return version;
+ }
+ return null;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IManifestEditor#setBundleVersion(java.lang.String)
+ *
+ * {@inheritDoc}
+ */
+ public void setBundleVersion(final String version) {
+ if(this.manifest != null) {
+ final Name bundleVersion = new Name(BUNDLE_VERSION);
+ if(version == null) {
+ this.manifest.getMainAttributes().remove(bundleVersion);
+ } else {
+ this.manifest.getMainAttributes().put(bundleVersion, version);
+ }
+ }
+ }
+
+ /**
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IManifestEditor#getBundleVendor()
+ *
+ * {@inheritDoc}
+ */
+ public String getBundleVendor() {
+ if(this.manifest != null) {
+ final Name bundleVendor = new Name(BUNDLE_VENDOR);
+ return this.manifest.getMainAttributes().getValue(bundleVendor);
+ }
+ return null;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IManifestEditor#setBundleVendor(java.lang.String)
+ *
+ * {@inheritDoc}
+ */
+ public void setBundleVendor(final String vendor) {
+ if(this.manifest != null) {
+ final Name bundleVendor = new Name(BUNDLE_VENDOR);
+ if(vendor == null) {
+ this.manifest.getMainAttributes().remove(bundleVendor);
+ } else {
+ this.manifest.getMainAttributes().put(bundleVendor, vendor);
+ }
+ }
+ }
+
+ public String getValue(final String key) {
+ if(this.manifest != null) {
+ String value = this.manifest.getMainAttributes().getValue(key);
+ if(value == null) {
+ final Attributes attributes = this.manifest.getAttributes(key);
+ if(attributes != null) {
+ value = attributes.getValue(key);
+ }
+ }
+ return value;
+ }
+ return null;
+ }
+
+ public String getBundleName() {
+ if(this.manifest != null) {
+ final Name bundleName = new Name(BUNDLE_NAME);
+ final String name = this.manifest.getMainAttributes().getValue(bundleName);
+ return name;
+ }
+ return null;
+ }
+
+ public void setBundleName(String newName) {
+ if(newName == null) {
+ newName = "noName"; //$NON-NLS-1$
+ }
+ final Name bundleNameName = new Name(BUNDLE_SYMBOLIC_NAME);
+ this.manifest.getMainAttributes().put(bundleNameName, newName);
+
+ }
+
+ public String getBundleLocalization() {
+ if(this.manifest != null) {
+ final Name bundleLocalization = new Name(BUNDLE_LOCALIZATION);
+ final String name = this.manifest.getMainAttributes().getValue(bundleLocalization);
+ return name;
+ }
+ return null;
+ }
+
+ public void setSingleton(final boolean singleton) {
+ String value = this.manifest.getMainAttributes().getValue("bundle-symbolicName");
+ final String[] directives = value.split(";");
+
+ if(directives.length == 0) {
+ return; //This should not happen if the Manifest is well-formed
+ } else {
+ value = directives[0];
+ boolean isDefined = false;
+ for(int i = 1; i < directives.length; i++) {
+ String directive = directives[i];
+ if(directive.startsWith("singleton:=")) {
+ directive = "singleton:=" + singleton;
+ isDefined = true;
+ }
+ value += ";" + directive;
+ }
+ if(!isDefined) {
+ value += ";singleton:=" + singleton;
+ }
+ }
+
+ this.manifest.getMainAttributes().putValue("bundle-symbolicName", value);
+ }
+}
diff --git a/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IBuildEditor.java b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IBuildEditor.java
new file mode 100644
index 00000000000..4515b3f933b
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IBuildEditor.java
@@ -0,0 +1,98 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.eclipse.project.editors.interfaces;
+
+/**
+ *
+ * Editor for the build.properties
+ *
+ */
+public interface IBuildEditor extends IFileEditor {
+
+ /**
+ * key for the bin
+ *
+ * @Deprecated The build key should be specified for each IBuildEditor instance
+ */
+ @Deprecated
+ public final static String BUILD_KEY = "bin.includes"; //$NON-NLS-1$
+
+ /** key for the source folders */
+ public final static String SOURCE_FOLDER_KEY = "source.."; //$NON-NLS-1$
+
+ /** key for the bin folders */
+ public static final String BIN_KEY = "bin.."; //$NON-NLS-1$
+
+ /** name of the file build.properties */
+ public static final String BUILD_PROPERTIES_FILE = "build.properties"; //$NON-NLS-1$
+
+ /**
+ * The build key for the Eclipse Binary Build
+ */
+ public static final String BINARY_BUILD = "bin.includes";
+
+ /**
+ * The build key for the Eclipse Source Build
+ */
+ public static final String SOURCE_BUILD = "src.includes";
+
+ /** the method to register a new source folder */
+ public void registerSourceFolder(String string);
+
+ /** registers a new bin folder */
+ public void registerBinFolder(String binFolder);
+
+ /** the method to add an element to the build */
+ public void addToBuild(final String path);
+
+ /** removes the given path from the build */
+ public void removeFromBuild(final String path);
+
+ /**
+ * Returns <code>true</code> if the folder is registered as a Source Folder
+ *
+ * @param path
+ * the path of a source folder
+ * @return
+ * <code>true</code> if the folder is registered
+ */
+ public boolean isRegisteredSourceFolder(final String path);
+
+ /**
+ * Returns <code>true</code> if the folder is registered as a Bin Folder
+ *
+ * @param path
+ * the path of a bin folder
+ * @return
+ * <code>true</code> if the folder is registered
+ */
+ public boolean isRegisteredBinFolder(final String binFolder);
+
+ /**
+ * Returns all the registered source folders
+ *
+ * @return
+ * all the registered source folders
+ */
+ public String[] getSourceFolders();
+
+ /**
+ * Returns all the files added to the build
+ *
+ * @return
+ * all the files added to the build
+ */
+ public String[] getElementsInBuild();
+}
diff --git a/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IClasspathEditor.java b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IClasspathEditor.java
new file mode 100644
index 00000000000..0aaaeab84e7
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IClasspathEditor.java
@@ -0,0 +1,55 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.eclipse.project.editors.interfaces;
+
+
+/**
+ *
+ * This interface for the file .classpath
+ *
+ */
+public interface IClasspathEditor extends IFileEditor {
+
+ /** the classpath file */
+ public static final String CLASSPATH_FILE = ".classpath"; //$NON-NLS-1$
+
+ /**
+ * add a source folder to the class path
+ * @param folderPath
+ */
+ public void addSourceFolderToClasspath(final String folderPath);
+
+ /**
+ * Tests if a folder is already registered in the classpath
+ *
+ * @param folderPath
+ * a folder path
+ * @return
+ * <code>true</code> if the folderPath is already registered
+ */
+ public boolean isSourceFolderRegistered(final String folderPath);
+
+ /**
+ *
+ * @return the source folders for this classpath
+ */
+ public String[] getSourceFolders();
+
+ /**
+ *
+ * @return the bin folders for this classpath
+ */
+ public String[] getBinFolders();
+}
diff --git a/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IEMFFacetProjectEditor.java b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IEMFFacetProjectEditor.java
new file mode 100644
index 00000000000..6a8c3a1fb51
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IEMFFacetProjectEditor.java
@@ -0,0 +1,77 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.eclipse.project.editors.interfaces;
+
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.facet.infra.facet.FacetSet;
+
+/**
+ *
+ * This interface is used to edit the EMF-Facet project
+ *
+ */
+public interface IEMFFacetProjectEditor extends IJavaProjectEditor/* , IManifestEditor , IBuildEditor */{
+
+ /** the EMF-Facet nature */
+ public static final String EMF_FACET_NATURE = "org.eclipse.emf.facet.common.ProjectNature"; //$NON-NLS-1$
+
+ /** the name of the extension point for the facet registration */
+ public static final String FACET_REGISTRATION = "org.eclipse.emf.facet.infra.facet.registration"; //$NON-NLS-1$
+
+ /** the name of the extension point for the query registration */
+ public static final String QUERY_REGISTRATION = "org.eclipse.emf.facet.infra.query.registration"; //$NON-NLS-1$
+
+ /** the build command for EMF_FACET project */
+ public static final String EMF_FACET_BUILD_COMMAND = "org.eclipse.emf.facet.common.core.builder";
+
+ public static final String FACET_SET = "facetset"; //$NON-NLS-1$
+
+ public static final String FILE = "file"; //$NON-NLS-1$
+
+ public static final String QUERY_SET = "modelqueryset"; //$NON-NLS-1$
+
+ /**
+ *
+ * @param facetSets
+ * a list of FacetSet to register
+ */
+ public void registerFacetSets(final List<FacetSet> facetSets);
+
+ /**
+ *
+ * @param querySets
+ * a list of QuerySet to register
+ */
+ public void registerQuerySets(final List<EObject> querySets);
+
+ /**
+ *
+ * @param dependency
+ * a dependency to add to the project
+ */
+ public void addDependency(final String dependency);
+
+ /**
+ *
+ * @param dependency
+ * a dependency to add to the project
+ * @param version
+ * the version of the dependency
+ */
+ public void addDependency(final String dependency, final String version);
+
+
+}
diff --git a/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IFeatureProjectEditor.java b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IFeatureProjectEditor.java
new file mode 100644
index 00000000000..186764ae7d5
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IFeatureProjectEditor.java
@@ -0,0 +1,51 @@
+package org.eclipse.papyrus.eclipse.project.editors.interfaces;
+
+import org.w3c.dom.Document;
+
+
+public interface IFeatureProjectEditor { //TODo use interface inheritance
+
+ /** the name of the file plugin.xml */
+ public static final String FRAGMENT_XML_FILE = "feature.xml"; //$NON-NLS-1$
+
+ public static final String LABEL = "label"; //$NON-NLS-1$
+
+ public static final String VERSION = "version"; //$NON-NLS-1$
+
+ public static final String PROVIDER = "provider-name"; //$NON-NLS-1$
+
+ public static final String URL = "url";
+
+ public static final String COPYRIGHT = "copyright";
+
+ public static final String LICENSE = "license";
+
+ /** the method to retrieve the plugin.xml XML Document associated to this project */
+ public Document getDocument();
+
+ public void setLabel(final String label);
+
+ public void setVersion(final String version);
+
+ public void setProviderName(final String providerName);
+
+ public void setCopyright(final String copyrightURL, final String copyRightDesc);
+
+ public void setLicense(final String licenseURL, final String licenseDesc);
+
+ public String getLabel();
+
+ public String getVersion();
+
+ public String getProviderName();
+
+ public String getCopyrightText();
+
+ public String getCopyrightURL();
+
+ public String getLicense();
+
+ public void init();
+
+ public void save() throws Throwable;
+}
diff --git a/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IFileEditor.java b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IFileEditor.java
new file mode 100644
index 00000000000..f83574d10d4
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IFileEditor.java
@@ -0,0 +1,66 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.eclipse.project.editors.interfaces;
+
+import java.util.Set;
+
+import org.eclipse.core.resources.IProject;
+
+/**
+ *
+ * Interface to edit file
+ *
+ */
+public interface IFileEditor {
+
+ /** test if all the required elements exist for the editor */
+ public boolean exists();
+
+
+ /** create the required elements for the editor */
+ public abstract void create();
+
+ /**
+ * a method to initialize the field of the editors
+ * This method should be called by the programmer AFTER the construciton of the element
+ */
+ public abstract void init();
+
+ /**
+ *
+ * @return
+ * the missing files for the project
+ */
+ public Set<String> getMissingFiles();
+
+ /**
+ *
+ * @param files
+ * create the required files
+ */
+ public void createFiles(final Set<String> files);
+
+
+ //TODO : Remove that "Throwable" exception...
+ /** save the modification on the editor */
+ public void save();
+
+ /**
+ *
+ * @return
+ * the eclipse project
+ */
+ public IProject getProject();
+
+}
diff --git a/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IJavaProjectEditor.java b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IJavaProjectEditor.java
new file mode 100644
index 00000000000..348e51f8d9d
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IJavaProjectEditor.java
@@ -0,0 +1,37 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.eclipse.project.editors.interfaces;
+
+/**
+ *
+ * Editor for the java project
+ *
+ */
+public interface IJavaProjectEditor extends IBuildEditor {
+
+ /** The java nature */
+ public static final String JAVA_NATURE = "org.eclipse.jdt.core.javanature"; //$NON-NLS-1$
+
+ /** the build command for the java project */
+ public static final String JAVA_BUILD_COMMAND = "org.eclipse.jdt.core.javabuilder"; //$NON-NLS-1$
+ /**
+ * Add a new java source folder in the .classpath and in the build.properties
+ *
+ * @param path
+ * the path of the java source folder
+ */
+ public void addJavaSourceFolder(final String path);
+
+
+}
diff --git a/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IManifestEditor.java b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IManifestEditor.java
new file mode 100644
index 00000000000..e8677841b73
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IManifestEditor.java
@@ -0,0 +1,190 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.eclipse.project.editors.interfaces;
+
+
+
+/**
+ *
+ * Editor for the Manifest
+ *
+ */
+public interface IManifestEditor extends IProjectEditor, IFileEditor {
+
+ /** the path for the manifest file */
+ public static final String MANIFEST_PATH = "META-INF/MANIFEST.MF"; //$NON-NLS-1$
+
+ /** the path for the META-INF folder */
+ public static final String META_INF_PATH = "META-INF/"; //$NON-NLS-1$
+
+ /** the key for the bundle symbolic name */
+ public static final String BUNDLE_SYMBOLIC_NAME = "Bundle-SymbolicName"; //$NON-NLS-1$
+
+ /** the key for the bundle name */
+ public static final String BUNDLE_NAME = "Bundle-Name";//$NON-NLS-1$
+
+ /** the key for the required bundle */
+ 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$
+
+ /** the key for the bundle vendor */
+ public static final String BUNDLE_VENDOR = "Bundle-Vendor"; //$NON-NLS-1$
+
+ /** the build command for the manifest */
+ public static final String MANIFEST_BUILD_COMMAND = "org.eclipse.pde.ManifestBuilder"; //$NON-NLS-1$
+
+ /** the key for the bundle localization */
+ public static final String BUNDLE_LOCALIZATION = "Bundle-Localization"; //$NON-NLS-1$
+
+ /**
+ *
+ * @param dependency
+ * the dependency to add
+ */
+ public void addDependency(final String dependency);
+
+ /**
+ *
+ * @param dependency
+ * the dependency to add
+ * @param version
+ * the version of the dependency
+ */
+ public void addDependency(final String dependency, final String version);
+
+
+ /**
+ *
+ * @param key
+ * the key
+ * @param value
+ * the new value for the key
+ */
+ public void setValue(final String key, final String value);
+
+ public String getValue(final String key);
+
+ /**
+ *
+ * @param key
+ * the key
+ * @param name
+ * the name
+ * @param value
+ * the new value for the key
+ */
+ public void setValue(final String key, final String name, final String value);
+
+ /**
+ *
+ * @param key
+ * the key
+ * @param value
+ * the value to remove for this key
+ */
+ public void removeValue(final String key, final String value);
+
+ /**
+ *
+ * @param key
+ * a key to remove from the manifest
+ *
+ */
+ public void removeValue(final String key);
+
+ /**
+ *
+ * @param name
+ * the symbolic name for the bundle
+ */
+ public void setSymbolicBundleName(final String name);
+
+
+ /**
+ *
+ * @return
+ * the bundle name for the project
+ */
+ public String getSymbolicBundleName();
+
+ /**
+ *
+ * @return
+ * the symbolic bundle name for the project
+ */
+ public String getBundleName();
+
+ /**
+ *
+ * @param name
+ * the bundle name for the bundle
+ */
+ public void setBundleName(final String name);
+
+ /**
+ *
+ * @return
+ * the version of the bundle
+ */
+ public String getBundleVersion();
+
+ /**
+ * Set the version of the bundle
+ */
+ public void setBundleVersion(final String version);
+
+ /**
+ * Gets this plug-in's provider
+ *
+ * @return
+ * this plug-in's provider
+ */
+ public String getBundleVendor();
+
+ /**
+ * Sets this plug-in's provider
+ *
+ * @param vendor
+ * this plug-in's provider
+ */
+ public void setBundleVendor(final String vendor);
+
+ /**
+ * Get the bundle localization
+ *
+ * @return
+ * the bundle localization
+ */
+ public String getBundleLocalization();
+
+ /**
+ * Sets the Manifest's singleton directive
+ *
+ * @param singleton
+ * Whether this plug-in should be a singleton
+ */
+ public void setSingleton(boolean singleton);
+
+ /**
+ *
+ * @param dependencyPattern
+ * the pattern for the dependency to update
+ * @param newVersion
+ * the version for the dependency
+ */
+ public void setDependenciesVersion(final String dependencyPattern, final String newVersion);
+}
diff --git a/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IPluginProjectEditor.java b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IPluginProjectEditor.java
new file mode 100644
index 00000000000..2be90cf2c13
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IPluginProjectEditor.java
@@ -0,0 +1,58 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.eclipse.project.editors.interfaces;
+
+import java.util.List;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ *
+ * Editor for the file plugin.xml
+ *
+ */
+public interface IPluginProjectEditor extends IProjectEditor, IFileEditor {
+
+ /** the node extension */
+ public static final String EXTENSION = "extension"; //$NON-NLS-1$
+
+ /** the attribute point */
+ public static final String POINT = "point"; //$NON-NLS-1$
+
+ /** the name of the file plugin.xml */
+ public static final String PLUGIN_XML_FILE = "plugin.xml"; //$NON-NLS-1$
+
+ /** the plugin nature */
+ public static final String PLUGIN_NATURE = "org.eclipse.pde.PluginNature"; //$NON-NLS-1$
+
+ /** the plugin build command */
+ public static final String PLUGIN_BUILD_COMMAND = "org.eclipse.pde.SchemaBuilder"; //$NON-NLS-1$
+
+ /** the method to add an extension to the plugin */
+ public Element addExtension(final String extensionPoint);
+
+ /** the method to get all the extensions of the type extensionPoint */
+ public List<Node> getExtensions(final String extensionPoint);
+
+ /** the method to set an attribute to an element */
+ public void setAttribute(final Element element, final String attributeName, final String attributeValue);
+
+ /** the method to add a child to an element */
+ public Element addChild(final Element element, final String childName);
+
+ /** the method to retrieve the plugin.xml XML Document associated to this project */
+ public Document getDocument();
+}
diff --git a/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IProjectEditor.java b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IProjectEditor.java
new file mode 100644
index 00000000000..5b11cec9947
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IProjectEditor.java
@@ -0,0 +1,93 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.eclipse.project.editors.interfaces;
+
+import java.net.URL;
+import java.util.Set;
+
+/**
+ *
+ * This interface defines the methods for the ProjectEditor
+ *
+ */
+public interface IProjectEditor extends IFileEditor {
+
+ /** the node buildSpec */
+ public static final String BUILD_SPEC = "buildSpec"; //$NON-NLS-1$
+
+ /** the node comment */
+ public static final String COMMENT = "comment"; //$NON-NLS-1$
+
+ /** the node name */
+ public static final String NAME = "name"; //$NON-NLS-1$
+
+ /** the node nature */
+ public static final String NATURE = "nature"; //$NON-NLS-1$
+
+ /** the node project description */
+ public static final String PROJECT_DESCRIPTION = "projectDescription"; //$NON-NLS-1$
+
+ /** the name of the project file */
+ public static final String PROJECT_FILE = ".project"; //$NON-NLS-1$
+
+
+
+ /**
+ *
+ * @return
+ * the missing nature for the project
+ */
+ public Set<String> getMissingNature();
+
+ /**
+ *
+ * @param nature
+ * a nature
+ * @return
+ * <code>true</code> if the project has this nature
+ */
+ public boolean hasNature(final String nature);
+
+ /**
+ *
+ * @return
+ * the missing build command
+ */
+ public Set<String> getMissingBuildCommand();
+
+ /**
+ *
+ * @param commands
+ * the command to add
+ */
+ public void addBuildCommands(Set<String> commands);
+
+ /**
+ *
+ * @param command
+ * a build command
+ * @return
+ * <code>true</code> if the project has the build command
+ */
+ public boolean hasBuildCommand(String command);
+
+ /**
+ *
+ * @param url
+ * the url of the file to copy
+ * @param fileDestinationPath
+ * the destination path for the added file
+ */
+ public void addFile(final URL url, final String fileDestinationPath, final boolean eraseExistingFile);
+}
diff --git a/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/AbstractProjectEditor.java b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/AbstractProjectEditor.java
new file mode 100644
index 00000000000..47941284b2d
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/AbstractProjectEditor.java
@@ -0,0 +1,195 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.eclipse.project.editors.project;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.internal.events.BuildCommand;
+import org.eclipse.core.resources.ICommand;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.papyrus.eclipse.project.editors.Activator;
+import org.eclipse.papyrus.eclipse.project.editors.file.AbstractFileEditor;
+import org.eclipse.papyrus.eclipse.project.editors.interfaces.IProjectEditor;
+
+/**
+ *
+ * This class provides useful method for project editor
+ *
+ */
+public abstract class AbstractProjectEditor extends AbstractFileEditor implements IProjectEditor {
+
+
+ /** the header for XML files */
+ public static final String XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; //$NON-NLS-1$
+
+ /**
+ * the project description
+ */
+ private final IProjectDescription description;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param project
+ * the eclipse project
+ * @throws CoreException
+ */
+ public AbstractProjectEditor(final IProject project) throws CoreException {
+ super(project);
+ this.description = getProject().getDescription();
+ }
+
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.project.AbstractProjectEditor.plugin.AbstractEditor#exists()
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean exists() {
+ return super.exists() && getMissingNature().size() == 0 && getMissingBuildCommand().size() == 0;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.file.AbstractFileEditor#create()
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public void create() {
+ createFiles(getMissingFiles());
+ addNatures(getMissingNature());
+ addBuildCommands(getMissingBuildCommand());
+ init();
+ }
+
+ /**
+ *
+ * @param nature
+ * a nature
+ * @return
+ * <code>true</code> if the project has the wanted nature
+ */
+ public boolean hasNature(final String nature) {
+ List<String> natures = new LinkedList<String>(Arrays.asList(this.description.getNatureIds()));
+ return natures.contains(nature);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IProjectEditor#getMissingNature()
+ *
+ * {@inheritDoc}
+ */
+ public Set<String> getMissingNature() {
+ return new HashSet<String>();
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IProjectEditor#addNatures(java.util.List)
+ *
+ * {@inheritDoc}
+ */
+ public void addNatures(final Set<String> natures) {
+ List<String> existingNatures = new LinkedList<String>(Arrays.asList(this.description.getNatureIds()));
+ Iterator<String> iter = natures.iterator();
+ while(iter.hasNext()) {
+ String nature = iter.next();
+ if(!existingNatures.contains(nature)) {
+ existingNatures.add(nature);
+ }
+ }
+ this.description.setNatureIds(existingNatures.toArray(new String[existingNatures.size()]));
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.project.AbstractProjectEditor#hasBuildCommand(java.lang.String)
+ *
+ * {@inheritDoc}
+ */
+ public boolean hasBuildCommand(final String command) {
+ ICommand[] buildSpec = this.description.getBuildSpec();
+ for(int i = 0; i < buildSpec.length; i++) {
+ if(buildSpec[i].getBuilderName().equals(command)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.project.AbstractProjectEditor#addBuildCommands(java.util.Set)
+ *
+ * {@inheritDoc}
+ */
+ public void addBuildCommands(final Set<String> commands) {
+ ICommand[] buildSpec = this.description.getBuildSpec();
+
+ List<ICommand> buildSpecList = new ArrayList<ICommand>();
+ buildSpecList.addAll(Arrays.asList(buildSpec));
+
+ Iterator<String> iter = commands.iterator();
+ while(iter.hasNext()) {
+ String name = iter.next();
+ if(!hasBuildCommand(name)) {
+ ICommand cmd = new BuildCommand();
+ cmd.setBuilderName(name);
+ buildSpecList.add(cmd);
+ }
+ }
+ this.description.setBuildSpec(buildSpecList.toArray(new ICommand[buildSpecList.size()]));
+ }
+
+ /**
+ *
+ * @throws Throwable
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IProjectEditor#save()
+ *
+ * {@inheritDoc}
+ */
+ public void save() {
+ if(this.description != null) {
+ try {
+ getProject().setDescription(this.description, null);
+ } catch (CoreException e) {
+ Activator.log.error(e);
+ }
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IProjectEditor#getMissingBuildCommand()
+ *
+ * {@inheritDoc}
+ */
+ public Set<String> getMissingBuildCommand() {
+ return new HashSet<String>();
+ }
+
+}
diff --git a/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/EMFFacetProjectEditor.java b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/EMFFacetProjectEditor.java
new file mode 100644
index 00000000000..91e42ce01d3
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/EMFFacetProjectEditor.java
@@ -0,0 +1,264 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.eclipse.project.editors.project;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.facet.infra.facet.FacetSet;
+import org.eclipse.papyrus.eclipse.project.editors.file.ManifestEditor;
+import org.eclipse.papyrus.eclipse.project.editors.interfaces.IEMFFacetProjectEditor;
+import org.eclipse.papyrus.eclipse.project.editors.interfaces.IManifestEditor;
+import org.eclipse.papyrus.eclipse.project.editors.interfaces.IPluginProjectEditor;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
+
+/**
+ *
+ * Editor for the EMF-Facet project
+ *
+ */
+public class EMFFacetProjectEditor extends JavaProjectEditor implements IEMFFacetProjectEditor {
+
+ /**
+ * the plugin editor
+ */
+ private final IPluginProjectEditor pluginEditor;
+
+ /**
+ * the manifest editor
+ */
+ private final IManifestEditor manifestEditor;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param project
+ * @throws CoreException
+ * @throws IOException
+ * @throws SAXException
+ * @throws ParserConfigurationException
+ */
+ public EMFFacetProjectEditor(final IProject project) throws IOException, CoreException, ParserConfigurationException, SAXException {
+ super(project);
+ this.pluginEditor = new PluginProjectEditor(project);
+ this.manifestEditor = new ManifestEditor(project);
+ }
+
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.project.JavaProjectEditor#getMissingNature()
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<String> getMissingNature() {
+ Set<String> natures = super.getMissingNature();
+ natures.addAll(this.pluginEditor.getMissingNature());
+ if(!hasNature(EMF_FACET_NATURE)) {
+ natures.add(EMF_FACET_NATURE);
+ }
+ return natures;
+ }
+
+ @Override
+ public void init() {
+ super.init();
+ this.manifestEditor.init();
+ this.pluginEditor.init();
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.project.JavaProjectEditor#getMissingFiles()
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<String> getMissingFiles() {
+ Set<String> files = super.getMissingFiles();
+ files.addAll(this.pluginEditor.getMissingFiles());
+ files.addAll(this.manifestEditor.getMissingFiles());
+ return files;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IEMFFacetProjectEditor#registerFacetSets(java.util.List)
+ *
+ * {@inheritDoc}
+ */
+ public void registerFacetSets(final List<FacetSet> facetSets) {
+ for(int i = 0; i < facetSets.size(); i++) {
+ FacetSet set = facetSets.get(i);
+ URI uri = set.eResource().getURI();
+ IPath projectLocation = getProject().getLocation();
+ String filepath = uri.devicePath();
+ String projectPath = projectLocation.toOSString();
+ filepath = filepath.substring(projectPath.length());
+ if(filepath.charAt(0) == '/') {
+ filepath = filepath.substring(1);
+ }
+ boolean registered = false;
+ //we test if the file is already registered
+ List<Node> extensions = this.pluginEditor.getExtensions(FACET_REGISTRATION);
+ if(extensions != null) {
+ Iterator<Node> iter = extensions.iterator();
+ while(iter.hasNext()) {
+ Node current = iter.next();
+ Node child = current.getFirstChild();
+ if(child != null) {
+ NamedNodeMap attributes = child.getAttributes();
+ Node node = attributes.getNamedItem(FILE);
+ if(node != null) {
+ String path = node.getNodeValue();
+ registered = filepath.equals(path);
+
+ }
+ }
+ }
+ }
+ if(!registered) {
+ Element extension = this.pluginEditor.addExtension(FACET_REGISTRATION);
+ Element facetSet = this.pluginEditor.addChild(extension, FACET_SET);
+ this.pluginEditor.setAttribute(facetSet, FILE, filepath);
+ }
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IEMFFacetProjectEditor#registerQuerySets(java.util.List)
+ *
+ * {@inheritDoc}
+ */
+ public void registerQuerySets(final List<EObject> querySets) {
+
+ for(int i = 0; i < querySets.size(); i++) {
+
+ URI uri = querySets.get(i).eResource().getURI();
+ IPath projectLocation = getProject().getLocation();
+ String filepath = uri.devicePath();
+ String projectPath = projectLocation.toOSString();
+ filepath = filepath.substring(projectPath.length());
+ if(filepath.charAt(0) == '/') {
+ filepath = filepath.substring(1);
+ }
+ boolean registered = false;
+ //we test if the file is already registered
+ List<Node> extensions = this.pluginEditor.getExtensions(QUERY_REGISTRATION);
+ if(extensions != null) {
+ Iterator<Node> iter = extensions.iterator();
+ while(iter.hasNext() && registered == false) {
+ Node current = iter.next();
+ Node child = current.getFirstChild();
+ if(child != null) {
+ NamedNodeMap attributes = child.getAttributes();
+ Node node = attributes.getNamedItem(FILE);
+ if(node != null) {
+ String path = node.getNodeValue();
+ registered = filepath.equals(path);
+
+ }
+ }
+ }
+ }
+ if(!registered) {
+ Element extension = this.pluginEditor.addExtension(QUERY_REGISTRATION);
+ Element querySet = this.pluginEditor.addChild(extension, QUERY_SET);
+ this.pluginEditor.setAttribute(querySet, FILE, filepath);
+ }
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IEMFFacetProjectEditor#addDependency(java.lang.String)
+ *
+ * {@inheritDoc}
+ */
+ public void addDependency(final String dependency) {
+ this.manifestEditor.addDependency(dependency);
+
+ }
+
+ @Override
+ public void save() {
+ this.pluginEditor.save();
+ this.manifestEditor.save();
+ super.save();
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IEMFFacetProjectEditor#addDependency(java.lang.String, java.lang.String)
+ *
+ * {@inheritDoc}
+ */
+ public void addDependency(final String dependency, final String version) {
+ this.manifestEditor.addDependency(dependency, version);
+ }
+
+ @Override
+ public void create() {
+ super.create();
+ this.pluginEditor.create();
+ this.manifestEditor.create();
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.project.JavaProjectEditor#createFiles(java.util.Set)
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public void createFiles(final Set<String> files) {
+ this.pluginEditor.createFiles(files);
+ this.manifestEditor.createFiles(files);
+ super.createFiles(files);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.project.JavaProjectEditor#getMissingBuildCommand()
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<String> getMissingBuildCommand() {
+ Set<String> buildCommand = super.getMissingBuildCommand();
+ buildCommand.addAll(this.pluginEditor.getMissingBuildCommand());
+ if(!hasBuildCommand(IManifestEditor.MANIFEST_BUILD_COMMAND)) {
+ buildCommand.add(IManifestEditor.MANIFEST_BUILD_COMMAND);
+ }
+ if(!hasBuildCommand(EMF_FACET_BUILD_COMMAND)) {
+ buildCommand.add(EMF_FACET_BUILD_COMMAND);
+ }
+ return buildCommand;
+ }
+}
diff --git a/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/FeatureProjectEditor.java b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/FeatureProjectEditor.java
new file mode 100644
index 00000000000..8b341fbc39d
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/FeatureProjectEditor.java
@@ -0,0 +1,346 @@
+package org.eclipse.papyrus.eclipse.project.editors.project;
+
+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;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.papyrus.eclipse.project.editors.Activator;
+import org.eclipse.papyrus.eclipse.project.editors.interfaces.IFeatureProjectEditor;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+
+public class FeatureProjectEditor extends ProjectEditor implements IFeatureProjectEditor {
+
+ //TODO pour l'externalization : utiliser l'Úditeur de Properties! dans java Utils
+
+ private Document fragmentXML;;
+
+ private IFile fragmentFile;;
+
+ private Element fragmentRoot;;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param project
+ * the eclipse project
+ * @throws ParserConfigurationException
+ * @throws SAXException
+ * @throws IOException
+ * @throws CoreException
+ */
+ public FeatureProjectEditor(final IProject project) throws ParserConfigurationException, SAXException, IOException, CoreException {
+ 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()) {
+ 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 (final ParserConfigurationException e) {
+ Activator.log.error(e);
+ } catch (final SAXException e) {
+ Activator.log.error(e);
+ } catch (final IOException e) {
+ Activator.log.error(e);
+ }
+ }
+ }
+
+ /**
+ * 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();
+ }
+
+ /**
+ *
+ * @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();
+ }
+
+
+
+
+ /**
+ *
+ * @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
+ */
+ private IFile getPlugin() {
+ final IFile plugin = getProject().getFile(FRAGMENT_XML_FILE);
+ if(plugin.exists()) {
+ return plugin;
+ }
+ return null;
+ }
+
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.project.ProjectEditor#save()
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public void save() {
+ if(exists()) {
+ try {
+ final TransformerFactory transformerFactory = TransformerFactory.newInstance();
+ 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);
+ transformer.transform(source, result);
+
+ final InputStream inputStream = getInputStream(result.getWriter().toString());
+ this.fragmentFile.setContents(inputStream, true, true, null);
+ } catch (final TransformerException ex) {
+ Activator.log.error(ex);
+ } catch (final CoreException ex) {
+ Activator.log.error(ex);
+ }
+ }
+ super.save();
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.project.ProjectEditor#getMissingNature()
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<String> getMissingNature() {
+ return Collections.EMPTY_SET;
+ //TODO
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.project.ProjectEditor#getMissingFiles()
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<String> getMissingFiles() {
+ return Collections.EMPTY_SET;
+ //TODO
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.file.AbstractFileEditor#getMissingBuildCommand()
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<String> getMissingBuildCommand() {
+ return Collections.emptySet();
+ //TODO
+ }
+
+ /**
+ * @return The XML Document associated to this plugin.xml file
+ * @see PluginProjectEditor#init()
+ * @see PluginProjectEditor#create()
+ */
+ public Document getDocument() {
+ return this.fragmentXML;
+ }
+
+ public void setLabel(final String label) {
+ this.fragmentRoot.setAttribute(LABEL, label);
+
+ }
+
+ public void setVersion(final String version) {
+ this.fragmentRoot.setAttribute(VERSION, version);
+
+ }
+
+ public void setProviderName(final String providerName) {
+ this.fragmentRoot.setAttribute(PROVIDER, providerName);
+
+ }
+
+ public static final String DESCRIPTION = "description";
+
+ public static final String URL = "url";
+
+ public void setDescription(final String copyrightURL, final String copyrightDesc) {
+ 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");
+ }
+ }
+ }
+
+ public void setLicense(final String licenseURL, final String licenseDesc) {
+ setURLNode(LICENSE, licenseURL, licenseDesc);
+ }
+
+ 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);
+ if(url != null) {
+ extension.setAttribute(URL, url);
+ }
+ extension.setTextContent(description);
+ this.fragmentRoot.appendChild(extension);
+ } else {
+ if(url != null) {
+ extension.setAttribute(URL, url);
+ }
+ extension.setTextContent(description);
+ }
+ }
+ }
+
+ public String getLabel() {
+ return this.fragmentRoot.getAttribute(LABEL);
+ }
+
+ public String getVersion() {
+ return this.fragmentRoot.getAttribute(VERSION);
+ }
+
+ public String getProviderName() {
+ return this.fragmentRoot.getAttribute(PROVIDER);
+ }
+
+ public void setCopyright(final String copyrightURL, final String copyrightDesc) {
+ setURLNode(COPYRIGHT, copyrightURL, copyrightDesc);
+ }
+
+ 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;
+ }
+
+ public String getLicense() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /**
+ *
+ * @param nodeName
+ * the node name
+ * @return
+ */
+ public Element getNode(final String nodeName) {
+ if(exists()) {
+ final NodeList nodes = this.fragmentRoot.getChildNodes();
+ for(int i = 0; i < nodes.getLength(); i++) {
+ final Node item = nodes.item(i);
+ if(item instanceof NodeList) {
+ final String name = item.getNodeName();
+ if(name.equals(nodeName)) {
+ if(item instanceof Element) {
+ return (Element)item;
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+}
diff --git a/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/JavaProjectEditor.java b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/JavaProjectEditor.java
new file mode 100644
index 00000000000..b6244e62603
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/JavaProjectEditor.java
@@ -0,0 +1,251 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.eclipse.project.editors.project;
+
+import java.util.Set;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.papyrus.eclipse.project.editors.Activator;
+import org.eclipse.papyrus.eclipse.project.editors.file.BuildEditor;
+import org.eclipse.papyrus.eclipse.project.editors.file.ClasspathEditor;
+import org.eclipse.papyrus.eclipse.project.editors.interfaces.IBuildEditor;
+import org.eclipse.papyrus.eclipse.project.editors.interfaces.IClasspathEditor;
+import org.eclipse.papyrus.eclipse.project.editors.interfaces.IJavaProjectEditor;
+
+/**
+ *
+ * This editor allows to manage a JavaProject
+ *
+ */
+public class JavaProjectEditor extends ProjectEditor implements IJavaProjectEditor {
+
+
+ /** the java project */
+ private final IJavaProject javaProject;
+
+ /** the classpath editor */
+ private final IClasspathEditor classpathEditor;
+
+ /** the build editor */
+ private final IBuildEditor buildEditor;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param project
+ * the eclipse project
+ * @throws CoreException
+ */
+ public JavaProjectEditor(final IProject project) throws CoreException {
+ super(project);
+ this.javaProject = JavaCore.create(project);
+ this.buildEditor = new BuildEditor(project);
+ this.classpathEditor = new ClasspathEditor(this.javaProject);
+ }
+
+ /**
+ *
+ * @return
+ * <code>true</code> if the project is a java project :
+ *
+ */
+ @Override
+ public boolean exists() {
+ return super.exists() && this.javaProject.exists();
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.project.ProjectEditor#getMissingFiles()
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<String> getMissingFiles() {
+ Set<String> files = super.getMissingFiles();
+ files.addAll(this.classpathEditor.getMissingFiles());
+ files.addAll(this.buildEditor.getMissingFiles());
+ return files;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.project.AbstractProjectEditor#getMissingNature()
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<String> getMissingNature() {
+ Set<String> natures = super.getMissingNature();
+ if(!hasNature(JAVA_NATURE)) {
+ natures.add(JAVA_NATURE);
+ }
+ return natures;
+ }
+
+ @Override
+ public void init() {
+ // TODO Auto-generated method stub
+ super.init();
+ this.classpathEditor.init();
+ this.buildEditor.init();
+ }
+
+ @Override
+ public void createFiles(final Set<String> files) {
+ super.createFiles(files);
+ this.classpathEditor.createFiles(files);
+ this.buildEditor.createFiles(files);
+ }
+
+
+
+ /**
+ * save the modification
+ *
+ * @throws Throwable
+ */
+ @Override
+ public void save() {
+ super.save();
+ try {
+ this.javaProject.save(new NullProgressMonitor(), true);
+ } catch (JavaModelException ex) {
+ Activator.log.error(ex);
+ }
+ this.classpathEditor.save();
+ this.buildEditor.save();
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IJavaProjectEditor#addJavaSourceFolder(java.lang.String)
+ *
+ * {@inheritDoc}
+ */
+ public void addJavaSourceFolder(final String path) {
+ if(exists()) {
+ //we add this source folder to the class path
+ // String classPath = "/" + this.project.getName()+"/" + path;
+ String classPath = path;
+ this.classpathEditor.addSourceFolderToClasspath(classPath);
+
+ //we add this source folder in the build file
+ this.buildEditor.registerSourceFolder(path + "/"); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IBuildEditor#registerSourceFolder(java.lang.String)
+ *
+ * {@inheritDoc}
+ */
+ public void registerSourceFolder(final String string) {
+ this.buildEditor.registerSourceFolder(string);
+
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IBuildEditor#addToBuild(java.lang.String)
+ *
+ * {@inheritDoc}
+ */
+ public void addToBuild(final String path) {
+ this.buildEditor.addToBuild(path);
+
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IBuildEditor#isRegistred(java.lang.String)
+ *
+ * {@inheritDoc}
+ */
+ public boolean isRegisteredSourceFolder(final String path) {
+ return this.buildEditor.isRegisteredSourceFolder(path);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IBuildEditor#getSourceFolders()
+ *
+ * {@inheritDoc}
+ */
+ public String[] getSourceFolders() {
+ return this.buildEditor.getSourceFolders();
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.file.AbstractFileEditor#getMissingBuildCommand()
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<String> getMissingBuildCommand() {
+ Set<String> buildCommand = super.getMissingBuildCommand();
+ if(!hasBuildCommand(IJavaProjectEditor.JAVA_BUILD_COMMAND)) {
+ buildCommand.add(IJavaProjectEditor.JAVA_BUILD_COMMAND);
+ }
+ return buildCommand;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IBuildEditor#removeFromBuild(java.lang.String)
+ *
+ * {@inheritDoc}
+ */
+ public void removeFromBuild(String path) {
+ buildEditor.removeFromBuild(path);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IBuildEditor#getElementsInBuild()
+ *
+ * {@inheritDoc}
+ */
+ public String[] getElementsInBuild() {
+ return buildEditor.getElementsInBuild();
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IBuildEditor#registerBinFolder(java.lang.String)
+ *
+ * {@inheritDoc}
+ */
+ public void registerBinFolder(String binFolder) {
+ buildEditor.registerBinFolder(binFolder);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IBuildEditor#isRegisteredBinFolder(java.lang.String)
+ *
+ * {@inheritDoc}
+ */
+ public boolean isRegisteredBinFolder(String binFolder) {
+ return buildEditor.isRegisteredBinFolder(binFolder);
+ }
+}
diff --git a/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/PluginProjectEditor.java b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/PluginProjectEditor.java
new file mode 100644
index 00000000000..ba840ad71ed
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/PluginProjectEditor.java
@@ -0,0 +1,305 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ * Vincent Lorenzot (CEA-LIST) vincent.lorenzo@cea.fr
+ *****************************************************************************/
+package org.eclipse.papyrus.eclipse.project.editors.project;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.papyrus.eclipse.project.editors.Activator;
+import org.eclipse.papyrus.eclipse.project.editors.interfaces.IPluginProjectEditor;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+/**
+ *
+ * This editor allows to edit the plugin file
+ *
+ */
+public class PluginProjectEditor extends ProjectEditor implements IPluginProjectEditor {
+
+ private Document pluginXML;
+
+ private IFile pluginFile;
+
+ private Element pluginRoot;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param project
+ * the eclipse project
+ * @throws ParserConfigurationException
+ * @throws SAXException
+ * @throws IOException
+ * @throws CoreException
+ */
+ public PluginProjectEditor(final IProject project) throws ParserConfigurationException, SAXException, IOException, CoreException {
+ super(project);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.project.ProjectEditor#init()
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public void init() {
+ this.pluginFile = getPlugin();
+ if(this.pluginFile != null && this.pluginFile.exists()) {
+ DocumentBuilderFactory documentFactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder documentBuilder;
+ try {
+ documentBuilder = documentFactory.newDocumentBuilder();
+ this.pluginXML = documentBuilder.parse(this.pluginFile.getLocation().toOSString());
+ this.pluginRoot = this.pluginXML.getDocumentElement();
+ } catch (ParserConfigurationException e) {
+ Activator.log.error(e);
+ } catch (SAXException e) {
+ Activator.log.error(e);
+ } catch (IOException e) {
+ Activator.log.error(e);
+ }
+ }
+ }
+
+ /**
+ * 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) {
+ if(files.contains(PLUGIN_XML_FILE)) {
+ IFile plugin = getProject().getFile(PLUGIN_XML_FILE);
+ if(!plugin.exists()) {
+ InputStream is = getInputStream("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<?eclipse version=\"3.4\"?>\n" + "<plugin>\n" + "</plugin>\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ try {
+ plugin.create(is, true, null);
+ } catch (CoreException e) {
+ Activator.log.error(e);
+ }
+ }
+ }
+ super.createFiles(files);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.project.AbstractProjectEditor.plugin.AbstractEditor#exists()
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean exists() {
+ IFile plugin = getProject().getFile(PLUGIN_XML_FILE);
+ return plugin.exists() && super.exists();
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IPluginProjectEditor#addExtension(java.lang.String)
+ *
+ * {@inheritDoc}
+ */
+ public Element addExtension(final String extensionPoint) {
+ if(exists()) {
+ Element extension = this.pluginXML.createElement(EXTENSION);
+ extension.setAttribute(POINT, extensionPoint);
+ this.pluginRoot.appendChild(extension);
+ return extension;
+ }
+ return null;
+ }
+
+ /**
+ * Returns the list of the registered extension with this extension point
+ *
+ * @param extensionPoint
+ * the name of an extension point
+ * @return
+ * the list of the registered extension with this extension point
+ */
+ public List<Node> getExtensions(final String extensionPoint) {
+ if(exists()) {
+ NodeList nodes = this.pluginRoot.getChildNodes();
+ List<Node> extensions = new ArrayList<Node>();
+ for(int i = 0; i < nodes.getLength(); i++) {
+ Node item = nodes.item(i);
+ if(item instanceof NodeList) {
+ String name = item.getNodeName();
+ if(name.equals(EXTENSION)) {
+ NamedNodeMap attributes = item.getAttributes();
+ Node point = attributes.getNamedItem(POINT);
+ if(extensionPoint.equals(point.getNodeValue())) {
+ if(item instanceof Node) {
+ extensions.add(item);
+ }
+ }
+ }
+ }
+ }
+ return extensions;
+ }
+ return null;
+ }
+
+
+ /**
+ *
+ * @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);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IPluginProjectEditor#addChild(org.w3c.dom.Element, java.lang.String)
+ *
+ * {@inheritDoc}
+ */
+ public Element addChild(final Element element, final String childName) {
+ Element child = this.pluginXML.createElement(childName);
+ element.appendChild(child);
+ return child;
+ }
+
+ /**
+ *
+ * @return
+ * the plugin file if it exists
+ */
+ private IFile getPlugin() {
+ IFile plugin = getProject().getFile(PLUGIN_XML_FILE);
+ if(plugin.exists()) {
+ return plugin;
+ }
+ return null;
+ }
+
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.project.ProjectEditor#save()
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public void save() {
+ if(exists()) {
+ try {
+ TransformerFactory transformerFactory = TransformerFactory.newInstance();
+ Transformer transformer = transformerFactory.newTransformer();
+ transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); //$NON-NLS-1$
+ StreamResult result = new StreamResult(new StringWriter());
+ DOMSource source = new DOMSource(this.pluginXML);
+ transformer.transform(source, result);
+
+ String resultAsString = result.getWriter().toString();
+ if(!resultAsString.endsWith("\n")) {
+ resultAsString += "\n";
+ }
+ InputStream inputStream = getInputStream(resultAsString);
+ this.pluginFile.setContents(inputStream, true, true, null);
+ } catch (TransformerException ex) {
+ Activator.log.error(ex);
+ } catch (CoreException ex) {
+ Activator.log.error(ex);
+ }
+ }
+ super.save();
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.project.ProjectEditor#getMissingNature()
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<String> getMissingNature() {
+ Set<String> natures = super.getMissingNature();
+ if(!hasNature(PLUGIN_NATURE)) {
+ natures.add(PLUGIN_NATURE);
+ }
+ return natures;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.project.ProjectEditor#getMissingFiles()
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<String> getMissingFiles() {
+ Set<String> files = super.getMissingFiles();
+ IFile plugin = getProject().getFile(PLUGIN_XML_FILE);
+ if(!plugin.exists()) {
+ files.add(PLUGIN_XML_FILE);
+ }
+ return files;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.file.AbstractFileEditor#getMissingBuildCommand()
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<String> getMissingBuildCommand() {
+ Set<String> commands = super.getMissingBuildCommand();
+ if(!hasBuildCommand(PLUGIN_BUILD_COMMAND)) {
+ commands.add(PLUGIN_BUILD_COMMAND);
+ }
+ return commands;
+ }
+
+ /**
+ * @return The XML Document associated to this plugin.xml file
+ * @see PluginProjectEditor#init()
+ * @see PluginProjectEditor#create()
+ */
+ public Document getDocument() {
+ return pluginXML;
+ }
+}
diff --git a/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/ProjectEditor.java b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/ProjectEditor.java
new file mode 100644
index 00000000000..1c223630c32
--- /dev/null
+++ b/incoming/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/project/ProjectEditor.java
@@ -0,0 +1,150 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.eclipse.project.editors.project;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.papyrus.eclipse.project.editors.Activator;
+import org.eclipse.papyrus.eclipse.project.editors.interfaces.IProjectEditor;
+
+/**
+ *
+ * This class allows to manage the eclipse project
+ *
+ */
+public class ProjectEditor extends AbstractProjectEditor implements IProjectEditor {
+
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param project
+ * the eclipse project
+ * @throws CoreException
+ */
+ public ProjectEditor(final IProject project) throws CoreException {
+ super(project);
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param folder
+ * a folder
+ * @throws CoreException
+ */
+ public ProjectEditor(final IFolder folder) throws CoreException {
+ super(null);
+ //TODO : create an action to import a folder as a project!
+ //this will allow to test the create method
+ throw new UnsupportedOperationException();
+ }
+
+
+
+ /**
+ * Create the project file
+ * TODO NOT TESTED
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IProjectEditor#createFiles(Set)
+ *
+ * {@inheritDoc}
+ */
+ public void createFiles(final Set<String> files) {
+ if(files.contains(PROJECT_FILE)) {
+ final IFile file = getProject().getFile(PROJECT_FILE);
+ if(!file.exists()) {
+ String input = ""; //$NON-NLS-1$
+ input += AbstractProjectEditor.XML_HEADER;
+ input += "<" + NAME + ">"; //$NON-NLS-1$ //$NON-NLS-2$
+ input += getProject().getName();
+ input += "</" + NAME + ">"; //$NON-NLS-1$ //$NON-NLS-2$
+ input += "<" + COMMENT + ">"; //$NON-NLS-1$ //$NON-NLS-2$
+ input += "</" + COMMENT + ">"; //$NON-NLS-1$ //$NON-NLS-2$
+ input += "<" + BUILD_SPEC + ">"; //$NON-NLS-1$ //$NON-NLS-2$
+ input += "</" + BUILD_SPEC + ">"; //$NON-NLS-1$ //$NON-NLS-2$
+ input += "<" + NATURE + ">"; //$NON-NLS-1$ //$NON-NLS-2$
+ input += "</" + NATURE + ">"; //$NON-NLS-1$ //$NON-NLS-2$
+
+ try {
+ file.create(getInputStream(input), true, null);
+ } catch (final CoreException e) {
+ Activator.log.error(e);
+ }
+ }
+ }
+ }
+
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IProjectEditor#getMissingFiles()
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<String> getMissingFiles() {
+ final Set<String> missingFile = super.getMissingFiles();
+ final IFile projectFile = getProject().getFile(PROJECT_FILE);
+ if(!projectFile.exists()) {
+ missingFile.add(IProjectEditor.PROJECT_FILE);
+ }
+ return missingFile;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IProjectEditor#addFile(java.net.URL, java.lang.String)
+ *
+ * @param url
+ * @param fileDestinationPath
+ * @param eraseExitingFile
+ */
+ public void addFile(final URL url, final String fileDestinationPath, final boolean eraseExitingFile) {
+ final IFile targetFile = getProject().getFile(new Path(fileDestinationPath));
+ if(targetFile.exists()) {
+ if(eraseExitingFile) {
+ try {
+ targetFile.delete(true, new NullProgressMonitor());
+ } catch (final CoreException e) {
+ Activator.log.error(e);
+ }
+ } else {
+ return;
+ }
+ }
+ try {
+ final InputStream is = url.openStream();;
+ targetFile.create(is, false, new NullProgressMonitor());
+ is.close();
+ targetFile.refreshLocal(IResource.DEPTH_ZERO, new NullProgressMonitor());
+ } catch (final CoreException e) {
+ Activator.log.error(e);
+ } catch (final IOException e) {
+ Activator.log.error(e);
+ }
+
+
+ }
+}

Back to the top