Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 72539 invoked from network); 7 Sep 2007 07:18:13 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 7 Sep 2007 07:18:13 -0000 Received: (qmail 4545 invoked by uid 500); 7 Sep 2007 07:18:06 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 4509 invoked by uid 500); 7 Sep 2007 07:18:06 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 4498 invoked by uid 99); 7 Sep 2007 07:18:06 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 07 Sep 2007 00:18:06 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 07 Sep 2007 07:18:11 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 4D5BF1A9832; Fri, 7 Sep 2007 00:17:51 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: scm@geronimo.apache.org From: djencks@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20070907071751.4D5BF1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 pluginMap = new HashMap(); + SortedSet 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 lookupHolder = new ThreadLocal(); // // 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 element = unmarshaller.unmarshal(xmlStream, PluginType.class);