geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r1098946 - in /geronimo/server/branches/3.0-osgi: framework/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ plugins/tomcat/tomcat7/
Date Tue, 03 May 2011 07:18:38 GMT
Author: djencks
Date: Tue May  3 07:18:37 2011
New Revision: 1098946

URL: http://svn.apache.org/viewvc?rev=1098946&view=rev
Log:
add capability to install and start features/kars in car-maven-plugin.  Try it out in tomcat7

Modified:
    geronimo/server/branches/3.0-osgi/framework/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/AbstractFrameworkMojo.java
    geronimo/server/branches/3.0-osgi/framework/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PackageMojo.java
    geronimo/server/branches/3.0-osgi/plugins/tomcat/tomcat7/pom.xml

Modified: geronimo/server/branches/3.0-osgi/framework/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/AbstractFrameworkMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-osgi/framework/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/AbstractFrameworkMojo.java?rev=1098946&r1=1098945&r2=1098946&view=diff
==============================================================================
--- geronimo/server/branches/3.0-osgi/framework/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/AbstractFrameworkMojo.java
(original)
+++ geronimo/server/branches/3.0-osgi/framework/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/AbstractFrameworkMojo.java
Tue May  3 07:18:37 2011
@@ -36,6 +36,7 @@ import org.apache.maven.plugin.MojoFailu
 import org.apache.maven.project.MavenProject;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleException;
+import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.launch.Framework;
 import org.sonatype.aether.RepositorySystem;
@@ -127,10 +128,27 @@ public class AbstractFrameworkMojo exten
         return framework;
     }
 
