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.TestHelper;
025: import org.apache.ivy.core.report.ResolveReport;
026: import org.apache.ivy.util.CacheCleaner;
027: import org.apache.ivy.util.DefaultMessageLogger;
028: import org.apache.ivy.util.Message;
029: import org.apache.tools.ant.BuildException;
030: import org.apache.tools.ant.Project;
031:
032: public class IvyPostResolveTaskTest extends TestCase {
033: private File cache;
034:
035: private IvyPostResolveTask task;
036:
037: private Project project;
038:
039: protected void setUp() throws Exception {
040: Message.setDefaultLogger(new DefaultMessageLogger(10));
041: createCache();
042: project = new Project();
043: project.setProperty("ivy.settings.file",
044: "test/repositories/ivysettings.xml");
045:
046: task = new IvyPostResolveTask() {
047: public void doExecute() throws BuildException {
048: prepareAndCheck();
049: }
050: };
051: task.setProject(project);
052: System.setProperty("ivy.cache.dir", cache.getAbsolutePath());
053: }
054:
055: private void createCache() {
056: cache = new File("build/cache");
057: cache.mkdirs();
058: }
059:
060: protected void tearDown() throws Exception {
061: CacheCleaner.deleteDir(cache);
062: }
063:
064: public void testWithPreviousResolveInSameBuildAndLessConfs()
065: throws Exception {
066: IvyResolve resolve = new IvyResolve();
067: resolve.setProject(project);
068: resolve.setFile(new File(
069: "test/java/org/apache/ivy/ant/ivy-multiconf.xml"));
070: resolve.setConf("default,compile");
071: resolve.execute();
072:
073: ResolveReport reportBefore = (ResolveReport) project
074: .getReference("ivy.resolved.report");
075:
076: task.setConf("default");
077: task.execute();
078:
079: ResolveReport reportAfter = (ResolveReport) project
080: .getReference("ivy.resolved.report");
081:
082: assertSame(
083: "IvyPostResolveTask has performed a resolve where it shouldn't",
084: reportBefore, reportAfter);
085: }
086:
087: public void testWithPreviousResolveInSameBuildAndSameConfs()
088: throws Exception {
089: IvyResolve resolve = new IvyResolve();
090: resolve.setProject(project);
091: resolve.setFile(new File(
092: "test/java/org/apache/ivy/ant/ivy-multiconf.xml"));
093: resolve.setConf("default");
094: resolve.execute();
095:
096: ResolveReport reportBefore = (ResolveReport) project
097: .getReference("ivy.resolved.report");
098:
099: task.setConf("default");
100: task.execute();
101:
102: ResolveReport reportAfter = (ResolveReport) project
103: .getReference("ivy.resolved.report");
104:
105: assertSame(
106: "IvyPostResolveTask has performed a resolve where it shouldn't",
107: reportBefore, reportAfter);
108: }
109:
110: public void testWithPreviousResolveInSameBuildAndWildcard()
111: throws Exception {
112: IvyResolve resolve = new IvyResolve();
113: resolve.setProject(project);
114: resolve.setFile(new File(
115: "test/java/org/apache/ivy/ant/ivy-multiconf.xml"));
116: resolve.setConf("*");
117: resolve.execute();
118:
119: ResolveReport reportBefore = (ResolveReport) project
120: .getReference("ivy.resolved.report");
121:
122: task.setConf("default");
123: task.execute();
124:
125: ResolveReport reportAfter = (ResolveReport) project
126: .getReference("ivy.resolved.report");
127:
128: assertSame(
129: "IvyPostResolveTask has performed a resolve where it shouldn't",
130: reportBefore, reportAfter);
131: }
132:
133: public void testWithPreviousResolveInSameBuildAndBothWildcard()
134: throws Exception {
135: IvyResolve resolve = new IvyResolve();
136: resolve.setProject(project);
137: resolve.setFile(new File(
138: "test/java/org/apache/ivy/ant/ivy-multiconf.xml"));
139: resolve.setConf("*");
140: resolve.execute();
141:
142: ResolveReport reportBefore = (ResolveReport) project
143: .getReference("ivy.resolved.report");
144:
145: task.setConf("*");
146: task.execute();
147:
148: ResolveReport reportAfter = (ResolveReport) project
149: .getReference("ivy.resolved.report");
150:
151: assertSame(
152: "IvyPostResolveTask has performed a resolve where it shouldn't",
153: reportBefore, reportAfter);
154: }
155:
156: public void testWithPreviousResolveInSameBuildAndMoreConfs()
157: throws Exception {
158: IvyResolve resolve = new IvyResolve();
159: resolve.setProject(project);
160: resolve.setFile(new File(
161: "test/java/org/apache/ivy/ant/ivy-multiconf.xml"));
162: resolve.setConf("compile");
163: resolve.execute();
164:
165: ResolveReport reportBefore = (ResolveReport) project
166: .getReference("ivy.resolved.report");
167: assertTrue(getArchiveFileInCache("org1", "mod1.1", "2.0",
168: "mod1.1", "jar", "jar").exists());
169: assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0",
170: "mod1.2", "jar", "jar").exists());
171:
172: task.setConf("*");
173: task.execute();
174:
175: ResolveReport reportAfter = (ResolveReport) project
176: .getReference("ivy.resolved.report");
177:
178: assertNotSame(
179: "IvyPostResolveTask hasn't performed a resolve where it should have",
180: reportBefore, reportAfter);
181: assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
182: "mod1.2", "jar", "jar").exists());
183: }
184:
185: public void testWithoutKeep() throws Exception {
186: IvyResolve resolve = new IvyResolve();
187: resolve.setProject(project);
188: resolve.setFile(new File(
189: "test/java/org/apache/ivy/ant/ivy-multiconf.xml"));
190: resolve.setConf("compile");
191: resolve.execute();
192:
193: ResolveReport reportBefore = (ResolveReport) project
194: .getReference("ivy.resolved.report");
195: assertTrue(getArchiveFileInCache("org1", "mod1.1", "2.0",
196: "mod1.1", "jar", "jar").exists());
197: assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0",
198: "mod1.2", "jar", "jar").exists());
199:
200: task.setConf("*"); // will trigger a resolve
201: task.setKeep(false); // don't keep the resolve results
202: task.execute();
203:
204: ResolveReport reportAfter = (ResolveReport) project
205: .getReference("ivy.resolved.report");
206:
207: assertSame(
208: "IvyPostResolveTask has kept the resolve report where it should have",
209: reportBefore, reportAfter);
210: assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
211: "mod1.2", "jar", "jar").exists());
212: }
213:
214: public void testInlineWithoutKeep() throws Exception {
215: task.setOrganisation("org1");
216: task.setModule("mod1.1");
217: task.setRevision("2.0");
218: task.setInline(true);
219: task.setConf("*"); // will trigger a resolve
220: task.execute();
221:
222: ResolveReport reportAfter = (ResolveReport) project
223: .getReference("ivy.resolved.report");
224:
225: assertNull(
226: "IvyPostResolveTask has kept the resolve report where it should have",
227: reportAfter);
228: assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.1",
229: "mod1.2", "jar", "jar").exists());
230: }
231:
232: public void testInlineWithKeep() throws Exception {
233: task.setOrganisation("org1");
234: task.setModule("mod1.1");
235: task.setRevision("2.0");
236: task.setInline(true);
237: task.setKeep(true);
238: task.setConf("*"); // will trigger a resolve
239: task.execute();
240:
241: ResolveReport reportAfter = (ResolveReport) project
242: .getReference("ivy.resolved.report");
243:
244: assertNotNull(
245: "IvyPostResolveTask has kept the resolve report where it should have",
246: reportAfter);
247: assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.1",
248: "mod1.2", "jar", "jar").exists());
249: }
250:
251: public void testWithResolveIdAndPreviousResolveInSameBuildAndLessConfs()
252: throws Exception {
253: IvyResolve resolve = new IvyResolve();
254: resolve.setProject(project);
255: resolve.setFile(new File(
256: "test/java/org/apache/ivy/ant/ivy-multiconf.xml"));
257: resolve.setConf("default,compile");
258: resolve.setResolveId("testResolveId");
259: resolve.execute();
260:
261: ResolveReport report1 = (ResolveReport) project
262: .getReference("ivy.resolved.report.testResolveId");
263:
264: // perform another resolve
265: resolve = new IvyResolve();
266: resolve.setProject(project);
267: resolve.setFile(new File(
268: "test/java/org/apache/ivy/ant/ivy-simple.xml"));
269: resolve.setConf("*");
270: resolve.execute();
271:
272: ResolveReport reportBefore = (ResolveReport) project
273: .getReference("ivy.resolved.report");
274:
275: task.setConf("default");
276: task.setResolveId("testResolveId");
277: task.execute();
278:
279: ResolveReport reportAfter = (ResolveReport) project
280: .getReference("ivy.resolved.report");
281: ResolveReport report2 = (ResolveReport) project
282: .getReference("ivy.resolved.report.testResolveId");
283:
284: assertSame(
285: "IvyPostResolveTask has performed a resolve where it shouldn't",
286: reportBefore, reportAfter);
287: assertSame(
288: "IvyPostResolveTask has performed a resolve where it shouldn't",
289: report1, report2);
290: }
291:
292: public void testWithResolveIdAndPreviousResolveInSameBuildAndSameConfs()
293: throws Exception {
294: IvyResolve resolve = new IvyResolve();
295: resolve.setProject(project);
296: resolve.setFile(new File(
297: "test/java/org/apache/ivy/ant/ivy-multiconf.xml"));
298: resolve.setConf("default");
299: resolve.setResolveId("testResolveId");
300: resolve.execute();
301:
302: ResolveReport report1 = (ResolveReport) project
303: .getReference("ivy.resolved.report.testResolveId");
304:
305: // perform another resolve
306: resolve = new IvyResolve();
307: resolve.setProject(project);
308: resolve.setFile(new File(
309: "test/java/org/apache/ivy/ant/ivy-simple.xml"));
310: resolve.setConf("*");
311: resolve.execute();
312:
313: ResolveReport reportBefore = (ResolveReport) project
314: .getReference("ivy.resolved.report");
315:
316: task.setConf("default");
317: task.setResolveId("testResolveId");
318: task.execute();
319:
320: ResolveReport reportAfter = (ResolveReport) project
321: .getReference("ivy.resolved.report");
322: ResolveReport report2 = (ResolveReport) project
323: .getReference("ivy.resolved.report.testResolveId");
324:
325: assertSame(
326: "IvyPostResolveTask has performed a resolve where it shouldn't",
327: reportBefore, reportAfter);
328: assertSame(
329: "IvyPostResolveTask has performed a resolve where it shouldn't",
330: report1, report2);
331: }
332:
333: public void testWithResolveIdAndPreviousResolveInSameBuildAndWildcard()
334: throws Exception {
335: IvyResolve resolve = new IvyResolve();
336: resolve.setProject(project);
337: resolve.setFile(new File(
338: "test/java/org/apache/ivy/ant/ivy-multiconf.xml"));
339: resolve.setConf("*");
340: resolve.setResolveId("testResolveId");
341: resolve.execute();
342:
343: ResolveReport report1 = (ResolveReport) project
344: .getReference("ivy.resolved.report.testResolveId");
345:
346: // perform another resolve
347: resolve = new IvyResolve();
348: resolve.setProject(project);
349: resolve.setFile(new File(
350: "test/java/org/apache/ivy/ant/ivy-simple.xml"));
351: resolve.setConf("*");
352: resolve.execute();
353:
354: ResolveReport reportBefore = (ResolveReport) project
355: .getReference("ivy.resolved.report");
356:
357: task.setConf("default");
358: task.setResolveId("testResolveId");
359: task.execute();
360:
361: ResolveReport reportAfter = (ResolveReport) project
362: .getReference("ivy.resolved.report");
363: ResolveReport report2 = (ResolveReport) project
364: .getReference("ivy.resolved.report.testResolveId");
365:
366: assertSame(
367: "IvyPostResolveTask has performed a resolve where it shouldn't",
368: reportBefore, reportAfter);
369: assertSame(
370: "IvyPostResolveTask has performed a resolve where it shouldn't",
371: report1, report2);
372: }
373:
374: public void testWithResolveIdAndPreviousResolveInSameBuildAndBothWildcard()
375: throws Exception {
376: IvyResolve resolve = new IvyResolve();
377: resolve.setProject(project);
378: resolve.setFile(new File(
379: "test/java/org/apache/ivy/ant/ivy-multiconf.xml"));
380: resolve.setConf("*");
381: resolve.setResolveId("testResolveId");
382: resolve.execute();
383:
384: ResolveReport report1 = (ResolveReport) project
385: .getReference("ivy.resolved.report.testResolveId");
386:
387: // perform another resolve
388: resolve = new IvyResolve();
389: resolve.setProject(project);
390: resolve.setFile(new File(
391: "test/java/org/apache/ivy/ant/ivy-simple.xml"));
392: resolve.setConf("*");
393: resolve.execute();
394:
395: ResolveReport reportBefore = (ResolveReport) project
396: .getReference("ivy.resolved.report");
397:
398: task.setConf("*");
399: task.setResolveId("testResolveId");
400: task.execute();
401:
402: ResolveReport reportAfter = (ResolveReport) project
403: .getReference("ivy.resolved.report");
404: ResolveReport report2 = (ResolveReport) project
405: .getReference("ivy.resolved.report.testResolveId");
406:
407: assertSame(
408: "IvyPostResolveTask has performed a resolve where it shouldn't",
409: reportBefore, reportAfter);
410: assertSame(
411: "IvyPostResolveTask has performed a resolve where it shouldn't",
412: report1, report2);
413: }
414:
415: public void testWithResolveIdAndPreviousResolveInSameBuildAndMoreConfs()
416: throws Exception {
417: IvyResolve resolve = new IvyResolve();
418: resolve.setProject(project);
419: resolve.setFile(new File(
420: "test/java/org/apache/ivy/ant/ivy-multiconf.xml"));
421: resolve.setConf("compile");
422: resolve.setResolveId("testResolveId");
423: resolve.execute();
424:
425: ResolveReport report1 = (ResolveReport) project
426: .getReference("ivy.resolved.report.testResolveId");
427: assertTrue(getArchiveFileInCache("org1", "mod1.1", "2.0",
428: "mod1.1", "jar", "jar").exists());
429: assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0",
430: "mod1.2", "jar", "jar").exists());
431:
432: // perform another resolve
433: resolve = new IvyResolve();
434: resolve.setProject(project);
435: resolve.setFile(new File(
436: "test/java/org/apache/ivy/ant/ivy-simple.xml"));
437: resolve.setConf("*");
438: resolve.execute();
439:
440: ResolveReport reportBefore = (ResolveReport) project
441: .getReference("ivy.resolved.report");
442:
443: task.setConf("*");
444: task.setResolveId("testResolveId");
445: task.execute();
446:
447: ResolveReport reportAfter = (ResolveReport) project
448: .getReference("ivy.resolved.report");
449: ResolveReport report2 = (ResolveReport) project
450: .getReference("ivy.resolved.report.testResolveId");
451:
452: assertNotSame(
453: "IvyPostResolveTask hasn't performed a resolve where it should have",
454: reportBefore, reportAfter);
455: assertNotSame(
456: "IvyPostResolveTask hasn't performed a resolve where it should have",
457: report1, report2);
458: assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
459: "mod1.2", "jar", "jar").exists());
460: }
461:
462: private File getArchiveFileInCache(String organisation,
463: String module, String revision, String artifact,
464: String type, String ext) {
465: return TestHelper.getArchiveFileInCache(task.getIvyInstance(),
466: organisation, module, revision, artifact, type, ext);
467: }
468: }
|