tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1291909 - in /openejb/trunk/maven-plugins: ./ spi-helper-jee6-profile/ spi-helper-jee6-profile/src/ spi-helper-jee6-profile/src/main/ spi-helper-jee6-profile/src/main/resources/ spi-helper-jee6-profile/src/main/resources/org/ spi-helper-je...
Date Tue, 21 Feb 2012 16:53:52 GMT
Author: rmannibucau
Date: Tue Feb 21 16:53:51 2012
New Revision: 1291909

URL: http://svn.apache.org/viewvc?rev=1291909&view=rev
Log:
externalizing profiles

Added:
    openejb/trunk/maven-plugins/spi-helper-jee6-profile/
    openejb/trunk/maven-plugins/spi-helper-jee6-profile/pom.xml
    openejb/trunk/maven-plugins/spi-helper-jee6-profile/src/
    openejb/trunk/maven-plugins/spi-helper-jee6-profile/src/main/
    openejb/trunk/maven-plugins/spi-helper-jee6-profile/src/main/resources/
    openejb/trunk/maven-plugins/spi-helper-jee6-profile/src/main/resources/org/
    openejb/trunk/maven-plugins/spi-helper-jee6-profile/src/main/resources/org/apache/
    openejb/trunk/maven-plugins/spi-helper-jee6-profile/src/main/resources/org/apache/xbean/
    openejb/trunk/maven-plugins/spi-helper-jee6-profile/src/main/resources/org/apache/xbean/profile.properties
Modified:
    openejb/trunk/maven-plugins/pom.xml
    openejb/trunk/maven-plugins/spi-helper-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/spi/SpiMojo.java

Modified: openejb/trunk/maven-plugins/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/maven-plugins/pom.xml?rev=1291909&r1=1291908&r2=1291909&view=diff
==============================================================================
--- openejb/trunk/maven-plugins/pom.xml (original)
+++ openejb/trunk/maven-plugins/pom.xml Tue Feb 21 16:53:51 2012
@@ -40,6 +40,7 @@
     <module>maven-util</module>
     <module>spi-helper-maven-plugin</module>
     <module>xbean-xml</module>
+    <module>spi-helper-jee6-profile</module>
   </modules>
 
   <dependencyManagement>

Added: openejb/trunk/maven-plugins/spi-helper-jee6-profile/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/maven-plugins/spi-helper-jee6-profile/pom.xml?rev=1291909&view=auto
==============================================================================
--- openejb/trunk/maven-plugins/spi-helper-jee6-profile/pom.xml (added)
+++ openejb/trunk/maven-plugins/spi-helper-jee6-profile/pom.xml Tue Feb 21 16:53:51 2012
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <parent>
+    <artifactId>maven-plugins-parent</artifactId>
+    <groupId>org.apache.openejb</groupId>
+    <version>0.0.1-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+
+  <artifactId>spi-helper-jee6-profile</artifactId>
+  <name>OpenEJB Maven Plugins :: JEE6 profile</name>
+</project>

Added: openejb/trunk/maven-plugins/spi-helper-jee6-profile/src/main/resources/org/apache/xbean/profile.properties
URL: http://svn.apache.org/viewvc/openejb/trunk/maven-plugins/spi-helper-jee6-profile/src/main/resources/org/apache/xbean/profile.properties?rev=1291909&view=auto
==============================================================================
--- openejb/trunk/maven-plugins/spi-helper-jee6-profile/src/main/resources/org/apache/xbean/profile.properties
(added)
+++ openejb/trunk/maven-plugins/spi-helper-jee6-profile/src/main/resources/org/apache/xbean/profile.properties
Tue Feb 21 16:53:51 2012
@@ -0,0 +1,53 @@
+name = jee6
+
+annotations = javax.annotation.ManagedBean,\
+              javax.annotation.PostConstruct,\
+              javax.annotation.PreDestroy,\
+              javax.annotation.Resource,\
+              javax.annotation.Resources,\
+              javax.annotation.security.DenyAll,\
+              javax.annotation.security.PermitAll,\
+              javax.annotation.security.RolesAllowed,\
+              javax.annotation.sql.DataSourceDefinition,\
+              javax.ejb.AfterBegin,\
+              javax.ejb.AfterCompletion,\
+              javax.ejb.ApplicationException,\
+              javax.ejb.Asynchronous,\
+              javax.ejb.BeforeCompletion,\
+              javax.ejb.ConcurrencyManagement,\
+              javax.ejb.DependsOn,\
+              javax.ejb.EJB,\
+              javax.ejb.EJBs,\
+              javax.ejb.Init,\
+              javax.ejb.LocalBean,\
+              javax.ejb.LocalHome,\
+              javax.ejb.MessageDriven,\
+              javax.ejb.PostActivate,\
+              javax.ejb.PrePassivate,\
+              javax.ejb.RemoteHome,\
+              javax.ejb.Remove,\
+              javax.ejb.Schedule,\
+              javax.ejb.Schedules,\
+              javax.ejb.Singleton,\
+              javax.ejb.Stateful,\
+              javax.ejb.Stateless,\
+              javax.ejb.Timeout,\
+              javax.enterprise.inject.Specializes,\
+              javax.interceptor.AroundInvoke,\
+              javax.interceptor.AroundTimeout,\
+              javax.interceptor.ExcludeClassInterceptors,\
+              javax.interceptor.ExcludeDefaultInterceptors,\
+              javax.interceptor.Interceptors,\
+              javax.jws.WebService,\
+              javax.persistence.PersistenceContext,\
+              javax.persistence.PersistenceContexts,\
+              javax.persistence.PersistenceUnit,\
+              javax.persistence.PersistenceUnits,\
+              javax.ws.rs.Path,\
+              javax.xml.ws.WebServiceProvider,\
+              javax.xml.ws.WebServiceRef,\
+              javax.xml.ws.WebServiceRefs
+
+subclasses = javax.ws.rs.core.Application
+
+implementations =

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=1291909&r1=1291908&r2=1291909&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 16:53:51 2012
@@ -2,7 +2,6 @@ package org.apache.openejb.maven.plugin.
 
 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;
