Apache Lucene open-source search software
LUCENE-7693: Replace "org.apache." logic in GetMavenDependenciesTask. (Daniel Collins, Christine Poerschke)
Christine Poerschke738da0998a7f
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 60a3e16df09..e4042dad5e1 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -178,6 +178,9 @@ Build* LUCENE-7694: Update forbiddenapis to version 2.3. (Uwe Schindler)+* LUCENE-7693: Replace "org.apache." logic in GetMavenDependenciesTask.+ (Daniel Collins, Christine Poerschke)+Other* LUCENE-7666: Fix typos in lucene-join package info javadoc.diff --git a/lucene/demo/ivy.xml b/lucene/demo/ivy.xmlindex 050f0a58883..5dd7e74fba5 100644--- a/lucene/demo/ivy.xml+++ b/lucene/demo/ivy.xml@@ -17,7 +17,7 @@under the License.--><ivy-module version="2.0">- <info organisation="org.apache.lucene" module="core-demo"/>+ <info organisation="org.apache.lucene" module="demo"/><configurations defaultconfmapping="compile->master"><conf name="compile" transitive="false"/></configurations>diff --git a/lucene/test-framework/ivy.xml b/lucene/test-framework/ivy.xmlindex a71c25a51ec..a51716c8698 100644--- a/lucene/test-framework/ivy.xml+++ b/lucene/test-framework/ivy.xml@@ -17,7 +17,7 @@under the License.--><ivy-module version="2.0">- <info organisation="org.apache.lucene" module="core-test-framework"/>+ <info organisation="org.apache.lucene" module="test-framework"/><configurations defaultconfmapping="compile->master"><conf name="compile" transitive="false"/>diff --git a/lucene/tools/ivy.xml b/lucene/tools/ivy.xmlindex 614aa8eb45b..1fa2974f85b 100644--- a/lucene/tools/ivy.xml+++ b/lucene/tools/ivy.xml@@ -17,7 +17,7 @@under the License.--><ivy-module version="2.0">- <info organisation="org.apache.lucene" module="core-tools"/>+ <info organisation="org.apache.lucene" module="tools"/><configurations defaultconfmapping="compile->master"><conf name="compile" transitive="false"/></configurations>diff --git a/lucene/tools/src/java/org/apache/lucene/dependencies/GetMavenDependenciesTask.java b/lucene/tools/src/java/org/apache/lucene/dependencies/GetMavenDependenciesTask.javaindex 45a9d1126ab..5b2f0b80b00 100644--- a/lucene/tools/src/java/org/apache/lucene/dependencies/GetMavenDependenciesTask.java+++ b/lucene/tools/src/java/org/apache/lucene/dependencies/GetMavenDependenciesTask.java@@ -54,6 +54,7 @@ import java.util.SortedMap;import java.util.SortedSet;import java.util.TreeMap;import java.util.TreeSet;+import java.util.function.Consumer;import java.util.regex.Matcher;import java.util.regex.Pattern;@@ -118,6 +119,7 @@ public class GetMavenDependenciesTask extends Task {private final DocumentBuilder documentBuilder;private File ivyCacheDir;private Pattern internalJarPattern;+ private Map<String,String> ivyModuleInfo;/**@@ -189,6 +191,8 @@ public class GetMavenDependenciesTask extends Task {internalJarPattern = Pattern.compile(".*(lucene|solr)([^/]*?)-"+ Pattern.quote(getProject().getProperty("version")) + "\\.jar");+ ivyModuleInfo = getIvyModuleInfo(ivyXmlResources, documentBuilder, xpath);+setInternalDependencyProperties(); // side-effect: all modules' internal deps are recordedsetExternalDependencyProperties(); // side-effect: all modules' external deps are recordedsetGrandparentDependencyManagementProperty(); // uses deps recorded in above two methods@@ -219,11 +223,57 @@ public class GetMavenDependenciesTask extends Task {}}+ /**+ * Visits all ivy.xml files and collects module and organisation attributes into a map.+ */+ private static Map<String,String> getIvyModuleInfo(Resources ivyXmlResources,+ DocumentBuilder documentBuilder, XPath xpath) {+ Map<String,String> ivyInfoModuleToOrganisation = new HashMap<String,String>();+ traverseIvyXmlResources(ivyXmlResources, new Consumer<File>() {+ @Override+ public void accept(File f) {+ try {+ Document document = documentBuilder.parse(f);+ {+ String infoPath = "/ivy-module/info";+ NodeList infos = (NodeList)xpath.evaluate(infoPath, document, XPathConstants.NODESET);+ for (int infoNum = 0 ; infoNum < infos.getLength() ; ++infoNum) {+ Element infoElement = (Element)infos.item(infoNum);+ String infoOrg = infoElement.getAttribute("organisation");+ String infoOrgSuffix = infoOrg.substring(infoOrg.lastIndexOf('.')+1);+ String infoModule = infoElement.getAttribute("module");+ String module = infoOrgSuffix+"-"+infoModule;+ ivyInfoModuleToOrganisation.put(module, infoOrg);+ }+ }+ } catch (XPathExpressionException | IOException | SAXException e) {+ throw new RuntimeException(e);+ }+ }+ });+ return ivyInfoModuleToOrganisation;+ }+/*** Collects external dependencies from each ivy.xml file and sets* external dependency properties to be inserted into modules' POMs.*/private void setExternalDependencyProperties() {+ traverseIvyXmlResources(ivyXmlResources, new Consumer<File>() {+ @Override+ public void accept(File f) {+ try {+ collectExternalDependenciesFromIvyXmlFile(f);+ } catch (XPathExpressionException | IOException | SAXException e) {+ throw new RuntimeException(e);+ }+ }+ });+ addSharedExternalDependencies();+ setExternalDependencyXmlProperties();+ }++ private static void traverseIvyXmlResources(Resources ivyXmlResources, Consumer<File> ivyXmlFileConsumer) {@SuppressWarnings("unchecked")Iterator<Resource> iter = (Iterator<Resource>)ivyXmlResources.iterator();while (iter.hasNext()) {@@ -238,15 +288,13 @@ public class GetMavenDependenciesTask extends Task {File ivyXmlFile = ((FileResource)resource).getFile();try {- collectExternalDependenciesFromIvyXmlFile(ivyXmlFile);+ ivyXmlFileConsumer.accept(ivyXmlFile);} catch (BuildException e) {throw e;} catch (Exception e) {throw new BuildException("Exception reading file " + ivyXmlFile.getPath() + ": " + e, e);}}- addSharedExternalDependencies();- setExternalDependencyXmlProperties();}/**@@ -396,7 +444,7 @@ public class GetMavenDependenciesTask extends Task {}}}- String groupId = "org.apache." + artifactId.substring(0, artifactId.indexOf('-'));+ String groupId = ivyModuleInfo.get(artifactId);appendDependencyXml(builder, groupId, artifactId, " ", "${project.version}", false, false, null, exclusions);}}@@ -581,7 +629,7 @@ public class GetMavenDependenciesTask extends Task {continue; // skip external (/(test-)lib/), and non-jar and unwanted (self) internal deps}String artifactId = dependencyToArtifactId(newPropertyKey, dependency);- String groupId = "org.apache." + artifactId.substring(0, artifactId.indexOf('-'));+ String groupId = ivyModuleInfo.get(artifactId);String coordinate = groupId + ':' + artifactId;sortedDeps.add(coordinate);}diff --git a/solr/contrib/extraction/ivy.xml b/solr/contrib/extraction/ivy.xmlindex 5cf19a17f36..42cee8af805 100644--- a/solr/contrib/extraction/ivy.xml+++ b/solr/contrib/extraction/ivy.xml@@ -17,7 +17,7 @@under the License.--><ivy-module version="2.0">- <info organisation="org.apache.solr" module="extraction"/>+ <info organisation="org.apache.solr" module="cell"/><configurations defaultconfmapping="compile->master;test->master"><conf name="compile" transitive="false"/><conf name="test" transitive="false"/>diff --git a/solr/test-framework/ivy.xml b/solr/test-framework/ivy.xmlindex 7ba1b2df6cd..e203b466401 100644--- a/solr/test-framework/ivy.xml+++ b/solr/test-framework/ivy.xml@@ -17,7 +17,7 @@under the License.--><ivy-module version="2.0">- <info organisation="org.apache.solr" module="solr-test-framework"/>+ <info organisation="org.apache.solr" module="test-framework"/><configurations defaultconfmapping="compile->master;junit4-stdalone->master"><conf name="compile" transitive="false" />