Skip to content
Snippets Groups Projects
Commit faa87fac authored by Konstantin Blaschke's avatar Konstantin Blaschke
Browse files

# 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: af3#4310


Signed-off-by: default avatarKonstantin Blaschke <blaschke@fortiss.org>
parent 170f632e
No related branches found
No related tags found
1 merge request!210Setting up Metric extraction plugin for AF3 : Issue 4310
Showing
with 100 additions and 61 deletions
Manifest-Version: 1.0 Manifest-Version: 1.0
Bundle-ManifestVersion: 2 Bundle-ManifestVersion: 2
Bundle-Name: Quality Bundle-Name: %pluginName
Bundle-SymbolicName: org.fortiss.tooling.ext.quality Bundle-SymbolicName: org.fortiss.tooling.ext.quality;singleton:=true
Bundle-Version: 1.0.0.qualifier Bundle-Version: 1.0.0.qualifier
Automatic-Module-Name: org.fortiss.tooling.ext.quality Automatic-Module-Name: org.fortiss.tooling.ext.quality
Bundle-RequiredExecutionEnvironment: JavaSE-11 Bundle-RequiredExecutionEnvironment: JavaSE-11
Import-Package: org.eclipse.core.runtime;version="3.5.0", Bundle-Vendor: %providerName
org.eclipse.emf.ecore, Bundle-Activator: org.fortiss.tooling.ext.quality.AF3QualityActivator
org.eclipse.emf.ecore.xml.type, Require-Bundle: org.eclipse.core.runtime,
org.fortiss.tooling.kernel.extension.data, org.eclipse.emf.ecore;visibility:=reexport,
org.fortiss.tooling.kernel.introspection, org.fortiss.tooling.base;visibility:=reexport,
org.fortiss.tooling.kernel.service, org.fortiss.tooling.kernel;visibility:=reexport
org.fortiss.tooling.kernel.service.base,
org.fortiss.tooling.kernel.utils,
org.osgi.framework
Export-Package: org.fortiss.tooling.ext.quality.service Export-Package: org.fortiss.tooling.ext.quality.service
source.. = src/ # (c) 2023 fortiss GmbH
output.. = bin/
bin.includes = META-INF/,\
. source.. = src/,\
generated-src/
output.. = build/
bin.includes = .,\
model/,\
META-INF/,\
plugin.xml,\
plugin.properties
<?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>
...@@ -17,9 +17,9 @@ package org.fortiss.tooling.ext.quality; ...@@ -17,9 +17,9 @@ package org.fortiss.tooling.ext.quality;
+--------------------------------------------------------------------------*/ +--------------------------------------------------------------------------*/
import org.eclipse.core.runtime.Plugin; import org.eclipse.core.runtime.Plugin;
import org.fortiss.tooling.ext.quality.service.MetricService;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
/** /**
* The activator class controls the plug-in life cycle. * The activator class controls the plug-in life cycle.
* *
...@@ -38,6 +38,7 @@ public class AF3QualityActivator extends Plugin { ...@@ -38,6 +38,7 @@ public class AF3QualityActivator extends Plugin {
super.start(context); super.start(context);
plugin = this; plugin = this;
System.out.println("[Plugin] " + PLUGIN_ID + " started."); System.out.println("[Plugin] " + PLUGIN_ID + " started.");
MetricService.getInstance().startService();
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
......
...@@ -15,12 +15,10 @@ ...@@ -15,12 +15,10 @@
+--------------------------------------------------------------------------*/ +--------------------------------------------------------------------------*/
package org.fortiss.tooling.ext.quality.service; 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.EObject;
import org.eclipse.emf.ecore.xml.type.AnyType; import org.fortiss.tooling.kernel.service.base.IEObjectAware;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.service.base.IObjectAware;
/** /**
* Interface for the migration provider implementations. * Interface for the migration provider implementations.
...@@ -29,27 +27,8 @@ import org.fortiss.tooling.kernel.service.base.IObjectAware; ...@@ -29,27 +27,8 @@ import org.fortiss.tooling.kernel.service.base.IObjectAware;
* *
* @author blaschke * @author blaschke
*/ */
public interface IMetricProvider extends IObjectAware<ITopLevelElement> { public interface IMetricProvider<C extends EObject> extends IEObjectAware<EObject> {
/** /** Applies the IMetricProvider to the given model element. */
* Determines whether migration provider is needed for the given List<String> apply(C modelElement);
* 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
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
+--------------------------------------------------------------------------*/ +--------------------------------------------------------------------------*/
package org.fortiss.tooling.ext.quality.service; package org.fortiss.tooling.ext.quality.service;
/** /**
* The migration service checks and upgrades the old models from the last release. * The migration service checks and upgrades the old models from the last release.
* *
...@@ -28,5 +27,5 @@ public interface IMetricService { ...@@ -28,5 +27,5 @@ public interface IMetricService {
} }
/** Registers the metric provider with the service. */ /** Registers the metric provider with the service. */
void registerMetricProvider(IMetricProvider provider, Class<?> modelElementClass); void registerMetricProvider(IMetricProvider<?> provider, Class<?> modelElementClass);
} }
/*-------------------------------------------------------------------------+
| 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;
}
}
...@@ -17,9 +17,11 @@ package org.fortiss.tooling.ext.quality.service; ...@@ -17,9 +17,11 @@ package org.fortiss.tooling.ext.quality.service;
import static java.util.Collections.emptyList; import static java.util.Collections.emptyList;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getFirstChildWithType; import static org.fortiss.tooling.kernel.utils.EcoreUtils.getFirstChildWithType;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement; import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.introspection.IIntrospectionDetailsItem; import org.fortiss.tooling.kernel.introspection.IIntrospectionDetailsItem;
...@@ -27,14 +29,15 @@ import org.fortiss.tooling.kernel.introspection.IIntrospectionItem; ...@@ -27,14 +29,15 @@ import org.fortiss.tooling.kernel.introspection.IIntrospectionItem;
import org.fortiss.tooling.kernel.introspection.IIntrospectiveKernelService; import org.fortiss.tooling.kernel.introspection.IIntrospectiveKernelService;
import org.fortiss.tooling.kernel.service.IKernelIntrospectionSystemService; import org.fortiss.tooling.kernel.service.IKernelIntrospectionSystemService;
import org.fortiss.tooling.kernel.service.IMigrationService; 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. * This class implements the {@link IMigrationService} interface.
* *
* @author blaschke * @author blaschke
*/ */
public class MetricService extends ObjectAwareServiceBase<IMetricProvider> implements IIntrospectiveKernelService, IMetricService{ public class MetricService extends EObjectAwareServiceBase<IMetricProvider<?>>
implements IIntrospectiveKernelService, IMetricService {
/** The singleton instance. */ /** The singleton instance. */
private static final MetricService INSTANCE = new MetricService(); private static final MetricService INSTANCE = new MetricService();
...@@ -61,7 +64,7 @@ public class MetricService extends ObjectAwareServiceBase<IMetricProvider> imple ...@@ -61,7 +64,7 @@ public class MetricService extends ObjectAwareServiceBase<IMetricProvider> imple
/** Registers the migration provider with the service. */ /** Registers the migration provider with the service. */
@Override @Override
public void registerMetricProvider(IMetricProvider provider, Class<?> modelElementClass) { public void registerMetricProvider(IMetricProvider<?> provider, Class<?> modelElementClass) {
addHandler(modelElementClass, provider); addHandler(modelElementClass, provider);
} }
...@@ -75,37 +78,32 @@ public class MetricService extends ObjectAwareServiceBase<IMetricProvider> imple ...@@ -75,37 +78,32 @@ public class MetricService extends ObjectAwareServiceBase<IMetricProvider> imple
"\n\nThe service extension point is '" + EXTENSION_POINT_NAME + "'."; "\n\nThe service extension point is '" + EXTENSION_POINT_NAME + "'.";
} }
/** Get all suitable {@link IMetricProvider} for the given input. */ /** Get all suitable {@link IMetricProvider} for the given input. */
@SuppressWarnings("unused") @SuppressWarnings("unused")
private List<IMetricProvider> getProviders(ITopLevelElement input) { private List<IMetricProvider<?>> getProviders(ITopLevelElement input) {
List<IMetricProvider> providers = new ArrayList<>(); List<IMetricProvider<?>> providers = new ArrayList<>();
EObject migElement = input.getRootModelElement(); 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) { if(getFirstChildWithType(migElement, migEntry.getKey()) != null) {
providers.addAll(migEntry.getValue()); providers.addAll(migEntry.getValue());
} }
} }
return providers; return providers;
} }
/** */ /** */
@Override @Override
protected String getExtensionPointName() { protected String getExtensionPointName() {
return EXTENSION_POINT_NAME; return EXTENSION_POINT_NAME;
} }
/** */ /** */
@Override @Override
protected String getConfigurationElementName() { protected String getConfigurationElementName() {
return CONFIGURATION_ELEMENT_NAME; return CONFIGURATION_ELEMENT_NAME;
} }
/** */ /** */
@Override @Override
protected String getHandlerClassAttribute() { protected String getHandlerClassAttribute() {
......
...@@ -41,5 +41,4 @@ Export-Package: org.fortiss.tooling.kernel; uses:="org.eclipse.core.runtime, ...@@ -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.fortiss.tooling.kernel.utils; uses:="org.eclipse.emf.ecore,
org.eclipse.core.resources" org.eclipse.core.resources"
Automatic-Module-Name: org.fortiss.tooling.kernel Automatic-Module-Name: org.fortiss.tooling.kernel
Import-Package: com.google.common.collect, Import-Package: com.google.common.collect
org.fortiss.tooling.ext.quality.service
...@@ -17,7 +17,6 @@ package org.fortiss.tooling.kernel.internal; ...@@ -17,7 +17,6 @@ package org.fortiss.tooling.kernel.internal;
import static org.fortiss.tooling.kernel.ToolingKernel.printPhase; 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; import org.fortiss.tooling.kernel.internal.storage.eclipse.EclipseResourceStorageService;
/** /**
...@@ -43,7 +42,6 @@ public final class ToolingKernelInternal { ...@@ -43,7 +42,6 @@ public final class ToolingKernelInternal {
PrototypeService.getInstance().initializeService(); PrototypeService.getInstance().initializeService();
TransformationService.getInstance().initializeService(); TransformationService.getInstance().initializeService();
TutorialService.getInstance().initializeService(); TutorialService.getInstance().initializeService();
MetricService.getInstance().initializeService();
printPhase("Tooling Kernel initialized."); printPhase("Tooling Kernel initialized.");
} }
...@@ -62,7 +60,6 @@ public final class ToolingKernelInternal { ...@@ -62,7 +60,6 @@ public final class ToolingKernelInternal {
PersistencyService.getInstance().startService(); PersistencyService.getInstance().startService();
PrototypeService.getInstance().startService(); PrototypeService.getInstance().startService();
TransformationService.getInstance().startService(); TransformationService.getInstance().startService();
MetricService.getInstance().startService();
printPhase("Tooling Kernel started."); printPhase("Tooling Kernel started.");
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment