[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[texo-commit] org.eclipse.emf/org.eclipse.emf.texo/plugins/org.eclipse.emf.texo.generator/src/org/eclipse/emf/texo/generator MergingOutputHandler.java generate_model_36.oaw WorkFlowStarter.java ModelController.java ArtifactGenerator.java generate_model.oaw SourceMerger.java PropertyMerger.java FileCleaner.java

Update of /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.texo/plugins/org.eclipse.emf.texo.generator/src/org/eclipse/emf/texo/generator
In directory dev1:/tmp/cvs-serv7753/src/org/eclipse/emf/texo/generator

Modified Files:
	MergingOutputHandler.java ModelController.java 
	ArtifactGenerator.java SourceMerger.java PropertyMerger.java 
	FileCleaner.java 
Removed Files:
	generate_model_36.oaw WorkFlowStarter.java generate_model.oaw 
Log Message:
Removed mwe from code generation, solved several warnings, improved progress display

--- generate_model.oaw DELETED ---

Index: PropertyMerger.java
===================================================================
RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.texo/plugins/org.eclipse.emf.texo.generator/src/org/eclipse/emf/texo/generator/PropertyMerger.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** PropertyMerger.java	23 Sep 2010 12:40:40 -0000	1.9
--- PropertyMerger.java	23 Apr 2011 20:32:15 -0000	1.10
***************
*** 29,33 ****
  
          try {
!             final File targetFile = fileHandle.getTargetFile();
              final Properties currentProps = new Properties();
              if (targetFile.exists()) {
--- 29,33 ----
  
          try {
!             final File targetFile = new File(fileHandle.getAbsolutePath());
              final Properties currentProps = new Properties();
              if (targetFile.exists()) {
***************
*** 101,105 ****
              // catch them all
              throw new IllegalStateException("Exception while merging and saving property file " //$NON-NLS-1$
!                     + fileHandle.getTargetFile().getAbsolutePath() + " " + e.getMessage() + " " + e, e); //$NON-NLS-1$ //$NON-NLS-2$
          }
      }
--- 101,105 ----
              // catch them all
              throw new IllegalStateException("Exception while merging and saving property file " //$NON-NLS-1$
!                     + fileHandle.getAbsolutePath() + " " + e.getMessage() + " " + e, e); //$NON-NLS-1$ //$NON-NLS-2$
          }
      }

Index: ArtifactGenerator.java
===================================================================
RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.texo/plugins/org.eclipse.emf.texo.generator/src/org/eclipse/emf/texo/generator/ArtifactGenerator.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** ArtifactGenerator.java	23 Sep 2010 12:40:40 -0000	1.14
--- ArtifactGenerator.java	23 Apr 2011 20:32:15 -0000	1.15
***************
*** 17,87 ****
  package org.eclipse.emf.texo.generator;
  
  import java.util.ArrayList;
  import java.util.List;
  
! import org.eclipse.emf.mwe.core.WorkflowContext;
! import org.eclipse.emf.mwe.core.issues.Issues;
! import org.eclipse.emf.mwe.core.monitor.ProgressMonitor;
! import org.eclipse.xpand2.Generator;
  import org.eclipse.xpand2.output.Outlet;
  import org.eclipse.xpand2.output.PostProcessor;
! import org.eclipse.xpand2.output.VetoStrategy;
  
  /**
!  * Extends the default oaw generator to support working within Eclipse projects without the oaw nature being enabled.
   * 
   * @author <a href="mtaal@xxxxxxxxx">Martin Taal</a>
   */
! public class ArtifactGenerator extends Generator {
  
      private String projectName;
!     private List<Outlet> specificOutlets;
  
!     @Override
!     protected void invokeInternal2(final WorkflowContext ctx, final ProgressMonitor monitor, final Issues issues) {
  
!         // read templates from projects
!         final TexoResourceManager texoResourceManager = new TexoResourceManager();
!         texoResourceManager.setProjectName(getProjectName());
!         setResourceManager(texoResourceManager);
  
!         final FileCleaner fileCleaner = new FileCleaner();
  
!         final List<VetoStrategy> vetoStrategies = new ArrayList<VetoStrategy>();
!         for (final Object o : getBeautifier()) {
!             if (o instanceof MergingOutputHandler) {
!                 ((MergingOutputHandler) o).setProjectName(getProjectName());
!                 ((MergingOutputHandler) o).setMonitor(monitor);
!             }
!             if (o instanceof VetoStrategy) {
!                 vetoStrategies.add((VetoStrategy) o);
              }
-         }
  
!         for (final Outlet outlet : getOutlets()) {
!             outlet.setPath(EclipseGeneratorUtils.getProjectFilePath(getProjectName()) + "/" + outlet.getPath()); //$NON-NLS-1$
  
!             // make sure not to overwrite generated files
!             // NOTE: apparently the vetoStrategies is a public member
!             // the output location tracker needs to be first otherwise it won't
!             // always be called
!             outlet.vetoStrategies.add(0, fileCleaner.getNewOutputLocationTracker());
  
!             for (final VetoStrategy vs : vetoStrategies) {
!                 outlet.addVetoStrategy(vs);
!             }
  
!             for (final PostProcessor postProcesor : outlet.postprocessors) {
!                 if (postProcesor instanceof MergingOutputHandler) {
!                     ((MergingOutputHandler) postProcesor).setProjectName(getProjectName());
!                     ((MergingOutputHandler) postProcesor).setMonitor(monitor);
!                 }
!                 if (postProcesor instanceof VetoStrategy) {
!                     outlet.addVetoStrategy((VetoStrategy) postProcesor);
!                 }
              }
!         }
!         try {
!             super.invokeInternal2(ctx, monitor, issues);
              fileCleaner.clean();
          } catch (final Exception e) {
--- 17,98 ----
  package org.eclipse.emf.texo.generator;
  
+ import java.io.StringReader;
  import java.util.ArrayList;
+ import java.util.HashMap;
  import java.util.List;
+ import java.util.Map;
  
! import org.eclipse.core.runtime.IProgressMonitor;
! import org.eclipse.internal.xpand2.XpandTokens;
! import org.eclipse.internal.xpand2.ast.Definition;
! import org.eclipse.internal.xpand2.ast.ExpandStatement;
! import org.eclipse.internal.xpand2.ast.Template;
! import org.eclipse.internal.xpand2.parser.XpandParseFacade;
! import org.eclipse.internal.xtend.expression.ast.SyntaxElement;
! import org.eclipse.xpand2.XpandExecutionContextImpl;
! import org.eclipse.xpand2.output.NoChangesVetoStrategy;
  import org.eclipse.xpand2.output.Outlet;
+ import org.eclipse.xpand2.output.OutputImpl;
  import org.eclipse.xpand2.output.PostProcessor;
! import org.eclipse.xtend.expression.ExceptionHandler;
! import org.eclipse.xtend.expression.ExecutionContext;
! import org.eclipse.xtend.expression.Variable;
! import org.eclipse.xtend.type.impl.java.JavaMetaModel;
  
  /**
!  * Calls the XPand generator directly without using a workflow.
   * 
   * @author <a href="mtaal@xxxxxxxxx">Martin Taal</a>
   */
! public class ArtifactGenerator {
!     private static final String MODEL_CONTROLLER = "modelController"; //$NON-NLS-1$
!     private static final String FILE_ENCODING = "UTF-8"; //$NON-NLS-1$
  
+     private IProgressMonitor monitor = new org.eclipse.core.runtime.NullProgressMonitor();
+     private TexoResourceManager resourceManager = new TexoResourceManager();
      private String projectName;
!     private ModelController modelController;
!     private String outputFolder;
!     private String expand = "org::eclipse::emf::texo::modelgenerator::templates::model::root(modelController) FOREACH modelController.EPackages"; //$NON-NLS-1$
!     private FileCleaner fileCleaner = new FileCleaner();
  
!     private List<Outlet> outlets;
  
!     /**
!      * Run the generation for the project and output location. Uses XPand to call the expand command (
!      * {@link #getExpand()}). The output is generated in the output folder ({@link #getOutputFolder()}.
!      * 
!      * The outlets ({@link #getOutlets()} are used to format the output.
!      */
!     public void run() {
  
!         initializeOutlets();
  
!         final Map<String, Object> parameters = new HashMap<String, Object>();
!         parameters.put(MODEL_CONTROLLER, modelController);
! 
!         try {
!             final OutputImpl out = new OutputImpl();
!             out.setAutomaticHyphens(false);
!             for (final Outlet outlet : getOutlets()) {
!                 out.addOutlet(outlet);
              }
  
!             XpandExecutionContextImpl executionContext = new XpandExecutionContextImpl(resourceManager, out, null,
!                     new HashMap<String, Variable>(), null, getExceptionHandler(), null, null);
  
!             executionContext.registerMetaModel(new JavaMetaModel());
  
!             final ExpandStatement es = getStatement();
  
!             for (final String name : parameters.keySet()) {
!                 executionContext = (XpandExecutionContextImpl) executionContext.cloneWithVariable(new Variable(name,
!                         parameters.get(name)));
              }
! 
!             executionContext.registerAdvices("org::eclipse::emf::texo::modelgenerator::templates::advices"); //$NON-NLS-1$
! 
!             es.evaluate(executionContext);
! 
              fileCleaner.clean();
          } catch (final Exception e) {
***************
*** 91,98 ****
      }
  
!     // overridden to prevent stack overflow because of bug in superclass
!     @Override
!     public void addAdvices(String advice) {
!         addAdvice(advice);
      }
  
--- 102,119 ----
      }
  
!     private ExpandStatement getStatement() {
!         final Template tpl = XpandParseFacade.file(new StringReader(XpandTokens.LT + "DEFINE test FOR test" //$NON-NLS-1$
!                 + XpandTokens.RT + XpandTokens.LT + "EXPAND " + getExpand() + XpandTokens.RT + XpandTokens.LT //$NON-NLS-1$
!                 + "ENDDEFINE" + XpandTokens.RT), null); //$NON-NLS-1$
!         return (ExpandStatement) ((Definition) tpl.getDefinitions()[0]).getBody()[1];
!     }
! 
!     protected ExceptionHandler getExceptionHandler() {
!         return new ExceptionHandler() {
!             public void handleRuntimeException(RuntimeException ex, SyntaxElement element, ExecutionContext ctx,
!                     Map<String, Object> additionalContextInfo) {
!                 throw ex;
!             }
!         };
      }
  
***************
*** 110,131 ****
      public void setProjectName(final String projectName) {
          this.projectName = projectName;
      }
  
      /**
!      * @return the specificOutlets
       */
!     public List<Outlet> getSpecificOutlets() {
!         return specificOutlets;
      }
  
      /**
!      * @param specificOutlets
!      *            the specificOutlets to set
       */
!     public void setSpecificOutlets(final List<Outlet> specificOutlets) {
!         this.specificOutlets = specificOutlets;
!         for (final Outlet outlet : specificOutlets) {
!             addOutlet(outlet);
          }
      }
  }
--- 131,237 ----
      public void setProjectName(final String projectName) {
          this.projectName = projectName;
+         resourceManager.setProjectName(projectName);
      }
  
      /**
!      * Creates 2 outlets, one default and one for java. Both use the {@link NoChangesVetoStrategy} veto strategy, the
!      * java outlet uses the {@link SourceMerger} as the {@link PostProcessor}. This PostProcessor merges sources,
!      * organizes imports and formats the source according to the project settings.
!      * 
!      * The {@link FileCleaner#getNewOutputLocationTracker()} (a VetoStrategy) is used to keep track of which files are
!      * being generated. This VetoStrategy is added to each of the 2 outlets.
       */
!     protected void initializeOutlets() {
!         if (outlets != null) {
!             return;
!         }
!         outlets = new ArrayList<Outlet>();
!         {
!             final Outlet outlet = new Outlet();
!             outlet.setFileEncoding(FILE_ENCODING);
!             // make sure not to overwrite generated files
!             // NOTE: apparently the vetoStrategies is a public member
!             // the output location tracker needs to be first otherwise it won't
!             // always be called
!             outlet.addVetoStrategy(fileCleaner.getNewOutputLocationTracker());
!             outlet.addVetoStrategy(new NoChangesVetoStrategy());
!             outlet.setPath(EclipseGeneratorUtils.getProjectFilePath(getProjectName()) + "/" + outputFolder); //$NON-NLS-1$
! 
!             outlets.add(outlet);
!         }
!         {
!             final Outlet outlet = new Outlet();
!             outlet.setFileEncoding(FILE_ENCODING);
!             outlet.setName("java"); //$NON-NLS-1$
! 
!             // make sure not to overwrite generated files
!             // NOTE: apparently the vetoStrategies is a public member
!             // the output location tracker needs to be first otherwise it won't
!             // always be called
!             outlet.addVetoStrategy(fileCleaner.getNewOutputLocationTracker());
!             outlet.addVetoStrategy(new NoChangesVetoStrategy());
! 
!             final SourceMerger sourceMerger = new SourceMerger();
!             sourceMerger.setProjectName(getProjectName());
!             sourceMerger.setMonitor(monitor);
! 
!             outlet.addPostprocessor(sourceMerger);
! 
!             outlet.setPath(EclipseGeneratorUtils.getProjectFilePath(getProjectName()) + "/" + outputFolder); //$NON-NLS-1$
!             outlets.add(outlet);
!         }
      }
  
      /**
!      * Return the outlets, if they are not yet defined then the {@link #initializeOutlets()} method is called.
!      * 
!      * @return the outlets used in the generation.
       */
!     public final List<Outlet> getOutlets() {
!         if (outlets == null) {
!             initializeOutlets();
          }
+         return outlets;
+     }
+ 
+     public ModelController getModelController() {
+         return modelController;
+     }
+ 
+     public void setModelController(ModelController modelController) {
+         this.modelController = modelController;
+     }
+ 
+     public String getOutputFolder() {
+         return outputFolder;
+     }
+ 
+     public void setOutputFolder(String outputFolder) {
+         this.outputFolder = outputFolder;
+     }
+ 
+     public IProgressMonitor getMonitor() {
+         return monitor;
+     }
+ 
+     public void setMonitor(IProgressMonitor monitor) {
+         this.monitor = monitor;
+     }
+ 
+     /**
+      * @return the expand command, the default value is:
+      *         org::eclipse::emf::texo::modelgenerator::templates::model::root(modelController) FOREACH
+      *         modelController.EPackages
+      */
+     public String getExpand() {
+         return expand;
+     }
+ 
+     public void setExpand(String expand) {
+         this.expand = expand;
+     }
+ 
+     public void setOutlets(List<Outlet> outlets) {
+         this.outlets = outlets;
      }
  }

--- generate_model_36.oaw DELETED ---

Index: ModelController.java
===================================================================
RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.texo/plugins/org.eclipse.emf.texo.generator/src/org/eclipse/emf/texo/generator/ModelController.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** ModelController.java	23 Sep 2010 12:40:40 -0000	1.11
--- ModelController.java	23 Apr 2011 20:32:15 -0000	1.12
***************
*** 30,34 ****
   * 
   * An instance of this class is available in the templates as the modelController slot ( (
!  * {@link WorkFlowStarter#MODEL_CONTROLLER_CONTEXT_SLOT}).
   * 
   * @see ModelAnnotator
--- 30,34 ----
   * 
   * An instance of this class is available in the templates as the modelController slot ( (
!  * {@link ArtifactGenerator#setModelController(ModelController)}).
   * 
   * @see ModelAnnotator

--- WorkFlowStarter.java DELETED ---

Index: SourceMerger.java
===================================================================
RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.texo/plugins/org.eclipse.emf.texo.generator/src/org/eclipse/emf/texo/generator/SourceMerger.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** SourceMerger.java	23 Sep 2010 12:40:40 -0000	1.12
--- SourceMerger.java	23 Apr 2011 20:32:15 -0000	1.13
***************
*** 55,59 ****
      @Override
      protected void merge(final FileHandle fileHandle) {
!         final String targetLocation = fileHandle.getTargetFile().getAbsolutePath();
          // final String targetLocation = fileHandle.getAbsolutePath();
          final File targetFile = new File(targetLocation);
--- 55,59 ----
      @Override
      protected void merge(final FileHandle fileHandle) {
!         final String targetLocation = fileHandle.getAbsolutePath();
          // final String targetLocation = fileHandle.getAbsolutePath();
          final File targetFile = new File(targetLocation);
***************
*** 129,137 ****
              throw new IllegalStateException(
                      "Syntax error in current source for " + targetLocation //$NON-NLS-1$
!                             + " :" + getExceptionMessage(e) + " location " + location + " old source \n" + source + " new source \n" + newSource, e); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
          } catch (final Throwable t) {
              throw new IllegalStateException(
                      "Throwable caught for current source for " + targetLocation //$NON-NLS-1$
!                             + " :" + getExceptionMessage(t) + " location " + location + " old source \n" + source + " new source \n" + newSource, t); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
          } finally {
              is.close();
--- 129,137 ----
              throw new IllegalStateException(
                      "Syntax error in current source for " + targetLocation //$NON-NLS-1$
!                             + " :" + getExceptionMessage(e) + " location " + location + " old source \n" + source + " new source \n" + newSource, e); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
          } catch (final Throwable t) {
              throw new IllegalStateException(
                      "Throwable caught for current source for " + targetLocation //$NON-NLS-1$
!                             + " :" + getExceptionMessage(t) + " location " + location + " old source \n" + source + " new source \n" + newSource, t); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
          } finally {
              is.close();

Index: FileCleaner.java
===================================================================
RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.texo/plugins/org.eclipse.emf.texo.generator/src/org/eclipse/emf/texo/generator/FileCleaner.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** FileCleaner.java	23 Sep 2010 12:40:40 -0000	1.6
--- FileCleaner.java	23 Apr 2011 20:32:15 -0000	1.7
***************
*** 78,82 ****
  
          public boolean hasVeto(FileHandle handle) {
!             addFileLocation(handle.getTargetFile().getAbsolutePath());
              return false;
          }
--- 78,82 ----
  
          public boolean hasVeto(FileHandle handle) {
!             addFileLocation(handle.getAbsolutePath());
              return false;
          }

Index: MergingOutputHandler.java
===================================================================
RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.texo/plugins/org.eclipse.emf.texo.generator/src/org/eclipse/emf/texo/generator/MergingOutputHandler.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** MergingOutputHandler.java	23 Sep 2010 12:40:40 -0000	1.12
--- MergingOutputHandler.java	23 Apr 2011 20:32:15 -0000	1.13
***************
*** 17,21 ****
  package org.eclipse.emf.texo.generator;
  
! import org.eclipse.emf.mwe.core.monitor.ProgressMonitor;
  import org.eclipse.xpand2.output.FileHandle;
  import org.eclipse.xpand2.output.PostProcessor;
--- 17,21 ----
  package org.eclipse.emf.texo.generator;
  
! import org.eclipse.core.runtime.IProgressMonitor;
  import org.eclipse.xpand2.output.FileHandle;
  import org.eclipse.xpand2.output.PostProcessor;
***************
*** 30,34 ****
  
      private String projectName;
!     private ProgressMonitor monitor;
  
      public void afterClose(final FileHandle impl) {
--- 30,35 ----
  
      private String projectName;
!     private IProgressMonitor monitor;
!     private int totalCount = 100;
  
      public void afterClose(final FileHandle impl) {
***************
*** 43,49 ****
      public void beforeWriteAndClose(final FileHandle fileHandle) {
          // final String targetLocation = fileHandle.getAbsolutePath();
!         final String targetLocation = fileHandle.getTargetFile().getAbsolutePath();
  
          if (monitor != null) {
              monitor.subTask(targetLocation);
          }
--- 44,51 ----
      public void beforeWriteAndClose(final FileHandle fileHandle) {
          // final String targetLocation = fileHandle.getAbsolutePath();
!         final String targetLocation = fileHandle.getAbsolutePath();
  
          if (monitor != null) {
+             monitor.worked(1);
              monitor.subTask(targetLocation);
          }
***************
*** 96,105 ****
      }
  
!     public ProgressMonitor getMonitor() {
          return monitor;
      }
  
!     public void setMonitor(ProgressMonitor monitor) {
          this.monitor = monitor;
      }
  }
\ No newline at end of file
--- 98,115 ----
      }
  
!     public IProgressMonitor getMonitor() {
          return monitor;
      }
  
!     public void setMonitor(IProgressMonitor monitor) {
          this.monitor = monitor;
      }
+ 
+     public int getTotalCount() {
+         return totalCount;
+     }
+ 
+     public void setTotalCount(int totalCount) {
+         this.totalCount = totalCount;
+     }
  }
\ No newline at end of file