-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved maven integration with test projects.
- Loading branch information
1 parent
e874119
commit 9376c87
Showing
27 changed files
with
1,198 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,15 +15,23 @@ | |
|
||
import java.io.File; | ||
import java.lang.reflect.Field; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.net.URLClassLoader; | ||
import java.util.Collection; | ||
import java.util.LinkedHashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.StringTokenizer; | ||
|
||
import org.apache.maven.artifact.Artifact; | ||
import org.apache.maven.artifact.DependencyResolutionRequiredException; | ||
import org.apache.maven.model.Dependency; | ||
import org.apache.maven.plugin.AbstractMojo; | ||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugin.MojoFailureException; | ||
import org.apache.maven.plugin.logging.Log; | ||
import org.apache.maven.project.MavenProject; | ||
import org.eclipse.acceleo.common.internal.utils.AcceleoPackageRegistry; | ||
import org.eclipse.acceleo.internal.parser.compiler.AcceleoParser; | ||
import org.eclipse.acceleo.internal.parser.compiler.AcceleoProjectClasspathEntry; | ||
|
@@ -38,11 +46,19 @@ | |
* | ||
* @goal acceleo-compile | ||
* @phase compile | ||
* @requiresDependencyResolution runtime | ||
* @author <a href="mailto:[email protected]">Stephane Begaudeau</a> | ||
* @since 3.2 | ||
*/ | ||
public class AcceleoParserMojo extends AbstractMojo { | ||
|
||
/** | ||
* @parameter expression="${project}" | ||
* @required | ||
* @readonly | ||
*/ | ||
private MavenProject project; | ||
|
||
/** | ||
* Indicates if we are compiling the Acceleo modules as binary resources. | ||
* | ||
|
@@ -74,39 +90,49 @@ public class AcceleoParserMojo extends AbstractMojo { | |
*/ | ||
public void execute() throws MojoExecutionException, MojoFailureException { | ||
Log log = getLog(); | ||
log.info("ACCELEO MAVEN STAND ALONE BUILD"); | ||
log.info("Acceleo maven stand alone build..."); | ||
|
||
log.info("Registering packages..."); | ||
log.info("Starting packages registration..."); | ||
for (String packageToRegister : this.packagesToRegister) { | ||
try { | ||
Class<?> forName = Class.forName(packageToRegister); | ||
List<?> runtimeClasspathElements = project.getRuntimeClasspathElements(); | ||
URL[] runtimeUrls = new URL[runtimeClasspathElements.size()]; | ||
for (int i = 0; i < runtimeClasspathElements.size(); i++) { | ||
String element = (String)runtimeClasspathElements.get(i); | ||
runtimeUrls[i] = new File(element).toURI().toURL(); | ||
} | ||
URLClassLoader newLoader = new URLClassLoader(runtimeUrls, Thread.currentThread() | ||
.getContextClassLoader()); | ||
|
||
Class<?> forName = Class.forName(packageToRegister, true, newLoader); | ||
Field nsUri = forName.getField("eNS_URI"); | ||
Field eInstance = forName.getField("eINSTANCE"); | ||
|
||
Object newInstance = forName.newInstance(); | ||
Object nsURIInvoked = nsUri.get(newInstance); | ||
Object nsURIInvoked = nsUri.get(null); | ||
if (nsURIInvoked instanceof String) { | ||
log.info("Registering package '" + packageToRegister + "'."); | ||
AcceleoPackageRegistry.INSTANCE.put((String)nsURIInvoked, eInstance.get(newInstance)); | ||
AcceleoPackageRegistry.INSTANCE.put((String)nsURIInvoked, eInstance.get(null)); | ||
} else { | ||
log.error("The URI field is not a string."); | ||
} | ||
|
||
} catch (ClassNotFoundException e) { | ||
log.error(e); | ||
} catch (InstantiationException e) { | ||
log.error(e); | ||
} catch (IllegalAccessException e) { | ||
log.error(e); | ||
} catch (SecurityException e) { | ||
log.error(e); | ||
} catch (NoSuchFieldException e) { | ||
log.error(e); | ||
} catch (DependencyResolutionRequiredException e) { | ||
log.error(e); | ||
} catch (MalformedURLException e) { | ||
log.error(e); | ||
} | ||
|
||
} | ||
|
||
log.info("Starting the build sequence..."); | ||
log.info("Starting the build sequence for the project '" + this.acceleoProject.getRoot() + "'..."); | ||
log.info("Mapping the pom.xml to AcceleoProject..."); | ||
|
||
Preconditions.checkNotNull(this.acceleoProject); | ||
|
@@ -123,6 +149,10 @@ public void execute() throws MojoExecutionException, MojoFailureException { | |
for (Entry entry : entries) { | ||
File inputDirectory = new File(root, entry.getInput()); | ||
File outputDirectory = new File(root, entry.getOutput()); | ||
|
||
log.debug("Input: " + inputDirectory.getAbsolutePath()); | ||
log.debug("Output: " + outputDirectory.getAbsolutePath()); | ||
|
||
AcceleoProjectClasspathEntry classpathEntry = new AcceleoProjectClasspathEntry(inputDirectory, | ||
outputDirectory); | ||
classpathEntries.add(classpathEntry); | ||
|
@@ -154,12 +184,92 @@ public void execute() throws MojoExecutionException, MojoFailureException { | |
} | ||
|
||
log.info("Adding jar dependencies..."); | ||
List<File> jars = this.acceleoProject.getJars(); | ||
List<String> jars = this.acceleoProject.getJars(); | ||
if (jars != null) { | ||
Set<URI> newDependencies = new LinkedHashSet<URI>(); | ||
for (File jar : jars) { | ||
URI uri = URI.createFileURI(jar.getAbsolutePath()); | ||
newDependencies.add(uri); | ||
for (String jar : jars) { | ||
log.info("Resolving jar: '" + jar + "'..."); | ||
File jarFile = new File(jar); | ||
if (jarFile.isFile()) { | ||
URI uri = URI.createFileURI(jar); | ||
newDependencies.add(uri); | ||
log.info("Found jar for '" + jar + "' on the filesystem: '" + jarFile.getAbsolutePath() | ||
+ "'."); | ||
} else { | ||
StringTokenizer tok = new StringTokenizer(jar, ":"); | ||
|
||
String groupdId = null; | ||
String artifactId = null; | ||
String version = null; | ||
|
||
int c = 0; | ||
while (tok.hasMoreTokens()) { | ||
String nextToken = tok.nextToken(); | ||
if (c == 0) { | ||
groupdId = nextToken; | ||
} else if (c == 1) { | ||
artifactId = nextToken; | ||
} else if (c == 2) { | ||
version = nextToken; | ||
} | ||
|
||
c++; | ||
} | ||
|
||
Set<?> artifacts = this.project.getArtifacts(); | ||
for (Object object : artifacts) { | ||
if (object instanceof Artifact) { | ||
Artifact artifact = (Artifact)object; | ||
if (groupdId != null && groupdId.equals(artifact.getGroupId()) | ||
&& artifactId != null && artifactId.equals(artifact.getArtifactId())) { | ||
if (version != null && version.equals(artifact.getVersion())) { | ||
File artifactFile = artifact.getFile(); | ||
if (artifactFile != null && artifactFile.exists()) { | ||
URI uri = URI.createFileURI(artifactFile.getAbsolutePath()); | ||
newDependencies.add(uri); | ||
log.info("Found jar for '" + jar + "' on the filesystem: '" | ||
+ uri.toString() + "'."); | ||
} | ||
} else if (version == null) { | ||
File artifactFile = artifact.getFile(); | ||
if (artifactFile != null && artifactFile.exists()) { | ||
URI uri = URI.createFileURI(artifactFile.getAbsolutePath()); | ||
newDependencies.add(uri); | ||
log.info("Found jar for '" + jar + "' on the filesystem: '" | ||
+ uri.toString() + "'."); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
List<?> mavenDependencies = this.project.getDependencies(); | ||
for (Object object : mavenDependencies) { | ||
if (object instanceof Dependency) { | ||
Dependency dependency = (Dependency)object; | ||
if (groupdId != null && groupdId.equals(dependency.getGroupId()) | ||
&& artifactId != null && artifactId.equals(dependency.getArtifactId())) { | ||
if (version != null && version.equals(dependency.getVersion())) { | ||
String systemPath = dependency.getSystemPath(); | ||
if (systemPath != null && new File(systemPath).exists()) { | ||
URI uri = URI.createFileURI(systemPath); | ||
newDependencies.add(uri); | ||
log.info("Found jar for '" + jar + "' on the filesystem: '" | ||
+ uri.toString() + "'."); | ||
} | ||
} else if (version == null) { | ||
String systemPath = dependency.getSystemPath(); | ||
if (systemPath != null && new File(systemPath).exists()) { | ||
URI uri = URI.createFileURI(systemPath); | ||
newDependencies.add(uri); | ||
log.info("Found jar for '" + jar + "' on the filesystem: '" | ||
+ uri.toString() + "'."); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
aProject.addDependencies(newDependencies); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" output="target/classes" path="src/main/java"/> | ||
<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.m2e.MAVEN2_CLASSPATH_CONTAINER"/> | ||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>org.eclipse.acceleo.maven.plugin.tests</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.pde.ManifestBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.pde.SchemaBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.m2e.core.maven2Builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.m2e.core.maven2Nature</nature> | ||
<nature>org.eclipse.pde.PluginNature</nature> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
9 changes: 9 additions & 0 deletions
9
tests/org.eclipse.acceleo.maven.plugin.tests/.settings/org.eclipse.jdt.core.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#Mon Jan 16 16:02:24 CET 2012 | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 | ||
org.eclipse.jdt.core.compiler.compliance=1.5 | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning | ||
org.eclipse.jdt.core.compiler.source=1.5 |
5 changes: 5 additions & 0 deletions
5
tests/org.eclipse.acceleo.maven.plugin.tests/.settings/org.eclipse.m2e.core.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#Mon Jan 16 16:02:24 CET 2012 | ||
activeProfiles= | ||
eclipse.preferences.version=1 | ||
resolveWorkspaceProjects=true | ||
version=1 |
7 changes: 7 additions & 0 deletions
7
tests/org.eclipse.acceleo.maven.plugin.tests/META-INF/MANIFEST.MF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Manifest-Version: 1.0 | ||
Bundle-ManifestVersion: 2 | ||
Bundle-Name: Tests | ||
Bundle-SymbolicName: org.eclipse.acceleo.maven.plugin.tests | ||
Bundle-Version: 1.0.0.qualifier | ||
Bundle-RequiredExecutionEnvironment: JavaSE-1.6 | ||
Require-Bundle: org.obeonetwork.pim.uml2.gen.java;bundle-version="1.0.0" |
5 changes: 5 additions & 0 deletions
5
tests/org.eclipse.acceleo.maven.plugin.tests/build.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
source.. = src/main/java/ | ||
output.. = target/classes/ | ||
bin.includes = META-INF/,\ | ||
. | ||
jre.compilation.profile = J2SE-1.5 |
Empty file.
Oops, something went wrong.