You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2012/02/21 15:04:57 UTC
svn commit: r1291790 - in /openejb/trunk/maven-plugins:
spi-helper-maven-plugin/
spi-helper-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/spi/
xbean-xml/src/main/java/org/apache/openejb/xbean/xml/
xbean-xml/src/test/resources/
Author: rmannibucau
Date: Tue Feb 21 14:04:57 2012
New Revision: 1291790
URL: http://svn.apache.org/viewvc?rev=1291790&view=rev
Log:
updating spi-helper-maven-plugin to manage provided and plugin dependencies
Modified:
openejb/trunk/maven-plugins/spi-helper-maven-plugin/pom.xml
openejb/trunk/maven-plugins/spi-helper-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/spi/SpiMojo.java
openejb/trunk/maven-plugins/xbean-xml/src/main/java/org/apache/openejb/xbean/xml/XMLAnnotationFinderHelper.java
openejb/trunk/maven-plugins/xbean-xml/src/test/resources/test-scan.xml
Modified: openejb/trunk/maven-plugins/spi-helper-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/maven-plugins/spi-helper-maven-plugin/pom.xml?rev=1291790&r1=1291789&r2=1291790&view=diff
==============================================================================
--- openejb/trunk/maven-plugins/spi-helper-maven-plugin/pom.xml (original)
+++ openejb/trunk/maven-plugins/spi-helper-maven-plugin/pom.xml Tue Feb 21 14:04:57 2012
@@ -31,11 +31,6 @@
<artifactId>xbean-xml</artifactId>
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>org.apache.openejb</groupId>
- <artifactId>javaee-api</artifactId>
- <version>6.0-3</version>
- </dependency>
</dependencies>
<properties>
Modified: openejb/trunk/maven-plugins/spi-helper-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/spi/SpiMojo.java
URL: http://svn.apache.org/viewvc/openejb/trunk/maven-plugins/spi-helper-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/spi/SpiMojo.java?rev=1291790&r1=1291789&r2=1291790&view=diff
==============================================================================
--- openejb/trunk/maven-plugins/spi-helper-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/spi/SpiMojo.java (original)
+++ openejb/trunk/maven-plugins/spi-helper-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/spi/SpiMojo.java Tue Feb 21 14:04:57 2012
@@ -1,6 +1,16 @@
package org.apache.openejb.maven.plugin.spi;
import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.handler.DefaultArtifactHandler;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
@@ -9,6 +19,7 @@ import org.apache.openejb.xbean.xml.Scan
import org.apache.xbean.finder.Annotated;
import org.apache.xbean.finder.AnnotationFinder;
import org.apache.xbean.finder.archive.Archive;
+import org.apache.xbean.finder.archive.ClasspathArchive;
import org.apache.xbean.finder.archive.FileArchive;
import javax.xml.bind.JAXBContext;
@@ -30,16 +41,19 @@ import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @goal generate
+ * @requiresDependencyResolution compile+runtime
* @phase compile
*/
public class SpiMojo extends AbstractMojo {
private static final Map<String, Profile> DEFAULT_PROFILES = new HashMap<String, Profile>();
+ private static final String DEFAULT_PROFILE = "jee6";
static {
final Profile jee6 = new Profile(
@@ -99,7 +113,7 @@ public class SpiMojo extends AbstractMoj
// no implementations
)
);
- DEFAULT_PROFILES.put("jee6", jee6);
+ DEFAULT_PROFILES.put(DEFAULT_PROFILE, jee6);
}
/**
@@ -109,6 +123,13 @@ public class SpiMojo extends AbstractMoj
private File module;
/**
+ * @parameter default-value="${project.build.outputDirectory}"
+ *
+ * for webapps "${project.build.directory}/${project.build.finalName}" is better
+ */
+ private File outputFolder;
+
+ /**
* @parameter default-value="${project}"
* @required
* @readonly
@@ -145,6 +166,41 @@ public class SpiMojo extends AbstractMoj
*/
private boolean useMeta;
+ /**
+ * @parameter expression="${spi.aggregated-archive}" default-value="true"
+ */
+ private boolean useAggregatedArchiveIfWar;
+
+ /**
+ * @parameter default-value="${project.packaging}"
+ * @readonly
+ */
+ private String packaging;
+
+ /**
+ * @parameter expression="${project.pluginArtifactRepositories}"
+ * @required
+ * @readonly
+ */
+ private List remotePluginRepositories;
+
+ /**
+ * @parameter expression="${localRepository}"
+ * @readonly
+ * @required
+ */
+ private ArtifactRepository local;
+
+ /**
+ * @component
+ */
+ protected ArtifactFactory factory;
+
+ /**
+ * @component
+ */
+ protected ArtifactResolver resolver;
+
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
//
@@ -160,14 +216,34 @@ public class SpiMojo extends AbstractMoj
}
}
}
- profileToUse.add(new Profile(annotations, subclasses, implementations));
+ if (annotations != null || subclasses != null || implementations != null) {
+ profileToUse.add(new Profile(annotations, subclasses, implementations));
+ }
+
+ if (profileToUse.isEmpty()) {
+ profileToUse.add(DEFAULT_PROFILES.get(DEFAULT_PROFILE));
+ }
+
+ //
+ // creating the archive and its classloader
+ //
+
+ // war is different since it will contain a single descriptor for its lib too (not an ear)
+ boolean war = "war".equals(packaging);
+ final Archive archive;
+ final URLClassLoader loader = createClassLoader(providedDependenciesClassLoader());
+ if (war && useAggregatedArchiveIfWar) {
+ // no parent to avoid to not simply look lib/
+ archive = new ClasspathArchive(loader, loader.getURLs());
+ getLog().info("using an aggregated archive");
+ } else {
+ archive = new FileArchive(loader, module);
+ getLog().info("using an file archive");
+ }
// the result
final Scan scan = new Scan();
-
try {
- final ClassLoader loader = createClassLoader();
- final Archive archive = new FileArchive(loader, module);
final AnnotationFinder finder = new AnnotationFinder(archive);
finder.link();
@@ -247,10 +323,7 @@ public class SpiMojo extends AbstractMoj
// dump found classes
//
- File output = new File(outputFilename);
- if (!output.isAbsolute()) {
- output = new File(module, outputFilename);
- }
+ final File output = path(outputFolder, outputFilename);
if (!output.getParentFile().exists() && !output.getParentFile().mkdirs()) {
getLog().error("can't create " + output.getParent());
return;
@@ -279,6 +352,53 @@ public class SpiMojo extends AbstractMoj
}
}
+ private File path(File outputFolder, String outputFilename) {
+ File output = new File(outputFilename);
+ if (!output.isAbsolute()) {
+ output = new File(outputFolder, outputFilename);
+ }
+ return output;
+ }
+
+ private ClassLoader providedDependenciesClassLoader() {
+ final Set<URL> urls = new HashSet<URL>();
+
+ // provided artifacts
+ for (Artifact artifact : (Set<Artifact>) project.getDependencyArtifacts()) {
+ if (!"provided".equals(artifact.getScope())) {
+ continue;
+ }
+
+ try {
+ urls.add(artifact.getFile().toURI().toURL());
+ } catch (MalformedURLException e) {
+ getLog().warn("can't use artifact " + artifact.toString());
+ }
+ }
+
+ // plugin dependencies
+ final Plugin thisPlugin = (Plugin) project.getBuild().getPluginsAsMap().get("org.apache.openejb:spi-helper-maven-plugin");
+ if (thisPlugin != null && thisPlugin.getDependencies() != null) {
+ for (Dependency artifact : thisPlugin.getDependencies()) {
+ final Artifact resolved = new DefaultArtifact(
+ artifact.getGroupId(), artifact.getArtifactId(), VersionRange.createFromVersion(artifact.getVersion()),
+ artifact.getScope(), artifact.getType(), artifact.getClassifier(), new DefaultArtifactHandler());
+ try {
+ resolver.resolve(resolved, remotePluginRepositories, local);
+ urls.add(resolved.getFile().toURI().toURL());
+ } catch (ArtifactResolutionException e) {
+ getLog().warn("can't resolve " + artifact.getArtifactId());
+ } catch (ArtifactNotFoundException e) {
+ getLog().warn("can't find " + artifact.getArtifactId());
+ } catch (MalformedURLException e) {
+ getLog().warn("can't get url of " + resolved.getFile() + " for artifact " + resolved.getArtifactId());
+ }
+ }
+ }
+
+ return new URLClassLoader(urls.toArray(new URL[urls.size()]), ClassLoader.getSystemClassLoader());
+ }
+
private Class<?> load(final ClassLoader loader, final String name) throws MojoFailureException {
try {
return loader.loadClass(name);
@@ -287,7 +407,7 @@ public class SpiMojo extends AbstractMoj
}
}
- private ClassLoader createClassLoader() {
+ private URLClassLoader createClassLoader(final ClassLoader parent) {
final List<URL> urls = new ArrayList<URL>();
for (Artifact artifact : (Set<Artifact>) project.getArtifacts()) {
try {
@@ -305,7 +425,7 @@ public class SpiMojo extends AbstractMoj
} else {
getLog().warn("can't find " + module.getPath());
}
- return new URLClassLoader(urls.toArray(new URL[urls.size()]), Thread.currentThread().getContextClassLoader());
+ return new URLClassLoader(urls.toArray(new URL[urls.size()]), parent);
}
public static final class Profile {
Modified: openejb/trunk/maven-plugins/xbean-xml/src/main/java/org/apache/openejb/xbean/xml/XMLAnnotationFinderHelper.java
URL: http://svn.apache.org/viewvc/openejb/trunk/maven-plugins/xbean-xml/src/main/java/org/apache/openejb/xbean/xml/XMLAnnotationFinderHelper.java?rev=1291790&r1=1291789&r2=1291790&view=diff
==============================================================================
--- openejb/trunk/maven-plugins/xbean-xml/src/main/java/org/apache/openejb/xbean/xml/XMLAnnotationFinderHelper.java (original)
+++ openejb/trunk/maven-plugins/xbean-xml/src/main/java/org/apache/openejb/xbean/xml/XMLAnnotationFinderHelper.java Tue Feb 21 14:04:57 2012
@@ -27,6 +27,8 @@ public final class XMLAnnotationFinderHe
public static IAnnotationFinder finderFromXml(final InputStream is, final ClassLoader loader) throws JAXBException {
final Scan scan = (Scan) JAXB_CONTEXT.createUnmarshaller().unmarshal(new BufferedInputStream(is));
+ // TODO: manage packages
+
Class<?>[] classes = new Class<?>[scan.getClassname().size()];
int i = 0;
for (String clazz : scan.getClassname()) {
@@ -44,6 +46,6 @@ public final class XMLAnnotationFinderHe
}
final Archive archive = new ClassesArchive(classes);
- return new AnnotationFinder(archive).link();
+ return new AnnotationFinder(archive); // don't link here
}
}
Modified: openejb/trunk/maven-plugins/xbean-xml/src/test/resources/test-scan.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/maven-plugins/xbean-xml/src/test/resources/test-scan.xml?rev=1291790&r1=1291789&r2=1291790&view=diff
==============================================================================
--- openejb/trunk/maven-plugins/xbean-xml/src/test/resources/test-scan.xml (original)
+++ openejb/trunk/maven-plugins/xbean-xml/src/test/resources/test-scan.xml Tue Feb 21 14:04:57 2012
@@ -6,4 +6,4 @@
<class>org.apache.openejb.xbean.xml.bean.MyBean3</class>
</classes>
<packages/>
-</scan>
\ No newline at end of file
+</scan>