1 19 20 package org.netbeans.core.startup; 21 22 import java.io.IOException ; 23 import java.text.Collator ; 24 import java.util.HashSet ; 25 import java.util.Iterator ; 26 import java.util.Set ; 27 import java.util.SortedSet ; 28 import java.util.TreeSet ; 29 import org.netbeans.InvalidException; 30 import org.netbeans.Module; 31 import org.netbeans.Util; 32 import org.openide.modules.Dependency; 33 import org.openide.modules.SpecificationVersion; 34 import org.openide.util.NbBundle; 35 36 43 public final class NbProblemDisplayer { 44 45 private NbProblemDisplayer() {} 46 47 57 public static String messageForProblem(Module m, Object problem) { 58 if (problem instanceof InvalidException) { 59 return Util.findLocalizedMessage((InvalidException)problem, true); 60 } else { 61 Dependency dep = (Dependency)problem; 62 switch (dep.getType()) { 63 case Dependency.TYPE_MODULE: 64 String polite = (String )m.getLocalizedAttribute("OpenIDE-Module-Module-Dependency-Message"); if (polite != null) { 66 return polite; 67 } else { 68 String name = dep.getName(); 69 int idx = name.lastIndexOf('/'); 71 if (idx != -1) { 72 name = name.substring(0, idx); 73 } 74 Module other = m.getManager().get(name); 75 if (other != null && other.getCodeName().equals(dep.getName())) { 76 switch (dep.getComparison()) { 77 case Dependency.COMPARE_ANY: 78 return NbBundle.getMessage(NbProblemDisplayer.class, "MSG_problem_other_disabled", other.getDisplayName()); 80 case Dependency.COMPARE_IMPL: 81 String requestedI = dep.getVersion(); 82 String actualI = (other.getImplementationVersion() != null) ? 83 other.getImplementationVersion() : 84 NbBundle.getMessage(NbProblemDisplayer.class, "LBL_no_impl_version"); 85 if (requestedI.equals(actualI)) { 86 return NbBundle.getMessage(NbProblemDisplayer.class, "MSG_problem_other_disabled", other.getDisplayName()); 88 } else { 89 return NbBundle.getMessage(NbProblemDisplayer.class, "MSG_problem_other_wrong_version", other.getDisplayName(), requestedI, actualI); 91 } 92 case Dependency.COMPARE_SPEC: 93 SpecificationVersion requestedS = new SpecificationVersion(dep.getVersion()); 94 SpecificationVersion actualS = (other.getSpecificationVersion() != null) ? 95 other.getSpecificationVersion() : 96 new SpecificationVersion("0"); if (actualS.compareTo(requestedS) >= 0) { 98 return NbBundle.getMessage(NbProblemDisplayer.class, "MSG_problem_other_disabled", other.getDisplayName()); 100 } else { 101 return NbBundle.getMessage(NbProblemDisplayer.class, "MSG_problem_other_too_old", other.getDisplayName(), requestedS, actualS); 103 } 104 default: 105 throw new IllegalStateException (); 106 } 107 } else { 108 return NbBundle.getMessage(NbProblemDisplayer.class, "MSG_problem_other_needed_not_found", dep.getName()); 112 } 113 } 114 case Dependency.TYPE_REQUIRES: 115 case Dependency.TYPE_NEEDS: 116 polite = (String )m.getLocalizedAttribute("OpenIDE-Module-Requires-Message"); if (polite != null) { 118 return polite; 119 } else { 120 Set others = m.getManager().getModules(); 121 Iterator it = others.iterator(); 122 while (it.hasNext()) { 123 Module other = (Module)it.next(); 124 if (other.provides(dep.getName())) { 125 return NbBundle.getMessage(NbProblemDisplayer.class, "MSG_problem_require_disabled", dep.getName()); 126 } 127 } 128 return NbBundle.getMessage(NbProblemDisplayer.class, "MSG_problem_require_not_found", dep.getName()); 129 } 130 case Dependency.TYPE_PACKAGE: 131 polite = (String )m.getLocalizedAttribute("OpenIDE-Module-Package-Dependency-Message"); if (polite != null) { 133 return polite; 134 } else { 135 String name = dep.getName(); 136 int idx = name.lastIndexOf('['); 138 if (idx == 0) { 139 return NbBundle.getMessage(NbProblemDisplayer.class, "MSG_problem_class_not_loaded", name.substring(1, name.length() - 1)); 141 } else if (idx != -1) { 142 return NbBundle.getMessage(NbProblemDisplayer.class, "MSG_problem_package_not_loaded_or_old", name.substring(0, idx)); 144 } else { 145 return NbBundle.getMessage(NbProblemDisplayer.class, "MSG_problem_package_not_loaded_or_old", name); 146 } 147 } 148 case Dependency.TYPE_JAVA: 149 if (dep.getName().equals(Dependency.JAVA_NAME) && dep.getComparison() == Dependency.COMPARE_SPEC) { 151 return NbBundle.getMessage(NbProblemDisplayer.class, "MSG_problem_java_too_old", dep.getVersion(), Dependency.JAVA_SPEC); 152 } else { 153 return dep.toString(); 155 } 156 default: 157 throw new IllegalArgumentException (dep.toString()); 158 } 159 } 160 } 161 162 static void problemMessagesForModules(Appendable writeTo, Set <? extends Module> modules, boolean justRootCause) { 163 try { 164 HashSet <String > names = new HashSet <String >(); 165 for (Module m : modules) { 166 names.add(m.getCodeName()); 167 } 168 169 HashSet <String > dependantModules = new HashSet <String >(); 170 for (Module m : modules) { 171 SortedSet <String > problemTexts = new TreeSet <String >(Collator.getInstance()); 172 Iterator pit = m.getProblems().iterator(); 173 if (pit.hasNext()) { 174 while (pit.hasNext()) { 175 Object problem = pit.next(); 176 if (problem instanceof Dependency && justRootCause) { 177 Dependency d = (Dependency)problem; 178 if ( 179 d.getType() == Dependency.TYPE_MODULE && 180 names.contains(d.getName()) 181 ) { 182 dependantModules.add(m.getCodeName()); 183 continue; 184 } 185 } 186 187 problemTexts.add(m.getDisplayName() + " - " + NbProblemDisplayer.messageForProblem(m, problem)); 189 } 190 } else { 191 throw new IllegalStateException ("Module " + m + " could not be installed but had no problems"); } 193 for (String s: problemTexts) { 194 writeTo.append("\n\t").append(s); } 196 } 197 if (!dependantModules.isEmpty()) { 198 writeTo.append("\n\t").append(NbBundle.getMessage(NbProblemDisplayer.class, "MSG_also_dep_modules", dependantModules.size())); 199 } 200 } catch (IOException ex) { 201 throw (IllegalStateException )new IllegalStateException ().initCause(ex); 202 } 203 } 204 205 } 206 | Popular Tags |