1 19 20 package org.netbeans.nbbuild; 21 22 import java.io.ByteArrayOutputStream ; 23 import java.io.File ; 24 import java.io.FileOutputStream ; 25 import java.io.FileReader ; 26 import java.io.IOException ; 27 import java.io.InputStream ; 28 import java.util.Arrays ; 29 import java.util.StringTokenizer ; 30 import java.util.jar.JarEntry ; 31 import java.util.jar.JarOutputStream ; 32 import java.util.jar.Manifest ; 33 import java.util.regex.Matcher ; 34 import java.util.regex.Pattern ; 35 import java.util.zip.ZipEntry ; 36 import java.util.zip.ZipOutputStream ; 37 import junit.framework.*; 38 39 import org.netbeans.junit.*; 40 41 42 47 public class ModuleDependenciesTest extends NbTestCase { 48 public ModuleDependenciesTest (String name) { 49 super (name); 50 } 51 73 74 public void testPublicPackagesOfAModuleThatDoesNotDefineThem () throws Exception { 75 File notAModule = generateJar (new String [] { "not/X.class", "not/resource/X.html" }, createManifest ()); 76 77 Manifest m = createManifest (); 78 m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3"); 79 File withoutPkgs = generateJar (new String [] { "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 withPkgs = generateJar (new String [] { "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 allPkgs = generateJar (new String [] { "not/very/A.class", "not/very/B.class", "not/very/sub/Root.class", "not/res/X.jpg"}, m); 90 91 File 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 output = PublicPackagesInProjectizedXMLTest.extractString (""); 98 output.delete (); 99 assertFalse ("Is gone", output.exists ()); 100 java.io.File 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 [] { "-verbose" }); 120 121 assertTrue ("Result generated", output.exists ()); 122 123 String 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 { 133 File notAModule = generateJar (new String [] { "not/X.class", "not/resource/X.html" }, createManifest ()); 134 135 Manifest m = createManifest (); 136 m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3"); 137 m.getMainAttributes ().putValue ("OpenIDE-Module-Friends", "my.very.public.module"); 138 File withoutPkgs = generateJar (new String [] { "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 withPkgs = generateJar (new String [] { "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 allPkgs = generateJar (new String [] { "not/very/A.class", "not/very/B.class", "not/very/sub/Root.class", "not/res/X.jpg"}, m); 150 151 File 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 output = PublicPackagesInProjectizedXMLTest.extractString (""); 158 output.delete (); 159 File friendPkg = PublicPackagesInProjectizedXMLTest.extractString (""); 160 friendPkg.delete (); 161 assertFalse ("Is gone", output.exists ()); 162 java.io.File 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 [] { "-verbose" }); 183 184 assertTrue ("Result generated", output.exists ()); 185 186 String res = readFile (output); 187 188 if (!res.equals("\n")) { 189 fail("No public packages:\n" + res); 190 } 191 192 res = readFile(friendPkg); 194 195 Matcher 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 { 213 File notAModule = generateJar (new String [] { "not/X.class", "not/resource/X.html" }, createManifest ()); 214 215 Manifest m = createManifest (); 216 m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3"); 217 m.getMainAttributes ().putValue ("OpenIDE-Module-Friends", "my.very.public.module"); 218 File withoutPkgs = generateJar (new String [] { "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 withPkgs = generateJar (new String [] { "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 allPkgs = generateJar (new String [] { "not/very/A.class", "not/very/B.class", "not/very/sub/Root.class", "not/res/X.jpg"}, m); 230 231 File 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 output = PublicPackagesInProjectizedXMLTest.extractString (""); 238 output.delete (); 239 File friendPkg = PublicPackagesInProjectizedXMLTest.extractString (""); 240 friendPkg.delete (); 241 assertFalse ("Is gone", output.exists ()); 242 java.io.File 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 PublicPackagesInProjectizedXMLTest.execute (f, new String [] { "-verbose" }); 265 } 266 267 public void testThereCanBeLimitOnNumberOfFriendsAmongGroups() throws Exception { 268 File notAModule = generateJar (new String [] { "not/X.class", "not/resource/X.html" }, createManifest ()); 269 270 Manifest m = createManifest (); 271 m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3"); 272 m.getMainAttributes ().putValue ("OpenIDE-Module-Friends", "my.very.public.module"); 273 File myModule = generateJar (new String [] { "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 myAnotherModule = generateJar (new String [] { "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 myVeryPublicModule = generateJar (new String [] { "not/very/A.class", "not/very/B.class", "not/very/sub/Root.class", "not/res/X.jpg"}, m); 285 286 File 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 friendPkg = PublicPackagesInProjectizedXMLTest.extractString (""); 293 friendPkg.delete (); 294 assertFalse ("Is gone", friendPkg.exists ()); 295 java.io.File 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 PublicPackagesInProjectizedXMLTest.execute (f, new String [] { "-verbose", "-Dlimit=5" }); 322 323 String 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 [] { "-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 { 351 File notAModule = generateJar (new String [] { "not/X.class", "not/resource/X.html" }, createManifest ()); 352 353 Manifest m = createManifest (); 354 m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3"); 355 m.getMainAttributes ().putValue ("OpenIDE-Module-Friends", "my.very.public.module"); 356 File myModule = generateJar (new String [] { "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 myAnotherModule = generateJar (new String [] { "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 myVeryPublicModule = generateJar (new String [] { "not/very/A.class", "not/very/B.class", "not/very/sub/Root.class", "not/res/X.jpg"}, m); 368 369 File 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 friendPkg = PublicPackagesInProjectizedXMLTest.extractString (""); 376 friendPkg.delete (); 377 assertFalse ("Is gone", friendPkg.exists ()); 378 java.io.File 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 PublicPackagesInProjectizedXMLTest.execute (f, new String [] { "-verbose", "-Dlimit=5" }); 399 400 String 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 [] { "-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 { 428 File notAModule = generateJar (new String [] { "not/X.class", "not/resource/X.html" }, createManifest ()); 429 430 Manifest m = createManifest (); 431 m.getMainAttributes ().putValue ("NetBeans-Own-Library", "true"); 432 File withoutPkgs = generateJar (new String [] { "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 withPkgs = generateJar (new String [] { "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 allPkgs = generateJar (new String [] { "not/very/A.class", "not/very/B.class", "not/very/sub/Root.class", "not/res/X.jpg"}, m); 443 444 File 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 output = PublicPackagesInProjectizedXMLTest.extractString (""); 451 output.delete (); 452 assertFalse ("Is gone", output.exists ()); 453 java.io.File 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 [] { "-verbose" }); 473 474 assertTrue ("Result generated", output.exists ()); 475 476 String 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 { 490 File notAModule = generateJar (new String [] { "is/cp/X.class", "not/cp/resource/X.html" }, createManifest ()); 491 492 Manifest m = createManifest (); 493 m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3"); 494 m.getMainAttributes ().putValue ("Class-Path", notAModule.getName ()); 495 File withoutPkgs = generateJar (new String [] { "DefaultPkg.class", "is/X.class", "is/too/MyClass.class", "not/as/it/is/resource/X.xml" }, m); 496 497 File parent = notAModule.getParentFile (); 498 assertEquals ("All parents are the same 1", parent, withoutPkgs.getParentFile ()); 499 500 501 File output = PublicPackagesInProjectizedXMLTest.extractString (""); 502 output.delete (); 503 assertFalse ("Is gone", output.exists ()); 504 java.io.File 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 [] { "-verbose" }); 522 523 assertTrue ("Result generated", output.exists ()); 524 525 String 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 { 535 Manifest m = createManifest (); 536 m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module"); 537 File module = generateJar (new String [] { "something" }, m); 538 539 File parent = module.getParentFile (); 540 541 542 File output = PublicPackagesInProjectizedXMLTest.extractString (""); 543 output.delete (); 544 assertFalse ("Is gone", output.exists ()); 545 java.io.File 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 [] { "-verbose" }); 562 563 assertTrue ("Result generated", output.exists ()); 564 565 String 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 { 574 File notAModule = generateJar (new String [] { "not/X.class", "not/resource/X.html" }, createManifest ()); 575 576 Manifest m = createManifest (); 577 m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3"); 578 File withoutPkgs = generateJar (new String [] { "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 withPkgs = generateJar (new String [] { "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 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 output = PublicPackagesInProjectizedXMLTest.extractString (""); 591 output.delete (); 592 assertFalse ("Is gone", output.exists ()); 593 java.io.File 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 [] { "-verbose" }); 612 613 assertTrue ("Result generated", output.exists ()); 614 615 String res = readFile (output); 616 StringTokenizer tok = new StringTokenizer (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 { 625 Manifest openideManifest = createManifest (); 626 openideManifest.getMainAttributes ().putValue ("OpenIDE-Module", "org.openide/1"); 627 File openide = generateJar (new String [] { "notneeded" }, openideManifest); 628 629 Manifest 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 withoutPkgs = generateJar (new String [] { "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 withPkgs = generateJar (new String [] { "some content"}, m); 638 639 File 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 output = PublicPackagesInProjectizedXMLTest.extractString (""); 645 output.delete (); 646 assertFalse ("Is gone", output.exists ()); 647 java.io.File 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 [] { "-verbose" }); 670 671 assertTrue ("Result generated", output.exists ()); 672 673 String 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 StringTokenizer f2 = new StringTokenizer (res.substring (0, y), "\r\n"); 682 StringTokenizer f1 = new StringTokenizer (res.substring (y), "\r\n"); 683 684 assertEquals ("One line + one dep for f1\n" + res, 2, f1.countTokens ()); 685 f1.nextToken (); 686 String 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 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 { 702 Manifest openideManifest = createManifest (); 703 openideManifest.getMainAttributes ().putValue ("OpenIDE-Module", "org.openide/1"); 704 File openide = generateJar (new String [] { "notneeded" }, openideManifest); 705 706 Manifest 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 withoutPkgs = generateJar (new String [] { "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 withPkgs = generateJar (new String [] { "some content"}, m); 715 716 File 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 output = PublicPackagesInProjectizedXMLTest.extractString (""); 722 output.delete (); 723 assertFalse ("Is gone", output.exists ()); 724 java.io.File 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 [] { "-verbose" }); 747 748 assertTrue ("Result generated", output.exists ()); 749 750 String 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 StringTokenizer f2 = new StringTokenizer (res.substring (0, y), "\r\n"); 761 StringTokenizer f1 = new StringTokenizer (res.substring (y), "\r\n"); 762 763 assertEquals ("One line + one dep for f1\n" + res, 2, f1.countTokens ()); 764 f1.nextToken (); 765 String 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 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 { 781 Manifest 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 withoutPkgs = generateJar (new String [] { "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 withPkgs = generateJar (new String [] { "some content"}, m); 790 791 File 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 output = PublicPackagesInProjectizedXMLTest.extractString (""); 797 output.delete (); 798 assertFalse ("Is gone", output.exists ()); 799 java.io.File 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 [] { "-verbose" }); 817 818 assertTrue ("Result generated", output.exists ()); 819 820 String 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 f1 = new StringTokenizer (res, "\r\n"); 827 828 assertEquals ("One line + one dep for f1\n" + res, 2, f1.countTokens ()); 829 String modulename = f1.nextToken (); 830 assertTrue ("module is ", modulename.indexOf ("my.another.module") >= 0); 831 String 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 { 838 Manifest m = createManifest (); 839 m.getMainAttributes ().putValue ("OpenIDE-Module", "org.openide/1"); 840 File openide = generateJar (new String [] { "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 withoutPkgs = generateJar (new String [] { "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 withPkgs = generateJar (new String [] { "some content"}, m); 851 852 File 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 output = PublicPackagesInProjectizedXMLTest.extractString (""); 858 output.delete (); 859 assertFalse ("Is gone", output.exists ()); 860 java.io.File 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 [] { "-verbose" }); 883 884 assertTrue ("Result generated", output.exists ()); 885 886 String 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 f1 = new StringTokenizer (res, "\r\n"); 893 894 assertEquals ("One line + dep on openide\n" + res, 2, f1.countTokens ()); 895 String groupname = f1.nextToken (); 896 assertTrue ("group is " + res, groupname.indexOf ("others") >= 0); 897 String 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 { 905 Manifest m = createManifest (); 906 m.getMainAttributes ().putValue ("OpenIDE-Module", "org.openide/1"); 907 File openide = generateJar (new String [] { "notneeded" }, m); 908 909 m = createManifest (); 910 m.getMainAttributes ().putValue ("OpenIDE-Module", "org.netbeans.core/1"); 911 File core = generateJar (new String [] { "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 withoutPkgs = generateJar (new String [] { "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 withPkgs = generateJar (new String [] { "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 coredepender = generateJar (new String [] { "notneeded" }, m); 927 928 929 File 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 output = PublicPackagesInProjectizedXMLTest.extractString (""); 935 output.delete (); 936 assertFalse ("Is gone", output.exists ()); 937 java.io.File 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 [] { "-verbose" }); 966 967 assertTrue ("Result generated", output.exists ()); 968 969 String 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 f1 = new StringTokenizer (res, "\r\n"); 976 977 assertEquals ("One line + dep on openide\n" + res, 2, f1.countTokens ()); 978 String groupname = f1.nextToken (); 979 assertTrue ("group is " + res, groupname.indexOf ("rest") >= 0); 980 String 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 { 986 Manifest 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 withoutPkgs = generateJar (new String [] { "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 withPkgs = generateJar (new String [] { "some content"}, m); 995 996 File 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 output = PublicPackagesInProjectizedXMLTest.extractString (""); 1002 output.delete (); 1003 assertFalse ("Is gone", output.exists ()); 1004 java.io.File 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 [] { "-verbose" }); 1022 1023 assertTrue ("Result generated", output.exists ()); 1024 1025 String 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 f1 = new StringTokenizer (res, "\r\n"); 1032 1033 assertEquals ("One line + one dep for f1\n" + res, 2, f1.countTokens ()); 1034 String modulename = f1.nextToken (); 1035 assertTrue ("module is ", modulename.indexOf ("my.another.module") >= 0); 1036 String 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 { 1042 Manifest m = createManifest (); 1043 m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3"); 1044 m.getMainAttributes ().putValue ("OpenIDE-Module-Provides", "my.token"); 1045 File withoutPkgs = generateJar (new String [] { "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 withPkgs = generateJar (new String [] { "some content"}, m); 1051 1052 File 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 output = PublicPackagesInProjectizedXMLTest.extractString (""); 1058 output.delete (); 1059 assertFalse ("Is gone", output.exists ()); 1060 java.io.File 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 [] { "-verbose" }); 1078 1079 assertTrue ("Result generated", output.exists ()); 1080 1081 String 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 f1 = new StringTokenizer (res, "\r\n"); 1088 1089 assertEquals ("One line + one dep for f1\n" + res, 2, f1.countTokens ()); 1090 String modulename = f1.nextToken (); 1091 assertTrue ("module name contains another " + modulename, modulename.indexOf ("my.another.module") > 0); 1092 String 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 { 1098 Manifest 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 withPkgs = generateJar (new String [] { "some content"}, m); 1102 1103 File parent = withPkgs.getParentFile (); 1104 1105 1106 File output = PublicPackagesInProjectizedXMLTest.extractString (""); 1107 File output2 = PublicPackagesInProjectizedXMLTest.extractString (""); 1108 output.delete (); 1109 assertFalse ("Is gone", output.exists ()); 1110 java.io.File 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 [] { "-verbose" }); 1128 1129 assertTrue ("Result generated", output.exists ()); 1130 1131 String 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 f1 = new StringTokenizer (res, "\r\n"); 1137 1138 assertEquals ("One line + one dep for f1\n" + res, 2, f1.countTokens ()); 1139 String modname = f1.nextToken (); 1140 assertTrue ("Name: " + modname, modname.indexOf ("my.another.module/3") > 0); 1141 String 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 { 1148 File notAModule = generateJar (new String [] { "org/shared/not/X.class", "org/shared/yes/X.html" }, createManifest ()); 1149 1150 Manifest m = createManifest (); 1151 m.getMainAttributes ().putValue ("OpenIDE-Module", "my.module/3"); 1152 File withoutPkgs = generateJar (new String [] { "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 withPkgs = generateJar (new String [] { "org/shared/not/res/X.jpg"}, m); 1158 1159 File 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 output = PublicPackagesInProjectizedXMLTest.extractString (""); 1165 output.delete (); 1166 assertFalse ("Is gone", output.exists ()); 1167 java.io.File 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 [] { "-verbose" }); 1186 1187 assertTrue ("Result generated", output.exists ()); 1188 1189 String 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 readFile (File f) throws IOException { 1201 java.io.BufferedReader r = new java.io.BufferedReader (new FileReader (f)); 1202 StringBuffer sb = new StringBuffer (); 1203 String prev = ""; 1204 for (;;) { 1205 String line = r.readLine (); 1206 if (line == null) { 1207 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 createManifest () { 1218 Manifest m = new Manifest (); 1219 m.getMainAttributes ().putValue (java.util.jar.Attributes.Name.MANIFEST_VERSION.toString (), "1.0"); 1220 return m; 1221 } 1222 1223 1224 private final File createNewJarFile () throws IOException { 1225 int i = 0; 1226 for (;;) { 1227 File f = new File (this.getWorkDir(), i++ + ".jar"); 1228 if (!f.exists ()) return f; 1229 } 1230 } 1231 1232 protected final File generateJar (String [] content, Manifest manifest) throws IOException { 1233 File f = createNewJarFile (); 1234 1235 JarOutputStream os = new JarOutputStream (new FileOutputStream (f), manifest); 1236 1237 for (int i = 0; i < content.length; i++) { 1238 os.putNextEntry(new JarEntry (content[i])); 1239 os.closeEntry(); 1240 } 1241 os.closeEntry (); 1242 os.close(); 1243 1244 return f; 1245 } 1246 1247} 1248 | Popular Tags |