1 19 20 package org.netbeans.modules.autoupdate; 21 22 import java.io.IOException ; 23 import java.net.URL ; 24 import java.util.*; 25 import java.util.jar.Attributes ; 26 27 import org.openide.modules.Dependency; 28 import org.openide.modules.ModuleInfo; 29 import org.openide.modules.SpecificationVersion; 30 31 import org.netbeans.core.startup.AutomaticDependencies; 32 import org.openide.filesystems.FileObject; 33 import org.openide.filesystems.FileStateInvalidException; 34 import org.openide.filesystems.Repository; 35 import org.openide.util.Exceptions; 36 import org.xml.sax.SAXException ; 37 38 42 final class DummyModuleInfo extends ModuleInfo { 43 44 private static AutomaticDependencies autoDepsHandler = null; 45 46 50 private static synchronized AutomaticDependencies getAutoDepsHandler() { 51 if (autoDepsHandler == null) { 52 FileObject depsFolder = Repository.getDefault().getDefaultFileSystem().findResource("ModuleAutoDeps"); if (depsFolder != null) { 54 FileObject[] kids = depsFolder.getChildren(); 55 List urls = new ArrayList(Math.max(kids.length, 1)); for (int i = 0; i < kids.length; i++) { 57 if (kids[i].hasExt("xml")) { 58 try { 59 urls.add(kids[i].getURL()); 60 } 61 catch (FileStateInvalidException e) { 62 Exceptions.printStackTrace(e); 63 } 64 } 65 } 66 try { 67 autoDepsHandler = AutomaticDependencies.parse((URL [])urls.toArray(new URL [urls.size()])); 68 } catch (IOException e) { 69 Exceptions.printStackTrace(e); 70 } catch (SAXException e) { 71 Exceptions.printStackTrace(e); 72 } 73 } 74 if (autoDepsHandler == null) { 75 autoDepsHandler = AutomaticDependencies.empty(); 77 } 78 } 79 return autoDepsHandler; 80 } 81 82 private final Attributes attr; 83 private final Set deps; private final String [] provides; 85 86 90 public DummyModuleInfo(Attributes attr) throws IllegalArgumentException { 91 this.attr = attr; 92 if (getCodeName() == null) throw new IllegalArgumentException (); 93 String cnb = getCodeNameBase(); 94 try { 95 getSpecificationVersion(); 96 } catch (NumberFormatException nfe) { 97 throw new IllegalArgumentException (nfe.toString() + " from " + cnb); } 99 deps = parseDeps(attr, cnb); 100 getAutoDepsHandler().refineDependencies(cnb, deps); String providesS = attr.getValue("OpenIDE-Module-Provides"); if (providesS == null) { 103 provides = new String [0]; 104 } else { 105 StringTokenizer tok = new StringTokenizer(providesS, ", "); provides = new String [tok.countTokens()]; 107 for (int i = 0; i < provides.length; i++) { 108 provides[i] = tok.nextToken(); 109 } 110 } 111 } 113 114 public boolean isEnabled() { 115 return false; 116 } 117 118 public SpecificationVersion getSpecificationVersion() { 119 String sv = attr.getValue("OpenIDE-Module-Specification-Version"); return (sv == null ? null : new SpecificationVersion(sv)); 121 } 122 123 public String getCodeName() { 124 return attr.getValue("OpenIDE-Module"); } 126 127 public int getCodeNameRelease() { 128 String s = getCodeName(); 129 int idx = s.lastIndexOf('/'); if (idx == -1) { 131 return -1; 132 } else { 133 return Integer.parseInt(s.substring(idx + 1)); 134 } 135 } 136 137 public String getCodeNameBase() { 138 String s = getCodeName(); 139 int idx = s.lastIndexOf('/'); if (idx == -1) { 141 return s; 142 } else { 143 return s.substring(0, idx); 144 } 145 } 146 147 public Object getLocalizedAttribute(String a) { 148 return attr.getValue(a); 149 } 150 151 public Object getAttribute(String a) { 152 return attr.getValue(a); 153 } 154 155 156 public Set getDependencies() { 157 return deps; 158 } 159 160 private final static Set parseDeps(Attributes attr, String cnb) throws IllegalArgumentException { 161 Set s = new HashSet(); s.addAll(Dependency.create(Dependency.TYPE_MODULE, attr.getValue("OpenIDE-Module-Module-Dependencies"))); s.addAll(Dependency.create(Dependency.TYPE_PACKAGE, attr.getValue("OpenIDE-Module-Package-Dependencies"))); s.addAll(Dependency.create(Dependency.TYPE_IDE, attr.getValue("OpenIDE-Module-IDE-Dependencies"))); s.addAll(Dependency.create(Dependency.TYPE_JAVA, attr.getValue("OpenIDE-Module-Java-Dependencies"))); s.addAll(Dependency.create(Dependency.TYPE_REQUIRES, attr.getValue("OpenIDE-Module-Requires"))); Iterator it = s.iterator(); 169 SpecificationVersion api = null; 170 String impl = null; 171 String major = null; 172 while (it.hasNext()) { 173 Dependency dep = (Dependency)it.next(); 174 if (dep.getType() == Dependency.TYPE_IDE) { 175 if (dep.getComparison() == Dependency.COMPARE_SPEC) { 176 if (api != null) { 177 throw new IllegalArgumentException ("Duplicate OpenIDE-Module-IDE-Dependencies found!"); } 179 api = new SpecificationVersion(dep.getVersion()); 180 } else { 181 if (impl != null) { 183 throw new IllegalArgumentException ("Duplicate OpenIDE-Module-IDE-Dependencies found!"); } 185 impl = dep.getVersion(); 186 } 187 String name = dep.getName(); 188 int index = name.lastIndexOf('/'); 189 String newmajor; 190 if (index == -1) { 191 newmajor = ""; } else { 193 newmajor = name.substring(index); 194 } 195 if (major != null && !major.equals(newmajor)) { 196 throw new IllegalArgumentException ("Clashing OpenIDE-Module-IDE-Dependencies found!"); } 198 major = newmajor; 199 it.remove(); 200 } 201 } 202 if (api != null) { 203 s.addAll(Dependency.create(Dependency.TYPE_MODULE, "org.openide" + major + " > " + api)); } 205 if (impl != null) { 206 s.addAll(Dependency.create(Dependency.TYPE_MODULE, "org.openide" + major + " = " + impl)); } 208 if (api == null && impl == null) { 209 s.addAll(Dependency.create(Dependency.TYPE_MODULE, "org.openide/1 > 0")); } 213 return s; 214 } 215 216 public boolean owns(Class clazz) { 217 return false; 218 } 219 220 public String [] getProvides() { 221 return provides; 222 } 223 } 224 | Popular Tags |