KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > nbbuild > ModuleDependenciesTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.nbbuild;
21
22 import java.io.ByteArrayOutputStream JavaDoc;
23 import java.io.File JavaDoc;
24 import java.io.FileOutputStream JavaDoc;
25 import java.io.FileReader JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.io.InputStream JavaDoc;
28 import java.util.Arrays JavaDoc;
29 import java.util.StringTokenizer JavaDoc;
30 import java.util.jar.JarEntry JavaDoc;
31 import java.util.jar.JarOutputStream JavaDoc;
32 import java.util.jar.Manifest JavaDoc;
33 import java.util.regex.Matcher JavaDoc;
34 import java.util.regex.Pattern JavaDoc;
35 import java.util.zip.ZipEntry JavaDoc;
36 import java.util.zip.ZipOutputStream JavaDoc;
37 import junit.framework.*;
38
39 import org.netbeans.junit.*;
40
41
42 /** Check the behaviour ModuleDependencies task that prints out info about
43  * module dependencies, etc.
44  *
45  * @author Jaroslav Tulach
46  */

47 public class ModuleDependenciesTest extends NbTestCase {
48     public ModuleDependenciesTest (String JavaDoc name) {
49         super (name);
50     }
51     /*
52     public void testJustMakeSureWeAreAbleToParseTheStructure () throws Exception {
53         java.io.File f = PublicPackagesInProjectizedXMLTest.extractString (
54             "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
55             "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" +
56             " <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" +
57             "<target name=\"all\" >" +
58             " <deps>" +
59             " <input name=\"ahoj\" >" +
60             " <jars dir=\"${nb_all}/nbbuild\" > " +
61             " <include name=\"nbantext.jar\" />" +
62             " </jars>" +
63             " </input>" +
64             " <output type=\"public-packages\" file=\"file.txt\" />" +
65             " </deps >" +
66             " " +
67             "</target>" +
68             "</project>"
69
70         );
71         PublicPackagesInProjectizedXMLTest.execute (f, new String[] { });
72     }*/

73     
74     public void testPublicPackagesOfAModuleThatDoesNotDefineThem () throws Exception JavaDoc {
75         File JavaDoc notAModule = generateJar (new String JavaDoc[] { "not/X.class", "not/resource/X.html" }, createManifest ());
76         
77         Manifest JavaDoc m = createManifest ();
78         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
79         File JavaDoc withoutPkgs = generateJar (new String JavaDoc[] { "DefaultPkg.class", "is/X.class", "is/too/MyClass.class", "not/as/it/is/resource/X.xml" }, m);
80         
81         m = createManifest ();
82         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/3");
83         m.getMainAttributes ().putValue ("OpenIDE-Module-Public-Packages", "is.there.*, is.recursive.**");
84         File JavaDoc withPkgs = generateJar (new String JavaDoc[] { "is/there/A.class", "not/there/B.class", "is/recursive/Root.class", "is/recursive/sub/Under.class", "not/res/X.jpg"}, m);
85
86         m = createManifest ();
87         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.very.public.module/10");
88         m.getMainAttributes ().putValue ("OpenIDE-Module-Public-Packages", "-");
89         File JavaDoc allPkgs = generateJar (new String JavaDoc[] { "not/very/A.class", "not/very/B.class", "not/very/sub/Root.class", "not/res/X.jpg"}, m);
90         
91         File JavaDoc parent = notAModule.getParentFile ();
92         assertEquals ("All parents are the same 1", parent, withoutPkgs.getParentFile ());
93         assertEquals ("All parents are the same 2", parent, withPkgs.getParentFile ());
94         assertEquals ("All parents are the same 3", parent, allPkgs.getParentFile ());
95         
96         
97         File JavaDoc output = PublicPackagesInProjectizedXMLTest.extractString ("");
98         output.delete ();
99         assertFalse ("Is gone", output.exists ());
100         java.io.File JavaDoc f = PublicPackagesInProjectizedXMLTest.extractString (
101             "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
102             "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" +
103             " <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" +
104             "<target name=\"all\" >" +
105             " <deps>" +
106             " <input name=\"ahoj\" >" +
107             " <jars dir=\"" + parent + "\" > " +
108             " <include name=\"" + notAModule.getName () + "\" />" +
109             " <include name=\"" + withoutPkgs.getName () + "\" />" +
110             " <include name=\"" + withPkgs.getName () + "\" />" +
111             " <include name=\"" + allPkgs.getName () + "\" />" +
112             " </jars>" +
113             " </input>" +
114             " <output type=\"public-packages\" file=\"" + output + "\" />" +
115             " </deps >" +
116             "</target>" +
117             "</project>"
118         );
119         PublicPackagesInProjectizedXMLTest.execute (f, new String JavaDoc[] { "-verbose" });
120         
121         assertTrue ("Result generated", output.exists ());
122         
123         String JavaDoc res = readFile (output);
124         
125         assertEquals ("No not package", -1, res.indexOf ("not"));
126         assertTrue ("Some of is pkgs: " + res, res.indexOf ("is\n") >= 0);
127         assertEquals ("No default pkg", -1, res.indexOf ("\n\n"));
128         assertTrue ("is there resursive: " + res, res.indexOf ("is.recursive\n") >= 0);
129         assertTrue ("is there too: " + res, res.indexOf ("is.too\n") >= 0);
130     }
131
132     public void testPublicPackagesInAModuleThatDeclaresFriendsAreNotCounted() throws Exception JavaDoc {
133         File JavaDoc notAModule = generateJar (new String JavaDoc[] { "not/X.class", "not/resource/X.html" }, createManifest ());
134         
135         Manifest JavaDoc m = createManifest ();
136         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
137         m.getMainAttributes ().putValue ("OpenIDE-Module-Friends", "my.very.public.module");
138         File JavaDoc withoutPkgs = generateJar (new String JavaDoc[] { "DefaultPkg.class", "just/friend/X.class", "just/friend/MyClass.class", "not/as/it/is/resource/X.xml" }, m);
139         
140         m = createManifest ();
141         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/3");
142         m.getMainAttributes ().putValue ("OpenIDE-Module-Public-Packages", "friend.there.*, friend.recursive.**");
143         m.getMainAttributes ().putValue ("OpenIDE-Module-Friends", "my.very.public.module");
144         File JavaDoc withPkgs = generateJar (new String JavaDoc[] { "friend/there/A.class", "not/there/B.class", "friend/recursive/Root.class", "friend/recursive/sub/Under.class", "not/res/X.jpg"}, m);
145
146         m = createManifest ();
147         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.very.public.module/10");
148         m.getMainAttributes ().putValue ("OpenIDE-Module-Public-Packages", "-");
149         File JavaDoc allPkgs = generateJar (new String JavaDoc[] { "not/very/A.class", "not/very/B.class", "not/very/sub/Root.class", "not/res/X.jpg"}, m);
150         
151         File JavaDoc parent = notAModule.getParentFile ();
152         assertEquals ("All parents are the same 1", parent, withoutPkgs.getParentFile ());
153         assertEquals ("All parents are the same 2", parent, withPkgs.getParentFile ());
154         assertEquals ("All parents are the same 3", parent, allPkgs.getParentFile ());
155         
156         
157         File JavaDoc output = PublicPackagesInProjectizedXMLTest.extractString ("");
158         output.delete ();
159         File JavaDoc friendPkg = PublicPackagesInProjectizedXMLTest.extractString ("");
160         friendPkg.delete ();
161     assertFalse ("Is gone", output.exists ());
162         java.io.File JavaDoc f = PublicPackagesInProjectizedXMLTest.extractString (
163             "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
164             "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" +
165             " <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" +
166             "<target name=\"all\" >" +
167             " <deps>" +
168             " <input name=\"ahoj\" >" +
169             " <jars dir=\"" + parent + "\" > " +
170             " <include name=\"" + notAModule.getName () + "\" />" +
171             " <include name=\"" + withoutPkgs.getName () + "\" />" +
172             " <include name=\"" + withPkgs.getName () + "\" />" +
173             " <include name=\"" + allPkgs.getName () + "\" />" +
174             " </jars>" +
175             " </input>" +
176             " <output type=\"public-packages\" file=\"" + output + "\" />" +
177             " <output type=\"friend-packages\" file=\"" + friendPkg + "\" />" +
178             " </deps >" +
179             "</target>" +
180             "</project>"
181         );
182         PublicPackagesInProjectizedXMLTest.execute (f, new String JavaDoc[] { "-verbose" });
183         
184         assertTrue ("Result generated", output.exists ());
185         
186         String JavaDoc res = readFile (output);
187         
188     if (!res.equals("\n")) {
189         fail("No public packages:\n" + res);
190     }
191     
192     // now friend packages
193
res = readFile(friendPkg);
194     
195     Matcher JavaDoc match = Pattern.compile("MODULE ([^ ]*)").matcher(res);
196     assertTrue("One MODULE is there: " + res, match.find());
197     int fst = match.start();
198     assertEquals("my.another.module/3", match.group(1));
199     
200     assertTrue("Second MODULE is there: " + res, match.find());
201     int snd = match.start();
202     assertEquals("my.module/3", match.group(1));
203
204     match = Pattern.compile(" FRIEND my.very.public.module/10 \\(ahoj\\)").matcher(res);
205     assertTrue("One FRIEND is there: " + res, match.find());
206     assertTrue("Second FRIEND is there: " + res, match.find());
207     
208     assertTrue("FriendPkg1\n" + res, res.indexOf("just.friend") >= snd);
209     assertTrue("FriendPkg2\n" + res, res.indexOf("friend.there") >= fst);
210     
211     }
212     public void testThereCanBeLimitOnNumberOfFriends() throws Exception JavaDoc {
213         File JavaDoc notAModule = generateJar (new String JavaDoc[] { "not/X.class", "not/resource/X.html" }, createManifest ());
214         
215         Manifest JavaDoc m = createManifest ();
216         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
217         m.getMainAttributes ().putValue ("OpenIDE-Module-Friends", "my.very.public.module");
218         File JavaDoc withoutPkgs = generateJar (new String JavaDoc[] { "DefaultPkg.class", "just/friend/X.class", "just/friend/MyClass.class", "not/as/it/is/resource/X.xml" }, m);
219         
220         m = createManifest ();
221         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/3");
222         m.getMainAttributes ().putValue ("OpenIDE-Module-Public-Packages", "friend.there.*, friend.recursive.**");
223         m.getMainAttributes ().putValue ("OpenIDE-Module-Friends", "my.very.public.module, my.module");
224         File JavaDoc withPkgs = generateJar (new String JavaDoc[] { "friend/there/A.class", "not/there/B.class", "friend/recursive/Root.class", "friend/recursive/sub/Under.class", "not/res/X.jpg"}, m);
225
226         m = createManifest ();
227         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.very.public.module/10");
228         m.getMainAttributes ().putValue ("OpenIDE-Module-Public-Packages", "-");
229         File JavaDoc allPkgs = generateJar (new String JavaDoc[] { "not/very/A.class", "not/very/B.class", "not/very/sub/Root.class", "not/res/X.jpg"}, m);
230         
231         File JavaDoc parent = notAModule.getParentFile ();
232         assertEquals ("All parents are the same 1", parent, withoutPkgs.getParentFile ());
233         assertEquals ("All parents are the same 2", parent, withPkgs.getParentFile ());
234         assertEquals ("All parents are the same 3", parent, allPkgs.getParentFile ());
235         
236         
237         File JavaDoc output = PublicPackagesInProjectizedXMLTest.extractString ("");
238         output.delete ();
239         File JavaDoc friendPkg = PublicPackagesInProjectizedXMLTest.extractString ("");
240         friendPkg.delete ();
241         assertFalse ("Is gone", output.exists ());
242         java.io.File JavaDoc f = PublicPackagesInProjectizedXMLTest.extractString (
243             "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
244             "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" +
245             " <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" +
246             "<target name=\"all\" >" +
247             " <property name='deps.max.friends' value='1'/>" +
248             " <deps>" +
249             " <input name=\"ahoj\" >" +
250             " <jars dir=\"" + parent + "\" > " +
251             " <include name=\"" + notAModule.getName () + "\" />" +
252             " <include name=\"" + withoutPkgs.getName () + "\" />" +
253             " <include name=\"" + withPkgs.getName () + "\" />" +
254             " <include name=\"" + allPkgs.getName () + "\" />" +
255             " </jars>" +
256             " </input>" +
257             " <output type=\"public-packages\" file=\"" + output + "\" />" +
258             " <output type=\"friend-packages\" file=\"" + friendPkg + "\" />" +
259             " </deps >" +
260             "</target>" +
261             "</project>"
262         );
263         // this should succeed now, as the limit applies only to intercluster relations - #87076
264
PublicPackagesInProjectizedXMLTest.execute (f, new String JavaDoc[] { "-verbose" });
265     }
266
267     public void testThereCanBeLimitOnNumberOfFriendsAmongGroups() throws Exception JavaDoc {
268         File JavaDoc notAModule = generateJar (new String JavaDoc[] { "not/X.class", "not/resource/X.html" }, createManifest ());
269         
270         Manifest JavaDoc m = createManifest ();
271         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
272         m.getMainAttributes ().putValue ("OpenIDE-Module-Friends", "my.very.public.module");
273         File JavaDoc myModule = generateJar (new String JavaDoc[] { "DefaultPkg.class", "just/friend/X.class", "just/friend/MyClass.class", "not/as/it/is/resource/X.xml" }, m);
274         
275         m = createManifest ();
276         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/3");
277         m.getMainAttributes ().putValue ("OpenIDE-Module-Public-Packages", "friend.there.*, friend.recursive.**");
278         m.getMainAttributes ().putValue ("OpenIDE-Module-Friends", "my.very.public.module, my.module");
279         File JavaDoc myAnotherModule = generateJar (new String JavaDoc[] { "friend/there/A.class", "not/there/B.class", "friend/recursive/Root.class", "friend/recursive/sub/Under.class", "not/res/X.jpg"}, m);
280
281         m = createManifest ();
282         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.very.public.module/10");
283         m.getMainAttributes ().putValue ("OpenIDE-Module-Public-Packages", "-");
284         File JavaDoc myVeryPublicModule = generateJar (new String JavaDoc[] { "not/very/A.class", "not/very/B.class", "not/very/sub/Root.class", "not/res/X.jpg"}, m);
285         
286         File JavaDoc parent = notAModule.getParentFile ();
287         assertEquals ("All parents are the same 1", parent, myModule.getParentFile ());
288         assertEquals ("All parents are the same 2", parent, myAnotherModule.getParentFile ());
289         assertEquals ("All parents are the same 3", parent, myVeryPublicModule.getParentFile ());
290         
291         
292         File JavaDoc friendPkg = PublicPackagesInProjectizedXMLTest.extractString ("");
293         friendPkg.delete ();
294         assertFalse ("Is gone", friendPkg.exists ());
295         java.io.File JavaDoc f = PublicPackagesInProjectizedXMLTest.extractString (
296             "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
297             "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" +
298             " <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" +
299             "<target name=\"all\" >" +
300             " <property name='deps.max.friends' value='${limit}'/>" +
301             " <deps>" +
302             " <input name=\"base\" >" +
303             " <jars dir=\"" + parent + "\" > " +
304             " <include name=\"" + notAModule.getName () + "\" />" +
305             " <include name=\"" + myAnotherModule.getName () + "\" />" +
306             " </jars>" +
307             " </input>" +
308             " <input name=\"extra\" >" +
309             " <jars dir=\"" + parent + "\" > " +
310             " <include name=\"" + myModule.getName () + "\" />" +
311             " <include name=\"" + myVeryPublicModule.getName () + "\" />" +
312             " </jars>" +
313             " </input>" +
314             " <output type=\"group-friend-packages\" file=\"" + friendPkg + "\" />" +
315             " </deps >" +
316             "</target>" +
317             "</project>"
318         );
319
320         // this will succeed, limit of 5 is ok
321
PublicPackagesInProjectizedXMLTest.execute (f, new String JavaDoc[] { "-verbose", "-Dlimit=5" });
322         
323         String JavaDoc res = readFile (friendPkg);
324
325         if (!res.equals(
326             "MODULE my.another.module/3 (base)\n" +
327             " FRIEND my.module/3 (extra)\n" +
328             " FRIEND my.very.public.module/10 (extra)\n" +
329             " PACKAGE friend.recursive\n" +
330             " PACKAGE friend.recursive.sub\n" +
331             " PACKAGE friend.there\n" +
332             ""
333         )) {
334             fail("Unexpected res:\n" + res);
335         }
336         
337         
338         friendPkg.delete();
339         
340         try {
341             PublicPackagesInProjectizedXMLTest.execute (f, new String JavaDoc[] { "-verbose", "-Dlimit=1" });
342             fail("This should fail");
343         } catch (PublicPackagesInProjectizedXMLTest.ExecutionError ex) {
344             if (PublicPackagesInProjectizedXMLTest.getStdErr().indexOf("Too many intercluster friends") == -1) {
345                 fail("There should be a message about too many friends:\n" + PublicPackagesInProjectizedXMLTest.getStdErr());
346             }
347         }
348     }
349     
350     public void testThereExternalsAreCountedAsWell() throws Exception JavaDoc {
351         File JavaDoc notAModule = generateJar (new String JavaDoc[] { "not/X.class", "not/resource/X.html" }, createManifest ());
352         
353         Manifest JavaDoc m = createManifest ();
354         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
355         m.getMainAttributes ().putValue ("OpenIDE-Module-Friends", "my.very.public.module");
356         File JavaDoc myModule = generateJar (new String JavaDoc[] { "DefaultPkg.class", "just/friend/X.class", "just/friend/MyClass.class", "not/as/it/is/resource/X.xml" }, m);
357         
358         m = createManifest ();
359         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/3");
360         m.getMainAttributes ().putValue ("OpenIDE-Module-Public-Packages", "friend.there.*, friend.recursive.**");
361         m.getMainAttributes ().putValue ("OpenIDE-Module-Friends", "my.very.public.module, my.module");
362         File JavaDoc myAnotherModule = generateJar (new String JavaDoc[] { "friend/there/A.class", "not/there/B.class", "friend/recursive/Root.class", "friend/recursive/sub/Under.class", "not/res/X.jpg"}, m);
363
364         m = createManifest ();
365         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.very.public.module/10");
366         m.getMainAttributes ().putValue ("OpenIDE-Module-Public-Packages", "-");
367         File JavaDoc myVeryPublicModule = generateJar (new String JavaDoc[] { "not/very/A.class", "not/very/B.class", "not/very/sub/Root.class", "not/res/X.jpg"}, m);
368         
369         File JavaDoc parent = notAModule.getParentFile ();
370         assertEquals ("All parents are the same 1", parent, myModule.getParentFile ());
371         assertEquals ("All parents are the same 2", parent, myAnotherModule.getParentFile ());
372         assertEquals ("All parents are the same 3", parent, myVeryPublicModule.getParentFile ());
373         
374         
375         File JavaDoc friendPkg = PublicPackagesInProjectizedXMLTest.extractString ("");
376         friendPkg.delete ();
377         assertFalse ("Is gone", friendPkg.exists ());
378         java.io.File JavaDoc f = PublicPackagesInProjectizedXMLTest.extractString (
379             "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
380             "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" +
381             " <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" +
382             "<target name=\"all\" >" +
383             " <property name='deps.max.friends' value='${limit}'/>" +
384             " <deps>" +
385             " <input name=\"base\" >" +
386             " <jars dir=\"" + parent + "\" > " +
387             " <include name=\"" + notAModule.getName () + "\" />" +
388             " <include name=\"" + myAnotherModule.getName () + "\" />" +
389             " </jars>" +
390             " </input>" +
391             " <output type=\"group-friend-packages\" file=\"" + friendPkg + "\" />" +
392             " </deps >" +
393             "</target>" +
394             "</project>"
395         );
396
397         // this will succeed, limit of 5 is ok
398
PublicPackagesInProjectizedXMLTest.execute (f, new String JavaDoc[] { "-verbose", "-Dlimit=5" });
399         
400         String JavaDoc res = readFile (friendPkg);
401
402         if (!res.equals(
403             "MODULE my.another.module/3 (base)\n" +
404             " EXTERNAL my.module\n" +
405             " EXTERNAL my.very.public.module\n" +
406             " PACKAGE friend.recursive\n" +
407             " PACKAGE friend.recursive.sub\n" +
408             " PACKAGE friend.there\n" +
409             ""
410         )) {
411             fail("Unexpected res:\n" + res);
412         }
413         
414         
415         friendPkg.delete();
416         
417         try {
418             PublicPackagesInProjectizedXMLTest.execute (f, new String JavaDoc[] { "-verbose", "-Dlimit=1" });
419             fail("This should fail");
420         } catch (PublicPackagesInProjectizedXMLTest.ExecutionError ex) {
421             if (PublicPackagesInProjectizedXMLTest.getStdErr().indexOf("Too many intercluster friends") == -1) {
422                 fail("There should be a message about too many friends:\n" + PublicPackagesInProjectizedXMLTest.getStdErr());
423             }
424         }
425     }
426     
427     public void testMd5CheckSumForExternalBinaries() throws Exception JavaDoc {
428         File JavaDoc notAModule = generateJar (new String JavaDoc[] { "not/X.class", "not/resource/X.html" }, createManifest ());
429         
430         Manifest JavaDoc m = createManifest ();
431         m.getMainAttributes ().putValue ("NetBeans-Own-Library", "true");
432         File JavaDoc withoutPkgs = generateJar (new String JavaDoc[] { "DefaultPkg.class", "is/X.class", "is/too/MyClass.class", "not/as/it/is/resource/X.xml" }, m);
433         
434         m = createManifest ();
435         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/3");
436         m.getMainAttributes ().putValue ("OpenIDE-Module-Public-Packages", "is.there.*, is.recursive.**");
437         File JavaDoc withPkgs = generateJar (new String JavaDoc[] { "is/there/A.class", "not/there/B.class", "is/recursive/Root.class", "is/recursive/sub/Under.class", "not/res/X.jpg"}, m);
438
439         m = createManifest ();
440         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.very.public.module/10");
441         m.getMainAttributes ().putValue ("OpenIDE-Module-Public-Packages", "-");
442         File JavaDoc allPkgs = generateJar (new String JavaDoc[] { "not/very/A.class", "not/very/B.class", "not/very/sub/Root.class", "not/res/X.jpg"}, m);
443         
444         File JavaDoc parent = notAModule.getParentFile ();
445         assertEquals ("All parents are the same 1", parent, withoutPkgs.getParentFile ());
446         assertEquals ("All parents are the same 2", parent, withPkgs.getParentFile ());
447         assertEquals ("All parents are the same 3", parent, allPkgs.getParentFile ());
448         
449         
450         File JavaDoc output = PublicPackagesInProjectizedXMLTest.extractString ("");
451         output.delete ();
452         assertFalse ("Is gone", output.exists ());
453         java.io.File JavaDoc f = PublicPackagesInProjectizedXMLTest.extractString (
454             "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
455             "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" +
456             " <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" +
457             "<target name=\"all\" >" +
458             " <deps>" +
459             " <input name=\"ahoj\" >" +
460             " <jars dir=\"" + parent + "\" > " +
461             " <include name=\"" + notAModule.getName () + "\" />" +
462             " <include name=\"" + withoutPkgs.getName () + "\" />" +
463             " <include name=\"" + withPkgs.getName () + "\" />" +
464             " <include name=\"" + allPkgs.getName () + "\" />" +
465             " </jars>" +
466             " </input>" +
467             " <output type=\"external-libraries\" file=\"" + output + "\" />" +
468             " </deps >" +
469             "</target>" +
470             "</project>"
471         );
472         PublicPackagesInProjectizedXMLTest.execute (f, new String JavaDoc[] { "-verbose" });
473         
474         assertTrue ("Result generated", output.exists ());
475         
476         String JavaDoc res = readFile (output);
477         
478         assertEquals ("No slashes", -1, res.indexOf ("/"));
479         assertEquals ("No back slashes", -1, res.indexOf ("\\"));
480         
481         assertEquals ("No module1", -1, res.indexOf (withPkgs.getName ()));
482         assertEquals ("No module2", -1, res.indexOf (allPkgs.getName ()));
483         assertEquals ("Specially marked nb package is not there either", -1, res.indexOf (withoutPkgs.getName ()));
484         assertTrue ("There is just the one JAR: " + res, res.indexOf (notAModule.getName ()) >= 0);
485         assertTrue ("And its size: " + res, res.indexOf (String.valueOf (notAModule.length ())) >= 0);
486     }
487
488     
489     public void testPublicPackagesOfAModuleThatDoesNotDefineThemButTheyAreProvidedByModuleTheModuleDependsOn () throws Exception JavaDoc {
490         File JavaDoc notAModule = generateJar (new String JavaDoc[] { "is/cp/X.class", "not/cp/resource/X.html" }, createManifest ());
491         
492         Manifest JavaDoc m = createManifest ();
493         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
494         m.getMainAttributes ().putValue ("Class-Path", notAModule.getName ());
495         File JavaDoc withoutPkgs = generateJar (new String JavaDoc[] { "DefaultPkg.class", "is/X.class", "is/too/MyClass.class", "not/as/it/is/resource/X.xml" }, m);
496         
497         File JavaDoc parent = notAModule.getParentFile ();
498         assertEquals ("All parents are the same 1", parent, withoutPkgs.getParentFile ());
499         
500         
501         File JavaDoc output = PublicPackagesInProjectizedXMLTest.extractString ("");
502         output.delete ();
503         assertFalse ("Is gone", output.exists ());
504         java.io.File JavaDoc f = PublicPackagesInProjectizedXMLTest.extractString (
505             "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
506             "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" +
507             " <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" +
508             "<target name=\"all\" >" +
509             " <deps>" +
510             " <input name=\"ahoj\" >" +
511             " <jars dir='" + parent + "' > " +
512             " <include name='" + notAModule.getName () + "' />" +
513             " <include name='" + withoutPkgs.getName () + "' />" +
514             " </jars>" +
515             " </input>" +
516             " <output type=\"public-packages\" file=\"" + output + "\" />" +
517             " </deps >" +
518             "</target>" +
519             "</project>"
520         );
521         PublicPackagesInProjectizedXMLTest.execute (f, new String JavaDoc[] { "-verbose" });
522         
523         assertTrue ("Result generated", output.exists ());
524         
525         String JavaDoc res = readFile (output);
526         
527         assertEquals ("No not package", -1, res.indexOf ("not"));
528         assertTrue ("Some of is pkgs: " + res, res.indexOf ("is\n") >= 0);
529         assertTrue ("is/too pkgs: " + res, res.indexOf ("is.too\n") >= 0);
530         assertEquals ("No default pkg", -1, res.indexOf ("\n\n"));
531         assertTrue ("is/cp is there as well as the withoutPkgs module depends on notAModule: " + res, res.indexOf ("is.cp\n") >= 0);
532     }
533     
534     public void testNameOfModuleWithoutMajorVersionDoesNotContainSlash () throws Exception JavaDoc {
535         Manifest JavaDoc m = createManifest ();
536         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module");
537         File JavaDoc module = generateJar (new String JavaDoc[] { "something" }, m);
538         
539         File JavaDoc parent = module.getParentFile ();
540         
541         
542         File JavaDoc output = PublicPackagesInProjectizedXMLTest.extractString ("");
543         output.delete ();
544         assertFalse ("Is gone", output.exists ());
545         java.io.File JavaDoc f = PublicPackagesInProjectizedXMLTest.extractString (
546             "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
547             "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" +
548             " <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" +
549             "<target name=\"all\" >" +
550             " <deps>" +
551             " <input name=\"ahoj\" >" +
552             " <jars dir=\"" + parent + "\" > " +
553             " <include name=\"" + module.getName () + "\" />" +
554             " </jars>" +
555             " </input>" +
556             " <output type=\"modules\" file=\"" + output + "\" />" +
557             " </deps >" +
558             "</target>" +
559             "</project>"
560         );
561         PublicPackagesInProjectizedXMLTest.execute (f, new String JavaDoc[] { "-verbose" });
562         
563         assertTrue ("Result generated", output.exists ());
564         
565         String JavaDoc res = readFile (output);
566
567         assertEquals ("Starts with MODULE", 0, res.indexOf ("MODULE"));
568         assertTrue ("module name is there" + res, res.indexOf ("my.module") > 0);
569         assertEquals ("no slash is there", -1, res.indexOf ('/'));
570     }
571     
572     
573     public void testGenerateListOfModules () throws Exception JavaDoc {
574         File JavaDoc notAModule = generateJar (new String JavaDoc[] { "not/X.class", "not/resource/X.html" }, createManifest ());
575         
576         Manifest JavaDoc m = createManifest ();
577         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
578         File JavaDoc withoutPkgs = generateJar (new String JavaDoc[] { "DefaultPkg.class", "is/X.class", "is/too/MyClass.class", "not/as/it/is/resource/X.xml" }, m);
579         
580         m = createManifest ();
581         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/3");
582         m.getMainAttributes ().putValue ("OpenIDE-Module-Public-Packages", "is.there.*, is.recursive.**");
583         File JavaDoc withPkgs = generateJar (new String JavaDoc[] { "is/there/A.class", "not/there/B.class", "is/recursive/Root.class", "is/recursive/sub/Under.class", "not/res/X.jpg"}, m);
584         
585         File JavaDoc parent = notAModule.getParentFile ();
586         assertEquals ("All parents are the same 1", parent, withoutPkgs.getParentFile ());
587         assertEquals ("All parents are the same 2", parent, withPkgs.getParentFile ());
588         
589         
590         File JavaDoc output = PublicPackagesInProjectizedXMLTest.extractString ("");
591         output.delete ();
592         assertFalse ("Is gone", output.exists ());
593         java.io.File JavaDoc f = PublicPackagesInProjectizedXMLTest.extractString (
594             "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
595             "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" +
596             " <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" +
597             "<target name=\"all\" >" +
598             " <deps>" +
599             " <input name=\"ahoj\" >" +
600             " <jars dir=\"" + parent + "\" > " +
601             " <include name=\"" + notAModule.getName () + "\" />" +
602             " <include name=\"" + withoutPkgs.getName () + "\" />" +
603             " <include name=\"" + withPkgs.getName () + "\" />" +
604             " </jars>" +
605             " </input>" +
606             " <output type=\"modules\" file=\"" + output + "\" />" +
607             " </deps >" +
608             "</target>" +
609             "</project>"
610         );
611         PublicPackagesInProjectizedXMLTest.execute (f, new String JavaDoc[] { "-verbose" });
612         
613         assertTrue ("Result generated", output.exists ());
614         
615         String JavaDoc res = readFile (output);
616         StringTokenizer JavaDoc tok = new StringTokenizer JavaDoc (res, "\n\r");
617         
618         assertEquals ("We have two modules: " + res, 2, tok.countTokens ());
619         assertEquals ("First contains another module, as it is sooner in alhabet\n" + res, "MODULE my.another.module/3 (ahoj)", tok.nextToken ());
620         assertEquals ("Second the next one" + res, "MODULE my.module/3 (ahoj)", tok.nextToken ());
621         assertFalse ("No next tokens", tok.hasMoreElements ());
622     }
623     
624     public void testGenerateModuleDependencies () throws Exception JavaDoc {
625         Manifest JavaDoc openideManifest = createManifest ();
626         openideManifest.getMainAttributes ().putValue ("OpenIDE-Module", "org.openide/1");
627         File JavaDoc openide = generateJar (new String JavaDoc[] { "notneeded" }, openideManifest);
628         
629         Manifest JavaDoc m = createManifest ();
630         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
631         m.getMainAttributes ().putValue ("OpenIDE-Module-Module-Dependencies", "org.openide/1 > 4.17");
632         File JavaDoc withoutPkgs = generateJar (new String JavaDoc[] { "notneeded" }, m);
633         
634         m = createManifest ();
635         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/3");
636         m.getMainAttributes ().putValue ("OpenIDE-Module-Module-Dependencies", "my.module/3, org.openide/1 > 4.17");
637         File JavaDoc withPkgs = generateJar (new String JavaDoc[] { "some content"}, m);
638         
639         File JavaDoc parent = openide.getParentFile ();
640         assertEquals ("All parents are the same 1", parent, withoutPkgs.getParentFile ());
641         assertEquals ("All parents are the same 2", parent, withPkgs.getParentFile ());
642         
643         
644         File JavaDoc output = PublicPackagesInProjectizedXMLTest.extractString ("");
645         output.delete ();
646         assertFalse ("Is gone", output.exists ());
647         java.io.File JavaDoc f = PublicPackagesInProjectizedXMLTest.extractString (
648             "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
649             "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" +
650             " <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" +
651             "<target name=\"all\" >" +
652             " <deps>" +
653             " <input name=\"platform\" >" +
654             " <jars dir=\"" + parent + "\" > " +
655             " <include name=\"" + openide.getName () + "\" />" +
656             " </jars>" +
657             " </input>" +
658             " <input name=\"ahoj\" >" +
659             " <jars dir=\"" + parent + "\" > " +
660             " <include name=\"" + withoutPkgs.getName () + "\" />" +
661             " <include name=\"" + withPkgs.getName () + "\" />" +
662             " </jars>" +
663             " </input>" +
664             " <output type=\"dependencies\" file=\"" + output + "\" />" +
665             " </deps >" +
666             "</target>" +
667             "</project>"
668         );
669         PublicPackagesInProjectizedXMLTest.execute (f, new String JavaDoc[] { "-verbose" });
670         
671         assertTrue ("Result generated", output.exists ());
672         
673         String JavaDoc res = readFile (output);
674         int y = res.indexOf ("MODULE", 1);
675         if (y <= 0) {
676             fail ("There is another module: " + y + " res: " + res);
677         }
678         assertEquals ("No other", -1, res.indexOf ("MODULE", y + 1));
679
680         // f1 is later due to algebraic sorting of modules!!!!
681
StringTokenizer JavaDoc f2 = new StringTokenizer JavaDoc (res.substring (0, y), "\r\n");
682         StringTokenizer JavaDoc f1 = new StringTokenizer JavaDoc (res.substring (y), "\r\n");
683         
684         assertEquals ("One line + one dep for f1\n" + res, 2, f1.countTokens ());
685         f1.nextToken ();
686         String JavaDoc dep1 = f1.nextToken ();
687         assertTrue (dep1, dep1.startsWith (" REQUIRES"));
688         assertTrue ("on " + dep1, dep1.indexOf ("org.openide/1") >= 0);
689         
690         assertEquals ("One line + two dep for f2", 3, f2.countTokens ());
691         f2.nextToken ();
692         String JavaDoc dep2 = f2.nextToken ();
693         assertTrue (dep2, dep2.startsWith (" REQUIRES"));
694         assertTrue ("on my " + dep2, dep2.indexOf ("my.module/3") >= 0);
695         dep2 = f2.nextToken ();
696         assertTrue (dep2, dep2.startsWith (" REQUIRES"));
697         assertTrue ("on " + dep2, dep2.indexOf ("org.openide/1") >= 0);
698         
699     }
700
701     public void testImplementationModuleDependenciesAreRegularDepsAsWell () throws Exception JavaDoc {
702         Manifest JavaDoc openideManifest = createManifest ();
703         openideManifest.getMainAttributes ().putValue ("OpenIDE-Module", "org.openide/1");
704         File JavaDoc openide = generateJar (new String JavaDoc[] { "notneeded" }, openideManifest);
705         
706         Manifest JavaDoc m = createManifest ();
707         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
708         m.getMainAttributes ().putValue ("OpenIDE-Module-Module-Dependencies", "org.openide/1 > 4.17");
709         File JavaDoc withoutPkgs = generateJar (new String JavaDoc[] { "notneeded" }, m);
710         
711         m = createManifest ();
712         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/3");
713         m.getMainAttributes ().putValue ("OpenIDE-Module-Module-Dependencies", "my.module/3 = Ahoj, org.openide/1 > 4.17");
714         File JavaDoc withPkgs = generateJar (new String JavaDoc[] { "some content"}, m);
715         
716         File JavaDoc parent = openide.getParentFile ();
717         assertEquals ("All parents are the same 1", parent, withoutPkgs.getParentFile ());
718         assertEquals ("All parents are the same 2", parent, withPkgs.getParentFile ());
719         
720         
721         File JavaDoc output = PublicPackagesInProjectizedXMLTest.extractString ("");
722         output.delete ();
723         assertFalse ("Is gone", output.exists ());
724         java.io.File JavaDoc f = PublicPackagesInProjectizedXMLTest.extractString (
725             "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
726             "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" +
727             " <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" +
728             "<target name=\"all\" >" +
729             " <deps>" +
730             " <input name=\"platform\" >" +
731             " <jars dir=\"" + parent + "\" > " +
732             " <include name=\"" + openide.getName () + "\" />" +
733             " </jars>" +
734             " </input>" +
735             " <input name=\"ahoj\" >" +
736             " <jars dir=\"" + parent + "\" > " +
737             " <include name=\"" + withoutPkgs.getName () + "\" />" +
738             " <include name=\"" + withPkgs.getName () + "\" />" +
739             " </jars>" +
740             " </input>" +
741             " <output type=\"dependencies\" file=\"" + output + "\" />" +
742             " </deps >" +
743             "</target>" +
744             "</project>"
745         );
746         PublicPackagesInProjectizedXMLTest.execute (f, new String JavaDoc[] { "-verbose" });
747         
748         assertTrue ("Result generated", output.exists ());
749         
750         String JavaDoc res = readFile (output);
751         int x = res.indexOf ("MODULE");
752         assertEquals ("The file starts with MODULE", 0, x);
753         int y = res.indexOf ("MODULE", 1);
754         if (y <= 0) {
755             fail ("There is another module: " + y + " res:\n" + res);
756         }
757         assertEquals ("No other", -1, res.indexOf ("MODULE", y + 1));
758
759         // f1 is later due to algebraic sorting of modules!!!!
760
StringTokenizer JavaDoc f2 = new StringTokenizer JavaDoc (res.substring (0, y), "\r\n");
761         StringTokenizer JavaDoc f1 = new StringTokenizer JavaDoc (res.substring (y), "\r\n");
762         
763         assertEquals ("One line + one dep for f1\n" + res, 2, f1.countTokens ());
764         f1.nextToken ();
765         String JavaDoc dep1 = f1.nextToken ();
766         assertTrue (dep1, dep1.startsWith (" REQUIRES"));
767         assertTrue ("on " + dep1, dep1.indexOf ("org.openide/1") >= 0);
768         
769         assertEquals ("One line + two dep for f2", 3, f2.countTokens ());
770         f2.nextToken ();
771         String JavaDoc dep2 = f2.nextToken ();
772         assertTrue (dep2, dep2.startsWith (" REQUIRES"));
773         assertTrue ("on my " + dep2, dep2.indexOf ("my.module/3") >= 0);
774         dep2 = f2.nextToken ();
775         assertTrue (dep2, dep2.startsWith (" REQUIRES"));
776         assertTrue ("on " + dep2, dep2.indexOf ("org.openide/1") >= 0);
777         
778     }
779
780     public void testGenerateImplementationModuleDependencies () throws Exception JavaDoc {
781         Manifest JavaDoc m = createManifest ();
782         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
783         m.getMainAttributes ().putValue ("OpenIDE-Module-IDE-Dependencies", "IDE/1 > 4.17");
784         File JavaDoc withoutPkgs = generateJar (new String JavaDoc[] { "notneeded" }, m);
785         
786         m = createManifest ();
787         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/3");
788         m.getMainAttributes ().putValue ("OpenIDE-Module-Module-Dependencies", "my.module/3 = Ahoj, org.openide/1 > 4.17");
789         File JavaDoc withPkgs = generateJar (new String JavaDoc[] { "some content"}, m);
790         
791         File JavaDoc parent = withoutPkgs.getParentFile ();
792         assertEquals ("All parents are the same 1", parent, withoutPkgs.getParentFile ());
793         assertEquals ("All parents are the same 2", parent, withPkgs.getParentFile ());
794         
795         
796         File JavaDoc output = PublicPackagesInProjectizedXMLTest.extractString ("");
797         output.delete ();
798         assertFalse ("Is gone", output.exists ());
799         java.io.File JavaDoc f = PublicPackagesInProjectizedXMLTest.extractString (
800             "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
801             "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" +
802             " <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" +
803             "<target name=\"all\" >" +
804             " <deps>" +
805             " <input name=\"ahoj\" >" +
806             " <jars dir=\"" + parent + "\" > " +
807             " <include name=\"" + withoutPkgs.getName () + "\" />" +
808             " <include name=\"" + withPkgs.getName () + "\" />" +
809             " </jars>" +
810             " </input>" +
811             " <output type=\"implementation-dependencies\" file=\"" + output + "\" />" +
812             " </deps >" +
813             "</target>" +
814             "</project>"
815         );
816         PublicPackagesInProjectizedXMLTest.execute (f, new String JavaDoc[] { "-verbose" });
817         
818         assertTrue ("Result generated", output.exists ());
819         
820         String JavaDoc res = readFile (output);
821         int x = res.indexOf ("MODULE");
822         assertEquals ("The file starts with MODULE", 0, x);
823         int y = res.indexOf ("MODULE", 1);
824         assertEquals ("No other:\n" + res, -1, y);
825
826         StringTokenizer JavaDoc f1 = new StringTokenizer JavaDoc (res, "\r\n");
827         
828         assertEquals ("One line + one dep for f1\n" + res, 2, f1.countTokens ());
829         String JavaDoc modulename = f1.nextToken ();
830         assertTrue ("module is ", modulename.indexOf ("my.another.module") >= 0);
831         String JavaDoc dep1 = f1.nextToken ();
832         assertTrue (dep1, dep1.startsWith (" REQUIRES"));
833         assertTrue ("on " + dep1, dep1.indexOf ("my.module/3") >= 0);
834     }
835     
836     
837     public void testCanOutputJustDependenciesBetweenClusters () throws Exception JavaDoc {
838         Manifest JavaDoc m = createManifest ();
839         m.getMainAttributes ().putValue ("OpenIDE-Module", "org.openide/1");
840         File JavaDoc openide = generateJar (new String JavaDoc[] { "notneeded" }, m);
841         
842         m = createManifest ();
843         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
844         m.getMainAttributes ().putValue ("OpenIDE-Module-IDE-Dependencies", "IDE/1 > 4.17");
845         File JavaDoc withoutPkgs = generateJar (new String JavaDoc[] { "notneeded" }, m);
846         
847         m = createManifest ();
848         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/3");
849         m.getMainAttributes ().putValue ("OpenIDE-Module-Module-Dependencies", "my.module/3 = Ahoj, org.openide/1 > 4.17");
850         File JavaDoc withPkgs = generateJar (new String JavaDoc[] { "some content"}, m);
851         
852         File JavaDoc parent = withoutPkgs.getParentFile ();
853         assertEquals ("All parents are the same 1", parent, withoutPkgs.getParentFile ());
854         assertEquals ("All parents are the same 2", parent, withPkgs.getParentFile ());
855         
856         
857         File JavaDoc output = PublicPackagesInProjectizedXMLTest.extractString ("");
858         output.delete ();
859         assertFalse ("Is gone", output.exists ());
860         java.io.File JavaDoc f = PublicPackagesInProjectizedXMLTest.extractString (
861             "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
862             "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" +
863             " <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" +
864             "<target name=\"all\" >" +
865             " <deps>" +
866             " <input name=\"platform\" >" +
867             " <jars dir=\"" + parent + "\" > " +
868             " <include name=\"" + openide.getName () + "\" />" +
869             " </jars>" +
870             " </input>" +
871             " <input name=\"others\" >" +
872             " <jars dir=\"" + parent + "\" > " +
873             " <include name=\"" + withoutPkgs.getName () + "\" />" +
874             " <include name=\"" + withPkgs.getName () + "\" />" +
875             " </jars>" +
876             " </input>" +
877             " <output type=\"group-dependencies\" file=\"" + output + "\" />" +
878             " </deps >" +
879             "</target>" +
880             "</project>"
881         );
882         PublicPackagesInProjectizedXMLTest.execute (f, new String JavaDoc[] { "-verbose" });
883         
884         assertTrue ("Result generated", output.exists ());
885         
886         String JavaDoc res = readFile (output);
887         int x = res.indexOf ("GROUP");
888         assertEquals ("The file starts with GROUP", 0, x);
889         int y = res.indexOf ("GROUP", 1);
890         assertEquals ("No other:\n" + res, -1, y);
891
892         StringTokenizer JavaDoc f1 = new StringTokenizer JavaDoc (res, "\r\n");
893         
894         assertEquals ("One line + dep on openide\n" + res, 2, f1.countTokens ());
895         String JavaDoc groupname = f1.nextToken ();
896         assertTrue ("group is " + res, groupname.indexOf ("others") >= 0);
897         String JavaDoc dep1 = f1.nextToken ();
898         assertTrue (dep1, dep1.startsWith (" REQUIRES"));
899         assertTrue ("on openide module" + dep1, dep1.indexOf ("org.openide/1") >= 0);
900     }
901     
902     
903
904     public void testCanOutputJustImplDependenciesBetweenClusters () throws Exception JavaDoc {
905         Manifest JavaDoc m = createManifest ();
906         m.getMainAttributes ().putValue ("OpenIDE-Module", "org.openide/1");
907         File JavaDoc openide = generateJar (new String JavaDoc[] { "notneeded" }, m);
908         
909         m = createManifest ();
910         m.getMainAttributes ().putValue ("OpenIDE-Module", "org.netbeans.core/1");
911         File JavaDoc core = generateJar (new String JavaDoc[] { "notneeded" }, m);
912         
913         m = createManifest ();
914         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
915         m.getMainAttributes ().putValue ("OpenIDE-Module-IDE-Dependencies", "IDE/1 > 4.17");
916         File JavaDoc withoutPkgs = generateJar (new String JavaDoc[] { "notneeded" }, m);
917         
918         m = createManifest ();
919         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/3");
920         m.getMainAttributes ().putValue ("OpenIDE-Module-Module-Dependencies", "my.module/3 = Ahoj, org.openide/1 > 4.17");
921         File JavaDoc withPkgs = generateJar (new String JavaDoc[] { "some content"}, m);
922
923         m = createManifest ();
924         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module.dependingoncore/3");
925         m.getMainAttributes ().putValue ("OpenIDE-Module-Module-Dependencies", "org.netbeans.core/1 = Ahoj, my.module/3 > 4.17");
926         File JavaDoc coredepender = generateJar (new String JavaDoc[] { "notneeded" }, m);
927         
928         
929         File JavaDoc parent = withoutPkgs.getParentFile ();
930         assertEquals ("All parents are the same 1", parent, withoutPkgs.getParentFile ());
931         assertEquals ("All parents are the same 2", parent, withPkgs.getParentFile ());
932         
933         
934         File JavaDoc output = PublicPackagesInProjectizedXMLTest.extractString ("");
935         output.delete ();
936         assertFalse ("Is gone", output.exists ());
937         java.io.File JavaDoc f = PublicPackagesInProjectizedXMLTest.extractString (
938             "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
939             "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" +
940             " <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" +
941             "<target name=\"all\" >" +
942             " <deps>" +
943             " <input name=\"platform\" >" +
944             " <jars dir=\"" + parent + "\" > " +
945             " <include name=\"" + openide.getName () + "\" />" +
946             " <include name=\"" + core.getName () + "\" />" +
947             " </jars>" +
948             " </input>" +
949             " <input name=\"others\" >" +
950             " <jars dir=\"" + parent + "\" > " +
951             " <include name=\"" + withoutPkgs.getName () + "\" />" +
952             " <include name=\"" + withPkgs.getName () + "\" />" +
953             " </jars>" +
954             " </input>" +
955             " <input name=\"rest\" >" +
956             " <jars dir=\"" + parent + "\" > " +
957             " <include name=\"" + coredepender.getName () + "\" />" +
958             " </jars>" +
959             " </input>" +
960             " <output type=\"group-implementation-dependencies\" file=\"" + output + "\" />" +
961             " </deps >" +
962             "</target>" +
963             "</project>"
964         );
965         PublicPackagesInProjectizedXMLTest.execute (f, new String JavaDoc[] { "-verbose" });
966         
967         assertTrue ("Result generated", output.exists ());
968         
969         String JavaDoc res = readFile (output);
970         int x = res.indexOf ("GROUP");
971         assertEquals ("The file starts with GROUP", 0, x);
972         int y = res.indexOf ("GROUP", 1);
973         assertEquals ("No other:\n" + res, -1, y);
974
975         StringTokenizer JavaDoc f1 = new StringTokenizer JavaDoc (res, "\r\n");
976         
977         assertEquals ("One line + dep on openide\n" + res, 2, f1.countTokens ());
978         String JavaDoc groupname = f1.nextToken ();
979         assertTrue ("group is " + res, groupname.indexOf ("rest") >= 0);
980         String JavaDoc dep1 = f1.nextToken ();
981         assertTrue (dep1, dep1.startsWith (" REQUIRES"));
982         assertTrue ("on openide module" + dep1, dep1.indexOf ("org.netbeans.core/1") >= 0);
983     }
984     
985     public void testRangeDependencyNeedsToBeParsed () throws Exception JavaDoc {
986         Manifest JavaDoc m = createManifest ();
987         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
988         m.getMainAttributes ().putValue ("OpenIDE-Module-IDE-Dependencies", "IDE/1 > 4.17");
989         File JavaDoc withoutPkgs = generateJar (new String JavaDoc[] { "notneeded" }, m);
990         
991         m = createManifest ();
992         m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/3");
993         m.getMainAttributes ().putValue ("OpenIDE-Module-Module-Dependencies", "my.module/2-3 = Ahoj, org.openide/1-2 > 4.17");
994         File JavaDoc withPkgs = generateJar (new String JavaDoc[] { "some content"}, m);
995         
996         File JavaDoc parent = withoutPkgs.getParentFile ();
997         assertEquals ("All parents are the same 1", parent, withoutPkgs.getParentFile ());
998         assertEquals ("All parents are the same 2", parent, withPkgs.getParentFile ());
999         
1000        
1001        File JavaDoc output = PublicPackagesInProjectizedXMLTest.extractString ("");
1002        output.delete ();
1003        assertFalse ("Is gone", output.exists ());
1004        java.io.File JavaDoc f = PublicPackagesInProjectizedXMLTest.extractString (
1005            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
1006            "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" +
1007            " <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" +
1008            "<target name=\"all\" >" +
1009            " <deps>" +
1010            " <input name=\"ahoj\" >" +
1011            " <jars dir=\"" + parent + "\" > " +
1012            " <include name=\"" + withoutPkgs.getName () + "\" />" +
1013            " <include name=\"" + withPkgs.getName () + "\" />" +
1014            " </jars>" +
1015            " </input>" +
1016            " <output type=\"implementation-dependencies\" file=\"" + output + "\" />" +
1017            " </deps >" +
1018            "</target>" +
1019            "</project>"
1020        );
1021        PublicPackagesInProjectizedXMLTest.execute (f, new String JavaDoc[] { "-verbose" });
1022        
1023        assertTrue ("Result generated", output.exists ());
1024        
1025        String JavaDoc res = readFile (output);
1026        int x = res.indexOf ("MODULE");
1027        assertEquals ("The file starts with MODULE", 0, x);
1028        int y = res.indexOf ("MODULE", 1);
1029        assertEquals ("No other:\n" + res, -1, y);
1030
1031        StringTokenizer JavaDoc f1 = new StringTokenizer JavaDoc (res, "\r\n");
1032        
1033        assertEquals ("One line + one dep for f1\n" + res, 2, f1.countTokens ());
1034        String JavaDoc modulename = f1.nextToken ();
1035        assertTrue ("module is ", modulename.indexOf ("my.another.module") >= 0);
1036        String JavaDoc dep1 = f1.nextToken ();
1037        assertTrue (dep1, dep1.startsWith (" REQUIRES"));
1038        assertTrue ("on " + dep1, dep1.indexOf ("my.module/3") >= 0);
1039    }
1040
1041    public void testGenerateProvidesRequiresDependencies () throws Exception JavaDoc {
1042        Manifest JavaDoc m = createManifest ();
1043        m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
1044        m.getMainAttributes ().putValue ("OpenIDE-Module-Provides", "my.token");
1045        File JavaDoc withoutPkgs = generateJar (new String JavaDoc[] { "notneeded" }, m);
1046        
1047        m = createManifest ();
1048        m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/7");
1049        m.getMainAttributes ().putValue ("OpenIDE-Module-Requires", "my.token");
1050        File JavaDoc withPkgs = generateJar (new String JavaDoc[] { "some content"}, m);
1051        
1052        File JavaDoc parent = withoutPkgs.getParentFile ();
1053        assertEquals ("All parents are the same 1", parent, withoutPkgs.getParentFile ());
1054        assertEquals ("All parents are the same 2", parent, withPkgs.getParentFile ());
1055        
1056        
1057        File JavaDoc output = PublicPackagesInProjectizedXMLTest.extractString ("");
1058        output.delete ();
1059        assertFalse ("Is gone", output.exists ());
1060        java.io.File JavaDoc f = PublicPackagesInProjectizedXMLTest.extractString (
1061            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
1062            "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" +
1063            " <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" +
1064            "<target name=\"all\" >" +
1065            " <deps>" +
1066            " <input name=\"ahoj\" >" +
1067            " <jars dir=\"" + parent + "\" > " +
1068            " <include name=\"" + withoutPkgs.getName () + "\" />" +
1069            " <include name=\"" + withPkgs.getName () + "\" />" +
1070            " </jars>" +
1071            " </input>" +
1072            " <output type=\"dependencies\" file=\"" + output + "\" />" +
1073            " </deps >" +
1074            "</target>" +
1075            "</project>"
1076        );
1077        PublicPackagesInProjectizedXMLTest.execute (f, new String JavaDoc[] { "-verbose" });
1078        
1079        assertTrue ("Result generated", output.exists ());
1080        
1081        String JavaDoc res = readFile (output);
1082        int x = res.indexOf ("MODULE");
1083        assertEquals ("The file starts with MODULE", 0, x);
1084        int y = res.indexOf ("MODULE", 1);
1085        assertEquals ("No other module: " + res, -1, y);
1086
1087        StringTokenizer JavaDoc f1 = new StringTokenizer JavaDoc (res, "\r\n");
1088        
1089        assertEquals ("One line + one dep for f1\n" + res, 2, f1.countTokens ());
1090        String JavaDoc modulename = f1.nextToken ();
1091        assertTrue ("module name contains another " + modulename, modulename.indexOf ("my.another.module") > 0);
1092        String JavaDoc dep1 = f1.nextToken ();
1093        assertTrue (dep1, dep1.startsWith (" REQUIRES"));
1094        assertTrue ("on " + dep1, dep1.indexOf ("my.module/3") >= 0);
1095    }
1096
1097    public void testSpecialDependenciesArePrintedWithoutSearchingForAppropriateModule () throws Exception JavaDoc {
1098        Manifest JavaDoc m = createManifest ();
1099        m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/3");
1100        m.getMainAttributes ().putValue ("OpenIDE-Module-Requires", "org.openide.modules.os.MacOSX");
1101        File JavaDoc withPkgs = generateJar (new String JavaDoc[] { "some content"}, m);
1102        
1103        File JavaDoc parent = withPkgs.getParentFile ();
1104        
1105        
1106        File JavaDoc output = PublicPackagesInProjectizedXMLTest.extractString ("");
1107        File JavaDoc output2 = PublicPackagesInProjectizedXMLTest.extractString ("");
1108        output.delete ();
1109        assertFalse ("Is gone", output.exists ());
1110        java.io.File JavaDoc f = PublicPackagesInProjectizedXMLTest.extractString (
1111            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
1112            "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" +
1113            " <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" +
1114            "<target name=\"all\" >" +
1115            " <deps>" +
1116            " <input name=\"ahoj\" >" +
1117            " <jars dir=\"" + parent + "\" > " +
1118            " <include name=\"" + withPkgs.getName () + "\" />" +
1119            " </jars>" +
1120            " </input>" +
1121            " <output type=\"dependencies\" file=\"" + output + "\" />" +
1122            " <output type=\"group-dependencies\" file=\"" + output2 + "\" />" +
1123            " </deps >" +
1124            "</target>" +
1125            "</project>"
1126        );
1127        PublicPackagesInProjectizedXMLTest.execute (f, new String JavaDoc[] { "-verbose" });
1128        
1129        assertTrue ("Result generated", output.exists ());
1130        
1131        String JavaDoc res = readFile (output);
1132        int x = res.indexOf ("MODULE");
1133        assertEquals ("The file starts with MODULE:" + res, 0, x);
1134        assertEquals ("No other", -1, res.indexOf ("MODULE", x + 1));
1135
1136        StringTokenizer JavaDoc f1 = new StringTokenizer JavaDoc (res, "\r\n");
1137        
1138        assertEquals ("One line + one dep for f1\n" + res, 2, f1.countTokens ());
1139        String JavaDoc modname = f1.nextToken ();
1140        assertTrue ("Name: " + modname, modname.indexOf ("my.another.module/3") > 0);
1141        String JavaDoc dep1 = f1.nextToken ();
1142        assertTrue (dep1, dep1.startsWith (" REQUIRES"));
1143        assertTrue ("on " + dep1, dep1.indexOf ("org.openide.modules.os.MacOSX") >= 0);
1144        
1145    }
1146    
1147    public void testPrintNamesOfPackagesSharedBetweenMoreModules () throws Exception JavaDoc {
1148        File JavaDoc notAModule = generateJar (new String JavaDoc[] { "org/shared/not/X.class", "org/shared/yes/X.html" }, createManifest ());
1149        
1150        Manifest JavaDoc m = createManifest ();
1151        m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3");
1152        File JavaDoc withoutPkgs = generateJar (new String JavaDoc[] { "org/shared/yes/Bla.class", "org/shared/not/sub/MyClass.class", }, m);
1153        
1154        m = createManifest ();
1155        m.getMainAttributes ().putValue ("OpenIDE-Module", "my.another.module/3");
1156        m.getMainAttributes ().putValue ("Class-Path", notAModule.getName ());
1157        File JavaDoc withPkgs = generateJar (new String JavaDoc[] { "org/shared/not/res/X.jpg"}, m);
1158        
1159        File JavaDoc parent = notAModule.getParentFile ();
1160        assertEquals ("All parents are the same 1", parent, withoutPkgs.getParentFile ());
1161        assertEquals ("All parents are the same 2", parent, withPkgs.getParentFile ());
1162        
1163        
1164        File JavaDoc output = PublicPackagesInProjectizedXMLTest.extractString ("");
1165        output.delete ();
1166        assertFalse ("Is gone", output.exists ());
1167        java.io.File JavaDoc f = PublicPackagesInProjectizedXMLTest.extractString (
1168            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
1169            "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" +
1170            " <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" +
1171            "<target name=\"all\" >" +
1172            " <deps>" +
1173            " <input name=\"ahoj\" >" +
1174            " <jars dir=\"" + parent + "\" > " +
1175            " <include name=\"" + notAModule.getName () + "\" />" +
1176            " <include name=\"" + withoutPkgs.getName () + "\" />" +
1177            " <include name=\"" + withPkgs.getName () + "\" />" +
1178            " </jars>" +
1179            " </input>" +
1180            " <output type=\"shared-packages\" file=\"" + output + "\" />" +
1181            " </deps >" +
1182            "</target>" +
1183            "</project>"
1184        );
1185        PublicPackagesInProjectizedXMLTest.execute (f, new String JavaDoc[] { "-verbose" });
1186        
1187        assertTrue ("Result generated", output.exists ());
1188        
1189        String JavaDoc res = readFile (output);
1190        
1191        assertEquals ("No not package", -1, res.indexOf ("not"));
1192        assertEquals ("No default pkg", -1, res.indexOf ("\n\n"));
1193        assertEquals ("No ork pkg", -1, res.indexOf ("org\n"));
1194        assertEquals ("No ork pkg", -1, res.indexOf ("org/shared\n"));
1195        assertTrue ("Shared is there: " + res, res.indexOf ("org.shared.yes\n") >= 0);
1196        assertEquals ("No META-INF pkg", -1, res.indexOf ("META"));
1197    }
1198
1199    
1200    static String JavaDoc readFile (File JavaDoc f) throws IOException JavaDoc {
1201        java.io.BufferedReader JavaDoc r = new java.io.BufferedReader JavaDoc (new FileReader JavaDoc (f));
1202        StringBuffer JavaDoc sb = new StringBuffer JavaDoc ();
1203        String JavaDoc prev = "";
1204        for (;;) {
1205            String JavaDoc line = r.readLine ();
1206            if (line == null) {
1207                // line ending at the end of file
1208
sb.append ('\n');
1209                return sb.toString();
1210            }
1211            sb.append (prev);
1212            sb.append (line);
1213            prev = "\n";
1214        }
1215    }
1216    
1217    static Manifest JavaDoc createManifest () {
1218        Manifest JavaDoc m = new Manifest JavaDoc ();
1219        m.getMainAttributes ().putValue (java.util.jar.Attributes.Name.MANIFEST_VERSION.toString (), "1.0");
1220        return m;
1221    }
1222    
1223    
1224    private final File JavaDoc createNewJarFile () throws IOException JavaDoc {
1225        int i = 0;
1226        for (;;) {
1227            File JavaDoc f = new File JavaDoc (this.getWorkDir(), i++ + ".jar");
1228            if (!f.exists ()) return f;
1229        }
1230    }
1231    
1232    protected final File JavaDoc generateJar (String JavaDoc[] content, Manifest JavaDoc manifest) throws IOException JavaDoc {
1233        File JavaDoc f = createNewJarFile ();
1234        
1235        JarOutputStream JavaDoc os = new JarOutputStream JavaDoc (new FileOutputStream JavaDoc (f), manifest);
1236        
1237        for (int i = 0; i < content.length; i++) {
1238            os.putNextEntry(new JarEntry JavaDoc (content[i]));
1239            os.closeEntry();
1240        }
1241        os.closeEntry ();
1242        os.close();
1243        
1244        return f;
1245    }
1246    
1247}
1248
Popular Tags