Return-Path: Delivered-To: apmail-ant-notifications-archive@locus.apache.org Received: (qmail 75036 invoked from network); 3 Dec 2007 11:12:46 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 3 Dec 2007 11:12:46 -0000 Received: (qmail 59742 invoked by uid 500); 3 Dec 2007 11:12:34 -0000 Delivered-To: apmail-ant-notifications-archive@ant.apache.org Received: (qmail 59717 invoked by uid 500); 3 Dec 2007 11:12:34 -0000 Mailing-List: contact notifications-help@ant.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ant.apache.org Delivered-To: mailing list notifications@ant.apache.org Received: (qmail 59708 invoked by uid 99); 3 Dec 2007 11:12:34 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Dec 2007 03:12:34 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Dec 2007 11:12:22 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 4441E1A9832; Mon, 3 Dec 2007 03:12:25 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r600481 - in /ant/ivy/core/trunk: src/java/org/apache/ivy/plugins/parser/m2/ test/java/org/apache/ivy/core/resolve/ test/repositories/m2/org/relocated/test3/1.1/ test/repositories/m2/org/relocated/testRelocationUser/ test/repositories/m2/or... Date: Mon, 03 Dec 2007 11:12:24 -0000 To: notifications@ant.apache.org From: gscokart@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071203111225.4441E1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: gscokart Date: Mon Dec 3 03:12:23 2007 New Revision: 600481 URL: http://svn.apache.org/viewvc?rev=600481&view=rev Log: (IVY-586) don't stop the resolution if the module is relocated to an other version of the same module. The complete fix requires to handle relocation in the resolution algorithm. This version will continue the resolution taking partially into account the relocation, and printing an error. Note that conflict resolution doesn't take into account the relocation Added: ant/ivy/core/trunk/test/repositories/m2/org/relocated/test3/1.1/ ant/ivy/core/trunk/test/repositories/m2/org/relocated/test3/1.1/test3-1.1.pom (with props) ant/ivy/core/trunk/test/repositories/m2/org/relocated/testRelocationUser/ ant/ivy/core/trunk/test/repositories/m2/org/relocated/testRelocationUser/1.0/ ant/ivy/core/trunk/test/repositories/m2/org/relocated/testRelocationUser/1.0/testRelocationUser-1.0.pom (with props) ant/ivy/core/trunk/test/repositories/m2/org/relocated/testRelocationUser/1.1/ ant/ivy/core/trunk/test/repositories/m2/org/relocated/testRelocationUser/1.1/testRelocationUser-1.1.pom (with props) Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java ant/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java?rev=600481&r1=600480&r2=600481&view=diff ============================================================================== --- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java (original) +++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java Mon Dec 3 03:12:23 2007 @@ -146,8 +146,6 @@ private String organisation; - private String relocationOrganisation = null; - private String module; private String revision; @@ -170,6 +168,8 @@ private StringBuffer buffer = new StringBuffer(); + private String relocationOrganisation = null; + private String relocationModule; private String relocationRevision; @@ -262,8 +262,8 @@ && "project/dependencies/dependency".equals(context)) { if (revision == null) { // if the revision is null, see if we can get it from the dependency management - String key = DEPENDENCY_MANAGEMENT + DEPENDENCY_MANAGEMENT_DELIMITER + organisation + - DEPENDENCY_MANAGEMENT_DELIMITER + module; + String key = DEPENDENCY_MANAGEMENT + DEPENDENCY_MANAGEMENT_DELIMITER + + organisation + DEPENDENCY_MANAGEMENT_DELIMITER + module; revision = (String) properties.get(key); } if (dd == null) { @@ -329,27 +329,50 @@ organisation = null; module = null; } else if ("project/distributionManagement/relocation".equals(context)) { - md.setModuleRevisionId(ModuleRevisionId - .newInstance(organisation, module, revision)); - if (relocationOrganisation == null ) { + if (relocationOrganisation == null) { relocationOrganisation = organisation; } - if (relocationModule == null ) { + if (relocationModule == null) { relocationModule = module; } - if (relocationRevision == null ) { + if (relocationRevision == null) { relocationRevision = revision; } - dd = new DefaultDependencyDescriptor(md, ModuleRevisionId.newInstance( - relocationOrganisation, relocationModule, relocationRevision), true, false, true); - dd.addDependencyConfiguration("*", "@"); - md.addDependency(dd); - dd = null; + ModuleRevisionId myModuleRev = ModuleRevisionId.newInstance( + organisation, module, revision); + ModuleRevisionId relocationeModuleRev = ModuleRevisionId.newInstance( + relocationOrganisation, relocationModule, relocationRevision); + md.setModuleRevisionId(myModuleRev); + if (relocationOrganisation.equals(organisation) + && relocationModule.equals(module)) { + Message.error("Relocation to an other version number not supported in ivy : " + + myModuleRev + " relocated to " + relocationModule + + ". Please update your dependency to directly use the right version."); + Message.warn("Resolution will only pick dependencies of the relocated element." + + " Artefact and other metadata will be ignored."); + Parser relocationParser = parserOtherPom(relocationeModuleRev); + if (relocationParser == null) { + throw new SAXException("Relocation can not be found : " + relocationModule); + } + DependencyDescriptor[] dependencies = relocationParser.md.getDependencies(); + for (int i = 0; i < dependencies.length; i++) { + md.addDependency(dependencies[i]); + } + } else { + Message.info(myModuleRev.toString() + " is relocated to " + + relocationeModuleRev + ". Please update your dependencies."); + Message.verbose("Relocated module will be considered as a dependency"); + dd = new DefaultDependencyDescriptor(md, relocationeModuleRev, + true, false, true); + dd.addDependencyConfiguration("*", "@"); + md.addDependency(dd); + dd = null; + } } else if ("project/dependencyManagement/dependencies/dependency".equals(context)) { - if ( dmGroupId != null && dmArtifactId != null && dmVersion != null ) { + if (dmGroupId != null && dmArtifactId != null && dmVersion != null) { // Note: we can't use substitute pattern, fillMrid has not been called yet. - String key = DEPENDENCY_MANAGEMENT + DEPENDENCY_MANAGEMENT_DELIMITER + dmGroupId + - DEPENDENCY_MANAGEMENT_DELIMITER + dmArtifactId; + String key = DEPENDENCY_MANAGEMENT + DEPENDENCY_MANAGEMENT_DELIMITER + + dmGroupId + DEPENDENCY_MANAGEMENT_DELIMITER + dmArtifactId; properties.put(key, dmVersion); } } @@ -393,7 +416,7 @@ return; } if (context.equals("project/distributionManagement/relocation/groupId")) { - relocationOrganisation= txt; + relocationOrganisation = txt; return; } if (context.equals("project/distributionManagement/relocation/artifactId")) { @@ -407,15 +430,18 @@ if (context.startsWith("project/parent")) { return; } - if (context.equals("project/dependencyManagement/dependencies/dependency/groupId")) { + if (context.equals( + "project/dependencyManagement/dependencies/dependency/groupId")) { dmGroupId = txt; return; } - if (context.equals("project/dependencyManagement/dependencies/dependency/artifactId")) { + if (context.equals( + "project/dependencyManagement/dependencies/dependency/artifactId")) { dmArtifactId = txt; return; } - if (context.equals("project/dependencyManagement/dependencies/dependency/version")) { + if (context.equals( + "project/dependencyManagement/dependencies/dependency/version")) { dmVersion = txt; return; } @@ -483,71 +509,80 @@ if (parentOrg != null && parentName != null && parentVersion != null) { ModuleRevisionId parent = ModuleRevisionId.newInstance(parentOrg, parentName, parentVersion); - DependencyResolver resolver = settings.getResolver(parent.getModuleId()); - if (resolver == null) { - // TODO: Maybe log warning or throw exception here? + Parser parser = parserOtherPom(parent); + if (parser == null) { + //see comments in parserOtherPom for case where parser==nul return; } - DependencyDescriptor dd = new DefaultDependencyDescriptor(parent, true); - ResolveData data = IvyContext.getContext().getResolveData(); - if (data == null) { - ResolveEngine engine = IvyContext.getContext().getIvy().getResolveEngine(); - ResolveOptions options = new ResolveOptions(); - options.setCache(IvyContext.getContext().getCacheManager()); - options.setDownload(false); - data = new ResolveData(engine, options); - } - - ResolvedResource rr = resolver.findIvyFileRef(dd, data); - - if (rr == null) { - // parent not found. Maybe we should throw an exception here? - return; - } - - Parser parser = new Parser(getModuleDescriptorParser(), rr.getResource(), settings); - InputStream pomStream = null; - try { - pomStream = rr.getResource().openStream(); - XMLHelper.parse(pomStream, null, parser, null); - } catch (IOException e) { - throw new SAXException("Error occurred while parsing parent", e); - } catch (ParserConfigurationException e) { - throw new SAXException("Error occurred while parsing parent", e); - } finally { - if (pomStream != null) { - try { - pomStream.close(); - } catch (IOException e) { - // ignore - } - } - } - // move the parent properties into ours Map parentProps = parser.properties; Set keys = parentProps.keySet(); - for ( Iterator iter = keys.iterator(); iter.hasNext(); ) { + for (Iterator iter = keys.iterator(); iter.hasNext();) { String key = iter.next().toString(); - if ( key.startsWith("pom")) { + if (key.startsWith("pom")) { // don't see a need to copy pom values from parent... // ignore - } else if ( key.startsWith("parent")) { + } else if (key.startsWith("parent")) { // don't see a need to copy parent values from parent... // ignore } else { // the key may need the groupId substituted - String _key = IvyPatternHelper.substituteVariables(key, + String fullKey = IvyPatternHelper.substituteVariables(key, parentProps).trim(); - String _value = IvyPatternHelper.substituteVariables(parentProps.get(key).toString(), - parentProps).trim(); - properties.put(_key, _value); + String fullValue = IvyPatternHelper.substituteVariables( + parentProps.get(key).toString(), parentProps).trim(); + properties.put(fullKey, fullValue); } } } } + + private Parser parserOtherPom(ModuleRevisionId other) throws SAXException { + DependencyResolver resolver = settings.getResolver(other.getModuleId()); + if (resolver == null) { + // TODO: Maybe log warning or throw exception here? + return null; + } + + DependencyDescriptor dd = new DefaultDependencyDescriptor(other, true); + ResolveData data = IvyContext.getContext().getResolveData(); + if (data == null) { + ResolveEngine engine = IvyContext.getContext().getIvy().getResolveEngine(); + ResolveOptions options = new ResolveOptions(); + options.setCache(IvyContext.getContext().getCacheManager()); + options.setDownload(false); + data = new ResolveData(engine, options); + } + + ResolvedResource rr = resolver.findIvyFileRef(dd, data); + + if (rr == null) { + // parent not found. Maybe we should throw an exception here? + return null; + } + + Parser parser = new Parser(getModuleDescriptorParser(), rr.getResource(), settings); + InputStream pomStream = null; + try { + pomStream = rr.getResource().openStream(); + XMLHelper.parse(pomStream, null, parser, null); + } catch (IOException e) { + throw new SAXException("Error occurred while parsing parent", e); + } catch (ParserConfigurationException e) { + throw new SAXException("Error occurred while parsing parent", e); + } finally { + if (pomStream != null) { + try { + pomStream.close(); + } catch (IOException e) { + // ignore + } + } + } + return parser; + } } private static final PomModuleDescriptorParser INSTANCE = new PomModuleDescriptorParser(); @@ -559,8 +594,8 @@ private PomModuleDescriptorParser() { } - public ModuleDescriptor parseDescriptor(ParserSettings settings, URL descriptorURL, Resource res, - boolean validate) throws ParseException, IOException { + public ModuleDescriptor parseDescriptor(ParserSettings settings, URL descriptorURL, + Resource res, boolean validate) throws ParseException, IOException { Parser parser = new Parser(this, res, settings); try { XMLHelper.parse(descriptorURL, null, parser); Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java?rev=600481&r1=600480&r2=600481&view=diff ============================================================================== --- ant/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java (original) +++ ant/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java Mon Dec 3 03:12:23 2007 @@ -3029,6 +3029,85 @@ } } + + public void testResolveVesionRelocationChainedWithGroupRelocation() throws Exception { + ivy = new Ivy(); + ivy.configure(new File("test/repositories/m2/ivysettings.xml")); + ivy.pushContext(); + try { + ResolveReport report = ivy.resolve(new File( + "test/repositories/m2/org/relocated/test3/1.1/test3-1.1.pom").toURL(), + getResolveOptions(new String[] {"*"})); + assertNotNull(report); + + // dependencies + assertTrue(ivy.getCacheManager(cache).getIvyFileInCache( + ModuleRevisionId.newInstance("org.apache", "test2", "1.0")).exists()); + assertTrue(TestHelper.getArchiveFileInCache(ivy, cache, "org.apache", "test2", "1.0", + "test2", "jar", "jar").exists()); + + assertTrue(ivy.getCacheManager(cache).getIvyFileInCache( + ModuleRevisionId.newInstance("org.apache", "test", "1.0")).exists()); + assertTrue(TestHelper.getArchiveFileInCache(ivy, cache, "org.apache", "test", "1.0", + "test", "jar", "jar").exists()); + } finally { + ivy.popContext(); + } + } + + + public void testResolveTransitivelyToRelocatedPom() throws Exception { + ivy = new Ivy(); + ivy.configure(new File("test/repositories/m2/ivysettings.xml")); + ivy.pushContext(); + try { + ResolveReport report = ivy.resolve(new File( + "test/repositories/m2/org/relocated/testRelocationUser/1.0/" + + "testRelocationUser-1.0.pom").toURL(), + getResolveOptions(new String[] {"compile"})); + assertNotNull(report); + assertFalse(report.hasError()); + // dependencies + assertTrue(ivy.getCacheManager(cache).getIvyFileInCache( + ModuleRevisionId.newInstance("org.apache", "test2", "1.0")).exists()); + assertTrue(TestHelper.getArchiveFileInCache(ivy, cache, "org.apache", "test2", "1.0", + "test2", "jar", "jar").exists()); + + assertTrue(ivy.getCacheManager(cache).getIvyFileInCache( + ModuleRevisionId.newInstance("org.apache", "test", "1.0")).exists()); + assertTrue(TestHelper.getArchiveFileInCache(ivy, cache, "org.apache", "test", "1.0", + "test", "jar", "jar").exists()); + } finally { + ivy.popContext(); + } + } + + public void testResolveTransitivelyToPomRelocatedToNewVersion() throws Exception { + ivy = new Ivy(); + ivy.configure(new File("test/repositories/m2/ivysettings.xml")); + ivy.pushContext(); + try { + ResolveReport report = ivy.resolve(new File( + "test/repositories/m2/org/relocated/testRelocationUser/1.1/" + + "testRelocationUser-1.1.pom").toURL(), + getResolveOptions(new String[] {"compile"})); + assertNotNull(report); + assertFalse(report.hasError()); + // dependencies + assertTrue(ivy.getCacheManager(cache).getIvyFileInCache( + ModuleRevisionId.newInstance("org.apache", "test2", "1.0")).exists()); + assertTrue(TestHelper.getArchiveFileInCache(ivy, cache, "org.apache", "test2", "1.0", + "test2", "jar", "jar").exists()); + + assertTrue(ivy.getCacheManager(cache).getIvyFileInCache( + ModuleRevisionId.newInstance("org.apache", "test", "1.0")).exists()); + assertTrue(TestHelper.getArchiveFileInCache(ivy, cache, "org.apache", "test", "1.0", + "test", "jar", "jar").exists()); + } finally { + ivy.popContext(); + } + } + public void testResolveMaven2Classifiers() throws Exception { // test case for IVY-418 Added: ant/ivy/core/trunk/test/repositories/m2/org/relocated/test3/1.1/test3-1.1.pom URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/repositories/m2/org/relocated/test3/1.1/test3-1.1.pom?rev=600481&view=auto ============================================================================== --- ant/ivy/core/trunk/test/repositories/m2/org/relocated/test3/1.1/test3-1.1.pom (added) +++ ant/ivy/core/trunk/test/repositories/m2/org/relocated/test3/1.1/test3-1.1.pom Mon Dec 3 03:12:23 2007 @@ -0,0 +1,31 @@ + + + + 4.0.0 + org.relocated + test3 + Test Module for Ivy M2 relocation parsing + 1.1 + + + 1.0 + + + Propchange: ant/ivy/core/trunk/test/repositories/m2/org/relocated/test3/1.1/test3-1.1.pom ------------------------------------------------------------------------------ svn:eol-style = native Added: ant/ivy/core/trunk/test/repositories/m2/org/relocated/testRelocationUser/1.0/testRelocationUser-1.0.pom URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/repositories/m2/org/relocated/testRelocationUser/1.0/testRelocationUser-1.0.pom?rev=600481&view=auto ============================================================================== --- ant/ivy/core/trunk/test/repositories/m2/org/relocated/testRelocationUser/1.0/testRelocationUser-1.0.pom (added) +++ ant/ivy/core/trunk/test/repositories/m2/org/relocated/testRelocationUser/1.0/testRelocationUser-1.0.pom Mon Dec 3 03:12:23 2007 @@ -0,0 +1,33 @@ + + + + 4.0.0 + org.relocated + testRelocationUser + Test Module for Ivy M2 parsing depending on a relocated module + 1.0 + + + org.relocated + test3 + 1.0 + + + Propchange: ant/ivy/core/trunk/test/repositories/m2/org/relocated/testRelocationUser/1.0/testRelocationUser-1.0.pom ------------------------------------------------------------------------------ svn:eol-style = native Added: ant/ivy/core/trunk/test/repositories/m2/org/relocated/testRelocationUser/1.1/testRelocationUser-1.1.pom URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/repositories/m2/org/relocated/testRelocationUser/1.1/testRelocationUser-1.1.pom?rev=600481&view=auto ============================================================================== --- ant/ivy/core/trunk/test/repositories/m2/org/relocated/testRelocationUser/1.1/testRelocationUser-1.1.pom (added) +++ ant/ivy/core/trunk/test/repositories/m2/org/relocated/testRelocationUser/1.1/testRelocationUser-1.1.pom Mon Dec 3 03:12:23 2007 @@ -0,0 +1,33 @@ + + + + 4.0.0 + org.relocated + testRelocationUser + Test Module for Ivy M2 parsing depending on a relocated module + 1.1 + + + org.relocated + test3 + 1.1 + + + Propchange: ant/ivy/core/trunk/test/repositories/m2/org/relocated/testRelocationUser/1.1/testRelocationUser-1.1.pom ------------------------------------------------------------------------------ svn:eol-style = native