IMPROVEMENT: undeprecate configure task (IVY-849)

git-svn-id: https://svn.apache.org/repos/asf/ant/ivy/core/trunk@675931 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Maarten Coene 2008-07-11 12:24:00 +00:00
parent 92107a9e24
commit ab72c0dcde
9 changed files with 194 additions and 104 deletions

View File

@ -77,6 +77,7 @@ for detailed view of each issue, please consult http://issues.apache.org/jira/br
- NEW: Add transitive dependency version and branch override mechanism (IVY-784)
- NEW: Add new packager resolver (IVY-829) (thanks to Archie Cobbs)
- IMPROVEMENT: undeprecate configure task (IVY-849)
- IMPROVEMENT: Detect missing artifacts on publish asap (IVY-862)
- IMPROVEMENT: Allow to set the branch at deliver/publish time (IVY-859)
- IMPROVEMENT: Add defaultconf in publications tag of ivy file (IVY-801)

View File

@ -46,7 +46,7 @@
</classpath>
</taskdef>
<ivy:settings id="ivy.instance" override="true"/>
<ivy:configure id="ivy.instance" override="true" />
</target>
<target name="install" depends="init-ivy-home, jar"
@ -90,7 +90,7 @@
<fileset dir="${lib.dir}">
<include name="*.jar" />
<exclude name="ant.jar" />
<exclude name="ant-*.jar" />
<exclude name="ant-launcher.jar" />
</fileset>
<pathelement location="${core.classes.build.dir}" />
<pathelement location="${ant.classes.build.dir}" />

View File

