Author: maartenc
Date: Fri Jul 16 06:18:53 2010
New Revision: 964690
URL: http://svn.apache.org/viewvc?rev=964690&view=rev
Log:
IMPROVEMENT: ivy:makepom now accepts a list of configurations to include
(IVY-1005) (thanks to Jesper Pedersen)
Added:
ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-compile-dependencies.xml
(with props)
Modified:
ant/ivy/core/trunk/CHANGES.txt
ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyMakePom.java
ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java
ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriterTest.java
Modified: ant/ivy/core/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/CHANGES.txt?rev=964690&r1=964689&r2=964690&view=diff
==============================================================================
--- ant/ivy/core/trunk/CHANGES.txt (original)
+++ ant/ivy/core/trunk/CHANGES.txt Fri Jul 16 06:18:53 2010
@@ -79,6 +79,7 @@ for detailed view of each issue, please
Mathias Muller
Randy Nott
Peter Oxenham
+ Jesper Pedersen
Emmanuel Pellereau
Roshan Punnoose
Jean-Baptiste Quenot
@@ -108,6 +109,8 @@ for detailed view of each issue, please
trunk
=====================================
+- IMPROVEMENT: ivy:makepom now accepts a list of configurations to include
(IVY-1005) (thanks to Jesper Pedersen)
+
- FIX: Ivy info/extends/extendsType attribute is misspelled by
XmlModuleDescriptorWriter (IVY-1203) (thanks to Jason Trump)
2.2.0-rc1
Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyMakePom.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyMakePom.java?rev=964690&r1=964689&r2=964690&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyMakePom.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyMakePom.java Fri Jul 16
06:18:53 2010
@@ -59,6 +59,8 @@ public class IvyMakePom extends IvyTask
private File headerFile = null;
+ private String conf;
+
private File ivyFile = null;
private Collection mappings = new ArrayList();
@@ -87,6 +89,14 @@ public class IvyMakePom extends IvyTask
this.headerFile = headerFile;
}
+ public String getConf() {
+ return conf;
+ }
+
+ public void setConf(String conf) {
+ this.conf = conf;
+ }
+
public Mapping createMapping() {
Mapping mapping = new Mapping();
this.mappings.add(mapping);
@@ -103,7 +113,7 @@ public class IvyMakePom extends IvyTask
}
ModuleDescriptor md =
XmlModuleDescriptorParser.getInstance().parseDescriptor(
getSettings(), ivyFile.toURI().toURL(), false);
- PomModuleDescriptorWriter.write(md,
+ PomModuleDescriptorWriter.write(md, splitConfs(conf),
headerFile == null ? null :
FileUtil.readEntirely(getHeaderFile()),
mappings.isEmpty()
? PomModuleDescriptorWriter.DEFAULT_MAPPING
Modified:
ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java?rev=964690&r1=964689&r2=964690&view=diff
==============================================================================
---
ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java
(original)
+++
ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java
Fri Jul 16 06:18:53 2010
@@ -22,14 +22,20 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.apache.ivy.Ivy;
import org.apache.ivy.core.module.descriptor.Artifact;
import org.apache.ivy.core.module.descriptor.DependencyDescriptor;
import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
import org.apache.ivy.core.module.id.ModuleRevisionId;
+import org.apache.ivy.util.ConfigurationUtils;
import org.apache.ivy.util.StringUtils;
public final class PomModuleDescriptorWriter {
@@ -42,12 +48,7 @@ public final class PomModuleDescriptorWr
private PomModuleDescriptorWriter() {
}
- public static void write(ModuleDescriptor md,
- ConfigurationScopeMapping mapping, File output) throws IOException
{
- write(md, null, mapping, output);
- }
-
- public static void write(ModuleDescriptor md,
+ public static void write(ModuleDescriptor md, String[] confs,
String licenseHeader, ConfigurationScopeMapping mapping, File
output)
throws IOException {
if (output.getParentFile() != null) {
@@ -74,7 +75,7 @@ public final class PomModuleDescriptorWr
+ "http://maven.apache.org/maven-v4_0_0.xsd\">\n");
out.println(" <modelVersion>4.0.0</modelVersion>");
printModuleId(md, out);
- printDependencies(md, mapping, out);
+ printDependencies(md, confs, mapping, out);
out.println("</project>");
} finally {
out.close();
@@ -121,8 +122,8 @@ public final class PomModuleDescriptorWr
}
private static void printDependencies(
- ModuleDescriptor md, ConfigurationScopeMapping mapping,
PrintWriter out) {
- DependencyDescriptor[] dds = md.getDependencies();
+ ModuleDescriptor md, String[] confs, ConfigurationScopeMapping
mapping, PrintWriter out) {
+ DependencyDescriptor[] dds = getDependencies(md, confs);
if (dds.length > 0) {
out.println(" <dependencies>");
for (int i = 0; i < dds.length; i++) {
@@ -144,6 +145,21 @@ public final class PomModuleDescriptorWr
}
}
+ private static DependencyDescriptor[] getDependencies(ModuleDescriptor md,
String[] confs) {
+ confs = ConfigurationUtils.replaceWildcards(confs, md);
+
+ List result = new ArrayList();
+ DependencyDescriptor[] dds = md.getDependencies();
+ for (int i = 0; i < dds.length; i++) {
+ String[] depConfs = dds[i].getDependencyConfigurations(confs);
+ if ((depConfs != null) && (depConfs.length > 0)) {
+ result.add(dds[i]);
+ }
+ }
+
+ return (DependencyDescriptor[]) result.toArray(new
DependencyDescriptor[result.size()]);
+ }
+
public static final ConfigurationScopeMapping DEFAULT_MAPPING
= new ConfigurationScopeMapping(new HashMap() {
{
Modified:
ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriterTest.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriterTest.java?rev=964690&r1=964689&r2=964690&view=diff
==============================================================================
---
ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriterTest.java
(original)
+++
ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriterTest.java
Fri Jul 16 06:18:53 2010
@@ -44,7 +44,7 @@ public class PomModuleDescriptorWriterTe
public void testSimple() throws Exception {
ModuleDescriptor md =
PomModuleDescriptorParser.getInstance().parseDescriptor(
new IvySettings(), getClass().getResource("test-simple.pom"),
false);
- PomModuleDescriptorWriter.write(md, LICENSE,
PomModuleDescriptorWriter.DEFAULT_MAPPING, _dest);
+ PomModuleDescriptorWriter.write(md, null, LICENSE,
PomModuleDescriptorWriter.DEFAULT_MAPPING, _dest);
assertTrue(_dest.exists());
String wrote = FileUtil.readEntirely(new BufferedReader(new
FileReader(_dest))).replaceAll(
@@ -57,7 +57,7 @@ public class PomModuleDescriptorWriterTe
public void testSimpleDependencies() throws Exception {
ModuleDescriptor md =
PomModuleDescriptorParser.getInstance().parseDescriptor(
new IvySettings(),
getClass().getResource("test-dependencies.pom"), false);
- PomModuleDescriptorWriter.write(md, LICENSE,
PomModuleDescriptorWriter.DEFAULT_MAPPING, _dest);
+ PomModuleDescriptorWriter.write(md, null, LICENSE,
PomModuleDescriptorWriter.DEFAULT_MAPPING, _dest);
assertTrue(_dest.exists());
String wrote = FileUtil.readEntirely(new BufferedReader(new
FileReader(_dest))).replaceAll(
@@ -70,7 +70,7 @@ public class PomModuleDescriptorWriterTe
public void testDependenciesWithScope() throws Exception {
ModuleDescriptor md =
PomModuleDescriptorParser.getInstance().parseDescriptor(
new IvySettings(),
getClass().getResource("test-dependencies-with-scope.pom"), false);
- PomModuleDescriptorWriter.write(md, LICENSE,
PomModuleDescriptorWriter.DEFAULT_MAPPING, _dest);
+ PomModuleDescriptorWriter.write(md, null, LICENSE,
PomModuleDescriptorWriter.DEFAULT_MAPPING, _dest);
assertTrue(_dest.exists());
String wrote = FileUtil.readEntirely(new BufferedReader(new
FileReader(_dest))).replaceAll(
@@ -83,7 +83,7 @@ public class PomModuleDescriptorWriterTe
public void testOptional() throws Exception {
ModuleDescriptor md =
PomModuleDescriptorParser.getInstance().parseDescriptor(
new IvySettings(), getClass().getResource("test-optional.pom"),
false);
- PomModuleDescriptorWriter.write(md, LICENSE,
PomModuleDescriptorWriter.DEFAULT_MAPPING, _dest);
+ PomModuleDescriptorWriter.write(md, null, LICENSE,
PomModuleDescriptorWriter.DEFAULT_MAPPING, _dest);
assertTrue(_dest.exists());
String wrote = FileUtil.readEntirely(new BufferedReader(new
FileReader(_dest))).replaceAll(
@@ -96,7 +96,7 @@ public class PomModuleDescriptorWriterTe
public void testPackaging() throws Exception {
ModuleDescriptor md =
PomModuleDescriptorParser.getInstance().parseDescriptor(
new IvySettings(), getClass().getResource("test-packaging.pom"),
false);
- PomModuleDescriptorWriter.write(md, LICENSE,
PomModuleDescriptorWriter.DEFAULT_MAPPING, _dest);
+ PomModuleDescriptorWriter.write(md, null, LICENSE,
PomModuleDescriptorWriter.DEFAULT_MAPPING, _dest);
assertTrue(_dest.exists());
String wrote = FileUtil.readEntirely(new BufferedReader(new
FileReader(_dest))).replaceAll(
@@ -106,6 +106,58 @@ public class PomModuleDescriptorWriterTe
assertEquals(expected, wrote);
}
+ public void testWriteCompileConfigurationOnly() throws Exception {
+ ModuleDescriptor md =
PomModuleDescriptorParser.getInstance().parseDescriptor(
+ new IvySettings(),
getClass().getResource("test-dependencies-with-scope.pom"), false);
+ PomModuleDescriptorWriter.write(md, new String[] {"compile"}, LICENSE,
PomModuleDescriptorWriter.DEFAULT_MAPPING, _dest);
+ assertTrue(_dest.exists());
+
+ String wrote = FileUtil.readEntirely(new BufferedReader(new
FileReader(_dest))).replaceAll(
+ "\r\n", "\n").replace('\r', '\n');
+ String expected = readEntirely("test-write-compile-dependencies.xml")
+ .replaceAll("\r\n", "\n").replace('\r', '\n');
+ assertEquals(expected, wrote);
+ }
+
+ public void testWriteRuntimeConfigurationOnly() throws Exception {
+ ModuleDescriptor md =
PomModuleDescriptorParser.getInstance().parseDescriptor(
+ new IvySettings(),
getClass().getResource("test-dependencies-with-scope.pom"), false);
+ PomModuleDescriptorWriter.write(md, new String[] {"runtime"}, LICENSE,
PomModuleDescriptorWriter.DEFAULT_MAPPING, _dest);
+ assertTrue(_dest.exists());
+
+ String wrote = FileUtil.readEntirely(new BufferedReader(new
FileReader(_dest))).replaceAll(
+ "\r\n", "\n").replace('\r', '\n');
+ String expected =
readEntirely("test-write-dependencies-with-scope.xml")
+ .replaceAll("\r\n", "\n").replace('\r', '\n');
+ assertEquals(expected, wrote);
+ }
+
+ public void testWriteAllConfiguration() throws Exception {
+ ModuleDescriptor md =
PomModuleDescriptorParser.getInstance().parseDescriptor(
+ new IvySettings(),
getClass().getResource("test-dependencies-with-scope.pom"), false);
+ PomModuleDescriptorWriter.write(md, new String[] {"*"}, LICENSE,
PomModuleDescriptorWriter.DEFAULT_MAPPING, _dest);
+ assertTrue(_dest.exists());
+
+ String wrote = FileUtil.readEntirely(new BufferedReader(new
FileReader(_dest))).replaceAll(
+ "\r\n", "\n").replace('\r', '\n');
+ String expected =
readEntirely("test-write-dependencies-with-scope.xml")
+ .replaceAll("\r\n", "\n").replace('\r', '\n');
+ assertEquals(expected, wrote);
+ }
+
+ public void testWriteAllExceptRuntimeConfiguration() throws Exception {
+ ModuleDescriptor md =
PomModuleDescriptorParser.getInstance().parseDescriptor(
+ new IvySettings(),
getClass().getResource("test-dependencies-with-scope.pom"), false);
+ PomModuleDescriptorWriter.write(md, new String[] {"*", "!runtime"},
LICENSE, PomModuleDescriptorWriter.DEFAULT_MAPPING, _dest);
+ assertTrue(_dest.exists());
+
+ String wrote = FileUtil.readEntirely(new BufferedReader(new
FileReader(_dest))).replaceAll(
+ "\r\n", "\n").replace('\r', '\n');
+ String expected = readEntirely("test-write-compile-dependencies.xml")
+ .replaceAll("\r\n", "\n").replace('\r', '\n');
+ assertEquals(expected, wrote);
+ }
+
private String readEntirely(String resource) throws IOException {
return FileUtil.readEntirely(new BufferedReader(new InputStreamReader(
PomModuleDescriptorWriterTest.class.getResource(resource).openStream())));
Added:
ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-compile-dependencies.xml
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-compile-dependencies.xml?rev=964690&view=auto
==============================================================================
---
ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-compile-dependencies.xml
(added)
+++
ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-compile-dependencies.xml
Fri Jul 16 06:18:53 2010
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<!--
+ Apache Maven 2 POM generated by Apache Ivy
+ http://ant.apache.org/ivy/
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache</groupId>
+ <artifactId>test</artifactId>
+ <packaging>jar</packaging>
+ <version>1.0</version>
+ <url>http://ant.apache.org/ivy</url>
+ <dependencies>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.0.4</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>cglib</groupId>
+ <artifactId>cglib</artifactId>
+ <version>2.0.2</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+</project>
Propchange:
ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/m2/test-write-compile-dependencies.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain