geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r573489 - in /geronimo/server/trunk: maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/
Date Fri, 07 Sep 2007 07:17:50 GMT
Author: djencks
Date: Fri Sep  7 00:17:49 2007
New Revision: 573489

URL: http://svn.apache.org/viewvc?rev=573489&view=rev
Log:
GERONIMO-3453 Add a create-pluginlist goal to aggregate all the plugin metadata into a geronimo-plugins.xml
in the local maven repo

Added:
    geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/CreatePluginListMojo.java
  (with props)
Modified:
    geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PackageMojo.java
    geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/PluginInstallerGBean.java

Added: geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/CreatePluginListMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/CreatePluginListMojo.java?rev=573489&view=auto
==============================================================================
--- geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/CreatePluginListMojo.java
(added)
+++ geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/CreatePluginListMojo.java
Fri Sep  7 00:17:49 2007
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.geronimo.mavenplugins.car;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Writer;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.SortedSet;
+import java.util.jar.JarFile;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipException;
+
+import javax.xml.bind.JAXBException;
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.geronimo.kernel.config.NoSuchStoreException;
+import org.apache.geronimo.kernel.repository.Artifact;
+import org.apache.geronimo.kernel.repository.ListableRepository;
+import org.apache.geronimo.kernel.repository.Maven2Repository;
+import org.apache.geronimo.system.plugin.PluginInstallerGBean;
+import org.apache.geronimo.system.plugin.model.PluginListType;
+import org.apache.geronimo.system.plugin.model.PluginType;
+import org.xml.sax.SAXException;
+
+/**
+ * @version $Rev:$ $Date:$
+ * @goal create-pluginlist
+ */
+public class CreatePluginListMojo extends AbstractCarMojo {
+
+    protected void doExecute() throws Exception {
+        String path = getArtifactRepository().getBasedir();
+        File baseDir = new File(path);
+
+        ListableRepository repository = new Maven2Repository(baseDir);
+        PluginListType pluginList = createPluginListForRepositories(repository,  path);
+        File outFile = new File(baseDir, "geronimo-plugins.xml");
+        Writer out = new FileWriter(outFile, false);
+        try {
+            PluginInstallerGBean.writePluginList(pluginList, out);
+        } finally {
+            out.close();
+        }
+    }
+
+    public PluginListType createPluginListForRepositories(ListableRepository repository,
String repoName) throws NoSuchStoreException {
+        Map<PluginType, PluginType> pluginMap = new HashMap<PluginType, PluginType>();
+        SortedSet<Artifact> configs = repository.list();
+        for (Artifact configId : configs) {
+            PluginType data = getPluginMetadata(repository, configId);
+
+            if (data != null) {
+                PluginType key = PluginInstallerGBean.copy(data, null);
+                PluginType existing = pluginMap.get(key);
+                if (existing == null) {
+                    pluginMap.put(key, data);
+                } else {
+                    existing.getPluginArtifact().addAll(data.getPluginArtifact());
+                }
+            }
+        }
+        PluginListType pluginList = new PluginListType();
+        pluginList.getPlugin().addAll(pluginMap.values());
+        pluginList.getDefaultRepository().add(repoName);
+        return pluginList;
+    }
+
+    private PluginType getPluginMetadata(ListableRepository repository, Artifact configId)
{
+        File dir = repository.getLocation(configId);
+        if (!dir.isFile() || !dir.canRead()) {
+            log.error("Cannot read artifact dir " + dir.getAbsolutePath());
+            throw new IllegalStateException("Cannot read artifact dir " + dir.getAbsolutePath());
+        }
+        if (dir.toString().endsWith(".pom")) {
+            return null;
+        }
+        try {
+            JarFile jar = new JarFile(dir);
+            try {
+                ZipEntry entry = jar.getEntry("META-INF/geronimo-plugin.xml");
+                if (entry == null) {
+                    return null;
+                }
+                InputStream in = jar.getInputStream(entry);
+                try {
+                    PluginType pluginType = PluginInstallerGBean.loadPluginMetadata(in);
+                    if (pluginType.getPluginArtifact().isEmpty()) {
+                        return null;
+                    }
+                    return pluginType;
+                } finally {
+                    in.close();
+                }
+            } finally {
+                jar.close();
+            }
+        } catch (ZipException e) {
+            //not a zip file, ignore
+        } catch (SAXException e) {
+            log.error("Unable to read JAR file " + dir.getAbsolutePath(), e);
+        } catch (XMLStreamException e) {
+            log.error("Unable to read JAR file " + dir.getAbsolutePath(), e);
+        } catch (JAXBException e) {
+            log.error("Unable to read JAR file " + dir.getAbsolutePath(), e);
+        } catch (IOException e) {
+            log.error("Unable to read JAR file " + dir.getAbsolutePath(), e);
+        }
+        return null;
+    }
+
+
+}

Propchange: geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/CreatePluginListMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/CreatePluginListMojo.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/CreatePluginListMojo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PackageMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PackageMojo.java?rev=573489&r1=573488&r2=573489&view=diff
==============================================================================
--- geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PackageMojo.java
(original)
+++ geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PackageMojo.java
Fri Sep  7 00:17:49 2007
@@ -239,7 +239,7 @@
      * Holds a local repo lookup instance so that we can use the current project to resolve.
      * This is required since the Kernel used to deploy is cached.
      */
-    private static ThreadLocal lookupHolder = new ThreadLocal();
+    private static ThreadLocal<Maven2RepositoryAdapter.ArtifactLookup> lookupHolder
= new ThreadLocal<Maven2RepositoryAdapter.ArtifactLookup>();
 
     //
     // Mojo

Modified: geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/PluginInstallerGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/PluginInstallerGBean.java?rev=573489&r1=573488&r2=573489&view=diff
==============================================================================
--- geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/PluginInstallerGBean.java
(original)
+++ geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/PluginInstallerGBean.java
Fri Sep  7 00:17:49 2007
@@ -1434,7 +1434,7 @@
     /**
      * Read a set of plugin metadata from a DOM document.
      */
-    static PluginType loadPluginMetadata(InputStream in) throws SAXException, MalformedURLException,
JAXBException, XMLStreamException {
+    public static PluginType loadPluginMetadata(InputStream in) throws SAXException, MalformedURLException,
JAXBException, XMLStreamException {
         XMLStreamReader xmlStream = XMLINPUT_FACTORY.createXMLStreamReader(in);
         Unmarshaller unmarshaller = PLUGIN_CONTEXT.createUnmarshaller();
         JAXBElement<PluginType> element = unmarshaller.unmarshal(xmlStream, PluginType.class);



Mime
View raw message