diff options
| author | Jessy Mallet | 2016-06-15 14:46:37 +0000 |
|---|---|---|
| committer | Laurent Redor | 2016-06-17 13:09:25 +0000 |
| commit | bb89a55f5199325ca3525b3082d975d8db6983ab (patch) | |
| tree | c13c73e0d185de43885908ed0aa6d2a0657a40d8 | |
| parent | a3e0df9b88aefd09b0ea3469630894ba0c66a998 (diff) | |
| download | org.eclipse.sirius-bb89a55f5199325ca3525b3082d975d8db6983ab.tar.gz org.eclipse.sirius-bb89a55f5199325ca3525b3082d975d8db6983ab.tar.xz org.eclipse.sirius-bb89a55f5199325ca3525b3082d975d8db6983ab.zip | |
[495135] Service class creation with VSP.
During VSP creation, an empty service class is added to the project and
a viewpoint is added in VSM to reference this class by javaExtension.
Bug: 495135
Change-Id: If1f1b7df22f399c7bee3fdfbb7c334a5323ee91b
Signed-off-by: Jessy Mallet <jessy.mallet@obeo.fr>
4 files changed, 70 insertions, 7 deletions
diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/modeler/ecore/design/JavaExtensionTests.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/modeler/ecore/design/JavaExtensionTests.java index 48124f7a19..e44daeeebb 100644 --- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/modeler/ecore/design/JavaExtensionTests.java +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/modeler/ecore/design/JavaExtensionTests.java @@ -197,6 +197,7 @@ public class JavaExtensionTests extends SiriusDiagramTestCase { } final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); assertTrue("The project " + projectName + " was not created correctly.", project.exists()); + assertTrue("The project " + projectName + " should contain Service.java class.", project.getFile("src/" + projectName + "/Services.java").exists()); // Copy of representation description file EclipseTestsSupportHelper.INSTANCE.copyFile(SiriusTestsPlugin.PLUGIN_ID, viewpointDescriptionPath, projectName + File.separator + DESCRIPTION_FOLDER_NAME + File.separator + new Path(viewpointDescriptionPath).lastSegment()); diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/editor/vsm/ViewpointSpecificationProjectCreationTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/editor/vsm/ViewpointSpecificationProjectCreationTest.java index 4630c196eb..ae6e3336da 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/editor/vsm/ViewpointSpecificationProjectCreationTest.java +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/editor/vsm/ViewpointSpecificationProjectCreationTest.java @@ -10,20 +10,29 @@ *******************************************************************************/ package org.eclipse.sirius.tests.swtbot.editor.vsm; +import java.io.IOException; + import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectNature; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.emf.common.util.EList; import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; import org.eclipse.sirius.business.internal.migration.description.VSMMigrationService; import org.eclipse.sirius.business.internal.migration.description.VSMVersionSAXParser; +import org.eclipse.sirius.ecore.extender.tool.api.ModelUtils; import org.eclipse.sirius.tests.support.api.TestsUtil; import org.eclipse.sirius.tests.swtbot.support.api.AbstractSiriusSwtBotGefTestCase; import org.eclipse.sirius.tests.swtbot.support.api.condition.ItemEnabledCondition; import org.eclipse.sirius.tests.swtbot.support.utils.SWTBotUtils; import org.eclipse.sirius.ui.tools.api.views.modelexplorerview.IModelExplorerView; +import org.eclipse.sirius.viewpoint.description.Group; +import org.eclipse.sirius.viewpoint.description.JavaExtension; +import org.eclipse.sirius.viewpoint.description.Viewpoint; import org.eclipse.swtbot.eclipse.gef.finder.SWTGefBot; import org.eclipse.swtbot.swt.finder.waits.Conditions; import org.eclipse.swtbot.swt.finder.waits.DefaultCondition; @@ -42,6 +51,10 @@ public class ViewpointSpecificationProjectCreationTest extends AbstractSiriusSwt private static final String VSM = "test.odesign"; + private static final String VIEWPOINT_NAME = "MyViewpoint"; + + private static final String JAVA_EXTENSION_QUALIFIED_NAME = VSM_PROJECT_NAME + ".Services"; + private static final String WIZARD_FILE = "File"; private static final String WIZARD_FINISH = "Finish"; @@ -68,8 +81,9 @@ public class ViewpointSpecificationProjectCreationTest extends AbstractSiriusSwt /** * Check that the VSM project is properly created. + * @throws IOException */ - public void test_ViewpointViewpoint_Specification_Project_Creation() { + public void test_ViewpointViewpoint_Specification_Project_Creation() throws IOException { if (TestsUtil.shouldSkipUnreliableTests()) { return; } @@ -107,14 +121,30 @@ public class ViewpointSpecificationProjectCreationTest extends AbstractSiriusSwt assertNotNull(VSP_SHOULD_CONTAIN + ".classpath file.", project.getFile(".classpath")); assertNotNull(VSP_SHOULD_CONTAIN + ".project file.", project.getFile(".project")); assertNotNull(VSP_SHOULD_CONTAIN + "MANIFEST.MF file.", project.getFile("META-INF/MANIFEST.MF")); - + assertNotNull(VSP_SHOULD_CONTAIN + "Services.java file.", project.getFile("src/" + project.getName() + "/Services.java")); + // Check that the created odesign does not need migration (version tag // must be initialized) - VSMVersionSAXParser parser = new VSMVersionSAXParser(URI.createPlatformResourceURI(vsm.getFullPath().toOSString())); + URI createPlatformResourceURI = URI.createPlatformResourceURI(vsm.getFullPath().toOSString()); + VSMVersionSAXParser parser = new VSMVersionSAXParser(createPlatformResourceURI); String loadedVersion = parser.getVersion(new NullProgressMonitor()); assertNotNull("The VSM Group version must be initialized at creation.", loadedVersion); - assertFalse("The migration must be required on just created VSM.", VSMMigrationService.getInstance().isMigrationNeeded(Version.parseVersion(loadedVersion))); - + assertFalse("The migration must be required on just created VSM.", + VSMMigrationService.getInstance().isMigrationNeeded(Version.parseVersion(loadedVersion))); + // Check that the created odesign contains a default viewpoint with one java extension. + ResourceSet set = new ResourceSetImpl(); + Group modeler = (Group) ModelUtils.load(createPlatformResourceURI, set); + EList<Viewpoint> ownedViewpoints = modeler.getOwnedViewpoints(); + assertTrue("The VSM Group must contains a default viewpoint.", ownedViewpoints.size() == 1); + Viewpoint viewpoint = ownedViewpoints.get(0); + assertTrue("The VSM Group must contains a default viewpoint named " + VIEWPOINT_NAME + ".", + VIEWPOINT_NAME.equals(viewpoint.getName())); + EList<JavaExtension> ownedJavaExtensions = viewpoint.getOwnedJavaExtensions(); + assertTrue("The default viewpoint of the VSM should contain a default java extension.", + ownedJavaExtensions.size() == 1); + JavaExtension javaExtension = ownedJavaExtensions.get(0); + assertTrue("The default Java extension name in Viewpoint should be " + JAVA_EXTENSION_QUALIFIED_NAME + ".", + JAVA_EXTENSION_QUALIFIED_NAME.equals(javaExtension.getQualifiedClassName())); // delete project closeAllEditors(); try { diff --git a/plugins/org.eclipse.sirius.ui/resources/Services.java_ b/plugins/org.eclipse.sirius.ui/resources/Services.java_ new file mode 100644 index 0000000000..0bbc3a622b --- /dev/null +++ b/plugins/org.eclipse.sirius.ui/resources/Services.java_ @@ -0,0 +1,17 @@ +package %packageName; + +import org.eclipse.emf.ecore.EObject; + +/** + * The services class used by VSM. + */ +public class Services { + + /** + * See http://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.sirius.doc%2Fdoc%2Findex.html&cp=24 for documentation on how to write service methods. + */ + public EObject myService(EObject self, String arg) { + // TODO Auto-generated code + return self; + } +} diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/project/ViewpointSpecificationProject.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/project/ViewpointSpecificationProject.java index f42ed562a8..942a4ad228 100644 --- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/project/ViewpointSpecificationProject.java +++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/project/ViewpointSpecificationProject.java @@ -53,6 +53,8 @@ import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.sirius.viewpoint.description.DescriptionFactory; import org.eclipse.sirius.viewpoint.description.DescriptionPackage; import org.eclipse.sirius.viewpoint.description.Group; +import org.eclipse.sirius.viewpoint.description.JavaExtension; +import org.eclipse.sirius.viewpoint.description.Viewpoint; import org.eclipse.sirius.viewpoint.provider.SiriusEditPlugin; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IWorkbench; @@ -86,6 +88,11 @@ public final class ViewpointSpecificationProject { public static final String ENCODING_DEFAULT = "UTF-8"; //$NON-NLS-1$ /** + * The dot separator path. + */ + private static final String DOT_SEPARATOR_PATH = "\\."; //$NON-NLS-1$ + + /** * The line separator to use on the running platform. */ private static final String NL = System.getProperty("line.separator"); //$NON-NLS-1$ @@ -236,6 +243,7 @@ public final class ViewpointSpecificationProject { protected static IFile createODesignFile(final IProject prj, final String modelName, final String modelInitialObjectName, final String encoding, final IRunnableContext runnable) throws IOException, InvocationTargetException, InterruptedException { final IFile modelFile = ViewpointSpecificationProject.getModelFile(prj, modelName); + final String javaExtensionQualifiedName = prj.getName() + ".Services"; //$NON-NLS-1$ final WorkspaceModifyOperation operation = new WorkspaceModifyOperation() { @Override protected void execute(final IProgressMonitor progressMonitor) { @@ -247,6 +255,12 @@ public final class ViewpointSpecificationProject { if (rootObject != null) { if (rootObject instanceof Group) { ((Group) rootObject).setName(modelName.replaceAll("." + VIEWPOINT_MODEL_EXTENSION, "")); //$NON-NLS-1$ //$NON-NLS-2$ + Viewpoint viewpoint = DescriptionFactory.eINSTANCE.createViewpoint(); + viewpoint.setName("MyViewpoint"); //$NON-NLS-1$ + JavaExtension javaExtension = DescriptionFactory.eINSTANCE.createJavaExtension(); + javaExtension.setQualifiedClassName(javaExtensionQualifiedName); + viewpoint.getOwnedJavaExtensions().add(javaExtension); + ((Group) rootObject).getOwnedViewpoints().add(viewpoint); } resource.getContents().add(rootObject); } @@ -317,7 +331,7 @@ public final class ViewpointSpecificationProject { * is the monitor */ private static void convert(final IProject prj, final String modelName, final IProgressMonitor monitor) { - final String modelNameWithoutExtension = modelName.replaceAll("\\." + VIEWPOINT_MODEL_EXTENSION + "$", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + final String modelNameWithoutExtension = modelName.replaceAll(DOT_SEPARATOR_PATH + VIEWPOINT_MODEL_EXTENSION + "$", ""); //$NON-NLS-1$ //$NON-NLS-2$ // WARNING: variable names should not share any common prefix. // applyReplacements() does not deal with this case. @@ -339,7 +353,8 @@ public final class ViewpointSpecificationProject { replacements.put("packageName", packageName); //$NON-NLS-1$ ViewpointSpecificationProject.createFileFromTemplate(prj, "build.properties", "resources/build.properties", replacements, monitor); //$NON-NLS-1$ //$NON-NLS-2$ $NON-NLS-2$ - ViewpointSpecificationProject.createFileFromTemplate(prj, "src/" + packageName.replaceAll("\\.", "/") + "/Activator.java", "resources/Activator.java_", replacements, monitor); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ + ViewpointSpecificationProject.createFileFromTemplate(prj, "src/" + packageName.replaceAll(DOT_SEPARATOR_PATH, "/") + "/Activator.java", "resources/Activator.java_", replacements, monitor); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + ViewpointSpecificationProject.createFileFromTemplate(prj, "src/" + packageName.replaceAll(DOT_SEPARATOR_PATH, "/") + "/Services.java", "resources/Services.java_", replacements, monitor); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ ViewpointSpecificationProject.createFileFromTemplate(prj, ".classpath", "resources/classpath.xml", replacements, monitor); //$NON-NLS-1$ //$NON-NLS-2$ $NON-NLS-2$ ViewpointSpecificationProject.createFileFromTemplate(prj, "META-INF/MANIFEST.MF", "resources/MANIFEST.MF", replacements, monitor); //$NON-NLS-1$ //$NON-NLS-2$ $NON-NLS-2$ ViewpointSpecificationProject.createFileFromTemplate(prj, ".project", "resources/project.xml", replacements, monitor); //$NON-NLS-1$ //$NON-NLS-2$ $NON-NLS-2$ |
