Author: maartenc Date: Thu Oct 11 21:08:27 2012 New Revision: 1397312 URL: http://svn.apache.org/viewvc?rev=1397312&view=rev Log: Re-implemented IVY-1281 because current implementation had too much issues. (merged from trunk)
Modified: ant/ivy/core/branches/2.3.x/ (props changed) ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/cache/DefaultResolutionCacheManager.java ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/cache/ResolutionCacheManager.java ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/deliver/DeliverEngine.java ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/module/descriptor/DefaultExtendsDescriptor.java ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/module/descriptor/DefaultModuleDescriptor.java ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/module/descriptor/ExtendsDescriptor.java ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/publish/PublishEngine.java ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/resolve/ResolveEngine.java ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/settings/IvySettings.java ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java Propchange: ant/ivy/core/branches/2.3.x/ ------------------------------------------------------------------------------ Merged /ant/ivy/core/trunk:r1396296 Modified: ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/cache/DefaultResolutionCacheManager.java URL: http://svn.apache.org/viewvc/ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/cache/DefaultResolutionCacheManager.java?rev=1397312&r1=1397311&r2=1397312&view=diff ============================================================================== --- ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/cache/DefaultResolutionCacheManager.java (original) +++ ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/cache/DefaultResolutionCacheManager.java Thu Oct 11 21:08:27 2012 @@ -18,13 +18,35 @@ package org.apache.ivy.core.cache; import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.FilenameFilter; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.text.ParseException; +import java.util.Map; +import java.util.Properties; import org.apache.ivy.core.IvyPatternHelper; +import org.apache.ivy.core.RelativeUrlResolver; +import org.apache.ivy.core.module.descriptor.ExtendsDescriptor; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleId; import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.module.status.StatusManager; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.IvySettingsAware; +import org.apache.ivy.plugins.conflict.ConflictManager; +import org.apache.ivy.plugins.matcher.PatternMatcher; +import org.apache.ivy.plugins.namespace.Namespace; +import org.apache.ivy.plugins.parser.ParserSettings; +import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParser; +import org.apache.ivy.plugins.resolver.DependencyResolver; import org.apache.ivy.util.FileUtil; -public class DefaultResolutionCacheManager implements ResolutionCacheManager { +public class DefaultResolutionCacheManager implements ResolutionCacheManager, IvySettingsAware { + private static final String DEFAULT_CACHE_RESOLVED_IVY_PATTERN = "resolved-[organisation]-[module]-[revision].xml"; @@ -39,7 +61,9 @@ public class DefaultResolutionCacheManag private File basedir; - private String name = "resolution-cache"; + private String name = "resolution-cache"; + + private IvySettings settings; public DefaultResolutionCacheManager() { } @@ -47,6 +71,10 @@ public class DefaultResolutionCacheManag public DefaultResolutionCacheManager(File basedir) { setBasedir(basedir); } + + public void setSettings(IvySettings settings) { + this.settings = settings; + } public File getResolutionCacheRoot() { return basedir; @@ -110,6 +138,62 @@ public class DefaultResolutionCacheManag } }); } + + public ModuleDescriptor getResolveModuleDescriptor(ModuleRevisionId mrid) + throws ParseException, IOException { + File ivyFile = getResolvedIvyFileInCache(mrid); + if (!ivyFile.exists()) { + throw new IllegalStateException("Ivy file not found in cache for " + mrid + "!"); + } + + Properties paths = new Properties(); + + File parentsFile = getResolvedIvyPropertiesInCache(ModuleRevisionId.newInstance(mrid, mrid.getRevision() + "-parents")); + if (parentsFile.exists()) { + FileInputStream in = new FileInputStream(parentsFile); + paths.load(in); + in.close(); + } + + ParserSettings pSettings = new CacheParserSettings(settings, paths); + + URL ivyFileURL = ivyFile.toURI().toURL(); + return XmlModuleDescriptorParser.getInstance().parseDescriptor(pSettings, ivyFileURL, false); + } + + public void saveResolvedModuleDescriptor(ModuleDescriptor md) throws ParseException, IOException { + ModuleRevisionId mrevId = md.getResolvedModuleRevisionId(); + File ivyFileInCache = getResolvedIvyFileInCache(mrevId); + md.toIvyFile(ivyFileInCache); + + Properties paths = new Properties(); + saveLocalParents(mrevId, md, ivyFileInCache, paths); + + if (!paths.isEmpty()) { + File parentsFile = getResolvedIvyPropertiesInCache(ModuleRevisionId.newInstance(mrevId, mrevId.getRevision() + "-parents")); + FileOutputStream out = new FileOutputStream(parentsFile); + paths.store(out, null); + out.close(); + } + } + + private void saveLocalParents(ModuleRevisionId baseMrevId, ModuleDescriptor md, File mdFile, Properties paths) throws ParseException, IOException { + ExtendsDescriptor[] parents = md.getInheritedDescriptors(); + for (int i = 0; i < parents.length; i++) { + if (!parents[i].isLocal()) { + // we store only local parents in the cache! + continue; + } + + ModuleDescriptor parent = parents[i].getParentMd(); + ModuleRevisionId pRevId = ModuleRevisionId.newInstance(baseMrevId, baseMrevId.getRevision() + "-parent." + paths.size()); + File parentFile = getResolvedIvyFileInCache(pRevId); + parent.toIvyFile(parentFile); + + paths.setProperty(mdFile.getName() + "|" + parents[i].getLocation(), parentFile.getAbsolutePath()); + saveLocalParents(baseMrevId, parent, parentFile, paths); + } + } public String toString() { return name; @@ -118,5 +202,88 @@ public class DefaultResolutionCacheManag public void clean() { FileUtil.forceDelete(getBasedir()); } - + + private static class CacheParserSettings implements ParserSettings { + + private ParserSettings delegate; + private Map parentPaths; + + public CacheParserSettings(ParserSettings delegate, Map parentPaths) { + this.delegate = delegate; + this.parentPaths = parentPaths; + } + + public String substitute(String value) { + return delegate.substitute(value); + } + + public Map substitute(Map strings) { + return delegate.substitute(strings); + } + + public ResolutionCacheManager getResolutionCacheManager() { + return delegate.getResolutionCacheManager(); + } + + public ConflictManager getConflictManager(String name) { + return delegate.getConflictManager(name); + } + + public PatternMatcher getMatcher(String matcherName) { + return delegate.getMatcher(matcherName); + } + + public Namespace getNamespace(String namespace) { + return delegate.getNamespace(namespace); + } + + public StatusManager getStatusManager() { + return delegate.getStatusManager(); + } + + public RelativeUrlResolver getRelativeUrlResolver() { + return new MapURLResolver(parentPaths, delegate.getRelativeUrlResolver()); + } + + public DependencyResolver getResolver(ModuleRevisionId mRevId) { + return delegate.getResolver(mRevId); + } + + public File resolveFile(String filename) { + return delegate.resolveFile(filename); + } + + public String getDefaultBranch(ModuleId moduleId) { + return delegate.getDefaultBranch(moduleId); + } + + public Namespace getContextNamespace() { + return delegate.getContextNamespace(); + } + } + + private static class MapURLResolver extends RelativeUrlResolver { + + private Map paths; + private RelativeUrlResolver delegate; + + private MapURLResolver(Map paths, RelativeUrlResolver delegate) { + this.paths = paths; + this.delegate = delegate; + } + + public URL getURL(URL context, String url) throws MalformedURLException { + String path = context.getPath(); + if (path.indexOf('/') >= 0) { + String file = path.substring(path.lastIndexOf('/') + 1); + + if (paths.containsKey(file + "|" + url)) { + File result = new File(paths.get(file + "|" + url).toString()); + return result.toURI().toURL(); + } + } + + return delegate.getURL(context, url); + } + } } Modified: ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/cache/ResolutionCacheManager.java URL: http://svn.apache.org/viewvc/ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/cache/ResolutionCacheManager.java?rev=1397312&r1=1397311&r2=1397312&view=diff ============================================================================== --- ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/cache/ResolutionCacheManager.java (original) +++ ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/cache/ResolutionCacheManager.java Thu Oct 11 21:08:27 2012 @@ -18,22 +18,30 @@ package org.apache.ivy.core.cache; import java.io.File; +import java.io.IOException; +import java.text.ParseException; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; import org.apache.ivy.core.module.id.ModuleRevisionId; public interface ResolutionCacheManager { - public abstract File getResolutionCacheRoot(); - public abstract File getResolvedIvyFileInCache(ModuleRevisionId mrid); - - public abstract File getResolvedIvyPropertiesInCache(ModuleRevisionId mrid); + File getResolutionCacheRoot(); + + File getResolvedIvyFileInCache(ModuleRevisionId mrid); + + File getResolvedIvyPropertiesInCache(ModuleRevisionId mrid); - public abstract File getConfigurationResolveReportInCache(String resolveId, String conf); + File getConfigurationResolveReportInCache(String resolveId, String conf); - public abstract File[] getConfigurationResolveReportsInCache(final String resolveId); + File[] getConfigurationResolveReportsInCache(final String resolveId); + + ModuleDescriptor getResolveModuleDescriptor(ModuleRevisionId mrid) throws ParseException, IOException; + + void saveResolvedModuleDescriptor(ModuleDescriptor md) throws ParseException, IOException; /** * Cleans the whole cache. */ - public void clean(); + void clean(); } Modified: ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/deliver/DeliverEngine.java URL: http://svn.apache.org/viewvc/ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/deliver/DeliverEngine.java?rev=1397312&r1=1397311&r2=1397312&view=diff ============================================================================== --- ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/deliver/DeliverEngine.java (original) +++ ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/deliver/DeliverEngine.java Thu Oct 11 21:08:27 2012 @@ -40,6 +40,7 @@ import org.apache.ivy.plugins.parser.xml import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParser; import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorUpdater; import org.apache.ivy.plugins.report.XmlReportParser; +import org.apache.ivy.plugins.repository.Resource; import org.apache.ivy.util.ConfigurationUtils; import org.apache.ivy.util.Message; import org.xml.sax.SAXException; @@ -107,27 +108,11 @@ public class DeliverEngine { destIvyPattern = settings.substitute(destIvyPattern); // 1) find the resolved module descriptor in cache - File ivyFile = getCache().getResolvedIvyFileInCache(mrid); - if (!ivyFile.exists()) { - throw new IllegalStateException("ivy file not found in cache for " + mrid - + ": please resolve dependencies before delivering (" + ivyFile + ")"); - } - ModuleDescriptor md = null; - URL ivyFileURL = null; - try { - ivyFileURL = ivyFile.toURI().toURL(); - md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, ivyFileURL, - options.isValidate()); - md.setResolvedModuleRevisionId(ModuleRevisionId.newInstance(md.getModuleRevisionId(), - options.getPubBranch() == null ? mrid.getBranch() : options.getPubBranch(), - revision)); - md.setResolvedPublicationDate(options.getPubdate()); - } catch (MalformedURLException e) { - throw new RuntimeException("malformed url obtained for file " + ivyFile, e); - } catch (ParseException e) { - throw new RuntimeException("bad ivy file in cache for " + mrid - + ": please clean '" + ivyFile + "' and resolve again", e); - } + ModuleDescriptor md = getCache().getResolveModuleDescriptor(mrid); + md.setResolvedModuleRevisionId(ModuleRevisionId.newInstance(md.getModuleRevisionId(), + options.getPubBranch() == null ? mrid.getBranch() : options.getPubBranch(), + revision)); + md.setResolvedPublicationDate(options.getPubdate()); // 2) parse resolvedRevisions From properties file Map resolvedRevisions = new HashMap(); // Map (ModuleId -> String revision) @@ -136,7 +121,7 @@ public class DeliverEngine { File ivyProperties = getCache().getResolvedIvyPropertiesInCache(mrid); if (!ivyProperties.exists()) { throw new IllegalStateException("ivy properties not found in cache for " + mrid - + ": please resolve dependencies before delivering (" + ivyFile + ")"); + + "; please resolve dependencies before delivering!"); } Properties props = new Properties(); FileInputStream in = new FileInputStream(ivyProperties); @@ -225,10 +210,10 @@ public class DeliverEngine { if (!resolvedBranches.isEmpty()) { opts = opts.setResolvedBranches(resolvedBranches); } - XmlModuleDescriptorUpdater.update(ivyFileURL, publishedIvy, opts); + Resource res = md.getResource(); + XmlModuleDescriptorUpdater.update(res.openStream(), res, publishedIvy, opts); } catch (SAXException ex) { - throw new RuntimeException("bad ivy file in cache for " + mrid - + ": please clean '" + ivyFile + "' and resolve again", ex); + throw new RuntimeException("bad ivy file in cache for " + mrid, ex); } Message.verbose("\tdeliver done (" + (System.currentTimeMillis() - start) + "ms)"); Modified: ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/module/descriptor/DefaultExtendsDescriptor.java URL: http://svn.apache.org/viewvc/ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/module/descriptor/DefaultExtendsDescriptor.java?rev=1397312&r1=1397311&r2=1397312&view=diff ============================================================================== --- ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/module/descriptor/DefaultExtendsDescriptor.java (original) +++ ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/module/descriptor/DefaultExtendsDescriptor.java Thu Oct 11 21:08:27 2012 @@ -24,17 +24,22 @@ import org.apache.ivy.core.module.id.Mod public class DefaultExtendsDescriptor implements ExtendsDescriptor { - private ModuleRevisionId parentRevisionId; - private ModuleRevisionId resolvedParentRevisionId; + private ModuleDescriptor parent; private String location; private List extendsTypes; + private boolean local; - public DefaultExtendsDescriptor(ModuleRevisionId parentRevisionId, - ModuleRevisionId resolvedParentRevisionId, - String location, String[] types) { - this.parentRevisionId = parentRevisionId; - this.resolvedParentRevisionId = resolvedParentRevisionId; + public DefaultExtendsDescriptor(ModuleDescriptor parent, + String location, String[] types) { + this(parent, location, types, false); + } + + public DefaultExtendsDescriptor(ModuleDescriptor parent, + String location, String[] types, + boolean local) { + this.parent = parent; this.location = location; + this.local = local; this.extendsTypes = new ArrayList(types.length); for (int i = 0; i < types.length; ++i) { extendsTypes.add(types[i]); @@ -42,11 +47,15 @@ public class DefaultExtendsDescriptor im } public ModuleRevisionId getParentRevisionId() { - return parentRevisionId; + return parent.getModuleRevisionId(); } public ModuleRevisionId getResolvedParentRevisionId() { - return resolvedParentRevisionId; + return parent.getResolvedModuleRevisionId(); + } + + public ModuleDescriptor getParentMd() { + return parent; } public String getLocation() { @@ -76,4 +85,8 @@ public class DefaultExtendsDescriptor im public boolean areDependenciesInherited() { return isAllInherited() || extendsTypes.contains("dependencies"); } + + public boolean isLocal() { + return local; + } } Modified: ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/module/descriptor/DefaultModuleDescriptor.java URL: http://svn.apache.org/viewvc/ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/module/descriptor/DefaultModuleDescriptor.java?rev=1397312&r1=1397311&r2=1397312&view=diff ============================================================================== --- ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/module/descriptor/DefaultModuleDescriptor.java (original) +++ ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/module/descriptor/DefaultModuleDescriptor.java Thu Oct 11 21:08:27 2012 @@ -153,9 +153,15 @@ public class DefaultModuleDescriptor imp ExtendsDescriptor[] ed = md.getInheritedDescriptors(); for (int i = 0; i < ed.length; ++i) { - ModuleRevisionId mrid = t.transform(ed[i].getParentRevisionId()); - ModuleRevisionId resolvedMrid = t.transform(ed[i].getResolvedParentRevisionId()); - nmd.inheritedDescriptors.add(new DefaultExtendsDescriptor(mrid, resolvedMrid, ed[i] + ModuleDescriptor parentMd = ed[i].getParentMd(); + DefaultModuleDescriptor parentNmd = new DefaultModuleDescriptor(parentMd.getParser(), parentMd.getResource()); + parentNmd.revId = t.transform(parentMd.getModuleRevisionId()); + parentNmd.resolvedRevId = t.transform(parentMd.getResolvedModuleRevisionId()); + parentNmd.status = parentMd.getStatus(); + parentNmd.publicationDate = parentMd.getPublicationDate(); + parentNmd.resolvedPublicationDate = parentMd.getResolvedPublicationDate(); + + nmd.inheritedDescriptors.add(new DefaultExtendsDescriptor(parentNmd, ed[i] .getLocation(), ed[i].getExtendsTypes())); } Modified: ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/module/descriptor/ExtendsDescriptor.java URL: http://svn.apache.org/viewvc/ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/module/descriptor/ExtendsDescriptor.java?rev=1397312&r1=1397311&r2=1397312&view=diff ============================================================================== --- ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/module/descriptor/ExtendsDescriptor.java (original) +++ ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/module/descriptor/ExtendsDescriptor.java Thu Oct 11 21:08:27 2012 @@ -31,6 +31,8 @@ public interface ExtendsDescriptor { * {@link org.apache.ivy.core.module.descriptor.ModuleDescriptor#getResolvedModuleRevisionId()} } */ public ModuleRevisionId getResolvedParentRevisionId(); + + public ModuleDescriptor getParentMd(); /** * If there is an explicit path to check for the parent descriptor, return it. @@ -60,4 +62,6 @@ public interface ExtendsDescriptor { /** @return true if parent dependencies are inherited */ public boolean areDependenciesInherited(); + + public boolean isLocal(); } Modified: ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/publish/PublishEngine.java URL: http://svn.apache.org/viewvc/ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/publish/PublishEngine.java?rev=1397312&r1=1397311&r2=1397312&view=diff ============================================================================== --- ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/publish/PublishEngine.java (original) +++ ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/publish/PublishEngine.java Thu Oct 11 21:08:27 2012 @@ -90,31 +90,21 @@ public class PublishEngine { } ModuleRevisionId pubmrid = ModuleRevisionId.newInstance( mrid, options.getPubBranch(), options.getPubrevision()); - File ivyFile; + + // let's find the resolved module descriptor + ModuleDescriptor md = null; if (options.getSrcIvyPattern() != null) { - ivyFile = settings.resolveFile(IvyPatternHelper.substitute(options.getSrcIvyPattern(), - DefaultArtifact.newIvyArtifact(pubmrid, new Date()))); + File ivyFile = settings.resolveFile(IvyPatternHelper.substitute(options.getSrcIvyPattern(), + DefaultArtifact.newIvyArtifact(pubmrid, new Date()))); if (!ivyFile.exists()) { throw new IllegalArgumentException("ivy file to publish not found for " + mrid + ": call deliver before (" + ivyFile + ")"); } - } else { - ResolutionCacheManager cacheManager = settings.getResolutionCacheManager(); - ivyFile = cacheManager.getResolvedIvyFileInCache(mrid); - if (!ivyFile.exists()) { - throw new IllegalStateException("ivy file not found in cache for " + mrid - + ": please resolve dependencies before publishing (" + ivyFile + ")"); - } - } - // let's find the resolved module descriptor - ModuleDescriptor md = null; - URL ivyFileURL = null; - try { - ivyFileURL = ivyFile.toURI().toURL(); - md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, ivyFileURL, - false); - if (options.getSrcIvyPattern() != null) { + URL ivyFileURL = ivyFile.toURI().toURL(); + try { + md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, ivyFileURL, false); + if (options.isUpdate()) { File tmp = File.createTempFile("ivy", ".xml"); tmp.deleteOnExit(); @@ -154,13 +144,17 @@ public class PublishEngine { + md.getModuleRevisionId().getRevision() + "). Use forcedeliver or update."); } - } else { - md.setResolvedModuleRevisionId(pubmrid); + } catch (ParseException e) { + throw new IllegalStateException("bad ivy file for " + mrid + ": " + ivyFile + ": " + e); + } + } else { + ResolutionCacheManager cacheManager = settings.getResolutionCacheManager(); + try { + md = cacheManager.getResolveModuleDescriptor(mrid); + } catch (ParseException e) { + throw new IllegalStateException("bad ivy file in cache for " + mrid + ": " + e); } - } catch (MalformedURLException e) { - throw new RuntimeException("malformed url obtained for file " + ivyFile); - } catch (ParseException e) { - throw new IllegalStateException("bad ivy file for " + mrid + ": " + ivyFile + ": " + e); + md.setResolvedModuleRevisionId(pubmrid); } DependencyResolver resolver = settings.getResolver(resolverName); Modified: ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/resolve/ResolveEngine.java URL: http://svn.apache.org/viewvc/ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/resolve/ResolveEngine.java?rev=1397312&r1=1397311&r2=1397312&view=diff ============================================================================== --- ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/resolve/ResolveEngine.java (original) +++ ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/resolve/ResolveEngine.java Thu Oct 11 21:08:27 2012 @@ -240,13 +240,10 @@ public class ResolveEngine { // produce resolved ivy file and ivy properties in cache ResolutionCacheManager cacheManager = settings.getResolutionCacheManager(); - File ivyFileInCache = cacheManager.getResolvedIvyFileInCache(md - .getResolvedModuleRevisionId()); - md.toIvyFile(ivyFileInCache); + cacheManager.saveResolvedModuleDescriptor(md); // we store the resolved dependencies revisions and statuses per asked dependency - // revision id, - // for direct dependencies only. + // revision id, for direct dependencies only. // this is used by the deliver task to resolve dynamic revisions to static ones File ivyPropertiesInCache = cacheManager.getResolvedIvyPropertiesInCache( md.getResolvedModuleRevisionId()); @@ -324,7 +321,7 @@ public class ResolveEngine { FileOutputStream out = new FileOutputStream(ivyPropertiesInCache); props.store(out, md.getResolvedModuleRevisionId() + " resolved revisions"); out.close(); - Message.verbose("\tresolved ivy file produced in " + ivyFileInCache); + Message.verbose("\tresolved ivy file produced in cache"); report.setResolveTime(System.currentTimeMillis() - start); Modified: ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java URL: http://svn.apache.org/viewvc/ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java?rev=1397312&r1=1397311&r2=1397312&view=diff ============================================================================== --- ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java (original) +++ ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java Thu Oct 11 21:08:27 2012 @@ -19,7 +19,6 @@ package org.apache.ivy.core.retrieve; import java.io.File; import java.io.IOException; -import java.net.URL; import java.text.ParseException; import java.util.ArrayList; import java.util.Arrays; @@ -48,10 +47,7 @@ import org.apache.ivy.core.module.id.Mod import org.apache.ivy.core.module.id.ModuleRevisionId; import org.apache.ivy.core.report.ArtifactDownloadReport; import org.apache.ivy.core.resolve.ResolveOptions; -import org.apache.ivy.plugins.parser.ModuleDescriptorParser; -import org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistry; import org.apache.ivy.plugins.report.XmlReportParser; -import org.apache.ivy.plugins.repository.url.URLResource; import org.apache.ivy.util.FileUtil; import org.apache.ivy.util.Message; @@ -220,14 +216,8 @@ public class RetrieveEngine { String[] confs = options.getConfs(); if (confs == null || (confs.length == 1 && "*".equals(confs[0]))) { try { - File ivyFile = getCache().getResolvedIvyFileInCache(mrid); - Message.verbose("no explicit confs given for retrieve, using ivy file: " + ivyFile); - URL ivySource = ivyFile.toURI().toURL(); - URLResource res = new URLResource(ivySource); - ModuleDescriptorParser parser = ModuleDescriptorParserRegistry.getInstance() - .getParser(res); - Message.debug("using " + parser + " to parse " + ivyFile); - ModuleDescriptor md = parser.parseDescriptor(settings, ivySource, false); + ModuleDescriptor md = getCache().getResolveModuleDescriptor(mrid); + Message.verbose("no explicit confs given for retrieve, using ivy file: " + md.getResource().getName()); confs = md.getConfigurationsNames(); options.setConfs(confs); } catch (IOException e) { Modified: ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/settings/IvySettings.java URL: http://svn.apache.org/viewvc/ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/settings/IvySettings.java?rev=1397312&r1=1397311&r2=1397312&view=diff ============================================================================== --- ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/settings/IvySettings.java (original) +++ ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/core/settings/IvySettings.java Thu Oct 11 21:08:27 2012 @@ -1252,6 +1252,7 @@ public class IvySettings implements Sort if (resolutionCacheManager == null) { resolutionCacheManager = new DefaultResolutionCacheManager(getDefaultResolutionCacheBasedir()); + init(resolutionCacheManager); } return resolutionCacheManager; } Modified: ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java URL: http://svn.apache.org/viewvc/ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java?rev=1397312&r1=1397311&r2=1397312&view=diff ============================================================================== --- ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java (original) +++ ant/ivy/core/branches/2.3.x/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java Thu Oct 11 21:08:27 2012 @@ -66,11 +66,12 @@ import org.apache.ivy.plugins.namespace. import org.apache.ivy.plugins.namespace.Namespace; import org.apache.ivy.plugins.parser.AbstractModuleDescriptorParser; import org.apache.ivy.plugins.parser.ModuleDescriptorParser; +import org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistry; import org.apache.ivy.plugins.parser.ParserSettings; import org.apache.ivy.plugins.repository.Resource; +import org.apache.ivy.plugins.repository.file.FileResource; import org.apache.ivy.plugins.repository.url.URLResource; import org.apache.ivy.plugins.resolver.DependencyResolver; -import org.apache.ivy.plugins.resolver.FileSystemResolver; import org.apache.ivy.util.FileUtil; import org.apache.ivy.util.DateUtil; import org.apache.ivy.util.Message; @@ -87,8 +88,6 @@ public class XmlModuleDescriptorParser e static final String[] DEPENDENCY_REGULAR_ATTRIBUTES = new String[] {"org", "name", "branch", "branchConstraint", "rev", "revConstraint", "force", "transitive", "changing", "conf"}; - public static final String MODULE_INHERITANCE_REPOSITORY = "module-inheritance-repository"; - private static final XmlModuleDescriptorParser INSTANCE = new XmlModuleDescriptorParser(); public static XmlModuleDescriptorParser getInstance() { @@ -403,13 +402,23 @@ public class XmlModuleDescriptorParser e ModuleId parentMid = new ModuleId(parentOrganisation, parentModule); ModuleRevisionId parentMrid = new ModuleRevisionId(parentMid, parentRevision); - //check on filesystem based on location attribute (for dev ONLY) + boolean local = false; try { - DependencyResolver parentResolver = checkParentModuleOnFilesystem(location, parentMrid); - if (parentResolver != null) { - parent = resolveParentFromModuleInheritanceRepository(parentResolver, parentMrid); + parent = parseParentModuleOnFilesystem(location); + if (parent != null) { + ModuleId foundMid = parent.getResolvedModuleRevisionId().getModuleId(); + if (!foundMid.equals(parentMid)) { + // the filesystem contains a parent module with different organisation + // or module name; ignore that parent module + Message.info("Found a parent module with unexpected ModuleRevisionId at source location " + + location + "! Expected: " + parentMid + ". Found: " + foundMid + + ". This parent module will be ignored."); + parent = null; + } } + + local = parent != null; } catch (IOException e) { Message.warn("Unable to parse included ivy file " + location + ": " + e.getMessage()); @@ -431,10 +440,10 @@ public class XmlModuleDescriptorParser e } DefaultExtendsDescriptor ed = new DefaultExtendsDescriptor( - parent.getModuleRevisionId(), - parent.getResolvedModuleRevisionId(), + parent, attributes.getValue("location"), - (String[]) extendTypes.toArray(new String[extendTypes.size()])); + (String[]) extendTypes.toArray(new String[extendTypes.size()]), + local); getMd().addInheritedDescriptor(ed); mergeWithOtherModuleDescriptor(extendTypes, parent); @@ -591,21 +600,19 @@ public class XmlModuleDescriptorParser e } /** - * Check if parent module is reachable using location attribute (for dev purpose). - * If parent module is reachable it will be registered in module inheritance repository + * Returns the parent module using the location attribute (for dev purpose). * @param location a given location - * @param parentMrid * @throws IOException * @throws ParseException */ - protected DependencyResolver checkParentModuleOnFilesystem(String location, ModuleRevisionId parentMrid) throws IOException { + private ModuleDescriptor parseParentModuleOnFilesystem(String location) throws IOException, ParseException { if (!"file".equals(descriptorURL.getProtocol())) { return null; } File file = new File(location); if (!file.isAbsolute()) { - URL url = new URL(descriptorURL, location); + URL url = settings.getRelativeUrlResolver().getURL(descriptorURL, location); try { file = new File(new URI(url.toExternalForm())); } catch (URISyntaxException e) { @@ -619,11 +626,9 @@ public class XmlModuleDescriptorParser e return null; } - FileSystemResolver parentModuleResolver = new FileSystemResolver(); - parentModuleResolver.setName(getModuleInheritanceRepositoryParentResolverName(parentMrid)); - parentModuleResolver.addIvyPattern(file.getAbsolutePath()); - parentModuleResolver.setSettings(IvyContext.getContext().getSettings()); - return parentModuleResolver; + FileResource res = new FileResource(null, file); + ModuleDescriptorParser parser = ModuleDescriptorParserRegistry.getInstance().getParser(res); + return parser.parseDescriptor(getSettings(), file.toURL(), res, isValidate()); } /** @@ -654,34 +659,6 @@ public class XmlModuleDescriptorParser e } - /** - * Resolve parent module from module inheritance repository - * @param parentMrid a given {@link ModuleRevisionId} to find - * @return a {@link ModuleDescriptor} if found. Return null if no {@link ModuleDescriptor} was found - * @throws ParseException - */ - protected ModuleDescriptor resolveParentFromModuleInheritanceRepository(DependencyResolver resolver, ModuleRevisionId parentMrid) throws ParseException { - Message.debug("Trying to resolve included ivy file from module inheritance repository " ); - DependencyDescriptor dd = new DefaultDependencyDescriptor(parentMrid, true); - ResolveEngine engine = IvyContext.getContext().getIvy().getResolveEngine(); - ResolveOptions options = new ResolveOptions(); - //not sure we need to download parent module - options.setDownload(false); - ResolveData data = new ResolveData(engine, options); - - dd = NameSpaceHelper.toSystem(dd, getSettings().getContextNamespace()); - ResolvedModuleRevision otherModule = resolver.getDependency(dd, data); - if (otherModule != null) { - return otherModule.getDescriptor(); - } else { - return null; - } - } - - private static String getModuleInheritanceRepositoryParentResolverName(ModuleRevisionId parentMrid) { - return MODULE_INHERITANCE_REPOSITORY + "-" + parentMrid.toString(); - } - protected void publicationsStarted(Attributes attributes) { state = State.PUB; artifactsDeclared = true;