Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortarendt2012-11-23 11:58:12 +0000
committertarendt2012-11-23 11:58:12 +0000
commit0bde0e72020f3e1af739edfaf6202635448332bc (patch)
tree41d5d4ba9023e8db55e67460f23612ea0573a848
parent8a99f52380dc8ab39bafa9f148c6809436bac8a6 (diff)
downloadorg.eclipse.emf.refactor.refactoring-0bde0e72020f3e1af739edfaf6202635448332bc.tar.gz
org.eclipse.emf.refactor.refactoring-0bde0e72020f3e1af739edfaf6202635448332bc.tar.xz
org.eclipse.emf.refactor.refactoring-0bde0e72020f3e1af739edfaf6202635448332bc.zip
three generation classes added
-rw-r--r--org.eclipse.emf.refactor.refactoring.henshin/META-INF/MANIFEST.MF7
-rw-r--r--org.eclipse.emf.refactor.refactoring.henshin/src/org/eclipse/emf/refactor/refactoring/henshin/managers/HenshinDependenciesManager.java59
-rw-r--r--org.eclipse.emf.refactor.refactoring.henshin/src/org/eclipse/emf/refactor/refactoring/henshin/managers/HenshinGenerationManager.java117
-rw-r--r--org.eclipse.emf.refactor.refactoring.henshin/src/org/eclipse/emf/refactor/refactoring/henshin/ui/NewRefactoringWizardHenshin.java242
4 files changed, 387 insertions, 38 deletions
diff --git a/org.eclipse.emf.refactor.refactoring.henshin/META-INF/MANIFEST.MF b/org.eclipse.emf.refactor.refactoring.henshin/META-INF/MANIFEST.MF
index 758ca21..06927ff 100644
--- a/org.eclipse.emf.refactor.refactoring.henshin/META-INF/MANIFEST.MF
+++ b/org.eclipse.emf.refactor.refactoring.henshin/META-INF/MANIFEST.MF
@@ -7,11 +7,14 @@ Bundle-Activator: org.eclipse.emf.refactor.refactoring.henshin.Activator
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.core.resources;bundle-version="3.8.1",
+ org.eclipse.jdt.core;bundle-version="3.8.2",
+ org.eclipse.ltk.core.refactoring;bundle-version="3.6.0",
+ org.eclipse.emf.codegen;bundle-version="2.8.0",
org.eclipse.emf.edit;bundle-version="2.8.0",
org.eclipse.emf.henshin.interpreter;bundle-version="0.9.4",
org.eclipse.emf.refactor.refactoring;bundle-version="0.7.0",
org.eclipse.emf.refactor.refactoring.generator;bundle-version="0.7.0",
- org.eclipse.emf.refactor.refactoring.runtime;bundle-version="0.7.0",
- org.eclipse.ltk.core.refactoring;bundle-version="3.6.0"
+ org.eclipse.emf.refactor.refactoring.runtime;bundle-version="0.7.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Import-Package: org.eclipse.ui.actions
diff --git a/org.eclipse.emf.refactor.refactoring.henshin/src/org/eclipse/emf/refactor/refactoring/henshin/managers/HenshinDependenciesManager.java b/org.eclipse.emf.refactor.refactoring.henshin/src/org/eclipse/emf/refactor/refactoring/henshin/managers/HenshinDependenciesManager.java
new file mode 100644
index 0000000..fa93a15
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.henshin/src/org/eclipse/emf/refactor/refactoring/henshin/managers/HenshinDependenciesManager.java
@@ -0,0 +1,59 @@
+package org.eclipse.emf.refactor.refactoring.henshin.managers;
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.emf.refactor.refactoring.generator.core.RefactoringInfo;
+import org.eclipse.emf.refactor.refactoring.generator.managers.DependenciesManager;
+
+public class HenshinDependenciesManager extends DependenciesManager {
+
+ private final static String REFACTORHENSHIN = "org.eclipse.emf.refactor.refactoring.henshin";
+
+ public static void updateDependencies(RefactoringInfo info) {
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(info.getProjectName());
+ try {
+ String fileName = project.getLocation().append(MANIFEST_FILE)
+ .toOSString();
+ FileInputStream is = new FileInputStream(fileName);
+ Manifest mf = new Manifest(is);
+ Attributes att = mf.getMainAttributes();
+ String value = att.getValue(REQUIREBUNDLE);
+ if (! value.contains(EXPRESSIONS))
+ value = value + "," + EXPRESSIONS;
+ if (! value.contains(ECORE))
+ value = value + "," + ECORE;
+ if (! value.contains(ECORECHANGE))
+ value = value + "," + ECORECHANGE;
+ if (! value.contains(LTKCORE))
+ value = value + "," + LTKCORE;
+ if (! value.contains(LTKUI))
+ value = value + "," + LTKUI;
+ if (! value.contains(REFACTORCOMMON))
+ value = value + "," + REFACTORCOMMON;
+ if (! value.contains(REFACTORRUNTIME))
+ value = value + "," + REFACTORRUNTIME;
+ if (! value.contains(REFACTORHENSHIN))
+ value = value + "," + REFACTORHENSHIN;
+ if (! value.contains(JUNIT))
+ value = value + "," + JUNIT + ";bundle-version=\"4.8.1\"";
+ if (! value.contains(info.getJar()))
+ value = value + "," + info.getJar();
+ att.putValue(REQUIREBUNDLE, value);
+ FileOutputStream out = new FileOutputStream(fileName);
+ mf.write(out);
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+
+}
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
new file mode 100644
index 0000000..3dab1ce
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.henshin/src/org/eclipse/emf/refactor/refactoring/henshin/managers/HenshinGenerationManager.java
@@ -0,0 +1,117 @@
+package org.eclipse.emf.refactor.refactoring.henshin.managers;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.codegen.jet.JETException;
+import org.eclipse.emf.refactor.refactoring.generator.managers.GenerationManager;
+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 {
+
+ private final String REFACTORINGWIZARDHENSHIN =
+ "RefactoringWizardHenshin";
+ private final String REFACTORINGWIZARDPAGEHENSHIN =
+ "RefactoringWizardPageHenshin";
+ private final String REFACTORINGGUIHANDLERHENSHIN =
+ "RefactoringGuiHandlerHenshin";
+ private final String REFACTORINGCONTROLLERHENSHIN =
+ "RefactoringControllerHenshin";
+ private final String REFACTORINGDATAMANAGEMENTHENSHIN =
+ "RefactoringDataManagementHenshin";
+ private final String REFACTORINGINFORMATIONHENSHIN =
+ "RefactoringInformationHenshin";
+ private final String REFACTORINGINFORMATION =
+ "RefactoringInformation";
+ protected final String REFACTORINGTESTHENSHIN =
+ "RefactoringTestHenshin";
+
+ /**
+ * Configuration data used for generating model refactoring code.
+ */
+ private HenshinRefactoringInfo info;
+
+
+ public HenshinGenerationManager(HenshinRefactoringInfo info) {
+ super(info);
+ this.info = info;
+ this.templateDirectory = this.setNewTemplateDirectory();
+ classpathEntries = setClassPathEntries();
+ System.out.println("HenshinGenerationManager initialized!");
+ }
+
+ protected List<IClasspathEntry> setClassPathEntries() {
+ List<IClasspathEntry> cpe = super.setClassPathEntries();
+ 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));
+ return cpe;
+ }
+
+ /**
+ * @see org.eclipse.emf.refactor.generator.RefactoringGenerator#
+ * run(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public void run(IProgressMonitor monitor){
+ deleteJetEmittersProject(monitor);
+ updatePluginXml();
+ HenshinDependenciesManager.updateDependencies(info);
+ setSingletonDirective();
+ createTestFolders(monitor);
+ generateCode(monitor);
+ }
+
+ private void generateCode(IProgressMonitor monitor) {
+ String generatedCode = "";
+ try {
+ generatedCode =
+ this.generateCode(monitor, REFACTORINGWIZARDHENSHIN);
+ this.save(monitor, generatedCode, REFACTORINGWIZARD);
+ generatedCode =
+ this.generateCode(monitor, REFACTORINGWIZARDPAGEHENSHIN);
+ this.save(monitor, generatedCode, REFACTORINGWIZARDPAGE);
+ generatedCode =
+ this.generateCode(monitor, REFACTORINGGUIHANDLERHENSHIN);
+ this.save(monitor, generatedCode, REFACTORINGGUIHANDLER);
+ generatedCode =
+ this.generateCode(monitor, REFACTORINGCONTROLLERHENSHIN);
+ this.save(monitor, generatedCode, REFACTORINGCONTROLLER);
+ generatedCode =
+ this.generateCode(monitor, REFACTORINGDATAMANAGEMENTHENSHIN);
+ this.save(monitor, generatedCode, REFACTORINGDATAMANAGEMENT);
+ generatedCode =
+ this.generateCode(monitor, REFACTORINGINFORMATIONHENSHIN);
+ this.save(monitor, generatedCode, REFACTORINGINFORMATION);
+ generatedCode =
+ this.generateCode(monitor, REFACTORINGTESTHENSHIN);
+ this.save(monitor, generatedCode, REFACTORINGTEST);
+ } catch (JETException e) {
+ e.printStackTrace();
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private String setNewTemplateDirectory() {
+ String td = "";
+ final Bundle bundle = Activator.getDefault().getBundle();
+ try {
+ td = FileLocator.toFileURL(bundle.getEntry(TEMPLATES)).getFile();
+ } catch (final IOException e) {
+ e.printStackTrace();
+ }
+ return td;
+ }
+
+}
diff --git a/org.eclipse.emf.refactor.refactoring.henshin/src/org/eclipse/emf/refactor/refactoring/henshin/ui/NewRefactoringWizardHenshin.java b/org.eclipse.emf.refactor.refactoring.henshin/src/org/eclipse/emf/refactor/refactoring/henshin/ui/NewRefactoringWizardHenshin.java
index 0b93bc7..ad1d0ef 100644
--- a/org.eclipse.emf.refactor.refactoring.henshin/src/org/eclipse/emf/refactor/refactoring/henshin/ui/NewRefactoringWizardHenshin.java
+++ b/org.eclipse.emf.refactor.refactoring.henshin/src/org/eclipse/emf/refactor/refactoring/henshin/ui/NewRefactoringWizardHenshin.java
@@ -1,102 +1,272 @@
package org.eclipse.emf.refactor.refactoring.henshin.ui;
+import java.lang.reflect.InvocationTargetException;
import java.util.LinkedList;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectNature;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+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.ui.BasicDataWizardPage;
+import org.eclipse.emf.refactor.refactoring.generator.ui.TestWizardPage;
+import org.eclipse.emf.refactor.refactoring.henshin.generator.HenshinRefactoringInfo;
+import org.eclipse.emf.refactor.refactoring.henshin.managers.HenshinGenerationManager;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.actions.WorkspaceModifyOperation;
public class NewRefactoringWizardHenshin extends Wizard implements INewWizard, INewRefactoringWizard {
+
+ private String menuLabel;
+ private String id;
+ private String namespaceUri;
+ private String className;
+ private String jar;
+ private String importPackage;
+ private LinkedList<IProject> projects;
+ private final String WINDOW_TITLE = "New Refactoring";
+
+ /**
+ * Name of the project the model refactoring code has to be
+ * generated to.
+ */
+ private String projectName;
+
+ /**
+ * Name of the Henshin file used for executing the EMF model
+ * refactoring.
+ */
+ private String transformationFileName;
+
+ /**
+ * Wizard page for configurating model refactoring data (basics).
+ */
+ private BasicDataWizardPage basicWizardPage;
+
+ /**
+ * Wizard page for specifying Henshin files used for initial checking,
+ * final checking, and executing the EMF model refactoring.
+ */
+ private HenshinTransformationWizardPage transformationWizardPage;
+
+ /**
+ * Wizard page for configurating model refactoring parameters.
+ */
+ private ParameterWizardPage parameterWizardPage;
+
+ /**
+ * Wizard page for configurating model test parameters.
+ */
+ private TestWizardPage testWizardPage;
+
+ public NewRefactoringWizardHenshin() { }
- public NewRefactoringWizardHenshin() {
- // TODO Auto-generated constructor stub
+ public NewRefactoringWizardHenshin(String metamodel, String contextType) {
+ this.namespaceUri = metamodel;
+ this.className = contextType;
}
@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
- // TODO Auto-generated method stub
-
+ initProjects();
+ }
+
+ @Override
+ public void addPages() {
+ setWindowTitle(WINDOW_TITLE);
+
+ this.basicWizardPage = new BasicDataWizardPage();
+ this.transformationWizardPage =
+ new HenshinTransformationWizardPage("EMF Refactor", this);
+ this.parameterWizardPage =
+ new ParameterWizardPage("EMF Refactor");
+ this.testWizardPage = new TestWizardPage();
+ if (namespaceUri != null && ! namespaceUri.isEmpty()
+ && className != null && ! className.isEmpty()) {
+ setMetamodelAndContext();
+ }
+ this.addPage(basicWizardPage);
+ this.addPage(transformationWizardPage);
+ this.addPage(parameterWizardPage);
+ this.addPage(testWizardPage);
+ }
+
+ public void setMetamodelAndContext() {
+ basicWizardPage.setMetamodel(namespaceUri);
+ basicWizardPage.setContextType(className);
+ }
+
+ private void initProjects(){
+ this.projects = new LinkedList<IProject>();
+ IProject[] allProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ for (IProject project : allProjects) {
+ if (project.isOpen()) {
+ IProjectNature nature = null;
+ try {
+ nature = project.getNature("org.eclipse.pde.PluginNature");
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ if (null != nature)
+ this.projects.add(project);
+ }
+ }
+ }
+
+ @Override
+ public boolean canFinish() {
+ return (basicWizardPage.isPageComplete()
+ && transformationWizardPage.isPageComplete());
}
@Override
public boolean performFinish() {
- // TODO Auto-generated method stub
- return false;
+ WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
+ @Override
+ public void execute(IProgressMonitor monitor)
+ throws InvocationTargetException {
+ try {
+ createRefactoring(monitor);
+ } catch (Exception e){
+ e.printStackTrace();
+ } finally {
+ monitor.done();
+ }
+ }
+ };
+ try {
+ getContainer().run(false, false, op);
+ } catch (InvocationTargetException e) {
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ return true;
+ }
+
+ /**
+ * Triggers the model refactoring generation activity. Collects data
+ * from its wizard pages and starts the refactoring generator.
+ * @param monitor Object monitoring the model refactoring
+ * generation activity.
+ */
+ protected void createRefactoring(IProgressMonitor monitor) {
+ // from ...Java
+ int numberOfTests = testWizardPage.getNumberOfTests();
+ String nsPrefix = getNsPrefix();
+ String metaModelName = getMetaModelName();
+ String createChangeFileName =
+ transformationWizardPage.getTransformationFileName();
+ HenshinRefactoringInfo refactoringConfig =
+ new HenshinRefactoringInfo(projectName, id, menuLabel, namespaceUri,
+ createChangeFileName, nsPrefix, numberOfTests);
+ refactoringConfig.setSelectedEObjectJar(jar);
+ refactoringConfig.setSelectedEObjectClass(importPackage + "." + className);
+ refactoringConfig.setMetaModelName(metaModelName);
+ refactoringConfig.setParameters(parameterWizardPage.getSelectedParameters());
+ refactoringConfig.setCheckInitialFileName
+ (transformationWizardPage.getCheckInitialFileName());
+ refactoringConfig.setCheckFinalFileName
+ (transformationWizardPage.getCheckFinalFileName());
+ System.out.println(refactoringConfig);
+ HenshinGenerationManager hgm =
+ new HenshinGenerationManager(refactoringConfig);
+ hgm.run(monitor);
+ }
+
+ private String getNsPrefix() {
+ EPackage mm =
+ EPackage.Registry.INSTANCE.getEPackage(namespaceUri);
+ return mm.getNsPrefix();
+ }
+
+ private String getMetaModelName() {
+ EPackage mm =
+ EPackage.Registry.INSTANCE.getEPackage(namespaceUri);
+ return mm.getName();
}
@Override
public LinkedList<IProject> getProjects() {
- // TODO Auto-generated method stub
- return null;
+ return projects;
}
@Override
public int getPageNumbers() {
- // TODO Auto-generated method stub
- return 0;
+ return 4;
}
@Override
- public void updateSecondPage() {
- // TODO Auto-generated method stub
-
+ public void updateSecondPage() {
+ this.transformationWizardPage.setProjectName(projectName);
}
@Override
public WizardPage getSecondPage() {
- // TODO Auto-generated method stub
- return null;
+ return transformationWizardPage;
}
@Override
- public void setTargetProject(String text) {
- // TODO Auto-generated method stub
-
+ public void setTargetProject(String projectName) {
+ this.projectName = projectName;
+ this.transformationWizardPage.setProjectName(projectName);
+ this.parameterWizardPage.setProjectName(projectName);
}
@Override
- public void setName(String text) {
- // TODO Auto-generated method stub
-
+ public void setName(String name) {
+ this.menuLabel = name;
}
@Override
- public void setId(String text) {
- // TODO Auto-generated method stub
-
+ public void setId(String id) {
+ this.id = id;
}
@Override
- public void setMetamodel(String text) {
- // TODO Auto-generated method stub
-
+ public void setMetamodel(String metamodel) {
+ this.namespaceUri = metamodel;
}
@Override
- public void setContext(String text) {
- // TODO Auto-generated method stub
-
+ public void setContext(String context) {
+ this.className = context;
}
@Override
public void setJar(String jar) {
- // TODO Auto-generated method stub
-
+ this.jar = jar;
}
@Override
public void setImportPackage(String importPackage) {
- // TODO Auto-generated method stub
-
+ this.importPackage = importPackage;
}
public void setTransformationFileName(String transformationFileName) {
- // TODO Auto-generated method stub
-
+ this.transformationFileName = transformationFileName;
+ this.parameterWizardPage.setTransformationFileName(transformationFileName);
}
+ public String getTransformationFileName() {
+ return transformationFileName;
+ }
+
+ /**
+ * Gets the name of the project the model refactoring code has to be
+ * generated to.
+ * @return Name of the project the model refactoring code has to be
+ * generated to.
+ */
+ public String getProjectName(){
+ return this.projectName;
+ }
}

Back to the top