This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 65924
Collapse All | Expand All

(-)apisupport/project/src/org/netbeans/modules/apisupport/project/ManifestManager.java (-3 / +17 lines)
Lines 7-13 Link Here
7
 * http://www.sun.com/
7
 * http://www.sun.com/
8
 *
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
11
 * Microsystems, Inc. All Rights Reserved.
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
12
 */
13
13
Lines 18-24 Link Here
18
import java.io.IOException;
18
import java.io.IOException;
19
import java.io.InputStream;
19
import java.io.InputStream;
20
import java.util.ArrayList;
20
import java.util.ArrayList;
21
import java.util.Collections;
21
import java.util.List;
22
import java.util.List;
23
import java.util.Set;
22
import java.util.StringTokenizer;
24
import java.util.StringTokenizer;
23
import java.util.jar.Attributes;
25
import java.util.jar.Attributes;
24
import java.util.jar.JarFile;
26
import java.util.jar.JarFile;
Lines 45-50 Link Here
45
    private String layer;
47
    private String layer;
46
    private String classPath;
48
    private String classPath;
47
    private PackageExport[] publicPackages;
49
    private PackageExport[] publicPackages;
50
    private String moduleDependencies;
48
    private boolean deprecated;
51
    private boolean deprecated;
49
    
52
    
50
    public static final String OPENIDE_MODULE = "OpenIDE-Module"; // NOI18N
53
    public static final String OPENIDE_MODULE = "OpenIDE-Module"; // NOI18N
Lines 56-61 Link Here
56
    public static final String OPENIDE_MODULE_LOCALIZING_BUNDLE = "OpenIDE-Module-Localizing-Bundle"; // NOI18N
59
    public static final String OPENIDE_MODULE_LOCALIZING_BUNDLE = "OpenIDE-Module-Localizing-Bundle"; // NOI18N
57
    public static final String OPENIDE_MODULE_PUBLIC_PACKAGES = "OpenIDE-Module-Public-Packages"; // NOI18N
60
    public static final String OPENIDE_MODULE_PUBLIC_PACKAGES = "OpenIDE-Module-Public-Packages"; // NOI18N
58
    public static final String OPENIDE_MODULE_FRIENDS = "OpenIDE-Module-Friends"; // NOI18N
61
    public static final String OPENIDE_MODULE_FRIENDS = "OpenIDE-Module-Friends"; // NOI18N
62
    public static final String OPENIDE_MODULE_MODULE_DEPENDENCIES = "OpenIDE-Module-Module-Dependencies"; // NOI18N
59
    public static final String CLASS_PATH = "Class-Path"; // NOI18N
63
    public static final String CLASS_PATH = "Class-Path"; // NOI18N
60
    
64
    
61
    static final PackageExport[] EMPTY_EXPORTED_PACKAGES = new PackageExport[0];
65
    static final PackageExport[] EMPTY_EXPORTED_PACKAGES = new PackageExport[0];
Lines 70-76 Link Here
70
    private ManifestManager(String cnb, String releaseVersion, String specVer,
74
    private ManifestManager(String cnb, String releaseVersion, String specVer,
71
            String implVer, String provTokensString, String requiredTokens,
75
            String implVer, String provTokensString, String requiredTokens,
72
            String locBundle, String layer, String classPath,
76
            String locBundle, String layer, String classPath,
73
            PackageExport[] publicPackages, boolean deprecated) {
77
            PackageExport[] publicPackages, boolean deprecated, String moduleDependencies) {
74
        this.codeNameBase = cnb;
78
        this.codeNameBase = cnb;
75
        this.releaseVersion = releaseVersion;
79
        this.releaseVersion = releaseVersion;
76
        this.specificationVersion = specVer;
80
        this.specificationVersion = specVer;
Lines 83-88 Link Here
83
        this.classPath = classPath;
87
        this.classPath = classPath;
84
        this.publicPackages = publicPackages;
88
        this.publicPackages = publicPackages;
85
        this.deprecated = deprecated;
89
        this.deprecated = deprecated;
90
        this.moduleDependencies = moduleDependencies;
86
    }
91
    }
87
    
92
    
