diff --git a/.gitignore b/.gitignore index 1f19541..1ecae55 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,10 @@ generated/ *.polyglot.category.xml *.polyglot.feature.xml +*.iml +.idea/ +.vscode/ + pom.tycho *.xml_gen diff --git a/.project b/.project new file mode 100644 index 0000000..b9b4caf --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + parent + + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + + diff --git a/README.md b/README.md index 520bb52..4620511 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ The TPCM language currently supports the PCM view points _Repository_, _System_, * Reliability modeling is not yet part of the language * Component parameters are not yet part of the language -All view points can be specified in a single .tpcm file otr split into multiple ones. A comprehensive specification-by-example can be found in the folder _tests/org.palladiosimulator.textual.tpcm.tests/test-resources/parser_. +All view points can be specified in a single .tpcm file otr split into multiple ones. A comprehensive specification-by-example can be found in the folder _examples/org.palladiosimulator.textual.tpcm.examples/_. ### Example ``` Smalltalk diff --git a/bundles/org.palladiosimulator.textual.tpcm.ide/pom.xml b/bundles/org.palladiosimulator.textual.tpcm.ide/pom.xml deleted file mode 100644 index 5e7ece3..0000000 --- a/bundles/org.palladiosimulator.textual.tpcm.ide/pom.xml +++ /dev/null @@ -1,238 +0,0 @@ - - 4.0.0 - - org.palladiosimulator.textual - bundles - 4.3.0-SNAPSHOT - ..\.polyglot.pom.tycho - - org.palladiosimulator.textual.tpcm.ide - eclipse-plugin - - - - log4j - log4j - - - org.eclipse.lsp4j - org.eclipse.lsp4j - - - org.ow2.asm - asm - - - org.ow2.asm - asm-commons - - - org.ow2.asm - asm-tree - - - - - - org.eclipse.xtend - xtend-maven-plugin - - - org.eclipse.tycho - target-platform-configuration - - consider - - - - org.apache.maven.plugins - maven-dependency-plugin - 3.1.2 - - - copy-dependencies - package - - copy-dependencies - - - p2.eclipse-feature - ${project.build.directory}/libs - false - false - true - true - - com.ibm.icu, - org.apache.ant, - org.apache.commons.lang, - org.apache.commons.logging, - org.eclipse.core.commands, - org.eclipse.core.contenttype, - org.eclipse.core.expressions, - org.eclipse.core.filesystem, - org.eclipse.core.jobs, - org.eclipse.core.resources, - org.eclipse.core.runtime, - org.eclipse.core.variables, - org.eclipse.debug.core, - org.eclipse.emf.codegen.ecore, - org.eclipse.emf.codegen, - org.eclipse.emf.emfstore.common, - org.eclipse.emf.mwe.core, - org.eclipse.emf.mwe.utils, - org.eclipse.emf.mwe2.lib, - org.eclipse.emf.mwe2.runtime, - org.eclipse.equinox.app, - org.eclipse.equinox.preferences, - org.eclipse.equinox.registry, - org.eclipse.jdt.core, - org.eclipse.jdt.debug, - org.eclipse.jdt.launching, - org.eclipse.text, - - - - - - - com.googlecode.addjars-maven-plugin - addjars-maven-plugin - 1.0.5 - - - package - - add-jars - - - - - ${project.build.directory}/libs - - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.3 - - - - org.eclipse.xtext.ide.server.ServerLauncher - - - plugin.properties - - - - - - - *:org.palladiosimulator.textual.tpcm.ide-org.eclipse.lsp4j* - *:org.palladiosimulator.textual.tpcm.ide-org.eclipse.xtext.xbase.lib* - *:org.palladiosimulator.textual.tpcm.ide-org.eclipse.xtend.lib* - *:org.palladiosimulator.textual.tpcm.ide-com.google.guava* - *:org.palladiosimulator.textual.tpcm.ide-asm* - *:org.palladiosimulator.textual.tpcm.ide-log4j* - *:org.palladiosimulator.textual.tpcm.ide-org.objectweb.asm* - *:org.palladiosimulator.textual.tpcm.ide-org.apache.log4j* - - - - - *:* - - META-INF/INDEX.LIST - META-INF/*.SF - META-INF/*.DSA - META-INF/*.RSA - .options - .api_description - *.profile - *.html - about.* - about_files/* - plugin.xml - systembundle.properties - profile.list - **/*._trace - **/*.g - **/*.mwe2 - **/*.xtext - - - - true - ls - false - - - - package - - shade - - - - - - org.apache.maven.plugins - maven-jar-plugin - 3.2.0 - - - dummy-javadoc - - jar - - - - false - - ${project.basedir}/docs - javadoc - - NO-JAVADOC - - - - - dummy-sources - - jar - - - ${project.basedir}/docs - - false - - ls-sources - - NO-SOURCES - - - - - - - - - - jdk9-or-newer - - [9,) - - - --add-modules=ALL-SYSTEM - - - - - diff --git a/bundles/org.palladiosimulator.textual.tpcm/META-INF/MANIFEST.MF b/bundles/org.palladiosimulator.textual.tpcm/META-INF/MANIFEST.MF index 1326c14..060965a 100644 --- a/bundles/org.palladiosimulator.textual.tpcm/META-INF/MANIFEST.MF +++ b/bundles/org.palladiosimulator.textual.tpcm/META-INF/MANIFEST.MF @@ -15,7 +15,7 @@ Require-Bundle: org.eclipse.xtext, org.eclipse.emf.common, org.antlr.runtime;bundle-version="[3.2.0,3.2.1)", org.palladiosimulator.commons.stoex;bundle-version="1.0.0";visibility:=reexport, - de.uka.ipd.sdq.stoex.analyser, + de.uka.ipd.sdq.stoex.analyser;visibility:=reexport, io.vavr;bundle-version="0.10.3", tools.mdsd.ecoreworkflow.mwe2lib.xtext;bundle-version="0.1.1", org.palladiosimulator.pcm;bundle-version="4.2.0", diff --git a/bundles/org.palladiosimulator.textual.tpcm/pom.xml b/bundles/org.palladiosimulator.textual.tpcm/pom.xml index 766e0ff..90e3128 100644 --- a/bundles/org.palladiosimulator.textual.tpcm/pom.xml +++ b/bundles/org.palladiosimulator.textual.tpcm/pom.xml @@ -5,7 +5,7 @@ org.palladiosimulator.textual bundles 4.3.0-SNAPSHOT - ..\.polyglot.pom.tycho + ../.polyglot.pom.tycho org.palladiosimulator.textual.tpcm eclipse-plugin diff --git a/examples/org.palladio.textual.tpcm.examples/.project b/examples/org.palladio.textual.tpcm.examples/.project new file mode 100644 index 0000000..ff67a13 --- /dev/null +++ b/examples/org.palladio.textual.tpcm.examples/.project @@ -0,0 +1,28 @@ + + + org.palladio.textual.tpcm.examples + + + + + + org.eclipse.xtext.ui.shared.xtextBuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.xtext.ui.shared.xtextNature + + diff --git a/examples/org.palladio.textual.tpcm.examples/.settings/org.eclipse.core.resources.prefs b/examples/org.palladio.textual.tpcm.examples/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/examples/org.palladio.textual.tpcm.examples/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/examples/org.palladio.textual.tpcm.examples/META-INF/MANIFEST.MF b/examples/org.palladio.textual.tpcm.examples/META-INF/MANIFEST.MF new file mode 100644 index 0000000..5da316e --- /dev/null +++ b/examples/org.palladio.textual.tpcm.examples/META-INF/MANIFEST.MF @@ -0,0 +1,7 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: TPCM Examples +Bundle-SymbolicName: org.palladio.textual.tpcm.examples +Bundle-Version: 4.3.0.qualifier +Automatic-Module-Name: org.palladio.textual.tpcm.examples +Bundle-Vendor: Palladiosimulator.org diff --git a/examples/org.palladio.textual.tpcm.examples/build.properties b/examples/org.palladio.textual.tpcm.examples/build.properties new file mode 100644 index 0000000..97b8792 --- /dev/null +++ b/examples/org.palladio.textual.tpcm.examples/build.properties @@ -0,0 +1,6 @@ +bin.includes = resources_explained.tpcm,\ + resourceenvironment_explained.tpcm,\ + repository_explained.tpcm,\ + imports_explained.tpcm,\ + fragments_explained.tpcm,\ + META-INF/ diff --git a/tests/org.palladiosimulator.textual.tpcm.tests/test-resources/parser/fragments_explained.tpcm b/examples/org.palladio.textual.tpcm.examples/fragments_explained.tpcm similarity index 100% rename from tests/org.palladiosimulator.textual.tpcm.tests/test-resources/parser/fragments_explained.tpcm rename to examples/org.palladio.textual.tpcm.examples/fragments_explained.tpcm diff --git a/tests/org.palladiosimulator.textual.tpcm.tests/test-resources/parser/imports_explained.tpcm b/examples/org.palladio.textual.tpcm.examples/imports_explained.tpcm similarity index 66% rename from tests/org.palladiosimulator.textual.tpcm.tests/test-resources/parser/imports_explained.tpcm rename to examples/org.palladio.textual.tpcm.examples/imports_explained.tpcm index 47ed871..6ea3c6a 100644 --- a/tests/org.palladiosimulator.textual.tpcm.tests/test-resources/parser/imports_explained.tpcm +++ b/examples/org.palladio.textual.tpcm.examples/imports_explained.tpcm @@ -1,4 +1,7 @@ -import "std_definitions.tpcm" //import definitions from separate files by providing a URI or its the relative path +import std::definitions //Import default models from provided plugins. The namespace is mapped to a pathmap uri. The import is equivalent to the next line. +import "pathmap://TPCM_RESOURCES_STD/definitions.tpcm"//import definitions from separate files by providing a URI or its the relative path +// If imported using a absolute or relative uri the file extension needs to be specified. + // imports are not transitively imported // imported objects can be referred to by their fully qualified name (Namespace::ObjectName), e. g. PrimitiveTypes::Integer diff --git a/tests/org.palladiosimulator.textual.tpcm.tests/test-resources/parser/repository_explained.tpcm b/examples/org.palladio.textual.tpcm.examples/repository_explained.tpcm similarity index 100% rename from tests/org.palladiosimulator.textual.tpcm.tests/test-resources/parser/repository_explained.tpcm rename to examples/org.palladio.textual.tpcm.examples/repository_explained.tpcm diff --git a/tests/org.palladiosimulator.textual.tpcm.tests/test-resources/parser/resourceenvironment_explained.tpcm b/examples/org.palladio.textual.tpcm.examples/resourceenvironment_explained.tpcm similarity index 96% rename from tests/org.palladiosimulator.textual.tpcm.tests/test-resources/parser/resourceenvironment_explained.tpcm rename to examples/org.palladio.textual.tpcm.examples/resourceenvironment_explained.tpcm index 43d7152..6162e58 100644 --- a/tests/org.palladiosimulator.textual.tpcm.tests/test-resources/parser/resourceenvironment_explained.tpcm +++ b/examples/org.palladio.textual.tpcm.examples/resourceenvironment_explained.tpcm @@ -1,4 +1,4 @@ -import "std_definitions.tpcm" +import std::definitions resourceenvironment ResourceEnvironment1 //Declaration of resource environment diff --git a/tests/org.palladiosimulator.textual.tpcm.tests/test-resources/parser/resources_explained.tpcm b/examples/org.palladio.textual.tpcm.examples/resources_explained.tpcm similarity index 98% rename from tests/org.palladiosimulator.textual.tpcm.tests/test-resources/parser/resources_explained.tpcm rename to examples/org.palladio.textual.tpcm.examples/resources_explained.tpcm index 56e18ca..f15e8d8 100644 --- a/tests/org.palladiosimulator.textual.tpcm.tests/test-resources/parser/resources_explained.tpcm +++ b/examples/org.palladio.textual.tpcm.examples/resources_explained.tpcm @@ -1,4 +1,4 @@ -import "std_definitions.tpcm" +import std::definitions resourcetypes { // Definition of resource types, which is equivalent to a ResourceTypeRepository // Resource interfaces are defined similar to operation interfaces diff --git a/pom.xml b/pom.xml index bdc7fa1..7eccaad 100644 --- a/pom.xml +++ b/pom.xml @@ -16,8 +16,9 @@ 2.22.0 2.11.3 + 2.0.0 UTF-8 - ${project.basedir}/releng/org.palladiosimulator.textual.targetplatform/org.palladiosimulator.textual.targetplatform.target + ${maven.multiModuleProjectDirectory}/releng/org.palladiosimulator.textual.targetplatform/org.palladiosimulator.textual.targetplatform.target diff --git a/releng/org.palladiosimulator.textual.languageserver/META-INF/MANIFEST.MF b/releng/org.palladiosimulator.textual.languageserver/META-INF/MANIFEST.MF new file mode 100644 index 0000000..034ecf3 --- /dev/null +++ b/releng/org.palladiosimulator.textual.languageserver/META-INF/MANIFEST.MF @@ -0,0 +1,7 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Textual Palladio Language Server +Bundle-SymbolicName: org.palladiosimulator.textual.languageserver +Bundle-Version: 4.3.0.qualifier +Automatic-Module-Name: org.palladiosimulator.textual.languageserver +Require-Bundle: org.palladiosimulator.textual.tpcm.ide;bundle-version="4.3.0" diff --git a/releng/org.palladiosimulator.textual.languageserver/build.properties b/releng/org.palladiosimulator.textual.languageserver/build.properties new file mode 100644 index 0000000..5f22cdd --- /dev/null +++ b/releng/org.palladiosimulator.textual.languageserver/build.properties @@ -0,0 +1 @@ +bin.includes = META-INF/ diff --git a/releng/org.palladiosimulator.textual.languageserver/language-server.xml b/releng/org.palladiosimulator.textual.languageserver/language-server.xml new file mode 100644 index 0000000..c626029 --- /dev/null +++ b/releng/org.palladiosimulator.textual.languageserver/language-server.xml @@ -0,0 +1,38 @@ + + + language-server + false + + zip + + + + target/appassembler/bin + bin + + + target/appassembler/repo + repo + + + + \ No newline at end of file diff --git a/releng/org.palladiosimulator.textual.languageserver/pom.xml b/releng/org.palladiosimulator.textual.languageserver/pom.xml new file mode 100644 index 0000000..025a7ef --- /dev/null +++ b/releng/org.palladiosimulator.textual.languageserver/pom.xml @@ -0,0 +1,141 @@ + + + 4.0.0 + + org.palladiosimulator.textual + releng + 4.3.0-SNAPSHOT + ../pom.xml + + org.palladiosimulator.textual.languageserver + eclipse-plugin + + + + log4j + log4j + + + org.eclipse.lsp4j + org.eclipse.lsp4j + + + org.ow2.asm + asm + + + org.ow2.asm + asm-commons + + + org.ow2.asm + asm-tree + + + + + + + org.codehaus.mojo + appassembler-maven-plugin + 2.1.0 + + + assemble + + assemble + + package + + true + + all + + + + org.eclipse.xtext.ide.server.ServerLauncher + ls + + + org.eclipse.xtext.ide.server.SocketServerLauncher + socket-ls + + + flat + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 3.1.2 + + + copy-dependencies + package + + copy-dependencies + + + p2.eclipse-feature + ${project.build.directory}/appassembler/repo + false + false + true + true + + com.ibm.icu, + org.apache.ant, + org.apache.commons.lang, + org.apache.commons.logging, + org.eclipse.core.commands, + org.eclipse.core.contenttype, + org.eclipse.core.expressions, + org.eclipse.core.filesystem, + org.eclipse.core.jobs, + org.eclipse.core.resources, + org.eclipse.core.runtime, + org.eclipse.core.variables, + org.eclipse.debug.core, + org.eclipse.emf.codegen.ecore, + org.eclipse.emf.codegen, + org.eclipse.emf.emfstore.common, + org.eclipse.emf.mwe.core, + org.eclipse.emf.mwe.utils, + org.eclipse.emf.mwe2.lib, + org.eclipse.emf.mwe2.runtime, + org.eclipse.equinox.app, + org.eclipse.equinox.preferences, + org.eclipse.equinox.registry, + org.eclipse.jdt.core, + org.eclipse.jdt.debug, + org.eclipse.jdt.launching, + org.eclipse.text, + + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 3.3.0 + + + package + + single + + + + + + language-server.xml + + + + + + \ No newline at end of file diff --git a/releng/org.palladiosimulator.textual.updatesite/pom.xml b/releng/org.palladiosimulator.textual.updatesite/pom.xml new file mode 100644 index 0000000..9b0c985 --- /dev/null +++ b/releng/org.palladiosimulator.textual.updatesite/pom.xml @@ -0,0 +1,48 @@ + + + 4.0.0 + + org.palladiosimulator.textual + releng + 4.3.0-SNAPSHOT + ..\pom.xml + + org.palladiosimulator.textual.updatesite.eclipse-repository + 4.3.0-SNAPSHOT + eclipse-repository + org.palladiosimulator.textual.updatesite.eclipse-repository + + + + + org.apache.maven.plugins + maven-dependency-plugin + 3.1.2 + + + copy + package + + copy + + + + + ${project.groupId} + org.palladiosimulator.textual.languageserver + ${project.version} + zip + language-server + true + ${project.build.directory}/repository/downloads/ + language-server.zip + + + + + + + + + diff --git a/releng/pom.xml b/releng/pom.xml new file mode 100644 index 0000000..fb9be31 --- /dev/null +++ b/releng/pom.xml @@ -0,0 +1,19 @@ + + + 4.0.0 + + org.palladiosimulator.textual + parent + 4.3.0-SNAPSHOT + ..\pom.xml + + releng + 4.3.0-SNAPSHOT + pom + releng + + org.palladiosimulator.textual.languageserver + org.palladiosimulator.textual.updatesite + + diff --git a/tests/org.palladiosimulator.textual.languageserver.tests/pom.xml b/tests/org.palladiosimulator.textual.languageserver.tests/pom.xml new file mode 100644 index 0000000..afe5597 --- /dev/null +++ b/tests/org.palladiosimulator.textual.languageserver.tests/pom.xml @@ -0,0 +1,85 @@ + + + 4.0.0 + + org.palladiosimulator.textual + tests + 4.3.0-SNAPSHOT + ../.polyglot.pom.tycho + + org.palladiosimulator.textual.languageserver.tests + + + UTF-8 + 1.8 + ${maven.compiler.source} + 5.6.2 + + + + + org.eclipse.lsp4j + org.eclipse.lsp4j + 0.9.0 + + + org.junit.jupiter + junit-jupiter + ${junit.jupiter.version} + test + + + ${project.groupId} + org.palladiosimulator.textual.languageserver + language-server + ${project.version} + zip + + + + + + + maven-compiler-plugin + + 11 + 11 + + + + maven-surefire-plugin + 2.22.2 + + @{argLine} -Dls.path=${project.build.directory}/lsForIt -Dtest.basepath=${project.basedir}/src/test/resources/ + + + + org.apache.maven.plugins + maven-dependency-plugin + 3.1.2 + + + unpack + process-test-resources + + unpack + + + + + ${project.groupId} + org.palladiosimulator.textual.languageserver + language-server + ${project.version} + zip + true + ${project.build.directory}/lsForIt + + + + + + + + + \ No newline at end of file diff --git a/tests/org.palladiosimulator.textual.languageserver.tests/src/test/java/org/palladiosimulator/textual/tpcm/lsp/LanguageServerTest.java b/tests/org.palladiosimulator.textual.languageserver.tests/src/test/java/org/palladiosimulator/textual/tpcm/lsp/LanguageServerTest.java new file mode 100644 index 0000000..bbfe00b --- /dev/null +++ b/tests/org.palladiosimulator.textual.languageserver.tests/src/test/java/org/palladiosimulator/textual/tpcm/lsp/LanguageServerTest.java @@ -0,0 +1,167 @@ +package org.palladiosimulator.textual.tpcm.lsp; + +import org.eclipse.lsp4j.InitializeParams; +import org.eclipse.lsp4j.InitializedParams; +import org.eclipse.lsp4j.PublishDiagnosticsParams; +import org.eclipse.lsp4j.WorkspaceFolder; +import org.eclipse.lsp4j.jsonrpc.Launcher; +import org.eclipse.lsp4j.launch.LSPLauncher; +import org.eclipse.lsp4j.services.LanguageServer; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; +import org.junit.platform.commons.logging.Logger; +import org.junit.platform.engine.discovery.UriSelector; + +import java.io.*; +import java.net.URI; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.time.Duration; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Objects; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.stream.Collectors; + +import static org.junit.jupiter.api.Assertions.*; + +class LanguageServerTest { + public static String EXAMPLE_MODELS_LOCATION_PARAMETER = "examples.location"; + public static String EXAMPLE_MODELS_LOCATION_DEFAULT = "../../examples/org.palladio.textual.tpcm.examples/"; + + Process lsProc; + LanguageServer serverUnderTest; + MockLanguageClient mockClient; + + @Test + void testEmpty() throws InterruptedException, TimeoutException, ExecutionException { + testSingleFileNoDiagnostics("testInitialization"); + } + + @Test + void testPathmap() throws InterruptedException, TimeoutException, ExecutionException { + testSingleFileNoDiagnostics("testPathmap"); + } + + @Test + void testParseFilesOfExamplesProject() throws InterruptedException, TimeoutException, ExecutionException, IOException { + Path examplesPath = Paths.get(System.getProperty(EXAMPLE_MODELS_LOCATION_PARAMETER, EXAMPLE_MODELS_LOCATION_DEFAULT)); + var tpcmFiles = Files.walk(examplesPath).filter(f -> f.toString().endsWith(".tpcm")) + .map(path -> { + try { + return path.toRealPath().toUri().toString(); + } catch (IOException e) { + throw new RuntimeException(e); + } + }).collect(Collectors.toSet()); + var failed = new HashMap(); + + assertTimeoutPreemptively(Duration.ofSeconds(60), () -> { + initializeLanguageServer(examplesPath); + while (!tpcmFiles.isEmpty()) { + var diag = mockClient.publishedDiagnostics.poll(60, TimeUnit.SECONDS); + var uri = Paths.get(URI.create(diag.getUri())).toRealPath().toUri().toString(); + System.out.println("Received: " + uri); + if (tpcmFiles.remove(uri) && diag.getDiagnostics().size() > 0) { + failed.put(diag.getUri(), diag.toString()); + } + } + }, () -> "The test timed out while waiting for a server diagnostic of files: " + tpcmFiles.toString()); + + assertEquals(0, failed.size(), () -> "The examples should have been parsed without issues. Instead the following files failed: " + failed.toString()); + assertEquals(0, tpcmFiles.size(), () -> "The server should have been parsed all files from the examples folder. Instead the following files were not processed: " + tpcmFiles.toString()); + } + + void testSingleFileNoDiagnostics(String testName) throws InterruptedException, ExecutionException, TimeoutException { + initializeLanguageServer(getTestArtifactsFolder(testName)); + + var diagnostic = mockClient.publishedDiagnostics.poll(10, TimeUnit.SECONDS); + assertEquals(diagnostic.getUri(), getTestDocument(testName).toUri().toString()); + assertEquals(0, diagnostic.getDiagnostics().size(), () -> "The file should have been parsed without an issue. The server returned the following issues: " + diagnostic.toString()); + } + + Path getTestDocument(String testName) { + return getTestArtifactsFolder(testName).resolve("test.tpcm"); + } + + Path getTestArtifactsFolder(String testName) { + return Paths.get(System.getProperty("test.basepath")).resolve(testName); + } + + void initializeLanguageServer(Path basePath) throws InterruptedException, ExecutionException, TimeoutException { + var params = new InitializeParams(); + params.setRootUri(basePath.toUri().toString()); + + WorkspaceFolder folder = new WorkspaceFolder(basePath.toUri().toString(), "Test Workspace"); + params.setWorkspaceFolders(Collections.singletonList(folder)); + + var res = serverUnderTest.initialize(params).get(10, TimeUnit.SECONDS); + serverUnderTest.initialized(new InitializedParams()); + } + + void shutdownLanguageServer() throws InterruptedException, ExecutionException, TimeoutException { + serverUnderTest.shutdown().thenRun(() -> serverUnderTest.exit()).get(10, TimeUnit.SECONDS); + } + + @BeforeEach + void startLanguageServer() throws IOException, InterruptedException { + boolean isWindows = System.getProperty("os.name").toLowerCase().startsWith("windows"); + + ProcessBuilder builder = new ProcessBuilder(); + if (isWindows) { + builder.command("cmd.exe", "/c", "bin\\ls.bat"); + } else { + builder.command("sh", "-c", "bin/ls"); + } + File folder = Paths.get(System.getProperty("ls.path")).toFile(); + builder.directory(folder); + lsProc = builder.start(); + StreamGobbler stdErrRedirect = new StreamGobbler(lsProc.getErrorStream()); + stdErrRedirect.start(); + + mockClient = new MockLanguageClient(); + Launcher launcher = LSPLauncher.createClientLauncher(mockClient, lsProc.getInputStream(), lsProc.getOutputStream()); + launcher.startListening(); + serverUnderTest = launcher.getRemoteProxy(); + } + + @AfterEach + void terminateLanguageServerProcess() throws InterruptedException, TimeoutException, ExecutionException { + shutdownLanguageServer(); + + if (lsProc.isAlive()) { + Thread.sleep(2000); + if (lsProc.isAlive()) { + lsProc.destroy(); + } + } + } + + class StreamGobbler extends Thread { + InputStream is; + + // reads everything from is until empty. + StreamGobbler(InputStream is) { + this.is = is; + } + + public void run() { + try { + InputStreamReader isr = new InputStreamReader(is); + BufferedReader br = new BufferedReader(isr); + String line=null; + while ( (line = br.readLine()) != null) + System.out.println(line); + } catch (IOException ioe) { + ioe.printStackTrace(); + } + } + } + +} \ No newline at end of file diff --git a/tests/org.palladiosimulator.textual.languageserver.tests/src/test/java/org/palladiosimulator/textual/tpcm/lsp/MockLanguageClient.java b/tests/org.palladiosimulator.textual.languageserver.tests/src/test/java/org/palladiosimulator/textual/tpcm/lsp/MockLanguageClient.java new file mode 100644 index 0000000..6f8f370 --- /dev/null +++ b/tests/org.palladiosimulator.textual.languageserver.tests/src/test/java/org/palladiosimulator/textual/tpcm/lsp/MockLanguageClient.java @@ -0,0 +1,65 @@ +package org.palladiosimulator.textual.tpcm.lsp; + +import org.eclipse.lsp4j.*; +import org.eclipse.lsp4j.services.LanguageClient; + +import java.nio.file.Paths; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.LinkedBlockingQueue; + +public class MockLanguageClient implements LanguageClient { + @Override + public CompletableFuture applyEdit(ApplyWorkspaceEditParams params) { + return null; + } + + @Override + public CompletableFuture registerCapability(RegistrationParams params) { + return null; + } + + @Override + public CompletableFuture unregisterCapability(UnregistrationParams params) { + return null; + } + + @Override + public void telemetryEvent(Object o) { + } + + public LinkedBlockingQueue publishedDiagnostics = new LinkedBlockingQueue<>(); + @Override + public void publishDiagnostics(PublishDiagnosticsParams publishDiagnosticsParams) { + publishedDiagnostics.add(publishDiagnosticsParams); + } + + @Override + public void showMessage(MessageParams messageParams) { + } + + @Override + public CompletableFuture showMessageRequest(ShowMessageRequestParams showMessageRequestParams) { + return null; + } + + @Override + public void logMessage(MessageParams messageParams) { + } + + @Override + public CompletableFuture> workspaceFolders() { + return null; + } + + @Override + public CompletableFuture> configuration(ConfigurationParams configurationParams) { + return null; + } + + @Override + public void semanticHighlighting(SemanticHighlightingParams params) { + } +} diff --git a/tests/org.palladiosimulator.textual.languageserver.tests/src/test/resources/testInitialization/test.tpcm b/tests/org.palladiosimulator.textual.languageserver.tests/src/test/resources/testInitialization/test.tpcm new file mode 100644 index 0000000..e69de29 diff --git a/tests/org.palladiosimulator.textual.languageserver.tests/src/test/resources/testPathmap/test.tpcm b/tests/org.palladiosimulator.textual.languageserver.tests/src/test/resources/testPathmap/test.tpcm new file mode 100644 index 0000000..d1ed538 --- /dev/null +++ b/tests/org.palladiosimulator.textual.languageserver.tests/src/test/resources/testPathmap/test.tpcm @@ -0,0 +1 @@ +import std::definitions \ No newline at end of file diff --git a/tests/org.palladiosimulator.textual.tpcm.tests/META-INF/MANIFEST.MF b/tests/org.palladiosimulator.textual.tpcm.tests/META-INF/MANIFEST.MF index 24cc5a2..3b9dc20 100644 --- a/tests/org.palladiosimulator.textual.tpcm.tests/META-INF/MANIFEST.MF +++ b/tests/org.palladiosimulator.textual.tpcm.tests/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Automatic-Module-Name: org.palladiosimulator.textual.tpcm.tests Bundle-ManifestVersion: 2 Bundle-Name: org.palladiosimulator.textual.tpcm.tests -Bundle-Vendor: My Company +Bundle-Vendor: Palladiosimulator.org Bundle-Version: 4.3.0.qualifier Bundle-SymbolicName: org.palladiosimulator.textual.tpcm.tests; singleton:=true Bundle-ActivationPolicy: lazy @@ -10,6 +10,7 @@ Require-Bundle: org.palladiosimulator.textual.tpcm, org.junit.jupiter.api;bundle-version="[5.0.0,6.0.0)", org.eclipse.xtext.testing, org.eclipse.xtext.xbase.testing, - org.eclipse.xtext.xbase.lib;bundle-version="2.14.0" + org.eclipse.xtext.xbase.lib;bundle-version="2.14.0", + org.apache.log4j;bundle-version="1.2.15" Bundle-RequiredExecutionEnvironment: JavaSE-11 Export-Package: org.palladiosimulator.textual.tpcm.tests;x-internal=true diff --git a/tests/org.palladiosimulator.textual.tpcm.tests/src/org/palladiosimulator/textual/tpcm/tests/TPCMParsingTest.xtend b/tests/org.palladiosimulator.textual.tpcm.tests/src/org/palladiosimulator/textual/tpcm/tests/TPCMParsingTest.xtend index 2a5c4ca..f1d990f 100644 --- a/tests/org.palladiosimulator.textual.tpcm.tests/src/org/palladiosimulator/textual/tpcm/tests/TPCMParsingTest.xtend +++ b/tests/org.palladiosimulator.textual.tpcm.tests/src/org/palladiosimulator/textual/tpcm/tests/TPCMParsingTest.xtend @@ -9,6 +9,8 @@ import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths import java.util.stream.Stream +import org.eclipse.core.runtime.FileLocator +import org.eclipse.core.runtime.Platform import org.eclipse.emf.common.util.URI import org.eclipse.xtext.resource.XtextResourceSet import org.eclipse.xtext.testing.InjectWith @@ -24,12 +26,27 @@ import static org.junit.jupiter.api.DynamicTest.dynamicTest @ExtendWith(InjectionExtension) @InjectWith(TPCMInjectorProvider) class TPCMParsingTest { + public static val EXAMPLE_MODELS_LOCATION_PARAMETER = "examples.location" + public static val EXAMPLE_MODELS_LOCATION_DEFAULT = "../../examples/org.palladio.textual.tpcm.examples/" + @Inject Provider resourceSetProvider; @TestFactory - def Stream checkAllTPCMParserTestFiles() { - return Files.walk(Paths.get("test-resources/parser"), 1).filter([it.toString().endsWith(".tpcm")]).map([ path | + def Stream tryParsingAllTPCMExamples() { + val testLocation = System.properties.getOrDefault(EXAMPLE_MODELS_LOCATION_PARAMETER, EXAMPLE_MODELS_LOCATION_DEFAULT).toString() + val testPath = Paths.get(testLocation) + + var java.net.URI fileURI; + if (Platform.isRunning) { + fileURI = FileLocator.toFileURL(testPath.toUri.toURL).toURI + } + + if (fileURI === null) { + fileURI = testPath.toUri + } + + return Files.walk(Paths.get(fileURI), 1).filter([it.toString().endsWith(".tpcm")]).map([ path | dynamicTest("> " + path.getFileName(), path.toUri(), // test source uri [|testParser(path)] as Executable) ]); diff --git a/tests/org.palladiosimulator.textual.tpcm.tests/test-resources/parser/std_definitions.tpcm b/tests/org.palladiosimulator.textual.tpcm.tests/test-resources/parser/std_definitions.tpcm deleted file mode 100644 index cd600ae..0000000 --- a/tests/org.palladiosimulator.textual.tpcm.tests/test-resources/parser/std_definitions.tpcm +++ /dev/null @@ -1,33 +0,0 @@ -repository PrimitiveTypes { - datatype Integer INT - datatype Double DOUBLE - failure CPUFailure -} - -resourcetypes { - interface ICPU { - op process(amount PrimitiveTypes::Integer) - } - - processing CPUResource { - provides ICPU - raises PrimitiveTypes::CPUFailure - property processingRate PrimitiveTypes::Double - property schedulingPolicy SchedulingPolicy - } - - link Ethernet { - property throughput PrimitiveTypes::Double - property latency PrimitiveTypes::Double - } - - internal PassiveResource { - property capacity PrimitiveTypes::Integer - op acquire - op release - } - - type SchedulingPolicy - entity SimFairShare SchedulingPolicy - entity FirstComeFirstServe SchedulingPolicy -} \ No newline at end of file