This is an automated email from the ASF dual-hosted git repository. jaikiran pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/ant-ivy.git
The following commit(s) were added to refs/heads/master by this push: new 424fa89 IVY-1615 implement retrieval of ivysettings from url in standalone. 424fa89 is described below commit 424fa89419147f50a41b4bdc665d8ea92b5da516 Author: Jason Guild <jagu...@gmail.com> AuthorDate: Tue Nov 12 19:07:42 2019 -0900 IVY-1615 implement retrieval of ivysettings from url in standalone. Closes #91 pull request at github.com/apache/ant-ivy repo --- asciidoc/release-notes.adoc | 3 ++- src/java/org/apache/ivy/Main.java | 40 +++++++++++++++++++++++++++------- test/java/org/apache/ivy/MainTest.java | 13 +++++++++++ 3 files changed, 47 insertions(+), 9 deletions(-) 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 @@ For details about the following changes, check our JIRA install at link:https:// - 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 @@ Here is the list of people who have contributed source code and documentation up * 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.io.PrintWriter; 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 @@ public final class Main { 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 @@ public final class Main { 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.ExpectedException; 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 @@ public class MainTest { 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); }