[jboss-cvs] JBossAS SVN: r84767 - in projects/ejb3/trunk: ivy and 20 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Feb 25 17:34:02 EST 2009
Author: wolfc
Date: 2009-02-25 17:34:02 -0500 (Wed, 25 Feb 2009)
New Revision: 84767
Added:
projects/ejb3/trunk/ivy/
projects/ejb3/trunk/ivy/.classpath
projects/ejb3/trunk/ivy/.project
projects/ejb3/trunk/ivy/build.xml
projects/ejb3/trunk/ivy/ivy.xml
projects/ejb3/trunk/ivy/src/
projects/ejb3/trunk/ivy/src/main/
projects/ejb3/trunk/ivy/src/main/ivy/
projects/ejb3/trunk/ivy/src/main/ivy/ivysettings-jboss-repo.xml
projects/ejb3/trunk/ivy/src/main/ivy/ivysettings-jboss-snapshots.xml
projects/ejb3/trunk/ivy/src/main/ivy/ivysettings-main-chain.xml
projects/ejb3/trunk/ivy/src/main/ivy/ivysettings.xml
projects/ejb3/trunk/ivy/src/main/java/
projects/ejb3/trunk/ivy/src/main/java/org/
projects/ejb3/trunk/ivy/src/main/java/org/jboss/
projects/ejb3/trunk/ivy/src/main/java/org/jboss/ejb3/
projects/ejb3/trunk/ivy/src/main/java/org/jboss/ejb3/ivy/
projects/ejb3/trunk/ivy/src/main/java/org/jboss/ejb3/ivy/plugins/
projects/ejb3/trunk/ivy/src/main/java/org/jboss/ejb3/ivy/plugins/resolver/
projects/ejb3/trunk/ivy/src/main/java/org/jboss/ejb3/ivy/plugins/resolver/MavenSnapshotResolver.java
projects/ejb3/trunk/ivy/src/main/java/org/jboss/ejb3/ivy/plugins/version/
projects/ejb3/trunk/ivy/src/main/java/org/jboss/ejb3/ivy/plugins/version/MavenVersionMatcher.java
projects/ejb3/trunk/ivy/src/test/
projects/ejb3/trunk/ivy/src/test/java/
projects/ejb3/trunk/ivy/src/test/java/org/
projects/ejb3/trunk/ivy/src/test/java/org/jboss/
projects/ejb3/trunk/ivy/src/test/java/org/jboss/ejb3/
projects/ejb3/trunk/ivy/src/test/java/org/jboss/ejb3/ivy/
projects/ejb3/trunk/ivy/src/test/java/org/jboss/ejb3/ivy/plugins/
projects/ejb3/trunk/ivy/src/test/java/org/jboss/ejb3/ivy/plugins/resolver/
projects/ejb3/trunk/ivy/src/test/java/org/jboss/ejb3/ivy/plugins/resolver/MavenSnapshotResolverTestCase.java
projects/ejb3/trunk/ivy/src/test/resources/
projects/ejb3/trunk/ivy/src/test/resources/ivysettings.xml
Log:
EJBTHREE-1744: initial import
Property changes on: projects/ejb3/trunk/ivy
___________________________________________________________________
Name: svn:ignore
+ eclipse-target
Added: projects/ejb3/trunk/ivy/.classpath
===================================================================
--- projects/ejb3/trunk/ivy/.classpath (rev 0)
+++ projects/ejb3/trunk/ivy/.classpath 2009-02-25 22:34:02 UTC (rev 84767)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" path="src/test/java"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.apache.ivyde.eclipse.cpcontainer.IVYDE_CONTAINER/?ivyXmlPath=ivy.xml&confs=*"/>
+ <classpathentry kind="output" path="target/eclipse-classes"/>
+</classpath>
Added: projects/ejb3/trunk/ivy/.project
===================================================================
--- projects/ejb3/trunk/ivy/.project (rev 0)
+++ projects/ejb3/trunk/ivy/.project 2009-02-25 22:34:02 UTC (rev 84767)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>jboss-ejb3-ivy</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Added: projects/ejb3/trunk/ivy/build.xml
===================================================================
--- projects/ejb3/trunk/ivy/build.xml (rev 0)
+++ projects/ejb3/trunk/ivy/build.xml 2009-02-25 22:34:02 UTC (rev 84767)
@@ -0,0 +1,52 @@
+<!--
+ vi:ts=3:sw=3:expandtab:
+-->
+<project name="jboss-ejb3-ivy" xmlns:ivy="antlib:org.apache.ivy.ant"
+ default="package">
+ <path id="ivy.lib.path">
+ <fileset dir="/opt/apache-ivy" includes="*.jar"/>
+ </path>
+ <taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
+
+ <ivy:settings file="src/main/ivy/ivysettings.xml"/>
+
+ <target name="compile" depends="resolve">
+ <ivy:cachepath pathid="compile.classpath" conf="compile"/>
+
+ <mkdir dir="target/classes"/>
+ <javac srcdir="src/main/java" destdir="target/classes" classpathref="compile.classpath"/>
+ </target>
+
+ <target name="package" depends="compile">
+ <jar destfile="target/jboss-ejb3-ivy.jar">
+ <fileset dir="target/classes"/>
+ </jar>
+ </target>
+
+ <target name="resolve">
+ <ivy:resolve/>
+ </target>
+
+ <target name="test" depends="test-compile">
+ <mkdir dir="target/reports"/>
+ <junit printsummary="true">
+ <classpath>
+ <pathelement path="target/classes"/>
+ <pathelement path="target/test-classes"/>
+ <path refid="test.classpath"/>
+ </classpath>
+ <formatter type="plain"/>
+ <formatter type="xml"/>
+ <batchtest todir="target/reports">
+ <fileset dir="src/test/java" includes="**/*Test*.java"/>
+ </batchtest>
+ </junit>
+ </target>
+
+ <target name="test-compile" depends="compile">
+ <ivy:cachepath pathid="test.classpath" conf="test"/>
+
+ <mkdir dir="target/test-classes"/>
+ <javac srcdir="src/test/java" destdir="target/test-classes" classpathref="test.classpath"/>
+ </target>
+</project>
Added: projects/ejb3/trunk/ivy/ivy.xml
===================================================================
--- projects/ejb3/trunk/ivy/ivy.xml (rev 0)
+++ projects/ejb3/trunk/ivy/ivy.xml 2009-02-25 22:34:02 UTC (rev 84767)
@@ -0,0 +1,15 @@
+<!--
+ vi:ts=3:sw=3:expandtab:
+-->
+<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
+ <info organisation="org.jboss.ejb3" module="jboss-ejb3-ivy"/>
+ <configurations>
+ <conf name="compile"/>
+ <conf name="test" extends="compile" visibility="private"/>
+ </configurations>
+ <dependencies>
+ <dependency org="org.apache.ivy" name="ivy" rev="2.0.0" conf="compile->default"/>
+ <dependency org="junit" name="junit" rev="4.4" conf="test->default"/>
+ </dependencies>
+</ivy-module>
Added: projects/ejb3/trunk/ivy/src/main/ivy/ivysettings-jboss-repo.xml
===================================================================
--- projects/ejb3/trunk/ivy/src/main/ivy/ivysettings-jboss-repo.xml (rev 0)
+++ projects/ejb3/trunk/ivy/src/main/ivy/ivysettings-jboss-repo.xml 2009-02-25 22:34:02 UTC (rev 84767)
@@ -0,0 +1,13 @@
+<!--
+ vi:ts=2:sw=2:expandtab:
+-->
+<ivysettings>
+ <resolvers>
+ <ibiblio name="repository.jboss.org" m2compatible="true" usepoms="true" root="http://repository.jboss.org/maven2"/>
+ <!--
+ <url name="repository.jboss.org" m2compatible="true">
+ <artifact pattern="http://repository.jboss.org/maven2/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]"/>
+ </url>
+ -->
+ </resolvers>
+</ivysettings>
Added: projects/ejb3/trunk/ivy/src/main/ivy/ivysettings-jboss-snapshots.xml
===================================================================
--- projects/ejb3/trunk/ivy/src/main/ivy/ivysettings-jboss-snapshots.xml (rev 0)
+++ projects/ejb3/trunk/ivy/src/main/ivy/ivysettings-jboss-snapshots.xml 2009-02-25 22:34:02 UTC (rev 84767)
@@ -0,0 +1,13 @@
+<!--
+ vi:ts=2:sw=2:expandtab:
+-->
+<ivysettings>
+ <resolvers>
+ <!-- version 1
+ <url name="snapshots.jboss.org" m2compatible="true">
+ <artifact pattern="http://snapshots.jboss.org/maven2/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]"/>
+ </url>
+ -->
+ <ibiblio name="snapshots.jboss.org" m2compatible="true" usepoms="true" root="http://snapshots.jboss.org/maven2"/>
+ </resolvers>
+</ivysettings>
Added: projects/ejb3/trunk/ivy/src/main/ivy/ivysettings-main-chain.xml
===================================================================
--- projects/ejb3/trunk/ivy/src/main/ivy/ivysettings-main-chain.xml (rev 0)
+++ projects/ejb3/trunk/ivy/src/main/ivy/ivysettings-main-chain.xml 2009-02-25 22:34:02 UTC (rev 84767)
@@ -0,0 +1,13 @@
+<!--
+ vi:ts=2:sw=2:expandtab
+-->
+<ivysettings>
+ <resolvers>
+ <chain name="main" dual="true">
+ <resolver ref="shared"/>
+ <resolver ref="repository.jboss.org"/>
+ <resolver ref="snapshots.jboss.org"/>
+ <resolver ref="public"/>
+ </chain>
+ </resolvers>
+</ivysettings>
Added: projects/ejb3/trunk/ivy/src/main/ivy/ivysettings.xml
===================================================================
--- projects/ejb3/trunk/ivy/src/main/ivy/ivysettings.xml (rev 0)
+++ projects/ejb3/trunk/ivy/src/main/ivy/ivysettings.xml 2009-02-25 22:34:02 UTC (rev 84767)
@@ -0,0 +1,14 @@
+<!--
+ vi:ts=2:sw=2:expandtab:
+-->
+<ivysettings>
+ <settings defaultResolver="default"/>
+ <include url="ivysettings-jboss-snapshots.xml"/>
+ <include url="ivysettings-jboss-repo.xml"/>
+ <include url="${ivy.default.settings.dir}/ivysettings-public.xml"/>
+ <include url="${ivy.default.settings.dir}/ivysettings-shared.xml"/>
+ <include url="${ivy.default.settings.dir}/ivysettings-local.xml"/>
+ <!--include url="${ivy.default.settings.dir}/ivysettings-main-chain.xml"/-->
+ <include url="ivysettings-main-chain.xml"/>
+ <include url="${ivy.default.settings.dir}/ivysettings-default-chain.xml"/>
+</ivysettings>
Added: projects/ejb3/trunk/ivy/src/main/java/org/jboss/ejb3/ivy/plugins/resolver/MavenSnapshotResolver.java
===================================================================
--- projects/ejb3/trunk/ivy/src/main/java/org/jboss/ejb3/ivy/plugins/resolver/MavenSnapshotResolver.java (rev 0)
+++ projects/ejb3/trunk/ivy/src/main/java/org/jboss/ejb3/ivy/plugins/resolver/MavenSnapshotResolver.java 2009-02-25 22:34:02 UTC (rev 84767)
@@ -0,0 +1,695 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.ejb3.ivy.plugins.resolver;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.ivy.core.IvyPatternHelper;
+import org.apache.ivy.core.cache.ArtifactOrigin;
+import org.apache.ivy.core.module.descriptor.Artifact;
+import org.apache.ivy.core.module.descriptor.DefaultArtifact;
+import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor;
+import org.apache.ivy.core.module.descriptor.DependencyDescriptor;
+import org.apache.ivy.core.module.id.ModuleRevisionId;
+import org.apache.ivy.core.report.DownloadReport;
+import org.apache.ivy.core.resolve.DownloadOptions;
+import org.apache.ivy.core.resolve.ResolveData;
+import org.apache.ivy.core.resolve.ResolvedModuleRevision;
+import org.apache.ivy.core.search.ModuleEntry;
+import org.apache.ivy.core.search.OrganisationEntry;
+import org.apache.ivy.core.search.RevisionEntry;
+import org.apache.ivy.plugins.matcher.PatternMatcher;
+import org.apache.ivy.plugins.repository.Repository;
+import org.apache.ivy.plugins.repository.Resource;
+import org.apache.ivy.plugins.resolver.ResolverSettings;
+import org.apache.ivy.plugins.resolver.URLResolver;
+import org.apache.ivy.plugins.resolver.util.ResolvedResource;
+import org.apache.ivy.util.ContextualSAXHandler;
+import org.apache.ivy.util.Message;
+import org.apache.ivy.util.XMLHelper;
+import org.xml.sax.SAXException;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class MavenSnapshotResolver extends URLResolver
+{
+ private final static Pattern VERSION_PATTERN = Pattern.compile("(\\d+)\\.(\\d+)\\.(\\d+)-\\d{8}\\.\\d{6}-\\d+");
+
+ private static final String M2_PER_MODULE_PATTERN = "[revision]/[artifact]-[revision](-[classifier]).[ext]";
+
+ private static final String M2_PATTERN = "[organisation]/[module]/" + M2_PER_MODULE_PATTERN;
+
+ public static final String DEFAULT_PATTERN = "[module]/[type]s/[artifact]-[revision].[ext]";
+
+ public static final String DEFAULT_ROOT = "http://www.ibiblio.org/maven/";
+
+ public static final String DEFAULT_M2_ROOT = "http://repo1.maven.org/maven2/";
+
+ private String root = null;
+
+ private String pattern = null;
+
+ // use poms if m2 compatible is true
+ private boolean usepoms = true;
+
+ // use maven-metadata.xml is exists to list revisions
+ private boolean useMavenMetadata = true;
+
+ public MavenSnapshotResolver()
+ {
+ // SNAPSHOT revisions are changing revisions
+ setChangingMatcher(PatternMatcher.REGEXP);
+ setChangingPattern(".*-SNAPSHOT");
+ }
+
+ public ResolvedResource findIvyFileRef(DependencyDescriptor dd, ResolveData data)
+ {
+ if (isM2compatible() && isUsepoms())
+ {
+ ModuleRevisionId mrid = dd.getDependencyRevisionId();
+ mrid = convertM2IdForResourceSearch(mrid);
+
+ ResolvedResource rres = null;
+ if (dd.getDependencyRevisionId().getRevision().endsWith("SNAPSHOT"))
+ {
+ rres = findSnapshotDescriptor(dd, data, mrid);
+ if (rres != null)
+ {
+ return rres;
+ }
+ }
+
+ rres = findResourceUsingPatterns(mrid, getIvyPatterns(), DefaultArtifact.newPomArtifact(mrid, data.getDate()),
+ getRMDParser(dd, data), data.getDate());
+ return rres;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ protected ResolvedResource findArtifactRef(Artifact artifact, Date date)
+ {
+ ensureConfigured(getSettings());
+ ModuleRevisionId mrid = artifact.getModuleRevisionId();
+ if (isM2compatible())
+ {
+ mrid = convertM2IdForResourceSearch(mrid);
+ }
+ ResolvedResource rres = null;
+ if (artifact.getId().getRevision().endsWith("SNAPSHOT"))
+ {
+ rres = findSnapshotArtifact(artifact, date, mrid);
+ if (rres != null)
+ {
+ return rres;
+ }
+ }
+ String rev = artifact.getId().getRevision();
+ // TODO: we assume here that nobody will version releases according to this scheme
+ Matcher matcher = VERSION_PATTERN.matcher(rev);
+ if(matcher.matches())
+ {
+ // TODO: blazing through on shear luck, there could be less version digits
+ String originalRev = matcher.group(1) + "." + matcher.group(2) + "." + matcher.group(3) + "-SNAPSHOT";
+ String pattern = (String) getArtifactPatterns().get(0);
+ pattern = pattern.replaceFirst("\\[revision\\]", originalRev);
+ return findResourceUsingPattern(mrid, pattern, artifact, getDefaultRMDParser(artifact
+ .getModuleRevisionId().getModuleId()), date);
+ }
+ return findResourceUsingPatterns(mrid, getArtifactPatterns(), artifact, getDefaultRMDParser(artifact
+ .getModuleRevisionId().getModuleId()), date);
+ }
+
+ private ResolvedResource findSnapshotArtifact(Artifact artifact, Date date, ModuleRevisionId mrid)
+ {
+ String rev = findSnapshotVersion(mrid);
+ if (rev != null)
+ {
+ // replace the revision token in file name with the resolved revision
+ String pattern = (String) getArtifactPatterns().get(0);
+ pattern = pattern.replaceFirst("\\-\\[revision\\]", "-" + rev);
+ return findResourceUsingPattern(mrid, pattern, artifact, getDefaultRMDParser(artifact.getModuleRevisionId()
+ .getModuleId()), date);
+ }
+ return null;
+ }
+
+ private ResolvedResource findSnapshotDescriptor(DependencyDescriptor dd, ResolveData data, ModuleRevisionId mrid)
+ {
+ String rev = findSnapshotVersion(mrid);
+ if (rev != null)
+ {
+ // here it would be nice to be able to store the resolved snapshot version, to avoid
+ // having to follow the same process to download artifacts
+
+ Message.verbose("[" + rev + "] " + mrid);
+
+ // replace the revision token in file name with the resolved revision
+ String pattern = (String) getIvyPatterns().get(0);
+ pattern = pattern.replaceFirst("\\-\\[revision\\]", "-" + rev);
+ return findResourceUsingPattern(mrid, pattern, DefaultArtifact.newPomArtifact(mrid, data.getDate()),
+ getRMDParser(dd, data), data.getDate());
+ }
+ return null;
+ }
+
+ private String findSnapshotVersion(ModuleRevisionId mrid)
+ {
+ String pattern = (String) getIvyPatterns().get(0);
+ if (shouldUseMavenMetadata(pattern))
+ {
+ InputStream metadataStream = null;
+ try
+ {
+ String metadataLocation = IvyPatternHelper.substitute(root
+ + "[organisation]/[module]/[revision]/maven-metadata.xml", mrid);
+ Resource metadata = getRepository().getResource(metadataLocation);
+ if (metadata.exists())
+ {
+ metadataStream = metadata.openStream();
+ final StringBuffer timestamp = new StringBuffer();
+ final StringBuffer buildNumer = new StringBuffer();
+ XMLHelper.parse(metadataStream, null, new ContextualSAXHandler()
+ {
+ public void endElement(String uri, String localName, String qName) throws SAXException
+ {
+ if ("metadata/versioning/snapshot/timestamp".equals(getContext()))
+ {
+ timestamp.append(getText());
+ }
+ if ("metadata/versioning/snapshot/buildNumber".equals(getContext()))
+ {
+ buildNumer.append(getText());
+ }
+ super.endElement(uri, localName, qName);
+ }
+ }, null);
+ if (timestamp.length() > 0)
+ {
+ // we have found a timestamp, so this is a snapshot unique version
+ String rev = mrid.getRevision();
+ rev = rev.substring(0, rev.length() - "SNAPSHOT".length());
+ rev = rev + timestamp.toString() + "-" + buildNumer.toString();
+
+ return rev;
+ }
+ }
+ else
+ {
+ Message.verbose("\tmaven-metadata not available: " + metadata);
+ }
+ }
+ catch (IOException e)
+ {
+ Message.verbose("impossible to access maven metadata file, ignored: " + e.getMessage());
+ }
+ catch (SAXException e)
+ {
+ Message.verbose("impossible to parse maven metadata file, ignored: " + e.getMessage());
+ }
+ catch (ParserConfigurationException e)
+ {
+ Message.verbose("impossible to parse maven metadata file, ignored: " + e.getMessage());
+ }
+ finally
+ {
+ if (metadataStream != null)
+ {
+ try
+ {
+ metadataStream.close();
+ }
+ catch (IOException e)
+ {
+ // ignored
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ public void setM2compatible(boolean m2compatible)
+ {
+ super.setM2compatible(m2compatible);
+ if (m2compatible)
+ {
+ if (root == null)
+ {
+ root = DEFAULT_M2_ROOT;
+ }
+ if (pattern == null)
+ {
+ pattern = M2_PATTERN;
+ }
+ updateWholePattern();
+ }
+ }
+
+ public void ensureConfigured(ResolverSettings settings)
+ {
+ if (settings != null && (root == null || pattern == null))
+ {
+ if (root == null)
+ {
+ String root = settings.getVariable("ivy.ibiblio.default.artifact.root");
+ if (root != null)
+ {
+ this.root = root;
+ }
+ else
+ {
+ settings.configureRepositories(true);
+ this.root = settings.getVariable("ivy.ibiblio.default.artifact.root");
+ }
+ }
+ if (pattern == null)
+ {
+ String pattern = settings.getVariable("ivy.ibiblio.default.artifact.pattern");
+ if (pattern != null)
+ {
+ this.pattern = pattern;
+ }
+ else
+ {
+ settings.configureRepositories(false);
+ this.pattern = settings.getVariable("ivy.ibiblio.default.artifact.pattern");
+ }
+ }
+ updateWholePattern();
+ }
+ }
+
+ private String getWholePattern()
+ {
+ return root + pattern;
+ }
+
+ public String getPattern()
+ {
+ return pattern;
+ }
+
+ public void setPattern(String pattern)
+ {
+ if (pattern == null)
+ {
+ throw new NullPointerException("pattern must not be null");
+ }
+ this.pattern = pattern;
+ ensureConfigured(getSettings());
+ updateWholePattern();
+ }
+
+ public String getRoot()
+ {
+ return root;
+ }
+
+ /**
+ * Sets the root of the maven like repository. The maven like repository is necessarily an http
+ * repository.
+ *
+ * @param root
+ * the root of the maven like repository
+ * @throws IllegalArgumentException
+ * if root does not start with "http://"
+ */
+ public void setRoot(String root)
+ {
+ if (root == null)
+ {
+ throw new NullPointerException("root must not be null");
+ }
+ if (!root.endsWith("/"))
+ {
+ this.root = root + "/";
+ }
+ else
+ {
+ this.root = root;
+ }
+ ensureConfigured(getSettings());
+ updateWholePattern();
+ }
+
+ private void updateWholePattern()
+ {
+ if (isM2compatible() && isUsepoms())
+ {
+ setIvyPatterns(Collections.singletonList(getWholePattern()));
+ }
+ setArtifactPatterns(Collections.singletonList(getWholePattern()));
+ }
+
+ public void publish(Artifact artifact, File src)
+ {
+ throw new UnsupportedOperationException("publish not supported by IBiblioResolver");
+ }
+
+ // we do not allow to list organisations on ibiblio, nor modules in ibiblio 1
+ public String[] listTokenValues(String token, Map otherTokenValues)
+ {
+ if (IvyPatternHelper.ORGANISATION_KEY.equals(token))
+ {
+ return new String[0];
+ }
+ if (IvyPatternHelper.MODULE_KEY.equals(token) && !isM2compatible())
+ {
+ return new String[0];
+ }
+ ensureConfigured(getSettings());
+ return super.listTokenValues(token, otherTokenValues);
+ }
+
+ protected String[] listTokenValues(String pattern, String token)
+ {
+ if (IvyPatternHelper.ORGANISATION_KEY.equals(token))
+ {
+ return new String[0];
+ }
+ if (IvyPatternHelper.MODULE_KEY.equals(token) && !isM2compatible())
+ {
+ return new String[0];
+ }
+ ensureConfigured(getSettings());
+
+ // let's see if we should use maven metadata for this listing...
+ if (IvyPatternHelper.REVISION_KEY.equals(token) && isM2compatible() && isUseMavenMetadata())
+ {
+ if (((String) getIvyPatterns().get(0)).endsWith(M2_PER_MODULE_PATTERN))
+ {
+ // now we must use metadata if available
+ /*
+ * we substitute tokens with ext token only in the m2 per module pattern, to match
+ * has has been done in the given pattern
+ */
+ String partiallyResolvedM2PerModulePattern = IvyPatternHelper.substituteTokens(M2_PER_MODULE_PATTERN,
+ Collections.singletonMap(IvyPatternHelper.EXT_KEY, "xml"));
+ if (pattern.endsWith(partiallyResolvedM2PerModulePattern))
+ {
+ /*
+ * the given pattern already contain resolved org and module, we just have to
+ * replace the per module pattern at the end by 'maven-metadata.xml' to have the
+ * maven metadata file location
+ */
+ String metadataLocation = pattern.substring(0, pattern.lastIndexOf(partiallyResolvedM2PerModulePattern))
+ + "maven-metadata.xml";
+ List revs = listRevisionsWithMavenMetadata(getRepository(), metadataLocation);
+ if (revs != null)
+ {
+ return (String[]) revs.toArray(new String[revs.size()]);
+ }
+ }
+ else
+ {
+ /*
+ * this is probably because the given pattern has been substituted with jar ext,
+ * if this resolver has optional module descriptors. But since we have to use
+ * maven metadata, we don't care about this case, maven metadata has already
+ * been used when looking for revisions with the pattern substituted with
+ * ext=xml for the "ivy" pattern.
+ */
+ return new String[0];
+ }
+ }
+ }
+ return super.listTokenValues(pattern, token);
+ }
+
+ public OrganisationEntry[] listOrganisations()
+ {
+ return new OrganisationEntry[0];
+ }
+
+ public ModuleEntry[] listModules(OrganisationEntry org)
+ {
+ if (isM2compatible())
+ {
+ ensureConfigured(getSettings());
+ return super.listModules(org);
+ }
+ return new ModuleEntry[0];
+ }
+
+ public RevisionEntry[] listRevisions(ModuleEntry mod)
+ {
+ ensureConfigured(getSettings());
+ return super.listRevisions(mod);
+ }
+
+ protected ResolvedResource[] listResources(Repository repository, ModuleRevisionId mrid, String pattern,
+ Artifact artifact)
+ {
+ if (shouldUseMavenMetadata(pattern))
+ {
+ List revs = listRevisionsWithMavenMetadata(repository, mrid.getModuleId().getAttributes());
+ if (revs != null)
+ {
+ Message.debug("\tfound revs: " + revs);
+ List rres = new ArrayList();
+ for (Iterator iter = revs.iterator(); iter.hasNext();)
+ {
+ String rev = (String) iter.next();
+ ModuleRevisionId snapshotMrid = ModuleRevisionId.newInstance(mrid, rev);
+ String realRev = findSnapshotVersion(snapshotMrid);
+ String realPattern = pattern.replaceFirst("\\[revision\\]", "/" + rev);
+ String resolvedPattern = IvyPatternHelper.substitute(realPattern, ModuleRevisionId.newInstance(snapshotMrid, realRev),
+ artifact);
+ try
+ {
+ Resource res = repository.getResource(resolvedPattern);
+ if ((res != null) && res.exists())
+ {
+ rres.add(new ResolvedResource(res, realRev));
+ }
+ }
+ catch (IOException e)
+ {
+ Message.warn("impossible to get resource from name listed by maven-metadata.xml:" + rres + ": "
+ + e.getMessage());
+ }
+ }
+ return (ResolvedResource[]) rres.toArray(new ResolvedResource[rres.size()]);
+ }
+ else
+ {
+ // maven metadata not available or something went wrong,
+ // use default listing capability
+ return super.listResources(repository, mrid, pattern, artifact);
+ }
+ }
+ else
+ {
+ return super.listResources(repository, mrid, pattern, artifact);
+ }
+ }
+
+ private List listRevisionsWithMavenMetadata(Repository repository, Map tokenValues)
+ {
+ String metadataLocation = IvyPatternHelper.substituteTokens(root + "[organisation]/[module]/maven-metadata.xml",
+ tokenValues);
+ return listRevisionsWithMavenMetadata(repository, metadataLocation);
+ }
+
+ private List listRevisionsWithMavenMetadata(Repository repository, String metadataLocation)
+ {
+ List revs = null;
+ InputStream metadataStream = null;
+ try
+ {
+ Resource metadata = repository.getResource(metadataLocation);
+ if (metadata.exists())
+ {
+ Message.verbose("\tlisting revisions from maven-metadata: " + metadata);
+ final List metadataRevs = new ArrayList();
+ metadataStream = metadata.openStream();
+ XMLHelper.parse(metadataStream, null, new ContextualSAXHandler()
+ {
+ public void endElement(String uri, String localName, String qName) throws SAXException
+ {
+ if ("metadata/versioning/versions/version".equals(getContext()))
+ {
+ metadataRevs.add(getText().trim());
+ }
+ super.endElement(uri, localName, qName);
+ }
+ }, null);
+ revs = metadataRevs;
+ }
+ else
+ {
+ Message.verbose("\tmaven-metadata not available: " + metadata);
+ }
+ }
+ catch (IOException e)
+ {
+ Message.verbose("impossible to access maven metadata file, ignored: " + e.getMessage());
+ }
+ catch (SAXException e)
+ {
+ Message.verbose("impossible to parse maven metadata file, ignored: " + e.getMessage());
+ }
+ catch (ParserConfigurationException e)
+ {
+ Message.verbose("impossible to parse maven metadata file, ignored: " + e.getMessage());
+ }
+ finally
+ {
+ if (metadataStream != null)
+ {
+ try
+ {
+ metadataStream.close();
+ }
+ catch (IOException e)
+ {
+ // ignored
+ }
+ }
+ }
+ return revs;
+ }
+
+ protected void findTokenValues(Collection names, List patterns, Map tokenValues, String token)
+ {
+ if (IvyPatternHelper.REVISION_KEY.equals(token))
+ {
+ String pattern = (String) patterns.get(0);
+ if (shouldUseMavenMetadata(pattern))
+ {
+ List revs = listRevisionsWithMavenMetadata(getRepository(), tokenValues);
+ if (revs != null)
+ {
+ names.addAll(filterNames(revs));
+ return;
+ }
+ }
+ }
+ super.findTokenValues(names, patterns, tokenValues, token);
+ }
+
+ private boolean shouldUseMavenMetadata(String pattern)
+ {
+ return isUseMavenMetadata() && isM2compatible() && pattern.endsWith(M2_PATTERN);
+ }
+
+ public String getTypeName()
+ {
+ return "maven-snapshot-resolver";
+ }
+
+ // override some methods to ensure configuration
+ public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) throws ParseException
+ {
+ ensureConfigured(data.getSettings());
+ return super.getDependency(dd, data);
+ }
+
+ public DownloadReport download(Artifact[] artifacts, DownloadOptions options)
+ {
+ ensureConfigured(getSettings());
+ return super.download(artifacts, options);
+ }
+
+ public boolean exists(Artifact artifact)
+ {
+ ensureConfigured(getSettings());
+ return super.exists(artifact);
+ }
+
+ public ArtifactOrigin locate(Artifact artifact)
+ {
+ ensureConfigured(getSettings());
+ return super.locate(artifact);
+ }
+
+ public List getArtifactPatterns()
+ {
+ ensureConfigured(getSettings());
+ return super.getArtifactPatterns();
+ }
+
+ public boolean isUsepoms()
+ {
+ return usepoms;
+ }
+
+ @Override
+ public ResolvedModuleRevision parse(ResolvedResource mdRef, DependencyDescriptor dd, ResolveData data)
+ throws ParseException
+ {
+ ResolvedModuleRevision rmr = super.parse(mdRef, dd, data);
+ // patch in the resolved snapshot version
+ ModuleRevisionId mrid = rmr.getId();
+ DefaultModuleDescriptor descriptor = (DefaultModuleDescriptor) rmr.getDescriptor();
+ //descriptor.addExtraInfo(MavenSnapshotResolver.class.getName() + ".originalRev", mrid.getRevision());
+ ModuleRevisionId revId = ModuleRevisionId.newInstance(mrid, mdRef.getRevision());
+ descriptor.setModuleRevisionId(revId);
+ rmr.getDescriptor().setResolvedModuleRevisionId(revId);
+ return rmr;
+ }
+
+ public void setUsepoms(boolean usepoms)
+ {
+ this.usepoms = usepoms;
+ updateWholePattern();
+ }
+
+ public boolean isUseMavenMetadata()
+ {
+ return useMavenMetadata;
+ }
+
+ public void setUseMavenMetadata(boolean useMavenMetadata)
+ {
+ this.useMavenMetadata = useMavenMetadata;
+ }
+
+ public void dumpSettings()
+ {
+ ensureConfigured(getSettings());
+ super.dumpSettings();
+ Message.debug("\t\troot: " + getRoot());
+ Message.debug("\t\tpattern: " + getPattern());
+ Message.debug("\t\tusepoms: " + usepoms);
+ Message.debug("\t\tuseMavenMetadata: " + useMavenMetadata);
+ }
+}
Added: projects/ejb3/trunk/ivy/src/main/java/org/jboss/ejb3/ivy/plugins/version/MavenVersionMatcher.java
===================================================================
--- projects/ejb3/trunk/ivy/src/main/java/org/jboss/ejb3/ivy/plugins/version/MavenVersionMatcher.java (rev 0)
+++ projects/ejb3/trunk/ivy/src/main/java/org/jboss/ejb3/ivy/plugins/version/MavenVersionMatcher.java 2009-02-25 22:34:02 UTC (rev 84767)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.ejb3.ivy.plugins.version;
+
+import java.util.regex.Pattern;
+
+import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
+import org.apache.ivy.core.module.id.ModuleRevisionId;
+import org.apache.ivy.plugins.version.AbstractVersionMatcher;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class MavenVersionMatcher extends AbstractVersionMatcher
+{
+ private final static Pattern VERSION_PATTERN = Pattern.compile("\\d+\\.\\d+\\.\\d+-\\d{8}\\.\\d{6}-\\d+");
+
+ public MavenVersionMatcher()
+ {
+ super("maven-version-matcher");
+ }
+
+ @Override
+ public boolean accept(ModuleRevisionId askedMrid, ModuleDescriptor foundMD)
+ {
+ System.err.println("NYI: accept md " + askedMrid + " : " + foundMD);
+ return foundMD.getRevision().endsWith("-SNAPSHOT");
+ }
+
+ public boolean accept(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid)
+ {
+ //return askedMrid.getRevision().endsWith("-SNAPSHOT");
+ //throw new RuntimeException("NYI: accept " + askedMrid + " : " + foundMrid);
+ return true;
+ }
+
+ public boolean isDynamic(ModuleRevisionId askedMrid)
+ {
+ boolean isDynamic = VERSION_PATTERN.matcher(askedMrid.getRevision()).matches();
+ System.err.println("isDynamic: " + askedMrid + " " + isDynamic);
+ return isDynamic;
+ //return askedMrid.getRevision().endsWith("-SNAPSHOT");
+ //return true;
+ }
+}
Added: projects/ejb3/trunk/ivy/src/test/java/org/jboss/ejb3/ivy/plugins/resolver/MavenSnapshotResolverTestCase.java
===================================================================
--- projects/ejb3/trunk/ivy/src/test/java/org/jboss/ejb3/ivy/plugins/resolver/MavenSnapshotResolverTestCase.java (rev 0)
+++ projects/ejb3/trunk/ivy/src/test/java/org/jboss/ejb3/ivy/plugins/resolver/MavenSnapshotResolverTestCase.java 2009-02-25 22:34:02 UTC (rev 84767)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.ejb3.ivy.plugins.resolver;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.text.ParseException;
+import java.util.regex.Pattern;
+
+import org.apache.ivy.Ivy;
+import org.apache.ivy.core.module.id.ModuleId;
+import org.apache.ivy.core.module.id.ModuleRevisionId;
+import org.apache.ivy.core.report.ResolveReport;
+import org.apache.ivy.core.resolve.ResolveOptions;
+import org.apache.ivy.util.DefaultMessageLogger;
+import org.apache.ivy.util.Message;
+import org.junit.Test;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class MavenSnapshotResolverTestCase
+{
+ @Test
+ public void test0()
+ {
+ Pattern VERSION_PATTERN = Pattern.compile("\\d{6}");
+ System.err.println(VERSION_PATTERN);
+ assertTrue(VERSION_PATTERN.matcher("123456").matches());
+// Pattern VERSION_PATTERN = Pattern.compile("\\d+\\.\\d+\\.\\d+-\\d{6}");
+// System.err.println(VERSION_PATTERN);
+// assertTrue(VERSION_PATTERN.matcher("1.0.0-20090202").matches());
+// Pattern VERSION_PATTERN = Pattern.compile("\\d+\\.\\d+\\.\\d+-\\d{6}+\\.\\d{6}+-\\d+");
+// System.err.println(VERSION_PATTERN);
+// assertTrue(VERSION_PATTERN.matcher("1.0.0-20090202-101010-10").matches());
+ }
+
+ @Test
+ public void test1() throws ParseException, IOException
+ {
+ Ivy ivy = Ivy.newInstance();
+ ivy.configure(new File("src/test/resources/ivysettings.xml"));
+ ivy.getLoggerEngine().pushLogger(new DefaultMessageLogger(Message.MSG_DEBUG));
+
+ ModuleRevisionId mrid = new ModuleRevisionId(new ModuleId("org.jboss.ejb3", "jboss-ejb3-cache"), "latest.integration");
+ ResolveOptions options = new ResolveOptions();
+ options.setTransitive(false);
+ String confs[] = { "default" };
+ options.setConfs(confs);
+ ResolveReport report = ivy.resolve(mrid, options, true);
+ System.out.println(report.getAllArtifactsReports()[0].getArtifact().getModuleRevisionId().getRevision());
+ }
+}
Added: projects/ejb3/trunk/ivy/src/test/resources/ivysettings.xml
===================================================================
--- projects/ejb3/trunk/ivy/src/test/resources/ivysettings.xml (rev 0)
+++ projects/ejb3/trunk/ivy/src/test/resources/ivysettings.xml 2009-02-25 22:34:02 UTC (rev 84767)
@@ -0,0 +1,20 @@
+<!--
+ vi:ts=3:sw=3:expandtab:
+-->
+<ivysettings>
+ <typedef name="maven-snapshot-resolver" classname="org.jboss.ejb3.ivy.plugins.resolver.MavenSnapshotResolver"/>
+ <typedef name="maven-vm" classname="org.jboss.ejb3.ivy.plugins.version.MavenVersionMatcher"/>
+ <settings defaultResolver="snapshots.jboss.org"/>
+ <resolvers>
+ <maven-snapshot-resolver name="snapshots.jboss.org" m2compatible="true" usepoms="true" root="http://snapshots.jboss.org/maven2"/>
+ </resolvers>
+ <version-matchers>
+ <exact-vm/>
+ <sub-vm/>
+ <range-vm/>
+ <latest-vm/>
+ <!--
+ <maven-vm/>
+ -->
+ </version-matchers>
+</ivysettings>
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list