IVY-1615 implement retrieval of ivysettings from url in standalone.

Closes #91 pull request at github.com/apache/ant-ivy repo
This commit is contained in:
Jason Guild 2019-11-12 19:07:42 -09:00 committed by Jaikiran Pai
parent ac9af265f9
commit 424fa89419
3 changed files with 47 additions and 9 deletions

View File

@ -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

View File

@ -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));

View File

@ -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);
}