瀏覽代碼

Validate model before generation (#922)

* Validate model before generation

* Minor refactorings.

* Removed obsolete extension point entries.

* Validate model before generation

* Extracted logging methods for better overwriting in subclasses.

* #790: Preferences documented.

* Added missing binding for type inferrer and re-added test.

* Whitespace fix.

* Removed beautifier and improved templates for better formatted java code.

* Fixed exception when simulation was stopped and restarted again (via snapshot).

* Fixed templates for custom code generators. Revived workspace generator wizard.

* Only use XMIResource when no default domain is registered

* Fixed Templates for new Generator Project Wizard

* removed deprecated feature configurationModule  from user .doc

* Moved binding for SCTFileEditorOpener to executable extension factory in order to fix hyperlink from SGen model to statechart.

* return null in case no objects are found for cross link fragments

* Five-minutes tutorial adopted to examples wizard.

* Extended type hierarchy by multi inheritance as there might be types which have multiple super types.

* Added documentation for translation of macro definition statements.

* Section numbering in Eclipsehelp added.

* #933: Support for installing examples via drag and drop of a URL.

* #933: Drag drop support for installing examples.

* Fixed compilation error for luna target.

* Refactored drop listeners.

* Filter out empty categories.

* Automatically download examples from repo on drop installation.

* Added copyright headers.

* Validate model before generation

* Validate model before generation

* Disable validation in gTest Helper

* Moved SCTResourceDescriptionStrategy to stext runtime module to avoid ui
dependencies
Andreas Mülder 9 年之前
父節點
當前提交
e438af2057

+ 0 - 2
plugins/org.yakindu.sct.branding/build.properties

@@ -1,5 +1,3 @@
-source.. = src/
-output.. = bin/
 bin.includes = META-INF/,\
                .,\
                about.html,\

+ 6 - 0
plugins/org.yakindu.sct.domain.generic.generator/src/org/yakindu/sct/domain/generic/generator/GenericGeneratorModule.java

@@ -13,9 +13,11 @@ package org.yakindu.sct.domain.generic.generator;
 
 import org.eclipse.xtext.naming.IQualifiedNameProvider;
 import org.eclipse.xtext.service.AbstractGenericModule;
+import org.eclipse.xtext.validation.IResourceValidator;
 import org.yakindu.base.types.typesystem.GenericTypeSystem;
 import org.yakindu.base.types.typesystem.ITypeSystem;
 import org.yakindu.sct.model.stext.naming.StextNameProvider;
+import org.yakindu.sct.model.stext.resource.SCTResourceValidatorImpl;
 
 import com.google.inject.Binder;
 
@@ -38,4 +40,8 @@ public class GenericGeneratorModule extends AbstractGenericModule {
 		return StextNameProvider.class;
 	}
 
+	public Class<? extends IResourceValidator> bindIResourceValidator() {
+		return SCTResourceValidatorImpl.class;
+	}
+
 }

+ 47 - 7
plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/execution/AbstractGeneratorEntryExecutor.java

@@ -10,6 +10,12 @@
  */
 package org.yakindu.sct.generator.core.execution;
 
+import java.util.List;
+
+import org.eclipse.xtext.diagnostics.Severity;
+import org.eclipse.xtext.validation.CheckMode;
+import org.eclipse.xtext.validation.IResourceValidator;
+import org.eclipse.xtext.validation.Issue;
 import org.yakindu.base.base.NamedElement;
 import org.yakindu.sct.generator.core.console.IConsoleLogger;
 import org.yakindu.sct.generator.core.filesystem.DefaultFileSystemAccessFactory;
@@ -17,7 +23,10 @@ import org.yakindu.sct.generator.core.filesystem.ISCTFileSystemAccess;
 import org.yakindu.sct.generator.core.library.ICoreLibraryHelper;
 import org.yakindu.sct.model.sgen.GeneratorEntry;
 
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
 import com.google.inject.Inject;