88
    private String[] parseTokens(String tokens) {
93
    private String[] parseTokens(String tokens) {
Lines 165-171 Link Here
165
                attr.getValue(OPENIDE_MODULE_LAYER),
170
                attr.getValue(OPENIDE_MODULE_LAYER),
166
                attr.getValue(CLASS_PATH),
171
                attr.getValue(CLASS_PATH),
167
                publicPackages,
172
                publicPackages,
168
                deprecated);
173
                deprecated,
174
                attr.getValue(OPENIDE_MODULE_MODULE_DEPENDENCIES));
169
        return mm;
175
        return mm;
170
    }
176
    }
171
    
177
    
Lines 270-275 Link Here
270
276
271
    public boolean isDeprecated() {
277
    public boolean isDeprecated() {
272
        return deprecated;
278
        return deprecated;
279
    }
280
    
281
    public Set/*<Dependency>*/ getModuleDependencies() {
282
        if (moduleDependencies != null) {
283
            return Dependency.create(Dependency.TYPE_MODULE, moduleDependencies);
284
        } else {
285
            return Collections.EMPTY_SET;
286
        }
273
    }
287
    }
274
    
288
    
275
    /**
289
    /**
(-)apisupport/project/src/org/netbeans/modules/apisupport/project/ui/customizer/SuiteCustomizerLibraries.java (-12 / +221 lines)
Lines 7-26 Link Here
7
 * http://www.sun.com/
7
 * http://www.sun.com/
8
 *
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
11
 * Microsystems, Inc. All Rights Reserved.
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
12
 */
