You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by pm...@apache.org on 2006/10/30 19:36:39 UTC
svn commit: r469226 - in
/geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin:
PluginInstallerGBean.java SnapshotVersion.java
Author: pmcmahan
Date: Mon Oct 30 10:36:39 2006
New Revision: 469226
URL: http://svn.apache.org/viewvc?view=rev&rev=469226
Log:
GERONIMO-2521 add support for maven2 style snapshot download URLs to plugin installer gbean
Added:
geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/SnapshotVersion.java (with props)
Modified:
geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/PluginInstallerGBean.java
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?view=diff&rev=469226&r1=469225&r2=469226
==============================================================================
--- 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 Mon Oct 30 10:36:39 2006
@@ -889,11 +889,28 @@
* 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();
+ qualifiedVersion = ssVersion.getMajorVersion() + "." + ssVersion.getMinorVersion();
+ if (ssVersion.getTimestamp()!=null) {
+ qualifiedVersion += "-" + ssVersion.getTimestamp();
+ }
+ if (ssVersion.getBuildNumber()!=0) {
+ qualifiedVersion += "-" + ssVersion.getBuildNumber();
+ }
+ }
+ return new URL(context, configId.getGroupId().replace('.','/') + "/"
+ + configId.getArtifactId() + "/" + configId.getVersion()
+ + "/" +configId.getArtifactId() + "-"
+ + qualifiedVersion + "." +configId.getType());
}
/**
@@ -920,8 +937,10 @@
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);
+ if(artifact != null) {
+ if (!artifact.isResolved() || artifact.getVersion().toString().indexOf("SNAPSHOT") >= 0) {
+ artifact = findArtifact(artifact, repos, username, password, monitor);
+ }
}
InputStream in;
LinkedList list = new LinkedList();
@@ -1071,14 +1090,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/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/SnapshotVersion.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/SnapshotVersion.java?view=auto&rev=469226
==============================================================================
--- geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/SnapshotVersion.java (added)
+++ geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/SnapshotVersion.java Mon Oct 30 10:36:39 2006
@@ -0,0 +1,90 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed 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 $Revision$ $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/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/SnapshotVersion.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/SnapshotVersion.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/SnapshotVersion.java
------------------------------------------------------------------------------
svn:mime-type = text/plain