+import com.google.inject.name.Named;
 
 /**
  * 
@@ -32,19 +41,29 @@ public abstract class AbstractGeneratorEntryExecutor implements IGeneratorEntryE
 	protected IConsoleLogger logger;
 	@Inject
 	protected ICoreLibraryHelper helper;
+	@Inject
+	protected IResourceValidator validator;
+	@Inject(optional = true)
+	@Named(SKIP_VALIDATION)
+	protected boolean skipValidation = false;
 
 	protected abstract void execute(ISCTFileSystemAccess access, GeneratorEntry generatorEntry);
 
 	@Override
 	public void execute(GeneratorEntry entry) {
-		logStart(entry);
-		try {
-			execute(factory.create(entry), entry);
-		} catch (Exception ex) {
-			logException(ex);
-		} finally {
-			logEnd(entry);
+		NamedElement element = (NamedElement) entry.getElementRef();
+		if (valid(entry)) {
+			logger.log("Generating '" + element.getName() + "' to target project ..."
+					+ helper.getTargetProjectValue(entry).getStringValue());
+			try {
+				execute(factory.create(entry), entry);
+			} catch (Exception ex) {
+				logger.logError(ex);
+			} finally {
+				logger.log("done...");
+			}
 		}
+
 	}
 
 	protected void logStart(GeneratorEntry entry) {
@@ -61,4 +80,25 @@ public abstract class AbstractGeneratorEntryExecutor implements IGeneratorEntryE
 		logger.logError(ex);
 	}
 
+	protected boolean valid(GeneratorEntry entry) {
+		if (skipValidation) {
+			logger.log("Validation skipped...");
+			return true;
+		}
+		List<Issue> issues = validator.validate(entry.getElementRef().eResource(), CheckMode.ALL, null);
+		Iterable<Issue> errors = Iterables.filter(issues, new Predicate<Issue>() {
+			@Override
+			public boolean apply(Issue input) {
+				return input.getSeverity() == Severity.ERROR;
+			}
+		});
+		if (!Iterables.isEmpty(errors)) {
+			logger.log("The referenced model contains errors and could not be generated:");
+			for (Issue issue : errors) {
+				logger.log(issue.getMessage());
+			}
+			return false;
+		}
+		return true;
+	}
 }

+ 2 - 0
plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/execution/IGeneratorEntryExecutor.java

@@ -19,6 +19,8 @@ import org.yakindu.sct.model.sgen.GeneratorEntry;
  */
 public interface IGeneratorEntryExecutor {
 
+	public static final String SKIP_VALIDATION = "skipValidation";
+	
 	public void execute(GeneratorEntry entry);
 
 }

+ 1 - 2
plugins/org.yakindu.sct.model.resource/META-INF/MANIFEST.MF

@@ -18,5 +18,4 @@ Require-Bundle: org.eclipse.ui,
  org.yakindu.sct.ui.editor
 Bundle-RequiredExecutionEnvironment: JavaSE-1.7
 Bundle-ActivationPolicy: lazy
-Export-Package: org.yakindu.sct.model.resource,
- org.yakindu.sct.model.resource.validation
+Export-Package: org.yakindu.sct.model.resource

+ 3 - 2
plugins/org.yakindu.sct.model.resource/src/org/yakindu/sct/model/resource/SCTExecutableExtensionFactory.java

@@ -23,11 +23,12 @@ import org.eclipse.xtext.ui.validation.MarkerTypeProvider;
 import org.eclipse.xtext.validation.IDiagnosticConverter;
 import org.eclipse.xtext.validation.IResourceValidator;
 import org.osgi.framework.Bundle;
-import org.yakindu.sct.model.resource.validation.SCTResourceValidatorImpl;
 import org.yakindu.sct.model.sgraph.ui.validation.SCTDiagnosticConverterImpl;
 import org.yakindu.sct.model.sgraph.ui.validation.SCTMarkerCreator;
 import org.yakindu.sct.model.sgraph.ui.validation.SCTMarkerTypeProvider;
 import org.yakindu.sct.model.stext.naming.StextNameProvider;
+import org.yakindu.sct.model.stext.resource.SCTResourceDescriptionStrategy;
+import org.yakindu.sct.model.stext.resource.SCTResourceValidatorImpl;
 import org.yakindu.sct.ui.editor.editor.SCTFileEditorOpener;
 
 import com.google.inject.Binder;
@@ -72,4 +73,4 @@ public class SCTExecutableExtensionFactory extends AbstractGuiceAwareExecutableE
 		});
 	}
 
-}
+}

+ 8 - 0
plugins/org.yakindu.sct.model.stext/src/org/yakindu/sct/model/stext/STextRuntimeModule.java

