From 856b838a0647b8c07d942e2a5b6ba267e74cea95 Mon Sep 17 00:00:00 2001 From: Xavier Hanin Date: Thu, 27 Apr 2006 14:33:20 +0000 Subject: [PATCH] IVY-217 extra attributes: now extra attributes can be used in patterns git-svn-id: https://svn.apache.org/repos/asf/incubator/ivy/trunk@484305 13f79535-47bb-0310-9956-ffa450edef68 --- .../fr/jayasoft/ivy/AbstractArtifact.java | 37 ++++++++- src/java/fr/jayasoft/ivy/Artifact.java | 2 + .../fr/jayasoft/ivy/ArtifactRevisionId.java | 32 ++++++-- src/java/fr/jayasoft/ivy/Configuration.java | 2 + src/java/fr/jayasoft/ivy/DefaultArtifact.java | 20 ++++- .../ivy/DefaultDependencyDescriptor.java | 28 ++++++- .../jayasoft/ivy/DefaultExtendableItem.java | 23 ------ .../jayasoft/ivy/DefaultModuleDescriptor.java | 27 ++++++- .../fr/jayasoft/ivy/DependencyDescriptor.java | 1 + src/java/fr/jayasoft/ivy/ExtendableItem.java | 19 ----- src/java/fr/jayasoft/ivy/Ivy.java | 27 +++---- src/java/fr/jayasoft/ivy/IvyNode.java | 3 +- src/java/fr/jayasoft/ivy/MDArtifact.java | 15 +++- .../fr/jayasoft/ivy/ModuleDescriptor.java | 2 + .../fr/jayasoft/ivy/ModuleRevisionId.java | 59 +++++++++++--- .../ivy/extendable/DefaultExtendableItem.java | 30 ++++++++ .../ivy/extendable/ExtendableItem.java | 52 +++++++++++++ .../ivy/extendable/ExtendableItemHelper.java | 40 ++++++++++ .../UnmodifiableExtendableItem.java | 64 ++++++++++++++++ .../ivy/namespace/MRIDTransformationRule.java | 2 +- .../ivy/namespace/NameSpaceHelper.java | 2 +- .../resolver/AbstractResourceResolver.java | 72 +++++++++++++++--- .../ivy/resolver/AbstractURLResolver.java | 12 +-- .../jayasoft/ivy/resolver/BasicResolver.java | 7 +- .../jayasoft/ivy/resolver/CacheResolver.java | 2 +- .../ivy/resolver/IBiblioResolver.java | 3 +- .../ivy/resolver/RepositoryResolver.java | 51 +++++++------ .../jayasoft/ivy/resolver/ResolverHelper.java | 76 ++++++++++--------- .../jayasoft/ivy/util/IvyPatternHelper.java | 40 ++++++---- .../ivy/xml/XmlModuleDescriptorParser.java | 25 +++--- .../fr/jayasoft/ivy/xml/XmlReportParser.java | 3 +- test/java/fr/jayasoft/ivy/ResolveTest.java | 14 ++++ test/java/fr/jayasoft/ivy/ivy-extra-att.xml | 6 ++ .../xml/XmlModuleDescriptorParserTest.java | 2 + .../repositories/extra-attributes/ivyconf.xml | 14 ++++ .../mymodule/task1/1854/ivy.xml | 14 ++++ .../mymodule/task1/1854/mymodule-linux.jar | 1 + .../mymodule/task1/1854/mymodule-windows.jar | 1 + 38 files changed, 632 insertions(+), 198 deletions(-) delete mode 100644 src/java/fr/jayasoft/ivy/DefaultExtendableItem.java delete mode 100644 src/java/fr/jayasoft/ivy/ExtendableItem.java create mode 100644 src/java/fr/jayasoft/ivy/extendable/DefaultExtendableItem.java create mode 100644 src/java/fr/jayasoft/ivy/extendable/ExtendableItem.java create mode 100644 src/java/fr/jayasoft/ivy/extendable/ExtendableItemHelper.java create mode 100644 src/java/fr/jayasoft/ivy/extendable/UnmodifiableExtendableItem.java create mode 100644 test/java/fr/jayasoft/ivy/ivy-extra-att.xml create mode 100644 test/repositories/extra-attributes/ivyconf.xml create mode 100644 test/repositories/extra-attributes/mymodule/task1/1854/ivy.xml create mode 100644 test/repositories/extra-attributes/mymodule/task1/1854/mymodule-linux.jar create mode 100644 test/repositories/extra-attributes/mymodule/task1/1854/mymodule-windows.jar diff --git a/src/java/fr/jayasoft/ivy/AbstractArtifact.java b/src/java/fr/jayasoft/ivy/AbstractArtifact.java index eed7b3b2..1b5261f6 100644 --- a/src/java/fr/jayasoft/ivy/AbstractArtifact.java +++ b/src/java/fr/jayasoft/ivy/AbstractArtifact.java @@ -5,11 +5,16 @@ */ package fr.jayasoft.ivy; +import java.util.Map; + /** * @author Hanin * */ -public abstract class AbstractArtifact extends DefaultExtendableItem implements Artifact { +public abstract class AbstractArtifact implements Artifact { + public AbstractArtifact() { + } + public boolean equals(Object obj) { if (!(obj instanceof Artifact)) { return false; @@ -19,7 +24,8 @@ public abstract class AbstractArtifact extends DefaultExtendableItem implements && getPublicationDate()==null?true:getPublicationDate().equals(art.getPublicationDate()) && getName().equals(art.getName()) && getExt().equals(art.getExt()) - && getType().equals(art.getType()); + && getType().equals(art.getType()) + && getExtraAttributes().equals(art.getExtraAttributes()); } public int hashCode() { @@ -31,10 +37,37 @@ public abstract class AbstractArtifact extends DefaultExtendableItem implements hash = hash * 17 + getName().hashCode(); hash = hash * 17 + getExt().hashCode(); hash = hash * 17 + getType().hashCode(); + hash = hash * 17 + getExtraAttributes().hashCode(); return hash; } public String toString() { return getModuleRevisionId()+"/"+getName()+"."+getExt()+"["+getType()+"]"; } + + public String getAttribute(String attName) { + return getId().getAttribute(attName); + } + + public Map getAttributes() { + return getId().getAttributes(); + } + + public String getExtraAttribute(String attName) { + return getId().getExtraAttribute(attName); + } + + public Map getExtraAttributes() { + return getId().getExtraAttributes(); + } + + public String getStandardAttribute(String attName) { + return getId().getStandardAttribute(attName); + } + + public Map getStandardAttributes() { + return getId().getStandardAttributes(); + } + + } diff --git a/src/java/fr/jayasoft/ivy/Artifact.java b/src/java/fr/jayasoft/ivy/Artifact.java index f5954879..3523f468 100644 --- a/src/java/fr/jayasoft/ivy/Artifact.java +++ b/src/java/fr/jayasoft/ivy/Artifact.java @@ -7,6 +7,8 @@ package fr.jayasoft.ivy; import java.util.Date; +import fr.jayasoft.ivy.extendable.ExtendableItem; + /** * @author x.hanin diff --git a/src/java/fr/jayasoft/ivy/ArtifactRevisionId.java b/src/java/fr/jayasoft/ivy/ArtifactRevisionId.java index 7d35cb1e..36de40ca 100644 --- a/src/java/fr/jayasoft/ivy/ArtifactRevisionId.java +++ b/src/java/fr/jayasoft/ivy/ArtifactRevisionId.java @@ -5,25 +5,41 @@ */ package fr.jayasoft.ivy; +import java.util.Map; + +import fr.jayasoft.ivy.extendable.UnmodifiableExtendableItem; +import fr.jayasoft.ivy.util.IvyPatternHelper; + /** * identifies an artifact in a particular module revision */ -public class ArtifactRevisionId { +public class ArtifactRevisionId extends UnmodifiableExtendableItem { public static ArtifactRevisionId newInstance(ModuleRevisionId mrid, String name, String type, String ext) { - return new ArtifactRevisionId(new ArtifactId(mrid.getModuleId(), name, type, ext), mrid); + return newInstance(mrid, name, type, ext, null); + } + + public static ArtifactRevisionId newInstance(ModuleRevisionId mrid, String name, String type, String ext, Map extraAttributes) { + return new ArtifactRevisionId(new ArtifactId(mrid.getModuleId(), name, type, ext), mrid, extraAttributes); } private ArtifactId _artifactId; private ModuleRevisionId _mrid; - /** - * @param revision - * @param artifactId - */ public ArtifactRevisionId(ArtifactId artifactId, ModuleRevisionId mrid) { + this(artifactId, mrid, null); + } + public ArtifactRevisionId(ArtifactId artifactId, ModuleRevisionId mrid, Map extraAttributes) { + super(null, extraAttributes); _artifactId = artifactId; _mrid = mrid; + + setStandardAttribute(IvyPatternHelper.ORGANISATION_KEY, getModuleRevisionId().getOrganisation()); + setStandardAttribute(IvyPatternHelper.MODULE_KEY, getModuleRevisionId().getName()); + setStandardAttribute(IvyPatternHelper.REVISION_KEY, getModuleRevisionId().getRevision()); + setStandardAttribute(IvyPatternHelper.ARTIFACT_KEY, getName()); + setStandardAttribute(IvyPatternHelper.TYPE_KEY, getType()); + setStandardAttribute(IvyPatternHelper.EXT_KEY, getExt()); } public boolean equals(Object obj) { @@ -32,13 +48,15 @@ public class ArtifactRevisionId { } ArtifactRevisionId arid = (ArtifactRevisionId)obj; return getArtifactId().equals(arid.getArtifactId()) - && getModuleRevisionId().equals(arid.getModuleRevisionId()); + && getModuleRevisionId().equals(arid.getModuleRevisionId()) + && getExtraAttributes().equals(arid.getExtraAttributes()); } public int hashCode() { int hash = 17; hash += getArtifactId().hashCode() * 37; hash += getModuleRevisionId().hashCode() * 37; + hash += getExtraAttributes().hashCode() * 37; return hash; } diff --git a/src/java/fr/jayasoft/ivy/Configuration.java b/src/java/fr/jayasoft/ivy/Configuration.java index 423b369b..4530a635 100644 --- a/src/java/fr/jayasoft/ivy/Configuration.java +++ b/src/java/fr/jayasoft/ivy/Configuration.java @@ -5,6 +5,8 @@ */ package fr.jayasoft.ivy; +import fr.jayasoft.ivy.extendable.DefaultExtendableItem; + /** * Represents a module configuration diff --git a/src/java/fr/jayasoft/ivy/DefaultArtifact.java b/src/java/fr/jayasoft/ivy/DefaultArtifact.java index 6c9264d9..1821978b 100644 --- a/src/java/fr/jayasoft/ivy/DefaultArtifact.java +++ b/src/java/fr/jayasoft/ivy/DefaultArtifact.java @@ -6,25 +6,38 @@ package fr.jayasoft.ivy; import java.util.Date; +import java.util.Map; /** * @author Hanin * */ public class DefaultArtifact extends AbstractArtifact { + + public static Artifact newIvyArtifact(ModuleRevisionId mrid, Date pubDate) { + return new DefaultArtifact(mrid, pubDate, "ivy", "ivy", "xml"); + } + + public static Artifact newPomArtifact(ModuleRevisionId mrid, Date pubDate) { + return new DefaultArtifact(mrid, pubDate, mrid.getName(), "pom", "pom"); + } + public static Artifact cloneWithAnotherType(Artifact artifact, String newType) { - return new DefaultArtifact(artifact.getModuleRevisionId(), artifact.getPublicationDate(), artifact.getName(), newType, artifact.getExt()); + return new DefaultArtifact(artifact.getModuleRevisionId(), artifact.getPublicationDate(), artifact.getName(), newType, artifact.getExt(), artifact.getExtraAttributes()); } Date _publicationDate; ArtifactRevisionId _arid; public DefaultArtifact(ModuleRevisionId mrid, Date publicationDate, String name, String type, String ext) { + this(mrid, publicationDate, name, type, ext, null); + } + public DefaultArtifact(ModuleRevisionId mrid, Date publicationDate, String name, String type, String ext, Map extraAttributes) { if (mrid == null) { throw new NullPointerException("null mrid not allowed"); } if (publicationDate == null) { - throw new NullPointerException("null publication date not allowed"); + publicationDate = new Date(); } if (name == null) { throw new NullPointerException("null name not allowed"); @@ -36,7 +49,7 @@ public class DefaultArtifact extends AbstractArtifact { throw new NullPointerException("null ext not allowed"); } _publicationDate = publicationDate; - _arid = ArtifactRevisionId.newInstance(mrid, name, type, ext); + _arid = ArtifactRevisionId.newInstance(mrid, name, type, ext, extraAttributes); } @@ -62,4 +75,5 @@ public class DefaultArtifact extends AbstractArtifact { public String[] getConfigurations() { return new String[0]; } + } diff --git a/src/java/fr/jayasoft/ivy/DefaultDependencyDescriptor.java b/src/java/fr/jayasoft/ivy/DefaultDependencyDescriptor.java index b387c82a..f119425c 100644 --- a/src/java/fr/jayasoft/ivy/DefaultDependencyDescriptor.java +++ b/src/java/fr/jayasoft/ivy/DefaultDependencyDescriptor.java @@ -31,7 +31,7 @@ import fr.jayasoft.ivy.namespace.NamespaceTransformer; * @author Xavier Hanin * */ -public class DefaultDependencyDescriptor extends DefaultExtendableItem implements DependencyDescriptor { +public class DefaultDependencyDescriptor implements DependencyDescriptor { private static final Pattern SELF_FALLBACK_PATTERN = Pattern.compile("@(\\(.*\\))?"); private static final Pattern THIS_FALLBACK_PATTERN = Pattern.compile("#(\\(.*\\))?"); @@ -122,7 +122,7 @@ public class DefaultDependencyDescriptor extends DefaultExtendableItem implement public DefaultDependencyDescriptor(DependencyDescriptor dd, String revision) { _parentId = dd.getParentRevisionId(); - _revId = new ModuleRevisionId(dd.getDependencyId(), revision); + _revId = new ModuleRevisionId(dd.getDependencyId(), revision, dd.getExtraAttributes()); _force = dd.isForce(); _changing = dd.isChanging(); _transitive = dd.isTransitive(); @@ -379,5 +379,29 @@ public class DefaultDependencyDescriptor extends DefaultExtendableItem implement public Namespace getNamespace() { return _namespace; } + + public String getAttribute(String attName) { + return _revId.getAttribute(attName); + } + + public Map getAttributes() { + return _revId.getAttributes(); + } + + public String getExtraAttribute(String attName) { + return _revId.getExtraAttribute(attName); + } + + public Map getExtraAttributes() { + return _revId.getExtraAttributes(); + } + + public String getStandardAttribute(String attName) { + return _revId.getStandardAttribute(attName); + } + + public Map getStandardAttributes() { + return _revId.getStandardAttributes(); + } } diff --git a/src/java/fr/jayasoft/ivy/DefaultExtendableItem.java b/src/java/fr/jayasoft/ivy/DefaultExtendableItem.java deleted file mode 100644 index 6b626442..00000000 --- a/src/java/fr/jayasoft/ivy/DefaultExtendableItem.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * This file is subject to the licence found in LICENCE.TXT in the root directory of the project. - * Copyright Jayasoft 2005 - All rights reserved - * - * #SNAPSHOT# - */ -package fr.jayasoft.ivy; - -import java.util.HashMap; -import java.util.Map; - -/** - * An item which is meant to be extended, i.e. defined using extra attributes - */ -public class DefaultExtendableItem { - private Map _attributes = new HashMap(); - public String getAttribute(String attName) { - return (String)_attributes.get(attName); - } - public void setAttribute(String attName, String attValue) { - _attributes.put(attName, attValue); - } -} diff --git a/src/java/fr/jayasoft/ivy/DefaultModuleDescriptor.java b/src/java/fr/jayasoft/ivy/DefaultModuleDescriptor.java index 86a4e572..13af4a0b 100644 --- a/src/java/fr/jayasoft/ivy/DefaultModuleDescriptor.java +++ b/src/java/fr/jayasoft/ivy/DefaultModuleDescriptor.java @@ -26,7 +26,7 @@ import fr.jayasoft.ivy.util.Message; * @author X.Hanin * */ -public class DefaultModuleDescriptor extends DefaultExtendableItem implements ModuleDescriptor { +public class DefaultModuleDescriptor implements ModuleDescriptor { public static DefaultModuleDescriptor newDefaultInstance(ModuleRevisionId mrid) { return newDefaultInstance(mrid, null); @@ -387,4 +387,29 @@ public class DefaultModuleDescriptor extends DefaultExtendableItem implements Mo public boolean isMappingOverride() { return _mappingOverride; } + + public String getAttribute(String attName) { + return _resolvedRevId.getAttribute(attName); + } + + public Map getAttributes() { + return _resolvedRevId.getAttributes(); + } + + public String getExtraAttribute(String attName) { + return _resolvedRevId.getExtraAttribute(attName); + } + + public Map getExtraAttributes() { + return _resolvedRevId.getExtraAttributes(); + } + + public String getStandardAttribute(String attName) { + return _resolvedRevId.getStandardAttribute(attName); + } + + public Map getStandardAttributes() { + return _resolvedRevId.getStandardAttributes(); + } + } diff --git a/src/java/fr/jayasoft/ivy/DependencyDescriptor.java b/src/java/fr/jayasoft/ivy/DependencyDescriptor.java index 45d32078..47f48d0f 100644 --- a/src/java/fr/jayasoft/ivy/DependencyDescriptor.java +++ b/src/java/fr/jayasoft/ivy/DependencyDescriptor.java @@ -5,6 +5,7 @@ */ package fr.jayasoft.ivy; +import fr.jayasoft.ivy.extendable.ExtendableItem; import fr.jayasoft.ivy.namespace.Namespace; diff --git a/src/java/fr/jayasoft/ivy/ExtendableItem.java b/src/java/fr/jayasoft/ivy/ExtendableItem.java deleted file mode 100644 index d3c378d6..00000000 --- a/src/java/fr/jayasoft/ivy/ExtendableItem.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * This file is subject to the licence found in LICENCE.TXT in the root directory of the project. - * Copyright Jayasoft 2005 - All rights reserved - * - * #SNAPSHOT# - */ -package fr.jayasoft.ivy; - -public interface ExtendableItem { - /** - * Gets the value of a dependency attribute - * Can be used to access the value of a standard attribute (like org, rev) or of an extra attribute. - * Note that standard attribute are not really standardized, i.e. some implementations my not return - * value for name, so avoid to rely on this in code in which you are not sure of the kind of module descriptor (ivy file, pom, ...) you use. - * @param attName the name of the attribute to get - * @return the value of the attribute, null if the attribute doesn't exist - */ - String getAttribute(String attName); -} \ No newline at end of file diff --git a/src/java/fr/jayasoft/ivy/Ivy.java b/src/java/fr/jayasoft/ivy/Ivy.java index 9f544fe1..4e2b5ff7 100644 --- a/src/java/fr/jayasoft/ivy/Ivy.java +++ b/src/java/fr/jayasoft/ivy/Ivy.java @@ -752,7 +752,7 @@ public class Ivy implements TransferListener { revision = "working@"+getLocalHostName(); } if (revision != null) { - md.setResolvedModuleRevisionId(new ModuleRevisionId(md.getModuleRevisionId().getModuleId(), revision)); + md.setResolvedModuleRevisionId(new ModuleRevisionId(md.getModuleRevisionId().getModuleId(), revision, md.getModuleRevisionId().getExtraAttributes())); } if (confs.length == 1 && confs[0].equals("*")) { confs = md.getConfigurationsNames(); @@ -1601,14 +1601,14 @@ public class Ivy implements TransferListener { if (destIvyPattern != null) { ModuleRevisionId[] mrids = parser.getRealDependencyRevisionIds(moduleId, conf, cache); for (int j = 0; j < mrids.length; j++) { - artifacts.add(new DefaultArtifact(mrids[j], new Date(), "ivy", "ivy", "xml")); + artifacts.add(DefaultArtifact.newIvyArtifact(mrids[j], null)); } } for (Iterator iter = artifacts.iterator(); iter.hasNext();) { Artifact artifact = (Artifact)iter.next(); String destPattern = "ivy".equals(artifact.getType()) ? destIvyPattern: destFilePattern; - String destFileName = IvyPatternHelper.substitute(destPattern, artifact.getModuleRevisionId().getOrganisation(), artifact.getModuleRevisionId().getName(), artifact.getModuleRevisionId().getRevision(), artifact.getName(), artifact.getType(), artifact.getExt(), conf); + String destFileName = IvyPatternHelper.substitute(destPattern, artifact, conf); Set dest = (Set)artifactsToCopy.get(artifact); if (dest == null) { @@ -1751,7 +1751,7 @@ public class Ivy implements TransferListener { try { ivyFileURL = ivyFile.toURL(); md = XmlModuleDescriptorParser.getInstance().parseDescriptor(this, ivyFileURL, validate); - md.setResolvedModuleRevisionId(new ModuleRevisionId(mrid.getModuleId(), revision)); + md.setResolvedModuleRevisionId(new ModuleRevisionId(mrid.getModuleId(), revision, mrid.getExtraAttributes())); md.setResolvedPublicationDate(pubdate); } catch (MalformedURLException e) { throw new RuntimeException("malformed url obtained for file "+ivyFile); @@ -1851,7 +1851,7 @@ public class Ivy implements TransferListener { try { ivyFileURL = ivyFile.toURL(); md = XmlModuleDescriptorParser.getInstance().parseDescriptor(this, ivyFileURL, false); - md.setResolvedModuleRevisionId(new ModuleRevisionId(mrid.getModuleId(), pubrevision)); + md.setResolvedModuleRevisionId(new ModuleRevisionId(mrid.getModuleId(), pubrevision, mrid.getExtraAttributes())); } catch (MalformedURLException e) { throw new RuntimeException("malformed url obtained for file "+ivyFile); } catch (ParseException e) { @@ -1883,7 +1883,7 @@ public class Ivy implements TransferListener { } } if (srcIvyPattern != null) { - Artifact artifact = new MDArtifact(md, "ivy", "ivy", "xml"); + Artifact artifact = MDArtifact.newIvyArtifact(md); if (!publish(artifact, srcIvyPattern, resolver, overwrite)) { missing.add(artifact); } @@ -1935,7 +1935,7 @@ public class Ivy implements TransferListener { } public File getIvyFileInCache(File cache, ModuleRevisionId mrid) { - return new File(cache, IvyPatternHelper.substitute(_cacheIvyPattern, mrid.getOrganisation(), mrid.getName(), mrid.getRevision(), "ivy", "ivy", "xml")); + return new File(cache, IvyPatternHelper.substitute(_cacheIvyPattern, DefaultArtifact.newIvyArtifact(mrid, null))); } public File getArchiveFileInCache(File cache, Artifact artifact) { @@ -1947,17 +1947,14 @@ public class Ivy implements TransferListener { } public String getArchivePathInCache(Artifact artifact) { - return getArchivePathInCache( - artifact.getModuleRevisionId().getOrganisation(), - artifact.getModuleRevisionId().getName(), - artifact.getModuleRevisionId().getRevision(), - artifact.getName(), - artifact.getType(), - artifact.getExt()); + return IvyPatternHelper.substitute(_cacheArtifactPattern, artifact); } + /** + * @deprecated + */ public String getArchivePathInCache(String organisation, String module, String revision, String artifact, String type, String ext) { - return IvyPatternHelper.substitute(_cacheArtifactPattern, organisation, module, revision, artifact, type, ext); + return getArchivePathInCache(new DefaultArtifact(ModuleRevisionId.newInstance(organisation, module, revision), new Date(), artifact, type, ext)); } public File getOriginFileInCache(File cache, Artifact artifact) { diff --git a/src/java/fr/jayasoft/ivy/IvyNode.java b/src/java/fr/jayasoft/ivy/IvyNode.java index db56fdbb..9b2021cc 100644 --- a/src/java/fr/jayasoft/ivy/IvyNode.java +++ b/src/java/fr/jayasoft/ivy/IvyNode.java @@ -10,7 +10,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -834,7 +833,7 @@ public class IvyNode { } private boolean isDependencyModuleExcluded(ModuleRevisionId dependencyRevisionId, String conf) { - return doesCallersExclude(getRootModuleConf(), new DefaultArtifact(dependencyRevisionId, new Date(), "ivy", "ivy", "xml")); + return doesCallersExclude(getRootModuleConf(), DefaultArtifact.newIvyArtifact(dependencyRevisionId, null)); } public ModuleRevisionId getId() { diff --git a/src/java/fr/jayasoft/ivy/MDArtifact.java b/src/java/fr/jayasoft/ivy/MDArtifact.java index 33c69a25..3f48dfe9 100644 --- a/src/java/fr/jayasoft/ivy/MDArtifact.java +++ b/src/java/fr/jayasoft/ivy/MDArtifact.java @@ -8,20 +8,30 @@ package fr.jayasoft.ivy; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Map; /** * @author x.hanin * */ public class MDArtifact extends AbstractArtifact { + + public static Artifact newIvyArtifact(ModuleDescriptor md) { + return new MDArtifact(md, "ivy", "ivy", "xml"); + } + private ModuleDescriptor _md; private String _name; private String _type; private String _ext; private List _confs = new ArrayList(); private ArtifactRevisionId _arid; + private Map _extraAttributes = null; public MDArtifact(ModuleDescriptor md, String name, String type, String ext) { + this(md, name, type, ext, null); + } + public MDArtifact(ModuleDescriptor md, String name, String type, String ext, Map extraAttributes) { if (md == null) { throw new NullPointerException("null module descriptor not allowed"); } @@ -38,6 +48,7 @@ public class MDArtifact extends AbstractArtifact { _name = name; _type = type; _ext = ext; + _extraAttributes = extraAttributes; } public ModuleRevisionId getModuleRevisionId() { @@ -49,10 +60,10 @@ public class MDArtifact extends AbstractArtifact { } public ArtifactRevisionId getId() { if (_arid == null) { - _arid = ArtifactRevisionId.newInstance(_md.getResolvedModuleRevisionId(), _name, _type, _ext); + _arid = ArtifactRevisionId.newInstance(_md.getResolvedModuleRevisionId(), _name, _type, _ext, _extraAttributes); } return _arid; - } + } public String getName() { return _name; diff --git a/src/java/fr/jayasoft/ivy/ModuleDescriptor.java b/src/java/fr/jayasoft/ivy/ModuleDescriptor.java index 7912ca7f..2d245966 100644 --- a/src/java/fr/jayasoft/ivy/ModuleDescriptor.java +++ b/src/java/fr/jayasoft/ivy/ModuleDescriptor.java @@ -7,6 +7,8 @@ package fr.jayasoft.ivy; import java.util.Date; +import fr.jayasoft.ivy.extendable.ExtendableItem; + /** * @author x.hanin * diff --git a/src/java/fr/jayasoft/ivy/ModuleRevisionId.java b/src/java/fr/jayasoft/ivy/ModuleRevisionId.java index 7366bd15..99e2d4d7 100644 --- a/src/java/fr/jayasoft/ivy/ModuleRevisionId.java +++ b/src/java/fr/jayasoft/ivy/ModuleRevisionId.java @@ -5,28 +5,45 @@ */ package fr.jayasoft.ivy; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import fr.jayasoft.ivy.extendable.UnmodifiableExtendableItem; +import fr.jayasoft.ivy.util.IvyPatternHelper; + /** * @author x.hanin * */ -public class ModuleRevisionId { +public class ModuleRevisionId extends UnmodifiableExtendableItem { private static final String ENCODE_SEPARATOR = ModuleId.ENCODE_SEPARATOR; - private static final String NO_REVISION = "[[NONE]]"; public static ModuleRevisionId newInstance(String organisation, String name, String revision) { return new ModuleRevisionId(new ModuleId(organisation, name), revision); } + public static ModuleRevisionId newInstance(String organisation, String name, String revision, Map extraAttributes) { + return new ModuleRevisionId(new ModuleId(organisation, name), revision, extraAttributes); + } private ModuleId _moduleId; private String _revision; private int _hash; public ModuleRevisionId(ModuleId moduleId, String revision) { + this(moduleId, revision, null); + } + public ModuleRevisionId(ModuleId moduleId, String revision, Map extraAttributes) { + super(null, extraAttributes); _moduleId = moduleId; _revision = revision; _hash = _hashCode(); //stored for performance reasons, hashCode is very used in many maps + setStandardAttribute(IvyPatternHelper.ORGANISATION_KEY, _moduleId.getOrganisation()); + setStandardAttribute(IvyPatternHelper.MODULE_KEY, _moduleId.getName()); + setStandardAttribute(IvyPatternHelper.REVISION_KEY, _revision); } + public ModuleId getModuleId() { return _moduleId; } @@ -46,7 +63,8 @@ public class ModuleRevisionId { } ModuleRevisionId other = (ModuleRevisionId)obj; return (other.getRevision() == null ? getRevision() == null : other.getRevision().equals(getRevision())) - && other.getModuleId().equals(getModuleId()); + && other.getModuleId().equals(getModuleId()) + && other.getExtraAttributes().equals(getExtraAttributes()); } public int hashCode() { return _hash; @@ -55,6 +73,7 @@ public class ModuleRevisionId { int hash = 31; hash = hash * 13 + (getRevision() == null ? 0 : getRevision().hashCode()); hash = hash * 13 + getModuleId().hashCode(); + hash = hash * 13 + getAttributes().hashCode(); return hash; } @@ -98,21 +117,37 @@ public class ModuleRevisionId { return !revision.startsWith("latest.") && !revision.endsWith("+"); } public String encodeToString() { - String revision = getRevision(); - if ((revision == null) || (revision.length() == 0)) { - revision = NO_REVISION; + StringBuffer buf = new StringBuffer(); + Map attributes = getAttributes(); + for (Iterator iter = attributes.keySet().iterator(); iter.hasNext();) { + String attName = (String)iter.next(); + buf.append(attName).append(ENCODE_SEPARATOR).append(attributes.get(attName)).append(ENCODE_SEPARATOR); } - return getOrganisation() + ENCODE_SEPARATOR + getName()+ ENCODE_SEPARATOR + revision; + return buf.toString(); } public static ModuleRevisionId decode(String encoded) { String[] parts = encoded.split(ENCODE_SEPARATOR); - if (parts.length != 3) { + if (parts.length % 2 != 0) { throw new IllegalArgumentException("badly encoded module revision id: '"+encoded+"'"); } - String revision = parts[2]; - if (NO_REVISION.equals(revision)) { - revision = ""; + Map attributes = new HashMap(); + for (int i = 0; i < parts.length; i+=2) { + String attName = parts[i]; + String attValue = parts[i+1]; + attributes.put(attName, attValue); } - return newInstance(parts[0], parts[1], revision); + String org = (String)attributes.remove(IvyPatternHelper.ORGANISATION_KEY); + String mod = (String)attributes.remove(IvyPatternHelper.MODULE_KEY); + String rev = (String)attributes.remove(IvyPatternHelper.REVISION_KEY); + if (org == null) { + throw new IllegalArgumentException("badly encoded module revision id: '"+encoded+"': no organisation"); + } + if (mod == null) { + throw new IllegalArgumentException("badly encoded module revision id: '"+encoded+"': no module name"); + } + if (rev == null) { + throw new IllegalArgumentException("badly encoded module revision id: '"+encoded+"': no revision"); + } + return newInstance(org, mod, rev, attributes); } } diff --git a/src/java/fr/jayasoft/ivy/extendable/DefaultExtendableItem.java b/src/java/fr/jayasoft/ivy/extendable/DefaultExtendableItem.java new file mode 100644 index 00000000..8ab83ac6 --- /dev/null +++ b/src/java/fr/jayasoft/ivy/extendable/DefaultExtendableItem.java @@ -0,0 +1,30 @@ +/* + * This file is subject to the licence found in LICENCE.TXT in the root directory of the project. + * Copyright Jayasoft 2005 - All rights reserved + * + * #SNAPSHOT# + */ +package fr.jayasoft.ivy.extendable; + +import java.util.Map; + +/** + * An item which is meant to be extended, i.e. defined using extra attributes + */ +public class DefaultExtendableItem extends UnmodifiableExtendableItem { + public DefaultExtendableItem() { + this(null, null); + } + public DefaultExtendableItem(Map stdAttributes, Map extraAttributes) { + super(stdAttributes, extraAttributes); + } + public void setExtraAttribute(String attName, String attValue) { + super.setExtraAttribute(attName, attValue); + } + public void setStandardAttribute(String attName, String attValue) { + super.setStandardAttribute(attName, attValue); + } + public void setAttribute(String attName, String attValue, boolean extra) { + super.setAttribute(attName, attValue, extra); + } +} diff --git a/src/java/fr/jayasoft/ivy/extendable/ExtendableItem.java b/src/java/fr/jayasoft/ivy/extendable/ExtendableItem.java new file mode 100644 index 00000000..28e50b83 --- /dev/null +++ b/src/java/fr/jayasoft/ivy/extendable/ExtendableItem.java @@ -0,0 +1,52 @@ +/* + * This file is subject to the licence found in LICENCE.TXT in the root directory of the project. + * Copyright Jayasoft 2005 - All rights reserved + * + * #SNAPSHOT# + */ +package fr.jayasoft.ivy.extendable; + +import java.util.Map; + +public interface ExtendableItem { + /** + * Gets the value of an attribute + * Can be used to access the value of a standard attribute (like organisation, revision) or of an extra attribute. + * @param attName the name of the attribute to get + * @return the value of the attribute, null if the attribute doesn't exist + */ + String getAttribute(String attName); + /** + * Gets the value of a standard attribute + * Can be used only to access the value of a standard attribute (like organisation, revision), not an extra one + * @param attName the name of the standard attribute to get + * @return the value of the attribute, null if the attribute doesn't exist + */ + String getStandardAttribute(String attName); + /** + * Gets the value of an extra attribute + * Can be used only to access the value of an extra attribute, not a standard one (like organisation, revision) + * @param attName the name of the extra attribute to get + * @return the value of the attribute, null if the attribute doesn't exist + */ + String getExtraAttribute(String attName); + + /** + * Returns a Map of all attributes of this extendable item, including standard and extra ones. + * The Map keys are attribute names as Strings, and values are corresponding attribute values (as String too) + * @return + */ + Map getAttributes(); + /** + * Returns a Map of all standard attributes of this extendable item. + * The Map keys are attribute names as Strings, and values are corresponding attribute values (as String too) + * @return + */ + Map getStandardAttributes(); + /** + * Returns a Map of all extra attributes of this extendable item. + * The Map keys are attribute names as Strings, and values are corresponding attribute values (as String too) + * @return + */ + Map getExtraAttributes(); +} \ No newline at end of file diff --git a/src/java/fr/jayasoft/ivy/extendable/ExtendableItemHelper.java b/src/java/fr/jayasoft/ivy/extendable/ExtendableItemHelper.java new file mode 100644 index 00000000..1b515d88 --- /dev/null +++ b/src/java/fr/jayasoft/ivy/extendable/ExtendableItemHelper.java @@ -0,0 +1,40 @@ +/* + * This file is subject to the licence found in LICENCE.TXT in the root directory of the project. + * Copyright Jayasoft 2005 - All rights reserved + * + * #SNAPSHOT# + */ +package fr.jayasoft.ivy.extendable; + +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.xml.sax.Attributes; + + +public class ExtendableItemHelper { + + public static Map getExtraAttributes(Attributes attributes, String[] ignoredAttNames) { + Map ret = new HashMap(); + Collection ignored = Arrays.asList(ignoredAttNames); + for (int i=0; i no attempt to find ivy file for "+mrid); } else { @@ -213,7 +263,7 @@ public abstract class AbstractResourceResolver extends BasicResolver { if (mrid.getOrganisation().indexOf('.') == -1) { return mrid; } - return ModuleRevisionId.newInstance(mrid.getOrganisation().replace('.', '/'), mrid.getName(), mrid.getRevision()); + return ModuleRevisionId.newInstance(mrid.getOrganisation().replace('.', '/'), mrid.getName(), mrid.getRevision(), mrid.getExtraAttributes()); } } diff --git a/src/java/fr/jayasoft/ivy/resolver/AbstractURLResolver.java b/src/java/fr/jayasoft/ivy/resolver/AbstractURLResolver.java index 3b0daf63..1aaf9a9b 100644 --- a/src/java/fr/jayasoft/ivy/resolver/AbstractURLResolver.java +++ b/src/java/fr/jayasoft/ivy/resolver/AbstractURLResolver.java @@ -152,7 +152,7 @@ public abstract class AbstractURLResolver extends AbstractResolver { Message.verbose("\t"+getName()+": no ivy file found for "+mrid+": using default data"); logIvyNotFound(mrid); if (!mrid.isExactRevision()) { - md.setResolvedModuleRevisionId(new ModuleRevisionId(mrid.getModuleId(), artifactURL.getRevision())); + md.setResolvedModuleRevisionId(new ModuleRevisionId(mrid.getModuleId(), artifactURL.getRevision(), mrid.getExtraAttributes())); } } } else { @@ -160,7 +160,7 @@ public abstract class AbstractURLResolver extends AbstractResolver { Message.verbose("\t\t=> "+ivyURL); // first check if this dependency has not yet been resolved if (!mrid.isExactRevision()) { - ModuleRevisionId resolvedMrid = new ModuleRevisionId(mrid.getModuleId(), ivyURL.getRevision()); + ModuleRevisionId resolvedMrid = new ModuleRevisionId(mrid.getModuleId(), ivyURL.getRevision(), mrid.getExtraAttributes()); IvyNode node = data.getNode(resolvedMrid); if (node != null) { // this revision has already be resolved : return it @@ -224,9 +224,9 @@ public abstract class AbstractURLResolver extends AbstractResolver { resolvedMrid = md.getResolvedModuleRevisionId(); if (resolvedMrid.getRevision() == null || resolvedMrid.getRevision().length() == 0) { if (ivyURL.getRevision() == null || ivyURL.getRevision().length() == 0) { - resolvedMrid = new ModuleRevisionId(resolvedMrid.getModuleId(), (_envDependent?"##":"")+DATE_FORMAT.format(data.getDate())+"@"+_workspaceName); + resolvedMrid = new ModuleRevisionId(resolvedMrid.getModuleId(), (_envDependent?"##":"")+DATE_FORMAT.format(data.getDate())+"@"+_workspaceName, mrid.getExtraAttributes()); } else { - resolvedMrid = new ModuleRevisionId(resolvedMrid.getModuleId(), ivyURL.getRevision()); + resolvedMrid = new ModuleRevisionId(resolvedMrid.getModuleId(), ivyURL.getRevision(), mrid.getExtraAttributes()); } } Message.verbose("\t\t["+resolvedMrid.getRevision()+"] "+mrid.getModuleId()); @@ -419,9 +419,9 @@ public abstract class AbstractURLResolver extends AbstractResolver { * @param artifact the artifact which has not been found */ protected void logIvyNotFound(ModuleRevisionId mrid) { - Artifact artifact = new DefaultArtifact(mrid, new Date(), "ivy", "ivy", "xml"); + Artifact artifact = DefaultArtifact.newIvyArtifact(mrid, null); String revisionToken = mrid.getRevision().startsWith("latest.")?"[any "+mrid.getRevision().substring("latest.".length())+"]":"["+mrid.getRevision()+"]"; - Artifact latestArtifact = new DefaultArtifact(new ModuleRevisionId(mrid.getModuleId(), revisionToken), new Date(), "ivy", "ivy", "xml"); + Artifact latestArtifact = DefaultArtifact.newIvyArtifact(new ModuleRevisionId(mrid.getModuleId(), revisionToken, mrid.getExtraAttributes()), null); for (Iterator iter = _ivyPatterns.iterator(); iter.hasNext();) { String pattern = (String)iter.next(); String resolvedFileName = IvyPatternHelper.substitute(pattern, artifact); diff --git a/src/java/fr/jayasoft/ivy/resolver/BasicResolver.java b/src/java/fr/jayasoft/ivy/resolver/BasicResolver.java index b99dbadf..3ffca542 100644 --- a/src/java/fr/jayasoft/ivy/resolver/BasicResolver.java +++ b/src/java/fr/jayasoft/ivy/resolver/BasicResolver.java @@ -186,7 +186,7 @@ public abstract class BasicResolver extends AbstractResolver { Message.verbose("\t"+getName()+": no ivy file found for "+mrid+": using default data"); logIvyNotFound(mrid); if (!mrid.isExactRevision()) { - md.setResolvedModuleRevisionId(new ModuleRevisionId(mrid.getModuleId(), artifactRef.getRevision())); + md.setResolvedModuleRevisionId(new ModuleRevisionId(mrid.getModuleId(), artifactRef.getRevision(), mrid.getExtraAttributes())); } } } else { @@ -277,7 +277,7 @@ public abstract class BasicResolver extends AbstractResolver { checkDescriptorConsistency(systemDd.getDependencyRevisionId(), systemMd, ivyRef); } else { if (md instanceof DefaultModuleDescriptor) { - ((DefaultModuleDescriptor)md).setModuleRevisionId(ModuleRevisionId.newInstance(mrid.getOrganisation(), mrid.getName(), ivyRef.getRevision())); + ((DefaultModuleDescriptor)md).setModuleRevisionId(ModuleRevisionId.newInstance(mrid.getOrganisation(), mrid.getName(), ivyRef.getRevision(), mrid.getExtraAttributes())); } else { Message.warn("consistency disabled with non default module descriptor... module info can't be updated, so consistency check will be done"); checkDescriptorConsistency(mrid, md, ivyRef); @@ -539,7 +539,8 @@ public abstract class BasicResolver extends AbstractResolver { artifacts[i].getPublicationDate(), artifacts[i].getName(), artifacts[i].getType(), - artifacts[i].getExt()+".part")); + artifacts[i].getExt()+".part", + artifacts[i].getExtraAttributes())); adr.setSize(get(artifactRef.getResource(), tmp)); if (!tmp.renameTo(archiveFile)) { originFile.delete(); diff --git a/src/java/fr/jayasoft/ivy/resolver/CacheResolver.java b/src/java/fr/jayasoft/ivy/resolver/CacheResolver.java index 2088acb3..1c23717d 100644 --- a/src/java/fr/jayasoft/ivy/resolver/CacheResolver.java +++ b/src/java/fr/jayasoft/ivy/resolver/CacheResolver.java @@ -59,7 +59,7 @@ public class CacheResolver extends FileSystemResolver { Message.verbose("\t"+getName()+": found ivy file in cache for "+mrid); Message.verbose("\t\t=> "+ivyRef); - ModuleRevisionId resolvedMrid = new ModuleRevisionId(mrid.getModuleId(), ivyRef.getRevision()); + ModuleRevisionId resolvedMrid = new ModuleRevisionId(mrid.getModuleId(), ivyRef.getRevision(), mrid.getExtraAttributes()); IvyNode node = data.getNode(resolvedMrid); if (node != null && node.getModuleRevision() != null) { // this revision has already be resolved : return it diff --git a/src/java/fr/jayasoft/ivy/resolver/IBiblioResolver.java b/src/java/fr/jayasoft/ivy/resolver/IBiblioResolver.java index 38f11c92..f7668444 100644 --- a/src/java/fr/jayasoft/ivy/resolver/IBiblioResolver.java +++ b/src/java/fr/jayasoft/ivy/resolver/IBiblioResolver.java @@ -12,6 +12,7 @@ import java.util.Date; import java.util.List; import fr.jayasoft.ivy.Artifact; +import fr.jayasoft.ivy.DefaultArtifact; import fr.jayasoft.ivy.DependencyDescriptor; import fr.jayasoft.ivy.Ivy; import fr.jayasoft.ivy.ModuleRevisionId; @@ -37,7 +38,7 @@ public class IBiblioResolver extends URLResolver { if (isM2compatible()) { ModuleRevisionId mrid = dd.getDependencyRevisionId(); mrid = convertM2IdForResourceSearch(mrid); - ResolvedResource rres = findResourceUsingPatterns(mrid, getIvyPatterns(), mrid.getName(), "pom", "pom", data.getDate()); + ResolvedResource rres = findResourceUsingPatterns(mrid, getIvyPatterns(), DefaultArtifact.newPomArtifact(mrid, data.getDate()), data.getDate()); return rres; } else { return null; diff --git a/src/java/fr/jayasoft/ivy/resolver/RepositoryResolver.java b/src/java/fr/jayasoft/ivy/resolver/RepositoryResolver.java index c11d55c4..076220c1 100644 --- a/src/java/fr/jayasoft/ivy/resolver/RepositoryResolver.java +++ b/src/java/fr/jayasoft/ivy/resolver/RepositoryResolver.java @@ -15,6 +15,7 @@ import java.util.List; import java.util.Map; import fr.jayasoft.ivy.Artifact; +import fr.jayasoft.ivy.DefaultArtifact; import fr.jayasoft.ivy.Ivy; import fr.jayasoft.ivy.LatestStrategy; import fr.jayasoft.ivy.ModuleRevisionId; @@ -54,16 +55,26 @@ public class RepositoryResolver extends AbstractResourceResolver { } - protected ResolvedResource findResourceUsingPattern(ModuleRevisionId mrid, String pattern, String artifact, String type, String ext, Date date) { - return findResourceUsingPattern(getName(), getRepository(), getLatestStrategy(), mrid, pattern, artifact, type, ext, date, isAlwaysCheckExactRevision()); + protected ResolvedResource findResourceUsingPattern(ModuleRevisionId mrid, String pattern, Artifact artifact, Date date) { + return findResourceUsingPattern(getName(), getRepository(), getLatestStrategy(), mrid, pattern, artifact, date, isAlwaysCheckExactRevision()); } + /** + * @deprecated + */ public static ResolvedResource findResourceUsingPattern(String name, Repository repository, LatestStrategy strategy, ModuleRevisionId mrid, String pattern, String artifact, String type, String ext, Date date) { return findResourceUsingPattern(name, repository, strategy, mrid, pattern, artifact, type, ext, date, true); } + /** + * @deprecated + */ public static ResolvedResource findResourceUsingPattern(String name, Repository repository, LatestStrategy strategy, ModuleRevisionId mrid, String pattern, String artifact, String type, String ext, Date date, boolean alwaysCheckExactRevision) { + return findResourceUsingPattern(name, repository, strategy, mrid, pattern, new DefaultArtifact(mrid, date, artifact, type, ext), date, alwaysCheckExactRevision); + } + + public static ResolvedResource findResourceUsingPattern(String name, Repository repository, LatestStrategy strategy, ModuleRevisionId mrid, String pattern, Artifact artifact, Date date, boolean alwaysCheckExactRevision) { try { if (mrid.isExactRevision() || alwaysCheckExactRevision) { - String resourceName = IvyPatternHelper.substitute(pattern, mrid, artifact, type, ext); + String resourceName = IvyPatternHelper.substitute(pattern, mrid, artifact); Message.debug("\t trying "+resourceName); Resource res = repository.getResource(resourceName); long start = System.currentTimeMillis(); @@ -71,22 +82,29 @@ public class RepositoryResolver extends AbstractResourceResolver { if (reachable) { return new ResolvedResource(res, mrid.getRevision()); } else if (!mrid.isExactRevision()) { - return findDynamicResourceUsingPattern(name, repository, strategy, mrid, pattern, artifact, type, ext, date); + return findDynamicResourceUsingPattern(name, repository, strategy, mrid, pattern, artifact, date); } else { Message.debug("\t"+name+": resource not reachable for "+mrid+": res="+res); return null; } } else { - return findDynamicResourceUsingPattern(name, repository, strategy, mrid, pattern, artifact, type, ext, date); + return findDynamicResourceUsingPattern(name, repository, strategy, mrid, pattern, artifact, date); } } catch (Exception ex) { - Message.debug("\t"+name+": unable to get resource for "+mrid+": res="+IvyPatternHelper.substitute(pattern, mrid, artifact, type, ext)+": "+ex.getMessage()); + Message.debug("\t"+name+": unable to get resource for "+mrid+": res="+IvyPatternHelper.substitute(pattern, mrid, artifact)+": "+ex.getMessage()); return null; } } + /** + * @deprecated + */ private static ResolvedResource findDynamicResourceUsingPattern(String name, Repository repository, LatestStrategy strategy, ModuleRevisionId mrid, String pattern, String artifact, String type, String ext, Date date) { - ResolvedResource[] rress = ResolverHelper.findAll(repository, mrid, pattern, artifact, type, ext); + return findDynamicResourceUsingPattern(name, repository, strategy, mrid, pattern, new DefaultArtifact(mrid, date, artifact, type, ext), date); + } + + private static ResolvedResource findDynamicResourceUsingPattern(String name, Repository repository, LatestStrategy strategy, ModuleRevisionId mrid, String pattern, Artifact artifact, Date date) { + ResolvedResource[] rress = ResolverHelper.findAll(repository, mrid, pattern, artifact); if (rress == null) { Message.debug("\t"+name+": unable to list resources for "+mrid+": pattern="+pattern); return null; @@ -113,16 +131,9 @@ public class RepositoryResolver extends AbstractResourceResolver { /** * Returns all resolved res matching the given pattern and matching given mrid, * or null if no lister is able to handle the given pattern - * - * @param mrid - * @param pattern - * @param artifact - * @param type - * @param ext - * @return */ - protected ResolvedResource[] findAll(ModuleRevisionId mrid, String pattern, String artifact, String type, String ext) { - return ResolverHelper.findAll(_repository, mrid, pattern, artifact, type, ext); + protected ResolvedResource[] findAll(ModuleRevisionId mrid, String pattern, Artifact artifact) { + return ResolverHelper.findAll(_repository, mrid, pattern, artifact); } protected long get(Resource resource, File ivyTempFile) throws IOException { @@ -146,12 +157,8 @@ public class RepositoryResolver extends AbstractResourceResolver { } String dest = IvyPatternHelper.substitute(destPattern, - mrid.getOrganisation(), - mrid.getName(), - mrid.getRevision(), - artifact.getName(), - artifact.getType(), - artifact.getExt()); + mrid, + artifact); _repository.put(src, dest, overwrite); Message.info("\tpublished "+artifact.getName()+" to "+dest); diff --git a/src/java/fr/jayasoft/ivy/resolver/ResolverHelper.java b/src/java/fr/jayasoft/ivy/resolver/ResolverHelper.java index 378d8715..195c58d7 100644 --- a/src/java/fr/jayasoft/ivy/resolver/ResolverHelper.java +++ b/src/java/fr/jayasoft/ivy/resolver/ResolverHelper.java @@ -10,11 +10,14 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; +import java.util.Date; import java.util.Iterator; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import fr.jayasoft.ivy.Artifact; +import fr.jayasoft.ivy.DefaultArtifact; import fr.jayasoft.ivy.ModuleRevisionId; import fr.jayasoft.ivy.ResolvedURL; import fr.jayasoft.ivy.repository.Repository; @@ -107,9 +110,16 @@ public class ResolverHelper { } } + /** + * @deprecated + */ public static ResolvedResource[] findAll(Repository rep, ModuleRevisionId mrid, String pattern, String artifact, String type, String ext) { + return findAll(rep, mrid, pattern, new DefaultArtifact(mrid, new Date(), artifact, type, ext)); + } + + public static ResolvedResource[] findAll(Repository rep, ModuleRevisionId mrid, String pattern, Artifact artifact) { // substitute all but revision - String partiallyResolvedPattern = IvyPatternHelper.substitute(pattern, new ModuleRevisionId(mrid.getModuleId(), IvyPatternHelper.getTokenString(IvyPatternHelper.REVISION_KEY)), artifact, type, ext); + String partiallyResolvedPattern = IvyPatternHelper.substitute(pattern, new ModuleRevisionId(mrid.getModuleId(), IvyPatternHelper.getTokenString(IvyPatternHelper.REVISION_KEY), mrid.getExtraAttributes()), artifact); Message.debug("\tlisting all in "+partiallyResolvedPattern); String[] revs = listTokenValues(rep, partiallyResolvedPattern, IvyPatternHelper.REVISION_KEY); @@ -147,13 +157,6 @@ public class ResolverHelper { return null; } - - - -// TODO: remove this code - - - // lists all the values a token can take in a pattern, as listed by a given url lister public static String[] listTokenValues(URLLister lister, String pattern, String token) { pattern = standardize(pattern); @@ -219,10 +222,39 @@ public class ResolverHelper { return path.replace('\\', '/'); } + public static String[] listAll(URLLister lister, URL root) { + try { + if (lister.accept(root.toExternalForm())) { + Message.debug("\tusing "+lister+" to list all in "+root); + List all = lister.listAll(root); + Message.debug("\t\tfound "+all.size()+" urls"); + List names = new ArrayList(all.size()); + for (Iterator iter = all.iterator(); iter.hasNext();) { + URL dir = (URL)iter.next(); + String path = dir.getPath(); + if (path.endsWith("/")) { + path = path.substring(0, path.length() - 1); + } + int slashIndex = path.lastIndexOf('/'); + names.add(path.substring(slashIndex +1)); + } + return (String[])names.toArray(new String[names.size()]); + } + return null; + } catch (Exception e) { + Message.warn("problem while listing directories in "+root+": "+e.getClass()+" "+e.getMessage()); + return null; + } + } + + + /** + * @deprecated + */ public static ResolvedURL[] findAll(URLLister lister, ModuleRevisionId mrid, String pattern, String artifact, String type, String ext) { if (lister.accept(pattern)) { // substitute all but revision - String partiallyResolvedPattern = IvyPatternHelper.substitute(pattern, new ModuleRevisionId(mrid.getModuleId(), IvyPatternHelper.getTokenString(IvyPatternHelper.REVISION_KEY)), artifact, type, ext); + String partiallyResolvedPattern = IvyPatternHelper.substitute(pattern, new ModuleRevisionId(mrid.getModuleId(), IvyPatternHelper.getTokenString(IvyPatternHelper.REVISION_KEY), mrid.getExtraAttributes()), artifact, type, ext); Message.debug("\tlisting all in "+partiallyResolvedPattern); String[] revs = listTokenValues(lister, partiallyResolvedPattern, IvyPatternHelper.REVISION_KEY); @@ -252,30 +284,4 @@ public class ResolverHelper { } return null; } - - public static String[] listAll(URLLister lister, URL root) { - try { - if (lister.accept(root.toExternalForm())) { - Message.debug("\tusing "+lister+" to list all in "+root); - List all = lister.listAll(root); - Message.debug("\t\tfound "+all.size()+" urls"); - List names = new ArrayList(all.size()); - for (Iterator iter = all.iterator(); iter.hasNext();) { - URL dir = (URL)iter.next(); - String path = dir.getPath(); - if (path.endsWith("/")) { - path = path.substring(0, path.length() - 1); - } - int slashIndex = path.lastIndexOf('/'); - names.add(path.substring(slashIndex +1)); - } - return (String[])names.toArray(new String[names.size()]); - } - return null; - } catch (Exception e) { - Message.warn("problem while listing directories in "+root+": "+e.getClass()+" "+e.getMessage()); - return null; - } - } - } diff --git a/src/java/fr/jayasoft/ivy/util/IvyPatternHelper.java b/src/java/fr/jayasoft/ivy/util/IvyPatternHelper.java index 368c08bd..907965d1 100644 --- a/src/java/fr/jayasoft/ivy/util/IvyPatternHelper.java +++ b/src/java/fr/jayasoft/ivy/util/IvyPatternHelper.java @@ -6,6 +6,8 @@ package fr.jayasoft.ivy.util; import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -14,6 +16,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import fr.jayasoft.ivy.Artifact; +import fr.jayasoft.ivy.DefaultArtifact; import fr.jayasoft.ivy.ModuleRevisionId; /** @@ -42,38 +45,50 @@ public class IvyPatternHelper { "ivy", "ivy", "xml", - null); + null, + moduleRevision.getAttributes()); } public static String substitute(String pattern, ModuleRevisionId moduleRevision, String artifact, String type, String ext) { return substitute(pattern, - moduleRevision.getOrganisation(), - moduleRevision.getName(), - moduleRevision.getRevision(), - artifact, - type, - ext, + moduleRevision, + new DefaultArtifact(moduleRevision, null, artifact, type, ext), null); } public static String substitute(String pattern, Artifact artifact) { return substitute(pattern, artifact, null); } public static String substitute(String pattern, Artifact artifact, String conf) { + return substitute(pattern, artifact.getModuleRevisionId(), artifact, null); + } + public static String substitute(String pattern, ModuleRevisionId mrid, Artifact artifact) { + return substitute(pattern, mrid, artifact, null); + } + public static String substitute(String pattern, ModuleRevisionId mrid, Artifact artifact, String conf) { + Map attributes = new HashMap(); + attributes.putAll(mrid.getAttributes()); + attributes.putAll(artifact.getAttributes()); return substitute(pattern, - artifact.getModuleRevisionId().getOrganisation(), - artifact.getModuleRevisionId().getName(), - artifact.getModuleRevisionId().getRevision(), + mrid.getOrganisation(), + mrid.getName(), + mrid.getRevision(), artifact.getName(), artifact.getType(), artifact.getExt(), - conf); + conf, + attributes); } + public static String substitute(String pattern, String org, String module, String revision, String artifact, String type, String ext) { return substitute(pattern, org, module, revision, artifact, type, ext, null); } public static String substitute(String pattern, String org, String module, String revision, String artifact, String type, String ext, String conf) { - Map tokens = new HashMap(); + return substitute(pattern, org, module, revision, artifact, type, ext, conf, null); + } + + public static String substitute(String pattern, String org, String module, String revision, String artifact, String type, String ext, String conf, Map extraAttributes) { + Map tokens = new HashMap(extraAttributes == null ? Collections.EMPTY_MAP : extraAttributes); tokens.put(ORGANISATION_KEY, org==null?"":org); tokens.put(ORGANISATION_KEY2, org==null?"":org); tokens.put(MODULE_KEY, module==null?"":module); @@ -294,5 +309,4 @@ public class IvyPatternHelper { System.out.println("pattern= "+pattern); System.out.println("resolved= "+substituteVariables(pattern, variables)); } - } diff --git a/src/java/fr/jayasoft/ivy/xml/XmlModuleDescriptorParser.java b/src/java/fr/jayasoft/ivy/xml/XmlModuleDescriptorParser.java index e7695577..62d7d5c1 100644 --- a/src/java/fr/jayasoft/ivy/xml/XmlModuleDescriptorParser.java +++ b/src/java/fr/jayasoft/ivy/xml/XmlModuleDescriptorParser.java @@ -10,8 +10,12 @@ import java.io.IOException; import java.net.URL; import java.text.ParseException; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; import java.util.List; +import java.util.Map; import javax.xml.parsers.ParserConfigurationException; @@ -24,7 +28,6 @@ import fr.jayasoft.ivy.ConflictManager; import fr.jayasoft.ivy.DefaultDependencyArtifactDescriptor; import fr.jayasoft.ivy.DefaultDependencyDescriptor; import fr.jayasoft.ivy.DefaultModuleDescriptor; -import fr.jayasoft.ivy.DefaultExtendableItem; import fr.jayasoft.ivy.Ivy; import fr.jayasoft.ivy.License; import fr.jayasoft.ivy.MDArtifact; @@ -33,6 +36,8 @@ import fr.jayasoft.ivy.ModuleId; import fr.jayasoft.ivy.ModuleRevisionId; import fr.jayasoft.ivy.Status; import fr.jayasoft.ivy.conflict.FixedConflictManager; +import fr.jayasoft.ivy.extendable.DefaultExtendableItem; +import fr.jayasoft.ivy.extendable.ExtendableItemHelper; import fr.jayasoft.ivy.matcher.PatternMatcher; import fr.jayasoft.ivy.namespace.Namespace; import fr.jayasoft.ivy.parser.AbstractModuleDescriptorParser; @@ -178,7 +183,7 @@ public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser { String org = _ivy.substitute(attributes.getValue("organisation")); String module = _ivy.substitute(attributes.getValue("module")); String revision = _ivy.substitute(attributes.getValue("revision")); - _md.setModuleRevisionId(ModuleRevisionId.newInstance(org, module, revision)); + _md.setModuleRevisionId(ModuleRevisionId.newInstance(org, module, revision, ExtendableItemHelper.getExtraAttributes(attributes, new String[] {"organisation", "module", "revision", "status", "publication", "namespace", "default"}))); String namespace = _ivy.substitute(attributes.getValue("namespace")); if (namespace != null) { @@ -205,7 +210,6 @@ public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser { _md.setPublicationDate(getDefaultPubDate()); } - fillAttributes(_md, attributes); } else if ("license".equals(qName)) { _md.addLicense(new License(_ivy.substitute(attributes.getValue("name")), _ivy.substitute(attributes.getValue("url")))); } else if ("description".equals(qName)) { @@ -237,8 +241,7 @@ public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser { // this is a published artifact String ext = _ivy.substitute(attributes.getValue("ext")); ext = ext != null?ext:_ivy.substitute(attributes.getValue("type")); - _artifact = new MDArtifact(_md, _ivy.substitute(attributes.getValue("name")), _ivy.substitute(attributes.getValue("type")), ext); - fillAttributes(_artifact, attributes); + _artifact = new MDArtifact(_md, _ivy.substitute(attributes.getValue("name")), _ivy.substitute(attributes.getValue("type")), ext, ExtendableItemHelper.getExtraAttributes(attributes, new String[] {"ext", "type", "name", "conf"})); String confs = _ivy.substitute(attributes.getValue("conf")); // only add confs if they are specified. if they aren't, endElement will handle this // only if there are no conf defined in sub elements @@ -277,8 +280,7 @@ public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser { String name = _ivy.substitute(attributes.getValue("name")); String rev = _ivy.substitute(attributes.getValue("rev")); - _dd = new DefaultDependencyDescriptor(_md, ModuleRevisionId.newInstance(org, name, rev), force, changing, transitive); - fillAttributes(_dd, attributes); + _dd = new DefaultDependencyDescriptor(_md, ModuleRevisionId.newInstance(org, name, rev, ExtendableItemHelper.getExtraAttributes(attributes, new String[] {"org", "name", "rev", "force", "transitive", "changing", "conf"})), force, changing, transitive); _md.addDependency(_dd); String confs = _ivy.substitute(attributes.getValue("conf")); if (confs != null && confs.length() > 0) { @@ -298,7 +300,7 @@ public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser { _ivy.substitute(attributes.getValue("description")), ext==null?null:ext.split(","), transitive); - fillAttributes(configuration, attributes); + ExtendableItemHelper.fillExtraAttributes(configuration, attributes, new String[] {"name", "visibility", "extends", "transitive", "description"}); _md.addConfiguration(configuration); break; case PUB: @@ -481,13 +483,6 @@ public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser { } - public void fillAttributes(DefaultExtendableItem item, Attributes attributes) { - for (int i=0; i + + + + + diff --git a/test/java/fr/jayasoft/ivy/xml/XmlModuleDescriptorParserTest.java b/test/java/fr/jayasoft/ivy/xml/XmlModuleDescriptorParserTest.java index 09365e9c..8dfe2eed 100644 --- a/test/java/fr/jayasoft/ivy/xml/XmlModuleDescriptorParserTest.java +++ b/test/java/fr/jayasoft/ivy/xml/XmlModuleDescriptorParserTest.java @@ -426,6 +426,7 @@ public class XmlModuleDescriptorParserTest extends AbstractModuleDescriptorParse assertNotNull(md); assertEquals("infoextravalue", md.getAttribute("infoextra")); + assertEquals("infoextravalue", md.getModuleRevisionId().getAttribute("infoextra")); assertEquals("confextravalue", md.getConfiguration("default").getAttribute("confextra")); @@ -445,6 +446,7 @@ public class XmlModuleDescriptorParserTest extends AbstractModuleDescriptorParse assertEquals("myorg", dd.getDependencyId().getOrganisation()); assertEquals("1.0", dd.getDependencyRevisionId().getRevision()); assertEquals("depextravalue", dd.getAttribute("depextra")); + assertEquals("depextravalue", dd.getDependencyRevisionId().getAttribute("depextra")); } public void testImportConfigurations1() throws Exception { diff --git a/test/repositories/extra-attributes/ivyconf.xml b/test/repositories/extra-attributes/ivyconf.xml new file mode 100644 index 00000000..bd834fd4 --- /dev/null +++ b/test/repositories/extra-attributes/ivyconf.xml @@ -0,0 +1,14 @@ + + + + + + + + + diff --git a/test/repositories/extra-attributes/mymodule/task1/1854/ivy.xml b/test/repositories/extra-attributes/mymodule/task1/1854/ivy.xml new file mode 100644 index 00000000..bcf2624e --- /dev/null +++ b/test/repositories/extra-attributes/mymodule/task1/1854/ivy.xml @@ -0,0 +1,14 @@ + + + + + + + + + diff --git a/test/repositories/extra-attributes/mymodule/task1/1854/mymodule-linux.jar b/test/repositories/extra-attributes/mymodule/task1/1854/mymodule-linux.jar new file mode 100644 index 00000000..0519ecba --- /dev/null +++ b/test/repositories/extra-attributes/mymodule/task1/1854/mymodule-linux.jar @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/repositories/extra-attributes/mymodule/task1/1854/mymodule-windows.jar b/test/repositories/extra-attributes/mymodule/task1/1854/mymodule-windows.jar new file mode 100644 index 00000000..0519ecba --- /dev/null +++ b/test/repositories/extra-attributes/mymodule/task1/1854/mymodule-windows.jar @@ -0,0 +1 @@ + \ No newline at end of file