KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > ConsistencyVerifier


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

19
20 package org.netbeans;
21
22 import java.util.HashSet JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Set JavaDoc;
25 import java.util.SortedMap JavaDoc;
26 import java.util.SortedSet JavaDoc;
27 import java.util.TreeMap JavaDoc;
28 import java.util.TreeSet JavaDoc;
29 import java.util.jar.Manifest JavaDoc;
30
31 /**
32  * Utility class permitting you to verify that a set of modules could be enabled together.
33  * Currently used from the <code>VerifyUpdateCenter</code> Ant task in the NB build system.
34  * @author Jesse Glick
35  */

36 public class ConsistencyVerifier {
37
38     private ConsistencyVerifier() {}
39
40     /**
41      * Find all expected installation problems for a set of modules.
42      * Standard OS and module format tokens are provided, but all other dependencies
43      * must be accessible from the set of modules supplied.
44      * @param modules a set of module manifests to test together
45      * @return a map from module code name bases, to sets of problems, expressed as {@link Dependency#toString}
46      * @throws IllegalArgumentException if the set of modules is illegal (e.g. contains duplicates)
47      */

48     public static SortedMap JavaDoc<String JavaDoc,SortedSet JavaDoc<String JavaDoc>> findInconsistencies(Set JavaDoc<Manifest JavaDoc> modules) throws IllegalArgumentException JavaDoc {
49         ModuleManager mgr = new ModuleManager(new DummyInstaller(), new DummyEvents());
50         mgr.mutexPrivileged().enterWriteAccess();
51         Manifest JavaDoc dummy = new Manifest JavaDoc();
52         dummy.getMainAttributes().putValue("OpenIDE-Module", "__dummy__"); // NOI18N
53
dummy.getMainAttributes().putValue("OpenIDE-Module-Provides", "org.openide.modules.ModuleFormat1, " + // NOI18N
54
"org.openide.modules.os.Unix, " + // NOI18N
55
"org.openide.modules.os.PlainUnix, " + // NOI18N
56
"org.openide.modules.os.Windows, " + // NOI18N
57
"org.openide.modules.os.MacOSX, " + // NOI18N
58
"org.openide.modules.os.OS2"); // NOI18N
59
dummy.getMainAttributes().putValue("OpenIDE-Module-Public-Packages", "-"); // NOI18N
60
try {
61             mgr.createFixed(dummy, null, ClassLoader.getSystemClassLoader());
62         } catch (Exception JavaDoc x) {
63             throw new AssertionError JavaDoc(x);
64         }
65         Set JavaDoc<Module> mods = new HashSet JavaDoc<Module>();
66         for (Manifest JavaDoc m : modules) {
67             try {
68                 m.getMainAttributes().putValue("OpenIDE-Module-Public-Packages", "-"); // NOI18N
69
mods.add(mgr.createFixed(m, null, ClassLoader.getSystemClassLoader()));
70             } catch (Exception JavaDoc x) {
71                 throw new IllegalArgumentException JavaDoc(x);
72             }
73         }
74         SortedMap JavaDoc<String JavaDoc,SortedSet JavaDoc<String JavaDoc>> problems = new TreeMap JavaDoc<String JavaDoc,SortedSet JavaDoc<String JavaDoc>>();
75         for (Module m : mods) {
76             Set JavaDoc<Object JavaDoc> probs = m.getProblems();
77             if (probs.isEmpty()) {
78                 continue;
79             }
80             SortedSet JavaDoc<String JavaDoc> probnames = new TreeSet JavaDoc<String JavaDoc>();
81             for (Object JavaDoc prob : probs) {
82                 probnames.add(prob.toString());
83             }
84             problems.put(m.getCodeNameBase(), probnames);
85         }
86         return problems;
87     }
88
89     private static final class DummyInstaller extends ModuleInstaller {
90         public void prepare(Module m) throws InvalidException {
91             throw new AssertionError JavaDoc();
92         }
93         public void dispose(Module m) {
94             throw new AssertionError JavaDoc();
95         }
96         public void load(List JavaDoc<Module> modules) {
97             throw new AssertionError JavaDoc();
98         }
99         public void unload(List JavaDoc<Module> modules) {
100             throw new AssertionError JavaDoc();
101         }
102         public boolean closing(List JavaDoc<Module> modules) {
103             throw new AssertionError JavaDoc();
104         }
105         public void close(List JavaDoc<Module> modules) {
106             throw new AssertionError JavaDoc();
107         }
108     }
109
110     private static final class DummyEvents extends Events {
111         protected void logged(String JavaDoc message, Object JavaDoc[] args) {}
112     }
113
114 }
115
Popular Tags