-    protected <T> T getService(Class<T> clazz) throws MojoExecutionException
{
+    protected <T> T getService(Class<T> clazz, String componentName) throws MojoExecutionException
{
+        String filter = null;
+        if (componentName != null) {
+            filter = "(osgi.service.blueprint.compname=" + componentName + ")";
+        }
         long timeout = this.timeout;
         while (timeout > 0) {
-            ServiceReference sr = framework.getBundleContext().getServiceReference(clazz.getName());
+            ServiceReference sr = null;
+            if (filter == null) {
+                sr = framework.getBundleContext().getServiceReference(clazz.getName());
+            } else {
+                ServiceReference[] refs = new ServiceReference[0];
+                try {
+                    refs = framework.getBundleContext().getServiceReferences(clazz.getName(),
filter);
+                } catch (InvalidSyntaxException e) {
+                    throw new MojoExecutionException("filter syntax problem", e);
+                }
+                if (refs != null && refs.length == 1) {
+                    sr = refs[0];
+                }
+            }
             if (sr != null) {
                 services.add(sr);
                 return (T)framework.getBundleContext().getService(sr);
@@ -145,6 +163,10 @@ public class AbstractFrameworkMojo exten
         throw new MojoExecutionException("Could not get service " + clazz.getName() + " in
" + this.timeout/1000 + " seconds");
     }
 
+    protected <T> T getService(Class<T> clazz) throws MojoExecutionException
{
+        return getService(clazz, null);
+    }
+
     void initializeFramework() throws MojoFailureException {
         FrameworkHelper helper = new FrameworkHelper(karafHome, new AetherResolver());
         try {

Modified: geronimo/server/branches/3.0-osgi/framework/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PackageMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-osgi/framework/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PackageMojo.java?rev=1098946&r1=1098945&r2=1098946&view=diff
==============================================================================
--- geronimo/server/branches/3.0-osgi/framework/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PackageMojo.java
(original)
+++ geronimo/server/branches/3.0-osgi/framework/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PackageMojo.java
Tue May  3 07:18:37 2011
@@ -21,12 +21,16 @@ package org.apache.geronimo.mavenplugins
 
 import java.io.File;
 import java.lang.reflect.Method;
+import java.net.URI;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.felix.fileinstall.ArtifactInstaller;
 import org.apache.geronimo.deployment.Deployer;
+import org.apache.karaf.features.FeaturesService;
 import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.project.MavenProject;
 import org.codehaus.plexus.util.FileUtils;
 import org.osgi.framework.Bundle;
@@ -130,6 +134,13 @@ public class PackageMojo extends Abstrac
      * @readonly
      */
     protected MavenProject project;
+
+    /**
+     * features to start
+     *
+     * @parameter
+     */
+    protected List<String> features;
     //
     // Mojo
     //
@@ -145,10 +156,38 @@ public class PackageMojo extends Abstrac
                 if (!planFile.exists()) {
                     return;
                 }
+                Object featuresService = getService(FeaturesService.class);
+                Object karService = getService(ArtifactInstaller.class, "karArtifactInstaller");
+                Method karInstallMethod;
+                Method featuresAddRepoMethod;
+                Method featuresInstallFeatureMethod;
+
+                try {
+                    karInstallMethod = karService.getClass().getMethod("install", new Class[]{File.class});
+                    featuresAddRepoMethod = featuresService.getClass().getMethod("addRepository",
new Class[]{URI.class});
+                    featuresInstallFeatureMethod = featuresService.getClass().getMethod("installFeature",
new Class[]{String.class});
+                } catch (NoSuchMethodException e) {
+                    throw new MojoFailureException("What class??", e);
+                }
+
                 List<Long> ids = new ArrayList<Long>();
                 Map<org.sonatype.aether.artifact.Artifact, String> artifacts = getTransitiveDependencies(project);
                 for (org.sonatype.aether.artifact.Artifact dependency : artifacts.keySet())
{
-                    if ("jar".equals(dependency.getExtension()) || "car".equals(dependency.getExtension()))
{
+                    if ("kar".equals(dependency.getExtension())) {
+                        try {
+                            File file = resolve(dependency);
+                            karInstallMethod.invoke(karService, file);
+                        } catch (Exception e) {
+                            throw new MojoExecutionException("Cannot install kar " + dependency,
e);
+                        }
+                    } else if ("xml".equals(dependency.getExtension()) && "features".equals(dependency.getClassifier()))
{
+                        try {
+                            File file = resolve(dependency);
+                            featuresAddRepoMethod.invoke(featuresService, file.toURI());
+                        } catch (Exception e) {
+                            throw new MojoExecutionException("Could not install feature "
+ dependency, e);
+                        }
+                    } else if ("jar".equals(dependency.getExtension()) || "car".equals(dependency.getExtension()))
{
                         getLog().info("starting dependency: " + dependency);
                         File file = resolve(dependency);
                         try {
@@ -158,7 +197,12 @@ public class PackageMojo extends Abstrac
                         }
                     }
                 }
-                for (Long id: ids) {
+                if (features != null) {
+                    for (String featureName: features) {
+                        featuresInstallFeatureMethod.invoke(featuresService, featureName);
+                    }
+                }
+                for (Long id : ids) {
                     try {
                         getFramework().getBundleContext().getBundle(id).start();
                     } catch (BundleException e) {
@@ -171,7 +215,7 @@ public class PackageMojo extends Abstrac
             } catch (Exception e) {
                 getLog().info("Exception, use console to investigate ", e);
                 listBundles();
-                for (Bundle b: getFramework().getBundleContext().getBundles()) {
+                for (Bundle b : getFramework().getBundleContext().getBundles()) {
                     if (b.getState() != 32) {
                         try {
                             b.start();

Modified: geronimo/server/branches/3.0-osgi/plugins/tomcat/tomcat7/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-osgi/plugins/tomcat/tomcat7/pom.xml?rev=1098946&r1=1098945&r2=1098946&view=diff
==============================================================================
--- geronimo/server/branches/3.0-osgi/plugins/tomcat/tomcat7/pom.xml (original)
+++ geronimo/server/branches/3.0-osgi/plugins/tomcat/tomcat7/pom.xml Tue May  3 07:18:37 2011
@@ -60,10 +60,17 @@
         </dependency>
 
         <dependency>
-            <groupId>org.apache.geronimo.framework.config</groupId>
+            <groupId>org.apache.geronimo.framework.feature</groupId>
+            <artifactId>j2ee-system</artifactId>
+            <version>${project.version}</version>
+            <type>xml</type>
+            <classifier>features</classifier>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.geronimo.framework.feature</groupId>
             <artifactId>server-security-config</artifactId>
             <version>${project.version}</version>
-            <type>car</type>
+            <type>kar</type>
         </dependency>
 
         <dependency>
@@ -127,6 +134,10 @@
                 <groupId>org.apache.geronimo.buildsupport</groupId>
                 <artifactId>car-maven-plugin</artifactId>
                 <configuration>
+                    <features>
+                        <feature>j2ee-system</feature>
+                        <feature>server-security-config</feature>
+                    </features>
                     <category>Tomcat</category>
                     <instance>
                         <plugin-artifact>



Mime
View raw message