Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Export-Package: org.apache.ivy;version="2.0.0",
org.apache.ivy.plugins.pack;version="2.6.0",
org.apache.ivy.plugins.parser;version="2.0.0",
org.apache.ivy.plugins.parser.m2;version="2.0.0",
org.apache.ivy.plugins.parser.xml;version="2.0.0",
org.apache.ivy.plugins.parser.xml;version="2.6.0",
org.apache.ivy.plugins.report;version="2.0.0",
org.apache.ivy.plugins.repository;version="2.0.0",
org.apache.ivy.plugins.repository.file;version="2.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
import org.apache.ivy.util.Message;
import org.apache.ivy.util.XMLHelper;
import org.apache.ivy.util.extendable.ExtendableItemHelper;

import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
Expand Down Expand Up @@ -548,37 +549,30 @@ protected void extendsStarted(Attributes attributes) throws ParseException {
* @param parent
* a given parent module descriptor
*/
protected void mergeWithOtherModuleDescriptor(List<String> extendTypes,
ModuleDescriptor parent) {

protected void mergeWithOtherModuleDescriptor(List<String> extendTypes, ModuleDescriptor parent) {
if (extendTypes.contains("all")) {
mergeAll(parent);
} else {
if (extendTypes.contains("info")) {
mergeInfo(parent);
}

if (extendTypes.contains("configurations")) {
mergeConfigurations(parent);
}

if (extendTypes.contains("dependencies")) {
mergeDependencies(parent.getDependencies());
}

if (extendTypes.contains("description")) {
mergeDescription(parent.getDescription());
}

if (extendTypes.contains("licenses")) {
mergeLicenses(parent.getLicenses());
}

if (extendTypes.contains("excludes")) {
mergeExcludes(parent.getAllExcludeRules());
}
}

mergeNamespaces(parent.getExtraAttributesNamespaces()); // IVY-1658
}

/**
Expand Down Expand Up @@ -722,6 +716,17 @@ public void mergeExcludes(ExcludeRule[] excludeRules) {
}
}

private void mergeNamespaces(Map<String, String> namespaces) {
if (namespaces != null && !namespaces.isEmpty()) {
for (Map.Entry<String, String> entry : namespaces.entrySet()) {
Message.debug("Merging extra attribute namesapce: " + entry);
if (getMd().getExtraAttributesNamespaces().get(entry.getKey()) == null) {
getMd().addExtraAttributeNamespace(entry.getKey(), entry.getValue());
}
}
}
}

/**
* Returns the parent module using the location attribute (for dev purpose).
*
Expand Down Expand Up @@ -1455,5 +1460,4 @@ protected URL getSchemaURL() {
public String toString() {
return "ivy parser";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.apache.ivy.util.Message;
import org.apache.ivy.util.XMLHelper;
import org.apache.ivy.util.extendable.ExtendableItemHelper;

import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
Expand Down Expand Up @@ -409,13 +410,22 @@ public void startElement(String uri, String localName, String qName, Attributes

// copy
write("<" + qName);
for (int i = 0; i < attributes.getLength(); i++) {
write(" " + attributes.getQName(i) + "=\""
+ substitute(settings, attributes.getValue(i)) + "\"");
if (options.isMerge() && path.equals("ivy-module")) {
for (int i = 0, n = attributes.getLength(); i < n; i += 1) {
if (attributes.getQName(i).startsWith("xmlns:")) continue;
write(" " + attributes.getQName(i) + "=\"" + substitute(settings, attributes.getValue(i)) + "\"");
}
Map<String, String> namespaces = options.getMergedDescriptor().getExtraAttributesNamespaces();
for (Map.Entry<String, String> namespace : namespaces.entrySet()) {
write(" xmlns:" + namespace.getKey() + "=\"" + substitute(settings, namespace.getValue()) + "\"");
}
} else {
for (int i = 0, n = attributes.getLength(); i < n; i += 1) {
write(" " + attributes.getQName(i) + "=\"" + substitute(settings, attributes.getValue(i)) + "\"");
}
}
}
justOpen = qName;
// indent.append("\t");
}

private void startExtends(Attributes attributes) {
Expand Down
145 changes: 99 additions & 46 deletions test/java/org/apache/ivy/core/deliver/DeliverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,67 @@
*/
package org.apache.ivy.core.deliver;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import org.apache.ivy.TestHelper;
import org.apache.ivy.ant.IvyDeliver;
import org.apache.ivy.ant.IvyResolve;
import org.apache.ivy.util.FileUtil;

import org.apache.commons.io.FileUtils;
import org.apache.tools.ant.Project;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.URI;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class DeliverTest {
private File cache;

private File cacheDir;

private File deliverDir;

private IvyDeliver ivyDeliver;

private void createCache() {
cacheDir.mkdirs();
}

private void resolve(File ivyFile) {
IvyResolve ivyResolve = new IvyResolve();
ivyResolve.setProject(ivyDeliver.getProject());
ivyResolve.setFile(ivyFile);
ivyResolve.doExecute();
}

private String readFile(String fileName) throws IOException {
StringBuilder retval = new StringBuilder();
File file = new File(fileName);
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
String line = null;
while ((line = reader.readLine()) != null) {
retval.append(line).append("\n");
}
}
return retval.toString();
}

private File writeFile(String fileText) throws IOException {
File file = File.createTempFile("ivy", ".xml");
file.deleteOnExit();
FileUtils.write(file, fileText, "UTF-8");
return file;
}

@Before
public void setUp() {
cache = new File("build/cache");
System.setProperty("ivy.cache.dir", cache.getAbsolutePath());
cacheDir = new File("build/cache");
System.setProperty("ivy.cache.dir", cacheDir.getAbsolutePath());
createCache();

deliverDir = new File("build/test/deliver");
Expand All @@ -56,61 +88,82 @@ public void setUp() {

ivyDeliver = new IvyDeliver();
ivyDeliver.setProject(project);
ivyDeliver.setDeliverpattern(deliverDir.getAbsolutePath()
+ "/[type]s/[artifact]-[revision](-[classifier]).[ext]");
ivyDeliver.setDeliverpattern(deliverDir.getAbsolutePath() + "/[type]s/[artifact]-[revision](-[classifier]).[ext]");
}

@After
public void tearDown() {
FileUtil.forceDelete(cache);
FileUtil.forceDelete(cacheDir);
FileUtil.forceDelete(deliverDir);
}

private void createCache() {
cache.mkdirs();
}

/**
* Test case for IVY-1111.
*
* @throws Exception if something goes wrong
* @see <a href="https://issues.apache.org/jira/browse/IVY-1111">IVY-1111</a>
* Test case for <a href="https://issues.apache.org/jira/browse/IVY-1111">IVY-1111</a>.
*/
@Test
public void testIVY1111() throws Exception {
Project project = ivyDeliver.getProject();
project.setProperty("ivy.settings.file", "test/repositories/IVY-1111/ivysettings.xml");
File ivyFile = new File(new URI(DeliverTest.class.getResource("ivy-1111.xml").toString()));
public void testDeliver1111() throws Exception {
ivyDeliver.getProject().setProperty("ivy.settings.file", "test/repositories/IVY-1111/ivysettings.xml");

String ivyFile
= "<ivy-module version='1.0' xmlns:e='http://ant.apache.org/ivy/extra'>\n"
+ " <info organisation='apache' module='IVY-1111' revision='1.0' e:att='att'/>\n"
+ " <dependencies>\n"
+ " <dependency org='test' name='a' rev='latest.integration'/>\n"
+ " <dependency org='test' name='b' rev='latest.integration' e:att='att'/>\n"
+ " <dependency org='junit' name='junit' rev='latest.integration'/>\n"
+ " </dependencies>\n"
+ "</ivy-module>\n";

resolve(ivyFile);
resolve(writeFile(ivyFile));

ivyDeliver.setReplacedynamicrev(true);
ivyDeliver.doExecute();

String deliverContent = readFile(deliverDir.getAbsolutePath() + "/ivys/ivy-1.0.xml");
assertFalse(deliverContent.contains("rev=\"latest.integration\""));
assertTrue(deliverContent.contains("name=\"b\" rev=\"1.5\""));
ivyFile = readFile(deliverDir.getAbsolutePath() + "/ivys/ivy-1.0.xml");
assertTrue(ivyFile.contains("org=\"test\" name=\"a\" rev=\"1\" revConstraint=\"latest.integration\""));
assertTrue(ivyFile.contains("org=\"test\" name=\"b\" rev=\"1.5\" revConstraint=\"latest.integration\" e:att=\"att\""));
assertTrue(ivyFile.contains("org=\"junit\" name=\"junit\" rev=\"4.4\" revConstraint=\"latest.integration\""));
}

private void resolve(File ivyFile) {
IvyResolve ivyResolve = new IvyResolve();
ivyResolve.setProject(ivyDeliver.getProject());
ivyResolve.setFile(ivyFile);
ivyResolve.doExecute();
}

private String readFile(String fileName) throws IOException {
StringBuilder retval = new StringBuilder();
/**
* Test case for <a href="https://issues.apache.org/jira/browse/IVY-1658">IVY-1658</a>.
*/
@Test
public void testDeliver1658() throws Exception {
String ivyFile
= "<ivy-module version='2.0'\n"
+ " xmlns:m='http://ant.apache.org/ivy/maven'\n"
+ " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n"
+ " xsi:noNamespaceSchemaLocation='http://ant.apache.org/ivy/schemas/ivy.xsd'>\n"
+ " <info module='xxx' organisation='zzz'/>\n"
+ " <dependencies>\n"
+ " <dependency name='groovy' org='org.codehaus.groovy' rev='3.0.25' transitive='false'>\n"
+ " <artifact name='groovy' m:classifier='indy'/>\n"
+ " </dependency>\n"
+ " </dependencies>\n"
+ "</ivy-module>\n";

ivyFile
= "<ivy-module version='2.0'\n"
+ " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n"
+ " xsi:noNamespaceSchemaLocation='http://ant.apache.org/ivy/schemas/ivy.xsd'>\n"
+ " <info module='yyy' organisation='zzz' revision='1.0'>\n"
+ " <extends module='xxx' organisation='zzz' extendType='dependencies'\n"
+ " location='" + writeFile(ivyFile).getName() + "' revision='latest'/>\n"
+ " </info>\n"
+ " <dependencies>\n"
+ " </dependencies>\n"
+ "</ivy-module>\n";

resolve(writeFile(ivyFile));

File ivyFile = new File(fileName);
BufferedReader reader = new BufferedReader(new FileReader(ivyFile));
ivyDeliver.doExecute();

String line = null;
while ((line = reader.readLine()) != null) {
retval.append(line).append("\n");
}
ivyFile = readFile(deliverDir.getAbsolutePath() + "/ivys/ivy-1.0.xml");

reader.close();
return retval.toString();
assertTrue(ivyFile.contains(" version=\"2.0\""));
assertTrue(ivyFile.contains(" xmlns:m=\"http://ant.apache.org/ivy/maven\""));
assertTrue(ivyFile.contains(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""));
assertTrue(ivyFile.contains(" xsi:noNamespaceSchemaLocation=\"http://ant.apache.org/ivy/schemas/ivy.xsd\""));
}
}
26 changes: 0 additions & 26 deletions test/java/org/apache/ivy/core/deliver/ivy-1111.xml

This file was deleted.