Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortarendt2012-11-21 14:15:50 +0000
committertarendt2012-11-21 14:15:50 +0000
commit7c58c0ca98bf44df540b7f1b54e9a990f3199271 (patch)
tree4db7e8173bf9012ff53f74af9b1a11a7048861e7 /org.eclipse.emf.refactor.refactoring.generator
parent6286aaa534cb663036f2078836d81c968f79002f (diff)
downloadorg.eclipse.emf.refactor.refactoring-7c58c0ca98bf44df540b7f1b54e9a990f3199271.tar.gz
org.eclipse.emf.refactor.refactoring-7c58c0ca98bf44df540b7f1b54e9a990f3199271.tar.xz
org.eclipse.emf.refactor.refactoring-7c58c0ca98bf44df540b7f1b54e9a990f3199271.zip
generation process implemented
Diffstat (limited to 'org.eclipse.emf.refactor.refactoring.generator')
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/managers/GenerationManager.java (renamed from org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/managers/GeneratioManager.java)65
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/managers/XMLPluginFileManager.java56
-rw-r--r--org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/ui/NewRefactoringWizardJava.java6
3 files changed, 81 insertions, 46 deletions
diff --git a/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/managers/GeneratioManager.java b/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/managers/GenerationManager.java
index b3b555b..302e9be 100644
--- a/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/managers/GeneratioManager.java
+++ b/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/managers/GenerationManager.java
@@ -61,7 +61,7 @@ import org.osgi.framework.Bundle;
* @author arendt
*
*/
-public class GeneratioManager {
+public class GenerationManager {
/**
* Full qualified name of the template directory inside the plugin.
@@ -111,7 +111,7 @@ public class GeneratioManager {
* @param config Configuration data used for generating model
* refactoring code.
*/
- public GeneratioManager(RefactoringInfo info) {
+ public GenerationManager(RefactoringInfo info) {
this.info = info;
this.templateDirectory = setTemplateDirectory();
this.classpathEntries = setClassPathEntries();
@@ -193,8 +193,10 @@ public class GeneratioManager {
try {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IResource r = root.findMember(JETEMITTERS);
+ System.out.println("IResoure: "+ r.getName());
if (r != null){
- r.delete(false, monitor);
+ r.delete(IResource.ALWAYS_DELETE_PROJECT_CONTENT, monitor);
+// r.delete(false, monitor);
}
}
catch (CoreException e) { }
@@ -357,31 +359,30 @@ public class GeneratioManager {
* as well as the contained config.xml files.
* @param monitor Object monitoring the code generation.
*/
- protected void createTestFolders(IProgressMonitor monitor) {
- String packageName = this.info.getPackageName();
- packageName = packageName.substring(0, packageName.lastIndexOf('.'));
- String path = Platform.getInstanceLocation()
- .getURL().getPath() + packageName;
+ protected void createTestFolders(IProgressMonitor monitor) {
+ IProject project = ResourcesPlugin.getWorkspace().getRoot()
+ .getProject(this.info.getProjectName());
+ System.out.println("-- info.getNumberOfTests(): " + info.getNumberOfTests());
if (this.info.getNumberOfTests() > 0) {
- try {
- File testFolder = new File(path + "/tests/" +
- this.info.getRefactoringId() + "/");
- testFolder.mkdirs();
- if (testFolder.exists() && testFolder.isDirectory()){
- String testfolderprefix =
- testFolder.getCanonicalPath() + "/test_";
- for (int i = 1; i <= this.info.getNumberOfTests(); i++) {
- File specifictestfolder = new File(testfolderprefix
- + String.format("%03d", i) + "/");
- if (!specifictestfolder.exists()
- || !specifictestfolder.isDirectory()) {
- specifictestfolder.mkdir();
- createConfigXml(monitor, specifictestfolder);
- }
+ String rootDir = "/tests/" + this.info.getRefactoringId() + "/";
+ String dirPath = project.getLocation().append(rootDir).toOSString();
+ System.out.println("--- dirPath: " + dirPath);
+ File testFolder = new File(dirPath);
+ testFolder.mkdirs();
+ if (testFolder.exists() && testFolder.isDirectory()){
+ for (int i = 1; i <= this.info.getNumberOfTests(); i++) {
+ String testDirSnippet = "/test_" + String.format("%03d", i) + "/";
+ String testDir = project.getLocation().append(rootDir + testDirSnippet).toOSString();
+ System.out.println("--- testDir: " + testDir);
+ File specifictestfolder = new File(testDir);
+ if (!specifictestfolder.exists()
+ || !specifictestfolder.isDirectory()) {
+ specifictestfolder.mkdir();
+ String xmlName = "/config.xml";
+ String xmlLocation = project.getLocation().append(rootDir + testDirSnippet + xmlName).toOSString();
+ createConfigXml(monitor, xmlLocation);
}
- }
- } catch (IOException e) {
- e.printStackTrace();
+ }
}
}
}
@@ -390,14 +391,16 @@ public class GeneratioManager {
* Creates the config.xml files within the test folders for the
* generated model refactoring.
* @param monitor Object monitoring the code generation.
- * @param xmlFolder File object containing the folder in which
+ * @param xmlLocation File object containing the folder in which
* the config should be saved.
*/
- private void createConfigXml(IProgressMonitor monitor, File xmlFolder) {
- String generatedCode = this.generateCode(monitor, XMLCONFIG);
+ private void createConfigXml(IProgressMonitor monitor, String path) {
+// String generatedCode = this.generateCode(monitor, XMLCONFIG);
+ String generatedCode = "TO DO";
try {
- File configXml = new File(xmlFolder.getCanonicalPath()
- + "/config.xml");
+// String path = xmlLocation.getCanonicalPath() + "/config.xml";
+ File configXml = new File(path);
+ System.out.println("---- createConfigXml::path: " + path);
if (!configXml.exists() || !configXml.isFile()) {
this.saveXml(monitor, generatedCode,
configXml.getCanonicalPath().toString());
diff --git a/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/managers/XMLPluginFileManager.java b/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/managers/XMLPluginFileManager.java
index 62a4e94..dce2d90 100644
--- a/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/managers/XMLPluginFileManager.java
+++ b/org.eclipse.emf.refactor.refactoring.generator/src/org/eclipse/emf/refactor/refactoring/generator/managers/XMLPluginFileManager.java
@@ -111,6 +111,18 @@ public abstract class XMLPluginFileManager {
}
}
+ private static Transformer createTransformer(){
+ final TransformerFactory transformerFactory = TransformerFactory.newInstance();
+ try {
+ Transformer transformer = transformerFactory.newTransformer();
+ transformer.setOutputProperty(OutputKeys.INDENT,"yes");
+ return transformer;
+ } catch (final TransformerConfigurationException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
/**
* Abstract method for getting a list of RefactoringConfig out from
* the model refactoring extension point served in the plugin.xml
@@ -132,9 +144,16 @@ public abstract class XMLPluginFileManager {
try {
IProject project = ResourcesPlugin.getWorkspace()
.getRoot().getProject(projectName);
+
+ String path = project.getLocation().toString() + "/" + XMLPluginFileManager.PLUGINXML;
+ System.out.println("Path: " + path);
+ final File file = new File(path);
+ System.out.println("exists: " + file.exists());
+ if (! file.exists()) createPluginFile(path);
+
java.net.URI uri = project.getLocationURI();
- doc = builder.parse
- (uri + "/" + XMLPluginFileManager.PLUGINXML);
+ path = uri + "/" + XMLPluginFileManager.PLUGINXML;
+ doc = builder.parse(path);
} catch (final SAXException e) {
e.printStackTrace();
} catch (final IOException e) {
@@ -142,6 +161,7 @@ public abstract class XMLPluginFileManager {
}
if (doc != null) {
Element root = doc.getDocumentElement();
+ System.out.println(root);
NodeList refactorings = root.getElementsByTagName
(ExtensionPointTags.REFACTORING_TAG);
for (int i=0; i < refactorings.getLength(); i++){
@@ -210,15 +230,7 @@ public abstract class XMLPluginFileManager {
extension.appendChild(refactoring);
}
root.appendChild(extension);
- final TransformerFactory transformerFactory =
- TransformerFactory.newInstance();
- Transformer transformer = null;
- try {
- transformer = transformerFactory.newTransformer();
- transformer.setOutputProperty(OutputKeys.INDENT,"yes");
- } catch (final TransformerConfigurationException e) {
- e.printStackTrace();
- }
+ Transformer transformer = XMLPluginFileManager.createTransformer();
final DOMSource source = new DOMSource(doc);
IProject project = ResourcesPlugin.getWorkspace()
.getRoot().getProject(projectName);
@@ -232,5 +244,27 @@ public abstract class XMLPluginFileManager {
}
}
}
+
+ private static void createPluginFile(String path) {
+ final DocumentBuilder builder = XMLPluginFileManager.newDocumentBuilder();
+ Document doc = null;
+ Element root;
+ if (builder != null) {
+ doc = builder.newDocument();
+ root = doc.createElement(XMLPluginFileManager.PLUGIN);
+ doc.appendChild(root);
+ final Element extension = doc.createElement(ExtensionPointTags.EXTENSION_POINT_TAG);
+ extension.setAttribute(XMLPluginFileManager.POINT, ExtensionPointTags.EXTENSION_POINT_NAME);
+ root.appendChild(extension);
+ }
+ final Transformer transformer = XMLPluginFileManager.createTransformer();
+ final DOMSource source = new DOMSource(doc);
+ final StreamResult result = new StreamResult(path);
+ try {
+ transformer.transform(source, result);
+ } catch (final TransformerException e) {
+ e.printStackTrace();
+ }
+ }
}
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 6ed39c9..4befb4c 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
@@ -11,7 +11,6 @@
package org.eclipse.emf.refactor.refactoring.generator.ui;
import java.lang.reflect.InvocationTargetException;
-import java.util.Arrays;
import java.util.LinkedList;
import org.eclipse.core.resources.IProject;
@@ -19,11 +18,10 @@ 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.EObject;
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.GeneratioManager;
+import org.eclipse.emf.refactor.refactoring.generator.managers.GenerationManager;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardPage;
@@ -155,7 +153,7 @@ public class NewRefactoringWizardJava extends Wizard implements INewWizard, INew
refactoringConfig.setMetaModelName(metaModelName);
refactoringConfig.setParameters(parameterWizardPage.getParameters());
System.out.println(refactoringConfig);
- GeneratioManager rg = new GeneratioManager(refactoringConfig);
+ GenerationManager rg = new GenerationManager(refactoringConfig);
rg.run(monitor);
}

Back to the top