13
13
14
package org.netbeans.modules.apisupport.project.ui.customizer;
14
package org.netbeans.modules.apisupport.project.ui.customizer;
15
15
16
import java.awt.EventQueue;
16
import java.beans.PropertyChangeEvent;
17
import java.beans.PropertyChangeEvent;
17
import java.beans.PropertyChangeListener;
18
import java.beans.PropertyChangeListener;
18
import java.beans.PropertyEditor;
19
import java.beans.PropertyEditor;
20
import java.io.IOException;
19
import java.lang.reflect.InvocationTargetException;
21
import java.lang.reflect.InvocationTargetException;
20
import java.util.Arrays;
22
import java.util.Arrays;
21
import java.util.Comparator;
23
import java.util.Comparator;
22
import java.util.HashMap;
24
import java.util.HashMap;
23
import java.util.HashSet;
25
import java.util.HashSet;
26
import java.util.Iterator;
27
import java.util.LinkedHashSet;
24
import java.util.Set;
28
import java.util.Set;
25
import java.util.TreeSet;
29
import java.util.TreeSet;
26
import javax.swing.JButton;
30
import javax.swing.JButton;
Lines 28-34 Link Here
28
import javax.swing.event.ChangeListener;
32
import javax.swing.event.ChangeListener;
29
import org.netbeans.api.java.platform.JavaPlatform;
33
import org.netbeans.api.java.platform.JavaPlatform;
30
import org.netbeans.api.java.platform.PlatformsCustomizer;
34
import org.netbeans.api.java.platform.PlatformsCustomizer;
35
import org.netbeans.api.project.ProjectUtils;
36
import org.netbeans.modules.apisupport.project.ManifestManager;
31
import org.netbeans.modules.apisupport.project.NbModuleProject;
37
import org.netbeans.modules.apisupport.project.NbModuleProject;
38
import org.netbeans.modules.apisupport.project.NbModuleProjectType;
39
import org.netbeans.modules.apisupport.project.Util;
32
import org.netbeans.modules.apisupport.project.suite.SuiteProject;
40
import org.netbeans.modules.apisupport.project.suite.SuiteProject;
33
import org.netbeans.modules.apisupport.project.ui.platform.PlatformComponentFactory;
41
import org.netbeans.modules.apisupport.project.ui.platform.PlatformComponentFactory;
34
import org.netbeans.modules.apisupport.project.ui.platform.NbPlatformCustomizer;
42
import org.netbeans.modules.apisupport.project.ui.platform.NbPlatformCustomizer;
Lines 36-49 Link Here
36
import org.netbeans.modules.apisupport.project.universe.NbPlatform;
44
import org.netbeans.modules.apisupport.project.universe.NbPlatform;
37
import org.openide.DialogDescriptor;
45
import org.openide.DialogDescriptor;
38
import org.openide.DialogDisplayer;
46
import org.openide.DialogDisplayer;
47
import org.openide.ErrorManager;
39
import org.openide.NotifyDescriptor;
48
import org.openide.NotifyDescriptor;
40
import org.openide.explorer.ExplorerManager;
49
import org.openide.explorer.ExplorerManager;
50
import org.openide.modules.Dependency;
51
import org.openide.modules.SpecificationVersion;
41
import org.openide.nodes.AbstractNode;
52
import org.openide.nodes.AbstractNode;
42
import org.openide.nodes.Children;
53
import org.openide.nodes.Children;
43
import org.openide.nodes.Node;
54
import org.openide.nodes.Node;
44
import org.openide.nodes.PropertySupport;
55
import org.openide.nodes.PropertySupport;
45
import org.openide.nodes.Sheet;
56
import org.openide.nodes.Sheet;
46
import org.openide.util.NbBundle;
57
import org.openide.util.NbBundle;
58
import org.openide.util.RequestProcessor;
59
import org.w3c.dom.Element;
47
60
48
/**
61
/**
49
 * Represents <em>Libraries</em> panel in Suite customizer.
62
 * Represents <em>Libraries</em> panel in Suite customizer.
Lines 53-58 Link Here
53
final class SuiteCustomizerLibraries extends NbPropertyPanel.Suite
66
final class SuiteCustomizerLibraries extends NbPropertyPanel.Suite
54
        implements Comparator, ExplorerManager.Provider, ChangeListener {
67
        implements Comparator, ExplorerManager.Provider, ChangeListener {
55
    private ExplorerManager manager;
68
    private ExplorerManager manager;
69
    private ModuleEntry[] platformModules;
56
    
70
    
57
    /**
71
    /**
58
     * Creates new form SuiteCustomizerLibraries
72
     * Creates new form SuiteCustomizerLibraries
Lines 88-96 Link Here
88
    }
102
    }
89
    
103
    
90
    private void refreshModules() {
104
    private void refreshModules() {
91
        ModuleEntry[] entry = getProperties().getActivePlatform().getModules();
105
        platformModules = getProperties().getActivePlatform().getModules();
92
        Node root = createModuleNode(entry);
106
        Node root = createPlatformModulesNode();
93
        manager.setRootContext(root);
107
        manager.setRootContext(root);
108
        universe = null;
109
        updateDependencyWarnings();
94
    }
110
    }
95
    
111
    
96
    private void refreshJavaPlatforms() {
112
    private void refreshJavaPlatforms() {
Lines 301-307 Link Here
301
    // End of variables declaration//GEN-END:variables
317
    // End of variables declaration//GEN-END:variables
302
    
318
    
303
    
319
    
304
    private Node createModuleNode(ModuleEntry[] entries) {
320
    private Node createPlatformModulesNode() {
305
        HashSet disabledModuleCNB = new HashSet(Arrays.asList(getProperties().getDisabledModules()));
321
        HashSet disabledModuleCNB = new HashSet(Arrays.asList(getProperties().getDisabledModules()));
306
        HashSet disabledClusters = new HashSet(Arrays.asList(getProperties().getDisabledClusters()));
322
        HashSet disabledClusters = new HashSet(Arrays.asList(getProperties().getDisabledClusters()));
307
        
323
        
Lines 313-338 Link Here
313
        n.setName(getMessage("LBL_ModuleListClusters"));
329
        n.setName(getMessage("LBL_ModuleListClusters"));
314
        n.setDisplayName(getMessage("LBL_ModuleListClustersModules"));
330
        n.setDisplayName(getMessage("LBL_ModuleListClustersModules"));
315
        
331
        
316
        for (int i = 0; i < entries.length; i++) {
332
        for (int i = 0; i < platformModules.length; i++) {
317
            Children clusterChildren = (Children)clusterToChildren.get(entries[i].getClusterDirectory());
333
            Children clusterChildren = (Children)clusterToChildren.get(platformModules[i].getClusterDirectory());
318
            if (clusterChildren == null) {
334
            if (clusterChildren == null) {
319
                Children.SortedArray modules = new Children.SortedArray();
335
                Children.SortedArray modules = new Children.SortedArray();
320
                modules.setComparator(this);
336
                modules.setComparator(this);
321
                clusterChildren = modules;
337
                clusterChildren = modules;
322
                
338
                
323
                String clusterName = entries[i].getClusterDirectory().getName();
339
                String clusterName = platformModules[i].getClusterDirectory().getName();
324
                Enabled cluster = new Enabled(modules, !disabledClusters.contains(clusterName));
340
                Enabled cluster = new Enabled(modules, !disabledClusters.contains(clusterName));
325
                cluster.setName(clusterName);
341
                cluster.setName(clusterName);
326
                cluster.setIconBaseWithExtension(SuiteProject.SUITE_ICON_PATH);
342
                cluster.setIconBaseWithExtension(SuiteProject.SUITE_ICON_PATH);
327
                clusterToChildren.put(entries[i].getClusterDirectory(), modules);
343
                clusterToChildren.put(platformModules[i].getClusterDirectory(), modules);
328
                n.getChildren().add(new Node[] { cluster });
344
                n.getChildren().add(new Node[] { cluster });
329
            }
345
            }
330
            
346
            
331
            String cnb = entries[i].getCodeNameBase();
347
            String cnb = platformModules[i].getCodeNameBase();
332
            AbstractNode module = new Enabled(Children.LEAF, !disabledModuleCNB.contains(cnb));
348
            AbstractNode module = new Enabled(Children.LEAF, !disabledModuleCNB.contains(cnb));
333
            module.setName(cnb);
349
            module.setName(cnb);
334
            module.setDisplayName(entries[i].getLocalizedName());
350
            module.setDisplayName(platformModules[i].getLocalizedName());
335
            String desc = entries[i].getShortDescription();
351
            String desc = platformModules[i].getShortDescription();
336
            String tooltip;
352
            String tooltip;
337
            if (desc != null) {
353
            if (desc != null) {
338
                if (desc.startsWith("<html>")) { // NOI18N
354
                if (desc.startsWith("<html>")) { // NOI18N
Lines 447-453 Link Here
447
        }
463
        }
448
    }
464
    }
449
    
465
    
450
    static final class Enabled extends AbstractNode {
466
    final class Enabled extends AbstractNode {
451
        private boolean enabled;
467
        private boolean enabled;
452
        private Children standard;
468
        private Children standard;
453
        
469
        
Lines 482-487 Link Here
482
                Enabled en = (Enabled)n;
498
                Enabled en = (Enabled)n;
483
                en.firePropertyChange(null, null, null);
499
                en.firePropertyChange(null, null, null);
484
            }
500
            }
501
            updateDependencyWarnings();
485
        }
502
        }
486
        
503
        
487
        public boolean isEnabled() {
504
        public boolean isEnabled() {
Lines 555-560 Link Here
555
    private void initAccessibility() {
572
    private void initAccessibility() {
556
        managePlafsButton.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_ManagePlafsButton"));
573
        managePlafsButton.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_ManagePlafsButton"));
557
        platformValue.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_PlatformValue"));
574
        platformValue.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_PlatformValue"));
575
    }
576
    
577
    // #65924: show warnings if some dependencies cannot be satisfied
578
    
579
    interface UniverseModule {
580
        String getCodeNameBase();
581
        int getReleaseVersion();
582
        SpecificationVersion getSpecificationVersion();
583
        String getImplementationVersion();
584
        Set/*<String>*/ getProvidedTokens();
