}
return ret;
}
private Diagnostic doGenerateTargetDefinitionFile(URI uri, IProgressMonitor monitor) {
BasicDiagnostic ret = new BasicDiagnostic();
SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
try {
Resource resource = loadTargetPlatform(uri);
subMonitor.worked(2);
Diagnostic resourceDiagnostic = EcoreUtil.computeDiagnostic(resource, true);
if (resourceDiagnostic.getSeverity() >= Diagnostic.WARNING) {
ret.merge(resourceDiagnostic);
}
if (resourceDiagnostic.getSeverity() < Diagnostic.ERROR) {
TargetPlatform targetPlatform = null;
if (resource != null && !resource.getContents().isEmpty()) {
targetPlatform = (TargetPlatform) resource.getContents().get(0);
}
if (targetPlatform == null) {
ret.merge(new BasicDiagnostic(Diagnostic.ERROR, TargetPlatformBundleActivator.PLUGIN_ID, -1, "Error occured while loading the file " + uri + ".", null));
} else if (subMonitor.isCanceled()) {
ret.merge(Diagnostic.CANCEL_INSTANCE);
} else {
SubMonitor diagnosticianMonitor = subMonitor.newChild(90).setWorkRemaining(targetPlatform.getLocations().size());
Diagnostic validation = new CustomDiagnostician(diagnosticianMonitor).validate(targetPlatform);
if (validation.getSeverity() >= Diagnostic.WARNING) {
ret.merge(validation);
} else if (subMonitor.isCanceled()) {
ret.merge(Diagnostic.CANCEL_INSTANCE);
}
if (validation.getSeverity() < Diagnostic.ERROR) {
Diagnostic diagnostic = doGenerateTargetDefinitionFile(uri, targetPlatform, subMonitor.newChild(8));
if (diagnostic.getSeverity() >= Diagnostic.WARNING) {
ret.merge(diagnostic);
}
}
subMonitor.setWorkRemaining(0);
}
}
} catch (Exception e) {
ret.merge(BasicDiagnostic.toDiagnostic(e));
}
return ret;
}