diff --git a/CHANGES.txt b/CHANGES.txt index e632e37a..a493331a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,5 @@ +- new useRemoteConfig on conf tag in ivyconf.xml, tells to use remote configuration file + for repository config - new type filtering in cachepath task - new cachefileset task: builds an ant fileset of artifacts in cache - publish task now uses srcivypattern for ivy files finding and for delivery diff --git a/src/java/fr/jayasoft/ivy/Ivy.java b/src/java/fr/jayasoft/ivy/Ivy.java index 1fb590e7..18710924 100644 --- a/src/java/fr/jayasoft/ivy/Ivy.java +++ b/src/java/fr/jayasoft/ivy/Ivy.java @@ -58,6 +58,7 @@ import fr.jayasoft.ivy.resolver.DualResolver; import fr.jayasoft.ivy.resolver.ModuleEntry; import fr.jayasoft.ivy.resolver.OrganisationEntry; import fr.jayasoft.ivy.resolver.RevisionEntry; +import fr.jayasoft.ivy.url.URLHandlerRegistry; import fr.jayasoft.ivy.util.FileUtil; import fr.jayasoft.ivy.util.IvyPatternHelper; import fr.jayasoft.ivy.util.Message; @@ -111,6 +112,8 @@ public class Ivy implements TransferListener { private List _listingIgnore = new ArrayList(); private boolean _repositoriesConfigured; + + private boolean _useRemoteConfig = true; public Ivy() { String ivyTypeDefs = System.getProperty("ivy.typedef.files"); @@ -165,19 +168,24 @@ public class Ivy implements TransferListener { } /** - * Call this method to ask ivy to configure some variables using a remote properties file + * Call this method to ask ivy to configure some variables using either a remote or a local properties file */ - public void configureRepositories() { + public void configureRepositories(boolean remote) { if (!_repositoriesConfigured) { - Properties props; - try { - props = new Properties(); - URL url = new URL("http://ivy.jayasoft.org/repository.properties"); - Message.verbose("configuring repositories with "+url); - props.load(url.openStream()); - } catch (Exception ex) { - Message.verbose("unable to use remote repository configuration: "+ex.getMessage()); - props = new Properties(); + Properties props = new Properties(); + boolean configured = false; + if (_useRemoteConfig && remote) { + try { + URL url = new URL("http://ivy.jayasoft.org/repository.properties"); + Message.verbose("configuring repositories with "+url); + props.load(URLHandlerRegistry.getDefault().openStream(url)); + configured = true; + } catch (Exception ex) { + Message.verbose("unable to use remote repository configuration: "+ex.getMessage()); + props = new Properties(); + } + } + if (!configured) { try { props.load(Ivy.class.getResourceAsStream("repository.properties")); } catch (IOException e) { @@ -1494,4 +1502,12 @@ public class Ivy implements TransferListener { fireTransferEvent(evt); } + public boolean isUseRemoteConfig() { + return _useRemoteConfig; + } + + public void setUseRemoteConfig(boolean useRemoteConfig) { + _useRemoteConfig = useRemoteConfig; + } + } diff --git a/src/java/fr/jayasoft/ivy/resolver/AbstractResourceResolver.java b/src/java/fr/jayasoft/ivy/resolver/AbstractResourceResolver.java index 8584f934..577f03e3 100644 --- a/src/java/fr/jayasoft/ivy/resolver/AbstractResourceResolver.java +++ b/src/java/fr/jayasoft/ivy/resolver/AbstractResourceResolver.java @@ -21,7 +21,6 @@ import java.util.Map; import fr.jayasoft.ivy.Artifact; import fr.jayasoft.ivy.DefaultArtifact; import fr.jayasoft.ivy.DependencyDescriptor; -import fr.jayasoft.ivy.ModuleDescriptor; import fr.jayasoft.ivy.ModuleRevisionId; import fr.jayasoft.ivy.ResolveData; import fr.jayasoft.ivy.repository.Resource; @@ -46,23 +45,8 @@ public abstract class AbstractResourceResolver extends BasicResolver { return findResourceUsingPatterns(dd.getDependencyRevisionId(), _ivyPatterns, "ivy", "ivy", "xml", data.getDate()); } - protected ResolvedResource findFirstArtifactRef(ModuleDescriptor md, DependencyDescriptor dd, ResolveData data) { - ResolvedResource ret = null; - String[] conf = md.getConfigurationsNames(); - for (int i = 0; i < conf.length; i++) { - Artifact[] artifacts = md.getArtifacts(conf[i]); - for (int j = 0; j < artifacts.length; j++) { - ret = findResourceUsingPatterns(dd.getDependencyRevisionId(), _artifactPatterns, artifacts[j].getName(), artifacts[j].getType(), artifacts[j].getExt(), data.getDate()); - if (ret != null) { - return ret; - } - } - } - return null; - } - - protected ResolvedResource findArtifactRef(Artifact artifact) { - return findResourceUsingPatterns(artifact.getModuleRevisionId(), _artifactPatterns, artifact.getName(), artifact.getType(), artifact.getExt(), null); + protected ResolvedResource findArtifactRef(Artifact artifact, Date date) { + return findResourceUsingPatterns(artifact.getModuleRevisionId(), _artifactPatterns, artifact.getName(), artifact.getType(), artifact.getExt(), date); } protected ResolvedResource findResourceUsingPatterns(ModuleRevisionId moduleRevision, List patternList, String artifact, String type, String ext, Date date) { diff --git a/src/java/fr/jayasoft/ivy/resolver/BasicResolver.java b/src/java/fr/jayasoft/ivy/resolver/BasicResolver.java index 1cde2302..f5533a38 100644 --- a/src/java/fr/jayasoft/ivy/resolver/BasicResolver.java +++ b/src/java/fr/jayasoft/ivy/resolver/BasicResolver.java @@ -410,7 +410,7 @@ public abstract class BasicResolver extends AbstractResolver { adr.setDownloadStatus(DownloadStatus.NO); adr.setSize(archiveFile.length()); } else { - ResolvedResource artifactRef = findArtifactRef(artifacts[i]); + ResolvedResource artifactRef = findArtifactRef(artifacts[i], null); if (artifactRef != null) { long start = System.currentTimeMillis(); try { @@ -440,7 +440,7 @@ public abstract class BasicResolver extends AbstractResolver { } public boolean exists(Artifact artifact) { - ResolvedResource artifactRef = findArtifactRef(artifact); + ResolvedResource artifactRef = findArtifactRef(artifact, null); if (artifactRef != null) { return artifactRef.getResource().exists(); } @@ -504,9 +504,23 @@ public abstract class BasicResolver extends AbstractResolver { protected abstract ResolvedResource findIvyFileRef(DependencyDescriptor dd, ResolveData data); - protected abstract ResolvedResource findFirstArtifactRef(ModuleDescriptor md, DependencyDescriptor dd, ResolveData data); + protected ResolvedResource findFirstArtifactRef(ModuleDescriptor md, DependencyDescriptor dd, ResolveData data) { + ResolvedResource ret = null; + String[] conf = md.getConfigurationsNames(); + for (int i = 0; i < conf.length; i++) { + Artifact[] artifacts = md.getArtifacts(conf[i]); + for (int j = 0; j < artifacts.length; j++) { + ret = findArtifactRef(artifacts[j], data.getDate()); + if (ret != null) { + return ret; + } + } + } + return null; + } - protected abstract ResolvedResource findArtifactRef(Artifact artifact); + + protected abstract ResolvedResource findArtifactRef(Artifact artifact, Date date); protected abstract long get(Resource resource, File ivyTempFile) throws IOException; diff --git a/src/java/fr/jayasoft/ivy/resolver/IBiblioResolver.java b/src/java/fr/jayasoft/ivy/resolver/IBiblioResolver.java index 225aaf5c..6577c895 100644 --- a/src/java/fr/jayasoft/ivy/resolver/IBiblioResolver.java +++ b/src/java/fr/jayasoft/ivy/resolver/IBiblioResolver.java @@ -6,10 +6,17 @@ package fr.jayasoft.ivy.resolver; import java.io.File; +import java.text.ParseException; import java.util.Collections; +import java.util.Date; +import java.util.List; import fr.jayasoft.ivy.Artifact; +import fr.jayasoft.ivy.DependencyDescriptor; import fr.jayasoft.ivy.Ivy; +import fr.jayasoft.ivy.ResolveData; +import fr.jayasoft.ivy.ResolvedModuleRevision; +import fr.jayasoft.ivy.report.DownloadReport; /** * IBiblioResolver is a resolver which can be used to resolve dependencies found @@ -25,26 +32,28 @@ public class IBiblioResolver extends URLResolver { public IBiblioResolver() { } - public void setIvy(Ivy ivy) { - super.setIvy(ivy); - ivy.configureRepositories(); - if (_root == null) { - String root = ivy.getVariable("ivy.ibiblio.default.artifact.root"); - if (root != null) { - _root = root; - } else { - _root = DEFAULT_ROOT; + public void ensureConfigured(Ivy ivy) { + if (ivy != null && (_root == null || _pattern == null)) { + if (_root == null) { + String root = ivy.getVariable("ivy.ibiblio.default.artifact.root"); + if (root != null) { + _root = root; + } else { + ivy.configureRepositories(true); + _root = ivy.getVariable("ivy.ibiblio.default.artifact.root"); + } } - } - if (_pattern == null) { - String pattern = ivy.getVariable("ivy.ibiblio.default.artifact.pattern"); - if (pattern != null) { - _pattern = pattern; - } else { - _pattern = DEFAULT_PATTERN; + if (_pattern == null) { + String pattern = ivy.getVariable("ivy.ibiblio.default.artifact.pattern"); + if (pattern != null) { + _pattern = pattern; + } else { + ivy.configureRepositories(false); + _pattern = ivy.getVariable("ivy.ibiblio.default.artifact.pattern"); + } } + updateWholePattern(); } - updateWholePattern(); } private String getWholePattern() { @@ -58,6 +67,7 @@ public class IBiblioResolver extends URLResolver { throw new NullPointerException("pattern must not be null"); } _pattern = pattern; + ensureConfigured(getIvy()); updateWholePattern(); } public String getRoot() { @@ -78,6 +88,7 @@ public class IBiblioResolver extends URLResolver { } else { _root = root; } + ensureConfigured(getIvy()); updateWholePattern(); } @@ -94,8 +105,35 @@ public class IBiblioResolver extends URLResolver { public ModuleEntry[] listModules(OrganisationEntry org) { return null; } + public RevisionEntry[] listRevisions(ModuleEntry mod) { + ensureConfigured(getIvy()); + return super.listRevisions(mod); + } public String getTypeName() { return "ibiblio"; } + // override some methods to ensure configuration + public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) throws ParseException { + ensureConfigured(data.getIvy()); + return super.getDependency(dd, data); + } + + protected ResolvedResource findArtifactRef(Artifact artifact, Date date) { + ensureConfigured(getIvy()); + return super.findArtifactRef(artifact, date); + } + + public DownloadReport download(Artifact[] artifacts, Ivy ivy, File cache) { + ensureConfigured(ivy); + return super.download(artifacts, ivy, cache); + } + public boolean exists(Artifact artifact) { + ensureConfigured(getIvy()); + return super.exists(artifact); + } + public List getArtifactPatterns() { + ensureConfigured(getIvy()); + return super.getArtifactPatterns(); + } } diff --git a/src/java/fr/jayasoft/ivy/resolver/IvyRepResolver.java b/src/java/fr/jayasoft/ivy/resolver/IvyRepResolver.java index 2e7307ca..c5e2b910 100644 --- a/src/java/fr/jayasoft/ivy/resolver/IvyRepResolver.java +++ b/src/java/fr/jayasoft/ivy/resolver/IvyRepResolver.java @@ -8,9 +8,11 @@ package fr.jayasoft.ivy.resolver; import java.io.File; import java.net.MalformedURLException; import java.net.URL; +import java.text.ParseException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -20,7 +22,11 @@ import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; import fr.jayasoft.ivy.Artifact; +import fr.jayasoft.ivy.DependencyDescriptor; import fr.jayasoft.ivy.Ivy; +import fr.jayasoft.ivy.ResolveData; +import fr.jayasoft.ivy.ResolvedModuleRevision; +import fr.jayasoft.ivy.report.DownloadReport; import fr.jayasoft.ivy.util.IvyPatternHelper; import fr.jayasoft.ivy.util.Message; import fr.jayasoft.ivy.util.XMLHelper; @@ -43,43 +49,52 @@ public class IvyRepResolver extends URLResolver { public IvyRepResolver() { } - public void setIvy(Ivy ivy) { - super.setIvy(ivy); - ivy.configureRepositories(); - if (_ivyroot == null) { - String root = ivy.getVariable("ivy.ivyrep.default.ivy.root"); - if (root != null) { - _ivyroot = root; - } else { - _ivyroot = DEFAULT_IVYROOT; + private void ensureArtifactConfigured(Ivy ivy) { + if (ivy != null && (_artroot == null || _artpattern == null)) { + if (_artroot == null) { + String root = ivy.getVariable("ivy.ivyrep.default.artifact.root"); + if (root != null) { + _artroot = root; + } else { + ivy.configureRepositories(true); + _artroot = ivy.getVariable("ivy.ivyrep.default.artifact.root"); + } } - } - if (_ivypattern == null) { - String pattern = ivy.getVariable("ivy.ivyrep.default.ivy.pattern"); - if (pattern != null) { - _ivypattern = pattern; - } else { - _ivypattern = DEFAULT_IVYPATTERN; + if (_artpattern == null) { + String pattern = ivy.getVariable("ivy.ivyrep.default.artifact.pattern"); + if (pattern != null) { + _artpattern = pattern; + } else { + ivy.configureRepositories(false); + _artpattern = ivy.getVariable("ivy.ivyrep.default.artifact.pattern"); + } } + updateWholeArtPattern(); } - if (_artroot == null) { - String root = ivy.getVariable("ivy.ivyrep.default.artifact.root"); - if (root != null) { - _artroot = root; - } else { - _artroot = IBiblioResolver.DEFAULT_ROOT; + } + + private void ensureIvyConfigured(Ivy ivy) { + if (ivy != null && (_ivyroot == null || _ivypattern == null)) { + if (_ivyroot == null) { + String root = ivy.getVariable("ivy.ivyrep.default.ivy.root"); + if (root != null) { + _ivyroot = root; + } else { + ivy.configureRepositories(true); + _ivyroot = ivy.getVariable("ivy.ivyrep.default.ivy.root"); + } } - } - if (_artpattern == null) { - String pattern = ivy.getVariable("ivy.ivyrep.default.artifact.pattern"); - if (pattern != null) { - _artpattern = pattern; - } else { - _artpattern = IBiblioResolver.DEFAULT_PATTERN; + if (_ivypattern == null) { + String pattern = ivy.getVariable("ivy.ivyrep.default.ivy.pattern"); + if (pattern != null) { + _ivypattern = pattern; + } else { + ivy.configureRepositories(false); + _ivypattern = ivy.getVariable("ivy.ivyrep.default.ivy.pattern"); + } } + updateWholeIvyPattern(); } - updateWholeIvyPattern(); - updateWholeArtPattern(); } private String getWholeIvyPattern() { @@ -96,6 +111,7 @@ public class IvyRepResolver extends URLResolver { throw new NullPointerException("pattern must not be null"); } _ivypattern = pattern; + ensureIvyConfigured(getIvy()); updateWholeIvyPattern(); } public String getIvyroot() { @@ -116,6 +132,7 @@ public class IvyRepResolver extends URLResolver { } else { _ivyroot = root; } + ensureIvyConfigured(getIvy()); updateWholeIvyPattern(); } @@ -144,6 +161,7 @@ public class IvyRepResolver extends URLResolver { throw new NullPointerException("pattern must not be null"); } _artpattern = pattern; + ensureArtifactConfigured(getIvy()); updateWholeArtPattern(); } @@ -156,10 +174,12 @@ public class IvyRepResolver extends URLResolver { } else { _artroot = root; } + ensureArtifactConfigured(getIvy()); updateWholeArtPattern(); } public OrganisationEntry[] listOrganisations() { + ensureIvyConfigured(getIvy()); try { URL content = new URL(_ivyroot + "content.xml"); final List ret = new ArrayList(); @@ -183,6 +203,7 @@ public class IvyRepResolver extends URLResolver { // overwrite parent to use only ivy patterns (and not artifact ones, cause ibiblio is too slow to answer) public ModuleEntry[] listModules(OrganisationEntry org) { + ensureIvyConfigured(getIvy()); Map tokenValues = new HashMap(); tokenValues.put(IvyPatternHelper.ORGANISATION_KEY, org.getOrganisation()); Collection names = findIvyNames(tokenValues, IvyPatternHelper.MODULE_KEY); @@ -194,8 +215,42 @@ public class IvyRepResolver extends URLResolver { } return ret; } + + public RevisionEntry[] listRevisions(ModuleEntry mod) { + ensureIvyConfigured(getIvy()); + ensureArtifactConfigured(getIvy()); + return super.listRevisions(mod); + } public String getTypeName() { return "ivyrep"; } + + // override some methods to ensure configuration + public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) throws ParseException { + ensureIvyConfigured(data.getIvy()); + return super.getDependency(dd, data); + } + + protected ResolvedResource findArtifactRef(Artifact artifact, Date date) { + ensureArtifactConfigured(getIvy()); + return super.findArtifactRef(artifact, date); + } + + public DownloadReport download(Artifact[] artifacts, Ivy ivy, File cache) { + ensureArtifactConfigured(ivy); + return super.download(artifacts, ivy, cache); + } + public boolean exists(Artifact artifact) { + ensureArtifactConfigured(getIvy()); + return super.exists(artifact); + } + public List getIvyPatterns() { + ensureIvyConfigured(getIvy()); + return super.getIvyPatterns(); + } + public List getArtifactPatterns() { + ensureArtifactConfigured(getIvy()); + return super.getArtifactPatterns(); + } } diff --git a/src/java/fr/jayasoft/ivy/xml/XmlIvyConfigurationParser.java b/src/java/fr/jayasoft/ivy/xml/XmlIvyConfigurationParser.java index 8a5e3294..7efbf434 100644 --- a/src/java/fr/jayasoft/ivy/xml/XmlIvyConfigurationParser.java +++ b/src/java/fr/jayasoft/ivy/xml/XmlIvyConfigurationParser.java @@ -118,6 +118,10 @@ public class XmlIvyConfigurationParser extends DefaultHandler { if (cacheArtPattern != null) { _ivy.setCacheArtifactPattern(_ivy.substitute(cacheArtPattern)); } + String useRemoteConfig = attributes.getValue("useRemoteConfig"); + if (useRemoteConfig != null) { + _ivy.setUseRemoteConfig(Boolean.valueOf(_ivy.substitute(useRemoteConfig)).booleanValue()); + } // we do not set following defaults here since no instances has been registered yet _defaultResolver = attributes.getValue("defaultResolver");