585
        Set/*<String>*/ getRequiredTokens();
586
        Set/*<Dependency>*/ getModuleDependencies();
587
        String getCluster();
588
        String getDisplayName();
589
    }
590
    
591
    private static abstract class AbstractUniverseModule implements UniverseModule {
592
        protected final ManifestManager mm;
593
        protected AbstractUniverseModule(ManifestManager mm) {
594
            this.mm = mm;
595
        }
596
        public int getReleaseVersion() {
597
            String s = mm.getReleaseVersion();
598
            return s != null ? Integer.parseInt(s) : -1;
599
        }
600
        public String getImplementationVersion() {
601
            return mm.getImplementationVersion();
602
        }
603
        public Set/*<String>*/ getProvidedTokens() {
604
            return new HashSet(Arrays.asList(mm.getProvidedTokens()));
605
        }
606
        public Set/*<String>*/ getRequiredTokens() {
607
            return new HashSet(Arrays.asList(mm.getRequiredTokens()));
608
        }
609
    }
610
    
611
    private static final class PlatformModule extends AbstractUniverseModule {
612
        private final ModuleEntry entry;
613
        public PlatformModule(ModuleEntry entry) throws IOException {
614
            super(ManifestManager.getInstanceFromJAR(entry.getJarLocation()));
615
            this.entry = entry;
616
        }
617
        public String getCodeNameBase() {
618
            return entry.getCodeNameBase();
619
        }
620
        public SpecificationVersion getSpecificationVersion() {
621
            String s = entry.getSpecificationVersion();
622
            return s != null ? new SpecificationVersion(s) : null;
623
        }
624
        public Set/*<Dependency>*/ getModuleDependencies() {
625
            return mm.getModuleDependencies();
626
        }
627
        public String getCluster() {
628
            return entry.getClusterDirectory().getName();
629
        }
630
        public String getDisplayName() {
631
            return entry.getLocalizedName();
632
        }
633
    }
