From 9e3ccaeb444382abe38ffc5a14f2e62a95b6432c Mon Sep 17 00:00:00 2001 From: rfeng Date: Tue, 23 Mar 2010 16:59:14 +0000 Subject: An eclipse plugin that can run in headless mode to configure the eclipse workspace using command line git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@926662 13f79535-47bb-0310-9956-ffa450edef68 --- sandbox/rfeng/eclipse-workspace-feature/.project | 17 ++ .../eclipse-workspace-feature/build.properties | 1 + .../rfeng/eclipse-workspace-feature/feature.xml | 27 ++ .../rfeng/eclipse-workspace-updatesite/.project | 17 ++ .../rfeng/eclipse-workspace-updatesite/index.html | 60 ++++ .../rfeng/eclipse-workspace-updatesite/site.xml | 10 + .../eclipse-workspace-updatesite/web/site.css | 12 + .../eclipse-workspace-updatesite/web/site.xsl | 214 ++++++++++++++ sandbox/rfeng/eclipse-workspace/.classpath | 7 + sandbox/rfeng/eclipse-workspace/.project | 28 ++ .../.settings/org.eclipse.jdt.core.prefs | 8 + .../rfeng/eclipse-workspace/META-INF/MANIFEST.MF | 14 + sandbox/rfeng/eclipse-workspace/build.properties | 5 + sandbox/rfeng/eclipse-workspace/plugin.xml | 32 +++ .../tuscany/eclipse/workspace/Activator.java | 60 ++++ .../eclipse/workspace/WorkspaceConfigurator.java | 312 +++++++++++++++++++++ 16 files changed, 824 insertions(+) create mode 100644 sandbox/rfeng/eclipse-workspace-feature/.project create mode 100644 sandbox/rfeng/eclipse-workspace-feature/build.properties create mode 100644 sandbox/rfeng/eclipse-workspace-feature/feature.xml create mode 100644 sandbox/rfeng/eclipse-workspace-updatesite/.project create mode 100644 sandbox/rfeng/eclipse-workspace-updatesite/index.html create mode 100644 sandbox/rfeng/eclipse-workspace-updatesite/site.xml create mode 100644 sandbox/rfeng/eclipse-workspace-updatesite/web/site.css create mode 100644 sandbox/rfeng/eclipse-workspace-updatesite/web/site.xsl create mode 100644 sandbox/rfeng/eclipse-workspace/.classpath create mode 100644 sandbox/rfeng/eclipse-workspace/.project create mode 100644 sandbox/rfeng/eclipse-workspace/.settings/org.eclipse.jdt.core.prefs create mode 100644 sandbox/rfeng/eclipse-workspace/META-INF/MANIFEST.MF create mode 100644 sandbox/rfeng/eclipse-workspace/build.properties create mode 100644 sandbox/rfeng/eclipse-workspace/plugin.xml create mode 100644 sandbox/rfeng/eclipse-workspace/src/main/java/org/apache/tuscany/eclipse/workspace/Activator.java create mode 100644 sandbox/rfeng/eclipse-workspace/src/main/java/org/apache/tuscany/eclipse/workspace/WorkspaceConfigurator.java (limited to 'sandbox/rfeng') diff --git a/sandbox/rfeng/eclipse-workspace-feature/.project b/sandbox/rfeng/eclipse-workspace-feature/.project new file mode 100644 index 0000000000..c74995953f --- /dev/null +++ b/sandbox/rfeng/eclipse-workspace-feature/.project @@ -0,0 +1,17 @@ + + + tuscany-eclipse-workspace-feature + + + + + + org.eclipse.pde.FeatureBuilder + + + + + + org.eclipse.pde.FeatureNature + + diff --git a/sandbox/rfeng/eclipse-workspace-feature/build.properties b/sandbox/rfeng/eclipse-workspace-feature/build.properties new file mode 100644 index 0000000000..64f93a9f0b --- /dev/null +++ b/sandbox/rfeng/eclipse-workspace-feature/build.properties @@ -0,0 +1 @@ +bin.includes = feature.xml diff --git a/sandbox/rfeng/eclipse-workspace-feature/feature.xml b/sandbox/rfeng/eclipse-workspace-feature/feature.xml new file mode 100644 index 0000000000..b9664685ea --- /dev/null +++ b/sandbox/rfeng/eclipse-workspace-feature/feature.xml @@ -0,0 +1,27 @@ + + + + + [Enter Feature Description here.] + + + + [Enter Copyright Description here.] + + + + [Enter License Description here.] + + + + + diff --git a/sandbox/rfeng/eclipse-workspace-updatesite/.project b/sandbox/rfeng/eclipse-workspace-updatesite/.project new file mode 100644 index 0000000000..a4ec08e86c --- /dev/null +++ b/sandbox/rfeng/eclipse-workspace-updatesite/.project @@ -0,0 +1,17 @@ + + + tuscany-eclipse-workspace-updatesite + + + + + + org.eclipse.pde.UpdateSiteBuilder + + + + + + org.eclipse.pde.UpdateSiteNature + + diff --git a/sandbox/rfeng/eclipse-workspace-updatesite/index.html b/sandbox/rfeng/eclipse-workspace-updatesite/index.html new file mode 100644 index 0000000000..c483c912d3 --- /dev/null +++ b/sandbox/rfeng/eclipse-workspace-updatesite/index.html @@ -0,0 +1,60 @@ + + +tuscany-eclipse-workspace-updatesite + + + + + + +
+ + diff --git a/sandbox/rfeng/eclipse-workspace-updatesite/site.xml b/sandbox/rfeng/eclipse-workspace-updatesite/site.xml new file mode 100644 index 0000000000..5c073248fe --- /dev/null +++ b/sandbox/rfeng/eclipse-workspace-updatesite/site.xml @@ -0,0 +1,10 @@ + + + + Apache Tuscany Headless Eclipse Workspace Configurator Update Site + + + + + + diff --git a/sandbox/rfeng/eclipse-workspace-updatesite/web/site.css b/sandbox/rfeng/eclipse-workspace-updatesite/web/site.css new file mode 100644 index 0000000000..425134ee31 --- /dev/null +++ b/sandbox/rfeng/eclipse-workspace-updatesite/web/site.css @@ -0,0 +1,12 @@ + diff --git a/sandbox/rfeng/eclipse-workspace-updatesite/web/site.xsl b/sandbox/rfeng/eclipse-workspace-updatesite/web/site.xsl new file mode 100644 index 0000000000..0b7e5f5a44 --- /dev/null +++ b/sandbox/rfeng/eclipse-workspace-updatesite/web/site.xsl @@ -0,0 +1,214 @@ + + + + + + + + tuscany-eclipse-workspace-updatesite + + + +

