001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.ivy.ant;
019:
020: import java.io.File;
021:
022: import junit.framework.TestCase;
023:
024: import org.apache.ivy.Ivy;
025: import org.apache.ivy.core.settings.IvySettings;
026: import org.apache.ivy.plugins.resolver.DependencyResolver;
027: import org.apache.ivy.plugins.resolver.IBiblioResolver;
028: import org.apache.ivy.plugins.resolver.IvyRepResolver;
029: import org.apache.tools.ant.Project;
030:
031: /**
032: * Test the deprecated IvyConfigureTest and the underlying implementation AntIvySettings. When
033: * IvyConfigure will be removed, this class should be renamed AntIvySettingsTest
034: */
035: public class IvyConfigureTest extends TestCase {
036: private IvyAntSettings antSettings;
037:
038: protected void setUp() throws Exception {
039: Project project = new Project();
040: project.setProperty("myproperty", "myvalue");
041:
042: antSettings = new IvyAntSettings();
043: antSettings.setProject(project);
044: }
045:
046: private Ivy getIvyInstance() {
047: return antSettings.getConfiguredIvyInstance();
048: }
049:
050: public void testDefault() throws Exception {
051: // by default configure look in the current directory for an ivysettings.xml file...
052: // but Ivy itself has one, and we don't want to use it
053: antSettings.getProject().setProperty("ivy.settings.file",
054: "no/settings/will/use/default.xml");
055: antSettings.execute();
056:
057: IvySettings settings = getIvyInstance().getSettings();
058: assertNotNull(settings.getDefaultResolver());
059:
060: DependencyResolver publicResolver = settings
061: .getResolver("public");
062: assertNotNull(publicResolver);
063: assertTrue(publicResolver instanceof IBiblioResolver);
064: IBiblioResolver ibiblio = (IBiblioResolver) publicResolver;
065: assertTrue(ibiblio.isM2compatible());
066: }
067:
068: public void testDefault14() throws Exception {
069: // by default configure look in the current directory for an ivysettings.xml file...
070: // but Ivy itself has one, and we don't want to use it
071: antSettings.getProject().setProperty("ivy.settings.file",
072: "no/settings/will/use/default.xml");
073: antSettings.getProject().setProperty("ivy.14.compatible",
074: "true");
075: antSettings.execute();
076:
077: IvySettings settings = getIvyInstance().getSettings();
078: assertNotNull(settings.getDefaultResolver());
079:
080: DependencyResolver publicResolver = settings
081: .getResolver("public");
082: assertTrue(publicResolver instanceof IvyRepResolver);
083: }
084:
085: public void testFile() throws Exception {
086: antSettings.setFile(new File(
087: "test/repositories/ivysettings.xml"));
088:
089: antSettings.execute();
090:
091: Ivy ivy = getIvyInstance();
092: assertNotNull(ivy);
093: IvySettings settings = ivy.getSettings();
094: assertNotNull(settings);
095:
096: assertEquals(new File("build/cache"), settings
097: .getDefaultCache());
098: assertEquals(new File("test/repositories/ivysettings.xml")
099: .getAbsolutePath(), settings.getVariables()
100: .getVariable("ivy.settings.file"));
101: assertEquals(new File("test/repositories/ivysettings.xml")
102: .toURL().toExternalForm(), settings.getVariables()
103: .getVariable("ivy.settings.url"));
104: assertEquals(new File("test/repositories").getAbsolutePath(),
105: settings.getVariables().getVariable("ivy.settings.dir"));
106: assertEquals("myvalue", settings.getVariables().getVariable(
107: "myproperty"));
108: }
109:
110: /*@SuppressWarnings*/
111: public void testURL() throws Exception {
112: String confUrl = new File("test/repositories/ivysettings.xml")
113: .toURL().toExternalForm();
114: String confDirUrl = new File("test/repositories").toURL()
115: .toExternalForm();
116: if (confDirUrl.endsWith("/")) {
117: confDirUrl = confDirUrl.substring(0,
118: confDirUrl.length() - 1);
119: }
120: antSettings.setUrl(confUrl);
121:
122: antSettings.execute();
123:
124: IvySettings settings = getIvyInstance().getSettings();
125:
126: assertEquals(new File("build/cache"), settings
127: .getDefaultCache());
128: assertEquals(confUrl, settings.getVariables().getVariable(
129: "ivy.settings.url"));
130: assertEquals(confDirUrl, settings.getVariables().getVariable(
131: "ivy.settings.dir"));
132: assertEquals("myvalue", settings.getVariables().getVariable(
133: "myproperty"));
134: }
135:
136: public void testAntProperties() throws Exception {
137: String confUrl = IvyConfigureTest.class.getResource(
138: "ivysettings-test.xml").toExternalForm();
139: antSettings.setUrl(confUrl);
140:
141: antSettings.execute();
142:
143: IvySettings settings = getIvyInstance().getSettings();
144: assertNotNull(settings);
145:
146: assertEquals("myvalue", settings.getVariables().getVariable(
147: "myproperty"));
148: assertEquals("myvalue", settings.getDefaultCache().getName());
149: }
150:
151: public void testExposeAntProperties() throws Exception {
152: String confUrl = IvyConfigureTest.class.getResource(
153: "ivysettings-props.xml").toExternalForm();
154: antSettings.setUrl(confUrl);
155:
156: antSettings.execute();
157:
158: assertNotNull(getIvyInstance());
159:
160: assertEquals("value", antSettings.getProject().getProperty(
161: "ivy.test.variable"));
162:
163: assertEquals(getIvyInstance().getSettings().getDefaultCache()
164: .getAbsolutePath(), antSettings.getProject()
165: .getProperty("ivy.cache.dir"));
166: }
167:
168: public void testOverrideVariables() throws Exception {
169: String confUrl = IvyConfigureTest.class.getResource(
170: "ivysettings-props.xml").toExternalForm();
171: antSettings.setUrl(confUrl);
172:
173: antSettings.execute();
174:
175: IvySettings settings = getIvyInstance().getSettings();
176: assertNotNull(settings);
177:
178: assertEquals("lib/test/[artifact]-[revision].[ext]", settings
179: .getVariables().getVariable("ivy.retrieve.pattern"));
180: }
181:
182: }
|