From faa87fac83ed6ed64bfb98a5fec517fc3a914b65 Mon Sep 17 00:00:00 2001 From: Konstantin Blaschke <blaschke@fortiss.org> Date: Wed, 31 May 2023 17:07:12 +0200 Subject: [PATCH] # WARNING: head commit changed in the meantime Setting up Metric extraction plugin for AF3 Searching for entry point to trigger the service and how Issue-Ref: 4310 Issue-Url: https://git.fortiss.org/af3/af3/-/issues/4310 Signed-off-by: Konstantin Blaschke <blaschke@fortiss.org> --- .../META-INF/MANIFEST.MF | 19 ++++----- .../build.properties | 15 +++++-- org.fortiss.tooling.ext.quality/plugin.xml | 21 ++++++++++ .../ext/quality/AF3QualityActivator.java | 3 +- .../ext/quality/service/IMetricProvider.java | 33 +++------------ .../ext/quality/service/IMetricService.java | 3 +- .../service/MetricCommentProvider.java | 41 +++++++++++++++++++ .../ext/quality/service/MetricService.java | 20 ++++----- .../META-INF/MANIFEST.MF | 3 +- .../internal/ToolingKernelInternal.java | 3 -- 10 files changed, 100 insertions(+), 61 deletions(-) create mode 100644 org.fortiss.tooling.ext.quality/plugin.xml create mode 100644 org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/MetricCommentProvider.java diff --git a/org.fortiss.tooling.ext.quality/META-INF/MANIFEST.MF b/org.fortiss.tooling.ext.quality/META-INF/MANIFEST.MF index 3584c3ee8..16c031e88 100644 --- a/org.fortiss.tooling.ext.quality/META-INF/MANIFEST.MF +++ b/org.fortiss.tooling.ext.quality/META-INF/MANIFEST.MF @@ -1,17 +1,14 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 -Bundle-Name: Quality -Bundle-SymbolicName: org.fortiss.tooling.ext.quality +Bundle-Name: %pluginName +Bundle-SymbolicName: org.fortiss.tooling.ext.quality;singleton:=true Bundle-Version: 1.0.0.qualifier Automatic-Module-Name: org.fortiss.tooling.ext.quality Bundle-RequiredExecutionEnvironment: JavaSE-11 -Import-Package: org.eclipse.core.runtime;version="3.5.0", - org.eclipse.emf.ecore, - org.eclipse.emf.ecore.xml.type, - org.fortiss.tooling.kernel.extension.data, - org.fortiss.tooling.kernel.introspection, - org.fortiss.tooling.kernel.service, - org.fortiss.tooling.kernel.service.base, - org.fortiss.tooling.kernel.utils, - org.osgi.framework +Bundle-Vendor: %providerName +Bundle-Activator: org.fortiss.tooling.ext.quality.AF3QualityActivator +Require-Bundle: org.eclipse.core.runtime, + org.eclipse.emf.ecore;visibility:=reexport, + org.fortiss.tooling.base;visibility:=reexport, + org.fortiss.tooling.kernel;visibility:=reexport Export-Package: org.fortiss.tooling.ext.quality.service diff --git a/org.fortiss.tooling.ext.quality/build.properties b/org.fortiss.tooling.ext.quality/build.properties index 34d2e4d2d..6daa0b7a1 100644 --- a/org.fortiss.tooling.ext.quality/build.properties +++ b/org.fortiss.tooling.ext.quality/build.properties @@ -1,4 +1,11 @@ -source.. = src/ -output.. = bin/ -bin.includes = META-INF/,\ - . +# (c) 2023 fortiss GmbH + + +source.. = src/,\ + generated-src/ +output.. = build/ +bin.includes = .,\ + model/,\ + META-INF/,\ + plugin.xml,\ + plugin.properties diff --git a/org.fortiss.tooling.ext.quality/plugin.xml b/org.fortiss.tooling.ext.quality/plugin.xml new file mode 100644 index 000000000..dd83c2691 --- /dev/null +++ b/org.fortiss.tooling.ext.quality/plugin.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.4"?> +<plugin> + <extension + point="org.eclipse.emf.ecore.generated_package"> + <package + class="org.fortiss.tooling.ext.quality.EPackage1" + uri="org.fortiss.tooling.ext.quality.package1"> + </package> + </extension> + <extension + point="org.fortiss.tooling.kernel.modelElementCompositor"> + <modelElementCompositor + compositor="org.fortiss.tooling.ext.quality.ElementCompositor1"> + <modelElementClass + modelElementClass="org.fortiss.tooling.ext.quality.EObject1"> + </modelElementClass> + </modelElementCompositor> + </extension> + +</plugin> diff --git a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/AF3QualityActivator.java b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/AF3QualityActivator.java index 97f276ca6..f2afb5fbd 100644 --- a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/AF3QualityActivator.java +++ b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/AF3QualityActivator.java @@ -17,9 +17,9 @@ package org.fortiss.tooling.ext.quality; +--------------------------------------------------------------------------*/ import org.eclipse.core.runtime.Plugin; +import org.fortiss.tooling.ext.quality.service.MetricService; import org.osgi.framework.BundleContext; - /** * The activator class controls the plug-in life cycle. * @@ -38,6 +38,7 @@ public class AF3QualityActivator extends Plugin { super.start(context); plugin = this; System.out.println("[Plugin] " + PLUGIN_ID + " started."); + MetricService.getInstance().startService(); } /** {@inheritDoc} */ diff --git a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/IMetricProvider.java b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/IMetricProvider.java index 830382c9e..fa6116cf0 100644 --- a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/IMetricProvider.java +++ b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/IMetricProvider.java @@ -15,12 +15,10 @@ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.ext.quality.service; -import java.util.Map; +import java.util.List; import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.xml.type.AnyType; -import org.fortiss.tooling.kernel.extension.data.ITopLevelElement; -import org.fortiss.tooling.kernel.service.base.IObjectAware; +import org.fortiss.tooling.kernel.service.base.IEObjectAware; /** * Interface for the migration provider implementations. @@ -29,27 +27,8 @@ import org.fortiss.tooling.kernel.service.base.IObjectAware; * * @author blaschke */ -public interface IMetricProvider extends IObjectAware<ITopLevelElement> { +public interface IMetricProvider<C extends EObject> extends IEObjectAware<EObject> { - /** - * Determines whether migration provider is needed for the given - * model element. - * - * The parameter "unknownFeatures" returns a map indicating the features that are not recognized - * in the model. This can be useful to detect features coming from old models and can be then - * translated to the new model by a migrator. - */ - boolean needMigration(ITopLevelElement modelElement, Map<EObject, AnyType> unknownFeatures); - - /** - * Applies the provider to the given element. - * - * The parameter "unknownFeatures" indicates the features that are not recognized - * in the model. This can be useful to detect features coming from old models and can be then - * translated to the new model by a migrator. - * - * @return all unknown features that have successfully been migrated. - */ - Map<EObject, AnyType> migrate(ITopLevelElement modelElement, - Map<EObject, AnyType> unknownFeatures); -} \ No newline at end of file + /** Applies the IMetricProvider to the given model element. */ + List<String> apply(C modelElement); +} diff --git a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/IMetricService.java b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/IMetricService.java index b5cc5feeb..1e669b910 100644 --- a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/IMetricService.java +++ b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/IMetricService.java @@ -15,7 +15,6 @@ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.ext.quality.service; - /** * The migration service checks and upgrades the old models from the last release. * @@ -28,5 +27,5 @@ public interface IMetricService { } /** Registers the metric provider with the service. */ - void registerMetricProvider(IMetricProvider provider, Class<?> modelElementClass); + void registerMetricProvider(IMetricProvider<?> provider, Class<?> modelElementClass); } diff --git a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/MetricCommentProvider.java b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/MetricCommentProvider.java new file mode 100644 index 000000000..e821bd27e --- /dev/null +++ b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/MetricCommentProvider.java @@ -0,0 +1,41 @@ +/*-------------------------------------------------------------------------+ +| Copyright 2023 fortiss GmbH | +| | +| Licensed under the Apache License, Version 2.0 (the "License"); | +| you may not use this file except in compliance with the License. | +| You may obtain a copy of the License at | +| | +| http://www.apache.org/licenses/LICENSE-2.0 | +| | +| Unless required by applicable law or agreed to in writing, software | +| distributed under the License is distributed on an "AS IS" BASIS, | +| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | +| See the License for the specific language governing permissions and | +| limitations under the License. | ++--------------------------------------------------------------------------*/ +package org.fortiss.tooling.ext.quality.service; + +import java.util.ArrayList; +import java.util.List; + +import org.fortiss.tooling.kernel.model.INamedCommentedElement; + +/** + * {@link IMetricProvider} to count the ratio of filled out comments of INamedCommentedElements. + * + * @author blaschke + */ +public class MetricCommentProvider implements IMetricProvider<INamedCommentedElement> { + + /** {@inheritDoc} */ + @Override + public List<String> apply(INamedCommentedElement commentedEle) { + commentedEle.getComment().equals(""); + ArrayList<String> strings = new ArrayList<String>(); + strings.add("test"); + strings.add("Is is actually done and how often? now because of element: \" +\n" + + commentedEle.getName()); + System.out.println(strings.get(1)); + return strings; + } +} diff --git a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/MetricService.java b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/MetricService.java index d7f16e362..b104419b1 100644 --- a/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/MetricService.java +++ b/org.fortiss.tooling.ext.quality/src/org/fortiss/tooling/ext/quality/service/MetricService.java @@ -17,9 +17,11 @@ package org.fortiss.tooling.ext.quality.service; import static java.util.Collections.emptyList; import static org.fortiss.tooling.kernel.utils.EcoreUtils.getFirstChildWithType; + import java.util.ArrayList; import java.util.List; import java.util.Map.Entry; + import org.eclipse.emf.ecore.EObject; import org.fortiss.tooling.kernel.extension.data.ITopLevelElement; import org.fortiss.tooling.kernel.introspection.IIntrospectionDetailsItem; @@ -27,14 +29,15 @@ import org.fortiss.tooling.kernel.introspection.IIntrospectionItem; import org.fortiss.tooling.kernel.introspection.IIntrospectiveKernelService; import org.fortiss.tooling.kernel.service.IKernelIntrospectionSystemService; import org.fortiss.tooling.kernel.service.IMigrationService; -import org.fortiss.tooling.kernel.service.base.ObjectAwareServiceBase; +import org.fortiss.tooling.kernel.service.base.EObjectAwareServiceBase; /** * This class implements the {@link IMigrationService} interface. * * @author blaschke */ -public class MetricService extends ObjectAwareServiceBase<IMetricProvider> implements IIntrospectiveKernelService, IMetricService{ +public class MetricService extends EObjectAwareServiceBase<IMetricProvider<?>> + implements IIntrospectiveKernelService, IMetricService { /** The singleton instance. */ private static final MetricService INSTANCE = new MetricService(); @@ -61,7 +64,7 @@ public class MetricService extends ObjectAwareServiceBase<IMetricProvider> imple /** Registers the migration provider with the service. */ @Override - public void registerMetricProvider(IMetricProvider provider, Class<?> modelElementClass) { + public void registerMetricProvider(IMetricProvider<?> provider, Class<?> modelElementClass) { addHandler(modelElementClass, provider); } @@ -75,37 +78,32 @@ public class MetricService extends ObjectAwareServiceBase<IMetricProvider> imple "\n\nThe service extension point is '" + EXTENSION_POINT_NAME + "'."; } - /** Get all suitable {@link IMetricProvider} for the given input. */ @SuppressWarnings("unused") - private List<IMetricProvider> getProviders(ITopLevelElement input) { - List<IMetricProvider> providers = new ArrayList<>(); + private List<IMetricProvider<?>> getProviders(ITopLevelElement input) { + List<IMetricProvider<?>> providers = new ArrayList<>(); EObject migElement = input.getRootModelElement(); - for(Entry<Class<?>, List<IMetricProvider>> migEntry : handlerMap.entrySet()) { + for(Entry<Class<?>, List<IMetricProvider<?>>> migEntry : handlerMap.entrySet()) { if(getFirstChildWithType(migElement, migEntry.getKey()) != null) { providers.addAll(migEntry.getValue()); } } - return providers; } - /** */ @Override protected String getExtensionPointName() { return EXTENSION_POINT_NAME; } - /** */ @Override protected String getConfigurationElementName() { return CONFIGURATION_ELEMENT_NAME; } - /** */ @Override protected String getHandlerClassAttribute() { diff --git a/org.fortiss.tooling.kernel/META-INF/MANIFEST.MF b/org.fortiss.tooling.kernel/META-INF/MANIFEST.MF index 2f54d7bd5..cd96ea055 100644 --- a/org.fortiss.tooling.kernel/META-INF/MANIFEST.MF +++ b/org.fortiss.tooling.kernel/META-INF/MANIFEST.MF @@ -41,5 +41,4 @@ Export-Package: org.fortiss.tooling.kernel; uses:="org.eclipse.core.runtime, org.fortiss.tooling.kernel.utils; uses:="org.eclipse.emf.ecore, org.eclipse.core.resources" Automatic-Module-Name: org.fortiss.tooling.kernel -Import-Package: com.google.common.collect, - org.fortiss.tooling.ext.quality.service +Import-Package: com.google.common.collect diff --git a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/internal/ToolingKernelInternal.java b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/internal/ToolingKernelInternal.java index 6033329e6..afbd2ccb5 100644 --- a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/internal/ToolingKernelInternal.java +++ b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/internal/ToolingKernelInternal.java @@ -17,7 +17,6 @@ package org.fortiss.tooling.kernel.internal; import static org.fortiss.tooling.kernel.ToolingKernel.printPhase; -import org.fortiss.tooling.ext.quality.service.MetricService; import org.fortiss.tooling.kernel.internal.storage.eclipse.EclipseResourceStorageService; /** @@ -43,7 +42,6 @@ public final class ToolingKernelInternal { PrototypeService.getInstance().initializeService(); TransformationService.getInstance().initializeService(); TutorialService.getInstance().initializeService(); - MetricService.getInstance().initializeService(); printPhase("Tooling Kernel initialized."); } @@ -62,7 +60,6 @@ public final class ToolingKernelInternal { PersistencyService.getInstance().startService(); PrototypeService.getInstance().startService(); TransformationService.getInstance().startService(); - MetricService.getInstance().startService(); printPhase("Tooling Kernel started."); } } -- GitLab