From ac40e3b4288a4fb66fe5e6fa02a1f13775e2bf5b Mon Sep 17 00:00:00 2001 From: Andreas Muelder Date: Fri, 12 Aug 2016 14:25:10 +0200 Subject: [PATCH] #899 extracted workspace runner plugin --- library/GenericJavaFeatureTypeLibrary.xmi | 8 - plugin.xml | 30 ---- .../core/AbstractWorkspaceGenerator.java | 66 -------- .../impl/IGenericJavaFeatureConstants.java | 19 --- .../core/impl/GenericJavaBasedGenerator.java | 141 ------------------ ...enericJavaLibraryDefaultValueProvider.java | 72 --------- 6 files changed, 336 deletions(-) delete mode 100644 library/GenericJavaFeatureTypeLibrary.xmi delete mode 100644 src/org/yakindu/sct/generator/core/AbstractWorkspaceGenerator.java delete mode 100644 src/org/yakindu/sct/generator/core/features/impl/IGenericJavaFeatureConstants.java delete mode 100644 src/org/yakindu/sct/generator/core/impl/GenericJavaBasedGenerator.java delete mode 100644 src/org/yakindu/sct/generator/core/library/impl/GenericJavaLibraryDefaultValueProvider.java diff --git a/library/GenericJavaFeatureTypeLibrary.xmi b/library/GenericJavaFeatureTypeLibrary.xmi deleted file mode 100644 index 879aaccdd6..0000000000 --- a/library/GenericJavaFeatureTypeLibrary.xmi +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/plugin.xml b/plugin.xml index 440722f656..75f6cb1a0b 100644 --- a/plugin.xml +++ b/plugin.xml @@ -11,35 +11,5 @@ defaultProvider="org.yakindu.sct.generator.core.library.impl.CoreLibraryDefaultFeatureValueProvider" uri="platform:/plugin/org.yakindu.sct.generator.core/library/CoreFeatureTypeLibrary.xmi"> - - - - - - - - - - - - - - diff --git a/src/org/yakindu/sct/generator/core/AbstractWorkspaceGenerator.java b/src/org/yakindu/sct/generator/core/AbstractWorkspaceGenerator.java deleted file mode 100644 index da221bc6fb..0000000000 --- a/src/org/yakindu/sct/generator/core/AbstractWorkspaceGenerator.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * Copyright (c) 2011 committers of YAKINDU and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * committers of YAKINDU - initial API and implementation - */ -package org.yakindu.sct.generator.core; - -import java.io.File; - -import org.eclipse.emf.common.util.URI; -import org.yakindu.sct.generator.core.impl.AbstractSExecModelGenerator; -import org.yakindu.sct.model.sgen.GeneratorEntry; - -/** - * Base class for generators that are executed inside the workspace - * - * @author holger willebrandt - Initial contribution and API - * @author Johannes Dicks - refactored because of EFS decoupling - */ -@Deprecated -public abstract class AbstractWorkspaceGenerator extends AbstractSExecModelGenerator { - - /** - * - * @param entry - * @deprecated Will be removed in future. Refreshing the project is moved to concrete file system access implementations - */ - @Deprecated - public final void refreshTargetProject(GeneratorEntry entry) { - /** - * This functionality will be provided by concrete file system accesses from now. - */ - } - - public final File getTargetProject(GeneratorEntry entry) { - URI uri = sctFsa.getURI(coreFeatureHelper.getTargetProjectValue(entry).getStringValue()); - return new File(uri.toFileString()); - } - - public final File getTargetFolder(GeneratorEntry entry) { - URI uri = sctFsa.getURI(coreFeatureHelper.getRelativeTargetFolder(entry)); - return new File(uri.toFileString()); - } - - public final File getLibraryTargetFolder(GeneratorEntry entry) { - URI uri = sctFsa.getURI(coreFeatureHelper.getRelativeLibraryFolder(entry)); - return new File(uri.toFileString()); - } - - public final File getApiTargetFolder(GeneratorEntry entry) { - URI uri = sctFsa.getURI(coreFeatureHelper.getRelativeApiFolder(entry)); - return new File(uri.toFileString()); - } - - public final void writeToConsole(String line){ - log.writeToConsole(line); - } - public final void writeToConsole(Throwable e){ - log.writeToConsole(e); - } -} diff --git a/src/org/yakindu/sct/generator/core/features/impl/IGenericJavaFeatureConstants.java b/src/org/yakindu/sct/generator/core/features/impl/IGenericJavaFeatureConstants.java deleted file mode 100644 index 5e9158e6a8..0000000000 --- a/src/org/yakindu/sct/generator/core/features/impl/IGenericJavaFeatureConstants.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2011 committers of YAKINDU and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * committers of YAKINDU - initial API and implementation - */ -package org.yakindu.sct.generator.core.features.impl; - -public interface IGenericJavaFeatureConstants { - public static final String LIBRARY_NAME = "Java"; - public static final String TEMPLATE_FEATURE = "Generator"; - public static final String GENERATOR_PROJECT = "generatorProject"; - public static final String GENERATOR_CLASS = "generatorClass"; - public static final String CONFIGURATION_MODULE = "configurationModule"; -} diff --git a/src/org/yakindu/sct/generator/core/impl/GenericJavaBasedGenerator.java b/src/org/yakindu/sct/generator/core/impl/GenericJavaBasedGenerator.java deleted file mode 100644 index ff0ce26a98..0000000000 --- a/src/org/yakindu/sct/generator/core/impl/GenericJavaBasedGenerator.java +++ /dev/null @@ -1,141 +0,0 @@ -/** - * Copyright (c) 2011 committers of YAKINDU and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * Contributors: - * committers of YAKINDU - initial API and implementation - * - */ -package org.yakindu.sct.generator.core.impl; - -import static org.yakindu.sct.generator.core.features.impl.IGenericJavaFeatureConstants.CONFIGURATION_MODULE; -import static org.yakindu.sct.generator.core.features.impl.IGenericJavaFeatureConstants.GENERATOR_CLASS; -import static org.yakindu.sct.generator.core.features.impl.IGenericJavaFeatureConstants.GENERATOR_PROJECT; -import static org.yakindu.sct.generator.core.features.impl.IGenericJavaFeatureConstants.TEMPLATE_FEATURE; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.Path; -import org.eclipse.emf.common.util.URI; -import org.eclipse.xtext.util.Strings; -import org.yakindu.sct.commons.WorkspaceClassLoaderFactory; -import org.yakindu.sct.model.sexec.ExecutionFlow; -import org.yakindu.sct.model.sgen.FeatureConfiguration; -import org.yakindu.sct.model.sgen.FeatureParameterValue; -import org.yakindu.sct.model.sgen.GeneratorEntry; -import org.yakindu.sct.model.sgraph.Statechart; - -import com.google.inject.Inject; -import com.google.inject.Injector; -import com.google.inject.Module; -import com.google.inject.util.Modules; - -/** - * - * - * @author holger willebrandt - Initial contribution and API - */ -@Deprecated -public class GenericJavaBasedGenerator extends AbstractSExecModelGenerator { - - @Inject - private Injector injector; - - @Override - public Module getOverridesModule(final GeneratorEntry entry) { - Module defaultModule = super.getOverridesModule(entry); - - String overridingModuleClass = null; - FeatureConfiguration featureConfiguration = entry.getFeatureConfiguration(TEMPLATE_FEATURE); - if (featureConfiguration != null) { - FeatureParameterValue parameterValue = featureConfiguration.getParameterValue(CONFIGURATION_MODULE); - if (parameterValue != null) { - overridingModuleClass = parameterValue.getStringValue(); - } - } - if (!Strings.isEmpty(overridingModuleClass)) { - try { - Class moduleClass = getClassLoader(entry).loadClass(overridingModuleClass); - if (Module.class.isAssignableFrom(moduleClass)) { - Module module = (Module) moduleClass.newInstance(); - defaultModule = Modules.override(defaultModule).with(module); - } - } catch (Exception e) { - e.printStackTrace(); - log.writeToConsole("Overriding module not found: " + overridingModuleClass); - log.writeToConsole(e); - } - } - return defaultModule; - } - - protected ClassLoader getClassLoader(GeneratorEntry entry) { - IProject project = getLookupRoot(entry); - final ClassLoader classLoader = new WorkspaceClassLoaderFactory().createClassLoader(project, - getClass().getClassLoader()); - return classLoader; - } - - @Override - public void runGenerator(Statechart statechart, GeneratorEntry entry) { - String templateClass = getTemplateClassName(entry); - final ClassLoader classLoader = getClassLoader(entry); - try { - Class delegateGeneratorClass = (Class) classLoader.loadClass(templateClass); - Object delegate = injector.getInstance(delegateGeneratorClass); - - Class iType_ = (Class) getClass().getClassLoader() - .loadClass("org.yakindu.sct.generator.core.impl.IExecutionFlowGenerator"); - Class iType__ = IExecutionFlowGenerator.class; - Class iType = (Class) classLoader - .loadClass("org.yakindu.sct.generator.core.impl.IExecutionFlowGenerator"); - - ExecutionFlow flow = createExecutionFlow(statechart, entry); - - if (coreFeatureHelper.isDumpSexec(entry)) { - dumpSexec(entry, flow); - } - - - if (delegate instanceof IExecutionFlowGenerator) { - IExecutionFlowGenerator flowGenerator = (IExecutionFlowGenerator) delegate; - flowGenerator.generate(flow, entry, sctFsa.getIFileSystemAccess()); - } - if (iType.isInstance(delegate)) { - IExecutionFlowGenerator flowGenerator = (IExecutionFlowGenerator) delegate; - flowGenerator.generate(flow, entry, sctFsa.getIFileSystemAccess()); - } - if (delegate instanceof ISGraphGenerator) { - ISGraphGenerator graphGenerator = (ISGraphGenerator) delegate; - graphGenerator.generate(statechart, entry); - } - } catch (Exception e) { - e.printStackTrace(); - log.writeToConsole(e); - } - } - - protected String getTemplateClassName(GeneratorEntry entry) { - return entry.getFeatureConfiguration(TEMPLATE_FEATURE).getParameterValue(GENERATOR_CLASS).getStringValue(); - } - - /** - * resolve the project that defines the lookup path for the XpandFacade - * - */ - protected IProject getLookupRoot(GeneratorEntry entry) { - IProject project = null; - FeatureConfiguration templateConfig = entry.getFeatureConfiguration(TEMPLATE_FEATURE); - FeatureParameterValue projectName = templateConfig.getParameterValue(GENERATOR_PROJECT); - if (projectName != null) { - project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName.getStringValue()); - } else { - URI uri = entry.getElementRef().eResource().getURI(); - project = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(uri.toPlatformString(true))) - .getProject(); - } - return project; - } -} diff --git a/src/org/yakindu/sct/generator/core/library/impl/GenericJavaLibraryDefaultValueProvider.java b/src/org/yakindu/sct/generator/core/library/impl/GenericJavaLibraryDefaultValueProvider.java deleted file mode 100644 index fe61fc2426..0000000000 --- a/src/org/yakindu/sct/generator/core/library/impl/GenericJavaLibraryDefaultValueProvider.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Copyright (c) 2011 committers of YAKINDU and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * Contributors: - * committers of YAKINDU - initial API and implementation - * - */ -package org.yakindu.sct.generator.core.library.impl; - -import static org.yakindu.sct.generator.core.features.impl.IGenericJavaFeatureConstants.GENERATOR_CLASS; -import static org.yakindu.sct.generator.core.features.impl.IGenericJavaFeatureConstants.GENERATOR_PROJECT; -import static org.yakindu.sct.generator.core.features.impl.IGenericJavaFeatureConstants.LIBRARY_NAME; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; -import org.yakindu.sct.generator.core.library.AbstractDefaultFeatureValueProvider; -import org.yakindu.sct.model.sgen.FeatureParameterValue; -import org.yakindu.sct.model.sgen.FeatureType; -import org.yakindu.sct.model.sgen.FeatureTypeLibrary; - -/** - * - * @author holger willebrandt - Initial contribution and API - */ -public class GenericJavaLibraryDefaultValueProvider extends AbstractDefaultFeatureValueProvider { - - // (ID.)+ID - private static final String GENERATOR_CLASS_REGEX = "([a-zA-Z_][a-zA-Z0-9_]*\\.)+[a-zA-Z_][a-zA-Z0-9_]*"; //$NON-NLS-1$ - - public boolean isProviderFor(FeatureTypeLibrary library) { - return library.getName().equals(LIBRARY_NAME); - } - - @Override - protected void setDefaultValue(FeatureType featureType, FeatureParameterValue parameterValue, - EObject contextElement) { - String parameterName = parameterValue.getParameter().getName(); - if (GENERATOR_PROJECT.equals(parameterName)) { - parameterValue.setValue(getProject(contextElement).getName()); - } else if (GENERATOR_CLASS.equals(parameterName)) { - parameterValue.setValue("org.yakindu.sct.generator.Generator"); - } - } - - public IStatus validateParameterValue(FeatureParameterValue parameterValue) { - String parameterName = parameterValue.getParameter().getName(); - String value = parameterValue.getStringValue(); - if (GENERATOR_PROJECT.equals(parameterName) && !projectExists(value)) { - return error(String.format("The Project %s does not exist", value)); - } - IJavaProject ijp = JavaCore.create(this.getProject(parameterValue)); - try { - if (ijp.findType(value) == null && GENERATOR_CLASS.equals(parameterName)) { - return error("Generator class does not exist."); - } - } catch (JavaModelException e) { - // Stacktrace - e.printStackTrace(); - } - if (GENERATOR_CLASS.equals(parameterName) && !value.matches(GENERATOR_CLASS_REGEX)) { - return error("Generator class must be a full qualified class name"); - } - return Status.OK_STATUS; - } -}