@@ -28,6 +27,7 @@ import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
+import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.StringReader;
@@ -39,11 +39,12 @@ import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 import java.util.Set;
 
 /**
@@ -52,69 +53,7 @@ import java.util.Set;
  * @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(
-                Arrays.asList( // annotations, TODO: possibly remove some redundant annotations
-                        "javax.annotation.ManagedBean",
-                        "javax.annotation.PostConstruct",
-                        "javax.annotation.PreDestroy",
-                        "javax.annotation.Resource",
-                        "javax.annotation.Resources",
-                        "javax.annotation.security.DenyAll",
-                        "javax.annotation.security.PermitAll",
-                        "javax.annotation.security.RolesAllowed",
-                        "javax.annotation.sql.DataSourceDefinition",
-                        "javax.ejb.AfterBegin",
-                        "javax.ejb.AfterCompletion",
-                        "javax.ejb.ApplicationException",
-                        "javax.ejb.Asynchronous",
-                        "javax.ejb.BeforeCompletion",
-                        "javax.ejb.ConcurrencyManagement",
-                        "javax.ejb.DependsOn",
-                        "javax.ejb.EJB",
-                        "javax.ejb.EJBs",
-                        "javax.ejb.Init",
-                        "javax.ejb.LocalBean",
-                        "javax.ejb.LocalHome",
-                        "javax.ejb.MessageDriven",
-                        "javax.ejb.PostActivate",
-                        "javax.ejb.PrePassivate",
-                        "javax.ejb.RemoteHome",
-                        "javax.ejb.Remove",
-                        "javax.ejb.Schedule",
-                        "javax.ejb.Schedules",
-                        "javax.ejb.Singleton",
-                        "javax.ejb.Stateful",
-                        "javax.ejb.Stateless",
-                        "javax.ejb.Timeout",
-                        "javax.enterprise.inject.Specializes",
-                        "javax.interceptor.AroundInvoke",
-                        "javax.interceptor.AroundTimeout",
-                        "javax.interceptor.ExcludeClassInterceptors",
-                        "javax.interceptor.ExcludeDefaultInterceptors",
-                        "javax.interceptor.Interceptors",
-                        "javax.jws.WebService",
-                        "javax.persistence.PersistenceContext",
-                        "javax.persistence.PersistenceContexts",
-                        "javax.persistence.PersistenceUnit",
-                        "javax.persistence.PersistenceUnits",
-                        "javax.ws.rs.Path",
-                        "javax.xml.ws.WebServiceProvider",
-                        "javax.xml.ws.WebServiceRef",
-                        "javax.xml.ws.WebServiceRefs"
-                ),
-                Arrays.asList( // subclasses
-                        "javax.ws.rs.core.Application"
-                ),
-                new ArrayList<String>( // implementations
-                        // no implementations
-                )
-        );
-        DEFAULT_PROFILES.put(DEFAULT_PROFILE, jee6);
-    }
+    private static final String PROFILE_PATH = "org/apache/xbean/profile.properties";
 
     /**
      * @parameter default-value="${project.build.outputDirectory}"
@@ -123,13 +62,6 @@ 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
@@ -157,7 +89,9 @@ public class SpiMojo extends AbstractMoj
     private List<String> profiles;
 
     /**
-     * @parameter expression="${spi.output}" default-value="META-INF/org/apache/xbean/scan.xml"
+     * @parameter expression="${spi.output}" default-value="${project.build.outputDirectory}/META-INF/org/apache/xbean/scan.xml"
+     *
+     * for webapp: ${project.build.directory}/${project.build.finalName}/WEB-INF/org/apache/xbean/scan.xml
      */
     private String outputFilename;
 
