From 7757586bf5893d13c6d63fa03d77994412844e09 Mon Sep 17 00:00:00 2001 From: nnn-dev Date: Sat, 12 Apr 2014 01:27:45 +0200 Subject: [PATCH 01/18] version 0.10.0 --- CHANGES | 5 + README.markdown | 15 +- code2code.feature/feature.xml | 17 ++- code2code/META-INF/MANIFEST.MF | 8 +- .../code2code/core/generator/Template.java | 9 ++ .../wizards/generate/GenerateFilesWizard.java | 123 ++++++++------- .../GenerationCustomizationComposite.java | 18 ++- .../generate/GeneratorParametersPage.java | 144 +++++++++++++----- .../src/code2code/utils/EclipseGuiUtils.java | 69 ++++++--- 9 files changed, 276 insertions(+), 132 deletions(-) diff --git a/CHANGES b/CHANGES index bf9907a..dd42894 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,8 @@ +[nnn] 0.10.0 + +allow overwrite +add save/load parameters + 0.9.2 better handling no generators found diff --git a/README.markdown b/README.markdown index d1763de..3371b81 100644 --- a/README.markdown +++ b/README.markdown @@ -1,12 +1,15 @@ # What it is -code2code is an eclipse plugin to generate source code from templates. +(nnn.)code2code is an eclipse plugin to generate source code from templates. You can easily create your custom generators using known template engines: Groovy (JSP like), Freemarker or Velocity. See it in action [here](http://elsethenif.wordpress.com/2009/06/12/quickly-cruding-with-code2code-plugin-and-vraptor2/). +Note: +nnn.code2code is a fork of [code2code](https://github.com/srizzo/code2code) with extra features (save/load parameters, allow overwride) + # Creating a Generator The files: @@ -45,21 +48,21 @@ See it in action here: [Quickly cruding with code2code plugin and VRaptor2](http # Installation -Current version is 0.9.2 beta, tested against Eclipse Ganymede 3.4.2. +Current version is 0.10.0, tested against Eclipse Kepler SR1. -You can install it from the [Update Site](http://srizzo.github.com/code2code/updatesite) +You can install it from the [Update Site](http://nnn-dev.github.com/code2code/updatesite) # Documentation -[http://wiki.github.com/srizzo/code2code](http://wiki.github.com/srizzo/code2code) +[http://wiki.github.com/nnn-dev/code2code](http://wiki.github.com/nnn-dev/code2code) # Issues/Features -[http://github.com/srizzo/code2code/issues](http://github.com/srizzo/code2code/issues) +[http://github.com/nnn-dev/code2code/issues](http://github.com/nnn-dev/code2code/issues) # Generator Examples -[http://github.com/srizzo/code2code-example-generators/downloads](http://github.com/srizzo/code2code-example-generators/downloads) +[http://github.com/nnn-dev/code2code-example-generators/downloads](http://github.com/nnn-dev/code2code-example-generators/downloads) diff --git a/code2code.feature/feature.xml b/code2code.feature/feature.xml index 21b04f6..2e1672d 100644 --- a/code2code.feature/feature.xml +++ b/code2code.feature/feature.xml @@ -1,15 +1,16 @@ + version="0.10.0" + provider-name="3Zen (original = Samuel Rizzo)"> - - http://srizzo.github.com/code2code + + http://nnn-dev.github.com/code2code + Copyright (c) 2014 3Zen Copyright (c) 2009 Samuel Rizzo Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation @@ -33,14 +34,14 @@ OTHER DEALINGS IN THE SOFTWARE. - + diff --git a/code2code/META-INF/MANIFEST.MF b/code2code/META-INF/MANIFEST.MF index ebc552a..1f88c5c 100644 --- a/code2code/META-INF/MANIFEST.MF +++ b/code2code/META-INF/MANIFEST.MF @@ -1,9 +1,9 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 -Bundle-Name: code2code Plug-in -Bundle-SymbolicName: code2code;singleton:=true -Bundle-Version: 0.9.2 -Bundle-Vendor: Samuel Rizzo +Bundle-Name: code2code Plug-in modified by 3Zen +Bundle-SymbolicName: nnn.code2code;singleton:=true +Bundle-Version: 0.10.0 +Bundle-Vendor: 3Zen (original = Samuel Rizzo) Bundle-RequiredExecutionEnvironment: J2SE-1.5 Require-Bundle: org.eclipse.ui, org.eclipse.core.resources;bundle-version="3.4.0", diff --git a/code2code/src/code2code/core/generator/Template.java b/code2code/src/code2code/core/generator/Template.java index bcd8067..6f37ad3 100644 --- a/code2code/src/code2code/core/generator/Template.java +++ b/code2code/src/code2code/core/generator/Template.java @@ -11,6 +11,7 @@ public class Template { private boolean selectedToGenerate = true; + private boolean overwriteAllowed = false; private String userChoosenResult; private String userChoosenDestination; private final String templateName; @@ -63,6 +64,14 @@ public void setSelectedToGenerate(boolean selectedToGenerate) { this.selectedToGenerate = selectedToGenerate; } + public boolean isOverwriteAllowed() { + return overwriteAllowed; + } + + public void setOverwriteAllowed(boolean overwriteAllowed) { + this.overwriteAllowed=overwriteAllowed; + } + public void setUserChoosenResult(String userChoosenResult) { this.userChoosenResult = userChoosenResult; } diff --git a/code2code/src/code2code/ui/wizards/generate/GenerateFilesWizard.java b/code2code/src/code2code/ui/wizards/generate/GenerateFilesWizard.java index 8cb9f89..9b57f0d 100644 --- a/code2code/src/code2code/ui/wizards/generate/GenerateFilesWizard.java +++ b/code2code/src/code2code/ui/wizards/generate/GenerateFilesWizard.java @@ -17,7 +17,6 @@ import code2code.utils.EclipseGuiUtils; import code2code.utils.FileUtils; - public class GenerateFilesWizard extends Wizard implements INewWizard { private IStructuredSelection selection; @@ -25,94 +24,116 @@ public class GenerateFilesWizard extends Wizard implements INewWizard { private GeneratorParametersPage generatorParametersPage; private IWorkbench workbench; private GenerationCustomizationPage generationCustomizationPage; - + @Override public boolean performFinish() { - - Generator selectedGenerator = generatorSelectionPage.getSelectedGenerator(); - - if(selectedGenerator==null){ + + Generator selectedGenerator = generatorSelectionPage + .getSelectedGenerator(); + + if (selectedGenerator == null) { return false; } - + try { - Console.write("Processing generator: " + selectedGenerator.getName()); - - IProject project = selectedGenerator.getGeneratorFolder().getProject(); - - for (Template template : selectedGenerator.calculateChoosenTemplatesToGenerate()) { - + Console.write("Processing generator: " + + selectedGenerator.getName()); + + IProject project = selectedGenerator.getGeneratorFolder() + .getProject(); + + for (Template template : selectedGenerator + .calculateChoosenTemplatesToGenerate()) { + String destination = template.calculateDestination(); - - if(destination.equals("")){ - Console.write("Generating " + template.getTemplateName() + " to console:"); + + if (destination.equals("")) { + Console.write("Generating " + template.getTemplateName() + + " to console:"); Console.write("-------------------------------------------------------------"); Console.write(FileUtils.read(template.calculateResult())); Console.write("-------------------------------------------------------------"); - }else{ + } else { Path destinationPath = new Path(destination); - if(project.exists(destinationPath)){ - Console.write("File already exists. Skipping: " + destinationPath); - continue; + if (project.exists(destinationPath)) { + if (!template.isOverwriteAllowed()) { + + Console.write("File already exists. Skipping: " + + destinationPath); + continue; + } else { + Console.write("File already exists. Overwriting: " + + destinationPath); + + } } - - Console.write("Generating: " + template.getTemplateName() + " to " + destination); - + + Console.write("Generating: " + template.getTemplateName() + + " to " + destination); + IFile file = project.getFile(destinationPath); - + FileUtils.createParentFolders(file); - - file.create(template.calculateResult(), false, null); - + + if (file.exists()) { + file.setContents(template.calculateResult(), false, + true, null); + } else { + file.create(template.calculateResult(), false, null); + } + } - - + } Console.write("Done"); - + } catch (Exception e) { - try{ + try { Console.write("An error ocurred. See Error Log for details"); - }catch (Exception e2) { - EclipseGuiUtils.showErrorDialog(workbench.getActiveWorkbenchWindow().getShell(), e2); + } catch (Exception e2) { + EclipseGuiUtils.showErrorDialog(workbench + .getActiveWorkbenchWindow().getShell(), e2); throw new RuntimeException(e2); } - EclipseGuiUtils.showErrorDialog(workbench.getActiveWorkbenchWindow().getShell(), e); + EclipseGuiUtils.showErrorDialog(workbench + .getActiveWorkbenchWindow().getShell(), e); throw new RuntimeException(e); - }finally{ + } finally { Console.disposeConsole(); } - + return true; } - public void init(IWorkbench workbench, IStructuredSelection selection) { this.workbench = workbench; this.selection = selection; } - + @Override public void addPages() { - - if(selection.size() == 0){ - MessageDialog.openError(workbench.getActiveWorkbenchWindow().getShell(), "Ops", "Ops... No Project Selected"); - throw new IllegalStateException("Ops... a project should be selected"); + + if (selection.size() == 0) { + MessageDialog.openError(workbench.getActiveWorkbenchWindow() + .getShell(), "Ops", "Ops... No Project Selected"); + throw new IllegalStateException( + "Ops... a project should be selected"); } - - IProject project = ((IResource) ((IAdaptable)selection.getFirstElement()).getAdapter(IResource.class)).getProject(); - + + IProject project = ((IResource) ((IAdaptable) selection + .getFirstElement()).getAdapter(IResource.class)).getProject(); + generatorSelectionPage = new GeneratorSelectionPage(project); - generatorParametersPage = new GeneratorParametersPage(generatorSelectionPage); - generationCustomizationPage = new GenerationCustomizationPage(generatorParametersPage); - + generatorParametersPage = new GeneratorParametersPage( + generatorSelectionPage); + generationCustomizationPage = new GenerationCustomizationPage( + generatorParametersPage); + addPage(generatorSelectionPage); addPage(generatorParametersPage); addPage(generationCustomizationPage); - + } - - } diff --git a/code2code/src/code2code/ui/wizards/generate/GenerationCustomizationComposite.java b/code2code/src/code2code/ui/wizards/generate/GenerationCustomizationComposite.java index ab884c5..30e2326 100644 --- a/code2code/src/code2code/ui/wizards/generate/GenerationCustomizationComposite.java +++ b/code2code/src/code2code/ui/wizards/generate/GenerationCustomizationComposite.java @@ -58,7 +58,7 @@ public GenerationCustomizationComposite(final List