Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan-Philipp Steghöfer2019-08-12 07:44:32 +0000
committerJan-Philipp Steghöfer2019-08-12 08:24:34 +0000
commit2edb80c15d86ccfeeaa9de52a8982dff89c9070e (patch)
tree77ee5b380987dcb0072e08c824389eed6bc8ac27
parente7e6b248d7568fcca4dbdf950791389adc499f08 (diff)
downloadorg.eclipse.capra-2edb80c15d86ccfeeaa9de52a8982dff89c9070e.tar.gz
org.eclipse.capra-2edb80c15d86ccfeeaa9de52a8982dff89c9070e.tar.xz
org.eclipse.capra-2edb80c15d86ccfeeaa9de52a8982dff89c9070e.zip
Implemented resolveWrapper() for FeatureIDE handler and added tests
The FeatureIDE handler was missing a resolveWrapper() implementation so far. This has now been added. In addition, a test case has been added to make sure that the handler behaves as expected. Change-Id: I926aa3e10c8deff1d51a35e7b4ed2584323d8699
-rw-r--r--bundles/org.eclipse.capra.handler.featureide/src/org/eclipse/capra/handler/featureide/FeatureIdeHandler.java31
-rw-r--r--pom.xml1
-rw-r--r--tests/org.eclipse.capra.handler.featureide.tests/.classpath7
-rw-r--r--tests/org.eclipse.capra.handler.featureide.tests/.project28
-rw-r--r--tests/org.eclipse.capra.handler.featureide.tests/.settings/org.eclipse.jdt.core.prefs15
-rw-r--r--tests/org.eclipse.capra.handler.featureide.tests/META-INF/MANIFEST.MF19
-rw-r--r--tests/org.eclipse.capra.handler.featureide.tests/build.properties4
-rw-r--r--tests/org.eclipse.capra.handler.featureide.tests/plugin.properties17
-rw-r--r--tests/org.eclipse.capra.handler.featureide.tests/pom.xml25
-rw-r--r--tests/org.eclipse.capra.handler.featureide.tests/src/org/eclipse/capra/handler/featureide/tests/TestFeatureIDETraces.java107
10 files changed, 245 insertions, 9 deletions
diff --git a/bundles/org.eclipse.capra.handler.featureide/src/org/eclipse/capra/handler/featureide/FeatureIdeHandler.java b/bundles/org.eclipse.capra.handler.featureide/src/org/eclipse/capra/handler/featureide/FeatureIdeHandler.java
index 885f9bd6..845a4c97 100644
--- a/bundles/org.eclipse.capra.handler.featureide/src/org/eclipse/capra/handler/featureide/FeatureIdeHandler.java
+++ b/bundles/org.eclipse.capra.handler.featureide/src/org/eclipse/capra/handler/featureide/FeatureIdeHandler.java
@@ -13,6 +13,7 @@
*******************************************************************************/
package org.eclipse.capra.handler.featureide;
+import java.nio.file.FileSystems;
import java.util.Collections;
import java.util.List;
@@ -29,32 +30,44 @@ import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
-import de.ovgu.featureide.fm.core.base.impl.Feature;
+import de.ovgu.featureide.fm.core.base.IFeature;
+import de.ovgu.featureide.fm.core.base.IFeatureModel;
+import de.ovgu.featureide.fm.core.io.manager.FeatureModelManager;
+import de.ovgu.featureide.fm.core.io.manager.FileHandler;
-public class FeatureIdeHandler extends AbstractArtifactHandler<Feature> {
+/**
+ * A handler for feature models from FeatureIDE.
+ *
+ * @author Jan-Philipp Steghöfer
+ *
+ */
+public class FeatureIdeHandler extends AbstractArtifactHandler<IFeature> {
@Override
- public EObject createWrapper(Feature spec, EObject artifactModel) {
+ public EObject createWrapper(IFeature feature, EObject artifactModel) {
ArtifactMetaModelAdapter adapter = ExtensionPointHelper.getArtifactWrapperMetaModelAdapter().get();
- final IPath path = Path.fromOSString(spec.getFeatureModel().getSourceFile().toString());
+ final IPath path = Path.fromOSString(feature.getFeatureModel().getSourceFile().toString());
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
final IFile file = root.getFileForLocation(path);
String uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true).toPlatformString(false);
EObject wrapper = adapter.createArtifact(artifactModel, this.getClass().getName(), uri,
- Long.toString(spec.getInternalId()), spec.getName(), spec.getFeatureModel().getSourceFile().toString());
+ Long.toString(feature.getInternalId()), feature.getName(), feature.getFeatureModel().getSourceFile().toString());
return wrapper;
}
@Override
- public Feature resolveWrapper(EObject wrapper) {
- return null;
+ public IFeature resolveWrapper(EObject wrapper) {
+ ArtifactMetaModelAdapter adapter = ExtensionPointHelper.getArtifactWrapperMetaModelAdapter().get();
+ FileHandler<IFeatureModel> fileHandler = FeatureModelManager
+ .load(FileSystems.getDefault().getPath(adapter.getArtifactPath(wrapper).toOSString()));
+ return fileHandler.getObject().getFeature(adapter.getArtifactName(wrapper));
}
@Override
- public String getDisplayName(Feature spec) {
- return spec.getName();
+ public String getDisplayName(IFeature feature) {
+ return feature.getName();
}
@Override
diff --git a/pom.xml b/pom.xml
index ea3670a4..4689ba7e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -52,6 +52,7 @@
<module>tests/org.eclipse.capra.handler.cdt.tests</module>
<module>tests/org.eclipse.capra.handler.jdt.tests</module>
<module>tests/org.eclipse.capra.handler.uml.tests</module>
+ <module>tests/org.eclipse.capra.handler.featureide.tests</module>
<!-- Branding -->
<module>releng/org.eclipse.capra.branding</module>
diff --git a/tests/org.eclipse.capra.handler.featureide.tests/.classpath b/tests/org.eclipse.capra.handler.featureide.tests/.classpath
new file mode 100644
index 00000000..22f30643
--- /dev/null
+++ b/tests/org.eclipse.capra.handler.featureide.tests/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/tests/org.eclipse.capra.handler.featureide.tests/.project b/tests/org.eclipse.capra.handler.featureide.tests/.project
new file mode 100644
index 00000000..355da108
--- /dev/null
+++ b/tests/org.eclipse.capra.handler.featureide.tests/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.capra.handler.featureide.tests</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ </natures>
+</projectDescription>
diff --git a/tests/org.eclipse.capra.handler.featureide.tests/.settings/org.eclipse.jdt.core.prefs b/tests/org.eclipse.capra.handler.featureide.tests/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000..0fee6a9c
--- /dev/null
+++ b/tests/org.eclipse.capra.handler.featureide.tests/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,15 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.release=disabled
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/tests/org.eclipse.capra.handler.featureide.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.capra.handler.featureide.tests/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..4ccb2bc7
--- /dev/null
+++ b/tests/org.eclipse.capra.handler.featureide.tests/META-INF/MANIFEST.MF
@@ -0,0 +1,19 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Localization: plugin
+Bundle-Name: %Bundle-Name
+Bundle-Vendor: %Bundle-Vendor
+Bundle-SymbolicName: org.eclipse.capra.handler.featureide.tests
+Bundle-Version: 0.7.1.qualifier
+Require-Bundle:
+ org.eclipse.capra.core,
+ org.eclipse.capra.generic.tracemodels,
+ org.eclipse.capra.handler.featureide,
+ org.eclipse.capra.ui,
+ org.eclipse.capra.testsuite,
+ org.eclipse.core.resources,
+ org.eclipse.core.runtime,
+ org.eclipse.ui,
+ de.ovgu.featureide.fm.core,
+ org.junit
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
diff --git a/tests/org.eclipse.capra.handler.featureide.tests/build.properties b/tests/org.eclipse.capra.handler.featureide.tests/build.properties
new file mode 100644
index 00000000..b5e3b75e
--- /dev/null
+++ b/tests/org.eclipse.capra.handler.featureide.tests/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+bin.includes = META-INF/,\
+ .,\
+ plugin.properties
diff --git a/tests/org.eclipse.capra.handler.featureide.tests/plugin.properties b/tests/org.eclipse.capra.handler.featureide.tests/plugin.properties
new file mode 100644
index 00000000..1e025b72
--- /dev/null
+++ b/tests/org.eclipse.capra.handler.featureide.tests/plugin.properties
@@ -0,0 +1,17 @@
+###############################################################################
+# Copyright (c) 2016, 2019 Chalmers | University of Gothenburg, rt-labs and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v2.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v20.html
+#
+# SPDX-License-Identifier: EPL-2.0
+#
+# Contributors:
+# Chalmers | University of Gothenburg and rt-labs - initial API and implementation and/or initial documentation
+# Chalmers | University of Gothenburg - additional features, updated API
+###############################################################################
+#
+
+Bundle-Name = Eclipse Capra Tests for the FeatureIDE Handler
+Bundle-Vendor = Eclipse Capra
diff --git a/tests/org.eclipse.capra.handler.featureide.tests/pom.xml b/tests/org.eclipse.capra.handler.featureide.tests/pom.xml
new file mode 100644
index 00000000..2fc119ac
--- /dev/null
+++ b/tests/org.eclipse.capra.handler.featureide.tests/pom.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?><!--
+ Copyright (c) 2016 Chalmers | University of Gothenburg, rt-labs 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:
+ Chalmers | University of Gothenburg and rt-labs - initial API and implementation and/or initial documentation
+--><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <relativePath>../../pom.xml</relativePath>
+ <groupId>org.eclipse.capra</groupId>
+ <artifactId>parent</artifactId>
+ <version>0.7.1-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>org.eclipse.capra.handler.featureide.tests</artifactId>
+ <packaging>eclipse-test-plugin</packaging>
+
+
+</project>
diff --git a/tests/org.eclipse.capra.handler.featureide.tests/src/org/eclipse/capra/handler/featureide/tests/TestFeatureIDETraces.java b/tests/org.eclipse.capra.handler.featureide.tests/src/org/eclipse/capra/handler/featureide/tests/TestFeatureIDETraces.java
new file mode 100644
index 00000000..763c317b
--- /dev/null
+++ b/tests/org.eclipse.capra.handler.featureide.tests/src/org/eclipse/capra/handler/featureide/tests/TestFeatureIDETraces.java
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Chalmers | University of Gothenburg, rt-labs 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:
+ * Chalmers | University of Gothenburg and rt-labs - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+package org.eclipse.capra.handler.featureide.tests;
+
+import static org.eclipse.capra.testsuite.TestHelper.clearWorkspace;
+import static org.eclipse.capra.testsuite.TestHelper.resetSelectionView;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.nio.file.FileSystems;
+
+import org.eclipse.capra.core.adapters.TracePersistenceAdapter;
+import org.eclipse.capra.core.handlers.IArtifactHandler;
+import org.eclipse.capra.core.helpers.ArtifactHelper;
+import org.eclipse.capra.core.helpers.ExtensionPointHelper;
+import org.eclipse.capra.generic.tracemodel.TracemodelPackage;
+import org.eclipse.capra.testsuite.TestHelper;
+import org.eclipse.capra.ui.views.SelectionView;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.junit.Before;
+import org.junit.Test;
+
+import de.ovgu.featureide.fm.core.base.IFeature;
+import de.ovgu.featureide.fm.core.base.IFeatureModel;
+import de.ovgu.featureide.fm.core.base.impl.FMFactoryManager;
+import de.ovgu.featureide.fm.core.io.manager.FeatureModelManager;
+import de.ovgu.featureide.fm.core.io.xml.XmlFeatureModelFormat;
+
+public class TestFeatureIDETraces {
+
+ private static final String FEATURE_A_NAME = "FeatureA";
+
+ private static final String TEST_PROJECT_NAME = "TestProject";
+
+ private static final String MODEL_A_FILE_NAME = "modelA.xml";
+ private static final String DUMMY_FILE_NAME = "dummy.txt";
+
+ @Before
+ public void init() throws CoreException {
+ clearWorkspace();
+ resetSelectionView();
+ }
+
+ @Test
+ public void TestTraceCreation() throws CoreException, IOException {
+ // Create a project
+ IProject testProject = TestHelper.createSimpleProject(TEST_PROJECT_NAME);
+ assert (TestHelper.projectExists(TEST_PROJECT_NAME));
+
+ // Create a feature model with one feature
+ IFeatureModel modelA = FMFactoryManager.getDefaultFactory().createFeatureModel();
+ modelA.createDefaultValues(TEST_PROJECT_NAME);
+ IFeature feature = FMFactoryManager.getDefaultFactory().createFeature(modelA, FEATURE_A_NAME);
+ modelA.addFeature(feature);
+ modelA.getStructure().getRoot().addChild(feature.getStructure());
+
+ java.nio.file.Path path = FileSystems.getDefault().getPath(testProject.getLocation().toOSString(),
+ MODEL_A_FILE_NAME);
+ modelA.setSourceFile(path);
+ FeatureModelManager.save(modelA, path, new XmlFeatureModelFormat());
+ assert (testProject.getFile(MODEL_A_FILE_NAME).exists());
+
+ // Create an empty file
+ IFile dummyFile = TestHelper.createEmptyFileInProject(DUMMY_FILE_NAME, TEST_PROJECT_NAME);
+ assert (testProject.getFile(DUMMY_FILE_NAME).exists());
+
+ // Add both files to selection
+ assertTrue(SelectionView.getOpenedView().getSelection().isEmpty());
+ SelectionView.getOpenedView().dropToSelection(feature);
+ SelectionView.getOpenedView().dropToSelection(dummyFile);
+ assertFalse(SelectionView.getOpenedView().getSelection().isEmpty());
+
+ // Create a trace via the selection view
+ TestHelper.createTraceForCurrentSelectionOfType(TracemodelPackage.eINSTANCE.getRelatedTo());
+ assertTrue(TestHelper.thereIsATraceBetween(dummyFile, feature));
+
+ // Clear selection view
+ SelectionView.getOpenedView().clearSelection();
+
+ // Test if the resolved wrapper equals the feature
+ TracePersistenceAdapter persistenceAdapter = ExtensionPointHelper.getTracePersistenceAdapter().get();
+ ResourceSet resource = new ResourceSetImpl();
+ ArtifactHelper artifactHelper = new ArtifactHelper(persistenceAdapter.getArtifactWrappers(resource));
+ EObject featureWrapper = artifactHelper.createWrapper(feature);
+ IArtifactHandler<?> featureIdeHandler = artifactHelper.getHandler(feature).orElse(null);
+ assertNotNull(featureIdeHandler);
+ Object resolvedFeature = featureIdeHandler.resolveWrapper(featureWrapper);
+ assertEquals(feature, resolvedFeature);
+
+ }
+}

Back to the top