use of org.netbeans.api.autoupdate.UpdateUnit in project netbeans-rcp-lite by outersky.
the class OperationDescriptionStep method getPresentationName.
private static String getPresentationName(String dep) {
String presentationName = null;
boolean isPending = false;
String reason = null;
if (dep != null && dep.startsWith("module")) {
// NOI18N
String codeName = dep.substring(6).trim();
// NOI18N
int end = codeName.indexOf('/');
String releaseVersion = null;
if (end == -1) {
// NOI18N
end = codeName.indexOf(' ');
} else {
int spaceIndex = codeName.indexOf(' ');
int index = (spaceIndex != -1) ? spaceIndex : codeName.length();
releaseVersion = codeName.substring(end + 1, index).trim();
}
if (end != -1) {
codeName = codeName.substring(0, end);
}
int greater = dep.indexOf('>');
int equals = dep.indexOf('=');
int idx = Math.max(greater, equals);
String version = null;
if (idx > 0) {
version = dep.substring(idx + 2).trim();
}
UpdateElement other = null;
for (UpdateUnit u : UpdateManager.getDefault().getUpdateUnits(UpdateManager.TYPE.MODULE)) {
if (codeName.equals(u.getCodeName())) {
if (u.getInstalled() != null) {
other = u.getInstalled();
} else if (u.getAvailableUpdates().size() > 0) {
other = u.getAvailableUpdates().get(0);
}
if (u != null) {
isPending = u.isPending();
}
break;
}
}
if (idx == -1) {
// COMPARE_ANY
// The module named {0} was needed and not found.
reason = getBundle("OperationDescriptionStep_BrokenModuleNameDep", other == null ? codeName : other.getDisplayName());
} else if (greater > 0) {
// COMPARE_SPEC
if (version != null && other != null && version.equals(other.getSpecificationVersion())) {
// The module {0} would also need to be installed.
reason = getBundle("OperationDescriptionStep_BrokenModuleDep", other.getDisplayName());
} else if (version != null) {
if (other != null) {
// The module {0} was requested in version >= {1} but only {2} was found.
int compare = new SpecificationVersion(other.getSpecificationVersion()).compareTo(new SpecificationVersion(version));
if (releaseVersion != null && (equals > 0 ? (compare >= 0) : (compare > 0))) {
reason = getBundle("OperationDescriptionStep_BrokenModuleReleaseVersionDep", other.getDisplayName(), version, releaseVersion, other.getSpecificationVersion());
} else {
reason = getBundle("OperationDescriptionStep_BrokenModuleVersionDep", other.getDisplayName(), version, other.getSpecificationVersion());
}
} else {
// The module {0} was requested in version >= {1}.
reason = getBundle("OperationDescriptionStep_BrokenModuleOnlyVersionDep", codeName, version);
}
} else {
// The module {0} would also need to be installed.
reason = getBundle("OperationDescriptionStep_BrokenModuleDep", other == null ? codeName : other.getDisplayName());
}
} else if (equals > 0) {
// The module {0} was requested in implementation version "{1}".
if (version != null) {
reason = getBundle("OperationDescriptionStep_BrokenModuleImplDep", other == null ? codeName : other.getDisplayName(), version);
} else {
reason = getBundle("OperationDescriptionStep_BrokenModuleDep", other == null ? codeName : other.getDisplayName());
}
}
if (isPending) {
presentationName = getBundle(// NOI18N
"OperationDescriptionStep_BrokenPendingModuleDepInit", // NOI18N
other == null ? codeName : other.getDisplayName(), reason);
} else {
presentationName = getBundle(// NOI18N
"OperationDescriptionStep_BrokenModuleDepInit", // NOI18N
other == null ? codeName : other.getDisplayName(), reason);
}
} else if (dep != null && (dep.toLowerCase().startsWith("requires") || dep.toLowerCase().startsWith("needs"))) {
// NOI18N
// No module providing the capability {0} could be found.
String token = dep.substring(dep.indexOf(' ') + 1);
presentationName = getBundle("OperationDescriptionStep_BrokenRequireDepInit", token, getBundle("OperationDescriptionStep_BrokenRequiresDep", token));
} else if (dep != null && dep.toLowerCase().startsWith("java")) {
// NOI18N
presentationName = getBundle("OperationDescriptionStep_BrokenJavaDepInit", dep, getBundle("OperationDescriptionStep_PluginBrokesJavaDependency", dep, Dependency.JAVA_SPEC));
} else if (dep != null && dep.toLowerCase().startsWith("package")) {
// NOI18N
presentationName = getBundle("OperationDescriptionStep_BrokenPackageDepInit");
}
return presentationName == null ? dep : presentationName;
}
use of org.netbeans.api.autoupdate.UpdateUnit in project netbeans-rcp-lite by outersky.
the class OperationDescriptionStep method preparePluginsForShow.
private String preparePluginsForShow(Set<UpdateElement> allPlugins, Set<UpdateElement> visiblePlugins, Set<UpdateElement> customHandled, OperationType type) {
String s = new String();
List<String> names = new ArrayList<String>();
if (OperationWizardModel.OperationType.UPDATE != type) {
if (visiblePlugins != null && !visiblePlugins.isEmpty()) {
for (UpdateElement el : visiblePlugins) {
// NOI18N
String updatename = "<b>" + el.getDisplayName() + "</b> ";
updatename += getBundle(// NOI18N
"OperationDescriptionStep_PluginVersionFormat", el.getSpecificationVersion());
// NOI18N
updatename += "<br>";
String notification = el.getNotification();
if (notification != null && notification.length() > 0) {
// NOI18N
updatename += "<font color=\"red\">" + notification + "</font><br><br>";
}
names.add(updatename);
}
Collections.sort(names, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return Collator.getInstance().compare(o1, o2);
}
});
for (String name : names) {
s += name;
}
}
} else {
SortedMap<UpdateUnit, TreeSet<UpdateElement>> visible2internals = new TreeMap<UpdateUnit, TreeSet<UpdateElement>>(new Comparator<UpdateUnit>() {
@Override
public int compare(UpdateUnit o1, UpdateUnit o2) {
UpdateElement ue1 = o1.getInstalled() != null ? o1.getInstalled() : o1.getAvailableUpdates().get(0);
UpdateElement ue2 = o2.getInstalled() != null ? o2.getInstalled() : o2.getAvailableUpdates().get(0);
return ue1.getDisplayName().compareTo(ue2.getDisplayName());
}
});
for (UpdateElement el : allPlugins) {
// a kit
if (UpdateManager.TYPE.KIT_MODULE.equals(el.getUpdateUnit().getType())) {
if (!visible2internals.containsKey(el.getUpdateUnit())) {
TreeSet<UpdateElement> elements = new TreeSet<UpdateElement>(new Comparator<UpdateElement>() {
@Override
public int compare(UpdateElement o1, UpdateElement o2) {
return o1.getDisplayName().compareTo(o2.getDisplayName());
}
});
visible2internals.put(el.getUpdateUnit(), elements);
}
} else {
UpdateUnit visibleUnit = el.getUpdateUnit().getVisibleAncestor();
// w/ visible ancestor
if (visibleUnit != null) {
if (!visible2internals.containsKey(visibleUnit)) {
TreeSet<UpdateElement> elements = new TreeSet<UpdateElement>(new Comparator<UpdateElement>() {
@Override
public int compare(UpdateElement o1, UpdateElement o2) {
return o1.getDisplayName().compareTo(o2.getDisplayName());
}
});
visible2internals.put(visibleUnit, elements);
}
visible2internals.get(visibleUnit).add(el);
} else {
// a fallback, w/o visible ancestor
if (!visible2internals.containsKey(el.getUpdateUnit())) {
TreeSet<UpdateElement> elements = new TreeSet<UpdateElement>(new Comparator<UpdateElement>() {
@Override
public int compare(UpdateElement o1, UpdateElement o2) {
return o1.getDisplayName().compareTo(o2.getDisplayName());
}
});
visible2internals.put(el.getUpdateUnit(), elements);
}
}
}
}
// prepare for show
UpdateElement element4showing = null;
for (UpdateUnit unit : visible2internals.keySet()) {
String updatename = "<b>";
if (unit.getInstalled() != null) {
// NOI18N
updatename += unit.getInstalled().getDisplayName() + "</b> ";
} else {
// NOI18N
updatename += unit.getAvailableUpdates().get(0).getDisplayName() + "</b> ";
}
if (visible2internals.get(unit).isEmpty()) {
element4showing = unit.getAvailableUpdates().get(0);
if (unit.getInstalled() != null) {
String oldVersion = unit.getInstalled().getSpecificationVersion();
String newVersion = element4showing.getSpecificationVersion();
updatename += getBundle("OperationDescriptionStep_UpdatePluginVersionFormat", oldVersion, newVersion);
} else {
String newVersion = element4showing.getSpecificationVersion();
updatename += getBundle("OperationDescriptionStep_PluginVersionFormat", newVersion);
}
} else {
for (UpdateElement el : visible2internals.get(unit)) {
element4showing = el;
if (el.getUpdateUnit().getInstalled() != null) {
updatename += "<br> " + el.getDisplayName() + " [" + el.getUpdateUnit().getInstalled().getSpecificationVersion() + " -> " + el.getSpecificationVersion() + "]";
} else {
updatename += "<br> " + el.getDisplayName() + " [" + unit.getAvailableUpdates().get(0).getSpecificationVersion() + "]";
}
}
}
// NOI18N
updatename += "<br>";
String notification = element4showing == null ? "" : element4showing.getNotification();
if (notification != null && notification.length() > 0) {
// NOI18N
updatename += "<font color=\"red\">" + notification + "</font><br><br>";
}
names.add(updatename);
}
for (String name : names) {
s += name;
}
}
if (customHandled != null && !customHandled.isEmpty()) {
names = new ArrayList<String>();
for (UpdateElement el : customHandled) {
names.add(// NOI18N
"<b>" + el.getDisplayName() + "</b> " + getBundle(// NOI18N
"OperationDescriptionStep_PluginVersionFormat", el.getSpecificationVersion()) + // NOI18N
"<br>");
}
Collections.sort(names);
// NOI18N
s += "<br>" + getBundle("OperationDescriptionStep_CustomHandled_Head", customHandled.size()) + "<br>";
for (String name : names) {
s += name;
}
}
return s.trim();
}
use of org.netbeans.api.autoupdate.UpdateUnit in project netbeans-rcp-lite by outersky.
the class LocalDownloadSupport method getDisplayNames.
private String getDisplayNames(Collection<UpdateUnit> units) {
SortedSet<String> names = new TreeSet<String>();
for (UpdateUnit uu : units) {
if (uu.getInstalled() != null) {
names.add(uu.getInstalled().getDisplayName());
} else {
names.add(uu.getAvailableUpdates().get(0).getDisplayName());
}
}
String res = "";
for (String dn : names) {
// NOI18N
res += res.length() == 0 ? dn : ", " + dn;
}
return res;
}
use of org.netbeans.api.autoupdate.UpdateUnit in project netbeans-rcp-lite by outersky.
the class LocalDownloadSupport method createUpdateUnitFromNBM.
private UpdateUnit createUpdateUnitFromNBM(File nbm, boolean quiet) {
UpdateUnitProviderFactory factory = UpdateUnitProviderFactory.getDefault();
UpdateUnitProvider provider = factory.create(nbm.getName(), new File[] { nbm });
List<UpdateUnit> units = Collections.emptyList();
try {
units = provider.getUpdateUnits(UpdateManager.TYPE.MODULE);
} catch (RuntimeException re) {
if (!quiet) {
err.log(Level.INFO, re.getMessage(), re);
DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Exception(re, NbBundle.getMessage(LocalDownloadSupport.class, "LocalDownloadSupport_BrokenNBM_Exception", nbm.getName(), re.getLocalizedMessage())));
fileList.removeFile(nbm);
}
}
if (units == null || units.isEmpty()) {
// skip to another one
return null;
}
assert units.size() == 1 : "Only once UpdateUnit for " + nbm + " but " + units;
return units.get(0);
}
use of org.netbeans.api.autoupdate.UpdateUnit in project netbeans-rcp-lite by outersky.
the class LocalDownloadSupport method initCodeName2Unit.
private synchronized void initCodeName2Unit() {
assert nbm2unitCodeName == null : "Cannot initialize nbm2unit twice!";
nbm2unitCodeName = new HashMap<File, String>();
codeName2unit = new HashMap<String, UpdateUnit>();
Iterator<File> it = getAllFiles().iterator();
while (it.hasNext()) {
File nbm = it.next();
UpdateUnit u = createUpdateUnitFromNBM(nbm, true);
if (u != null && !u.getAvailableUpdates().isEmpty()) {
nbm2unitCodeName.put(nbm, u.getCodeName());
codeName2unit.put(u.getCodeName(), u);
} else {
it.remove();
}
}
}
Aggregations