@@ -194,25 +128,22 @@ public class SpiMojo extends AbstractMoj
     /**
      * @component
      */
-    protected ArtifactFactory factory;
-
-    /**
-     * @component
-     */
     protected ArtifactResolver resolver;
 
     @Override
     public void execute() throws MojoExecutionException, MojoFailureException {
+        final Map<String, Profile> loadedProfiles = loadProfiles();
+
         //
         // create profiles to use
         //
         final List<Profile> profileToUse = new ArrayList<Profile>();
         if (profiles != null) {
             for (String profile : profiles) {
-                if (DEFAULT_PROFILES.containsKey(profile)) {
-                    profileToUse.add(DEFAULT_PROFILES.get(profile));
+                if (loadedProfiles.containsKey(profile)) {
+                    profileToUse.add(loadedProfiles.get(profile));
                 } else {
-                    getLog().info("can't find profile " + profile + ", available ones are
" + DEFAULT_PROFILES.keySet());
+                    getLog().info("can't find profile " + profile + ", available ones are
" + loadedProfiles.keySet());
                 }
             }
         }
@@ -220,8 +151,15 @@ public class SpiMojo extends AbstractMoj
             profileToUse.add(new Profile(annotations, subclasses, implementations));
         }
 
+        if (profileToUse.isEmpty() && loadedProfiles.size() > 0) {
+            final Map.Entry<String, Profile> profile = loadedProfiles.entrySet().iterator().next();
+            getLog().info("using profile " + profile.getKey());
+            profileToUse.add(profile.getValue());
+        }
+
         if (profileToUse.isEmpty()) {
-            profileToUse.add(DEFAULT_PROFILES.get(DEFAULT_PROFILE));
+            getLog().warn("no profile or configuration, nothing will be done");
+            return;
         }
 
         //
@@ -233,7 +171,6 @@ public class SpiMojo extends AbstractMoj
         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 {
@@ -323,7 +260,7 @@ public class SpiMojo extends AbstractMoj
             // dump found classes
             //
 
-            final File output = path(outputFolder, outputFilename);
+            final File output = new File(outputFilename);
             if (!output.getParentFile().exists() && !output.getParentFile().mkdirs())
{
                 getLog().error("can't create " + output.getParent());
                 return;
@@ -352,12 +289,44 @@ 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);
+    private Map<String, Profile> loadProfiles() {
+        final Map<String, Profile> profiles = new HashMap<String, Profile>();
+        try {
+            final Enumeration<URL> urls = Thread.currentThread().getContextClassLoader().getResources(PROFILE_PATH);
+            while (urls.hasMoreElements()) {
+                final URL url = urls.nextElement();
+                final Properties properties = new Properties();
+                properties.load(new BufferedInputStream(url.openStream()));
+
+                final String name = properties.getProperty("name");
+                if (name == null) {
+                    getLog().warn("ignoring " + url.toExternalForm() + " since it doesn't
contain a name");
+                }
+                
+
+                final List<String> profileAnnotations = list(properties.getProperty("annotations"));
+                final List<String> profileSubclasses = list(properties.getProperty("subclasses"));
+                final List<String> profileImplementations = list(properties.getProperty("implementations"));
+
+                profiles.put(name, new Profile(profileAnnotations, profileSubclasses, profileImplementations));
+            }
+        } catch (Exception e) {
+            getLog().warn("can't look for profiles");
+        }
+        return profiles;
+    }
+
+    private static List<String> list(final String commaSeparatedList) {
+        final List<String> list = new ArrayList<String>();
+        if (commaSeparatedList != null) {
+            for (String value : commaSeparatedList.split(",")) {
+                final String trimmed = value.trim();
+                if (!trimmed.isEmpty()) {
+                    list.add(trimmed);
+                }
+            }
         }
-        return output;
+        return list;
     }
 
     private ClassLoader providedDependenciesClassLoader() {



Mime
View raw message