You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by re...@apache.org on 2013/01/25 00:42:07 UTC

svn commit: r1438268 - in /uima/sandbox/uimafit/trunk/uimafit-maven-plugin: ./ src/main/java/org/apache/uima/fit/maven/ src/main/resources/ src/main/resources/META-INF/ src/main/resources/META-INF/m2e/

Author: rec
Date: Thu Jan 24 23:42:06 2013
New Revision: 1438268

URL: http://svn.apache.org/viewvc?rev=1438268&view=rev
Log:
[UIMA-2553] Maven plugin to generate component descriptors from uimaFIT annotations at build time 
- Write descriptors to ${project.build.directory}/generated-sources/uimafit (configurable)
- Ignore unresolved dependencies (probably those out of scope, e.g. in "test" scope)
- Add m2e life cycle mapping

Added:
    uima/sandbox/uimafit/trunk/uimafit-maven-plugin/src/main/resources/
    uima/sandbox/uimafit/trunk/uimafit-maven-plugin/src/main/resources/META-INF/
    uima/sandbox/uimafit/trunk/uimafit-maven-plugin/src/main/resources/META-INF/m2e/
    uima/sandbox/uimafit/trunk/uimafit-maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml   (with props)
Modified:
    uima/sandbox/uimafit/trunk/uimafit-maven-plugin/pom.xml
    uima/sandbox/uimafit/trunk/uimafit-maven-plugin/src/main/java/org/apache/uima/fit/maven/GenerateDescriptorsMojo.java

Modified: uima/sandbox/uimafit/trunk/uimafit-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit-maven-plugin/pom.xml?rev=1438268&r1=1438267&r2=1438268&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit-maven-plugin/pom.xml (original)
+++ uima/sandbox/uimafit/trunk/uimafit-maven-plugin/pom.xml Thu Jan 24 23:42:06 2013
@@ -27,7 +27,7 @@
 	</parent>
 	<artifactId>uimafit-maven-plugin</artifactId>
 	<name>uimaFIT - Maven Plugin</name>
-	
+
 	<properties>
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 	</properties>
@@ -49,6 +49,11 @@
 			<version>2.0.10</version>
 		</dependency>
 		<dependency>
+			<groupId>org.sonatype.plexus</groupId>
+			<artifactId>plexus-build-api</artifactId>
+			<version>0.0.7</version>
+		</dependency>
+		<dependency>
 			<groupId>commons-io</groupId>
 			<artifactId>commons-io</artifactId>
 		</dependency>
@@ -64,16 +69,13 @@
 			<scope>provided</scope>
 		</dependency>
 	</dependencies>
-	
+
 	<build>
 		<plugins>
 			<plugin>
 				<groupId>org.apache.maven.plugins</groupId>
 				<artifactId>maven-plugin-plugin</artifactId>
 				<version>3.2</version>
-				<configuration>
-					<goalPrefix>descgen-maven-plugin</goalPrefix>
-				</configuration>
 				<executions>
 					<execution>
 						<id>generated-helpmojo</id>
@@ -86,7 +88,8 @@
 		</plugins>
 		<pluginManagement>
 			<plugins>
-				<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
+				<!--This plugin's configuration is used to store Eclipse m2e settings 
+					only. It has no influence on the Maven build itself. -->
 				<plugin>
 					<groupId>org.eclipse.m2e</groupId>
 					<artifactId>lifecycle-mapping</artifactId>
@@ -114,4 +117,5 @@
 			</plugins>
 		</pluginManagement>
 	</build>
+	<packaging>maven-plugin</packaging>
 </project>
\ No newline at end of file

Modified: uima/sandbox/uimafit/trunk/uimafit-maven-plugin/src/main/java/org/apache/uima/fit/maven/GenerateDescriptorsMojo.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit-maven-plugin/src/main/java/org/apache/uima/fit/maven/GenerateDescriptorsMojo.java?rev=1438268&r1=1438267&r2=1438268&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit-maven-plugin/src/main/java/org/apache/uima/fit/maven/GenerateDescriptorsMojo.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit-maven-plugin/src/main/java/org/apache/uima/fit/maven/GenerateDescriptorsMojo.java Thu Jan 24 23:42:06 2013
@@ -29,12 +29,15 @@ import java.util.List;
 import java.util.Set;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.exception.ExceptionUtils;
 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DependencyResolutionRequiredException;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.LifecyclePhase;
 import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.plugins.annotations.ResolutionScope;
 import org.apache.maven.project.MavenProject;
 import org.apache.uima.fit.factory.AnalysisEngineFactory;
@@ -42,6 +45,7 @@ import org.apache.uima.fit.factory.Colle
 import org.apache.uima.resource.ResourceInitializationException;
 import org.apache.uima.resource.ResourceSpecifier;
 import org.codehaus.plexus.util.FileUtils;
