Переглянути джерело

Add MetaInf to new Frontends and align language options

Dominik Fuchß 4 роки тому
батько
коміт
8d3eecbd13

+ 1 - 1
jplag.cli/src/test/java/de/jplag/cli/LanguageTest.java

@@ -28,7 +28,7 @@ class LanguageTest extends CommandLineInterfaceTest {
     @Test
     void testLoading() {
         var languages = LanguageLoader.getAllAvailableLanguages();
-        Assertions.assertEquals(9, languages.size());
+        Assertions.assertEquals(11, languages.size(), "Loaded Languages: " + languages.keySet());
     }
 
     @Test

+ 5 - 0
jplag.endToEndTesting/pom.xml

@@ -13,6 +13,11 @@
             <groupId>de.jplag</groupId>
             <artifactId>jplag</artifactId>
         </dependency>
+        <dependency>
+            <groupId>de.jplag</groupId>
+            <artifactId>java</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>de.jplag</groupId>
             <artifactId>frontend-testutils</artifactId>

+ 6 - 7
jplag.endToEndTesting/src/main/java/de/jplag/end_to_end_testing/helper/JPlagTestSuiteHelper.java

@@ -15,7 +15,6 @@ import org.slf4j.LoggerFactory;
 import de.jplag.end_to_end_testing.constants.TestDirectoryConstants;
 import de.jplag.end_to_end_testing.model.JsonModel;
 import de.jplag.end_to_end_testing.model.TestCaseModel;
-import de.jplag.options.LanguageOption;
 
 /**
  * This helper class deals with creating the test cases as well as copying and deleting for the end-to-end tests. The
@@ -28,18 +27,18 @@ public class JPlagTestSuiteHelper {
 
     private String[] resourceNames;
     private List<JsonModel> resultModel;
-    private LanguageOption languageOption;
+    private String languageIdentifier;
 
     /**
      * Helper class for the endToEnd tests. In this class the necessary resources are loaded, prepared and copied for the
      * tests based on the passed parameters. An instance of this class loads all necessary paths and properties for a test
      * run with the specified language
-     * @param languageOption for loading language-specific resources
+     * @param languageIdentifier for loading language-specific resources
      * @throws IOException is thrown for all problems that may occur while parsing the json file. This includes both reading
      * and parsing problems.
      */
-    public JPlagTestSuiteHelper(LanguageOption languageOption) throws IOException {
-        this.languageOption = languageOption;
+    public JPlagTestSuiteHelper(String languageIdentifier) throws IOException {
+        this.languageIdentifier = languageIdentifier;
         this.resourceNames = new File(TestDirectoryConstants.BASE_PATH_TO_JAVA_RESOURCES_SORTALGO.toString()).list();
 
         this.resultModel = JsonHelper.getResultModelFromPath();
@@ -56,7 +55,7 @@ public class JPlagTestSuiteHelper {
     public TestCaseModel createNewTestCase(String[] classNames, String functionName) throws IOException {
         createNewTestCaseDirectory(classNames);
         JsonModel resultJsonModel = resultModel.stream().filter(jsonModel -> functionName.equals(jsonModel.getFunctionName())).findAny().orElse(null);
-        return new TestCaseModel(TestDirectoryConstants.TEMPORARY_SUBMISSION_DIRECTORY_NAME, resultJsonModel, languageOption);
+        return new TestCaseModel(TestDirectoryConstants.TEMPORARY_SUBMISSION_DIRECTORY_NAME, resultJsonModel, languageIdentifier);
     }
 
     /**
@@ -98,7 +97,7 @@ public class JPlagTestSuiteHelper {
 
     /**
      * Delete directory with including files
-     * @param file Path to a folder or file to be deleted. This happens recursively to the path
+     * @param folder Path to a folder or file to be deleted. This happens recursively to the path
      * @throws IOException if an I/O error occurs
      */
     private void deleteCopiedFiles(File folder) throws IOException {

+ 5 - 6
jplag.endToEndTesting/src/main/java/de/jplag/end_to_end_testing/model/TestCaseModel.java

@@ -4,7 +4,6 @@ import java.util.ArrayList;
 import java.util.Arrays;
 
 import de.jplag.options.JPlagOptions;
-import de.jplag.options.LanguageOption;
 
 /**
  * Median class for trading the results and the paths used in the tests. Also the JPlagOptions used for a test run are
@@ -13,19 +12,19 @@ import de.jplag.options.LanguageOption;
 public class TestCaseModel {
 
     private JsonModel jsonModel;
-    private LanguageOption languageOption;
+    private String languageIdentifier;
     private String submissionFolderPath;
 
     /**
      * Constructor for creating the instance
      * @param submissionFolderPath path to the plagiarism folder structure to be tested using Jplag
      * @param jsonModel the parsed result model needed for the test to be able to match it later in the tests.
-     * @param languageOption the language selection in which the tests take place
+     * @param languageIdentifier the language selection in which the tests take place
      */
-    public TestCaseModel(String submissionFolderPath, JsonModel jsonModel, LanguageOption languageOption) {
+    public TestCaseModel(String submissionFolderPath, JsonModel jsonModel, String languageIdentifier) {
         this.submissionFolderPath = submissionFolderPath;
         this.jsonModel = jsonModel;
-        this.languageOption = languageOption;
+        this.languageIdentifier = languageIdentifier;
     }
 
     /**
@@ -41,6 +40,6 @@ public class TestCaseModel {
      * @return current JPlag options for the created object
      */
     public JPlagOptions getJPlagOptionsFromCurrentModel() {
-        return new JPlagOptions(new ArrayList<>(Arrays.asList(submissionFolderPath)), new ArrayList<>(), languageOption);
+        return new JPlagOptions(new ArrayList<>(Arrays.asList(submissionFolderPath)), new ArrayList<>(), languageIdentifier);
     }
 }

+ 2 - 2
jplag.endToEndTesting/src/test/java/de/jplag/end_to_end_testing/JavaEndToEndTest.java

@@ -20,7 +20,7 @@ import de.jplag.end_to_end_testing.constants.TestDirectoryConstants;
 import de.jplag.end_to_end_testing.helper.JPlagTestSuiteHelper;
 import de.jplag.end_to_end_testing.model.TestCaseModel;
 import de.jplag.exceptions.ExitException;
-import de.jplag.options.LanguageOption;
+import de.jplag.java.Language;
 
 /**
  * Main test class for end-to-end testing in the Java language. The test cases aim to detect changes in the detection of
@@ -34,7 +34,7 @@ class JavaEndToEndTest {
 
     @BeforeAll
     public void setUp() throws IOException {
-        jplagTestSuiteHelper = new JPlagTestSuiteHelper(LanguageOption.JAVA);
+        jplagTestSuiteHelper = new JPlagTestSuiteHelper(Language.IDENTIFIER);
         assertTrue(TestDirectoryConstants.BASE_PATH_TO_JAVA_RESOURCES_SORTALGO.toFile().exists(), "Could not find base directory!");
         assertTrue(TestDirectoryConstants.BASE_PATH_TO_JAVA_RESULT_JSON.toFile().isFile(), "Could not find java result json!");
     }

+ 3 - 0
jplag.frontend.golang/src/main/java/de/jplag/golang/Language.java

@@ -2,8 +2,11 @@ package de.jplag.golang;
 
 import java.io.File;
 
+import org.kohsuke.MetaInfServices;
+
 import de.jplag.TokenList;
 
+@MetaInfServices(de.jplag.Language.class)
 public class Language implements de.jplag.Language {
 
     private static final String NAME = "Go Parser";

+ 1 - 0
jplag.frontend.scala/src/main/resources/META-INF/services/de.jplag.Language

@@ -0,0 +1 @@
+de.jplag.scala.Language

+ 3 - 1
jplag.frontend.scala/src/main/scala/de/jplag/scala/Language.scala

@@ -4,6 +4,8 @@ import de.jplag.TokenList
 
 import java.io.File
 
+import org.kohsuke.MetaInfServices
+
 class Language extends de.jplag.Language {
   private val parser = new Parser
   private final val fileExtensions = Array(".scala", ".sc")
@@ -12,7 +14,7 @@ class Language extends de.jplag.Language {
 
   override def getName = "Scala parser"
 
-  override def getShortName = "scala"
+  override def getIdentifier = "scala"
 
   override def minimumTokenMatch = 8