634
    
635
    private static final class SuiteModule extends AbstractUniverseModule {
636
        private final NbModuleProject project;
637
        private final Set/*<Dependency>*/ dependencies;
638
        public SuiteModule(NbModuleProject project) {
639
            super(ManifestManager.getInstance(project.getManifest(), false));
640
            this.project = project;
641
            dependencies = new HashSet();
642
            // Cannot use ProjectXMLManager since we need to report also deps on nonexistent modules.
643
            Element dataE = project.getHelper().getPrimaryConfigurationData(true);
644
            Element depsE = Util.findElement(dataE, "module-dependencies", NbModuleProjectType.NAMESPACE_SHARED); // NOI18N
645
            Iterator/*<Element>*/ deps = Util.findSubElements(depsE).iterator();
646
            while (deps.hasNext()) {
647
                Element dep = (Element) deps.next();
648
                Element run = Util.findElement(dep, "run-dependency", NbModuleProjectType.NAMESPACE_SHARED); // NOI18N
649
                if (run == null) {
650
                    continue;
651
                }
652
                String text = Util.findText(Util.findElement(dep, "code-name-base", NbModuleProjectType.NAMESPACE_SHARED)); // NOI18N
653
                Element relverE = Util.findElement(run, "release-version", NbModuleProjectType.NAMESPACE_SHARED); // NOI18N
654
                if (relverE != null) {
655
                    text += '/' + Util.findText(relverE);
656
                }
657
                Element specverE = Util.findElement(run, "specification-version", NbModuleProjectType.NAMESPACE_SHARED); // NOI18N
658
                if (specverE != null) {
659
                    text += '>' + Util.findText(specverE);
660
                } else {
661
                    Element implver = Util.findElement(run, "implementation-version", NbModuleProjectType.NAMESPACE_SHARED); // NOI18N
662
                    if (implver != null) {
663
                        // Will special-case '*' as an impl version to mean "match anything".
664
                        text += "=*"; // NOI18N
665
                    }
666
                }
667
                dependencies.addAll(Dependency.create(Dependency.TYPE_MODULE, text));
668
            }
669
        }
670
        public String getCodeNameBase() {
671
            return project.getCodeNameBase();
672
        }
673
        public SpecificationVersion getSpecificationVersion() {
674
            String s = project.getSpecVersion();
675
            return s != null ? new SpecificationVersion(s) : null;
676
        }
677
        public Set/*<Dependency>*/ getModuleDependencies() {
678
            return dependencies;
679
        }
680
        public String getCluster() {
681
            return null;
682
        }
683
        public String getDisplayName() {
684
            return ProjectUtils.getInformation(project).getDisplayName();
685
        }
686
    }
687
688
    private RequestProcessor.Task updateDependencyWarningsTask;
689
    private void updateDependencyWarnings() {
690
        if (updateDependencyWarningsTask == null) {
691
            updateDependencyWarningsTask = RequestProcessor.getDefault().create(new Runnable() {
692
                public void run() {
693
                    doUpdateDependencyWarnings();
694
                }
695
            });
696
        }
697
        updateDependencyWarningsTask.schedule(0);
698
    }
699
    
