geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmcma...@apache.org
Subject svn commit: r474454 - in /geronimo/server/branches/1.1/modules/system/src/java/org/apache/geronimo/system/plugin: PluginInstallerGBean.java SnapshotVersion.java
Date Mon, 13 Nov 2006 19:29:37 GMT
Author: pmcmahan
Date: Mon Nov 13 11:29:36 2006
New Revision: 474454

URL: http://svn.apache.org/viewvc?view=rev&rev=474454
Log:
GERONIMO-2521 add support for maven2 style snapshot download URLs to plugin installer gbean.
  backport from 1.2

Added:
    geronimo/server/branches/1.1/modules/system/src/java/org/apache/geronimo/system/plugin/SnapshotVersion.java
  (with props)
Modified:
    geronimo/server/branches/1.1/modules/system/src/java/org/apache/geronimo/system/plugin/PluginInstallerGBean.java

Modified: geronimo/server/branches/1.1/modules/system/src/java/org/apache/geronimo/system/plugin/PluginInstallerGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/1.1/modules/system/src/java/org/apache/geronimo/system/plugin/PluginInstallerGBean.java?view=diff&rev=474454&r1=474453&r2=474454
==============================================================================
--- geronimo/server/branches/1.1/modules/system/src/java/org/apache/geronimo/system/plugin/PluginInstallerGBean.java
(original)
+++ geronimo/server/branches/1.1/modules/system/src/java/org/apache/geronimo/system/plugin/PluginInstallerGBean.java
Mon Nov 13 11:29:36 2006
@@ -889,11 +889,26 @@
      * Constructs a URL to a particular artifact in a particular repository
      */
     private static URL getURL(Artifact configId, URL repository) throws MalformedURLException
{
-        if(repository.toString().endsWith("/")) {
-            return new URL(repository, configId.getGroupId().replace('.','/')+"/"+configId.getArtifactId()+"/"+configId.getVersion()+"/"+configId.getArtifactId()+"-"+configId.getVersion()+"."+configId.getType());
-        } else {
-            return new URL(new URL(repository.toString()+"/"), configId.getGroupId().replace('.','/')+"/"+configId.getArtifactId()+"/"+configId.getVersion()+"/"+configId.getArtifactId()+"-"+configId.getVersion()+"."+configId.getType());
-        }
+	URL context;
+	if(repository.toString().endsWith("/")) {
+	    context = repository;
+	} else {
+	    context = new URL(repository.toString()+"/");
+	}
+
+	String qualifiedVersion = configId.getVersion().toString();
+	if (configId.getVersion() instanceof SnapshotVersion) {
+            SnapshotVersion ssVersion = (SnapshotVersion)configId.getVersion();
+            String timestamp = ssVersion.getTimestamp();
+            int buildNumber = ssVersion.getBuildNumber();
+            if (timestamp!=null && buildNumber!=0) {
+                qualifiedVersion = qualifiedVersion.replaceAll("SNAPSHOT", timestamp + "-"
+ buildNumber);
+            }
+	}
+        return new URL(context, configId.getGroupId().replace('.','/') + "/"
+                     + configId.getArtifactId() + "/" + configId.getVersion()
+                     + "/" +configId.getArtifactId() + "-"
+                     + qualifiedVersion + "." +configId.getType());
     }
 
     /**
@@ -915,14 +930,16 @@
      *                                    in question
      */
     private static OpenResult openStream(Artifact artifact, URL[] repos, String username,
String password, ResultsFileWriteMonitor monitor) throws IOException, FailedLoginException,
MissingDependencyException {
+        if(artifact != null) {
+            if (!artifact.isResolved() || artifact.getVersion().toString().indexOf("SNAPSHOT")
>= 0) {
+                artifact = findArtifact(artifact, repos, username, password, monitor);
+            }
+        }
         if(monitor != null) {
             monitor.getResults().setCurrentFilePercent(-1);
             monitor.getResults().setCurrentMessage("Downloading "+artifact+"...");
             monitor.setTotalBytes(-1); // In case the server doesn't say
         }
-        if(artifact != null && !artifact.isResolved()) {
-            artifact = findArtifact(artifact, repos, username, password, monitor);
-        }
         InputStream in;
         LinkedList list = new LinkedList();
         list.addAll(Arrays.asList(repos));
@@ -1071,14 +1088,42 @@
         Arrays.sort(available);
         for(int i=available.length-1; i>=0; i--) {
             Version version = available[i];
-            URL test = new URL(url.toString()+base+"/"+version+"/"+query.getArtifactId()+"-"+version+"."+query.getType());
+            URL metadataURL = new URL(url.toString()+base+"/"+version+"/maven-metadata.xml");
+            InputStream metadataStream = connect(metadataURL, username, password, monitor);
+            
+            // check for a snapshot qualifier
+            if (metadataStream != null) {
+                DocumentBuilder metadatabuilder = XmlUtil.newDocumentBuilderFactory().newDocumentBuilder();
+                Document metadatadoc = metadatabuilder.parse(metadataStream);
+                NodeList snapshots = metadatadoc.getDocumentElement().getElementsByTagName("snapshot");
+                if (snapshots.getLength() >= 1) {
+                    Element snapshot = (Element)snapshots.item(0);
+                    String[] timestamp = getChildrenText(snapshot, "timestamp");
+                    String[] buildNumber = getChildrenText(snapshot, "buildNumber");
+                    if (timestamp.length>=1 && buildNumber.length>=1) {
+                        try {
+                            SnapshotVersion snapshotVersion = new SnapshotVersion(version);
+                            snapshotVersion.setBuildNumber(Integer.parseInt(buildNumber[0]));
+                            snapshotVersion.setTimestamp(timestamp[0]);
+                            version = snapshotVersion;
+                        } catch (NumberFormatException nfe) {
+                            log.warn("Could not create snapshot version for " + query);
+                        }
+                    }
+                }
+                metadataStream.close();
+            }
+            
+            // look for the artifact in the maven repo
+            Artifact verifiedArtifact = new Artifact(query.getGroupId(), query.getArtifactId(),
version, query.getType()); 
+            URL test = getURL(verifiedArtifact, url);
             InputStream testStream = connect(test, username, password, monitor, "HEAD");
             if(testStream == null) {
                 log.warn("Maven repository "+url+" listed artifact "+query+" version "+version+"
but I couldn't find it at "+test);
                 continue;
             }
             testStream.close();
-            return new Artifact(query.getGroupId(), query.getArtifactId(), version, query.getType());
+            return verifiedArtifact; 
         }
         return null;
     }

Added: geronimo/server/branches/1.1/modules/system/src/java/org/apache/geronimo/system/plugin/SnapshotVersion.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/1.1/modules/system/src/java/org/apache/geronimo/system/plugin/SnapshotVersion.java?view=auto&rev=474454
==============================================================================
--- geronimo/server/branches/1.1/modules/system/src/java/org/apache/geronimo/system/plugin/SnapshotVersion.java
(added)
+++ geronimo/server/branches/1.1/modules/system/src/java/org/apache/geronimo/system/plugin/SnapshotVersion.java
Mon Nov 13 11:29:36 2006
@@ -0,0 +1,91 @@
+/**
+ *
+ *  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.system.plugin;
+
+import org.apache.geronimo.kernel.repository.Version;
+
+/**
+ * SnapshotVersion is like Version but holds extra fields that appear in the
+ * filename of a snapshot artifact. The toString() method is not overriden
+ * because the super implementation produces the correct string for navigating
+ * the directory structure of a plugin repository. The extra fields maintained
+ * in this class are needed for constructing the filename portion of a URL for a
+ * snapshot artifact where the qualifier and build number are replaced with a
+ * snapshot timestamp and build number.
+ * 
+ * @version $Rev$ $Date$
+ * 
+ */
+public class SnapshotVersion extends Version {
+    private static final long serialVersionUID = -4165276456639945508L;
+
+    private Integer buildNumber;
+
+    private String timestamp;
+
+    public SnapshotVersion(Version version) {
+        super(version.toString());
+    }
+
+    public SnapshotVersion(String version) {
+        super(version);
+    }
+
+    public int getBuildNumber() {
+        return buildNumber != null ? buildNumber.intValue() : 0;
+    }
+
+    public void setBuildNumber(int buildNumber) {
+        this.buildNumber = new Integer(buildNumber);
+    }
+
+    public String getTimestamp() {
+        return timestamp;
+    }
+
+    public void setTimestamp(String timestamp) {
+        this.timestamp = timestamp;
+    }
+
+    public boolean equals(Object other) {
+        if (super.equals(other)) {
+            if (other instanceof SnapshotVersion) {
+                SnapshotVersion v = (SnapshotVersion) other;
+                if (buildNumber == null ? v.buildNumber != null : !buildNumber.equals(v.buildNumber))
{
+                    return false;
+                }
+                if (timestamp == null ? v.timestamp != null : !timestamp.equals(v.timestamp))
{
+                    return false;
+                }
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public int hashCode() {
+        int hashCode = super.hashCode();
+        if (buildNumber != null) {
+            hashCode = 37 * hashCode + buildNumber.hashCode();
+        }
+        if (timestamp != null) {
+            hashCode = 37 * hashCode + timestamp.hashCode();
+        }
+        return hashCode;
+    }
+}

Propchange: geronimo/server/branches/1.1/modules/system/src/java/org/apache/geronimo/system/plugin/SnapshotVersion.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/branches/1.1/modules/system/src/java/org/apache/geronimo/system/plugin/SnapshotVersion.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/server/branches/1.1/modules/system/src/java/org/apache/geronimo/system/plugin/SnapshotVersion.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message