Source Code Cross Referenced for IvyPublishTest.java in  » Code-Analyzer » apache-ivy » org » apache » ivy » ant » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Code Analyzer » apache ivy » org.apache.ivy.ant 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.BufferedReader;
021:        import java.io.File;
022:        import java.io.FileReader;
023:        import java.io.InputStreamReader;
024:
025:        import junit.framework.TestCase;
026:
027:        import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
028:        import org.apache.ivy.core.settings.IvySettings;
029:        import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParser;
030:        import org.apache.ivy.util.DefaultMessageLogger;
031:        import org.apache.ivy.util.FileUtil;
032:        import org.apache.ivy.util.Message;
033:        import org.apache.tools.ant.BuildException;
034:        import org.apache.tools.ant.Project;
035:        import org.apache.tools.ant.taskdefs.Delete;
036:        import org.apache.tools.ant.taskdefs.Echo;
037:
038:        public class IvyPublishTest extends TestCase {
039:            private File cache;
040:
041:            private IvyPublish publish;
042:
043:            private Project project;
044:
045:            protected void setUp() throws Exception {
046:                cleanTestDir();
047:                cleanRep();
048:                createCache();
049:                project = new Project();
050:                project.init();
051:                project.setProperty("ivy.settings.file",
052:                        "test/repositories/ivysettings.xml");
053:                project.setProperty("build", "build/test/publish");
054:
055:                publish = new IvyPublish();
056:                publish.setProject(project);
057:                System.setProperty("ivy.cache.dir", cache.getAbsolutePath());
058:
059:                Message.setDefaultLogger(new DefaultMessageLogger(10));
060:            }
061:
062:            private void createCache() {
063:                cache = new File("build/cache");
064:                cache.mkdirs();
065:            }
066:
067:            protected void tearDown() throws Exception {
068:                cleanCache();
069:                cleanTestDir();
070:                cleanRep();
071:            }
072:
073:            private void cleanCache() {
074:                Delete del = new Delete();
075:                del.setProject(new Project());
076:                del.setDir(cache);
077:                del.execute();
078:            }
079:
080:            private void cleanTestDir() {
081:                Delete del = new Delete();
082:                del.setProject(new Project());
083:                del.setDir(new File("build/test/publish"));
084:                del.execute();
085:            }
086:
087:            private void cleanRep() {
088:                Delete del = new Delete();
089:                del.setProject(new Project());
090:                del.setDir(new File("test/repositories/1/apache"));
091:                del.execute();
092:            }
093:
094:            public void testSimple() throws Exception {
095:                project.setProperty("ivy.dep.file",
096:                        "test/java/org/apache/ivy/ant/ivy-multiconf.xml");
097:                IvyResolve res = new IvyResolve();
098:                res.setProject(project);
099:                res.execute();
100:
101:                publish.setPubrevision("1.2");
102:                publish.setResolver("1");
103:                File art = new File("build/test/publish/resolve-simple-1.2.jar");
104:                FileUtil.copy(new File(
105:                        "test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"),
106:                        art, null);
107:                publish.execute();
108:
109:                // should have do the ivy delivering
110:                assertTrue(new File("build/test/publish/ivy-1.2.xml").exists());
111:
112:                // should have published the files with "1" resolver
113:                assertTrue(new File(
114:                        "test/repositories/1/apache/resolve-simple/ivys/ivy-1.2.xml")
115:                        .exists());
116:                assertTrue(new File(
117:                        "test/repositories/1/apache/resolve-simple/jars/resolve-simple-1.2.jar")
118:                        .exists());
119:
120:                // should have updated published ivy version
121:                ModuleDescriptor md = XmlModuleDescriptorParser
122:                        .getInstance()
123:                        .parseDescriptor(
124:                                new IvySettings(),
125:                                new File(
126:                                        "test/repositories/1/apache/resolve-simple/ivys/ivy-1.2.xml")
127:                                        .toURL(), false);
128:                assertEquals("1.2", md.getModuleRevisionId().getRevision());
129:            }
130:
131:            public void testPublishNotAllConfigs() throws Exception {
132:                project.setProperty("ivy.dep.file",
133:                        "test/java/org/apache/ivy/ant/ivy-multiconf.xml");
134:                IvyResolve res = new IvyResolve();
135:                res.setProject(project);
136:                res.execute();
137:
138:                publish.setPubrevision("1.2");
139:                publish.setResolver("1");
140:                publish.setConf("compile");
141:                publish.setUpdate(true);
142:                File art = new File("build/test/publish/resolve-simple-1.2.jar");
143:                FileUtil.copy(new File(
144:                        "test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"),
145:                        art, null);
146:                publish.execute();
147:
148:                // should have do the ivy delivering
149:                assertTrue(new File("build/test/publish/ivy-1.2.xml").exists());
150:
151:                // should have published the files with "1" resolver
152:                assertTrue(new File(
153:                        "test/repositories/1/apache/resolve-simple/ivys/ivy-1.2.xml")
154:                        .exists());
155:                assertTrue(new File(
156:                        "test/repositories/1/apache/resolve-simple/jars/resolve-simple-1.2.jar")
157:                        .exists());
158:
159:                // should have updated published ivy version
160:                ModuleDescriptor md = XmlModuleDescriptorParser
161:                        .getInstance()
162:                        .parseDescriptor(
163:                                new IvySettings(),
164:                                new File(
165:                                        "test/repositories/1/apache/resolve-simple/ivys/ivy-1.2.xml")
166:                                        .toURL(), false);
167:                assertEquals("1.2", md.getModuleRevisionId().getRevision());
168:
169:                // should only contain the default configuration
170:                String[] configs = md.getConfigurationsNames();
171:                assertEquals("Number of configurations not correct", 1,
172:                        configs.length);
173:                assertEquals("Compile configuration not present", "compile",
174:                        configs[0]);
175:            }
176:
177:            public void testMultiPatterns() throws Exception {
178:                project.setProperty("ivy.dep.file",
179:                        "test/java/org/apache/ivy/ant/ivy-publish-multi.xml");
180:                IvyResolve res = new IvyResolve();
181:                res.setProject(project);
182:                res.execute();
183:
184:                publish.setPubrevision("1.2");
185:                publish.setResolver("1");
186:                File art = new File("build/test/publish/1/multi1-1.2.jar");
187:                FileUtil.copy(new File(
188:                        "test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"),
189:                        art, null);
190:                art = new File("build/test/publish/2/multi2-1.2.jar");
191:                FileUtil.copy(new File(
192:                        "test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"),
193:                        art, null);
194:                publish
195:                        .addArtifactspattern("build/test/publish/1/[artifact]-[revision].[ext]");
196:                publish
197:                        .addArtifactspattern("build/test/publish/2/[artifact]-[revision].[ext]");
198:                publish.execute();
199:
200:                // should have do the ivy delivering
201:                assertTrue(new File("build/test/publish/1/ivy-1.2.xml")
202:                        .exists());
203:
204:                // should have published the files with "1" resolver
205:                assertTrue(new File(
206:                        "test/repositories/1/apache/multi/ivys/ivy-1.2.xml")
207:                        .exists());
208:                assertTrue(new File(
209:                        "test/repositories/1/apache/multi/jars/multi1-1.2.jar")
210:                        .exists());
211:                assertTrue(new File(
212:                        "test/repositories/1/apache/multi/jars/multi2-1.2.jar")
213:                        .exists());
214:            }
215:
216:            public void testCustom() throws Exception {
217:                project.setProperty("ivy.dep.file",
218:                        "test/java/org/apache/ivy/ant/ivy-custom.xml");
219:                IvyResolve res = new IvyResolve();
220:                res.setValidate(false);
221:                res.setProject(project);
222:                res.execute();
223:
224:                publish.setPubrevision("1.2");
225:                publish.setPubdate("20060906141243");
226:                publish.setResolver("1");
227:                publish.setValidate(false);
228:                File art = new File("build/test/publish/resolve-custom-1.2.jar");
229:                FileUtil.copy(new File(
230:                        "test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"),
231:                        art, null);
232:                publish.execute();
233:
234:                // should have do the ivy delivering
235:                assertTrue(new File("build/test/publish/ivy-1.2.xml").exists());
236:
237:                File dest = new File(
238:                        "test/repositories/1/apache/resolve-custom/ivys/ivy-1.2.xml");
239:                // should have published the files with "1" resolver
240:                assertTrue(dest.exists());
241:                assertTrue(new File(
242:                        "test/repositories/1/apache/resolve-custom/jars/resolve-custom-1.2.jar")
243:                        .exists());
244:
245:                // should have updated published ivy version
246:                ModuleDescriptor md = XmlModuleDescriptorParser
247:                        .getInstance()
248:                        .parseDescriptor(new IvySettings(), dest.toURL(), false);
249:                assertEquals("1.2", md.getModuleRevisionId().getRevision());
250:
251:                // should have kept custom attributes
252:                assertEquals("cval1", md.getModuleRevisionId().getAttribute(
253:                        "custom-info"));
254:                assertEquals("cval2", md.getConfiguration("default")
255:                        .getAttribute("custom-conf"));
256:                assertEquals("cval3", md.getDependencies()[0]
257:                        .getAttribute("custom-dep"));
258:
259:                // should respect the ivy file, with descriptions, ...
260:                String expected = FileUtil
261:                        .readEntirely(new BufferedReader(
262:                                new InputStreamReader(
263:                                        IvyPublishTest.class
264:                                                .getResourceAsStream("published-ivy-custom.xml"))));
265:                String updated = FileUtil.readEntirely(new BufferedReader(
266:                        new FileReader(dest)));
267:                assertEquals(expected, updated);
268:
269:            }
270:
271:            public void testNoDeliver() throws Exception {
272:                project.setProperty("ivy.dep.file",
273:                        "test/java/org/apache/ivy/ant/ivy-latest.xml");
274:                IvyResolve res = new IvyResolve();
275:                res.setProject(project);
276:                res.execute();
277:
278:                publish.setPubrevision("1.3");
279:                publish.setResolver("1");
280:                publish.setSrcivypattern("build/test/publish/ivy-1.3.xml");
281:
282:                FileUtil.copy(new File(
283:                        "test/java/org/apache/ivy/ant/ivy-publish.xml"),
284:                        new File("build/test/publish/ivy-1.3.xml"), null);
285:
286:                File art = new File("build/test/publish/resolve-latest-1.3.jar");
287:                FileUtil.copy(new File(
288:                        "test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"),
289:                        art, null);
290:                publish.execute();
291:
292:                // should have published the files with "1" resolver
293:                assertTrue(new File(
294:                        "test/repositories/1/apache/resolve-latest/ivys/ivy-1.3.xml")
295:                        .exists());
296:                assertTrue(new File(
297:                        "test/repositories/1/apache/resolve-latest/jars/resolve-latest-1.3.jar")
298:                        .exists());
299:
300:                // the published ivy version should be ok (ok in ivy-publish file)
301:                ModuleDescriptor md = XmlModuleDescriptorParser
302:                        .getInstance()
303:                        .parseDescriptor(
304:                                new IvySettings(),
305:                                new File(
306:                                        "test/repositories/1/apache/resolve-latest/ivys/ivy-1.3.xml")
307:                                        .toURL(), false);
308:                assertEquals("1.3", md.getModuleRevisionId().getRevision());
309:
310:                // should not have done delivery (replace dynamic revisions with static ones)
311:                assertEquals("latest.integration", md.getDependencies()[0]
312:                        .getDependencyRevisionId().getRevision());
313:            }
314:
315:            public void testForceDeliver() throws Exception {
316:                project.setProperty("ivy.dep.file",
317:                        "test/java/org/apache/ivy/ant/ivy-latest.xml");
318:                IvyResolve res = new IvyResolve();
319:                res.setProject(project);
320:                res.execute();
321:
322:                publish.setPubrevision("1.3");
323:                publish.setResolver("1");
324:                publish.setSrcivypattern("build/test/publish/ivy-1.3.xml");
325:                publish.setForcedeliver(true);
326:
327:                FileUtil.copy(new File(
328:                        "test/java/org/apache/ivy/ant/ivy-latest.xml"),
329:                        new File("build/test/publish/ivy-1.3.xml"), null);
330:
331:                File art = new File("build/test/publish/resolve-latest-1.3.jar");
332:                FileUtil.copy(new File(
333:                        "test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"),
334:                        art, null);
335:                publish.execute();
336:
337:                // should have published the files with "1" resolver
338:                assertTrue(new File(
339:                        "test/repositories/1/apache/resolve-latest/ivys/ivy-1.3.xml")
340:                        .exists());
341:                assertTrue(new File(
342:                        "test/repositories/1/apache/resolve-latest/jars/resolve-latest-1.3.jar")
343:                        .exists());
344:
345:                // should have updated published ivy version
346:                ModuleDescriptor md = XmlModuleDescriptorParser
347:                        .getInstance()
348:                        .parseDescriptor(
349:                                new IvySettings(),
350:                                new File(
351:                                        "test/repositories/1/apache/resolve-latest/ivys/ivy-1.3.xml")
352:                                        .toURL(), false);
353:                assertEquals("1.3", md.getModuleRevisionId().getRevision());
354:            }
355:
356:            public void testBadNoDeliver() throws Exception {
357:                project.setProperty("ivy.dep.file",
358:                        "test/java/org/apache/ivy/ant/ivy-latest.xml");
359:                IvyResolve res = new IvyResolve();
360:                res.setProject(project);
361:                res.execute();
362:
363:                publish.setPubrevision("1.3");
364:                publish.setResolver("1");
365:                publish.setSrcivypattern("build/test/publish/ivy-1.3.xml");
366:
367:                FileUtil.copy(new File(
368:                        "test/java/org/apache/ivy/ant/ivy-latest.xml"),
369:                        new File("build/test/publish/ivy-1.3.xml"), null);
370:
371:                File art = new File("build/test/publish/resolve-latest-1.3.jar");
372:                FileUtil.copy(new File(
373:                        "test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"),
374:                        art, null);
375:                try {
376:                    publish.execute();
377:                    fail("shouldn't publish ivy file with bad revision");
378:                } catch (BuildException ex) {
379:                    //normal
380:                }
381:            }
382:
383:            public void testReadonly() throws Exception {
384:                project.setProperty("ivy.dep.file",
385:                        "test/java/org/apache/ivy/ant/ivy-simple.xml");
386:                IvyResolve res = new IvyResolve();
387:                res.setProject(project);
388:                res.execute();
389:
390:                publish.setPubrevision("1.2");
391:                publish.setResolver("1");
392:                File art = new File("build/test/publish/resolve-simple-1.2.jar");
393:                FileUtil.copy(new File(
394:                        "test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"),
395:                        art, null);
396:
397:                Echo echo = new Echo();
398:                echo.setProject(project);
399:                echo.setMessage("new version");
400:                echo.setFile(art);
401:                echo.execute();
402:
403:                File dest = new File(
404:                        "test/repositories/1/apache/resolve-simple/jars/resolve-simple-1.2.jar");
405:                FileUtil.copy(new File(
406:                        "test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"),
407:                        dest, null);
408:
409:                echo = new Echo();
410:                echo.setProject(project);
411:                echo.setMessage("old version");
412:                echo.setFile(dest);
413:                echo.execute();
414:
415:                dest.setReadOnly();
416:
417:                try {
418:                    publish.execute();
419:                    fail("by default, publish should fail when a readonly artifact already exist");
420:                } catch (Exception ex) {
421:                    assertTrue(dest.exists());
422:                    BufferedReader reader = new BufferedReader(new FileReader(
423:                            dest));
424:                    assertEquals("old version", reader.readLine());
425:                    reader.close();
426:                }
427:            }
428:
429:            public void testOverwrite() throws Exception {
430:                project.setProperty("ivy.dep.file",
431:                        "test/java/org/apache/ivy/ant/ivy-simple.xml");
432:                IvyResolve res = new IvyResolve();
433:                res.setProject(project);
434:                res.execute();
435:
436:                publish.setPubrevision("1.2");
437:                publish.setResolver("1");
438:                File art = new File("build/test/publish/resolve-simple-1.2.jar");
439:                FileUtil.copy(new File(
440:                        "test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"),
441:                        art, null);
442:
443:                Echo echo = new Echo();
444:                echo.setProject(project);
445:                echo.setMessage("new version");
446:                echo.setFile(art);
447:                echo.execute();
448:
449:                File dest = new File(
450:                        "test/repositories/1/apache/resolve-simple/jars/resolve-simple-1.2.jar");
451:                FileUtil.copy(new File(
452:                        "test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"),
453:                        dest, null);
454:
455:                echo = new Echo();
456:                echo.setProject(project);
457:                echo.setMessage("old version");
458:                echo.setFile(dest);
459:                echo.execute();
460:
461:                publish.setOverwrite(true);
462:                publish.execute();
463:                assertTrue(dest.exists());
464:                BufferedReader reader = new BufferedReader(new FileReader(dest));
465:                assertEquals("new version", reader.readLine());
466:                reader.close();
467:            }
468:
469:            public void testOverwriteReadOnly() throws Exception {
470:                project.setProperty("ivy.dep.file",
471:                        "test/java/org/apache/ivy/ant/ivy-simple.xml");
472:                IvyResolve res = new IvyResolve();
473:                res.setProject(project);
474:                res.execute();
475:
476:                publish.setPubrevision("1.2");
477:                publish.setResolver("1");
478:                File art = new File("build/test/publish/resolve-simple-1.2.jar");
479:                FileUtil.copy(new File(
480:                        "test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"),
481:                        art, null);
482:
483:                Echo echo = new Echo();
484:                echo.setProject(project);
485:                echo.setMessage("new version");
486:                echo.setFile(art);
487:                echo.execute();
488:
489:                File dest = new File(
490:                        "test/repositories/1/apache/resolve-simple/jars/resolve-simple-1.2.jar");
491:                FileUtil.copy(new File(
492:                        "test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"),
493:                        dest, null);
494:
495:                echo = new Echo();
496:                echo.setProject(project);
497:                echo.setMessage("old version");
498:                echo.setFile(dest);
499:                echo.execute();
500:
501:                dest.setReadOnly();
502:
503:                publish.setOverwrite(true);
504:                publish.execute();
505:                assertTrue(dest.exists());
506:                BufferedReader reader = new BufferedReader(new FileReader(dest));
507:                assertEquals("new version", reader.readLine());
508:                reader.close();
509:            }
510:
511:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.