700
    static Set/*<UniverseModule>*/ loadUniverseModules(ModuleEntry[] platformModules, Set/*<NbModuleProject>*/ suiteModules) throws IOException {
701
        Set universe = new LinkedHashSet();
702
        Iterator/*<Project>*/ it = suiteModules.iterator();
703
        while (it.hasNext()) {
704
            universe.add(new SuiteModule((NbModuleProject) it.next()));
705
        }
706
        for (int i = 0; i < platformModules.length; i++) {
707
            universe.add(new PlatformModule(platformModules[i]));
708
        }
709
        return universe;
710
    }
711
    
712
    static String[] findWarning(Set/*<UniverseModule>*/ universeModules, Set/*<String>*/ disabledClusters, Set/*<String>*/ disabledModules) {
713
        // XXX
714
        return null;
715
    }
716
    
717
    private Set/*<UniverseModule>*/ universe;
718
    private void doUpdateDependencyWarnings() {
719
        // XXX consider using a PorgressHandle
720
        if (universe == null) {
721
            try {
722
                universe = loadUniverseModules(platformModules, getProperties().getSubModules());
723
            } catch (IOException e) {
724
                Util.err.notify(ErrorManager.INFORMATIONAL, e);
725
                return; // any warnings would probably be wrong anyway
726
            }
727
        }
728
        
729
        Set disabledClusters = new TreeSet();
730
        Set disabledModules = new TreeSet();
731
        
732
        Node[] clusters = getExplorerManager().getRootContext().getChildren().getNodes();
733
        for (int i = 0; i < clusters.length; i++) {
734
            if (clusters[i] instanceof Enabled) {
735
                Enabled e = (Enabled) clusters[i];
736
                if (!e.isEnabled()) {
737
                    disabledClusters.add(e.getName());
738
                } else {
739
                    Node[] modules = e.getChildren().getNodes();
740
                    for (int j = 0; j < modules.length; j++) {
741
                        if (modules[j] instanceof Enabled) {
742
                            Enabled m = (Enabled) modules[j];
743
                            if (!m.isEnabled()) {
744
                                disabledModules.add(m.getName());
745
                            }
746
                        }
747
                    }
748
                }
749
            }
750
        }
751
        
752
        final String[] warning = findWarning(universe, disabledClusters, disabledModules);
753
        
754
        EventQueue.invokeLater(new Runnable() {
755
            public void run() {
756
                if (warning != null) {
757
                    String key = warning[0];
758
                    String[] args = new String[warning.length - 1];
759
                    System.arraycopy(warning, 1, args, 0, args.length);
760
                    setWarning(NbBundle.getMessage(SuiteCustomizerLibraries.class, key, args));
761
                } else {
762
                    setWarning(null);
763
                }
764
            }
765
        });
766
        
558
    }
767
    }
559
    
768
    
