From 50bba7b9e073c66068bad31685d1c6040c99f00e Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Fri, 19 Sep 2014 14:09:49 +0400 Subject: [PATCH] First version of m2e-plugin: https://github.com/konsoletyper/teavm/issues/5 --- .../teavm-eclipse-m2e-plugin/.classpath | 7 ++ .../teavm-eclipse-m2e-plugin/.gitignore | 1 + .../teavm-eclipse-m2e-plugin/.project | 28 +++++ .../.settings/org.eclipse.jdt.core.prefs | 7 ++ .../META-INF/MANIFEST.MF | 13 +++ .../teavm-eclipse-m2e-plugin/build.properties | 6 ++ .../lifecycle-mapping-metadata.xml | 20 ++++ .../teavm-eclipse-m2e-plugin/plugin.xml | 26 +++++ .../eclipse/m2e/TeaVMProjectConfigurator.java | 101 ++++++++++++++++++ .../teavm-eclipse-m2e-plugin/src/plugin.xml | 19 ++++ .../teavm-eclipse-plugin/META-INF/MANIFEST.MF | 2 +- 11 files changed, 229 insertions(+), 1 deletion(-) create mode 100644 teavm-eclipse/teavm-eclipse-m2e-plugin/.classpath create mode 100644 teavm-eclipse/teavm-eclipse-m2e-plugin/.gitignore create mode 100644 teavm-eclipse/teavm-eclipse-m2e-plugin/.project create mode 100644 teavm-eclipse/teavm-eclipse-m2e-plugin/.settings/org.eclipse.jdt.core.prefs create mode 100644 teavm-eclipse/teavm-eclipse-m2e-plugin/META-INF/MANIFEST.MF create mode 100644 teavm-eclipse/teavm-eclipse-m2e-plugin/build.properties create mode 100644 teavm-eclipse/teavm-eclipse-m2e-plugin/lifecycle-mapping-metadata.xml create mode 100644 teavm-eclipse/teavm-eclipse-m2e-plugin/plugin.xml create mode 100644 teavm-eclipse/teavm-eclipse-m2e-plugin/src/main/java/org/teavm/eclipse/m2e/TeaVMProjectConfigurator.java create mode 100644 teavm-eclipse/teavm-eclipse-m2e-plugin/src/plugin.xml diff --git a/teavm-eclipse/teavm-eclipse-m2e-plugin/.classpath b/teavm-eclipse/teavm-eclipse-m2e-plugin/.classpath new file mode 100644 index 000000000..e493a86d4 --- /dev/null +++ b/teavm-eclipse/teavm-eclipse-m2e-plugin/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/teavm-eclipse/teavm-eclipse-m2e-plugin/.gitignore b/teavm-eclipse/teavm-eclipse-m2e-plugin/.gitignore new file mode 100644 index 000000000..ea8c4bf7f --- /dev/null +++ b/teavm-eclipse/teavm-eclipse-m2e-plugin/.gitignore @@ -0,0 +1 @@ +/target diff --git a/teavm-eclipse/teavm-eclipse-m2e-plugin/.project b/teavm-eclipse/teavm-eclipse-m2e-plugin/.project new file mode 100644 index 000000000..778192415 --- /dev/null +++ b/teavm-eclipse/teavm-eclipse-m2e-plugin/.project @@ -0,0 +1,28 @@ + + + teavm-eclipse-m2e-plugin + + + + + + 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/teavm-eclipse/teavm-eclipse-m2e-plugin/.settings/org.eclipse.jdt.core.prefs b/teavm-eclipse/teavm-eclipse-m2e-plugin/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..f42de363a --- /dev/null +++ b/teavm-eclipse/teavm-eclipse-m2e-plugin/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/teavm-eclipse/teavm-eclipse-m2e-plugin/META-INF/MANIFEST.MF b/teavm-eclipse/teavm-eclipse-m2e-plugin/META-INF/MANIFEST.MF new file mode 100644 index 000000000..5f523a57c --- /dev/null +++ b/teavm-eclipse/teavm-eclipse-m2e-plugin/META-INF/MANIFEST.MF @@ -0,0 +1,13 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Teavm-eclipse-m2e-plugin +Bundle-SymbolicName: org.teavm.eclipse.m2e;singleton:=true +Bundle-Version: 0.2.0.qualifier +Bundle-Vendor: Alexey Andreev +Bundle-RequiredExecutionEnvironment: JavaSE-1.7 +Require-Bundle: org.teavm.eclipse;bundle-version="[0.2,0.3)", + org.eclipse.m2e.core;bundle-version="[1.3,2)", + org.eclipse.core.runtime;bundle-version="[3.8.0,4.0)", + org.eclipse.m2e.maven.runtime;bundle-version="[1.3,2)", + org.eclipse.core.resources;bundle-version="[3.6,4)", + org.eclipse.ui;bundle-version="[3.6,4.0)" diff --git a/teavm-eclipse/teavm-eclipse-m2e-plugin/build.properties b/teavm-eclipse/teavm-eclipse-m2e-plugin/build.properties new file mode 100644 index 000000000..33e7a5cff --- /dev/null +++ b/teavm-eclipse/teavm-eclipse-m2e-plugin/build.properties @@ -0,0 +1,6 @@ +source.. = src/main/java/ +output.. = target/ +bin.includes = plugin.xml,\ + META-INF/,\ + .,\ + lifecycle-mapping-metadata.xml diff --git a/teavm-eclipse/teavm-eclipse-m2e-plugin/lifecycle-mapping-metadata.xml b/teavm-eclipse/teavm-eclipse-m2e-plugin/lifecycle-mapping-metadata.xml new file mode 100644 index 000000000..141c937e7 --- /dev/null +++ b/teavm-eclipse/teavm-eclipse-m2e-plugin/lifecycle-mapping-metadata.xml @@ -0,0 +1,20 @@ + + + + + + org.teavm + teavm-maven-plugin + 0.2.0-SNAPSHOT + + build-javascript + + + + + org.teavm.eclipse.m2e.teaVMConfigurator + + + + + \ No newline at end of file diff --git a/teavm-eclipse/teavm-eclipse-m2e-plugin/plugin.xml b/teavm-eclipse/teavm-eclipse-m2e-plugin/plugin.xml new file mode 100644 index 000000000..48fac8dbc --- /dev/null +++ b/teavm-eclipse/teavm-eclipse-m2e-plugin/plugin.xml @@ -0,0 +1,26 @@ + + + + + + + + + + diff --git a/teavm-eclipse/teavm-eclipse-m2e-plugin/src/main/java/org/teavm/eclipse/m2e/TeaVMProjectConfigurator.java b/teavm-eclipse/teavm-eclipse-m2e-plugin/src/main/java/org/teavm/eclipse/m2e/TeaVMProjectConfigurator.java new file mode 100644 index 000000000..e4e398aff --- /dev/null +++ b/teavm-eclipse/teavm-eclipse-m2e-plugin/src/main/java/org/teavm/eclipse/m2e/TeaVMProjectConfigurator.java @@ -0,0 +1,101 @@ +package org.teavm.eclipse.m2e; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import org.apache.maven.plugin.MojoExecution; +import org.apache.maven.project.MavenProject; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.embedder.IMaven; +import org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator; +import org.eclipse.m2e.core.project.configurator.ProjectConfigurationRequest; +import org.teavm.eclipse.TeaVMEclipsePlugin; +import org.teavm.eclipse.TeaVMProfile; +import org.teavm.eclipse.TeaVMProjectSettings; + +/** + * + * @author Alexey Andreev + */ +public class TeaVMProjectConfigurator extends AbstractProjectConfigurator { + private static final String TEAVM_ARTIFACT_ID = "teavm-maven-plugin"; + private static final String TEAVM_GROUP_ID = "org.teavm"; + private static final String TEAVM_MAIN_GOAL = "build-javascript"; + private int executionIdGenerator; + private Set usedExecutionIds = new HashSet<>(); + private IMaven maven; + private MavenProject mavenProject; + + @Override + public void configure(ProjectConfigurationRequest configurationRequest, IProgressMonitor monitor) + throws CoreException { + maven = MavenPlugin.getMaven(); + mavenProject = configurationRequest.getMavenProject(); + List executions = configurationRequest.getMavenProjectFacade().getMojoExecutions( + TEAVM_GROUP_ID, TEAVM_ARTIFACT_ID, monitor, TEAVM_MAIN_GOAL); + TeaVMEclipsePlugin teaVMPlugin = TeaVMEclipsePlugin.getDefault(); + IProject project = configurationRequest.getProject(); + boolean hasNature = project.hasNature(TeaVMEclipsePlugin.NATURE_ID); + int sz = executions.size(); + if (!hasNature) { + ++sz; + } + monitor.beginTask("Configuring TeaVM builder", sz * 1000); + TeaVMProjectSettings settings = teaVMPlugin.getSettings(project); + settings.load(); + try { + for (MojoExecution execution : executions) { + if (monitor.isCanceled()) { + return; + } + String profileId = getIdForProfile(execution); + TeaVMProfile profile = settings.getProfile(profileId); + if (profile == null) { + profile = settings.createProfile(); + profile.setName(profileId); + } + configureProfile(execution, profile, new SubProgressMonitor(monitor, 1000)); + if (monitor.isCanceled()) { + return; + } + } + if (!hasNature) { + teaVMPlugin.addNature(new SubProgressMonitor(monitor, 1000), project); + } + settings.save(); + } finally { + monitor.done(); + } + } + + private void configureProfile(MojoExecution execution, TeaVMProfile profile, IProgressMonitor monitor) + throws CoreException { + monitor.beginTask("Configuring profile " + profile.getName(), 30); + String mainClass = maven.getMojoParameterValue(mavenProject, execution, "mainClass", String.class, + new SubProgressMonitor(monitor, 10)); + profile.setMainClass(mainClass); + String targetDir = maven.getMojoParameterValue(mavenProject, execution, "targetDirectory", String.class, + new SubProgressMonitor(monitor, 10)); + profile.setTargetDirectory(targetDir); + String targetFileName = maven.getMojoParameterValue(mavenProject, execution, "targetFileName", String.class, + new SubProgressMonitor(monitor, 10)); + profile.setTargetFileName(targetFileName != null ? targetFileName : "classes.js"); + monitor.done(); + } + + private String getIdForProfile(MojoExecution pluginExecution) { + String executionId = pluginExecution.getExecutionId(); + if (executionId != null && usedExecutionIds.add(executionId)) { + return executionId; + } + String id; + do { + id = "maven-" + executionIdGenerator++; + } while (!usedExecutionIds.add(id)); + return id; + } +} diff --git a/teavm-eclipse/teavm-eclipse-m2e-plugin/src/plugin.xml b/teavm-eclipse/teavm-eclipse-m2e-plugin/src/plugin.xml new file mode 100644 index 000000000..58ddd5620 --- /dev/null +++ b/teavm-eclipse/teavm-eclipse-m2e-plugin/src/plugin.xml @@ -0,0 +1,19 @@ + + + + + diff --git a/teavm-eclipse/teavm-eclipse-plugin/META-INF/MANIFEST.MF b/teavm-eclipse/teavm-eclipse-plugin/META-INF/MANIFEST.MF index 4ca24ca16..53c693e2e 100644 --- a/teavm-eclipse/teavm-eclipse-plugin/META-INF/MANIFEST.MF +++ b/teavm-eclipse/teavm-eclipse-plugin/META-INF/MANIFEST.MF @@ -59,5 +59,5 @@ Bundle-ClassPath: ., lib/gson-2.2.4.jar, lib/teavm-classlib-0.2-SNAPSHOT.jar, lib/teavm-platform-0.2-SNAPSHOT.jar -Export-Package: org.teavm.eclipse.debugger +Export-Package: org.teavm.eclipse.debugger,org.teavm.eclipse Bundle-ActivationPolicy: lazy