@ -23,8 +23,6 @@ import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.ParseException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Properties;
import org.apache.ivy.Ivy;
@ -37,10 +35,10 @@ import org.apache.ivy.util.url.URLHandlerDispatcher;
import org.apache.ivy.util.url.URLHandlerRegistry;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.Property;
import org.apache.tools.ant.types.DataType;
public class IvyAntSettings extends Task {
public class IvyAntSettings extends DataType {
public static class Credentials {
private String realm;
@ -84,24 +82,6 @@ public class IvyAntSettings extends Task {
}
}
/**
* Use to override a previous definition of settings with the same id
*/
public static final String OVERRIDE_TRUE = "true";
/**
* Use to avoid overriding a previous definition of settings with the same id
*/
public static final String OVERRIDE_FALSE = "false";
/**
* Use to raise an error if attempting to override a previous definition of settings with the
* same id
*/
public static final String OVERRIDE_NOT_ALLOWED = "notallowed";
private static final Collection OVERRIDE_VALUES = Arrays.asList(new String[] {
OVERRIDE_TRUE, OVERRIDE_FALSE, OVERRIDE_NOT_ALLOWED
});
private Ivy ivyEngine = null;
private File file = null;
@ -117,8 +97,8 @@ public class IvyAntSettings extends Task {
private String passwd = null;
private String id = "ivy.instance";
private String override = OVERRIDE_NOT_ALLOWED;
private boolean autoRegistered = false;
/**
* Returns the default ivy settings of this classloader. If it doesn't exist yet, a new one is
@ -144,10 +124,12 @@ public class IvyAntSettings extends Task {
if (defaultInstanceObj == null) {
project.log("No ivy:settings found for the default reference 'ivy.instance'. "
+ "A default instance will be used", Project.MSG_INFO);
IvyAntSettings defaultInstance = new IvyAntSettings();
defaultInstance.setProject(project);
defaultInstance.perform();
return defaultInstance;
IvyAntSettings settings = new IvyAntSettings();
settings.setProject(project);
project.addReference("ivy.instance", settings);
settings.createIvyEngine();
return settings;
} else {
return (IvyAntSettings) defaultInstanceObj;
}
@ -193,7 +175,16 @@ public class IvyAntSettings extends Task {
userName = format(aUserName);
}
public void setProject(Project p) {
super.setProject(p);
if ("ivy.instance".equals(id) && getProject().getReference(id) == null) {
// register ourselfs as default settings, just in case the id attribute is not set
getProject().addReference("ivy.instance", this);
autoRegistered = true;
}
}
private static String format(String str) {
return str == null ? str : (str.trim().length() == 0 ? null : str.trim());
}
@ -211,19 +202,15 @@ public class IvyAntSettings extends Task {
this.url = new URL(confUrl);
}
public void setOverride(String override) {
if (!OVERRIDE_VALUES.contains(override)) {
throw new IllegalArgumentException("invalid override value '" + override + "'. "
+ "Valid values are " + OVERRIDE_VALUES);
}
this.override = override;
}
/*
* This is usually not necessary to define a reference in Ant, but it's the only
* way to know the id of the settings, which we use to set ant properties.
*/
public void setId(String id) {
if (autoRegistered && getProject().getReference(this.id) == this) {
getProject().getReferences().remove(this.id);
autoRegistered = false;
}
this.id = id;
}
@ -231,53 +218,28 @@ public class IvyAntSettings extends Task {
return id;
}
/*
* public void execute() throws BuildException {
* ensureMessageInitialised();
* if (getId()==null) {
* log("No id specified for the ivy:settings, set the instance as the default one",
* Project.MSG_DEBUG); getProject().addReference("ivy.instance", this); } else {
* getProject().addReference(id, this); } }
*/
/**
* Return the configured Ivy instance.
* @return Returns the configured Ivy instance.
*/
public Ivy getConfiguredIvyInstance() {
if (ivyEngine == null) {
perform();
createIvyEngine();
}
return ivyEngine;
}
public void execute() throws BuildException {
if (!OVERRIDE_TRUE.equals(override)) {
Object otherRef = getProject().getReference(id);
if ((otherRef != null) && (otherRef != this)) {
if (OVERRIDE_FALSE.equals(override)) {
verbose("a settings definition is already available for " + id + ": skipping");
return;
} else {
// OVERRIDE_NOT_ALLOWED
throw new BuildException(
"overriding a previous definition of ivy:settings with the id '" + id + "'"
+ " is not allowed when using override='" + OVERRIDE_NOT_ALLOWED + "'.");
}
}
}
getProject().addReference(id, this);
void createIvyEngine() {
Property prop = new Property() {
public void execute() throws BuildException {
addProperties(getDefaultProperties());
}
};
prop.setProject(getProject());
prop.init();
prop.execute();
createIvyEngine();
}
private void createIvyEngine() {
IvyAntVariableContainer ivyAntVariableContainer = new IvyAntVariableContainer(getProject());
IvySettings settings = new IvySettings(ivyAntVariableContainer);
@ -384,10 +346,6 @@ public class IvyAntSettings extends Task {
log(msg, Project.MSG_INFO);
}
private void warn(String msg) {
log(msg, Project.MSG_WARN);
}
private void configureURLHandler() {
// TODO : the credentialStore should also be scoped
CredentialsStore.INSTANCE.addCredentials(getRealm(), getHost(), getUsername(), getPasswd());

View File

@ -17,23 +17,133 @@
*/
package org.apache.ivy.ant;
import org.apache.ivy.Ivy;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.Collection;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
/**
* Configure Ivy with an ivysettings.xml file
*
* @deprecated Use the IvyAntSettings instead.
*/
public class IvyConfigure extends IvyAntSettings {
public void execute() throws BuildException {
log("ivy:configure is deprecated, please use the data type ivy:settings instead",
Project.MSG_WARN);
super.execute();
*/
public class IvyConfigure extends Task {
/**
* Use to override a previous definition of settings with the same id
*/
public static final String OVERRIDE_TRUE = "true";
/**
* Use to avoid overriding a previous definition of settings with the same id
*/
public static final String OVERRIDE_FALSE = "false";
/**
* Use to raise an error if attempting to override a previous definition of settings with the
* same id
*/
public static final String OVERRIDE_NOT_ALLOWED = "notallowed";
private static final Collection OVERRIDE_VALUES = Arrays.asList(new String[] {
OVERRIDE_TRUE, OVERRIDE_FALSE, OVERRIDE_NOT_ALLOWED
});
private String override = OVERRIDE_NOT_ALLOWED;
private IvyAntSettings settings = new IvyAntSettings();
public void setSettingsId(String settingsId) {
settings.setId(settingsId);
}
public String getSettingsId() {
return settings.getId();
}
public void setOverride(String override) {
if (!OVERRIDE_VALUES.contains(override)) {
throw new IllegalArgumentException("invalid override value '" + override + "'. "
+ "Valid values are " + OVERRIDE_VALUES);
}
this.override = override;
}
public String getOverride() {
return override;
}
public File getFile() {
return settings.getFile();
}
public Ivy getIvyInstance() {
return getConfiguredIvyInstance();
public void setFile(File file) {
settings.setFile(file);
}
public URL getUrl() {
return settings.getUrl();
}
public void setUrl(String url) throws MalformedURLException {
settings.setUrl(url);
}
public String getRealm() {
return settings.getRealm();
}
public void setRealm(String realm) {
settings.setRealm(realm);
}
public String getHost() {
return settings.getHost();
}
public void setHost(String host) {
settings.setHost(host);
}
public String getUserName() {
return settings.getUsername();
}
public void setUserName(String userName) {
settings.setUsername(userName);
}
public String getPasswd() {
return settings.getPasswd();
}
public void setPasswd(String passwd) {
settings.setPasswd(passwd);
}
public void execute() throws BuildException {
String settingsId = settings.getId();
Object otherRef = getProject().getReference(settingsId);
if ((otherRef != null) && OVERRIDE_NOT_ALLOWED.equals(override)) {
throw new BuildException(
"Overriding a previous definition of ivy:settings with the id '"
+ settingsId + "' is not allowed when using override='"
+ OVERRIDE_NOT_ALLOWED + "'.");
}
if ((otherRef != null) && OVERRIDE_FALSE.equals(override)) {
verbose("A settings definition is already available for " + settingsId + ": skipping");
return;
}
settings.setProject(getProject());
getProject().addReference(settingsId, settings);
settings.createIvyEngine();
}
private void verbose(String msg) {
log(msg, Project.MSG_VERBOSE);
}
}

View File

@ -26,17 +26,17 @@
</target>
<target name="testOverrideNotSpecified">
<ivy:settings id="test1" file="test/repositories/ivysettings.xml" />
<ivy:configure settingsId="test1" file="test/repositories/ivysettings.xml" />
<ivy:resolve settingsRef="test1" file="test/java/org/apache/ivy/ant/ivy-simple.xml" />
</target>
<target name="testOverrideSetToFalse">
<ivy:settings id="test2" file="test/repositories/ivysettings.xml" override="false" />
<ivy:configure settingsId="test2" file="test/repositories/ivysettings.xml" override="false" />
<ivy:resolve settingsRef="test2" file="test/java/org/apache/ivy/ant/ivy-simple.xml" />
</target>
<target name="testUnnecessaryDefaultIvyInstance">
<ivy:settings id="testUnnecessaryDefaultIvyInstance" file="test/repositories/ivysettings.xml" override="true" />
<ivy:configure settingsId="testUnnecessaryDefaultIvyInstance" file="test/repositories/ivysettings.xml" override="true" />
<ivy:cachepath settingsRef="testUnnecessaryDefaultIvyInstance" file="test/java/org/apache/ivy/ant/ivy-simple.xml" pathid="ptest" />
</target>
</project>

View File

@ -26,23 +26,33 @@ import org.apache.ivy.plugins.resolver.IBiblioResolver;
import org.apache.ivy.plugins.resolver.IvyRepResolver;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Reference;
import junit.framework.TestCase;
public class IvyAntSettingsTest extends TestCase {
private IvyAntSettings antSettings;
private IvyConfigure antSettings;
private Project project;
protected void setUp() throws Exception {
project = new Project();
project.setProperty("myproperty", "myvalue");
antSettings = new IvyAntSettings();
antSettings = new IvyConfigure();
antSettings.setProject(project);
}
private Ivy getIvyInstance() {
return antSettings.getConfiguredIvyInstance();
IvyTask task = new IvyTask() {
public void doExecute() throws BuildException {
}};
task.setProject(project);
task.init();
Reference ref = new Reference(antSettings.getSettingsId());
// ref.setProject(project);
task.setSettingsRef(ref);
return task.getIvyInstance();
}
public void testDefault() throws Exception {
@ -147,7 +157,7 @@ public class IvyAntSettingsTest extends TestCase {
String confUrl = IvyConfigureTest.class.getResource("ivysettings-props.xml")
.toExternalForm();
antSettings.setUrl(confUrl);
antSettings.setId("this.id");
antSettings.setSettingsId("this.id");
antSettings.execute();
@ -175,9 +185,9 @@ public class IvyAntSettingsTest extends TestCase {
Ivy ivy = getIvyInstance();
assertNotNull(ivy);
antSettings = new IvyAntSettings();
antSettings = new IvyConfigure();
antSettings.setProject(project);
antSettings.setOverride(IvyAntSettings.OVERRIDE_TRUE);
antSettings.setOverride("true");
antSettings.setFile(new File("test/repositories/ivysettings.xml"));
antSettings.execute();
assertNotNull(getIvyInstance());
@ -192,13 +202,13 @@ public class IvyAntSettingsTest extends TestCase {
Ivy ivy = getIvyInstance();
assertNotNull(ivy);
IvyAntSettings newAntSettings = new IvyAntSettings();
IvyConfigure newAntSettings = new IvyConfigure();
newAntSettings.setProject(project);
newAntSettings.setOverride(IvyAntSettings.OVERRIDE_FALSE);
newAntSettings.setOverride("false");
newAntSettings.setFile(new File("test/repositories/ivysettings.xml"));
newAntSettings.execute();
assertTrue(antSettings == project.getReference(newAntSettings.getId()));
assertTrue(ivy == getIvyInstance());
}
public void testOverrideNotAllowed() throws Exception {
@ -208,9 +218,9 @@ public class IvyAntSettingsTest extends TestCase {
Ivy ivy = getIvyInstance();
assertNotNull(ivy);
antSettings = new IvyAntSettings();
antSettings = new IvyConfigure();
antSettings.setProject(project);
antSettings.setOverride(IvyAntSettings.OVERRIDE_NOT_ALLOWED);
antSettings.setOverride("notallowed");
antSettings.setFile(new File("test/repositories/ivysettings.xml"));
try {
@ -219,7 +229,7 @@ public class IvyAntSettingsTest extends TestCase {
+ "override=notallowed should raise an exception");
} catch (BuildException e) {
assertTrue(e.getMessage().indexOf("notallowed") != -1);
assertTrue(e.getMessage().indexOf(antSettings.getId()) != -1);
assertTrue(e.getMessage().indexOf(antSettings.getSettingsId()) != -1);
}
}

View File

@ -37,7 +37,7 @@ public class IvyCleanCacheTest extends TestCase {
p.setProperty("cache", cacheDir.getAbsolutePath());
cleanCache = new IvyCleanCache();
cleanCache.setProject(p);
IvyAntSettings settings = new IvyAntSettings();
IvyConfigure settings = new IvyConfigure();
settings.setProject(p);
settings.setUrl(
IvyCleanCacheTest.class.getResource("ivysettings-cleancache.xml").toExternalForm());

View File

@ -26,25 +26,36 @@ import org.apache.ivy.core.settings.IvySettings;
import org.apache.ivy.plugins.resolver.DependencyResolver;
import org.apache.ivy.plugins.resolver.IBiblioResolver;
import org.apache.ivy.plugins.resolver.IvyRepResolver;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Reference;
/**
* Test the deprecated IvyConfigureTest and the underlying implementation AntIvySettings. When
* IvyConfigure will be removed, this class should be renamed AntIvySettingsTest
*/
public class IvyConfigureTest extends TestCase {
private IvyAntSettings antSettings;
private IvyConfigure antSettings;
protected void setUp() throws Exception {
Project project = new Project();
project.setProperty("myproperty", "myvalue");
antSettings = new IvyAntSettings();
antSettings = new IvyConfigure();
antSettings.setProject(project);
}
private Ivy getIvyInstance() {
return antSettings.getConfiguredIvyInstance();
IvyTask task = new IvyTask() {
public void doExecute() throws BuildException {
}};
task.setProject(antSettings.getProject());
task.init();
Reference ref = new Reference(antSettings.getSettingsId());
// ref.setProject(antSettings.getProject());
task.setSettingsRef(ref);
return task.getIvyInstance();
}
public void testDefault() throws Exception {

View File

@ -225,11 +225,11 @@ public class IvyDeliverTest extends TestCase {
}
public void testReplaceBranch() throws Exception {
IvyAntSettings settings = new IvyAntSettings();
IvyConfigure settings = new IvyConfigure();
settings.setProject(project);
settings.execute();
// change the default branch to use
settings.getConfiguredIvyInstance().getSettings().setDefaultBranch("BRANCH1");
IvyAntSettings.getDefaultInstance(project).getConfiguredIvyInstance().getSettings().setDefaultBranch("BRANCH1");
// resolve a module dependencies
project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-latest.xml");