[jboss-cvs] JBossAS SVN: r112221 - projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/upgrader.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Sep 9 10:29:31 EDT 2011
Author: jesper.pedersen
Date: 2011-09-09 10:29:31 -0400 (Fri, 09 Sep 2011)
New Revision: 112221
Added:
projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/upgrader/MavenMetadata.java
Modified:
projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/upgrader/Http.java
projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/upgrader/Main.java
projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/upgrader/ModuleXml.java
Log:
[JBJCA-671] Support for snapshot version
Modified: projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/upgrader/Http.java
===================================================================
--- projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/upgrader/Http.java 2011-09-09 14:25:59 UTC (rev 112220)
+++ projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/upgrader/Http.java 2011-09-09 14:29:31 UTC (rev 112221)
@@ -23,6 +23,7 @@
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -108,4 +109,68 @@
return false;
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public String get(String path)
+ {
+ boolean redirect = HttpURLConnection.getFollowRedirects();
+ HttpURLConnection.setFollowRedirects(true);
+
+ InputStream is = null;
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ try
+ {
+ URL u = new URL(path);
+ URLConnection connection = u.openConnection();
+
+ connection.connect();
+
+ is = new BufferedInputStream(connection.getInputStream(), 8192);
+
+ int b;
+ while ((b = is.read()) != -1)
+ {
+ os.write(b);
+ }
+
+ os.flush();
+
+ return new String(os.toByteArray(), "UTF-8");
+ }
+ catch (Throwable t)
+ {
+ // Nothing to do
+ }
+ finally
+ {
+ if (is != null)
+ {
+ try
+ {
+ is.close();
+ }
+ catch (IOException ignore)
+ {
+ // Ignore
+ }
+ }
+ if (os != null)
+ {
+ try
+ {
+ os.close();
+ }
+ catch (IOException ignore)
+ {
+ // Ignore
+ }
+ }
+
+ HttpURLConnection.setFollowRedirects(redirect);
+ }
+
+ return "";
+ }
}
Modified: projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/upgrader/Main.java
===================================================================
--- projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/upgrader/Main.java 2011-09-09 14:25:59 UTC (rev 112220)
+++ projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/upgrader/Main.java 2011-09-09 14:29:31 UTC (rev 112221)
@@ -39,10 +39,14 @@
*/
public class Main
{
- /** REpository */
- public static final String REPOSITORY =
+ /** Release repository */
+ public static final String RELEASE_REPOSITORY =
"http://repository.jboss.org/nexus/content/groups/public/org/jboss/ironjacamar";
+ /** Snapshot repository */
+ public static final String SNAPSHOT_REPOSITORY =
+ "http://repository.jboss.org/nexus/content/repositories/snapshots/org/jboss/ironjacamar";
+
/**
* API artifacts
*/
@@ -157,19 +161,48 @@
toDirectory.mkdirs();
- for (String artifact : API_ARTIFACTS)
+ if (version.endsWith("-SNAPSHOT"))
{
- downloadArtifact(artifact, version, toDirectory);
+ for (String artifact : API_ARTIFACTS)
+ {
+ String snapshotVersion = MavenMetadata.getVersion(SNAPSHOT_REPOSITORY + "/" + artifact + "/" +
+ version + "/maven-metadata.xml");
+
+ downloadSnapshotArtifact(artifact, version, snapshotVersion, toDirectory);
+ }
+
+ for (String artifact : IMPLEMENTATION_ARTIFACTS)
+ {
+ String snapshotVersion = MavenMetadata.getVersion(SNAPSHOT_REPOSITORY + "/" + artifact + "/" +
+ version + "/maven-metadata.xml");
+
+ downloadSnapshotArtifact(artifact, version, snapshotVersion, toDirectory);
+ }
+
+ for (String artifact : JDBC_ARTIFACTS)
+ {
+ String snapshotVersion = MavenMetadata.getVersion(SNAPSHOT_REPOSITORY + "/" + artifact + "/" +
+ version + "/maven-metadata.xml");
+
+ downloadSnapshotArtifact(artifact, version, snapshotVersion, toDirectory);
+ }
}
-
- for (String artifact : IMPLEMENTATION_ARTIFACTS)
+ else
{
- downloadArtifact(artifact, version, toDirectory);
- }
+ for (String artifact : API_ARTIFACTS)
+ {
+ downloadArtifact(artifact, version, toDirectory);
+ }
- for (String artifact : JDBC_ARTIFACTS)
- {
- downloadArtifact(artifact, version, toDirectory);
+ for (String artifact : IMPLEMENTATION_ARTIFACTS)
+ {
+ downloadArtifact(artifact, version, toDirectory);
+ }
+
+ for (String artifact : JDBC_ARTIFACTS)
+ {
+ downloadArtifact(artifact, version, toDirectory);
+ }
}
System.out.println("Download: Done");
@@ -184,18 +217,39 @@
* @param dest The destination
* @exception Throwable If an error occurs
*/
- private static void downloadArtifact(String name, String version, File destination) throws Throwable
+ private static void downloadArtifact(String name, String version, File destination)
+ throws Throwable
{
Http downloader = new Http();
- String fileName = name + "-" + version + ".jar";
- String path = REPOSITORY + "/" + name + "/" + version + "/" + fileName;
+ String fileName = name + "-" + version + ".jar";;
+ String path = RELEASE_REPOSITORY + "/" + name + "/" + version + "/" + fileName;;
if (!downloader.download(path, new File(destination, fileName)))
throw new IOException("Could not download: " + path);
}
/**
+ * Download snapshot artifact
+ * @param name The artifact name
+ * @param version The version
+ * @param snapshotVersion The snapshot version
+ * @param dest The destination
+ * @exception Throwable If an error occurs
+ */
+ private static void downloadSnapshotArtifact(String name, String version, String snapshotVersion, File destination)
+ throws Throwable
+ {
+ Http downloader = new Http();
+
+ String fileName = name + "-" + snapshotVersion + ".jar";;
+ String path = SNAPSHOT_REPOSITORY + "/" + name + "/" + version + "/" + fileName;;
+
+ if (!downloader.download(path, new File(destination, fileName)))
+ throw new IOException("Could not download: " + path);
+ }
+
+ /**
* Move the old version
* @param root The root
* @exception Throwable If an error occurs
@@ -248,7 +302,15 @@
int firstDot = name.indexOf(".");
int jar = name.indexOf(".jar");
- return name.substring(firstDot - 1, jar);
+ String s = name.substring(firstDot - 1, jar);
+ if (s.indexOf("-") == -1)
+ {
+ return s;
+ }
+ else
+ {
+ return s.substring(0, s.indexOf("-")) + "-SNAPSHOT";
+ }
}
}
@@ -398,15 +460,14 @@
File apiMain = new File(apiRoot, "main");
apiMain.mkdirs();
- for (String artifact : API_ARTIFACTS)
- {
- installArtifact(fromDirectory, artifact, version, apiMain);
- }
+ String commonApiVersion = installArtifact(fromDirectory, API_ARTIFACTS[0], apiMain);
+ String commonSpiVersion = installArtifact(fromDirectory, API_ARTIFACTS[1], apiMain);
+ String coreApiVersion = installArtifact(fromDirectory, API_ARTIFACTS[2], apiMain);
File apiModuleXml = new File(apiMain, "module.xml");
FileWriter fw = new FileWriter(apiModuleXml);
- for (String s : ModuleXml.getApi(version))
+ for (String s : ModuleXml.getApi(commonApiVersion, commonSpiVersion, coreApiVersion))
{
fw.write(s);
fw.write("\n");
@@ -418,15 +479,16 @@
File implMain = new File(implRoot, "main");
implMain.mkdirs();
- for (String artifact : IMPLEMENTATION_ARTIFACTS)
- {
- installArtifact(fromDirectory, artifact, version, implMain);
- }
+ String commonImplVersion = installArtifact(fromDirectory, IMPLEMENTATION_ARTIFACTS[0], implMain);
+ String coreImplVersion = installArtifact(fromDirectory, IMPLEMENTATION_ARTIFACTS[1], implMain);
+ String deployersCommonVersion = installArtifact(fromDirectory, IMPLEMENTATION_ARTIFACTS[2], implMain);
+ String validatorVersion = installArtifact(fromDirectory, IMPLEMENTATION_ARTIFACTS[3], implMain);
File implModuleXml = new File(implMain, "module.xml");
fw = new FileWriter(implModuleXml);
- for (String s : ModuleXml.getImplementation(version))
+ for (String s : ModuleXml.getImplementation(commonImplVersion, coreImplVersion,
+ deployersCommonVersion, validatorVersion))
{
fw.write(s);
fw.write("\n");
@@ -438,15 +500,12 @@
File jdbcMain = new File(jdbcRoot, "main");
jdbcMain.mkdirs();
- for (String artifact : JDBC_ARTIFACTS)
- {
- installArtifact(fromDirectory, artifact, version, jdbcMain);
- }
+ String jdbcVersion = installArtifact(fromDirectory, JDBC_ARTIFACTS[0], jdbcMain);
File jdbcModuleXml = new File(jdbcMain, "module.xml");
fw = new FileWriter(jdbcModuleXml);
- for (String s : ModuleXml.getJdbc(version))
+ for (String s : ModuleXml.getJdbc(jdbcVersion))
{
fw.write(s);
fw.write("\n");
@@ -462,15 +521,30 @@
* Install artifact
* @param from The from directory
* @param artifact The artifact name
- * @param version The version
* @param to The to directory
+ * @return The version number
* @exception Throwable If an error occurs
*/
- private static void installArtifact(File from, String artifact, String version, File to) throws Throwable
+ private static String installArtifact(File from, String artifact, File to) throws Throwable
{
- File src = new File(from, artifact + "-" + version + ".jar");
- File dest = new File(to, artifact + "-" + version + ".jar");
+ File[] files = from.listFiles();
- copy(src, dest);
+ for (File f : files)
+ {
+ if (f.getName().startsWith(artifact))
+ {
+ File dest = new File(to, f.getName());
+ copy(f, dest);
+
+ String version = f.getName();
+
+ version = version.substring(artifact.length() + 1);
+ version = version.substring(0, version.length() - 4);
+
+ return version;
+ }
+ }
+
+ throw new IOException(artifact + " couldn't be found");
}
}
Added: projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/upgrader/MavenMetadata.java
===================================================================
--- projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/upgrader/MavenMetadata.java (rev 0)
+++ projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/upgrader/MavenMetadata.java 2011-09-09 14:29:31 UTC (rev 112221)
@@ -0,0 +1,110 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.as.upgrader;
+
+import java.io.StringReader;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+/**
+ * maven-metadata.xml utilities
+ *
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class MavenMetadata
+{
+ /**
+ * Get the version from the specified url
+ * @param url The url
+ * @return The value
+ */
+ public static String getVersion(String url)
+ {
+ try
+ {
+ Http http = new Http();
+ String mavenMetadataXml = http.get(url);
+
+ StringReader sr = new StringReader(mavenMetadataXml);
+
+ XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
+ XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(sr);
+
+ while (xmlStreamReader.hasNext())
+ {
+ int eventCode = xmlStreamReader.next();
+
+ switch (eventCode)
+ {
+ case XMLStreamReader.START_ELEMENT :
+
+ if ("value".equals(xmlStreamReader.getLocalName()))
+ {
+ return readString(xmlStreamReader);
+ }
+
+ break;
+ default :
+ }
+ }
+ }
+ catch (Throwable t)
+ {
+ // Nothing to do
+ }
+
+ return null;
+ }
+
+ /**
+ * Read a string
+ * @param xmlStreamReader The XML stream
+ * @return The parameter
+ * @exception XMLStreamException Thrown if an exception occurs
+ */
+ private static String readString(XMLStreamReader xmlStreamReader) throws XMLStreamException
+ {
+ String result = null;
+
+ int eventCode = xmlStreamReader.next();
+
+ while (eventCode != XMLStreamReader.END_ELEMENT)
+ {
+ switch (eventCode)
+ {
+ case XMLStreamReader.CHARACTERS :
+ if (!xmlStreamReader.getText().trim().equals(""))
+ result = xmlStreamReader.getText().trim();
+
+ break;
+
+ default :
+ }
+
+ eventCode = xmlStreamReader.next();
+ }
+
+ return result;
+ }
+}
Modified: projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/upgrader/ModuleXml.java
===================================================================
--- projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/upgrader/ModuleXml.java 2011-09-09 14:25:59 UTC (rev 112220)
+++ projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/upgrader/ModuleXml.java 2011-09-09 14:29:31 UTC (rev 112221)
@@ -59,10 +59,14 @@
/**
* Get the API definiton
- * @param version The version
+ * @param commonApiVersion The version
+ * @param commonSpiVersion The version
+ * @param coreApiVersion The version
* @return The value
*/
- public static List<String> getApi(String version)
+ public static List<String> getApi(String commonApiVersion,
+ String commonSpiVersion,
+ String coreApiVersion)
{
List<String> result = new ArrayList<String>();
@@ -75,9 +79,9 @@
result.add("<module xmlns=\"urn:jboss:module:1.0\" name=\"org.jboss.ironjacamar.api\">");
result.add(" <resources>");
- result.add(" <resource-root path=\"ironjacamar-common-api-" + version + ".jar\"/>");
- result.add(" <resource-root path=\"ironjacamar-common-spi-" + version + ".jar\"/>");
- result.add(" <resource-root path=\"ironjacamar-core-api-" + version + ".jar\"/>");
+ result.add(" <resource-root path=\"ironjacamar-common-api-" + commonApiVersion + ".jar\"/>");
+ result.add(" <resource-root path=\"ironjacamar-common-spi-" + commonSpiVersion + ".jar\"/>");
+ result.add(" <resource-root path=\"ironjacamar-core-api-" + coreApiVersion + ".jar\"/>");
result.add(" </resources>");
result.add("");
@@ -96,10 +100,16 @@
/**
* Get the implementation definiton
- * @param version The version
+ * @param commonImplVersion The version
+ * @param coreImplVersion The version
+ * @param deployersCommonVersion The version
+ * @param validatorVersion The version
* @return The value
*/
- public static List<String> getImplementation(String version)
+ public static List<String> getImplementation(String commonImplVersion,
+ String coreImplVersion,
+ String deployersCommonVersion,
+ String validatorVersion)
{
List<String> result = new ArrayList<String>();
@@ -112,10 +122,10 @@
result.add("<module xmlns=\"urn:jboss:module:1.0\" name=\"org.jboss.ironjacamar.impl\">");
result.add(" <resources>");
- result.add(" <resource-root path=\"ironjacamar-common-impl-" + version + ".jar\"/>");
- result.add(" <resource-root path=\"ironjacamar-core-impl-" + version + ".jar\"/>");
- result.add(" <resource-root path=\"ironjacamar-deployers-common-" + version + ".jar\"/>");
- result.add(" <resource-root path=\"ironjacamar-validator-" + version + ".jar\"/>");
+ result.add(" <resource-root path=\"ironjacamar-common-impl-" + commonImplVersion + ".jar\"/>");
+ result.add(" <resource-root path=\"ironjacamar-core-impl-" + coreImplVersion + ".jar\"/>");
+ result.add(" <resource-root path=\"ironjacamar-deployers-common-" + deployersCommonVersion + ".jar\"/>");
+ result.add(" <resource-root path=\"ironjacamar-validator-" + validatorVersion + ".jar\"/>");
result.add(" </resources>");
result.add("");
@@ -143,10 +153,10 @@
/**
* Get the JDBC definiton
- * @param version The version
+ * @param jdbcVersion The version
* @return The value
*/
- public static List<String> getJdbc(String version)
+ public static List<String> getJdbc(String jdbcVersion)
{
List<String> result = new ArrayList<String>();
@@ -159,7 +169,7 @@
result.add("<module xmlns=\"urn:jboss:module:1.0\" name=\"org.jboss.ironjacamar.jdbcadapters\">");
result.add(" <resources>");
- result.add(" <resource-root path=\"ironjacamar-jdbc-" + version + ".jar\"/>");
+ result.add(" <resource-root path=\"ironjacamar-jdbc-" + jdbcVersion + ".jar\"/>");
result.add(" </resources>");
result.add("");
More information about the jboss-cvs-commits
mailing list