IVY-1615 implement retrieval of ivysettings from url in standalone.
Closes #91 pull request at github.com/apache/ant-ivy repo
diff --git a/asciidoc/release-notes.adoc b/asciidoc/release-notes.adoc
index aef7b18..493b9db 100644
--- a/asciidoc/release-notes.adoc
+++ b/asciidoc/release-notes.adoc
@@ -50,7 +50,7 @@
- FIX: ConcurrentModificationException in MessageLoggerHelper.sumupProblems (jira:IVY-1628[])
-- IMPROVEMENT:
+- IMPROVEMENT: Ivy command now accepts a URL for the -settings option (jira:IVY-1615[])
- NEW:
@@ -219,3 +219,4 @@
* Jaroslaw Wypychowski
* Sven Zethelius
* Aleksey Zhukov
+* Jason A. Guild
\ No newline at end of file
diff --git a/src/java/org/apache/ivy/Main.java b/src/java/org/apache/ivy/Main.java
index dff227f..b4f1ed4 100644
--- a/src/java/org/apache/ivy/Main.java
+++ b/src/java/org/apache/ivy/Main.java
@@ -24,6 +24,8 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
@@ -76,8 +78,8 @@
return new CommandLineParser()
.addCategory("settings options")
.addOption(
- new OptionBuilder("settings").arg("settingsfile")
- .description("use given file for settings").create())
+ new OptionBuilder("settings").arg("settingsfile|url")
+ .description("use given file or URL for settings").create())
.addOption(
new OptionBuilder("properties").arg("propertiesfile")
.description("use given file for properties not specified in settings").create())
@@ -515,17 +517,39 @@
if ("".equals(settingsPath)) {
ivy.configureDefault();
} else {
- File conffile = new File(settingsPath);
- if (!conffile.exists()) {
- error("ivy configuration file not found: " + conffile);
- } else if (conffile.isDirectory()) {
- error("ivy configuration file is not a file: " + conffile);
+ final URI confUri = getSettingsURI(settingsPath);
+ if ("file".equals(confUri.getScheme())) {
+ File conffile = new File(confUri);
+ if (!conffile.exists()) {
+ throw new IOException("ivy configuration file not found: " + conffile);
+ } else if (conffile.isDirectory()) {
+ throw new IOException("ivy configuration file is not a file: " + conffile);
+ }
+ ivy.configure(conffile);
+ } else {
+ try {
+ ivy.configure(confUri.toURL());
+ } catch (IOException ioe) {
+ throw new IOException("ivy configuration failed to load from: " + settingsPath, ioe);
+ }
}
- ivy.configure(conffile);
}
return settings;
}
+ private static URI getSettingsURI(String settingsPath) {
+ URI settingsUri;
+ try {
+ settingsUri = new URI(settingsPath);
+ if (settingsUri.getScheme() == null) {
+ settingsUri = new File(settingsPath).toURI();
+ }
+ } catch (URISyntaxException badUriEx) {
+ return new File(settingsPath).toURI();
+ }
+ return settingsUri;
+ }
+
private static void initMessage(CommandLine line, Ivy ivy) {
if (line.hasOption("debug")) {
ivy.getLoggerEngine().pushLogger(new DefaultMessageLogger(Message.MSG_DEBUG));
diff --git a/test/java/org/apache/ivy/MainTest.java b/test/java/org/apache/ivy/MainTest.java
index f890cb4..994afb2 100644
--- a/test/java/org/apache/ivy/MainTest.java
+++ b/test/java/org/apache/ivy/MainTest.java
@@ -29,6 +29,7 @@
import org.junit.rules.TemporaryFolder;
import java.io.File;
+import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -206,6 +207,18 @@
assertTrue("pom file hasn't been generated at " + pomFilePath, new File(pomFilePath).isFile());
}
+ /**
+ * Tests that the ivy command can use a URL for the {@code -settings} option. See IVY-1615
+ */
+ @Test
+ public void testSettingsURL() throws Exception {
+ final URL settingsURL = new File("test/repositories/ivysettings.xml").toURI().toURL();
+ run(new String[] {"-settings", settingsURL.toString(), "-ivy",
+ "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml"});
+
+ assertTrue(new File("build/cache/org1/mod1.2/ivy-2.0.xml").exists());
+ }
+
private void run(String[] args) throws Exception {
Main.run(Main.getParser(), args);
}