geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r573738 - in /geronimo/server/trunk: maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ maven-plugins/car-maven-plugin/src/main/resources/META-INF/plexus/ modules/geronimo-system/src/main/java/org/apache/gero...
Date Fri, 07 Sep 2007 22:37:21 GMT
Author: djencks
Date: Fri Sep  7 15:37:17 2007
New Revision: 573738

URL: http://svn.apache.org/viewvc?rev=573738&view=rev
Log:
GERONIMO-3453 car-maven-plugin now updates geronimo-plugins.xml in local maven repo whenever
it builds a configuration

Added:
    geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/UpdatePluginListMojo.java
  (with props)
Modified:
    geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/CreatePluginListMojo.java
    geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/resources/META-INF/plexus/components.xml
    geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/PluginInstallerGBean.java

Modified: 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=573738&r1=573737&r2=573738&view=diff
==============================================================================
--- geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/CreatePluginListMojo.java
(original)
+++ geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/CreatePluginListMojo.java
Fri Sep  7 15:37:17 2007
@@ -45,7 +45,7 @@
 import org.xml.sax.SAXException;
 
 /**
- * @version $Rev:$ $Date:$
+ * @version $Rev$ $Date$
  * @goal create-pluginlist
  */
 public class CreatePluginListMojo extends AbstractCarMojo {
@@ -72,7 +72,7 @@
             PluginType data = getPluginMetadata(repository, configId);
 
             if (data != null) {
-                PluginType key = PluginInstallerGBean.copy(data, null);
+                PluginType key = PluginInstallerGBean.toKey(data);
                 PluginType existing = pluginMap.get(key);
                 if (existing == null) {
                     pluginMap.put(key, data);

Added: geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/UpdatePluginListMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/UpdatePluginListMojo.java?rev=573738&view=auto
==============================================================================
--- geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/UpdatePluginListMojo.java
(added)
+++ geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/UpdatePluginListMojo.java
Fri Sep  7 15:37:17 2007
@@ -0,0 +1,113 @@
+/*
+ * 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.FileInputStream;
+import java.io.FileWriter;
+import java.io.InputStream;
+import java.io.Writer;
+import java.util.Iterator;
+
+import org.apache.geronimo.kernel.config.NoSuchStoreException;
+import org.apache.geronimo.kernel.repository.Artifact;
+import org.apache.geronimo.system.plugin.PluginInstallerGBean;
+import org.apache.geronimo.system.plugin.model.ArtifactType;
+import org.apache.geronimo.system.plugin.model.PluginListType;
+import org.apache.geronimo.system.plugin.model.PluginType;
+import org.apache.geronimo.system.plugin.model.PluginArtifactType;
+
+/**
+ * @version $Rev$ $Date$
+ * @goal update-pluginlist
+ */
+public class UpdatePluginListMojo extends AbstractCarMojo {
+
+    /**
+     * @parameter expression="${project.build.directory}/resources/META-INF/geronimo-plugin.xml"
+     * @required
+     */
+    protected File targetFile;
+
+    protected void doExecute() throws Exception {
+
+        InputStream min = new FileInputStream(targetFile);
+        PluginType plugin;
+        try {
+            plugin = PluginInstallerGBean.loadPluginMetadata(min);
+        } finally {
+            min.close();
+        }
+
+        String path = getArtifactRepository().getBasedir();
+        File baseDir = new File(path);
+
+        File outFile = new File(baseDir, "geronimo-plugins.xml");
+        PluginListType pluginList;
+        if (outFile.exists()) {
+            InputStream in = new FileInputStream(outFile);
+            try {
+                pluginList = PluginInstallerGBean.loadPluginList(in);
+            } finally {
+                in.close();
+            }
+        } else {
+            pluginList = new PluginListType();
+            pluginList.getDefaultRepository().add(path);
+        }
+
+        updatePluginList(plugin, pluginList);
+        Writer out = new FileWriter(outFile, false);
+        try {
+            PluginInstallerGBean.writePluginList(pluginList, out);
+        } finally {
+            out.close();
+        }
+    }
+
+    public void updatePluginList(PluginType plugin, PluginListType pluginList) throws NoSuchStoreException
{
+        PluginType key = PluginInstallerGBean.toKey(plugin);
+        PluginArtifactType instance = plugin.getPluginArtifact().get(0);
+        Artifact id = PluginInstallerGBean.toArtifact(instance.getModuleId());
+        boolean foundKey = false;
+        for (PluginType test : pluginList.getPlugin()) {
+            for (Iterator<PluginArtifactType> it = test.getPluginArtifact().iterator();
it.hasNext();) {
+                PluginArtifactType testInstance = it.next();
+                Artifact testId = PluginInstallerGBean.toArtifact(testInstance.getModuleId());
+                if (id.equals(testId)) {
+                    //if the module id appears anywhere, remove that instance
+                    it.remove();
+                }
+            }
+            PluginType testKey = PluginInstallerGBean.toKey(test);
+            if (key.equals(testKey)) {
+                foundKey = true;
+                //if the name, group, author, licences, url match, then add this instance
to current pluginType
+                test.getPluginArtifact().add(instance);
+            }
+        }
+        if (!foundKey) {
+            //did not find a matching key
+            pluginList.getPlugin().add(plugin);
+        }
+    }
+
+}

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

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

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

Modified: geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/resources/META-INF/plexus/components.xml?rev=573738&r1=573737&r2=573738&view=diff
==============================================================================
--- geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/resources/META-INF/plexus/components.xml
(original)
+++ geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/resources/META-INF/plexus/components.xml
Fri Sep  7 15:37:17 2007
@@ -40,7 +40,8 @@
                             org.apache.geronimo.plugins:car-maven-plugin:prepare-plan,
                             org.apache.geronimo.plugins:car-maven-plugin:prepare-metadata</compile>
                             <package>org.apache.geronimo.plugins:car-maven-plugin:package</package>
-                            <install>org.apache.maven.plugins:maven-install-plugin:install</install>
+                            <install>org.apache.maven.plugins:maven-install-plugin:install,
+                            org.apache.geronimo.plugins:car-maven-plugin:update-pluginlist</install>
                             <deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
                         </phases>
                     </lifecycle>

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=573738&r1=573737&r2=573738&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 15:37:17 2007
@@ -99,6 +99,7 @@
 import org.apache.geronimo.system.plugin.model.PluginType;
 import org.apache.geronimo.system.plugin.model.PrerequisiteType;
 import org.apache.geronimo.system.plugin.model.PropertyType;
+import org.apache.geronimo.system.plugin.model.LicenseType;
 import org.apache.geronimo.system.resolver.AliasedArtifactResolver;
 import org.apache.geronimo.system.serverinfo.ServerInfo;
 import org.apache.geronimo.system.threads.ThreadPool;
@@ -1503,7 +1504,7 @@
      * Loads the list of all available plugins from the specified stream
      * (representing geronimo-plugins.xml at the specified repository).
      */
-    private static PluginListType loadPluginList(InputStream in) throws ParserConfigurationException,
IOException, SAXException, JAXBException, XMLStreamException {
+    public static PluginListType loadPluginList(InputStream in) throws ParserConfigurationException,
IOException, SAXException, JAXBException, XMLStreamException {
         Unmarshaller unmarshaller = PLUGIN_LIST_CONTEXT.createUnmarshaller();
         XMLStreamReader xmlStream = XMLINPUT_FACTORY.createXMLStreamReader(in);
         JAXBElement<PluginListType> element = unmarshaller.unmarshal(xmlStream, PluginListType.class);
@@ -1686,6 +1687,51 @@
         return copy;
     }
 
+    public static PluginType toKey(PluginType metadata) {
+        PluginType copy = new PluginKey();
+        copy.setAuthor(metadata.getAuthor());
+        copy.setCategory(metadata.getCategory());
+        copy.setName(metadata.getName());
+        copy.setUrl(metadata.getUrl());
+        copy.getLicense().addAll(metadata.getLicense());
+        return copy;
+    }
+
+    private static class PluginKey extends PluginType {
+        public boolean equals(Object o) {
+            if (this == o) return true;
+            if (o == null || getClass() != o.getClass()) return false;
+
+            PluginKey that = (PluginKey) o;
+
+            if (author != null ? !author.equals(that.author) : that.author != null) return
false;
+            if (category != null ? !category.equals(that.category) : that.category != null)
return false;
+            if (name != null ? !name.equals(that.name) : that.name != null) return false;
+            if (url != null ? !url.equals(that.url) : that.url != null) return false;
+            if ((license == null) != (that.license == null)) return false;
+            if (license != null) {
+                if (license.size() != that.license.size()) return false;
+                int i = 0;
+                for (LicenseType licenseType: license) {
+                    LicenseType otherLicense = that.license.get(i++);
+                    if (licenseType.isOsiApproved() != otherLicense.isOsiApproved()) return
false;
+                    if (licenseType.getValue() != null? !licenseType.getValue().equals(otherLicense.getValue())
: otherLicense.getValue() != null) return false;
+                }
+            }
+
+            return true;
+        }
+
+        public int hashCode() {
+            int result;
+            result = (name != null ? name.hashCode() : 0);
+            result = 31 * result + (category != null ? category.hashCode() : 0);
+            result = 31 * result + (url != null ? url.hashCode() : 0);
+            result = 31 * result + (author != null ? author.hashCode() : 0);
+            return result;
+        }
+    }
+
     public PluginListType createPluginListForRepositories(ConfigurationManager mgr, String
repo) throws NoSuchStoreException {
         Map<PluginType, PluginType> pluginMap = new HashMap<PluginType, PluginType>();
         List<AbstractName> stores = mgr.listStores();
@@ -1694,7 +1740,7 @@
             for (ConfigurationInfo info : configs) {
                 PluginType data = getPluginMetadata(info.getConfigID());
 
-                PluginType key = PluginInstallerGBean.copy(data, null);
+                PluginType key = PluginInstallerGBean.toKey(data);
                 PluginType existing = pluginMap.get(key);
                 if (existing == null) {
                     pluginMap.put(key, data);



Mime
View raw message