+import org.sonatype.plexus.build.incremental.BuildContext;
 import org.xml.sax.SAXException;
 
 /**
@@ -54,34 +58,65 @@ public class GenerateDescriptorsMojo ext
   @Component
   private MavenProject project;
 
+  @Component
+  private BuildContext buildContext;
+  
+  @Parameter(defaultValue="${project.build.directory}/generated-sources/uimafit", required=true)
+  private File outputDirectory;
+  
   private ClassLoader componentLoader;
 
   public void execute() throws MojoExecutionException {
+    
+    // add the generated sources to the build
+    if (!outputDirectory.exists()) {
+      outputDirectory.mkdirs();
+      buildContext.refresh(outputDirectory);
+    }
+    project.addCompileSourceRoot(outputDirectory.getPath());
+    
     String[] files = FileUtils.getFilesFromExtension(project.getBuild().getOutputDirectory(),
             new String[] { "class" });
 
     // Create a class loader which covers the classes compiled in the current project and all
     // dependencies.
+    List<URL> urls = new ArrayList<URL>();
     try {
-      List<URL> urls = new ArrayList<URL>();
       for (Object object : project.getCompileClasspathElements()) {
         String path = (String) object;
         getLog().debug("Classpath entry: " + object);
         urls.add(new File(path).toURI().toURL());
       }
-      for (Artifact dep : (Set<Artifact>) project.getDependencyArtifacts()) {
-        getLog().debug("Classpath entry: " + dep.getFile());
+    } catch (IOException e) {
+      throw new MojoExecutionException("Unable to assemble classpath: "
+              + ExceptionUtils.getRootCauseMessage(e), e);
+    } catch (DependencyResolutionRequiredException e) {
+      throw new MojoExecutionException("Unable to resolve dependencies: "
+              + ExceptionUtils.getRootCauseMessage(e), e);
+    }
+    
+    for (Artifact dep : (Set<Artifact>) project.getDependencyArtifacts()) {
+      try {
+        if (dep.getFile() == null) {
+          // Unresolved file because it is in the wrong scope (e.g. test?)
+          continue;
+        }
+        getLog().debug(
+                "Classpath entry: " + dep.getGroupId() + ":" + dep.getArtifactId() + ":"
+                        + dep.getVersion() + " -> " + dep.getFile());
         urls.add(dep.getFile().toURI().toURL());
+      } catch (Exception e) {
+        throw new MojoExecutionException("Unable get dependency artifact location for "
+                + dep.getGroupId() + ":" + dep.getArtifactId() + ":" + dep.getVersion()
+                + ExceptionUtils.getRootCauseMessage(e), e);
       }
-      componentLoader = new URLClassLoader(urls.toArray(new URL[] {}), getClass().getClassLoader());
-    } catch (Exception e) {
-      throw new MojoExecutionException("Cannot initialize classloader", e);
     }
+    componentLoader = new URLClassLoader(urls.toArray(new URL[] {}), getClass().getClassLoader());
 
     for (String file : files) {
       String base = file.substring(0, file.length() - 6);
-      String clazzName = base.substring(project.getBuild().getOutputDirectory().length() + 1)
-              .replace("/", ".");
+      String clazzPath = base.substring(project.getBuild().getOutputDirectory().length() + 1);
+      String clazzName = clazzPath.replace("/", ".");
       try {
         Class clazz = getClass(clazzName);
         ResourceSpecifier desc = null;
@@ -96,7 +131,9 @@ public class GenerateDescriptorsMojo ext
         }
 
         if (desc != null) {
-          toXML(desc, base + ".xml");
+          File out = new File(outputDirectory, clazzPath+".xml");
+          out.getParentFile().mkdirs();
+          toXML(desc, out.getPath());
         }
       } catch (SAXException e) {
         getLog().warn("Cannot serialize descriptor for [" + clazzName + "]", e);

Added: uima/sandbox/uimafit/trunk/uimafit-maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit-maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml?rev=1438268&view=auto
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit-maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml (added)
+++ uima/sandbox/uimafit/trunk/uimafit-maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml Thu Jan 24 23:42:06 2013
@@ -0,0 +1,17 @@
+<lifecycleMappingMetadata>
+  <pluginExecutions>
+    <pluginExecution>
+      <pluginExecutionFilter>
+        <goals>
+          <goal>generate</goal>
+        </goals>
+      </pluginExecutionFilter>
+      <action>
+        <execute>
+          <runOnIncremental>true</runOnIncremental>
+          <runOnConfiguration>true</runOnConfiguration>
+        </execute>
+      </action>
+    </pluginExecution>
+  </pluginExecutions>
+</lifecycleMappingMetadata>

Propchange: uima/sandbox/uimafit/trunk/uimafit-maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: uima/sandbox/uimafit/trunk/uimafit-maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml