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.core.install;
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.module.id.ModuleRevisionId;
026: import org.apache.ivy.plugins.matcher.PatternMatcher;
027: import org.apache.tools.ant.Project;
028: import org.apache.tools.ant.taskdefs.Delete;
029:
030: public class InstallTest extends TestCase {
031:
032: public void testSimple() throws Exception {
033: Ivy ivy = Ivy.newInstance();
034: ivy.configure(new File("test/repositories/ivysettings.xml"));
035:
036: ivy.install(ModuleRevisionId.newInstance("org1", "mod1.2",
037: "2.0"), ivy.getSettings().getDefaultResolver()
038: .getName(), "install", true, true, true, null,
039: PatternMatcher.EXACT);
040:
041: assertTrue(new File(
042: "build/test/install/org1/mod1.2/ivy-2.0.xml").exists());
043: assertTrue(new File(
044: "build/test/install/org1/mod1.2/mod1.2-2.0.jar")
045: .exists());
046: }
047:
048: public void testValidate() throws Exception {
049: Ivy ivy = Ivy.newInstance();
050: ivy.configure(new File("test/repositories/ivysettings.xml"));
051:
052: ivy.install(ModuleRevisionId.newInstance("orgfailure",
053: "modfailure", "1.0"), ivy.getSettings()
054: .getDefaultResolver().getName(), "install", true, true,
055: true, null, PatternMatcher.EXACT);
056:
057: assertFalse(new File(
058: "build/test/install/orgfailure/modfailure/ivy-1.0.xml")
059: .exists());
060: assertFalse(new File(
061: "build/test/install/orgfailure/modfailure/modfailure-1.0.jar")
062: .exists());
063: }
064:
065: public void testNoValidate() throws Exception {
066: Ivy ivy = Ivy.newInstance();
067: ivy.configure(new File("test/repositories/ivysettings.xml"));
068:
069: ivy.install(ModuleRevisionId.newInstance("orgfailure",
070: "modfailure", "1.0"), ivy.getSettings()
071: .getDefaultResolver().getName(), "install", true,
072: false, true, null, PatternMatcher.EXACT);
073:
074: assertTrue(new File(
075: "build/test/install/orgfailure/modfailure/ivy-1.0.xml")
076: .exists());
077: assertTrue(new File(
078: "build/test/install/orgfailure/modfailure/modfailure-1.0.jar")
079: .exists());
080: }
081:
082: public void testSimpleWithoutDefaultResolver() throws Exception {
083: Ivy ivy = Ivy.newInstance();
084: ivy.configure(new File(
085: "test/repositories/ivysettings-nodefaultresolver.xml"));
086:
087: ivy.install(ModuleRevisionId.newInstance("org1", "mod1.2",
088: "2.0"), "test", "install", true, true, true, null,
089: PatternMatcher.EXACT);
090:
091: assertTrue(new File(
092: "build/test/install/org1/mod1.2/ivy-2.0.xml").exists());
093: assertTrue(new File(
094: "build/test/install/org1/mod1.2/mod1.2-2.0.jar")
095: .exists());
096: }
097:
098: public void testDependencies() throws Exception {
099: Ivy ivy = Ivy.newInstance();
100: ivy.configure(new File("test/repositories/ivysettings.xml"));
101:
102: ivy.install(ModuleRevisionId.newInstance("org1", "mod1.1",
103: "1.0"), ivy.getSettings().getDefaultResolver()
104: .getName(), "install", true, true, true, null,
105: PatternMatcher.EXACT);
106:
107: assertTrue(new File(
108: "build/test/install/org1/mod1.1/ivy-1.0.xml").exists());
109: assertTrue(new File(
110: "build/test/install/org1/mod1.1/mod1.1-1.0.jar")
111: .exists());
112:
113: assertTrue(new File(
114: "build/test/install/org1/mod1.2/ivy-2.0.xml").exists());
115: assertTrue(new File(
116: "build/test/install/org1/mod1.2/mod1.2-2.0.jar")
117: .exists());
118: }
119:
120: public void testNotTransitive() throws Exception {
121: Ivy ivy = Ivy.newInstance();
122: ivy.configure(new File("test/repositories/ivysettings.xml"));
123:
124: ivy.install(ModuleRevisionId.newInstance("org1", "mod1.1",
125: "1.0"), ivy.getSettings().getDefaultResolver()
126: .getName(), "install", false, true, true, null,
127: PatternMatcher.EXACT);
128:
129: assertTrue(new File(
130: "build/test/install/org1/mod1.1/ivy-1.0.xml").exists());
131: assertTrue(new File(
132: "build/test/install/org1/mod1.1/mod1.1-1.0.jar")
133: .exists());
134:
135: assertFalse(new File(
136: "build/test/install/org1/mod1.2/ivy-2.0.xml").exists());
137: assertFalse(new File(
138: "build/test/install/org1/mod1.2/mod1.2-2.0.jar")
139: .exists());
140: }
141:
142: public void testRegexpMatcher() throws Exception {
143: Ivy ivy = Ivy.newInstance();
144: ivy.configure(new File("test/repositories/ivysettings.xml"));
145:
146: ivy.install(ModuleRevisionId.newInstance("org1", ".*", ".*"),
147: "1", "install", false, true, true, null,
148: PatternMatcher.REGEXP);
149:
150: assertTrue(new File(
151: "build/test/install/org1/mod1.1/ivy-1.0.xml").exists());
152: assertTrue(new File(
153: "build/test/install/org1/mod1.1/mod1.1-1.0.jar")
154: .exists());
155:
156: assertTrue(new File(
157: "build/test/install/org1/mod1.1/ivy-1.1.xml").exists());
158: assertTrue(new File(
159: "build/test/install/org1/mod1.1/mod1.1-1.1.jar")
160: .exists());
161:
162: assertTrue(new File(
163: "build/test/install/org1/mod1.2/ivy-2.0.xml").exists());
164: assertTrue(new File(
165: "build/test/install/org1/mod1.2/mod1.2-2.0.jar")
166: .exists());
167:
168: // mod1.3 is split because Ivy thinks there are two versions of the module:
169: // this is the normal behaviour in this case
170: assertTrue(new File(
171: "build/test/install/org1/mod1.3/ivy-B-3.0.xml")
172: .exists());
173: assertTrue(new File(
174: "build/test/install/org1/mod1.3/ivy-A-3.0.xml")
175: .exists());
176: assertTrue(new File(
177: "build/test/install/org1/mod1.3/mod1.3-A-3.0.jar")
178: .exists());
179: assertTrue(new File(
180: "build/test/install/org1/mod1.3/mod1.3-B-3.0.jar")
181: .exists());
182:
183: assertTrue(new File(
184: "build/test/install/org1/mod1.4/ivy-1.0.1.xml")
185: .exists());
186: }
187:
188: private File _cache;
189:
190: protected void setUp() throws Exception {
191: createCache();
192: }
193:
194: private void createCache() {
195: _cache = new File("build/cache");
196: _cache.mkdirs();
197: }
198:
199: protected void tearDown() throws Exception {
200: cleanCache();
201: cleanInstall();
202: }
203:
204: private void cleanCache() {
205: Delete del = new Delete();
206: del.setProject(new Project());
207: del.setDir(_cache);
208: del.execute();
209: }
210:
211: private void cleanInstall() {
212: Delete del = new Delete();
213: del.setProject(new Project());
214: del.setDir(new File("build/test/install"));
215: del.execute();
216: }
217: }
|