Lines 20-32
Link Here
|
20 |
import java.io.IOException; |
20 |
import java.io.IOException; |
21 |
import java.io.InputStream; |
21 |
import java.io.InputStream; |
22 |
import java.io.OutputStream; |
22 |
import java.io.OutputStream; |
23 |
import java.io.OutputStreamWriter; |
|
|
24 |
import java.io.Writer; |
25 |
import java.util.ArrayList; |
23 |
import java.util.ArrayList; |
|
|
24 |
import java.util.Arrays; |
25 |
import java.util.HashSet; |
26 |
import java.util.Hashtable; |
26 |
import java.util.Hashtable; |
27 |
import java.util.Iterator; |
27 |
import java.util.Iterator; |
28 |
import java.util.List; |
28 |
import java.util.List; |
|
|
29 |
import java.util.Set; |
30 |
import java.util.StringTokenizer; |
31 |
import java.util.jar.Attributes; |
29 |
import java.util.jar.JarFile; |
32 |
import java.util.jar.JarFile; |
|
|
33 |
import java.util.regex.Pattern; |
34 |
import java.util.zip.CRC32; |
35 |
import java.util.zip.ZipEntry; |
36 |
import java.util.zip.ZipInputStream; |
37 |
import java.util.zip.ZipOutputStream; |
30 |
import org.apache.tools.ant.BuildException; |
38 |
import org.apache.tools.ant.BuildException; |
31 |
import org.apache.tools.ant.Project; |
39 |
import org.apache.tools.ant.Project; |
32 |
import org.apache.tools.ant.Task; |
40 |
import org.apache.tools.ant.Task; |
Lines 98-113
Link Here
|
98 |
javadocPackagesProperty = s; |
106 |
javadocPackagesProperty = s; |
99 |
} |
107 |
} |
100 |
|
108 |
|
101 |
private String ideDependenciesProperty; |
|
|
102 |
/** |
103 |
* Set the property to set a list of |
104 |
* OpenIDE-Module-IDE-Dependencies to, based on the list of stated |
105 |
* run-time dependencies. |
106 |
*/ |
107 |
public void setIdeDependenciesProperty(String s) { |
108 |
ideDependenciesProperty = s; |
109 |
} |
110 |
|
111 |
private String moduleDependenciesProperty; |
109 |
private String moduleDependenciesProperty; |
112 |
/** |
110 |
/** |
113 |
* Set the property to set a list of |
111 |
* Set the property to set a list of |
Lines 154-159
Link Here
|
154 |
moduleClassPathProperty = s; |
152 |
moduleClassPathProperty = s; |
155 |
} |
153 |
} |
156 |
|
154 |
|
|
|
155 |
private File publicPackageJarDir; |
156 |
/** |
157 |
* Set the location of a directory in which to look for and create |
158 |
* JARs containing just the public packages of appropriate |
159 |
* compile-time dependencies. |
160 |
*/ |
161 |
public void setPublicPackageJarDir(File d) { |
162 |
publicPackageJarDir = d; |
163 |
} |
164 |
|
157 |
private String classPathExtensionsProperty; |
165 |
private String classPathExtensionsProperty; |
158 |
/** |
166 |
/** |
159 |
* Set the property to set the declared Class-Path attribute to. |
167 |
* Set the property to set the declared Class-Path attribute to. |
Lines 248-283
Link Here
|
248 |
} |
256 |
} |
249 |
} |
257 |
} |
250 |
ModuleListParser modules = null; |
258 |
ModuleListParser modules = null; |
|
|
259 |
Dep[] deps = null; |
251 |
if (moduleDependenciesProperty != null || moduleClassPathProperty != null) { |
260 |
if (moduleDependenciesProperty != null || moduleClassPathProperty != null) { |
252 |
String nball = getProject().getProperty("nb_all"); |
261 |
String nball = getProject().getProperty("nb_all"); |
253 |
Hashtable properties = getProject().getProperties(); |
262 |
Hashtable properties = getProject().getProperties(); |
254 |
properties.put("project", project.getAbsolutePath()); |
263 |
properties.put("project", project.getAbsolutePath()); |
255 |
modules = new ModuleListParser(properties, getModuleType(pDoc), getProject()); |
264 |
modules = new ModuleListParser(properties, getModuleType(pDoc), getProject()); |
|
|
265 |
deps = getDeps(pDoc, modules); |
256 |
} |
266 |
} |
257 |
if (ideDependenciesProperty != null || moduleDependenciesProperty != null) { |
267 |
if (moduleDependenciesProperty != null) { |
258 |
Dep[] deps = getDeps(pDoc); |
|
|
259 |
if (ideDependenciesProperty != null) { |
260 |
Dep ide = null; |
261 |
for (int i = 0; i < deps.length; i++) { |
262 |
if (deps[i].codenamebase.equals("IDE")) { |
263 |
ide = deps[i]; |
264 |
break; |
265 |
} |
266 |
} |
267 |
if (ide != null) { |
268 |
define(ideDependenciesProperty, ide.toString(modules)); |
269 |
} |
270 |
} |
271 |
if (moduleDependenciesProperty != null) { |
268 |
if (moduleDependenciesProperty != null) { |
272 |
StringBuffer b = new StringBuffer(); |
269 |
StringBuffer b = new StringBuffer(); |
273 |
for (int i = 0; i < deps.length; i++) { |
270 |
for (int i = 0; i < deps.length; i++) { |
274 |
if (deps[i].codenamebase.equals("IDE")) { |
271 |
if (!deps[i].run) { |
275 |
continue; |
272 |
continue; |
276 |
} |
273 |
} |
277 |
if (b.length() > 0) { |
274 |
if (b.length() > 0) { |
278 |
b.append(", "); |
275 |
b.append(", "); |
279 |
} |
276 |
} |
280 |
b.append(deps[i].toString(modules)); |
277 |
b.append(deps[i]); |
281 |
} |
278 |
} |
282 |
if (b.length() > 0) { |
279 |
if (b.length() > 0) { |
283 |
define(moduleDependenciesProperty, b.toString()); |
280 |
define(moduleDependenciesProperty, b.toString()); |
Lines 293-299
Link Here
|
293 |
define(codeNameBaseSlashesProperty, cnb.replace('.', '/')); |
290 |
define(codeNameBaseSlashesProperty, cnb.replace('.', '/')); |
294 |
} |
291 |
} |
295 |
if (moduleClassPathProperty != null) { |
292 |
if (moduleClassPathProperty != null) { |
296 |
String cp = computeClasspath(pDoc, modules); |
293 |
String cp = computeClasspath(pDoc, modules, deps); |
297 |
if (cp != null) { |
294 |
if (cp != null) { |
298 |
define(moduleClassPathProperty, cp); |
295 |
define(moduleClassPathProperty, cp); |
299 |
} |
296 |
} |
Lines 419-430
Link Here
|
419 |
} |
416 |
} |
420 |
|
417 |
|
421 |
private final class Dep { |
418 |
private final class Dep { |
422 |
/** will be e.g. org.netbeans.modules.form or IDE */ |
419 |
private final ModuleListParser modules; |
|
|
420 |
/** will be e.g. org.netbeans.modules.form */ |
423 |
public String codenamebase; |
421 |
public String codenamebase; |
424 |
public String release = null; |
422 |
public String release = null; |
425 |
public String spec = null; |
423 |
public String spec = null; |
426 |
public boolean impl = false; |
424 |
public boolean impl = false; |
427 |
public String toString(ModuleListParser modules) throws IOException, BuildException { |
425 |
public boolean compile = false; |
|
|
426 |
public boolean run = false; |
427 |
|
428 |
public Dep(ModuleListParser modules) { |
429 |
this.modules = modules; |
430 |
} |
431 |
|
432 |
public String toString() throws BuildException { |
428 |
StringBuffer b = new StringBuffer(codenamebase); |
433 |
StringBuffer b = new StringBuffer(codenamebase); |
429 |
if (release != null) { |
434 |
if (release != null) { |
430 |
b.append('/'); |
435 |
b.append('/'); |
Lines 445-465
Link Here
|
445 |
} |
450 |
} |
446 |
return b.toString(); |
451 |
return b.toString(); |
447 |
} |
452 |
} |
448 |
private String implementationVersionOf(ModuleListParser modules, String cnb) throws IOException { |
453 |
|
449 |
File jar = computeClasspathModuleLocation(modules, cnb); |
454 |
private String implementationVersionOf(ModuleListParser modules, String cnb) throws BuildException { |
|
|
455 |
File jar = computeClasspathModuleLocation(modules, cnb, null, null); |
450 |
if (!jar.isFile()) { |
456 |
if (!jar.isFile()) { |
451 |
throw new BuildException("No such classpath entry: " + jar, getLocation()); |
457 |
throw new BuildException("No such classpath entry: " + jar, getLocation()); |
452 |
} |
458 |
} |
453 |
JarFile jarFile = new JarFile(jar, false); |
|
|
454 |
try { |
459 |
try { |
455 |
return jarFile.getManifest().getMainAttributes().getValue("OpenIDE-Module-Implementation-Version"); |
460 |
JarFile jarFile = new JarFile(jar, false); |
456 |
} finally { |
461 |
try { |
457 |
jarFile.close(); |
462 |
return jarFile.getManifest().getMainAttributes().getValue("OpenIDE-Module-Implementation-Version"); |
|
|
463 |
} finally { |
464 |
jarFile.close(); |
465 |
} |
466 |
} catch (IOException e) { |
467 |
throw new BuildException(e, getLocation()); |
468 |
} |
469 |
} |
470 |
|
471 |
private boolean matches(Attributes attr) { |
472 |
if (release != null) { |
473 |
String givenCodeName = attr.getValue("OpenIDE-Module"); |
474 |
int slash = givenCodeName.indexOf('/'); |
475 |
int givenRelease = -1; |
476 |
if (slash != -1) { |
477 |
assert codenamebase.equals(givenCodeName.substring(0, slash)); |
478 |
givenRelease = Integer.parseInt(givenCodeName.substring(slash + 1)); |
479 |
} |
480 |
int dash = release.indexOf('-'); |
481 |
if (dash == -1) { |
482 |
if (Integer.parseInt(release) != givenRelease) { |
483 |
return false; |
484 |
} |
485 |
} else { |
486 |
int lower = Integer.parseInt(release.substring(0, dash)); |
487 |
int upper = Integer.parseInt(release.substring(dash + 1)); |
488 |
if (givenRelease < lower || givenRelease > upper) { |
489 |
return false; |
490 |
} |
491 |
} |
492 |
} |
493 |
if (spec != null) { |
494 |
String givenSpec = attr.getValue("OpenIDE-Module-Specification-Version"); |
495 |
if (givenSpec == null) { |
496 |
return false; |
497 |
} |
498 |
// XXX cannot use org.openide.modules.SpecificationVersion from here |
499 |
int[] specVals = digitize(spec); |
500 |
int[] givenSpecVals = digitize(givenSpec); |
501 |
int len1 = specVals.length; |
502 |
int len2 = givenSpecVals.length; |
503 |
int max = Math.max(len1, len2); |
504 |
for (int i = 0; i < max; i++) { |
505 |
int d1 = ((i < len1) ? specVals[i] : 0); |
506 |
int d2 = ((i < len2) ? givenSpecVals[i] : 0); |
507 |
if (d1 < d2) { |
508 |
break; |
509 |
} else if (d1 > d2) { |
510 |
return false; |
511 |
} |
512 |
} |
458 |
} |
513 |
} |
|
|
514 |
if (impl) { |
515 |
if (attr.getValue("OpenIDE-Module-Implementation-Version") == null) { |
516 |
return false; |
517 |
} |
518 |
} |
519 |
return true; |
520 |
} |
521 |
private int[] digitize(String spec) throws NumberFormatException { |
522 |
StringTokenizer tok = new StringTokenizer(spec, "."); |
523 |
int len = tok.countTokens(); |
524 |
int[] digits = new int[len]; |
525 |
for (int i = 0; i < len; i++) { |
526 |
digits[i] = Integer.parseInt(tok.nextToken()); |
527 |
} |
528 |
return digits; |
459 |
} |
529 |
} |
|
|
530 |
|
460 |
} |
531 |
} |
461 |
|
532 |
|
462 |
private Dep[] getDeps(Document pDoc) throws BuildException { |
533 |
private Dep[] getDeps(Document pDoc, ModuleListParser modules) throws BuildException { |
463 |
Element cfg = getConfig(pDoc); |
534 |
Element cfg = getConfig(pDoc); |
464 |
Element md = XMLUtil.findElement(cfg, "module-dependencies", NBM_NS); |
535 |
Element md = XMLUtil.findElement(cfg, "module-dependencies", NBM_NS); |
465 |
if (md == null) { |
536 |
if (md == null) { |
Lines 470-476
Link Here
|
470 |
Iterator it = l.iterator(); |
541 |
Iterator it = l.iterator(); |
471 |
while (it.hasNext()) { |
542 |
while (it.hasNext()) { |
472 |
Element dep = (Element)it.next(); |
543 |
Element dep = (Element)it.next(); |
473 |
Dep d = new Dep(); |
544 |
Dep d = new Dep(modules); |
474 |
Element cnb = XMLUtil.findElement(dep, "code-name-base", NBM_NS); |
545 |
Element cnb = XMLUtil.findElement(dep, "code-name-base", NBM_NS); |
475 |
if (cnb == null) { |
546 |
if (cnb == null) { |
476 |
throw new BuildException("No <code-name-base>", getLocation()); |
547 |
throw new BuildException("No <code-name-base>", getLocation()); |
Lines 479-490
Link Here
|
479 |
if (t == null) { |
550 |
if (t == null) { |
480 |
throw new BuildException("No text in <code-name-base>", getLocation()); |
551 |
throw new BuildException("No text in <code-name-base>", getLocation()); |
481 |
} |
552 |
} |
482 |
if (t.equals("org.openide")) { |
|
|
483 |
t = "IDE"; |
484 |
} |
485 |
d.codenamebase = t; |
553 |
d.codenamebase = t; |
486 |
Element rd = XMLUtil.findElement(dep, "run-dependency", NBM_NS); |
554 |
Element rd = XMLUtil.findElement(dep, "run-dependency", NBM_NS); |
487 |
if (rd != null) { |
555 |
if (rd != null) { |
|
|
556 |
d.run = true; |
488 |
Element rv = XMLUtil.findElement(rd, "release-version", NBM_NS); |
557 |
Element rv = XMLUtil.findElement(rd, "release-version", NBM_NS); |
489 |
if (rv != null) { |
558 |
if (rv != null) { |
490 |
t = XMLUtil.findText(rv); |
559 |
t = XMLUtil.findText(rv); |
Lines 501-513
Link Here
|
501 |
} |
570 |
} |
502 |
d.spec = t; |
571 |
d.spec = t; |
503 |
} |
572 |
} |
504 |
// <implementation-version> added in /2: |
|
|
505 |
Element iv = XMLUtil.findElement(rd, "implementation-version", NBM_NS); |
573 |
Element iv = XMLUtil.findElement(rd, "implementation-version", NBM_NS); |
506 |
if (iv != null) { |
574 |
if (iv != null) { |
507 |
d.impl = true; |
575 |
d.impl = true; |
508 |
} |
576 |
} |
509 |
deps.add(d); |
|
|
510 |
} |
577 |
} |
|
|
578 |
d.compile = XMLUtil.findElement(dep, "compile-dependency", NBM_NS) != null; |
579 |
deps.add(d); |
511 |
} |
580 |
} |
512 |
return (Dep[])deps.toArray(new Dep[deps.size()]); |
581 |
return (Dep[])deps.toArray(new Dep[deps.size()]); |
513 |
} |
582 |
} |
Lines 536-608
Link Here
|
536 |
} |
605 |
} |
537 |
} |
606 |
} |
538 |
|
607 |
|
539 |
private String computeClasspath(Document pDoc, ModuleListParser modules) throws BuildException, IOException, SAXException { |
608 |
private String computeClasspath(Document pDoc, ModuleListParser modules, Dep[] deps) throws BuildException, IOException, SAXException { |
540 |
Element data = getConfig(pDoc); |
609 |
String myCnb = getCodeNameBase(pDoc); |
541 |
Element moduleDependencies = XMLUtil.findElement(data, "module-dependencies", NBM_NS); |
|
|
542 |
List/*<Element>*/ deps = XMLUtil.findSubElements(moduleDependencies); |
543 |
StringBuffer cp = new StringBuffer(); |
610 |
StringBuffer cp = new StringBuffer(); |
544 |
Iterator it = deps.iterator(); |
611 |
String excludedClustersProp = getProject().getProperty("disabled.clusters"); |
545 |
while (it.hasNext()) { |
612 |
Set/*<String>*/ excludedClusters = excludedClustersProp != null ? |
546 |
Element dep = (Element)it.next(); |
613 |
new HashSet(Arrays.asList(excludedClustersProp.split(" *, *"))) : |
547 |
if (XMLUtil.findElement(dep, "compile-dependency", NBM_NS) == null) { |
614 |
null; |
|
|
615 |
String excludedModulesProp = getProject().getProperty("disabled.modules"); |
616 |
Set/*<String>*/ excludedModules = excludedModulesProp != null ? |
617 |
new HashSet(Arrays.asList(excludedModulesProp.split(" *, *"))) : |
618 |
null; |
619 |
for (int i = 0; i < deps.length; i++) { |
620 |
Dep dep = deps[i]; |
621 |
if (!dep.compile) { |
548 |
continue; |
622 |
continue; |
549 |
} |
623 |
} |
550 |
if (cp.length() > 0) { |
624 |
String cnb = dep.codenamebase; |
551 |
cp.append(':'); |
625 |
File depJar = computeClasspathModuleLocation(modules, cnb, excludedClusters, excludedModules); |
|
|
626 |
|
627 |
Attributes attr; |
628 |
JarFile jarFile = new JarFile(depJar, false); |
629 |
try { |
630 |
attr = jarFile.getManifest().getMainAttributes(); |
631 |
} finally { |
632 |
jarFile.close(); |
552 |
} |
633 |
} |
553 |
Element cnbEl = XMLUtil.findElement(dep, "code-name-base", NBM_NS); |
|
|
554 |
String cnb = XMLUtil.findText(cnbEl); |
555 |
|
634 |
|
556 |
if ("org.openide".equals (cnb)) { |
635 |
if (!dep.matches(attr)) { // #68631 |
557 |
// XXX special handling of splited openide, can be removed |
636 |
throw new BuildException("Cannot compile against a module: " + depJar + " because of dependency: " + dep, getLocation()); |
558 |
// after 5.0 release or when apisupport improved |
|
|
559 |
getProject ().log ("Do not depend on org.openide anymore, depend on its libraries. Update " + getProjectFile (), getProject().MSG_WARN); |
560 |
|
561 |
cp.append (computeClasspathModuleLocation (modules, "org.openide.util").getAbsolutePath ()); |
562 |
cp.append(File.pathSeparatorChar); |
563 |
cp.append (computeClasspathModuleLocation (modules, "org.openide.util.enumerations").getAbsolutePath ()); |
564 |
cp.append(File.pathSeparatorChar); |
565 |
cp.append (computeClasspathModuleLocation (modules, "org.openide.filesystems").getAbsolutePath ()); |
566 |
cp.append(File.pathSeparatorChar); |
567 |
cp.append (computeClasspathModuleLocation (modules, "org.openide.modules").getAbsolutePath ()); |
568 |
cp.append(File.pathSeparatorChar); |
569 |
cp.append (computeClasspathModuleLocation (modules, "org.openide.awt").getAbsolutePath ()); |
570 |
cp.append(File.pathSeparatorChar); |
571 |
cp.append (computeClasspathModuleLocation (modules, "org.openide.dialogs").getAbsolutePath ()); |
572 |
cp.append(File.pathSeparatorChar); |
573 |
cp.append (computeClasspathModuleLocation (modules, "org.openide.loaders").getAbsolutePath ()); |
574 |
cp.append(File.pathSeparatorChar); |
575 |
cp.append (computeClasspathModuleLocation (modules, "org.openide.nodes").getAbsolutePath ()); |
576 |
cp.append(File.pathSeparatorChar); |
577 |
cp.append (computeClasspathModuleLocation (modules, "org.openide.explorer").getAbsolutePath ()); |
578 |
cp.append(File.pathSeparatorChar); |
579 |
cp.append (computeClasspathModuleLocation (modules, "org.openide.actions").getAbsolutePath ()); |
580 |
cp.append(File.pathSeparatorChar); |
581 |
cp.append (computeClasspathModuleLocation (modules, "org.openide.text").getAbsolutePath ()); |
582 |
cp.append(File.pathSeparatorChar); |
583 |
cp.append (computeClasspathModuleLocation (modules, "org.openide.windows").getAbsolutePath ()); |
584 |
cp.append(File.pathSeparatorChar); |
585 |
cp.append (computeClasspathModuleLocation (modules, "org.openide.options").getAbsolutePath ()); |
586 |
cp.append(File.pathSeparatorChar); |
587 |
cp.append (computeClasspathModuleLocation (modules, "org.openide.compat").getAbsolutePath ()); |
588 |
|
589 |
continue; |
590 |
} |
637 |
} |
591 |
|
638 |
|
592 |
cp.append(computeClasspathModuleLocation(modules, cnb).getAbsolutePath()); |
639 |
List/*<File>*/ additions = new ArrayList(); |
|
|
640 |
additions.add(depJar); |
593 |
// #52354: look for <class-path-extension>s in dependent modules. |
641 |
// #52354: look for <class-path-extension>s in dependent modules. |
594 |
ModuleListParser.Entry entry = modules.findByCodeNameBase(cnb); |
642 |
ModuleListParser.Entry entry = modules.findByCodeNameBase(cnb); |
595 |
if (entry != null) { |
643 |
if (entry != null) { |
596 |
File[] exts = entry.getClassPathExtensions(); |
644 |
File[] exts = entry.getClassPathExtensions(); |
597 |
for (int i = 0; i < exts.length; i++) { |
645 |
for (int j = 0; j < exts.length; j++) { |
|
|
646 |
additions.add(exts[j]); |
647 |
} |
648 |
} |
649 |
|
650 |
if (!dep.impl) { |
651 |
String friends = attr.getValue("OpenIDE-Module-Friends"); |
652 |
if (friends != null && !Arrays.asList(friends.split(" *, *")).contains(myCnb)) { |
653 |
throw new BuildException("The module " + myCnb + " is not a friend of " + depJar, getLocation()); |
654 |
} |
655 |
String pubpkgs = attr.getValue("OpenIDE-Module-Public-Packages"); |
656 |
if ("-".equals(pubpkgs)) { |
657 |
throw new BuildException("The module " + depJar + " has no public packages and so cannot be compiled against", getLocation()); |
658 |
} else if (pubpkgs != null) { |
659 |
File splitJar = createPublicPackageJar(additions, pubpkgs, publicPackageJarDir, cnb); |
660 |
additions.clear(); |
661 |
additions.add(splitJar); |
662 |
} |
663 |
} |
664 |
|
665 |
Iterator it = additions.iterator(); |
666 |
while (it.hasNext()) { |
667 |
if (cp.length() > 0) { |
598 |
cp.append(':'); |
668 |
cp.append(':'); |
599 |
cp.append(exts[i].getAbsolutePath()); |
|
|
600 |
} |
669 |
} |
|
|
670 |
cp.append(((File) it.next()).getAbsolutePath()); |
601 |
} |
671 |
} |
602 |
} |
672 |
} |
603 |
// Also look for <class-path-extension>s for myself and put them in my own classpath. |
673 |
// Also look for <class-path-extension>s for myself and put them in my own classpath. |
604 |
String cnb = getCodeNameBase(pDoc); |
674 |
ModuleListParser.Entry entry = modules.findByCodeNameBase(myCnb); |
605 |
ModuleListParser.Entry entry = modules.findByCodeNameBase(cnb); |
|
|
606 |
assert entry != null; |
675 |
assert entry != null; |
607 |
File[] exts = entry.getClassPathExtensions(); |
676 |
File[] exts = entry.getClassPathExtensions(); |
608 |
for (int i = 0; i < exts.length; i++) { |
677 |
for (int i = 0; i < exts.length; i++) { |
Lines 612-625
Link Here
|
612 |
return cp.toString(); |
681 |
return cp.toString(); |
613 |
} |
682 |
} |
614 |
|
683 |
|
615 |
private File computeClasspathModuleLocation(ModuleListParser modules, String cnb) throws BuildException { |
684 |
private File computeClasspathModuleLocation(ModuleListParser modules, String cnb, Set/*<String>*/ excludedClusters, Set/*<String>*/ excludedModules) throws BuildException { |
616 |
ModuleListParser.Entry module = modules.findByCodeNameBase(cnb); |
685 |
ModuleListParser.Entry module = modules.findByCodeNameBase(cnb); |
617 |
if (module == null) { |
686 |
if (module == null) { |
618 |
throw new BuildException("No dependent module " + cnb, getLocation()); |
687 |
throw new BuildException("No dependent module " + cnb, getLocation()); |
619 |
} |
688 |
} |
620 |
// XXX if that module is projectized, check its public |
689 |
if (excludedClusters != null && excludedClusters.contains(module.getClusterName())) { // #68716 |
621 |
// packages; if it has none, halt the build, unless we are |
690 |
throw new BuildException("Module " + cnb + " part of cluster " + module.getClusterName() + " which is excluded from the target platform", getLocation()); |
622 |
// declaring an impl dependency |
691 |
} |
|
|
692 |
if (excludedModules != null && excludedModules.contains(cnb)) { // again #68716 |
693 |
throw new BuildException("Module " + cnb + " excluded from the target platform", getLocation()); |
694 |
} |
623 |
return module.getJar(); |
695 |
return module.getJar(); |
624 |
} |
696 |
} |
625 |
|
697 |
|
Lines 646-651
Link Here
|
646 |
list.append(reltext); |
718 |
list.append(reltext); |
647 |
} |
719 |
} |
648 |
return list != null ? list.toString() : null; |
720 |
return list != null ? list.toString() : null; |
|
|
721 |
} |
722 |
|
723 |
/** |
724 |
* Create a compact JAR containing only classes in public packages. |
725 |
* Forces the compiler to honor public package restrictions. |
726 |
* @see "#59792" |
727 |
*/ |
728 |
private File createPublicPackageJar(List/*<File>*/ jars, String pubpkgs, File dir, String cnb) throws IOException { |
729 |
File ppjar = new File(dir, cnb.replace('.', '-') + ".jar"); |
730 |
if (ppjar.exists()) { |
731 |
// Check if it is up to date first. Must be as new as any input JAR. |
732 |
boolean uptodate = true; |
733 |
long stamp = ppjar.lastModified(); |
734 |
Iterator it = jars.iterator(); |
735 |
while (it.hasNext()) { |
736 |
File jar = (File) it.next(); |
737 |
if (jar.lastModified() > stamp) { |
738 |
uptodate = false; |
739 |
break; |
740 |
} |
741 |
} |
742 |
if (uptodate) { |
743 |
log("Distilled " + ppjar + " was already up to date", Project.MSG_VERBOSE); |
744 |
return ppjar; |
745 |
} |
746 |
} |
747 |
log("Distilling " + ppjar + " from " + jars); |
748 |
String corePattern = pubpkgs. |
749 |
replaceAll(" +", ""). |
750 |
replaceAll("\\.", "/"). |
751 |
replaceAll(",", "|"). |
752 |
replaceAll("\\*\\*", "(.+/)?"). |
753 |
replaceAll("\\*", ""); |
754 |
Pattern p = Pattern.compile("(" + corePattern + ")[^/]+\\.class"); |
755 |
// E.g.: (org/netbeans/api/foo/|org/netbeans/spi/foo/)[^/]+\.class |
756 |
OutputStream os = new FileOutputStream(ppjar); |
757 |
try { |
758 |
ZipOutputStream zos = new ZipOutputStream(os); |
759 |
Iterator it = jars.iterator(); |
760 |
while (it.hasNext()) { |
761 |
File jar = (File) it.next(); |
762 |
InputStream is = new FileInputStream(jar); |
763 |
try { |
764 |
ZipInputStream zis = new ZipInputStream(is); |
765 |
ZipEntry inEntry; |
766 |
while ((inEntry = zis.getNextEntry()) != null) { |
767 |
String path = inEntry.getName(); |
768 |
if (!p.matcher(path).matches()) { |
769 |
continue; |
770 |
} |
771 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
772 |
byte[] buf = new byte[4096]; |
773 |
int read; |
774 |
while ((read = zis.read(buf)) != -1) { |
775 |
baos.write(buf, 0, read); |
776 |
} |
777 |
byte[] data = baos.toByteArray(); |
778 |
ZipEntry outEntry = new ZipEntry(path); |
779 |
outEntry.setSize(data.length); |
780 |
CRC32 crc = new CRC32(); |
781 |
crc.update(data); |
782 |
outEntry.setCrc(crc.getValue()); |
783 |
zos.putNextEntry(outEntry); |
784 |
zos.write(data); |
785 |
} |
786 |
} finally { |
787 |
is.close(); |
788 |
} |
789 |
} |
790 |
zos.close(); |
791 |
} finally { |
792 |
os.close(); |
793 |
} |
794 |
return ppjar; |
649 |
} |
795 |
} |
650 |
|
796 |
|
651 |
} |
797 |
} |