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 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.relocated</groupId>
+ <artifactId>test3</artifactId>
+ <name>Test Module for Ivy M2 relocation parsing</name>
+ <version>1.1</version>
+ <distributionManagement>
+ <relocation>
+ <version>1.0</version>
+ </relocation>
+ </distributionManagement>
+</project>
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 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.relocated</groupId>
+ <artifactId>testRelocationUser</artifactId>
+ <name>Test Module for Ivy M2 parsing depending on a relocated module</name>
+ <version>1.0</version>
+ <dependencies>
+ <dependency>
+ <groupId>org.relocated</groupId>
+ <artifactId>test3</artifactId>
+ <version>1.0</version>
+ </dependency>
+ </dependencies>
+</project>
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 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.relocated</groupId>
+ <artifactId>testRelocationUser</artifactId>
+ <name>Test Module for Ivy M2 parsing depending on a relocated module</name>
+ <version>1.1</version>
+ <dependencies>
+ <dependency>
+ <groupId>org.relocated</groupId>
+ <artifactId>test3</artifactId>
+ <version>1.1</version>
+ </dependency>
+ </dependencies>
+</project>
Propchange:
ant/ivy/core/trunk/test/repositories/m2/org/relocated/testRelocationUser/1.1/testRelocationUser-1.1.pom
------------------------------------------------------------------------------
svn:eol-style = native