Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortarendt2014-04-15 11:00:35 -0400
committertarendt2014-04-15 11:00:35 -0400
commit3a8324a08b8e912ac35b0310f3a11b6acd53a03a (patch)
tree4b98b50c13b40ef6527e321fe37db533ba40629d
parentabcc85dae181b54e9a86776dac2c0eec54363a6b (diff)
downloadorg.eclipse.emf.refactor.refactoring-3a8324a08b8e912ac35b0310f3a11b6acd53a03a.tar.gz
org.eclipse.emf.refactor.refactoring-3a8324a08b8e912ac35b0310f3a11b6acd53a03a.tar.xz
org.eclipse.emf.refactor.refactoring-3a8324a08b8e912ac35b0310f3a11b6acd53a03a.zip
generation manager structure improved
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/bin/org/eclipse/emf/refactor/refactoring/generator/managers/RefactoringGenerationManager.class (renamed from org.eclipse.emf.refactor.refactoring.generator/bin/org/eclipse/emf/refactor/refactoring/generator/managers/GenerationManager.class)bin14146 -> 14179 bytes
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/bin/org/eclipse/emf/refactor/refactoring/generator/ui/NewRefactoringWizardJava.classbin8050 -> 8072 bytes
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/managers/RefactoringGenerationManager.java (renamed from org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/managers/GenerationManager.java)4
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/ui/NewRefactoringWizardJava.java4
-rw-r--r--org.eclipse.emf.refactor.refactoring.henshin/bin/.gitignore (renamed from org.eclipse.emf.refactor.refactoring.configuration/bin/.gitignore)0
-rw-r--r--org.eclipse.emf.refactor.refactoring.henshin/bin/org/eclipse/emf/refactor/refactoring/henshin/managers/HenshinGenerationManager.classbin8234 -> 15455 bytes
-rw-r--r--org.eclipse.emf.refactor.refactoring.henshin/src/org/eclipse/emf/refactor/refactoring/henshin/managers/HenshinGenerationManager.java235
8 files changed, 237 insertions, 9 deletions
diff --git a/org.eclipse.emf.refactor.refactoring.generator/META-INF/MANIFEST.MF b/org.eclipse.emf.refactor.refactoring.generator/META-INF/MANIFEST.MF
index 20d7365..16a2685 100644
--- a/org.eclipse.emf.refactor.refactoring.generator/META-INF/MANIFEST.MF
+++ b/org.eclipse.emf.refactor.refactoring.generator/META-INF/MANIFEST.MF
@@ -13,7 +13,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.emf.refactor.refactoring;bundle-version="0.7.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Export-Package: org.eclipse.emf.refactor.refactoring.generator.core,
+Export-Package: org.eclipse.emf.refactor.refactoring.generator,
+ org.eclipse.emf.refactor.refactoring.generator.core,
org.eclipse.emf.refactor.refactoring.generator.interfaces,
org.eclipse.emf.refactor.refactoring.generator.managers,
org.eclipse.emf.refactor.refactoring.generator.ui
diff --git a/org.eclipse.emf.refactor.refactoring.generator/bin/org/eclipse/emf/refactor/refactoring/generator/managers/GenerationManager.class b/org.eclipse.emf.refactor.refactoring.generator/bin/org/eclipse/emf/refactor/refactoring/generator/managers/RefactoringGenerationManager.class
index bf34b6d..0210af3 100644
--- a/org.eclipse.emf.refactor.refactoring.generator/bin/org/eclipse/emf/refactor/refactoring/generator/managers/GenerationManager.class
+++ b/org.eclipse.emf.refactor.refactoring.generator/bin/org/eclipse/emf/refactor/refactoring/generator/managers/RefactoringGenerationManager.class
Binary files differ
diff --git a/org.eclipse.emf.refactor.refactoring.generator/bin/org/eclipse/emf/refactor/refactoring/generator/ui/NewRefactoringWizardJava.class b/org.eclipse.emf.refactor.refactoring.generator/bin/org/eclipse/emf/refactor/refactoring/generator/ui/NewRefactoringWizardJava.class
index 6e7f63a..13b122e 100644
--- a/org.eclipse.emf.refactor.refactoring.generator/bin/org/eclipse/emf/refactor/refactoring/generator/ui/NewRefactoringWizardJava.class
+++ b/org.eclipse.emf.refactor.refactoring.generator/bin/org/eclipse/emf/refactor/refactoring/generator/ui/NewRefactoringWizardJava.class
Binary files differ
diff --git a/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/managers/GenerationManager.java b/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/managers/RefactoringGenerationManager.java
index 9770c7d..8c851d6 100644
--- a/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/managers/GenerationManager.java
+++ b/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/managers/RefactoringGenerationManager.java
@@ -61,7 +61,7 @@ import org.osgi.framework.Bundle;
* @author arendt
*
*/
-public class GenerationManager {
+public class RefactoringGenerationManager {
/**
* Full qualified name of the template directory inside the plugin.
@@ -111,7 +111,7 @@ public class GenerationManager {
* @param config Configuration data used for generating model
* refactoring code.
*/
- public GenerationManager(RefactoringInfo info) {
+ public RefactoringGenerationManager(RefactoringInfo info) {
this.info = info;
this.templateDirectory = setTemplateDirectory();
this.classpathEntries = setClassPathEntries();
diff --git a/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/ui/NewRefactoringWizardJava.java b/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/ui/NewRefactoringWizardJava.java
index 724caad..54a6157 100644
--- a/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/ui/NewRefactoringWizardJava.java
+++ b/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/ui/NewRefactoringWizardJava.java
@@ -21,7 +21,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.refactor.refactoring.generator.core.RefactoringInfo;
import org.eclipse.emf.refactor.refactoring.generator.interfaces.INewRefactoringWizard;
-import org.eclipse.emf.refactor.refactoring.generator.managers.GenerationManager;
+import org.eclipse.emf.refactor.refactoring.generator.managers.RefactoringGenerationManager;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardPage;
@@ -182,7 +182,7 @@ public class NewRefactoringWizardJava extends Wizard implements INewWizard, INew
refactoringConfig.setMetaModelName(metaModelName);
refactoringConfig.setParameters(parameterWizardPage.getParameters());
System.out.println(refactoringConfig);
- GenerationManager rg = new GenerationManager(refactoringConfig);
+ RefactoringGenerationManager rg = new RefactoringGenerationManager(refactoringConfig);
rg.run(monitor);
}
diff --git a/org.eclipse.emf.refactor.refactoring.configuration/bin/.gitignore b/org.eclipse.emf.refactor.refactoring.henshin/bin/.gitignore
index 571ee51..571ee51 100644
--- a/org.eclipse.emf.refactor.refactoring.configuration/bin/.gitignore
+++ b/org.eclipse.emf.refactor.refactoring.henshin/bin/.gitignore
diff --git a/org.eclipse.emf.refactor.refactoring.henshin/bin/org/eclipse/emf/refactor/refactoring/henshin/managers/HenshinGenerationManager.class b/org.eclipse.emf.refactor.refactoring.henshin/bin/org/eclipse/emf/refactor/refactoring/henshin/managers/HenshinGenerationManager.class
index 6aec08b..0392d32 100644
--- a/org.eclipse.emf.refactor.refactoring.henshin/bin/org/eclipse/emf/refactor/refactoring/henshin/managers/HenshinGenerationManager.class
+++ b/org.eclipse.emf.refactor.refactoring.henshin/bin/org/eclipse/emf/refactor/refactoring/henshin/managers/HenshinGenerationManager.class
Binary files differ
diff --git a/org.eclipse.emf.refactor.refactoring.henshin/src/org/eclipse/emf/refactor/refactoring/henshin/managers/HenshinGenerationManager.java b/org.eclipse.emf.refactor.refactoring.henshin/src/org/eclipse/emf/refactor/refactoring/henshin/managers/HenshinGenerationManager.java
index c57414f..8ab61ae 100644
--- a/org.eclipse.emf.refactor.refactoring.henshin/src/org/eclipse/emf/refactor/refactoring/henshin/managers/HenshinGenerationManager.java
+++ b/org.eclipse.emf.refactor.refactoring.henshin/src/org/eclipse/emf/refactor/refactoring/henshin/managers/HenshinGenerationManager.java
@@ -1,25 +1,66 @@
package org.eclipse.emf.refactor.refactoring.henshin.managers;
+import java.io.BufferedWriter;
+import java.io.ByteArrayInputStream;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.Writer;
+import java.net.MalformedURLException;
+import java.util.ArrayList;
import java.util.List;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.emf.codegen.jet.JETEmitter;
import org.eclipse.emf.codegen.jet.JETException;
-import org.eclipse.emf.refactor.refactoring.generator.managers.GenerationManager;
+import org.eclipse.emf.codegen.util.CodeGenUtil;
+import org.eclipse.emf.refactor.refactoring.generator.core.RefactoringInfo;
+import org.eclipse.emf.refactor.refactoring.generator.managers.XMLPluginFileManager;
import org.eclipse.emf.refactor.refactoring.henshin.Activator;
import org.eclipse.emf.refactor.refactoring.henshin.generator.HenshinRefactoringInfo;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.JavaCore;
import org.osgi.framework.Bundle;
-public class HenshinGenerationManager extends GenerationManager {
+public class HenshinGenerationManager {// extends RefactoringGenerationManager {
+
+ protected final String BUNDLEVERSION = "Bundle-Version";
+ protected final String BUNDLESYMBOLICNAME = "Bundle-SymbolicName";
+ protected final String SINGLETONTRUE = "singleton:=true";
+ protected final String PLUGINSPATH =
+ Platform.getInstallLocation().getURL().getPath() + "plugins/";
+ private final String JETEMITTERS = ".JETEmitters";
+ private final String JAVA = ".java";
+ protected final String JAVAJET = ".javajet";
+ protected final String TEMPLATES = "templates";
+
+ protected final String REFACTORINGWIZARD = "RefactoringWizard";
+ protected final String REFACTORINGWIZARDPAGE =
+ "RefactoringWizardPage";
+ protected final String REFACTORINGGUIHANDLER =
+ "RefactoringGuiHandler";
+ protected final String REFACTORINGCONTROLLER =
+ "RefactoringController";
+ protected final String REFACTORINGDATAMANAGEMENT =
+ "RefactoringDataManagement";
+ protected final String REFACTORINGTEST = "RefactoringTest";
private final String REFACTORINGWIZARDHENSHIN =
"RefactoringWizardHenshin";
@@ -44,9 +85,23 @@ public class HenshinGenerationManager extends GenerationManager {
*/
private HenshinRefactoringInfo info;
+ /**
+ * Full qualified name of the template directory inside the plugin.
+ */
+ protected String templateDirectory;
+
+ /**
+ * Classpath entry needed for compiling JET code.
+ */
+ protected List<IClasspathEntry> classpathEntries;
+
+ /**
+ * JETEmitter instance used for code generation.
+ */
+ protected JETEmitter jetEmitter;
+
public HenshinGenerationManager(HenshinRefactoringInfo info) {
- super(info);
this.info = info;
this.templateDirectory = this.setNewTemplateDirectory();
classpathEntries = setClassPathEntries();
@@ -54,12 +109,22 @@ public class HenshinGenerationManager extends GenerationManager {
}
protected List<IClasspathEntry> setClassPathEntries() {
- List<IClasspathEntry> cpe = super.setClassPathEntries();
+ List<IClasspathEntry> cpe = new ArrayList<IClasspathEntry>();
Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID);
// add org.eclipse.emf.refactor.refactoring.henshin to class path
String version = (String) bundle.getHeaders().get(BUNDLEVERSION);
cpe.add(JavaCore.newLibraryEntry(new Path(PLUGINSPATH +
Activator.PLUGIN_ID + "_" + version + ".jar"), null, null));
+ // add org.eclipse.emf.refactor.refactoring.generator to class path
+ bundle = Platform.getBundle(org.eclipse.emf.refactor.refactoring.generator.Activator.PLUGIN_ID);
+ version = (String) bundle.getHeaders().get(BUNDLEVERSION);
+ cpe.add(JavaCore.newLibraryEntry(new Path(PLUGINSPATH
+ + org.eclipse.emf.refactor.refactoring.generator.Activator.PLUGIN_ID + "_" + version + ".jar"), null, null));
+ // add org.eclipse.emf.refactor.refactoring to class path
+ bundle = Platform.getBundle(org.eclipse.emf.refactor.refactoring.Activator.PLUGIN_ID);
+ version = (String) bundle.getHeaders().get(BUNDLEVERSION);
+ cpe.add(JavaCore.newLibraryEntry(new Path(PLUGINSPATH +
+ org.eclipse.emf.refactor.refactoring.Activator.PLUGIN_ID + "_" + version + ".jar"), null, null));
return cpe;
}
@@ -76,6 +141,64 @@ public class HenshinGenerationManager extends GenerationManager {
generateCode(monitor);
}
+ /**
+ * Sets the singleton directive of the plugin to true.
+ */
+ protected void setSingletonDirective() {
+ IProject project = ResourcesPlugin.getWorkspace().getRoot()
+ .getProject(this.info.getProjectName());
+ try {
+ String fileName = project.getLocation()
+ .append("/META-INF/MANIFEST.MF")
+ .toOSString();
+ FileInputStream is = new FileInputStream(fileName);
+ Manifest mf = new Manifest(is);
+ Attributes att = mf.getMainAttributes();
+ String value = att.getValue(BUNDLESYMBOLICNAME);
+ if (! value.contains(SINGLETONTRUE))
+ value = value + ";" + SINGLETONTRUE;
+ att.putValue(BUNDLESYMBOLICNAME, value);
+ FileOutputStream out = new FileOutputStream(fileName);
+ mf.write(out);
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Deletes the .JETEmitters project used for model refactoring
+ * code generation.
+ * @param monitor Object for monitoring the deleting activity.
+ */
+ protected void deleteJetEmittersProject(IProgressMonitor monitor) {
+ try {
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ IResource r = root.findMember(JETEMITTERS);
+ System.out.println("IResoure: "+ r.getName());
+ if (r != null){
+ r.delete(IResource.ALWAYS_DELETE_PROJECT_CONTENT, monitor);
+// r.delete(false, monitor);
+ }
+ }
+ catch (CoreException e) { }
+ catch (Exception e) { }
+ }
+
+ /**
+ * Updates the plugin.xml file by adding the generated model refactoring
+ * to served extension points.
+ */
+ protected void updatePluginXml() {
+ List<RefactoringInfo> refactoringConfig =
+ XMLPluginFileManager.getRefactoringConfig
+ (this.info.getProjectName());
+ refactoringConfig.add(this.info);
+ XMLPluginFileManager.saveRefactoringConfig
+ (this.info.getProjectName(), refactoringConfig);
+ }
+
private void generateCode(IProgressMonitor monitor) {
String generatedCode = "";
try {
@@ -107,6 +230,77 @@ public class HenshinGenerationManager extends GenerationManager {
}
}
+ /**
+ * Saves the given content in a file with the given name.
+ * @param monitor Object for monitoring the saving activity.
+ * @param content Content to be saved in a file with the given name.
+ * @param fileName Name of the file the content has to be saved in.
+ * @throws CoreException Exception that can be thrown.
+ * @throws JETException Exception that can be thrown.
+ */
+ protected void save
+ (IProgressMonitor monitor, String content, String fileName)
+ throws CoreException, JETException {
+ IContainer container = findOrCreatePackage(monitor);
+ if (container == null) {
+ throw new JETException
+ ("Cound not find or create container for package "
+ + this.info.getPackageName() + " in "
+ + this.info.getProjectName());
+ }
+ IFile file = container.getFile(new Path(fileName + JAVA));
+ InputStream inputStream =
+ new ByteArrayInputStream(content.getBytes());
+ if (!file.exists()) {
+ file.create(inputStream, false, monitor);
+ } else {
+ container.refreshLocal(1, monitor);
+ file.setContents(inputStream, true, false, monitor);
+ }
+ }
+
+ /**
+ * Finds or creates the package the code has to be located to.
+ * @param progressMonitor Object for monitoring the activity.
+ * @return Package the code has to be located to.
+ * @throws CoreException Exception that can be thrown.
+ */
+ private IContainer findOrCreatePackage(IProgressMonitor progressMonitor)
+ throws CoreException {
+ IPath outputPath = new Path
+ (this.info.getProjectName() + "/src/"
+ + this.info.getPackageName().replace('.', '/'));
+ IProgressMonitor subMonitor =
+ new SubProgressMonitor(progressMonitor, 1);
+ IPath localLocation = null;
+ IContainer container =
+ CodeGenUtil.EclipseUtil.findOrCreateContainer
+ (outputPath, true, localLocation, subMonitor);
+ return container;
+ }
+
+ /**
+ * Generates code out of the template with the given name.
+ * @param monitor Object monitoring the code generation.
+ * @param template Name of the template used by JET.
+ * @return Generated code as String.
+ */
+ protected String generateCode(IProgressMonitor monitor, String template) {
+ String templatePath = this.templateDirectory + template + JAVAJET;
+ System.out.println("templatePath: " + templatePath);
+ ClassLoader classLoader = getClass().getClassLoader();
+ this.jetEmitter = new JETEmitter(templatePath, classLoader);
+ this.jetEmitter.getClasspathEntries().addAll(classpathEntries);
+ String result = "";
+ IProgressMonitor sub = new SubProgressMonitor(monitor, 1);
+ try {
+ result = jetEmitter.generate(sub, new Object[] { this.info });
+ } catch (JETException e) {
+ e.printStackTrace();
+ }
+ return result;
+ }
+
private String setNewTemplateDirectory() {
String td = "";
final Bundle bundle = Activator.getDefault().getBundle();
@@ -177,5 +371,38 @@ public class HenshinGenerationManager extends GenerationManager {
e.printStackTrace();
}
}
+
+ /**
+ * Saves the given content in a XML file with the given name.
+ * @param monitor Object for monitoring the saving activity.
+ * @param content Content to be saved in a file with the given name.
+ * @param fileName Name of the file the content has to be saved in.
+ * @throws CoreException Exception that can be thrown.
+ * @throws JETException Exception that can be thrown.
+ */
+ protected void saveXml
+ (IProgressMonitor monitor, String content, String fileName)
+ throws CoreException, JETException {
+ IContainer container = findOrCreatePackage(monitor).getParent()
+ .getParent().getParent();
+ if (container == null) {
+ throw new JETException
+ ("Cound not find or create container for package "
+ + this.info.getPackageName() + " in "
+ + this.info.getProjectName());
+ }
+ File file = new File(fileName);
+ try {
+ if (!file.exists()) {
+ Writer output = new BufferedWriter(new FileWriter(file));
+ output.write(content);
+ output.close();
+ } else {
+ container.refreshLocal(1, monitor);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
}

Back to the top