Support for headless generation of Installed Module JAR.
diff --git a/plugins/org.eclipse.tigerstripe.workbench.headless/.classpath b/plugins/org.eclipse.tigerstripe.workbench.headless/.classpath
index edbbfc6..64c5e31 100644
--- a/plugins/org.eclipse.tigerstripe.workbench.headless/.classpath
+++ b/plugins/org.eclipse.tigerstripe.workbench.headless/.classpath
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry exported="true" kind="lib" path="lib/commons-io-2.4.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
diff --git a/plugins/org.eclipse.tigerstripe.workbench.headless/META-INF/MANIFEST.MF b/plugins/org.eclipse.tigerstripe.workbench.headless/META-INF/MANIFEST.MF
index 1cf9558..ec1d783 100644
--- a/plugins/org.eclipse.tigerstripe.workbench.headless/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.tigerstripe.workbench.headless/META-INF/MANIFEST.MF
@@ -6,11 +6,11 @@
Bundle-Activator: org.eclipse.tigerstripe.workbench.headless.Activator
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.tigerstripe.workbench.base,
- org.eclipse.core.resources
+ org.eclipse.core.resources,
+ org.apache.commons.lang3,
+ org.apache.commons.io
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
-Export-Package: org.apache.commons.io,
- org.eclipse.tigerstripe.workbench.headless
+Export-Package: org.eclipse.tigerstripe.workbench.headless
Eclipse-BundleShape: jar
-Bundle-ClassPath: .,
- lib/commons-io-2.4.jar
+Bundle-ClassPath: .
diff --git a/plugins/org.eclipse.tigerstripe.workbench.headless/build.properties b/plugins/org.eclipse.tigerstripe.workbench.headless/build.properties
index ddd04da..6f1c034 100644
--- a/plugins/org.eclipse.tigerstripe.workbench.headless/build.properties
+++ b/plugins/org.eclipse.tigerstripe.workbench.headless/build.properties
@@ -5,5 +5,4 @@
.,\
plugin.xml,\
about.html,\
- lib/commons-io-2.4.jar,\
templates/
diff --git a/plugins/org.eclipse.tigerstripe.workbench.headless/lib/commons-io-2.4.jar b/plugins/org.eclipse.tigerstripe.workbench.headless/lib/commons-io-2.4.jar
deleted file mode 100644
index 90035a4..0000000
--- a/plugins/org.eclipse.tigerstripe.workbench.headless/lib/commons-io-2.4.jar
+++ /dev/null
Binary files differ
diff --git a/plugins/org.eclipse.tigerstripe.workbench.headless/src/org/eclipse/tigerstripe/workbench/headless/GenerateInstalledModuleRunnable.java b/plugins/org.eclipse.tigerstripe.workbench.headless/src/org/eclipse/tigerstripe/workbench/headless/GenerateInstalledModuleRunnable.java
index d3bb7d7..a51fd35 100644
--- a/plugins/org.eclipse.tigerstripe.workbench.headless/src/org/eclipse/tigerstripe/workbench/headless/GenerateInstalledModuleRunnable.java
+++ b/plugins/org.eclipse.tigerstripe.workbench.headless/src/org/eclipse/tigerstripe/workbench/headless/GenerateInstalledModuleRunnable.java
@@ -1,81 +1,55 @@
package org.eclipse.tigerstripe.workbench.headless;
import java.io.File;
-import java.util.List;
-import org.eclipse.core.resources.IWorkspaceRunnable;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
import org.eclipse.tigerstripe.workbench.TigerstripeException;
-import org.eclipse.tigerstripe.workbench.generation.PluginRunStatus;
import org.eclipse.tigerstripe.workbench.internal.core.generation.M1RunConfig;
import org.eclipse.tigerstripe.workbench.internal.core.generation.RunConfig;
import org.eclipse.tigerstripe.workbench.internal.core.module.InstalledModule;
import org.eclipse.tigerstripe.workbench.internal.core.module.InstalledModuleManager;
import org.eclipse.tigerstripe.workbench.project.ITigerstripeModelProject;
-public class GenerateInstalledModuleRunnable implements IWorkspaceRunnable {
+public class GenerateInstalledModuleRunnable extends GenerateTigerstripeModelRunnable {
- private List<String> moduleIds;
- private String path;
+ private String moduleId;
+ private File outputDir;
+ private ITigerstripeModelProject modelProject;
- public GenerateInstalledModuleRunnable(List<String> moduleIds, String path) {
- this.moduleIds = moduleIds;
- this.path = path;
+ public GenerateInstalledModuleRunnable(String moduleId, File outputDir) {
+ this.moduleId = moduleId;
+ this.outputDir = outputDir;
}
- public void run(final IProgressMonitor monitor) throws CoreException {
+ public Boolean call() throws Exception {
+ System.out.println("Starting on installed module: " + moduleId);
+ return super.call();
+ }
- for(String moduleId : moduleIds){
- InstalledModule moduleToGen = InstalledModuleManager.getInstance().getModule(moduleId);
- if (moduleToGen == null ){
- throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "No Module "+moduleId));
- }
- File outDir = null;
- if (path == null ){
- throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "No Path "+path));
- } else {
- outDir = new File(path);
- if (! outDir.exists() || ! outDir.isDirectory()){
- throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Path does not exist :"+path));
- }
- }
+ @Override
+ public M1RunConfig getGenerationRunConfig() throws TigerstripeException {
-
- try {
- ITigerstripeModelProject modelProject = moduleToGen.makeModuleProject();
-
- M1RunConfig runConfig = (M1RunConfig) RunConfig.newGenerationConfig(modelProject, RunConfig.M1);
-
- String moduleDir = path+File.separator+moduleId;
-
- File moduleDirectory = new File(moduleDir);
- moduleDirectory.mkdirs();
-
- if (! moduleDirectory.exists()){
- throw new CoreException( new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to create dir "+moduleDir));
- }
-
- runConfig.setAbsoluteOutputDir(moduleDir);
- runConfig.setGenerateModules(false);
- runConfig.setIgnoreFacets(true);
-
- PluginRunStatus[] results = modelProject.generate(runConfig, monitor);
- for (final PluginRunStatus status : results) {
- if (!status.isOK()) {
- // This bombs out on the first exception in any project
- // even on warning - is that what we want?
- throw new CoreException( new Status(status.getSeverity(), Activator.PLUGIN_ID, "Error performing generation "+status.getPluginConfig().getPluginName()+" "+status.getMessage()));
- }
- }
-
-
- } catch (TigerstripeException e) {
- throw new CoreException( new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error performing generation", e));
- }
+ M1RunConfig runConfig = (M1RunConfig) RunConfig.newGenerationConfig(getTargetProject(), RunConfig.M1);
+ File generationDir = new File(outputDir, moduleId);
+ if (!generationDir.mkdirs()) {
+ throw new TigerstripeException("Failed to create generation directory: " + generationDir.getAbsolutePath());
}
+ runConfig.setAbsoluteOutputDir(generationDir.getAbsolutePath());
+ runConfig.setGenerateModules(false);
+ return runConfig;
+ }
+
+ @Override
+ public ITigerstripeModelProject getTargetProject() throws TigerstripeException {
+ if (modelProject == null) {
+ System.out.println("Locating installed module JAR: " + moduleId);
+ InstalledModule moduleToGen = InstalledModuleManager.getInstance().getModule(moduleId);
+ if (moduleToGen == null) {
+ throw new TigerstripeException("Did not find any installed module for modelId=: " + moduleId);
+ }
+
+ modelProject = moduleToGen.makeModuleProject();
+ }
+ return modelProject;
}
}
diff --git a/plugins/org.eclipse.tigerstripe.workbench.headless/src/org/eclipse/tigerstripe/workbench/headless/GenerateProjectRunnable.java b/plugins/org.eclipse.tigerstripe.workbench.headless/src/org/eclipse/tigerstripe/workbench/headless/GenerateProjectRunnable.java
new file mode 100644
index 0000000..e5ab29d
--- /dev/null
+++ b/plugins/org.eclipse.tigerstripe.workbench.headless/src/org/eclipse/tigerstripe/workbench/headless/GenerateProjectRunnable.java
@@ -0,0 +1,76 @@
+package org.eclipse.tigerstripe.workbench.headless;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.tigerstripe.workbench.TigerstripeCore;
+import org.eclipse.tigerstripe.workbench.TigerstripeException;
+import org.eclipse.tigerstripe.workbench.internal.core.generation.M1RunConfig;
+import org.eclipse.tigerstripe.workbench.internal.core.generation.RunConfig;
+import org.eclipse.tigerstripe.workbench.project.ITigerstripeModelProject;
+
+public class GenerateProjectRunnable extends GenerateTigerstripeModelRunnable {
+
+ private IProject project;
+ private ITigerstripeModelProject tsProject;
+
+ public GenerateProjectRunnable(IProject project) {
+ this.project = project;
+ }
+
+ public Boolean call() throws Exception {
+ System.out.println("Starting on model project: " + project.getName());
+ System.out.println("Validating project: " + project.getName());
+ validateProject(project);
+ return super.call();
+ }
+
+ @Override
+ public M1RunConfig getGenerationRunConfig() throws TigerstripeException {
+ ITigerstripeModelProject tsProject = (ITigerstripeModelProject) TigerstripeCore.findProject(project);
+ return (M1RunConfig) RunConfig.newGenerationConfig(tsProject, RunConfig.M1);
+ }
+
+ @Override
+ public ITigerstripeModelProject getTargetProject() throws TigerstripeException {
+ if (tsProject == null) {
+ tsProject = (ITigerstripeModelProject) TigerstripeCore.findProject(project);
+ }
+ return tsProject;
+ }
+
+ public static void validateProject(final IProject project) throws Exception {
+
+ final StringBuffer errorMsg = new StringBuffer();
+ IWorkspaceRunnable checkForErrorsRunnable = new IWorkspaceRunnable() {
+
+ public void run(IProgressMonitor monitor) throws CoreException {
+
+ IMarker[] markers = project.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
+ for (int i = 0; i < markers.length; i++) {
+ if (IMarker.SEVERITY_ERROR == markers[i].getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO)) {
+ String message = (String) markers[i].getAttribute(IMarker.MESSAGE);
+ if (message.contains("Plugin execution not covered by lifecycle configuration")) {
+ continue;
+ }
+ errorMsg.append("\n - ").append(markers[i].getResource().getProjectRelativePath().toString())
+ .append(": ").append(message);
+ }
+ }
+ }
+ };
+
+ ResourcesPlugin.getWorkspace().run(checkForErrorsRunnable, new NullProgressMonitor());
+
+ if (errorMsg.length() > 0) {
+ throw new TigerstripeException("Unable to perform generation. Project [" + project.getName()
+ + "] contains errors: " + errorMsg.toString());
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.tigerstripe.workbench.headless/src/org/eclipse/tigerstripe/workbench/headless/GenerateTigerstripeModelRunnable.java b/plugins/org.eclipse.tigerstripe.workbench.headless/src/org/eclipse/tigerstripe/workbench/headless/GenerateTigerstripeModelRunnable.java
new file mode 100644
index 0000000..9a758cf
--- /dev/null
+++ b/plugins/org.eclipse.tigerstripe.workbench.headless/src/org/eclipse/tigerstripe/workbench/headless/GenerateTigerstripeModelRunnable.java
@@ -0,0 +1,79 @@
+package org.eclipse.tigerstripe.workbench.headless;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.concurrent.Callable;
+
+import org.eclipse.tigerstripe.workbench.TigerstripeException;
+import org.eclipse.tigerstripe.workbench.internal.contract.segment.FacetReference;
+import org.eclipse.tigerstripe.workbench.internal.core.generation.M1RunConfig;
+import org.eclipse.tigerstripe.workbench.project.IPluginConfig;
+import org.eclipse.tigerstripe.workbench.project.ITigerstripeModelProject;
+
+public abstract class GenerateTigerstripeModelRunnable implements Callable<Boolean> {
+
+ private File facetFile;
+ private boolean ignoreFacet;
+ private Collection<String> disabledGenerators;
+
+ public Collection<String> getDisabledGenerators() {
+ return disabledGenerators;
+ }
+
+ public void setDisabledGenerators(Collection<String> disabledGenerators) {
+ this.disabledGenerators = disabledGenerators;
+ }
+
+ public boolean ignoreFacet() {
+ return ignoreFacet;
+ }
+
+ public void setIgnoreFacet(boolean ignore) {
+ this.ignoreFacet = ignore;
+ }
+
+ public void setFacet(File facet) {
+ this.facetFile = facet;
+ }
+
+ public File getFacet() {
+ return facetFile;
+ }
+
+ public abstract M1RunConfig getGenerationRunConfig() throws TigerstripeException;
+
+ public abstract ITigerstripeModelProject getTargetProject() throws TigerstripeException;
+
+ public Boolean call() throws Exception {
+
+ ITigerstripeModelProject modelProject = getTargetProject();
+ M1RunConfig runConfig = getGenerationRunConfig();
+
+ if (getFacet() != null && getFacet().exists()) {
+ System.out.println(
+ "Setting project facet for: " + modelProject.getName() + " to: " + facetFile.getAbsolutePath());
+ FacetReference facet = new FacetReference(facetFile.toURI(), modelProject);
+ modelProject.setActiveFacet(facet, null);
+ runConfig.setUseCurrentFacet(true);
+ } else if (ignoreFacet()) {
+ runConfig.setIgnoreFacets(true);
+ }
+
+ for (IPluginConfig generator : runConfig.getPluginConfigs()) {
+ if (disabledGenerators.contains(generator.getPluginName())) {
+ System.out.println("Disabling " + generator.getPluginName() + " generator.");
+ generator.setEnabled(false);
+ }
+ }
+
+ System.out.println("Running generation on model: " + modelProject.getName());
+ try {
+ GenerationUtils.generateTigerstripeOutput(modelProject, runConfig);
+ } finally {
+ if (facetFile != null && facetFile.exists()) {
+ modelProject.resetActiveFacet();
+ }
+ }
+ return true;
+ }
+}
diff --git a/plugins/org.eclipse.tigerstripe.workbench.headless/src/org/eclipse/tigerstripe/workbench/headless/GenerationUtils.java b/plugins/org.eclipse.tigerstripe.workbench.headless/src/org/eclipse/tigerstripe/workbench/headless/GenerationUtils.java
index c2b3eb0..a5d0673 100644
--- a/plugins/org.eclipse.tigerstripe.workbench.headless/src/org/eclipse/tigerstripe/workbench/headless/GenerationUtils.java
+++ b/plugins/org.eclipse.tigerstripe.workbench.headless/src/org/eclipse/tigerstripe/workbench/headless/GenerationUtils.java
@@ -1,64 +1,17 @@
package org.eclipse.tigerstripe.workbench.headless;
-import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IWorkspaceRunnable;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.tigerstripe.workbench.TigerstripeCore;
import org.eclipse.tigerstripe.workbench.TigerstripeException;
import org.eclipse.tigerstripe.workbench.generation.IM1RunConfig;
import org.eclipse.tigerstripe.workbench.generation.PluginRunStatus;
-import org.eclipse.tigerstripe.workbench.internal.core.generation.RunConfig;
import org.eclipse.tigerstripe.workbench.project.ITigerstripeModelProject;
public class GenerationUtils {
- public static void generate(IProject project) throws Exception {
- System.out.println("Validating " + project.getName());
- validateProject(project);
- System.out.println("Running generation on " + project.getName());
- generateTigerstripeOutput(project);
- }
-
- public static void validateProject(final IProject project) throws Exception {
+ public static void generateTigerstripeOutput(ITigerstripeModelProject project, IM1RunConfig runConfig)
+ throws TigerstripeException {
- final StringBuffer errorMsg = new StringBuffer();
- IWorkspaceRunnable checkForErrorsRunnable = new IWorkspaceRunnable() {
-
- public void run(IProgressMonitor monitor) throws CoreException {
-
- IMarker[] markers = project.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
- for (int i = 0; i < markers.length; i++) {
- if (IMarker.SEVERITY_ERROR == markers[i].getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO)) {
- String message = (String) markers[i].getAttribute(IMarker.MESSAGE);
- if (message.contains("Plugin execution not covered by lifecycle configuration")) {
- continue;
- }
- errorMsg.append("\n - ").append(markers[i].getResource().getProjectRelativePath().toString())
- .append(": ").append(message);
- }
- }
- }
- };
-
- ResourcesPlugin.getWorkspace().run(checkForErrorsRunnable, new NullProgressMonitor());
-
- if (errorMsg.length() > 0) {
- throw new TigerstripeException("Unable to perform generation. Project [" + project.getName()
- + "] contains errors: " + errorMsg.toString());
- }
- }
-
- public static void generateTigerstripeOutput(IProject project) throws TigerstripeException {
-
- ITigerstripeModelProject tsProject = (ITigerstripeModelProject) TigerstripeCore.findProject(project);
- IM1RunConfig config = (IM1RunConfig) RunConfig.newGenerationConfig(tsProject, RunConfig.M1);
- PluginRunStatus[] statuses = tsProject.generate(config, null);
+ PluginRunStatus[] statuses = project.generate(runConfig, null);
StringBuffer failedGenerators = new StringBuffer();
if (statuses.length != 0) {
for (PluginRunStatus pluginRunStatus : statuses) {
diff --git a/plugins/org.eclipse.tigerstripe.workbench.headless/src/org/eclipse/tigerstripe/workbench/headless/ProjectGenerationRunnable.java b/plugins/org.eclipse.tigerstripe.workbench.headless/src/org/eclipse/tigerstripe/workbench/headless/ProjectGenerationRunnable.java
deleted file mode 100644
index b6c95f1..0000000
--- a/plugins/org.eclipse.tigerstripe.workbench.headless/src/org/eclipse/tigerstripe/workbench/headless/ProjectGenerationRunnable.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package org.eclipse.tigerstripe.workbench.headless;
-
-import java.util.concurrent.Callable;
-
-import org.eclipse.core.resources.IProject;
-
-public class ProjectGenerationRunnable implements Callable<Boolean> {
-
- private IProject project;
-
- public ProjectGenerationRunnable(IProject project) {
- this.project = project;
- }
-
- public Boolean call() throws Exception {
- GenerationUtils.generate(project);
- return true;
- }
-}
diff --git a/plugins/org.eclipse.tigerstripe.workbench.headless/src/org/eclipse/tigerstripe/workbench/headless/Tigerstripe.java b/plugins/org.eclipse.tigerstripe.workbench.headless/src/org/eclipse/tigerstripe/workbench/headless/Tigerstripe.java
index 16fb783..d36677e 100644
--- a/plugins/org.eclipse.tigerstripe.workbench.headless/src/org/eclipse/tigerstripe/workbench/headless/Tigerstripe.java
+++ b/plugins/org.eclipse.tigerstripe.workbench.headless/src/org/eclipse/tigerstripe/workbench/headless/Tigerstripe.java
@@ -13,9 +13,11 @@
import java.io.File;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
+import org.apache.commons.lang3.StringUtils;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.equinox.app.IApplication;
@@ -44,10 +46,10 @@
public static final String GENERATE_PATH_ARG = "OUTPUT_DIR";
+ public static final String DISABLED_GENERATORS_ARG = "DISABLED_GENERATORS";
- public static int STYLE_PROJECT = 1;
-
- public static int STYLE_INSTALLED = 2;
+ public static final String ACTIVE_FACET_ARG = "ACTIVE_FACET";
+ public static final String IGNORE_FACET_ARG = "IGNORE_FACET";
private List<String> projects;
@@ -55,6 +57,11 @@
private String pathToGenerate = null;
+ private List<String> disabledGenerators = null;
+
+ private String activeFacet = null;
+ private boolean ignoreFacet = false;
+
private int numThreads = 8;
private ExecutorService threadPool;
@@ -65,79 +72,93 @@
System.out.println("Starting Tigerstripe...");
printTigerstipeVersionInfo();
- int style = setPluginParams(context);
+ setPluginParams(context);
+
+ PostInstallActions.init();
+ printProfile();
List<Throwable> exc = new ArrayList<Throwable>();
- if ( style == STYLE_PROJECT){
- try {
- PostInstallActions.init();
- printProfile();
+ List<GenerateTigerstripeModelRunnable> generationRunnables = new ArrayList<GenerateTigerstripeModelRunnable>();
+ if (!projects.isEmpty()) {
+ ImportProjectsRunnable op = new ImportProjectsRunnable(projects);
+ ResourcesPlugin.getWorkspace().run(op, null);
+ List<IProject> importedProjects = op.getImportedProjects();
+ for (IProject project : importedProjects) {
+ generationRunnables.add(new GenerateProjectRunnable(project));
+ }
+ }
+ if (!installedModuleIds.isEmpty() && !StringUtils.isEmpty(pathToGenerate)) {
+ File outputDir = new File(pathToGenerate);
+ for (String modelId : installedModuleIds) {
+ generationRunnables.add(new GenerateInstalledModuleRunnable(modelId, outputDir));
+ }
+ }
+ if (generationRunnables.isEmpty()) {
+ printUsage();
+ throw new TigerstripeException("Must provide at least one module project to generate.");
+ }
- ImportProjectsRunnable op = new ImportProjectsRunnable(projects);
- ResourcesPlugin.getWorkspace().run(op, null);
- List<IProject> importedProjects = op.getImportedProjects();
- // if (importedProjects.size() > 1 && numThreads > 1) {
- // int poolSize =
- // importedProjects.size() < numThreads ? importedProjects.size() : numThreads;
- // System.out.println("Running generation with " + String.valueOf(poolSize) + " threads.");
- // threadPool = Executors.newFixedThreadPool(poolSize);
- // }
-
- List<Future<Boolean>> threadedTasks = new ArrayList<Future<Boolean>>();
- int count = 1;
- for (IProject project : importedProjects) {
- if (threadPool != null) {
- System.out.println("Creating thread for project: " + project.getName());
- Future<Boolean> task = threadPool.submit(new ProjectGenerationRunnable(project));
- threadedTasks.add(task);
- } else {
- System.out.println("Starting on project " + count++ + "/" + importedProjects.size() + " - " + project.getName());
- GenerationUtils.generate(project);
- }
- }
+ File facet = null;
+ if (activeFacet != null) {
+ facet = new File(activeFacet);
+ }
+ for (GenerateTigerstripeModelRunnable runner : generationRunnables) {
+ runner.setDisabledGenerators(disabledGenerators);
+ if (ignoreFacet) {
+ runner.setIgnoreFacet(true);
+ } else if (facet != null && facet.exists()) {
+ runner.setFacet(facet);
+ }
+ }
+ // if (generationRunnables.size() > 1 && numThreads > 1) {
+ // int poolSize =
+ // generationRunnables.size() < numThreads ? generationRunnables.size()
+ // : numThreads;
+ // System.out.println("Running generation with " +
+ // String.valueOf(poolSize) + " threads.");
+ // threadPool = Executors.newFixedThreadPool(poolSize);
+ // }
+ try {
+ List<Future<Boolean>> threadedTasks = new ArrayList<Future<Boolean>>();
+ int count = 1;
+ for (Callable<Boolean> runner : generationRunnables) {
if (threadPool != null) {
- for (Future<Boolean> task : threadedTasks) {
- if (!exc.isEmpty()) {
- task.cancel(true);
- } else {
- try {
- task.get();
- } catch (Throwable e) {
- exc.add(e);
- e.printStackTrace();
- }
+ Future<Boolean> task = threadPool.submit(runner);
+ threadedTasks.add(task);
+ } else {
+ System.out.println("Starting on " + count++ + "/" + generationRunnables.size());
+ runner.call();
+ }
+ }
+ if (threadPool != null) {
+ for (Future<Boolean> task : threadedTasks) {
+ if (!exc.isEmpty()) {
+ task.cancel(true);
+ } else {
+ try {
+ task.get();
+ } catch (Throwable e) {
+ exc.add(e);
+ e.printStackTrace();
}
}
}
-
- } catch (Exception e) {
- e.printStackTrace();
- exc.add(e);
- } finally {
- if (threadPool != null) {
- threadPool.shutdown();
- }
- if (!exc.isEmpty()) {
- return 1;
- }
}
-
- long finish = System.currentTimeMillis();
- System.out.println("Generation complete. Took " + (finish - start) + " milliseconds.");
-
- return EXIT_OK;
-
- }
- if (style == STYLE_INSTALLED){
-
- GenerateInstalledModuleRunnable op = new GenerateInstalledModuleRunnable(installedModuleIds,pathToGenerate);
- ResourcesPlugin.getWorkspace().run(op, null);
-
- return EXIT_OK;
+ } catch (Exception e) {
+ e.printStackTrace();
+ exc.add(e);
+ } finally {
+ if (threadPool != null) {
+ threadPool.shutdown();
+ }
+ if (!exc.isEmpty()) {
+ return 1;
+ }
}
- //TODO - should be a better value to return if this does nothing??
+ long finish = System.currentTimeMillis();
+ System.out.println("Generation complete. Took " + (finish - start) + " milliseconds.");
return EXIT_OK;
}
@@ -146,76 +167,65 @@
+ TigerstripeCore.getRuntimeDetails().getBaseBundleValue(Constants.BUNDLE_VERSION) + ")");
}
- private int setPluginParams(IApplicationContext context) throws TigerstripeException {
+ private void setPluginParams(IApplicationContext context) throws TigerstripeException {
projects = new ArrayList<String>();
installedModuleIds = new ArrayList<String>();
+ disabledGenerators = new ArrayList<String>();
String[] split = new String[2];
String[] cmdLineArgs = (String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS);
for (String arg : cmdLineArgs) {
split = arg.split(DELIMITER);
String key = split[0];
- String[] values = split[1].split(VALUE_SEPARATOR);
-
- for (String value : values) {
- if (key.equals(IMPORT_PROJECT_ARG)) {
- projects.add(value);
- } else if (key.equals(INSTALLED_MODULE_ARG)){
- installedModuleIds.add(value);
- } else if (key.equals(GENERATE_PATH_ARG)){
- pathToGenerate = value;
- } else if (key.equals(GENERATION_THREADS_ARG)) {
- try {
- numThreads = Integer.valueOf(value);
- } catch (Exception e) {
- // Oh well, we tried
- System.err.println(
- "Could not parse the " + GENERATION_THREADS_ARG + " as a valid integer: " + value);
- e.printStackTrace();
+ if (split.length > 1) {
+ String[] values = split[1].split(VALUE_SEPARATOR);
+ for (String value : values) {
+ if (key.equals(IMPORT_PROJECT_ARG)) {
+ projects.add(value);
+ } else if (key.equals(INSTALLED_MODULE_ARG)) {
+ installedModuleIds.add(value);
+ } else if (key.equals(GENERATE_PATH_ARG)) {
+ pathToGenerate = value;
+ } else if (key.equals(GENERATION_THREADS_ARG)) {
+ try {
+ numThreads = Integer.valueOf(value);
+ } catch (Exception e) {
+ // Oh well, we tried
+ System.err.println(
+ "Could not parse the " + GENERATION_THREADS_ARG + " as a valid integer: " + value);
+ e.printStackTrace();
+ }
+ } else if (key.equals(DISABLED_GENERATORS_ARG)) {
+ disabledGenerators.add(value);
+ } else if (key.equals(ACTIVE_FACET_ARG)) {
+ activeFacet = value;
}
}
+ } else {
+ if (key.equals(IGNORE_FACET_ARG)) {
+ ignoreFacet = true;
+ }
}
}
-
- // We have two styles :
-
- // A with projects
- // B with a module and a path
- if (projects.isEmpty()) {
- if (!isValidModuleStyle()){
- throw new TigerstripeException("Must have at least one generation project defined OR specify moduleId(s) AND a path(that must exist).");
- } else {
- return STYLE_INSTALLED;
- }
- } else {
- return STYLE_PROJECT;
- }
-
}
- private boolean isValidModuleStyle(){
- if (installedModuleIds.isEmpty()){
- return false;
- }
-
- if (pathToGenerate == null || pathToGenerate.trim().length() == 0){
- return false;
- }
-
- File outDir = new File(pathToGenerate);
- if (! outDir.exists() || ! outDir.isDirectory()){
- return false;
- }
-
- return true;
- }
-
-
private void printProfile() {
IWorkbenchProfileSession profileSession = TigerstripeCore.getWorkbenchProfileSession();
System.out.println("Active Profile: " + profileSession.getActiveProfile().getName() + " "
+ profileSession.getActiveProfile().getVersion());
}
+ private void printUsage() {
+ System.out.println("Usage:");
+ System.out.println("\tTo generate a model project:");
+ System.out.println("\t - Use " + IMPORT_PROJECT_ARG
+ + " argument with comma separated list to the full path of the project to import and generate.");
+ System.out.println("\tTo regenerate an installed model JAR:");
+ System.out.println("\t - Use " + INSTALLED_MODULE_ARG
+ + " argument with comma separated list of the model ID's to regenerate.");
+ System.out.println("\t - Use " + GENERATE_PATH_ARG
+ + " argument to specify the path for the regenerated sources to be output to. The model ID of each model being regenerated will be appended to this path.");
+ }
+
public void stop() {
System.out.println("Stopping");
}