@@ -14,6 +14,7 @@ import org.eclipse.emf.ecore.resource.Resource;
 import org.eclipse.xtext.Constants;
 import org.eclipse.xtext.linking.ILinker;
 import org.eclipse.xtext.naming.IQualifiedNameProvider;
+import org.eclipse.xtext.resource.IDefaultResourceDescriptionStrategy;
 import org.eclipse.xtext.validation.CompositeEValidator;
 import org.yakindu.base.types.inferrer.ITypeSystemInferrer;
 import org.yakindu.base.types.typesystem.GenericTypeSystem;
@@ -22,6 +23,7 @@ import org.yakindu.sct.model.sgraph.resource.SCTLinker;
 import org.yakindu.sct.model.stext.conversion.StextValueConverterService;
 import org.yakindu.sct.model.stext.inferrer.STextTypeInferrer;
 import org.yakindu.sct.model.stext.naming.StextNameProvider;
+import org.yakindu.sct.model.stext.resource.SCTResourceDescriptionStrategy;
 import org.yakindu.sct.model.stext.resource.StextResource;
 import org.yakindu.sct.model.stext.scoping.STextGlobalScopeProvider;
 
@@ -37,6 +39,12 @@ import com.google.inject.name.Names;
  */
 public class STextRuntimeModule extends org.yakindu.sct.model.stext.AbstractSTextRuntimeModule {
 
+	
+	@Override
+	public void configure(Binder binder) {
+		super.configure(binder);
+		binder.bind(IDefaultResourceDescriptionStrategy.class).to(SCTResourceDescriptionStrategy.class);
+	}
 	public Class<? extends org.eclipse.xtext.scoping.IGlobalScopeProvider> bindIGlobalScopeProvider() {
 		return STextGlobalScopeProvider.class;
 	}

+ 1 - 1
plugins/org.yakindu.sct.model.resource/src/org/yakindu/sct/model/resource/SCTResourceDescriptionStrategy.java

@@ -8,7 +8,7 @@
  * 	committers of YAKINDU - initial API and implementation
  * 
  */
-package org.yakindu.sct.model.resource;
+package org.yakindu.sct.model.stext.resource;
 
 import org.eclipse.emf.ecore.EObject;
 import org.eclipse.emf.ecore.util.EcoreUtil;

+ 1 - 1
plugins/org.yakindu.sct.model.resource/src/org/yakindu/sct/model/resource/validation/SCTResourceValidatorImpl.java

@@ -8,7 +8,7 @@
  * 	committers of YAKINDU - initial API and implementation
  * 
  */
-package org.yakindu.sct.model.resource.validation;
+package org.yakindu.sct.model.stext.resource;
 
 import org.eclipse.emf.ecore.EObject;
 import org.eclipse.emf.ecore.resource.Resource;

+ 19 - 1
test-plugins/org.yakindu.sct.generator.c.test/src/org/yakindu/sct/generator/c/gtest/GTestHelper.java

@@ -38,10 +38,16 @@ import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.FrameworkUtil;
 import org.yakindu.sct.generator.builder.EclipseContextGeneratorExecutorLookup;
+import org.yakindu.sct.generator.core.execution.IGeneratorEntryExecutor;
 import org.yakindu.sct.model.sgen.GeneratorModel;
 import org.yakindu.sct.model.sgraph.Statechart;
 import org.yakindu.sct.test.models.SCTUnitTestModels;
 
+import com.google.inject.Binder;
+import com.google.inject.Module;
+import com.google.inject.name.Names;
+import com.google.inject.util.Modules;
+
 /**
  * @author Andreas Unger - Initial contribution and API
  * @author Markus Mühlbrandt
@@ -81,7 +87,19 @@ public class GTestHelper {
 
 		performFullBuild();
 
-		new EclipseContextGeneratorExecutorLookup().execute(model);
+		new EclipseContextGeneratorExecutorLookup() {
+			@Override
+			protected Module getContextModule() {
+				return Modules.override(super.getContextModule()).with(new Module() {
+					@Override
+					public void configure(Binder binder) {
+						binder.bind(boolean.class).annotatedWith(Names.named(IGeneratorEntryExecutor.SKIP_VALIDATION))
+								.toInstance(true);
+					}
+				});
+			}
+
+		}.execute(model);
 	}
 
 	protected GCCCommandExecutor getCommandExecutor() {