560
}
769
}
(-)apisupport/project/test/unit/src/org/netbeans/modules/apisupport/project/ui/customizer/SuiteCustomizerLibrariesTest.java (+164 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 *
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.modules.apisupport.project.ui.customizer;
15
16
import java.io.File;
17
import java.util.Arrays;
18
import java.util.Collections;
19
import java.util.HashMap;
20
import java.util.HashSet;
21
import java.util.Iterator;
22
import java.util.Map;
23
import java.util.Set;
24
import java.util.jar.Manifest;
25
import org.netbeans.api.project.ProjectManager;
26
import org.netbeans.junit.NbTestCase;
27
import org.netbeans.modules.apisupport.project.EditableManifest;
28
import org.netbeans.modules.apisupport.project.ManifestManager;
29
import org.netbeans.modules.apisupport.project.NbModuleProject;
30
import org.netbeans.modules.apisupport.project.ProjectXMLManager;
31
import org.netbeans.modules.apisupport.project.TestBase;
32
import org.netbeans.modules.apisupport.project.Util;
33
import org.netbeans.modules.apisupport.project.suite.SuiteProject;
34
import org.netbeans.modules.apisupport.project.universe.LocalizedBundleInfo;
35
import org.netbeans.modules.apisupport.project.universe.NbPlatform;
36
import org.openide.modules.Dependency;
37
import org.openide.modules.SpecificationVersion;
38
39
/**
40
 * Tests module dependencies in a suite.
41
 * @author Jesse Glick
42
 */
43
public class SuiteCustomizerLibrariesTest extends NbTestCase {
44
    
45
    public SuiteCustomizerLibrariesTest(String name) {
46
        super(name);
47
    }
48
    
49
    private NbPlatform platform;
50
    private SuiteProject suite;
51
52
    protected void setUp() throws Exception {
53
        super.setUp();
54
        clearWorkDir();
55
        // PLATFORM SETUP
56
        TestBase.initializeBuildProperties(getWorkDir());
57
        File install = new File(getWorkDir(), "install");
58
        TestBase.makePlatform(install);
59
        // MODULE foo
60
        Manifest mani = new Manifest();
61
        mani.getMainAttributes().putValue(ManifestManager.OPENIDE_MODULE, "foo/1");
62
        mani.getMainAttributes().putValue(ManifestManager.OPENIDE_MODULE_SPECIFICATION_VERSION, "1.0");
63
        mani.getMainAttributes().putValue(ManifestManager.OPENIDE_MODULE_IMPLEMENTATION_VERSION, "foo-1");
64
        mani.getMainAttributes().putValue(ManifestManager.OPENIDE_MODULE_LOCALIZING_BUNDLE, "foo/Bundle.properties");
65
        mani.getMainAttributes().putValue(ManifestManager.OPENIDE_MODULE_PROVIDES, "tok1, tok1a");
66
        Map/*<String,String>*/ contents = new HashMap();
67
        contents.put("foo/Bundle.properties", "OpenIDE-Module-Name=Foo Module");
68
        TestBase.createJar(new File(new File(new File(install, "somecluster"), "modules"), "foo.jar"), contents, mani);
69
        // MODULE bar
70
        mani = new Manifest();
71
        mani.getMainAttributes().putValue(ManifestManager.OPENIDE_MODULE, "bar");
72
        mani.getMainAttributes().putValue(ManifestManager.OPENIDE_MODULE_REQUIRES, "tok1");
73
        TestBase.createJar(new File(new File(new File(install, "somecluster"), "modules"), "bar.jar"), Collections.EMPTY_MAP, mani);
74
        // MODULE baz
75
        mani = new Manifest();
76
        mani.getMainAttributes().putValue(ManifestManager.OPENIDE_MODULE, "baz");
77
        mani.getMainAttributes().putValue("OpenIDE-Module-Module-Dependencies", "foo/1 > 1.0");
78
        TestBase.createJar(new File(new File(new File(install, "anothercluster"), "modules"), "baz.jar"), Collections.EMPTY_MAP, mani);
79
        platform = NbPlatform.addPlatform("custom", install, "custom");
80
        // SUITE setup
81
        suite = TestBase.generateSuite(getWorkDir(), "suite", "custom");
82
        // MODULE org.example.module1
83
        NbModuleProject module = TestBase.generateSuiteComponent(suite, "module1");
84
        EditableManifest em = Util.loadManifest(module.getManifestFile());
85
        em.setAttribute(ManifestManager.OPENIDE_MODULE, "org.example.module1/2", null);
86
        em.setAttribute(ManifestManager.OPENIDE_MODULE_SPECIFICATION_VERSION, "2.0", null);
87
        em.setAttribute(ManifestManager.OPENIDE_MODULE_PROVIDES, "tok2", null);
88
        Util.storeManifest(module.getManifestFile(), em);
89
        LocalizedBundleInfo lbinfo = ((LocalizedBundleInfo.Provider) module.getLookup().lookup(LocalizedBundleInfo.Provider.class)).getLocalizedBundleInfo();
90
        lbinfo.setDisplayName("Module One");
91
        lbinfo.store();
92
        // MODULE org.example.module2
93
        module = TestBase.generateSuiteComponent(suite, "module2");
94
        em = Util.loadManifest(module.getManifestFile());
95
        em.removeAttribute(ManifestManager.OPENIDE_MODULE_SPECIFICATION_VERSION, null);
96
        em.setAttribute(ManifestManager.OPENIDE_MODULE_REQUIRES, "tok2", null);
97
        Util.storeManifest(module.getManifestFile(), em);
98
        lbinfo = ((LocalizedBundleInfo.Provider) module.getLookup().lookup(LocalizedBundleInfo.Provider.class)).getLocalizedBundleInfo();
99
        lbinfo.setDisplayName("Module Two");
100
        lbinfo.store();
101
        // MODULE org.example.module3
102
        module = TestBase.generateSuiteComponent(suite, "module3");
103
        ProjectXMLManager xml = new ProjectXMLManager(module.getHelper());
104
        xml.addDependency(new ModuleDependency(module.getModuleList().getEntry("org.example.module2")));
105
        xml.addDependency(new ModuleDependency(module.getModuleList().getEntry("bar")));
106
        // XXX need richer deps
107
        ProjectManager.getDefault().saveAllProjects();
108
    }
109
    
110
    public void testUniverseModules() throws Exception { // #65924
111
        Set/*<UniverseModule>*/ modules = SuiteCustomizerLibraries.loadUniverseModules(platform.getModules(), SuiteUtils.getSubProjects(suite));
112
        Map/*<String,UniverseModule>*/ modulesByName = new HashMap();
113
        for (Iterator it = modules.iterator(); it.hasNext(); ) {
114
            SuiteCustomizerLibraries.UniverseModule m = (SuiteCustomizerLibraries.UniverseModule) it.next();
115
            modulesByName.put(m.getCodeNameBase(), m);
116
        }
117
        assertEquals(modules.size(), modulesByName.size());
118
        SuiteCustomizerLibraries.UniverseModule m = (SuiteCustomizerLibraries.UniverseModule) modulesByName.get("core");
119
        assertNotNull(m);
120
        // core.jar is just a dummy JAR, nothing interesting to test
121
        m = (SuiteCustomizerLibraries.UniverseModule) modulesByName.get("foo");
122
        assertNotNull(m);
123
        assertEquals("somecluster", m.getCluster());
124
        assertEquals("Foo Module", m.getDisplayName());
125
        assertEquals(1, m.getReleaseVersion());
126
        assertEquals(new SpecificationVersion("1.0"), m.getSpecificationVersion());
127
        assertEquals("foo-1", m.getImplementationVersion());
128
        assertEquals(new HashSet(Arrays.asList(new String[] {"tok1", "tok1a"})), m.getProvidedTokens());
129
        assertEquals(Collections.EMPTY_SET, m.getRequiredTokens());
130
        assertEquals(Collections.EMPTY_SET, m.getModuleDependencies());
131
        m = (SuiteCustomizerLibraries.UniverseModule) modulesByName.get("bar");
132
        assertNotNull(m);
133
        assertEquals(Collections.EMPTY_SET, m.getProvidedTokens());
134
        assertEquals(Collections.singleton("tok1"), m.getRequiredTokens());
135
        m = (SuiteCustomizerLibraries.UniverseModule) modulesByName.get("baz");
136
        assertNotNull(m);
137
        assertEquals(Dependency.create(Dependency.TYPE_MODULE, "foo/1 > 1.0"), m.getModuleDependencies());
138
        m = (SuiteCustomizerLibraries.UniverseModule) modulesByName.get("org.example.module1");
139
        assertNotNull(m);
140
        assertNull(m.getCluster());
141
        assertEquals("Module One", m.getDisplayName());
142
        assertEquals(2, m.getReleaseVersion());
143
        assertEquals(new SpecificationVersion("2.0"), m.getSpecificationVersion());
144
        assertNull(m.getImplementationVersion());
145
        assertEquals(Collections.singleton("tok2"), m.getProvidedTokens());
146
        assertEquals(Collections.EMPTY_SET, m.getRequiredTokens());
147
        assertEquals(Collections.EMPTY_SET, m.getModuleDependencies());
148
        m = (SuiteCustomizerLibraries.UniverseModule) modulesByName.get("org.example.module2");
149
        assertNotNull(m);
150
        assertEquals(-1, m.getReleaseVersion());
151
        assertNull(m.getSpecificationVersion());
152
        assertNull(m.getImplementationVersion());
153
        assertEquals(Collections.EMPTY_SET, m.getProvidedTokens());
154
        assertEquals(Collections.singleton("tok2"), m.getRequiredTokens());
155
        m = (SuiteCustomizerLibraries.UniverseModule) modulesByName.get("org.example.module3");
156
        assertNotNull(m);
157
        assertEquals(Dependency.create(Dependency.TYPE_MODULE, "org.example.module2, bar"), m.getModuleDependencies());
158
    }
159
    
160
    public void testDependencyWarnings() throws Exception { // #65924
161
        // XXX
162
    }
163
    
164
}

Return to bug 65924