Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Belle2019-04-10 07:37:34 -0400
committerJan Belle2019-04-10 07:37:34 -0400
commitc4fc914e0870f96b996033a92ba515d54c21da0c (patch)
tree44a6548344b65792bc029c980ce1bb00797d7a06 /plugins
parent8fb6b0acddb70a0d67f8a215466ca0bb922c7674 (diff)
downloadorg.eclipse.etrice-c4fc914e0870f96b996033a92ba515d54c21da0c.tar.gz
org.eclipse.etrice-c4fc914e0870f96b996033a92ba515d54c21da0c.tar.xz
org.eclipse.etrice-c4fc914e0870f96b996033a92ba515d54c21da0c.zip
[generator] Restrict validation of imported resources to errors
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/ModelValidator.java83
1 files changed, 67 insertions, 16 deletions
diff --git a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/ModelValidator.java b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/ModelValidator.java
index 40fa5abde..c4d64d1aa 100644
--- a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/ModelValidator.java
+++ b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/ModelValidator.java
@@ -26,47 +26,98 @@ import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.etrice.generator.base.args.Arguments;
import org.eclipse.etrice.generator.base.logging.ILogger;
-import org.eclipse.etrice.generator.base.validation.GeneratorResourceValidator;
+import org.eclipse.etrice.generator.base.validation.IGeneratorResourceValidator;
+import org.eclipse.xtext.diagnostics.Severity;
+import org.eclipse.xtext.util.CancelIndicator;
+import org.eclipse.xtext.validation.CheckMode;
import org.eclipse.xtext.validation.IResourceValidator;
+import org.eclipse.xtext.validation.Issue;
import com.google.inject.Inject;
/**
* Validates all resources in the transitive closure of the input files.
*/
-public class ModelValidator extends GeneratorResourceValidator {
+public class ModelValidator implements IGeneratorResourceValidator {
+
+ private IResourceValidator resourceValidator;
@Inject
public ModelValidator(IResourceValidator validator) {
- super(validator);
+ this.resourceValidator = validator;
}
@Override
public void validate(List<Resource> resources, Arguments arguments, ILogger logger) {
- logger.logInfo("-- validating models");
- try {
- validateTransitiveClosure(resources, arguments, logger);
- }
- catch(Exception e) {
- logger.logInfo("validation failed");
- logger.logInfo("-- terminating");
- throw e;
- }
+ validateTransitiveClosure(resources, arguments, logger);
}
/**
* Validate all referenced models (including transitive references).
+ * Only errors are reported for imported resources.
*
* @param resources the resources to validate the transitive closure of
* @param arguments the generator arguments
* @param logger the logger to log issues
*/
private void validateTransitiveClosure(List<Resource> resources, Arguments arguments, ILogger logger) {
- Set<Resource> transitiveClosure = new LinkedHashSet<>();
- resources.forEach(r -> computeTransitiveClosure(r, transitiveClosure));
- List<Resource> toValidate = new ArrayList<>(transitiveClosure);
+ logger.logInfo("-- validating models");
+
+ int errors = 0;
+ int warnings = 0;
+ List<Resource> importedResources = computeImportedResources(resources);
- super.validate(toValidate, arguments, logger);
+ // Validate imported resources, only report errors (see Bug 546145)
+ for(Resource resource : importedResources) {
+ List<Issue> list = resourceValidator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
+ for(Issue issue: list) {
+ if(issue.getSeverity() == Severity.ERROR) {
+ ++errors;
+ logger.logError(issue.toString());
+ }
+ }
+ }
+
+ // Validate resources
+ for (Resource resource : resources) {
+ List<Issue> list = resourceValidator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
+ for (Issue issue : list) {
+ if (issue.getSeverity() == Severity.ERROR) {
+ ++errors;
+ logger.logError(issue.toString());
+ }
+ else if(issue.getSeverity() == Severity.WARNING) {
+ ++warnings;
+ logger.logWarning(issue.toString());
+ }
+ else {
+ logger.logInfo(issue.toString());
+ }
+ }
+ }
+
+ if(warnings > 0) {
+ logger.logWarning(warnings + " warnings");
+ }
+ if(errors > 0) {
+ logger.logError(errors + " errors");
+ logger.logInfo("validation failed");
+ logger.logInfo("-- terminating");
+ throw new GeneratorException("validation failed");
+ }
+ }
+
+ /**
+ * Computes a list of imported resources.
+ *
+ * @param the resources to compute the imported resources of
+ * @return list of imported resources
+ */
+ private List<Resource> computeImportedResources(List<Resource> resources) {
+ Set<Resource> closure = new LinkedHashSet<>();
+ resources.forEach(r -> computeTransitiveClosure(r, closure));
+ closure.removeAll(resources);
+ return new ArrayList<>(closure);
}
/**

Back to the top