tuscany-eclipse-workspace-updatesite

+

+ + + + + + + + + + + + + + + + dark-row + + + light-row + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + dark-row + + + light-row + + + + + + + + + + + + + + + dark-row + + + light-row + + + + + + + + +
+ + + +
+ + + +
+
+ ( - ) +
+
+ + - + +
+
+
+ + + + + + + + + + + + + + + + + + + + + +
Operating Systems:
Windows Systems:
Languages:
Architecture:
+


+ Uncategorized +
+ + + +
+
+ ( - ) +
+
+ + - + +
+

+
+ + + + + + + + + + + + + + + + + + + + + +
Operating Systems:
Windows Systems:
Languages:
Architecture:
+
+ + + +
+
+ ( - ) +
+
+ + - + +
+

+
+ + + + + + + + + + + + + + + + + + + + + +
Operating Systems:
Windows Systems:
Languages:
Architecture:
+
+ + +
+
+
diff --git a/sandbox/rfeng/eclipse-workspace/.classpath b/sandbox/rfeng/eclipse-workspace/.classpath new file mode 100644 index 0000000000..eff0df67e2 --- /dev/null +++ b/sandbox/rfeng/eclipse-workspace/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/sandbox/rfeng/eclipse-workspace/.project b/sandbox/rfeng/eclipse-workspace/.project new file mode 100644 index 0000000000..4e85a9a074 --- /dev/null +++ b/sandbox/rfeng/eclipse-workspace/.project @@ -0,0 +1,28 @@ + + + tuscany-eclipse-workspace + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/sandbox/rfeng/eclipse-workspace/.settings/org.eclipse.jdt.core.prefs b/sandbox/rfeng/eclipse-workspace/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..4a0c7d9b39 --- /dev/null +++ b/sandbox/rfeng/eclipse-workspace/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Mon Mar 22 14:57:37 PDT 2010 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/sandbox/rfeng/eclipse-workspace/META-INF/MANIFEST.MF b/sandbox/rfeng/eclipse-workspace/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..faf26edd65 --- /dev/null +++ b/sandbox/rfeng/eclipse-workspace/META-INF/MANIFEST.MF @@ -0,0 +1,14 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: org.apache.tuscany.eclipse.workspace +Bundle-SymbolicName: org.apache.tuscany.eclipse.workspace;singleton:=true +Bundle-Version: 1.0.0 +Bundle-Activator: org.apache.tuscany.eclipse.workspace.Activator +Bundle-Vendor: Apache Software Foundation +Require-Bundle: org.eclipse.core.runtime, + org.eclipse.jdt.core, + org.eclipse.jdt.launching, + org.eclipse.pde.core, + org.eclipse.core.resources +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-ActivationPolicy: lazy diff --git a/sandbox/rfeng/eclipse-workspace/build.properties b/sandbox/rfeng/eclipse-workspace/build.properties new file mode 100644 index 0000000000..7b6db787bd --- /dev/null +++ b/sandbox/rfeng/eclipse-workspace/build.properties @@ -0,0 +1,5 @@ +source.. = src/main/java/ +output.. = target/classes/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/sandbox/rfeng/eclipse-workspace/plugin.xml b/sandbox/rfeng/eclipse-workspace/plugin.xml new file mode 100644 index 0000000000..5b9a6c032a --- /dev/null +++ b/sandbox/rfeng/eclipse-workspace/plugin.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + diff --git a/sandbox/rfeng/eclipse-workspace/src/main/java/org/apache/tuscany/eclipse/workspace/Activator.java b/sandbox/rfeng/eclipse-workspace/src/main/java/org/apache/tuscany/eclipse/workspace/Activator.java new file mode 100644 index 0000000000..c0095686f8 --- /dev/null +++ b/sandbox/rfeng/eclipse-workspace/src/main/java/org/apache/tuscany/eclipse/workspace/Activator.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.eclipse.workspace; + +import org.eclipse.core.runtime.Plugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends Plugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.apache.tuscany.eclipse.workspace"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + +} diff --git a/sandbox/rfeng/eclipse-workspace/src/main/java/org/apache/tuscany/eclipse/workspace/WorkspaceConfigurator.java b/sandbox/rfeng/eclipse-workspace/src/main/java/org/apache/tuscany/eclipse/workspace/WorkspaceConfigurator.java new file mode 100644 index 0000000000..fcdd484939 --- /dev/null +++ b/sandbox/rfeng/eclipse-workspace/src/main/java/org/apache/tuscany/eclipse/workspace/WorkspaceConfigurator.java @@ -0,0 +1,312 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.eclipse.workspace; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; + +import javax.xml.parsers.ParserConfigurationException; + +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.jobs.IJobChangeEvent; +import org.eclipse.core.runtime.jobs.IJobChangeListener; +import org.eclipse.core.runtime.jobs.JobChangeAdapter; +import org.eclipse.equinox.app.IApplication; +import org.eclipse.equinox.app.IApplicationContext; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.launching.IVMInstall; +import org.eclipse.jdt.launching.JavaRuntime; +import org.eclipse.pde.internal.core.PDECore; +import org.eclipse.pde.internal.core.target.TargetDefinitionPersistenceHelper; +import org.eclipse.pde.internal.core.target.provisional.ITargetHandle; +import org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService; +import org.eclipse.pde.internal.core.target.provisional.LoadTargetDefinitionJob; +import org.xml.sax.SAXException; + +@SuppressWarnings("restriction") +public class WorkspaceConfigurator implements IApplication { + private static final String SOURCE_ROOT = "source.root"; + private static final String TARGET_DEFINITION = "target.definition"; + private static final String MAVEN_LOCAL_REPO = "maven.repo"; + private static final String M2_REPO = "M2_REPO"; + + private IWorkspace workspace; + private final Object lock = new Object(); + + public Object start(final IApplicationContext appcontext) throws Exception { + IProgressMonitor monitor = createMonitor(); + final String[] args = (String[])appcontext.getArguments().get(IApplicationContext.APPLICATION_ARGS); + setM2REPOClassPathVariable(args, monitor); + setTargetPlatform(args); + + // Wait for the target platform job is done + synchronized (lock) { + lock.wait(); + } + configureWorkspace(args, monitor); + return EXIT_OK; + } + + private void setTargetPlatform(String args[]) throws FileNotFoundException, CoreException, + ParserConfigurationException, SAXException, IOException { + String targetFile = getOptionValue(args, TARGET_DEFINITION); + if (targetFile == null) { + return; + } + File tf = new File(targetFile).getAbsoluteFile(); + print("Setting target platform: " + tf); + ITargetPlatformService tps = + (ITargetPlatformService)PDECore.getDefault().acquireService(ITargetPlatformService.class.getName()); + ITargetHandle th = tps.getTarget(tf.toURI()); + FileInputStream is = new FileInputStream(tf); + try { + TargetDefinitionPersistenceHelper.initFromXML(th.getTargetDefinition(), is); + } finally { + is.close(); + } + IJobChangeListener jobListener = new JobChangeAdapter() { + + @Override + public void done(IJobChangeEvent event) { + super.done(event); + synchronized (lock) { + print("Target platform is configured: " + event.getResult()); + lock.notifyAll(); + } + } + + }; + LoadTargetDefinitionJob.load(th.getTargetDefinition(), jobListener); + } + + private IProgressMonitor createMonitor() { + return new NullProgressMonitor() { + + @Override + public void beginTask(String name, int totalWork) { + } + + @Override + public void done() { + // System.out.println(); + } + + @Override + public void worked(int work) { + // System.out.print("."); + } + }; + } + + private IPath setM2REPOClassPathVariable(String args[], IProgressMonitor monitor) throws JavaModelException { + IPath var = JavaCore.getClasspathVariable(M2_REPO); + if (var == null) { + String localRepo = getOptionValue(args, MAVEN_LOCAL_REPO); + if (localRepo == null) { + String home = System.getProperty("user.home"); + localRepo = home + File.separator + ".m2" + File.separator + "repository"; + } + File repo = new File(localRepo); + IPath path = new Path(repo.getAbsolutePath()); + JavaCore.setClasspathVariable(M2_REPO, path, monitor); + return path; + } + return var; + } + + private void configureWorkspace(final String[] args, IProgressMonitor monitor) throws Exception, CoreException { + this.workspace = ResourcesPlugin.getWorkspace(); + + String sourceRootArg = getOptionValue(args, SOURCE_ROOT); + File sourceRoot = null; + if (sourceRootArg != null) { + sourceRoot = new File(sourceRootArg); + } + + configureJDT(); + + if (sourceRoot != null) { + importProjects(sourceRoot, monitor); + } + + // cleanProjects(monitor); + buildWorkspace(monitor); + + workspace.save(true, monitor); + } + + private String getOptionValue(final String[] args, String option) { + String value = null; + if (args != null) { + List argList = Arrays.asList(args); + int index = argList.indexOf("-" + option); + if (index != -1 && argList.size() - 1 >= index + 1) { + value = argList.get(index + 1); + } + } + return value; + } + + public void stop() { + this.workspace = null; + } + + private void importProjects(File sourceRoot, final IProgressMonitor monitor) throws Exception { + IWorkspaceRoot workspaceRoot = workspace.getRoot(); + + loadProjects(sourceRoot, monitor); + + for (IProject p : workspaceRoot.getProjects()) { + if (!p.isOpen()) { + // Open the project + p.open(monitor); + } else { + // Refresh the project + p.refreshLocal(IResource.DEPTH_INFINITE, monitor); + } + if (p.getFile(".project") == null) { + print("Deleting project: " + p.getName()); + p.delete(false, true, monitor); + } + } + + } + + @SuppressWarnings("unchecked") + private void configureJDT() { + Hashtable options = JavaCore.getOptions(); + options.put(JavaCore.CORE_CIRCULAR_CLASSPATH, JavaCore.ERROR); + options.put(JavaCore.CORE_INCOMPLETE_CLASSPATH, JavaCore.WARNING); + JavaCore.setOptions(options); + + IVMInstall vminstall = JavaRuntime.getDefaultVMInstall(); + if (!vminstall.getName().equals("Default JRE")) { + vminstall.setName("Default JRE"); + } + } + + private void loadProjects(File sourceRoot, final IProgressMonitor monitor) throws CoreException { + if (sourceRoot.isDirectory()) { + File dotProject = new File(sourceRoot, ".project"); + if (dotProject.exists() && dotProject.isFile()) { + IPath path = new Path(dotProject.getAbsolutePath()); + IProjectDescription project = workspace.loadProjectDescription(path); + IProject p = workspace.getRoot().getProject(project.getName()); + if (!p.exists()) { + print("Importing project: " + project.getName()); + p.create(project, monitor); + } + } + } else { + return; + } + + File[] dirs = sourceRoot.listFiles(); + if (dirs == null) { + return; + } + + for (int i = 0; i < dirs.length; i++) { + if (dirs[i].isDirectory()) { + loadProjects(dirs[i], monitor); + } + } + } + + private void buildWorkspace(IProgressMonitor monitor) throws Exception { + print("Running a full build..."); + workspace.build(IncrementalProjectBuilder.FULL_BUILD, monitor); + + reportErrors(); + } + + private void reportErrors() throws CoreException { + int errorCount = 0; + print(); + IProject[] projects = workspace.getRoot().getProjects(); + HashMap> errors = new HashMap>(); + for (IProject p : projects) { + IMarker[] markers = p.findMarkers(null, true, IResource.DEPTH_INFINITE); + for (int m = 0; m < markers.length; m++) { + IMarker marker = markers[m]; + int severity = marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO); + if (severity == IMarker.SEVERITY_ERROR) { + List list = errors.get(p.getName()); + if (list == null) { + list = new ArrayList(); + errors.put(p.getName(), list); + } + list.add(marker); + reportError(marker); + errorCount++; + } + } + } + + Iterator it = errors.keySet().iterator(); + while (it.hasNext()) { + String project = it.next(); + List list = errors.get(project); + print("Project " + project + " has " + list.size() + " errors."); + } + print(); + + if (errorCount > 0) { + print("The build is completed with " + errorCount + " errors."); + } else { + print("The build is completed successfully."); + } + print(); + } + + private void reportError(IMarker marker) throws CoreException { + print("Error: " + marker.getResource() + + ":" + + marker.getAttribute(IMarker.LINE_NUMBER, 0) + + ": " + + marker.getAttribute(IMarker.MESSAGE)); + } + + private void print(Object... msgs) { + for (Object msg : msgs) { + System.out.println(msg); + } + } +} -- cgit v1.2.3