You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by mb...@apache.org on 2017/04/21 14:15:40 UTC
[1/2] ant-ivy git commit: [IVY-1558] support dependencies in active
profiles
Repository: ant-ivy
Updated Branches:
refs/heads/master 539e1ee1d -> f63775336
[IVY-1558] support dependencies in active profiles
Project: http://git-wip-us.apache.org/repos/asf/ant-ivy/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant-ivy/commit/8ff6e5a9
Tree: http://git-wip-us.apache.org/repos/asf/ant-ivy/tree/8ff6e5a9
Diff: http://git-wip-us.apache.org/repos/asf/ant-ivy/diff/8ff6e5a9
Branch: refs/heads/master
Commit: 8ff6e5a90f725ce7acd56f2c919221d8c179270f
Parents: 539e1ee
Author: Matt Benson <mb...@apache.org>
Authored: Fri Apr 21 09:15:07 2017 -0500
Committer: Matt Benson <mb...@apache.org>
Committed: Fri Apr 21 09:15:07 2017 -0500
----------------------------------------------------------------------
.../parser/m2/PomModuleDescriptorBuilder.java | 13 +-
.../parser/m2/PomModuleDescriptorParser.java | 178 ++++++++--------
.../apache/ivy/plugins/parser/m2/PomReader.java | 205 ++++++++++++++-----
.../m2/PomModuleDescriptorParserTest.java | 92 ++++++++-
.../apache/ivy/plugins/parser/m2/depmgt/bom.pom | 52 +++++
.../ivy/plugins/parser/m2/depmgt/child.pom | 36 ++++
.../ivy/plugins/parser/m2/depmgt/grandchild.pom | 36 ++++
.../ivy/plugins/parser/m2/depmgt/parent.pom | 38 ++++
.../parser/m2/depmgt/profile-parent-child.pom | 36 ++++
.../plugins/parser/m2/depmgt/profile-parent.pom | 46 +++++
10 files changed, 587 insertions(+), 145 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/8ff6e5a9/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java b/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java
index 5445f0c..63ad87f 100644
--- a/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java
+++ b/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java
@@ -27,7 +27,6 @@ import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import org.apache.ivy.Ivy;
import org.apache.ivy.core.cache.ArtifactOrigin;
@@ -284,7 +283,7 @@ public class PomModuleDescriptorBuilder {
ModuleRevisionId moduleRevId = ModuleRevisionId.newInstance(dep.getGroupId(),
dep.getArtifactId(), version);
- // Some POMs depend on theirselfves, don't add this dependency: Ivy doesn't allow this!
+ // Some POMs depend on themselves; Ivy doesn't allow this. Don't add this dependency!
// Example: https://repo1.maven.org/maven2/net/jini/jsk-platform/2.1/jsk-platform-2.1.pom
ModuleRevisionId mRevId = ivyModuleDescriptor.getModuleRevisionId();
if ((mRevId != null) && mRevId.getModuleId().equals(moduleRevId.getModuleId())) {
@@ -533,7 +532,7 @@ public class PomModuleDescriptorBuilder {
public static Map<ModuleId, String> getDependencyManagementMap(ModuleDescriptor md) {
Map<ModuleId, String> ret = new LinkedHashMap<ModuleId, String>();
if (md instanceof PomModuleDescriptor) {
- for (Entry<ModuleId, PomDependencyMgt> e : ((PomModuleDescriptor) md)
+ for (Map.Entry<ModuleId, PomDependencyMgt> e : ((PomModuleDescriptor) md)
.getDependencyManagementMap().entrySet()) {
PomDependencyMgt dependencyMgt = e.getValue();
ret.put(e.getKey(), dependencyMgt.getVersion());
@@ -564,7 +563,7 @@ public class PomModuleDescriptorBuilder {
} else {
for (ExtraInfoHolder extraInfoHolder : md.getExtraInfos()) {
String key = extraInfoHolder.getName();
- if ((key).startsWith(DEPENDENCY_MANAGEMENT)) {
+ if (key.startsWith(DEPENDENCY_MANAGEMENT)) {
String[] parts = key.split(EXTRA_INFO_DELIMITER);
if (parts.length != DEPENDENCY_MANAGEMENT_KEY_PARTS_COUNT) {
Message.warn("what seem to be a dependency management extra info "
@@ -592,7 +591,7 @@ public class PomModuleDescriptorBuilder {
@Deprecated
public void addExtraInfos(Map<String, String> extraAttributes) {
- for (Entry<String, String> entry : extraAttributes.entrySet()) {
+ for (Map.Entry<String, String> entry : extraAttributes.entrySet()) {
addExtraInfo(entry.getKey(), entry.getValue());
}
}
@@ -625,7 +624,7 @@ public class PomModuleDescriptorBuilder {
@Deprecated
public static Map<String, String> extractPomProperties(Map<String, String> extraInfo) {
Map<String, String> r = new HashMap<String, String>();
- for (Entry<String, String> extraInfoEntry : extraInfo.entrySet()) {
+ for (Map.Entry<String, String> extraInfoEntry : extraInfo.entrySet()) {
if (extraInfoEntry.getKey().startsWith(PROPERTIES)) {
String prop = extraInfoEntry.getKey().substring(
PROPERTIES.length() + EXTRA_INFO_DELIMITER.length());
@@ -706,7 +705,7 @@ public class PomModuleDescriptorBuilder {
}
public static class PomModuleDescriptor extends DefaultModuleDescriptor {
- private final Map<ModuleId, PomDependencyMgt> dependencyManagementMap = new HashMap<ModuleId, PomDependencyMgt>();
+ private final Map<ModuleId, PomDependencyMgt> dependencyManagementMap = new LinkedHashMap<ModuleId, PomDependencyMgt>();
public PomModuleDescriptor(ModuleDescriptorParser parser, Resource res) {
super(parser, res);
http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/8ff6e5a9/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java b/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java
index f2d3cfc..c7d82ba 100644
--- a/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java
+++ b/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java
@@ -23,7 +23,6 @@ import java.io.InputStream;
import java.net.URL;
import java.text.ParseException;
import java.util.Date;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -48,6 +47,8 @@ import org.apache.ivy.plugins.parser.ParserSettings;
import org.apache.ivy.plugins.parser.m2.PomModuleDescriptorBuilder.PomDependencyDescriptor;
import org.apache.ivy.plugins.parser.m2.PomReader.PomDependencyData;
import org.apache.ivy.plugins.parser.m2.PomReader.PomDependencyMgtElement;
+import org.apache.ivy.plugins.parser.m2.PomReader.PomPluginElement;
+import org.apache.ivy.plugins.parser.m2.PomReader.PomProfileElement;
import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorWriter;
import org.apache.ivy.plugins.repository.Resource;
import org.apache.ivy.plugins.repository.url.URLResource;
@@ -122,11 +123,10 @@ public final class PomModuleDescriptorParser implements ModuleDescriptorParser {
domReader.setProperty("project.parent.version", domReader.getParentVersion());
domReader.setProperty("project.parent.groupId", domReader.getParentGroupId());
- Map pomProperties = domReader.getPomProperties();
- for (Iterator iter = pomProperties.entrySet().iterator(); iter.hasNext();) {
- Map.Entry prop = (Map.Entry) iter.next();
- domReader.setProperty((String) prop.getKey(), (String) prop.getValue());
- mdBuilder.addProperty((String) prop.getKey(), (String) prop.getValue());
+ Map<String, String> pomProperties = domReader.getPomProperties();
+ for (Map.Entry<String, String> prop : pomProperties.entrySet()) {
+ domReader.setProperty(prop.getKey(), prop.getValue());
+ mdBuilder.addProperty(prop.getKey(), prop.getValue());
}
ModuleDescriptor parentDescr = null;
@@ -137,18 +137,16 @@ public final class PomModuleDescriptorParser implements ModuleDescriptorParser {
domReader.getParentGroupId(), domReader.getParentArtifactId(),
domReader.getParentVersion());
ResolvedModuleRevision parentModule = parseOtherPom(ivySettings, parentModRevID);
- if (parentModule != null) {
- parentDescr = parentModule.getDescriptor();
- } else {
- throw new IOException("Impossible to load parent for " + res.getName() + "."
- + " Parent=" + parentModRevID);
+ if (parentModule == null) {
+ throw new IOException("Impossible to load parent for " + res.getName()
+ + ". Parent=" + parentModRevID);
}
+ parentDescr = parentModule.getDescriptor();
if (parentDescr != null) {
- Map parentPomProps = PomModuleDescriptorBuilder
+ Map<String, String> parentPomProps = PomModuleDescriptorBuilder
.extractPomProperties(parentDescr.getExtraInfos());
- for (Iterator iter = parentPomProps.entrySet().iterator(); iter.hasNext();) {
- Map.Entry prop = (Map.Entry) iter.next();
- domReader.setProperty((String) prop.getKey(), (String) prop.getValue());
+ for (Map.Entry<String, String> prop : parentPomProps.entrySet()) {
+ domReader.setProperty(prop.getKey(), prop.getValue());
}
}
}
@@ -164,17 +162,14 @@ public final class PomModuleDescriptorParser implements ModuleDescriptorParser {
final License[] licenses = domReader.getLicenses();
if (licenses != null && licenses.length > 0) {
mdBuilder.setLicenses(licenses);
- } else {
- if (parentDescr != null) {
- mdBuilder.setLicenses(parentDescr.getLicenses());
- }
+ } else if (parentDescr != null) {
+ mdBuilder.setLicenses(parentDescr.getLicenses());
}
ModuleRevisionId relocation = domReader.getRelocation();
if (relocation != null) {
- if (groupId != null && artifactId != null
- && artifactId.equals(relocation.getName())
+ if (groupId != null && artifactId != null && artifactId.equals(relocation.getName())
&& groupId.equals(relocation.getOrganisation())) {
Message.error("Relocation to an other version number not supported in ivy : "
+ mdBuilder.getModuleDescriptor().getModuleRevisionId()
@@ -184,28 +179,28 @@ public final class PomModuleDescriptorParser implements ModuleDescriptorParser {
+ " Artefact and other metadata will be ignored.");
ResolvedModuleRevision relocatedModule = parseOtherPom(ivySettings, relocation);
if (relocatedModule == null) {
- throw new ParseException("impossible to load module " + relocation
- + " to which "
- + mdBuilder.getModuleDescriptor().getModuleRevisionId()
- + " has been relocated", 0);
+ throw new ParseException(
+ "impossible to load module " + relocation + " to which "
+ + mdBuilder.getModuleDescriptor().getModuleRevisionId()
+ + " has been relocated",
+ 0);
}
- DependencyDescriptor[] dds = relocatedModule.getDescriptor().getDependencies();
- for (int i = 0; i < dds.length; i++) {
- mdBuilder.addDependency(dds[i]);
+ for (DependencyDescriptor dd : relocatedModule.getDescriptor()
+ .getDependencies()) {
+ mdBuilder.addDependency(dd);
}
} else {
- Message.info(mdBuilder.getModuleDescriptor().getModuleRevisionId()
- + " is relocated to " + relocation
- + ". Please update your dependencies.");
+ Message.info(
+ mdBuilder.getModuleDescriptor().getModuleRevisionId() + " is relocated to "
+ + relocation + ". Please update your dependencies.");
Message.verbose("Relocated module will be considered as a dependency");
DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(
mdBuilder.getModuleDescriptor(), relocation, true, false, true);
/* Map all public dependencies */
Configuration[] m2Confs = PomModuleDescriptorBuilder.MAVEN2_CONFIGURATIONS;
- for (int i = 0; i < m2Confs.length; i++) {
- if (Visibility.PUBLIC.equals(m2Confs[i].getVisibility())) {
- dd.addDependencyConfiguration(m2Confs[i].getName(),
- m2Confs[i].getName());
+ for (Configuration m2Conf : m2Confs) {
+ if (Visibility.PUBLIC.equals(m2Conf.getVisibility())) {
+ dd.addDependencyConfiguration(m2Conf.getName(), m2Conf.getName());
}
}
mdBuilder.addDependency(dd);
@@ -225,9 +220,9 @@ public final class PomModuleDescriptorParser implements ModuleDescriptorParser {
mdBuilder.addExtraInfos(parentDescr.getExtraInfos());
// add dependency management info from parent
- List depMgt = PomModuleDescriptorBuilder.getDependencyManagements(parentDescr);
- for (Iterator it = depMgt.iterator(); it.hasNext();) {
- PomDependencyMgt dep = (PomDependencyMgt) it.next();
+ List<PomDependencyMgt> depMgt = PomModuleDescriptorBuilder
+ .getDependencyManagements(parentDescr);
+ for (PomDependencyMgt dep : depMgt) {
if (dep instanceof PomDependencyMgtElement) {
dep = domReader.new PomDependencyMgtElement(
(PomDependencyMgtElement) dep);
@@ -236,52 +231,40 @@ public final class PomModuleDescriptorParser implements ModuleDescriptorParser {
}
// add plugins from parent
- List /* <PomDependencyMgt> */plugins = PomModuleDescriptorBuilder
- .getPlugins(parentDescr);
- for (Iterator it = plugins.iterator(); it.hasNext();) {
- mdBuilder.addPlugin((PomDependencyMgt) it.next());
+ for (PomDependencyMgt pomDependencyMgt : PomModuleDescriptorBuilder
+ .getPlugins(parentDescr)) {
+ mdBuilder.addPlugin((PomDependencyMgt) pomDependencyMgt);
}
}
- for (Iterator it = domReader.getDependencyMgt().iterator(); it.hasNext();) {
- PomDependencyMgt dep = (PomDependencyMgt) it.next();
- if ("import".equals(dep.getScope())) {
- ModuleRevisionId importModRevID = ModuleRevisionId.newInstance(
- dep.getGroupId(), dep.getArtifactId(), dep.getVersion());
- ResolvedModuleRevision importModule = parseOtherPom(ivySettings,
- importModRevID);
- if (importModule != null) {
- ModuleDescriptor importDescr = importModule.getDescriptor();
-
- // add dependency management info from imported module
- List depMgt = PomModuleDescriptorBuilder
- .getDependencyManagements(importDescr);
- for (Iterator it2 = depMgt.iterator(); it2.hasNext();) {
- PomDependencyMgt importedDepMgt = (PomDependencyMgt) it2.next();
- mdBuilder.addDependencyMgt(new DefaultPomDependencyMgt(
- importedDepMgt.getGroupId(),
- importedDepMgt.getArtifactId(),
- importedDepMgt.getVersion(), importedDepMgt.getScope(),
- importedDepMgt.getExcludedModules()));
- }
- } else {
- throw new IOException("Impossible to import module for "
- + res.getName() + "." + " Import=" + importModRevID);
- }
+ for (PomDependencyMgt dep : domReader.getDependencyMgt()) {
+ addTo(mdBuilder, dep, ivySettings);
+ }
+ for (PomDependencyData dep : domReader.getDependencies()) {
+ mdBuilder.addDependency(res, dep);
+ }
- } else {
- mdBuilder.addDependencyMgt(dep);
- }
+ for (PomPluginElement plugin : domReader.getPlugins()) {
+ mdBuilder.addPlugin(plugin);
}
- for (Iterator it = domReader.getDependencies().iterator(); it.hasNext();) {
- PomReader.PomDependencyData dep = (PomReader.PomDependencyData) it.next();
- mdBuilder.addDependency(res, dep);
+ // consult active profiles:
+ for (PomProfileElement profile : domReader.getProfiles()) {
+ if (profile.isActive()) {
+ for (PomDependencyMgt dep : profile.getDependencyMgt()) {
+ addTo(mdBuilder, dep, ivySettings);
+ }
+ for (PomDependencyData dep : profile.getDependencies()) {
+ mdBuilder.addDependency(res, dep);
+ }
+ for (PomPluginElement plugin : profile.getPlugins()) {
+ mdBuilder.addPlugin(plugin);
+ }
+ }
}
if (parentDescr != null) {
- for (int i = 0; i < parentDescr.getDependencies().length; i++) {
- DependencyDescriptor descriptor = parentDescr.getDependencies()[i];
+ for (DependencyDescriptor descriptor : parentDescr.getDependencies()) {
if (descriptor instanceof PomDependencyDescriptor) {
PomDependencyData parentDep = ((PomDependencyDescriptor) descriptor)
.getPomDependencyData();
@@ -293,11 +276,6 @@ public final class PomModuleDescriptorParser implements ModuleDescriptorParser {
}
}
- for (Iterator it = domReader.getPlugins().iterator(); it.hasNext();) {
- PomReader.PomPluginElement plugin = (PomReader.PomPluginElement) it.next();
- mdBuilder.addPlugin(plugin);
- }
-
mdBuilder.addMainArtifact(artifactId, domReader.getPackaging());
addSourcesAndJavadocArtifactsIfPresent(mdBuilder, ivySettings);
@@ -309,6 +287,33 @@ public final class PomModuleDescriptorParser implements ModuleDescriptorParser {
return mdBuilder.getModuleDescriptor();
}
+ private void addTo(PomModuleDescriptorBuilder mdBuilder, PomDependencyMgt dep,
+ ParserSettings ivySettings) throws ParseException, IOException {
+ if ("import".equals(dep.getScope())) {
+ ModuleRevisionId importModRevID = ModuleRevisionId.newInstance(dep.getGroupId(),
+ dep.getArtifactId(), dep.getVersion());
+ ResolvedModuleRevision importModule = parseOtherPom(ivySettings, importModRevID);
+ if (importModule == null) {
+ throw new IOException("Impossible to import module for "
+ + mdBuilder.getModuleDescriptor().getResource().getName() + ". Import="
+ + importModRevID);
+ }
+ ModuleDescriptor importDescr = importModule.getDescriptor();
+
+ // add dependency management info from imported module
+ List<PomDependencyMgt> depMgt = PomModuleDescriptorBuilder
+ .getDependencyManagements(importDescr);
+ for (PomDependencyMgt importedDepMgt : depMgt) {
+ mdBuilder.addDependencyMgt(new DefaultPomDependencyMgt(importedDepMgt.getGroupId(),
+ importedDepMgt.getArtifactId(), importedDepMgt.getVersion(),
+ importedDepMgt.getScope(), importedDepMgt.getExcludedModules()));
+ }
+ } else {
+ mdBuilder.addDependencyMgt(dep);
+ }
+
+ }
+
private void addSourcesAndJavadocArtifactsIfPresent(PomModuleDescriptorBuilder mdBuilder,
ParserSettings ivySettings) {
if (mdBuilder.getMainArtifact() == null) {
@@ -316,8 +321,10 @@ public final class PomModuleDescriptorParser implements ModuleDescriptorParser {
return;
}
- boolean sourcesLookup = !"false".equals(ivySettings.getVariable("ivy.maven.lookup.sources"));
- boolean javadocLookup = !"false".equals(ivySettings.getVariable("ivy.maven.lookup.javadoc"));
+ boolean sourcesLookup = !"false"
+ .equals(ivySettings.getVariable("ivy.maven.lookup.sources"));
+ boolean javadocLookup = !"false"
+ .equals(ivySettings.getVariable("ivy.maven.lookup.javadoc"));
if (!sourcesLookup && !javadocLookup) {
Message.debug("Sources and javadocs lookup disabled");
return;
@@ -328,8 +335,8 @@ public final class PomModuleDescriptorParser implements ModuleDescriptorParser {
DependencyResolver resolver = ivySettings.getResolver(mrid);
if (resolver == null) {
- Message.debug("no resolver found for " + mrid
- + ": no source or javadoc artifact lookup");
+ Message.debug(
+ "no resolver found for " + mrid + ": no source or javadoc artifact lookup");
} else {
ArtifactOrigin mainArtifact = resolver.locate(mdBuilder.getMainArtifact());
@@ -359,7 +366,8 @@ public final class PomModuleDescriptorParser implements ModuleDescriptorParser {
}
if (javadocLookup) {
- ArtifactOrigin javadocArtifact = resolver.locate(mdBuilder.getJavadocArtifact());
+ ArtifactOrigin javadocArtifact = resolver
+ .locate(mdBuilder.getJavadocArtifact());
if (!ArtifactOrigin.isUnknown(javadocArtifact)
&& !javadocArtifact.getLocation().equals(mainArtifactLocation)) {
Message.debug("javadoc artifact found for " + mrid);
http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/8ff6e5a9/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java b/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java
index 1d25d48..bfefe7c 100644
--- a/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java
+++ b/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java
@@ -52,6 +52,8 @@ import org.xml.sax.SAXParseException;
*/
public class PomReader {
+ private static final String PROFILES_ELEMENT = "profiles";
+
private static final String PACKAGING = "packaging";
private static final String DEPENDENCY = "dependency";
@@ -106,6 +108,8 @@ public class PomReader {
private static final String TYPE = "type";
+ private static final String PROFILE = "profile";
+
private HashMap<String, String> properties = new HashMap<String, String>();
private final Element projectElement;
@@ -113,8 +117,8 @@ public class PomReader {
private final Element parentElement;
public PomReader(URL descriptorURL, Resource res) throws IOException, SAXException {
- InputStream stream = new AddDTDFilterInputStream(URLHandlerRegistry.getDefault()
- .openStream(descriptorURL));
+ InputStream stream = new AddDTDFilterInputStream(
+ URLHandlerRegistry.getDefault().openStream(descriptorURL));
InputSource source = new InputSource(stream);
source.setSystemId(XMLHelper.toSystemId(descriptorURL));
try {
@@ -122,8 +126,8 @@ public class PomReader {
public InputSource resolveEntity(String publicId, String systemId)
throws SAXException, IOException {
if ((systemId != null) && systemId.endsWith("m2-entities.ent")) {
- return new InputSource(PomReader.class
- .getResourceAsStream("m2-entities.ent"));
+ return new InputSource(
+ PomReader.class.getResourceAsStream("m2-entities.ent"));
}
return null;
}
@@ -276,36 +280,62 @@ public class PomReader {
}
public List<PomDependencyData> getDependencies() {
- Element dependenciesElement = getFirstChildElement(projectElement, DEPENDENCIES);
- LinkedList<PomDependencyData> dependencies = new LinkedList<PomDependencyData>();
- if (dependenciesElement != null) {
- NodeList childs = dependenciesElement.getChildNodes();
- for (int i = 0; i < childs.getLength(); i++) {
- Node node = childs.item(i);
- if (node instanceof Element && DEPENDENCY.equals(node.getNodeName())) {
- dependencies.add(new PomDependencyData((Element) node));
- }
+ return getDependencies(projectElement);
+ }
+
+ private List<PomDependencyData> getDependencies(Element parent) {
+ Element dependenciesElement = getFirstChildElement(parent, DEPENDENCIES);
+ if (dependenciesElement == null) {
+ return Collections.emptyList();
+ }
+ List<PomDependencyData> dependencies = new LinkedList<PomDependencyData>();
+ NodeList children = dependenciesElement.getChildNodes();
+ for (int i = 0, sz = children.getLength(); i < sz; i++) {
+ Node node = children.item(i);
+ if (node instanceof Element && DEPENDENCY.equals(node.getNodeName())) {
+ dependencies.add(new PomDependencyData((Element) node));
}
}
return dependencies;
}
public List<PomDependencyMgt> getDependencyMgt() {
- Element dependenciesElement = getFirstChildElement(projectElement, DEPENDENCY_MGT);
- dependenciesElement = getFirstChildElement(dependenciesElement, DEPENDENCIES);
- LinkedList<PomDependencyMgt> dependencies = new LinkedList<PomDependencyMgt>();
- if (dependenciesElement != null) {
- NodeList childs = dependenciesElement.getChildNodes();
- for (int i = 0; i < childs.getLength(); i++) {
- Node node = childs.item(i);
- if (node instanceof Element && DEPENDENCY.equals(node.getNodeName())) {
- dependencies.add(new PomDependencyMgtElement((Element) node));
- }
+ return getDependencyMgt(projectElement);
+ }
+
+ private List<PomDependencyMgt> getDependencyMgt(Element parent) {
+ Element dependenciesElement = getFirstChildElement(
+ getFirstChildElement(parent, DEPENDENCY_MGT), DEPENDENCIES);
+ if (dependenciesElement == null) {
+ return Collections.emptyList();
+ }
+ List<PomDependencyMgt> dependencies = new LinkedList<PomDependencyMgt>();
+ NodeList children = dependenciesElement.getChildNodes();
+ for (int i = 0, sz = children.getLength(); i < sz; i++) {
+ Node node = children.item(i);
+ if (node instanceof Element && DEPENDENCY.equals(node.getNodeName())) {
+ dependencies.add(new PomDependencyMgtElement((Element) node));
}
}
return dependencies;
}
+ public List<PomProfileElement> getProfiles() {
+ Element profilesElement = getFirstChildElement(projectElement, PROFILES_ELEMENT);
+ if (profilesElement == null) {
+ return Collections.emptyList();
+ }
+ List<PomProfileElement> result = new LinkedList<PomReader.PomProfileElement>();
+ NodeList children = profilesElement.getChildNodes();
+ for (int i = 0, sz = children.getLength(); i < sz; i++) {
+ Node node = children.item(i);
+ if (node instanceof Element && PROFILE.equals(node.getNodeName())) {
+ result.add(new PomProfileElement((Element) node));
+ }
+ }
+ return result;
+ }
+
public class PomDependencyMgtElement implements PomDependencyMgt {
private final Element depElement;
@@ -319,7 +349,6 @@ public class PomReader {
/*
* (non-Javadoc)
- *
* @see org.apache.ivy.plugins.parser.m2.PomDependencyMgt#getGroupId()
*/
public String getGroupId() {
@@ -329,7 +358,6 @@ public class PomReader {
/*
* (non-Javadoc)
- *
* @see org.apache.ivy.plugins.parser.m2.PomDependencyMgt#getArtifaceId()
*/
public String getArtifactId() {
@@ -339,7 +367,6 @@ public class PomReader {
/*
* (non-Javadoc)
- *
* @see org.apache.ivy.plugins.parser.m2.PomDependencyMgt#getVersion()
*/
public String getVersion() {
@@ -354,17 +381,18 @@ public class PomReader {
public List<ModuleId> getExcludedModules() {
Element exclusionsElement = getFirstChildElement(depElement, EXCLUSIONS);
+ if (exclusionsElement == null) {
+ return Collections.emptyList();
+ }
LinkedList<ModuleId> exclusions = new LinkedList<ModuleId>();
- if (exclusionsElement != null) {
- NodeList childs = exclusionsElement.getChildNodes();
- for (int i = 0; i < childs.getLength(); i++) {
- Node node = childs.item(i);
- if (node instanceof Element && EXCLUSION.equals(node.getNodeName())) {
- String groupId = getFirstChildText((Element) node, GROUP_ID);
- String artifactId = getFirstChildText((Element) node, ARTIFACT_ID);
- if ((groupId != null) && (artifactId != null)) {
- exclusions.add(ModuleId.newInstance(groupId, artifactId));
- }
+ NodeList children = exclusionsElement.getChildNodes();
+ for (int i = 0, sz = children.getLength(); i < sz; i++) {
+ Node node = children.item(i);
+ if (node instanceof Element && EXCLUSION.equals(node.getNodeName())) {
+ String groupId = getFirstChildText((Element) node, GROUP_ID);
+ String artifactId = getFirstChildText((Element) node, ARTIFACT_ID);
+ if ((groupId != null) && (artifactId != null)) {
+ exclusions.add(ModuleId.newInstance(groupId, artifactId));
}
}
}
@@ -373,21 +401,22 @@ public class PomReader {
}
public List<PomPluginElement> getPlugins() {
- LinkedList<PomPluginElement> plugins = new LinkedList<PomPluginElement>();
-
- Element buildElement = getFirstChildElement(projectElement, "build");
- if (buildElement == null) {
- return plugins;
- }
+ return getPlugins(projectElement);
+ }
+ private List<PomPluginElement> getPlugins(Element parent) {
+ Element buildElement = getFirstChildElement(parent, "build");
Element pluginsElement = getFirstChildElement(buildElement, PLUGINS);
- if (pluginsElement != null) {
- NodeList childs = pluginsElement.getChildNodes();
- for (int i = 0; i < childs.getLength(); i++) {
- Node node = childs.item(i);
- if (node instanceof Element && PLUGIN.equals(node.getNodeName())) {
- plugins.add(new PomPluginElement((Element) node));
- }
+
+ if (pluginsElement == null) {
+ return Collections.emptyList();
+ }
+ NodeList children = pluginsElement.getChildNodes();
+ List<PomPluginElement> plugins = new LinkedList<PomPluginElement>();
+ for (int i = 0; i < children.getLength(); i++) {
+ Node node = children.item(i);
+ if (node instanceof Element && PLUGIN.equals(node.getNodeName())) {
+ plugins.add(new PomPluginElement((Element) node));
}
}
return plugins;
@@ -453,8 +482,80 @@ public class PomReader {
}
public boolean isOptional() {
- Element e = getFirstChildElement(depElement, OPTIONAL);
- return (e != null) && "true".equalsIgnoreCase(getTextContent(e));
+ return Boolean.parseBoolean(getFirstChildText(depElement, OPTIONAL));
+ }
+
+ }
+
+ public class PomProfileElement {
+
+ private static final String VALUE = "value";
+
+ private static final String NAME = "name";
+
+ private static final String PROPERTY = "property";
+
+ private static final String ID_ELEMENT = "id";
+
+ private static final String ACTIVATION_ELEMENT = "activation";
+
+ private static final String ACTIVE_BY_DEFAULT_ELEMENT = "activeByDefault";
+
+ private final Element profileElement;
+
+ PomProfileElement(Element profileElement) {
+ this.profileElement = profileElement;
+ }
+
+ public String getId() {
+ return getFirstChildText(profileElement, ID_ELEMENT);
+ }
+
+ public boolean isActive() {
+ return isActiveByDefault() || isActivatedByProperty();
+ }
+
+ public boolean isActiveByDefault() {
+ Element activation = getFirstChildElement(profileElement, ACTIVATION_ELEMENT);
+ return Boolean.parseBoolean(getFirstChildText(activation, ACTIVE_BY_DEFAULT_ELEMENT));
+ }
+
+ public boolean isActivatedByProperty() {
+ Element activation = getFirstChildElement(profileElement, ACTIVATION_ELEMENT);
+ Element propertyActivation = getFirstChildElement(activation, PROPERTY);
+ String propertyName = getFirstChildText(propertyActivation, NAME);
+ if (propertyName == null || "".equals(propertyName)) {
+ return false;
+ }
+ boolean negate = propertyName.charAt(0) == '!';
+ if (negate) {
+ propertyName = propertyName.substring(1);
+ }
+ if ("".equals(propertyName)) {
+ return false;
+ }
+ String propertyValue = getFirstChildText(propertyActivation, VALUE);
+
+ Map<String, String> pomProperties = PomReader.this.getPomProperties();
+ boolean matched;
+ if (propertyValue == null || "".equals(propertyValue)) {
+ matched = pomProperties.containsKey(propertyName);
+ } else {
+ matched = propertyValue.equals(pomProperties.get(propertyName));
+ }
+ return matched ^ negate;
+ }
+
+ public List<PomDependencyData> getDependencies() {
+ return PomReader.this.getDependencies(profileElement);
+ }
+
+ public List<PomDependencyMgt> getDependencyMgt() {
+ return PomReader.this.getDependencyMgt(profileElement);
+ }
+
+ public List<PomPluginElement> getPlugins() {
+ return PomReader.this.getPlugins(profileElement);
}
}
@@ -483,7 +584,7 @@ public class PomReader {
}
private static String getTextContent(Element element) {
- StringBuffer result = new StringBuffer();
+ StringBuilder result = new StringBuilder();
NodeList childNodes = element.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/8ff6e5a9/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParserTest.java
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParserTest.java b/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParserTest.java
index 6f60ace..02e1736 100644
--- a/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParserTest.java
+++ b/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParserTest.java
@@ -340,7 +340,7 @@ public class PomModuleDescriptorParserTest extends AbstractModuleDescriptorParse
}
// IVY-392
- public void testDependenciesWithProfile() throws Exception {
+ public void testDependenciesWithInactiveProfile() throws Exception {
ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings,
getClass().getResource("test-dependencies-with-profile.pom"), false);
assertNotNull(md);
@@ -888,6 +888,96 @@ public class PomModuleDescriptorParserTest extends AbstractModuleDescriptorParse
assertEquals("jar", artifact[0].getType());
}
+ public void testParentBomImport() throws ParseException, IOException {
+ settings.setDictatorResolver(new MockResolver() {
+ public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data)
+ throws ParseException {
+ try {
+ ModuleDescriptor moduleDescriptor = PomModuleDescriptorParser.getInstance()
+ .parseDescriptor(settings,
+ getClass().getResource(
+ String.format("depmgt/%s.pom", dd.getDependencyId().getName())),
+ false);
+ return new ResolvedModuleRevision(null, null, moduleDescriptor, null);
+ } catch (IOException e) {
+ throw new AssertionError(e);
+ }
+ }
+ });
+ ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings,
+ getClass().getResource("depmgt/child.pom"), false);
+ assertNotNull(md);
+ assertEquals("1.0", md.getRevision());
+
+ DependencyDescriptor[] dds = md.getDependencies();
+ assertNotNull(dds);
+ assertEquals(1, dds.length);
+
+ assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"),
+ dds[0].getDependencyRevisionId());
+ }
+
+ public void testGrandparentBomImport() throws ParseException, IOException {
+ settings.setDictatorResolver(new MockResolver() {
+ public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data)
+ throws ParseException {
+ try {
+ ModuleDescriptor moduleDescriptor = PomModuleDescriptorParser.getInstance()
+ .parseDescriptor(settings,
+ getClass().getResource(
+ String.format("depmgt/%s.pom", dd.getDependencyId().getName())),
+ false);
+ return new ResolvedModuleRevision(null, null, moduleDescriptor, null);
+ } catch (IOException e) {
+ throw new AssertionError(e);
+ }
+ }
+ });
+ ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings,
+ getClass().getResource("depmgt/grandchild.pom"), false);
+ assertNotNull(md);
+ assertEquals("1.0", md.getRevision());
+
+ DependencyDescriptor[] dds = md.getDependencies();
+ assertNotNull(dds);
+ assertEquals(2, dds.length);
+
+ assertEquals(
+ ModuleRevisionId.newInstance("commons-collection", "commons-collection", "1.0.5"),
+ dds[0].getDependencyRevisionId());
+ assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"),
+ dds[1].getDependencyRevisionId());
+ }
+
+ public void testParentProfileBomImport() throws ParseException, IOException {
+ settings.setDictatorResolver(new MockResolver() {
+ public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data)
+ throws ParseException {
+ try {
+ ModuleDescriptor moduleDescriptor = PomModuleDescriptorParser.getInstance()
+ .parseDescriptor(settings,
+ getClass().getResource(
+ String.format("depmgt/%s.pom", dd.getDependencyId().getName())),
+ false);
+ return new ResolvedModuleRevision(null, null, moduleDescriptor, null);
+ } catch (IOException e) {
+ throw new AssertionError(e);
+ }
+ }
+ });
+ ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings,
+ getClass().getResource("depmgt/profile-parent-child.pom"), false);
+ assertNotNull(md);
+ assertEquals("1.0", md.getRevision());
+
+ DependencyDescriptor[] dds = md.getDependencies();
+ assertNotNull(dds);
+ assertEquals(1, dds.length);
+
+ assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"),
+ dds[0].getDependencyRevisionId());
+ }
+
private IvySettings createIvySettingsForParentLicenseTesting(final String parentPomFileName, final String parentOrgName,
final String parentModuleName) throws Exception {
final URL parentPomURL = this.getClass().getResource(parentPomFileName);
http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/8ff6e5a9/test/java/org/apache/ivy/plugins/parser/m2/depmgt/bom.pom
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/plugins/parser/m2/depmgt/bom.pom b/test/java/org/apache/ivy/plugins/parser/m2/depmgt/bom.pom
new file mode 100644
index 0000000..99d35a9
--- /dev/null
+++ b/test/java/org/apache/ivy/plugins/parser/m2/depmgt/bom.pom
@@ -0,0 +1,52 @@
+<?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.apache</groupId>
+ <artifactId>bom</artifactId>
+ <version>1.0</version>
+ <packaging>pom</packaging>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.0.4</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-collection</groupId>
+ <artifactId>commons-collection</artifactId>
+ <version>1.0.5</version>
+ <exclusions>
+ <exclusion>
+ <groupId>javax.mail</groupId>
+ <artifactId>mail</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>javax.jms</groupId>
+ <artifactId>jms</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+</project>
http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/8ff6e5a9/test/java/org/apache/ivy/plugins/parser/m2/depmgt/child.pom
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/plugins/parser/m2/depmgt/child.pom b/test/java/org/apache/ivy/plugins/parser/m2/depmgt/child.pom
new file mode 100644
index 0000000..73d4157
--- /dev/null
+++ b/test/java/org/apache/ivy/plugins/parser/m2/depmgt/child.pom
@@ -0,0 +1,36 @@
+<?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>
+
+ <parent>
+ <groupId>org.apache</groupId>
+ <artifactId>parent</artifactId>
+ <version>1.0</version>
+ </parent>
+ <artifactId>child</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/8ff6e5a9/test/java/org/apache/ivy/plugins/parser/m2/depmgt/grandchild.pom
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/plugins/parser/m2/depmgt/grandchild.pom b/test/java/org/apache/ivy/plugins/parser/m2/depmgt/grandchild.pom
new file mode 100644
index 0000000..460bffb
--- /dev/null
+++ b/test/java/org/apache/ivy/plugins/parser/m2/depmgt/grandchild.pom
@@ -0,0 +1,36 @@
+<?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>
+
+ <parent>
+ <groupId>org.apache</groupId>
+ <artifactId>child</artifactId>
+ <version>1.0</version>
+ </parent>
+ <artifactId>grandchild</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>commons-collection</groupId>
+ <artifactId>commons-collection</artifactId>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/8ff6e5a9/test/java/org/apache/ivy/plugins/parser/m2/depmgt/parent.pom
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/plugins/parser/m2/depmgt/parent.pom b/test/java/org/apache/ivy/plugins/parser/m2/depmgt/parent.pom
new file mode 100644
index 0000000..8940c99
--- /dev/null
+++ b/test/java/org/apache/ivy/plugins/parser/m2/depmgt/parent.pom
@@ -0,0 +1,38 @@
+<?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.apache</groupId>
+ <artifactId>parent</artifactId>
+ <version>1.0</version>
+ <packaging>pom</packaging>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>bom</artifactId>
+ <version>1.0</version>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+</project>
http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/8ff6e5a9/test/java/org/apache/ivy/plugins/parser/m2/depmgt/profile-parent-child.pom
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/plugins/parser/m2/depmgt/profile-parent-child.pom b/test/java/org/apache/ivy/plugins/parser/m2/depmgt/profile-parent-child.pom
new file mode 100644
index 0000000..8b712d8
--- /dev/null
+++ b/test/java/org/apache/ivy/plugins/parser/m2/depmgt/profile-parent-child.pom
@@ -0,0 +1,36 @@
+<?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>
+
+ <parent>
+ <groupId>org.apache</groupId>
+ <artifactId>profile-parent</artifactId>
+ <version>1.0</version>
+ </parent>
+ <artifactId>profile-parent-child</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/8ff6e5a9/test/java/org/apache/ivy/plugins/parser/m2/depmgt/profile-parent.pom
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/plugins/parser/m2/depmgt/profile-parent.pom b/test/java/org/apache/ivy/plugins/parser/m2/depmgt/profile-parent.pom
new file mode 100644
index 0000000..74b0135
--- /dev/null
+++ b/test/java/org/apache/ivy/plugins/parser/m2/depmgt/profile-parent.pom
@@ -0,0 +1,46 @@
+<?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.apache</groupId>
+ <artifactId>parent</artifactId>
+ <version>1.0</version>
+ <packaging>pom</packaging>
+
+ <profiles>
+ <profile>
+ <id>basic</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>bom</artifactId>
+ <version>1.0</version>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+ </profile>
+ </profiles>
+</project>
[2/2] ant-ivy git commit: small cleanups
Posted by mb...@apache.org.
small cleanups
Project: http://git-wip-us.apache.org/repos/asf/ant-ivy/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant-ivy/commit/f6377533
Tree: http://git-wip-us.apache.org/repos/asf/ant-ivy/tree/f6377533
Diff: http://git-wip-us.apache.org/repos/asf/ant-ivy/diff/f6377533
Branch: refs/heads/master
Commit: f6377533645ca415addf9e1c428600e10053d72d
Parents: 8ff6e5a
Author: Matt Benson <mb...@apache.org>
Authored: Fri Apr 21 09:15:34 2017 -0500
Committer: Matt Benson <mb...@apache.org>
Committed: Fri Apr 21 09:15:34 2017 -0500
----------------------------------------------------------------------
.../cache/DefaultRepositoryCacheManager.java | 137 ++++++++-----------
.../org/apache/ivy/core/resolve/IvyNode.java | 117 +++++++---------
.../ivy/plugins/resolver/BasicResolver.java | 103 +++++++-------
3 files changed, 152 insertions(+), 205 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/f6377533/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java b/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java
index d6f33b7..6fe13c7 100644
--- a/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java
+++ b/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java
@@ -27,7 +27,6 @@ import java.security.NoSuchAlgorithmException;
import java.text.ParseException;
import java.util.Date;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.regex.Pattern;
import org.apache.ivy.Ivy;
@@ -188,17 +187,17 @@ public class DefaultRepositoryCacheManager implements RepositoryCacheManager, Iv
public long getDefaultTTL() {
if (defaultTTL == null) {
- defaultTTL = new Long(parseDuration(settings.getVariable("ivy.cache.ttl.default")));
+ defaultTTL = Long.valueOf(parseDuration(settings.getVariable("ivy.cache.ttl.default")));
}
return defaultTTL.longValue();
}
public void setDefaultTTL(long defaultTTL) {
- this.defaultTTL = new Long(defaultTTL);
+ this.defaultTTL = Long.valueOf(defaultTTL);
}
public void setDefaultTTL(String defaultTTL) {
- this.defaultTTL = new Long(parseDuration(defaultTTL));
+ this.defaultTTL = Long.valueOf(parseDuration(defaultTTL));
}
public String getDataFilePattern() {
@@ -295,10 +294,9 @@ public class DefaultRepositoryCacheManager implements RepositoryCacheManager, Iv
return days * MILLIS_IN_DAY + hours * MILLIS_IN_HOUR + minutes * MILLIS_IN_MINUTES
+ seconds * MILLIS_IN_SECONDS + millis;
- } else {
- throw new IllegalArgumentException("invalid duration '" + duration
- + "': it must match " + DURATION_PATTERN.pattern() + " or 'eternal'");
}
+ throw new IllegalArgumentException("invalid duration '" + duration
+ + "': it must match " + DURATION_PATTERN.pattern() + " or 'eternal'");
}
private int getGroupIntValue(java.util.regex.Matcher m, int groupNumber) {
@@ -309,19 +307,14 @@ public class DefaultRepositoryCacheManager implements RepositoryCacheManager, Iv
/**
* True if this cache should check lastmodified date to know if ivy files are up to date.
*
- * @return
+ * @return boolean
*/
public boolean isCheckmodified() {
if (checkmodified == null) {
- if (getSettings() != null) {
- String check = getSettings().getVariable("ivy.resolver.default.check.modified");
- return check != null ? Boolean.valueOf(check).booleanValue() : false;
- } else {
- return false;
- }
- } else {
- return checkmodified.booleanValue();
+ return getSettings() != null && Boolean
+ .parseBoolean(getSettings().getVariable("ivy.resolver.default.check.modified"));
}
+ return checkmodified.booleanValue();
}
public void setCheckmodified(boolean check) {
@@ -334,14 +327,9 @@ public class DefaultRepositoryCacheManager implements RepositoryCacheManager, Iv
*/
public boolean isUseOrigin() {
if (useOrigin == null) {
- if (getSettings() != null) {
- return getSettings().isDefaultUseOrigin();
- } else {
- return false;
- }
- } else {
- return useOrigin.booleanValue();
+ return getSettings() != null && getSettings().isDefaultUseOrigin();
}
+ return useOrigin.booleanValue();
}
public void setUseOrigin(boolean b) {
@@ -384,9 +372,8 @@ public class DefaultRepositoryCacheManager implements RepositoryCacheManager, Iv
private File getArchiveFileInCache(Artifact artifact, ArtifactOrigin origin, boolean useOrigin) {
if (useOrigin && !ArtifactOrigin.isUnknown(origin) && origin.isLocal()) {
return Checks.checkAbsolute(origin.getLocation(), artifact + " origin location");
- } else {
- return new File(getRepositoryCacheRoot(), getArchivePathInCache(artifact, origin));
}
+ return new File(getRepositoryCacheRoot(), getArchivePathInCache(artifact, origin));
}
public String getArchivePathInCache(Artifact artifact) {
@@ -396,9 +383,8 @@ public class DefaultRepositoryCacheManager implements RepositoryCacheManager, Iv
public String getArchivePathInCache(Artifact artifact, ArtifactOrigin origin) {
if (isOriginalMetadataArtifact(artifact)) {
return IvyPatternHelper.substitute(getIvyPattern() + ".original", artifact, origin);
- } else {
- return IvyPatternHelper.substitute(getArtifactPattern(), artifact, origin);
}
+ return IvyPatternHelper.substitute(getArtifactPattern(), artifact, origin);
}
/**
@@ -532,7 +518,7 @@ public class DefaultRepositoryCacheManager implements RepositoryCacheManager, Iv
// origin. We must parse the key as we do not know for sure what the original
// artifact is named.
String ownLocationKey = getLocationKey(artifact);
- for (Entry<Object, Object> entry : cdf.entrySet()) {
+ for (Map.Entry<Object, Object> entry : cdf.entrySet()) {
if (entry.getValue().equals(location)
&& !ownLocationKey.equals(entry.getKey())) {
// found a match, key is
@@ -574,7 +560,7 @@ public class DefaultRepositoryCacheManager implements RepositoryCacheManager, Iv
origin.setLastChecked(Long.valueOf(lastChecked));
}
if (exists != null) {
- origin.setExist(Boolean.valueOf(exists).booleanValue());
+ origin.setExist(Boolean.parseBoolean(exists));
}
return origin;
@@ -705,24 +691,23 @@ public class DefaultRepositoryCacheManager implements RepositoryCacheManager, Iv
try {
if (settings.getVersionMatcher().isDynamic(mrid)) {
String resolvedRevision = getResolvedRevision(expectedResolver, mrid, options);
- if (resolvedRevision != null) {
- Message.verbose("found resolved revision in cache: " + mrid + " => "
- + resolvedRevision);
-
- // we have found another module in the cache, make sure we unlock
- // the original module
- unlockMetadataArtifact(mrid);
- mrid = ModuleRevisionId.newInstance(mrid, resolvedRevision);
-
- // don't forget to request a lock on the new module!
- if (!lockMetadataArtifact(mrid)) {
- Message.error("impossible to acquire lock for " + mrid);
-
- // we couldn't lock the new module, so no need to unlock it
- unlock = false;
- return null;
- }
- } else {
+ if (resolvedRevision == null) {
+ return null;
+ }
+ Message.verbose("found resolved revision in cache: " + mrid + " => "
+ + resolvedRevision);
+
+ // we have found another module in the cache, make sure we unlock
+ // the original module
+ unlockMetadataArtifact(mrid);
+ mrid = ModuleRevisionId.newInstance(mrid, resolvedRevision);
+
+ // don't forget to request a lock on the new module!
+ if (!lockMetadataArtifact(mrid)) {
+ Message.error("impossible to acquire lock for " + mrid);
+
+ // we couldn't lock the new module, so no need to unlock it
+ unlock = false;
return null;
}
}
@@ -775,11 +760,10 @@ public class DefaultRepositoryCacheManager implements RepositoryCacheManager, Iv
}
}
return new ResolvedModuleRevision(resolver, artResolver, depMD, madr);
- } else {
- Message.debug("found module in cache but with a different resolver: "
- + "discarding: " + mrid + "; expected resolver="
- + expectedResolver + "; resolver=" + resolver.getName());
}
+ Message.debug("found module in cache but with a different resolver: "
+ + "discarding: " + mrid + "; expected resolver="
+ + expectedResolver + "; resolver=" + resolver.getName());
} else {
Message.debug("\tresolver not found: " + resolverName
+ " => cannot use cached ivy file for " + mrid);
@@ -853,7 +837,6 @@ public class DefaultRepositoryCacheManager implements RepositoryCacheManager, Iv
return null;
}
try {
- String resolvedRevision = null;
if (options.isForce()) {
Message.verbose("refresh mode: no check for cached resolved revision for " + mrid);
return null;
@@ -865,7 +848,7 @@ public class DefaultRepositoryCacheManager implements RepositoryCacheManager, Iv
} else {
cachedResolvedRevision = getCachedDataFile(mrid);
}
- resolvedRevision = cachedResolvedRevision.getProperty("resolved.revision");
+ String resolvedRevision = cachedResolvedRevision.getProperty("resolved.revision");
if (resolvedRevision == null) {
Message.verbose(getName() + ": no cached resolved revision for " + mrid);
return null;
@@ -1173,13 +1156,12 @@ public class DefaultRepositoryCacheManager implements RepositoryCacheManager, Iv
* @return the hash
*/
private String computeResourceNameHash(Resource resource) {
- byte[] shaDigest;
try {
- shaDigest = SHA_DIGEST.digest(resource.getName().getBytes("UTF-8"));
+ byte[] shaDigest = SHA_DIGEST.digest(resource.getName().getBytes("UTF-8"));
+ return HexEncoder.encode(shaDigest);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("UTF-8 not supported", e);
}
- return HexEncoder.encode(shaDigest);
}
/**
@@ -1203,18 +1185,13 @@ public class DefaultRepositoryCacheManager implements RepositoryCacheManager, Iv
if (savedOrigin.getLastChecked() != null
&& (time - savedOrigin.getLastChecked().longValue()) < ttl) {
// still in the ttl period, no need to check, trust the cache
- if (!archiveFile.exists()) {
- // but if the local archive doesn't exist, trust the cache only if the cached origin
- // says that the remote resource doesn't exist either
- return !savedOrigin.isExists();
- }
- return true;
+ return archiveFile.exists() || !savedOrigin.isExists();
}
if (!archiveFile.exists()) {
// the the file doesn't exist in the cache, obviously not up to date
return false;
}
- origin.setLastChecked(new Long(time));
+ origin.setLastChecked(Long.valueOf(time));
// check if the local resource is up to date regarding the remote one
return archiveFile.lastModified() >= resource.getLastModified();
}
@@ -1317,16 +1294,15 @@ public class DefaultRepositoryCacheManager implements RepositoryCacheManager, Iv
+ mrid);
rmr.getReport().setSearched(true);
return rmr;
- } else {
- Message.verbose("\t" + getName()
- + ": revision in cache is not up to date: " + mrid);
- if (isChanging(dd, mrid, options)) {
- // ivy file has been updated, we should see if it has a new publication
- // date to see if a new download is required (in case the dependency is
- // a changing one)
- cachedPublicationDate = rmr.getDescriptor()
- .getResolvedPublicationDate();
- }
+ }
+ Message.verbose("\t" + getName()
+ + ": revision in cache is not up to date: " + mrid);
+ if (isChanging(dd, mrid, options)) {
+ // ivy file has been updated, we should see if it has a new publication
+ // date to see if a new download is required (in case the dependency is
+ // a changing one)
+ cachedPublicationDate = rmr.getDescriptor()
+ .getResolvedPublicationDate();
}
}
}
@@ -1359,9 +1335,8 @@ public class DefaultRepositoryCacheManager implements RepositoryCacheManager, Iv
parserSettings);
if (md == null) {
throw new IllegalStateException(
- "module descriptor parser returned a null module descriptor, "
- + "which is not allowed. " + "parser=" + parser
- + "; parser class=" + parser.getClass().getName()
+ "module descriptor parser returned a null module descriptor, which is not allowed. parser="
+ + parser + "; parser class=" + parser.getClass().getName()
+ "; module descriptor resource=" + mdRef.getResource());
}
Message.debug("\t" + getName() + ": parsed downloaded md file for " + mrid
@@ -1376,11 +1351,9 @@ public class DefaultRepositoryCacheManager implements RepositoryCacheManager, Iv
deleteOldArtifacts = true;
}
if (deleteOldArtifacts) {
- String[] confs = md.getConfigurationsNames();
- for (int i = 0; i < confs.length; i++) {
- Artifact[] arts = md.getArtifacts(confs[i]);
- for (int j = 0; j < arts.length; j++) {
- Artifact transformedArtifact = NameSpaceHelper.transform(arts[j],
+ for (String conf : md.getConfigurationsNames()) {
+ for (Artifact art : md.getArtifacts(conf)) {
+ Artifact transformedArtifact = NameSpaceHelper.transform(art,
options.getNamespace().getToSystemTransformer());
ArtifactOrigin origin = getSavedArtifactOrigin(transformedArtifact);
File artFile = getArchiveFileInCache(transformedArtifact, origin, false);
@@ -1462,7 +1435,7 @@ public class DefaultRepositoryCacheManager implements RepositoryCacheManager, Iv
return new DefaultArtifact(mrid, new Date(), "metadata", "metadata", "ivy", true);
}
- // not used any more, but maybe useful for finer grain locking when downloading artifacts
+ // not used any more, but may be useful for finer grained locking when downloading artifacts
// private boolean lockArtifact(Artifact artifact) {
// try {
// return getLockStrategy().lockArtifact(artifact,
http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/f6377533/src/java/org/apache/ivy/core/resolve/IvyNode.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/core/resolve/IvyNode.java b/src/java/org/apache/ivy/core/resolve/IvyNode.java
index f4e7702..48b23db 100644
--- a/src/java/org/apache/ivy/core/resolve/IvyNode.java
+++ b/src/java/org/apache/ivy/core/resolve/IvyNode.java
@@ -20,6 +20,7 @@ package org.apache.ivy.core.resolve;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -191,8 +192,7 @@ public class IvyNode implements Comparable<IvyNode> {
if (settings.getVersionMatcher().isDynamic(getId())
&& settings.getVersionMatcher().isDynamic(module.getId())) {
Message.error("impossible to resolve dynamic revision for " + getId()
- + ": check your configuration and "
- + "make sure revision is part of your pattern");
+ + ": check your configuration and make sure revision is part of your pattern");
problem = new RuntimeException("impossible to resolve dynamic revision");
return false;
}
@@ -254,13 +254,12 @@ public class IvyNode implements Comparable<IvyNode> {
if (hasProblem()) {
Message.debug("problem : " + problem.getMessage());
return false;
- } else {
- DependencyDescriptor dd = getDependencyDescriptor(parent);
- if (dd != null) {
- usage.addUsage(rootModuleConf, dd, parentConf);
- }
- return loaded;
}
+ DependencyDescriptor dd = getDependencyDescriptor(parent);
+ if (dd != null) {
+ usage.addUsage(rootModuleConf, dd, parentConf);
+ }
+ return loaded;
}
private void moveToRealNode(String rootModuleConf, IvyNode parent, String parentConf,
@@ -320,7 +319,7 @@ public class IvyNode implements Comparable<IvyNode> {
* the configuration to load of this node
* @param requestedConf
* the actual node conf requested, possibly extending the <code>conf</code> one.
- * @return
+ * @return {@link Collection} of {@link IvyNode}
*/
public Collection<IvyNode> getDependencies(String rootModuleConf, String conf,
String requestedConf) {
@@ -331,8 +330,8 @@ public class IvyNode implements Comparable<IvyNode> {
DependencyDescriptor[] dds = md.getDependencies();
// it's important to respect order => LinkedHashMap
Map<ModuleRevisionId, IvyNode> dependencies = new LinkedHashMap<ModuleRevisionId, IvyNode>();
- for (int i = 0; i < dds.length; i++) {
- DependencyDescriptor dd = data.mediate(dds[i]);
+ for (DependencyDescriptor dependencyDescriptor : dds) {
+ DependencyDescriptor dd = data.mediate(dependencyDescriptor);
String[] dependencyConfigurations = dd.getDependencyConfigurations(conf, requestedConf);
if (dependencyConfigurations.length == 0) {
// no configuration of the dependency is required for current confs :
@@ -416,9 +415,8 @@ public class IvyNode implements Comparable<IvyNode> {
return null;
}
return Boolean.valueOf(c.doesCallersExclude(rootModuleConf, artifact, callersStack));
- } else {
- return Boolean.FALSE;
}
+ return Boolean.FALSE;
}
public boolean hasConfigurationsToLoad() {
@@ -438,23 +436,24 @@ public class IvyNode implements Comparable<IvyNode> {
if (md != null) {
String[] confs = getRealConfs(conf);
addRootModuleConfigurations(usage, rootModuleConf, confs);
- for (int i = 0; i < confs.length; i++) {
- Configuration c = md.getConfiguration(confs[i]);
+ for (String realConf : confs) {
+ Configuration c = md.getConfiguration(realConf);
if (c == null) {
confsToFetch.remove(conf);
if (isConfRequiredByMergedUsageOnly(rootModuleConf, conf)) {
Message.verbose("configuration required by evicted revision is not available in "
+ "selected revision. skipping " + conf + " in " + this);
- } else if (!conf.equals(confs[i])) {
+ } else if (!conf.equals(realConf)) {
problem = new RuntimeException("configuration not found in " + this + ": '"
- + conf + "'. Missing configuration: '" + confs[i]
+ + conf + "'. Missing configuration: '" + realConf
+ "'. It was required from " + parent + " " + parentConf);
} else {
problem = new RuntimeException("configuration not found in " + this + ": '"
- + confs[i] + "'. It was required from " + parent + " " + parentConf);
+ + realConf + "'. It was required from " + parent + " " + parentConf);
}
return false;
- } else if (shouldBePublic && !isRoot()
+ }
+ if (shouldBePublic && !isRoot()
&& c.getVisibility() != Configuration.Visibility.PUBLIC) {
confsToFetch.remove(conf);
if (isConfRequiredByMergedUsageOnly(rootModuleConf, conf)) {
@@ -479,20 +478,12 @@ public class IvyNode implements Comparable<IvyNode> {
private String getDefaultConf(String conf) {
Matcher m = FALLBACK_CONF_PATTERN.matcher(conf);
- if (m.matches()) {
- return m.group(2);
- } else {
- return conf;
- }
+ return m.matches() ? m.group(2) : conf;
}
private String getMainConf(String conf) {
Matcher m = FALLBACK_CONF_PATTERN.matcher(conf);
- if (m.matches()) {
- return m.group(1);
- } else {
- return null;
- }
+ return m.matches() ? m.group(1) : null;
}
public void updateConfsToFetch(Collection<String> confs) {
@@ -526,7 +517,7 @@ public class IvyNode implements Comparable<IvyNode> {
* returns the required configurations from the given node
*
* @param in
- * @return
+ * @return array of configuration names
*/
public String[] getRequiredConfigurations(IvyNode in, String inConf) {
Collection<String> req = new LinkedHashSet<String>();
@@ -534,7 +525,7 @@ public class IvyNode implements Comparable<IvyNode> {
for (IvyNodeUsage usage : mergedUsages.values()) {
addAllIfNotNull(req, usage.getRequiredConfigurations(in, inConf));
}
- return req == null ? new String[0] : req.toArray(new String[req.size()]);
+ return req.toArray(new String[req.size()]);
}
private <T> void addAllIfNotNull(Collection<T> into, Collection<T> col) {
@@ -546,7 +537,7 @@ public class IvyNode implements Comparable<IvyNode> {
/**
* returns all the current required configurations of the node
*
- * @return
+ * @return array of configuration names
*/
public String[] getRequiredConfigurations() {
Collection<String> required = new ArrayList<String>(confsToFetch.size()
@@ -574,7 +565,7 @@ public class IvyNode implements Comparable<IvyNode> {
* Returns the configurations of the dependency required in a given root module configuration.
*
* @param rootModuleConf
- * @return
+ * @return array of configuration names
*/
public String[] getConfigurations(String rootModuleConf) {
Set<String> depConfs = new LinkedHashSet<String>();
@@ -613,29 +604,23 @@ public class IvyNode implements Comparable<IvyNode> {
private void addRootModuleConfigurations(IvyNodeUsage usage, String rootModuleConf,
String[] dependencyConfs) {
- Set<String> depConfs = usage.addAndGetConfigurations(rootModuleConf);
if (md != null) {
// add all given dependency configurations to the set + extended ones
- for (int i = 0; i < dependencyConfs.length; i++) {
- depConfs.add(dependencyConfs[i]);
- Configuration conf = md.getConfiguration(dependencyConfs[i]);
+ for (String dependencyConf : dependencyConfs) {
+ Configuration conf = md.getConfiguration(dependencyConf);
if (conf != null) {
- String[] exts = conf.getExtends();
// recursive add of extended
- addRootModuleConfigurations(usage, rootModuleConf, exts);
+ addRootModuleConfigurations(usage, rootModuleConf, conf.getExtends());
}
}
- } else {
- for (int i = 0; i < dependencyConfs.length; i++) {
- depConfs.add(dependencyConfs[i]);
- }
}
+ Collections.addAll(usage.addAndGetConfigurations(rootModuleConf), dependencyConfs);
}
/**
* Returns the root module configurations in which this dependency is required
*
- * @return
+ * @return array of configuration names
*/
public String[] getRootModuleConfigurations() {
Set<String> confs = getRootModuleConfigurationsSet();
@@ -645,7 +630,7 @@ public class IvyNode implements Comparable<IvyNode> {
/**
* Returns the root module configurations in which this dependency is required
*
- * @return
+ * @return {@link Set} of configuration names
*/
public Set<String> getRootModuleConfigurationsSet() {
Set<String> confs = new LinkedHashSet<String>();
@@ -674,9 +659,10 @@ public class IvyNode implements Comparable<IvyNode> {
}
conf = defaultConf;
}
- if (conf.startsWith("*")) {
+ if (conf.charAt(0) == '*') {
return resolveSpecialConfigurations(new String[] {conf});
- } else if (conf.indexOf(',') != -1) {
+ }
+ if (conf.indexOf(',') != -1) {
String[] confs = conf.split(",");
for (int i = 0; i < confs.length; i++) {
confs[i] = confs[i].trim();
@@ -705,8 +691,9 @@ public class IvyNode implements Comparable<IvyNode> {
}
if (path.contains(parent)) {
path.add(0, parent);
- Message.verbose("circular dependency found while looking for the path for another one: "
- + "was looking for " + from + " as a caller of " + path.get(path.size() - 1));
+ Message.verbose(
+ "circular dependency found while looking for the path for another one: was looking for "
+ + from + " as a caller of " + path.get(path.size() - 1));
return path;
}
path.add(0, parent);
@@ -761,7 +748,7 @@ public class IvyNode implements Comparable<IvyNode> {
/**
* Returns all the artifacts of this dependency required in all the root module configurations
*
- * @return
+ * @return array of {@link Artifact}s
*/
public Artifact[] getAllArtifacts() {
Set<Artifact> ret = new HashSet<Artifact>();
@@ -776,7 +763,7 @@ public class IvyNode implements Comparable<IvyNode> {
* which the node is not evicted nor blacklisted
*
* @param artifactFilter
- * @return
+ * @return array of {@link Artifact}s
*/
public Artifact[] getSelectedArtifacts(Filter<Artifact> artifactFilter) {
Collection<Artifact> ret = new HashSet<Artifact>();
@@ -794,7 +781,7 @@ public class IvyNode implements Comparable<IvyNode> {
* in the given root module configuration
*
* @param rootModuleConf
- * @return
+ * @return array of {@link Artifact}s
*/
public Artifact[] getArtifacts(String rootModuleConf) {
// first we look for the dependency configurations required
@@ -807,7 +794,7 @@ public class IvyNode implements Comparable<IvyNode> {
if (md == null) {
throw new IllegalStateException(
"impossible to get artifacts when data has not been loaded. IvyNode = "
- + this.toString());
+ + this);
}
Set<Artifact> artifacts = new HashSet<Artifact>(); // the set we fill before returning
@@ -966,7 +953,7 @@ public class IvyNode implements Comparable<IvyNode> {
if (md == null) {
throw new IllegalStateException(
"impossible to get conflict manager when data has not been loaded. IvyNode = "
- + this.toString());
+ + this);
}
ConflictManager cm = md.getConflictManager(mid);
return cm == null ? settings.getConflictManager(mid) : cm;
@@ -1020,11 +1007,11 @@ public class IvyNode implements Comparable<IvyNode> {
public ModuleRevisionId getResolvedId() {
if (md != null && md.getResolvedModuleRevisionId().getRevision() != null) {
return md.getResolvedModuleRevisionId();
- } else if (module != null) {
+ }
+ if (module != null) {
return module.getId();
- } else {
- return getId();
}
+ return getId();
}
/**
@@ -1039,9 +1026,8 @@ public class IvyNode implements Comparable<IvyNode> {
// /////////////////////////////////////////////////////////////////////////////
boolean canExclude(String rootModuleConf) {
- Caller[] callers = getCallers(rootModuleConf);
- for (int i = 0; i < callers.length; i++) {
- if (callers[i].canExclude()) {
+ for (Caller caller : getCallers(rootModuleConf)) {
+ if (caller.canExclude()) {
return true;
}
}
@@ -1250,10 +1236,8 @@ public class IvyNode implements Comparable<IvyNode> {
}
private void clearEvictionDataInAllCallers(String rootModuleConf, Stack<IvyNode> callerStack) {
- IvyNode node = callerStack.peek();
- Caller[] callers = node.getCallers(rootModuleConf);
- for (int i = 0; i < callers.length; i++) {
- IvyNode callerNode = findNode(callers[i].getModuleRevisionId());
+ for (Caller caller : callerStack.peek().getCallers(rootModuleConf)) {
+ IvyNode callerNode = findNode(caller.getModuleRevisionId());
if (callerNode != null) {
callerNode.eviction = new IvyNodeEviction(callerNode);
if (!callerStack.contains(callerNode)) {
@@ -1291,9 +1275,8 @@ public class IvyNode implements Comparable<IvyNode> {
if (isRoot()) {
return false;
}
- String[] rootModuleConfigurations = getRootModuleConfigurations();
- for (int i = 0; i < rootModuleConfigurations.length; i++) {
- if (!isBlacklisted(rootModuleConfigurations[i])) {
+ for (String rootModuleConfiguration : getRootModuleConfigurations()) {
+ if (!isBlacklisted(rootModuleConfiguration)) {
return false;
}
}
http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/f6377533/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java b/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java
index 2980d0c..389998d 100644
--- a/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java
+++ b/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java
@@ -34,7 +34,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
-import java.util.Map.Entry;
import org.apache.ivy.core.IvyContext;
import org.apache.ivy.core.IvyPatternHelper;
@@ -97,6 +96,8 @@ public abstract class BasicResolver extends AbstractResolver {
* </p>
*/
private static class UnresolvedDependencyException extends RuntimeException {
+ private static final long serialVersionUID = 1L;
+
private boolean error;
/**
@@ -204,8 +205,7 @@ public abstract class BasicResolver extends AbstractResolver {
boolean isDynamic = getAndCheckIsDynamic(systemMrid);
// we first search for the dependency in cache
- ResolvedModuleRevision rmr = null;
- rmr = findModuleInCache(systemDd, data);
+ ResolvedModuleRevision rmr = findModuleInCache(systemDd, data);
if (rmr != null) {
if (rmr.getDescriptor().isDefault() && rmr.getResolver() != this) {
Message.verbose("\t" + getName() + ": found revision in cache: " + systemMrid
@@ -277,30 +277,29 @@ public abstract class BasicResolver extends AbstractResolver {
}
if (!rmr.getReport().isDownloaded() && rmr.getReport().getLocalFile() != null) {
return checkLatest(systemDd, checkForcedResolvedModuleRevision(rmr), data);
- } else {
- nsMd = rmr.getDescriptor();
+ }
+ nsMd = rmr.getDescriptor();
- // check descriptor data is in sync with resource revision and names
- systemMd = toSystem(nsMd);
- if (isCheckconsistency()) {
- checkDescriptorConsistency(systemMrid, systemMd, ivyRef);
- checkDescriptorConsistency(nsMrid, nsMd, ivyRef);
+ // check descriptor data is in sync with resource revision and names
+ systemMd = toSystem(nsMd);
+ if (isCheckconsistency()) {
+ checkDescriptorConsistency(systemMrid, systemMd, ivyRef);
+ checkDescriptorConsistency(nsMrid, nsMd, ivyRef);
+ } else {
+ if (systemMd instanceof DefaultModuleDescriptor) {
+ DefaultModuleDescriptor defaultMd = (DefaultModuleDescriptor) systemMd;
+ ModuleRevisionId revision = getRevision(ivyRef, systemMrid, systemMd);
+ defaultMd.setModuleRevisionId(revision);
+ defaultMd.setResolvedModuleRevisionId(revision);
} else {
- if (systemMd instanceof DefaultModuleDescriptor) {
- DefaultModuleDescriptor defaultMd = (DefaultModuleDescriptor) systemMd;
- ModuleRevisionId revision = getRevision(ivyRef, systemMrid, systemMd);
- defaultMd.setModuleRevisionId(revision);
- defaultMd.setResolvedModuleRevisionId(revision);
- } else {
- Message.warn("consistency disabled with instance of non DefaultModuleDescriptor..."
- + " module info can't be updated, so consistency check will be done");
- checkDescriptorConsistency(nsMrid, nsMd, ivyRef);
- checkDescriptorConsistency(systemMrid, systemMd, ivyRef);
- }
+ Message.warn(
+ "consistency disabled with instance of non DefaultModuleDescriptor... module info can't be updated, so consistency check will be done");
+ checkDescriptorConsistency(nsMrid, nsMd, ivyRef);
+ checkDescriptorConsistency(systemMrid, systemMd, ivyRef);
}
- rmr = new ResolvedModuleRevision(this, this, systemMd,
- toSystem(rmr.getReport()), isForce());
}
+ rmr = new ResolvedModuleRevision(this, this, systemMd,
+ toSystem(rmr.getReport()), isForce());
}
resolveAndCheckRevision(systemMd, systemMrid, ivyRef, isDynamic);
@@ -390,9 +389,7 @@ public abstract class BasicResolver extends AbstractResolver {
DefaultModuleDescriptor dmd = (DefaultModuleDescriptor) systemMd;
if (dmd.isNamespaceUseful()) {
Message.warn("the module descriptor " + ivyRef.getResource()
- + " has information which can't be converted into "
- + "the system namespace. "
- + "It will require the availability of the namespace '"
+ + " has information which can't be converted into the system namespace. It will require the availability of the namespace '"
+ getNamespace().getName() + "' to be fully usable.");
}
}
@@ -407,7 +404,8 @@ public abstract class BasicResolver extends AbstractResolver {
throw new UnresolvedDependencyException("\t" + getName()
+ ": unacceptable publication date => was=" + new Date(pubDate)
+ " required=" + data.getDate());
- } else if (pubDate == -1) {
+ }
+ if (pubDate == -1) {
throw new UnresolvedDependencyException("\t" + getName()
+ ": impossible to guess publication date: artifact missing for "
+ systemMrid);
@@ -437,7 +435,7 @@ public abstract class BasicResolver extends AbstractResolver {
private void checkRevision(ModuleRevisionId systemMrid) {
// check revision
- int index = systemMrid.getRevision().indexOf("@");
+ int index = systemMrid.getRevision().indexOf('@');
if (index != -1 && !systemMrid.getRevision().substring(index + 1).equals(workspaceName)) {
throw new UnresolvedDependencyException("\t" + getName() + ": unhandled revision => "
+ systemMrid.getRevision());
@@ -545,15 +543,13 @@ public abstract class BasicResolver extends AbstractResolver {
try {
ResolvedModuleRevision rmr = BasicResolver.this.parse(new ResolvedResource(
resource, rev), dd, data);
- if (rmr == null) {
- return null;
- } else {
+ if (rmr != null) {
return new MDResolvedResource(resource, rev, rmr);
}
} catch (ParseException e) {
Message.warn("Failed to parse the file '" + resource + "'", e);
- return null;
}
+ return null;
}
};
@@ -582,7 +578,7 @@ public abstract class BasicResolver extends AbstractResolver {
private void checkDescriptorConsistency(ModuleRevisionId mrid, ModuleDescriptor md,
ResolvedResource ivyRef) throws ParseException {
boolean ok = true;
- StringBuffer errors = new StringBuffer();
+ StringBuilder errors = new StringBuilder();
if (!mrid.getOrganisation().equals(md.getModuleRevisionId().getOrganisation())) {
Message.error("\t" + getName() + ": bad organisation found in " + ivyRef.getResource()
+ ": expected='" + mrid.getOrganisation() + "' found='"
@@ -626,7 +622,7 @@ public abstract class BasicResolver extends AbstractResolver {
errors.append("bad status: '" + md.getStatus() + "'; ");
ok = false;
}
- for (Entry<String, String> extra : mrid.getExtraAttributes().entrySet()) {
+ for (Map.Entry<String, String> extra : mrid.getExtraAttributes().entrySet()) {
if (extra.getValue() != null
&& !extra.getValue().equals(md.getExtraAttribute(extra.getKey()))) {
String errorMsg = "bad " + extra.getKey() + " found in " + ivyRef.getResource()
@@ -721,13 +717,13 @@ public abstract class BasicResolver extends AbstractResolver {
+ "requiring module descriptor: " + rres);
rejected.add(rres.getRevision() + " (MD)");
continue;
- } else if (!versionMatcher.accept(mrid, md)) {
+ }
+ if (!versionMatcher.accept(mrid, md)) {
Message.debug("\t" + name + ": md rejected by version matcher: " + rres);
rejected.add(rres.getRevision() + " (MD)");
continue;
- } else {
- found = r;
}
+ found = r;
} else {
found = rres;
}
@@ -801,7 +797,7 @@ public abstract class BasicResolver extends AbstractResolver {
for (String m : ivyattempts) {
Message.warn(" " + m);
}
- for (Entry<Artifact, List<String>> entry : artattempts.entrySet()) {
+ for (Map.Entry<Artifact, List<String>> entry : artattempts.entrySet()) {
Artifact art = entry.getKey();
List<String> attempts = entry.getValue();
if (attempts != null) {
@@ -865,15 +861,14 @@ public abstract class BasicResolver extends AbstractResolver {
public ResolvedResource resolve(Artifact artifact) {
try {
Resource resource = getResource(origin.getLocation());
- if (resource == null) {
- return null;
+ if (resource != null) {
+ String revision = origin.getArtifact().getModuleRevisionId().getRevision();
+ return new ResolvedResource(resource, revision);
}
- String revision = origin.getArtifact().getModuleRevisionId().getRevision();
- return new ResolvedResource(resource, revision);
} catch (IOException e) {
Message.debug(e);
- return null;
}
+ return null;
}
}, downloader, getCacheDownloadOptions(options));
}
@@ -969,12 +964,9 @@ public abstract class BasicResolver extends AbstractResolver {
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 = getArtifactRef(artifacts[j], data.getDate());
+ for (String configName : md.getConfigurationsNames()) {
+ for (Artifact artifact : md.getArtifacts(configName)) {
+ ResolvedResource ret = getArtifactRef(artifact, data.getDate());
if (ret != null) {
return ret;
}
@@ -985,10 +977,10 @@ public abstract class BasicResolver extends AbstractResolver {
protected long getAndCheck(Resource resource, File dest) throws IOException {
long size = get(resource, dest);
- String[] checksums = getChecksumAlgorithms();
- boolean checked = false;
- for (int i = 0; i < checksums.length && !checked; i++) {
- checked = check(resource, dest, checksums[i]);
+ for (String checksum : getChecksumAlgorithms()) {
+ if (check(resource, dest, checksum)) {
+ break;
+ }
}
return size;
}
@@ -1123,10 +1115,9 @@ public abstract class BasicResolver extends AbstractResolver {
}
// csDef is a comma separated list of checksum algorithms to use with this resolver
// we parse and return it as a String[]
- String[] checksums = csDef.split(",");
List<String> algos = new ArrayList<String>();
- for (int i = 0; i < checksums.length; i++) {
- String cs = checksums[i].trim();
+ for (String checksum : csDef.split(",")) {
+ String cs = checksum.trim();
if (!"".equals(cs) && !"none".equals(cs)) {
algos.add(cs);
}