diff --git a/cobigen/cobigen-javaplugin-parent/cobigen-javaplugin-model/pom.xml b/cobigen/cobigen-javaplugin-parent/cobigen-javaplugin-model/pom.xml index 98b6ea92d1..2f439307b5 100644 --- a/cobigen/cobigen-javaplugin-parent/cobigen-javaplugin-model/pom.xml +++ b/cobigen/cobigen-javaplugin-parent/cobigen-javaplugin-model/pom.xml @@ -1,7 +1,7 @@ 4.0.0 javaplugin-model - 2.2.3 + 7.0.0 CobiGen Javaplugin Model jar CobiGen - Java Plug-in Model diff --git a/cobigen/cobigen-javaplugin-parent/cobigen-javaplugin/pom.xml b/cobigen/cobigen-javaplugin-parent/cobigen-javaplugin/pom.xml index 05492cfcf8..78e11a6128 100644 --- a/cobigen/cobigen-javaplugin-parent/cobigen-javaplugin/pom.xml +++ b/cobigen/cobigen-javaplugin-parent/cobigen-javaplugin/pom.xml @@ -2,7 +2,7 @@ 4.0.0 javaplugin CobiGen - Java Plug-in - 2.2.3 + 7.0.0 jar CobiGen - Java Plug-in @@ -27,7 +27,7 @@ ${project.groupId} core-api - 6.1.0 + 7.0.0 @@ -39,19 +39,19 @@ ${project.groupId} core-test - 6.1.0 + 7.0.0 test ${project.groupId} core - 6.1.0 + 7.0.0 test ${project.groupId} tempeng-freemarker - 2.0.0 + [7.0.0-SNAPSHOT,) test diff --git a/cobigen/cobigen-javaplugin-parent/cobigen-javaplugin/src/main/java/com/devonfw/cobigen/javaplugin/JavaPluginActivator.java b/cobigen/cobigen-javaplugin-parent/cobigen-javaplugin/src/main/java/com/devonfw/cobigen/javaplugin/JavaPluginActivator.java index 2184ce01ab..bc20eb4ff5 100644 --- a/cobigen/cobigen-javaplugin-parent/cobigen-javaplugin/src/main/java/com/devonfw/cobigen/javaplugin/JavaPluginActivator.java +++ b/cobigen/cobigen-javaplugin-parent/cobigen-javaplugin/src/main/java/com/devonfw/cobigen/javaplugin/JavaPluginActivator.java @@ -2,20 +2,30 @@ import java.util.List; +import com.devonfw.cobigen.api.annotation.Activation; import com.devonfw.cobigen.api.extension.GeneratorPluginActivator; import com.devonfw.cobigen.api.extension.Merger; import com.devonfw.cobigen.api.extension.TriggerInterpreter; +import com.devonfw.cobigen.javaplugin.inputreader.JavaInputReader; import com.devonfw.cobigen.javaplugin.merger.JavaMerger; import com.google.common.collect.Lists; /** Plug-in activator to be registered to the PluginRegistry of CobiGen by any client. */ +@Activation(byFileExtension = { JavaInputReader.VALID_EXTENSION }, + byMergeStrategy = { JavaPluginActivator.JAVAMERGE, JavaPluginActivator.JAVAMERGE_OVERRIDE }, byFolder = true) public class JavaPluginActivator implements GeneratorPluginActivator { + /** Merge Strategy name for simple java merging (prefer patch) */ + static final String JAVAMERGE_OVERRIDE = "javamerge_override"; + + /** Merge Strategy name for simple java merging (prefer base) */ + static final String JAVAMERGE = "javamerge"; + @Override public List bindMerger() { List merger = Lists.newLinkedList(); - merger.add(new JavaMerger("javamerge", false)); - merger.add(new JavaMerger("javamerge_override", true)); + merger.add(new JavaMerger(JAVAMERGE, false)); + merger.add(new JavaMerger(JAVAMERGE_OVERRIDE, true)); return merger; } diff --git a/cobigen/cobigen-javaplugin-parent/cobigen-javaplugin/src/main/java/com/devonfw/cobigen/javaplugin/JavaTriggerInterpreter.java b/cobigen/cobigen-javaplugin-parent/cobigen-javaplugin/src/main/java/com/devonfw/cobigen/javaplugin/JavaTriggerInterpreter.java index b3418d8b38..84bd37ce35 100644 --- a/cobigen/cobigen-javaplugin-parent/cobigen-javaplugin/src/main/java/com/devonfw/cobigen/javaplugin/JavaTriggerInterpreter.java +++ b/cobigen/cobigen-javaplugin-parent/cobigen-javaplugin/src/main/java/com/devonfw/cobigen/javaplugin/JavaTriggerInterpreter.java @@ -1,12 +1,15 @@ package com.devonfw.cobigen.javaplugin; +import com.devonfw.cobigen.api.annotation.ReaderPriority; import com.devonfw.cobigen.api.extension.InputReader; import com.devonfw.cobigen.api.extension.MatcherInterpreter; +import com.devonfw.cobigen.api.extension.Priority; import com.devonfw.cobigen.api.extension.TriggerInterpreter; import com.devonfw.cobigen.javaplugin.inputreader.JavaInputReader; import com.devonfw.cobigen.javaplugin.matcher.JavaMatcher; /** {@link TriggerInterpreter} implementation of a Java Interpreter */ +@ReaderPriority(Priority.LOW) public class JavaTriggerInterpreter implements TriggerInterpreter { /** {@link TriggerInterpreter} type to be registered */ diff --git a/cobigen/cobigen-javaplugin-parent/cobigen-javaplugin/src/main/java/com/devonfw/cobigen/javaplugin/inputreader/JavaInputReader.java b/cobigen/cobigen-javaplugin-parent/cobigen-javaplugin/src/main/java/com/devonfw/cobigen/javaplugin/inputreader/JavaInputReader.java index 100300135f..ca18a29cc0 100644 --- a/cobigen/cobigen-javaplugin-parent/cobigen-javaplugin/src/main/java/com/devonfw/cobigen/javaplugin/inputreader/JavaInputReader.java +++ b/cobigen/cobigen-javaplugin-parent/cobigen-javaplugin/src/main/java/com/devonfw/cobigen/javaplugin/inputreader/JavaInputReader.java @@ -40,6 +40,9 @@ */ public class JavaInputReader implements InputReader { + /** Valid file extension for the reader */ + public static final String VALID_EXTENSION = "java"; + /** Logger instance */ private static final Logger LOG = LoggerFactory.getLogger(JavaInputReader.class); @@ -473,9 +476,8 @@ public Object read(Path path, Charset inputCharset, Object... additionalArgument @Override public boolean isMostLikelyReadable(Path path) { - String validExtension = "java"; String fileExtension = FilenameUtils.getExtension(path.toString()).toLowerCase(); - return validExtension.equals(fileExtension) || Files.isDirectory(path); + return VALID_EXTENSION.equals(fileExtension) || Files.isDirectory(path); } /** diff --git a/cobigen/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/java/com/devonfw/cobigen/javaplugin/integrationtest/AnnotationQueryingTest.java b/cobigen/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/java/com/devonfw/cobigen/javaplugin/integrationtest/AnnotationQueryingTest.java index 2a2d0cbf78..40661874a7 100644 --- a/cobigen/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/java/com/devonfw/cobigen/javaplugin/integrationtest/AnnotationQueryingTest.java +++ b/cobigen/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/java/com/devonfw/cobigen/javaplugin/integrationtest/AnnotationQueryingTest.java @@ -4,7 +4,7 @@ import static org.assertj.core.api.Assertions.assertThat; import java.io.File; -import java.io.FileReader; +import java.nio.charset.Charset; import java.nio.file.Paths; import java.util.List; @@ -15,9 +15,7 @@ import com.devonfw.cobigen.api.to.GenerationReportTo; import com.devonfw.cobigen.api.to.TemplateTo; import com.devonfw.cobigen.impl.CobiGenFactory; -import com.devonfw.cobigen.javaplugin.inputreader.JavaParserUtil; import com.devonfw.cobigen.javaplugin.integrationtest.common.AbstractIntegrationTest; -import com.devonfw.cobigen.javaplugin.unittest.inputreader.testdata.TestClassWithAnnotationsContainingObjectArrays; import junit.framework.AssertionFailedError; @@ -36,10 +34,10 @@ public void testAnnotationWithObjectArraysAsValues() throws Exception { CobiGen cobiGen = CobiGenFactory.create(cobigenConfigFolder.toURI()); File tmpFolderCobiGen = tmpFolder.newFolder("cobigen_output"); - String testFileRootPath = "src/test/resources/testdata/unittest/inputreader/"; - File javaSourceFile = new File(testFileRootPath + "TestClassWithAnnotationsContainingObjectArrays.java"); - Object[] input = new Object[] { JavaParserUtil.getFirstJavaClass(new FileReader(javaSourceFile)), - TestClassWithAnnotationsContainingObjectArrays.class }; + Object input = cobiGen.read(new File( + "src/test/resources/testdata/unittest/inputreader/TestClassWithAnnotationsContainingObjectArrays.java") + .toPath(), + Charset.forName("UTF-8"), getClass().getClassLoader()); List templates = cobiGen.getMatchingTemplates(input); boolean methodTemplateFound = false; diff --git a/cobigen/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/java/com/devonfw/cobigen/javaplugin/integrationtest/ModelCreationTest.java b/cobigen/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/java/com/devonfw/cobigen/javaplugin/integrationtest/ModelCreationTest.java index 0c98418510..16bff419ea 100644 --- a/cobigen/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/java/com/devonfw/cobigen/javaplugin/integrationtest/ModelCreationTest.java +++ b/cobigen/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/java/com/devonfw/cobigen/javaplugin/integrationtest/ModelCreationTest.java @@ -4,7 +4,7 @@ import static org.assertj.core.api.Assertions.assertThat; import java.io.File; -import java.io.FileReader; +import java.nio.charset.Charset; import java.nio.file.Paths; import java.util.List; @@ -15,7 +15,6 @@ import com.devonfw.cobigen.api.to.GenerationReportTo; import com.devonfw.cobigen.api.to.TemplateTo; import com.devonfw.cobigen.impl.CobiGenFactory; -import com.devonfw.cobigen.javaplugin.inputreader.JavaParserUtil; import com.devonfw.cobigen.javaplugin.integrationtest.common.AbstractIntegrationTest; import junit.framework.AssertionFailedError; @@ -43,9 +42,9 @@ public void testCorrectGenericTypeExtraction() throws Exception { CobiGen cobiGen = CobiGenFactory.create(cobigenConfigFolder.toURI()); File tmpFolderCobiGen = tmpFolder.newFolder("cobigen_output"); - Object[] input = new Object[] { this.getClass(), - JavaParserUtil.getFirstJavaClass(getClass().getClassLoader(), new FileReader( - new File("src/test/resources/testdata/integrationtest/javaSources/ModelCreationTest.java"))) }; + Object input = cobiGen.read( + new File("src/test/resources/testdata/integrationtest/javaSources/ModelCreationTest.java").toPath(), + Charset.forName("UTF-8"), getClass().getClassLoader()); List templates = cobiGen.getMatchingTemplates(input); boolean methodTemplateFound = false; @@ -78,9 +77,9 @@ public void testCorrectAnnotationValueExtraction() throws Exception { CobiGen cobiGen = CobiGenFactory.create(cobigenConfigFolder.toURI()); File tmpFolderCobiGen = tmpFolder.newFolder("cobigen_output"); - Object[] input = new Object[] { this.getClass(), - JavaParserUtil.getFirstJavaClass(getClass().getClassLoader(), new FileReader( - new File("src/test/resources/testdata/integrationtest/javaSources/ModelCreationTest.java"))) }; + Object input = cobiGen.read( + new File("src/test/resources/testdata/integrationtest/javaSources/ModelCreationTest.java").toPath(), + Charset.forName("UTF-8"), getClass().getClassLoader()); List templates = cobiGen.getMatchingTemplates(input); boolean methodTemplateFound = false; diff --git a/cobigen/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/java/com/devonfw/cobigen/javaplugin/integrationtest/VariablesResolutionTest.java b/cobigen/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/java/com/devonfw/cobigen/javaplugin/integrationtest/VariablesResolutionTest.java index 35b1702a51..1176d6065a 100644 --- a/cobigen/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/java/com/devonfw/cobigen/javaplugin/integrationtest/VariablesResolutionTest.java +++ b/cobigen/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/java/com/devonfw/cobigen/javaplugin/integrationtest/VariablesResolutionTest.java @@ -3,7 +3,7 @@ import static com.devonfw.cobigen.test.assertj.CobiGenAsserts.assertThat; import java.io.File; -import java.io.FileReader; +import java.nio.charset.Charset; import java.nio.file.Paths; import java.util.List; @@ -13,9 +13,7 @@ import com.devonfw.cobigen.api.to.GenerationReportTo; import com.devonfw.cobigen.api.to.TemplateTo; import com.devonfw.cobigen.impl.CobiGenFactory; -import com.devonfw.cobigen.javaplugin.inputreader.JavaParserUtil; import com.devonfw.cobigen.javaplugin.integrationtest.common.AbstractIntegrationTest; -import com.thoughtworks.qdox.model.JavaClass; import junit.framework.AssertionFailedError; @@ -39,8 +37,9 @@ public void testSuccessfulPathResolution_variableEqNull() throws Exception { CobiGen cobiGen = CobiGenFactory.create(cobigenConfigFolder.toURI()); File tmpFolderCobiGen = tmpFolder.newFolder("cobigen_output"); - JavaClass input = JavaParserUtil.getFirstJavaClass( - new FileReader(new File("src/test/resources/testdata/integrationtest/javaSources/SampleEntity.java"))); + Object input = + cobiGen.read(new File("src/test/resources/testdata/integrationtest/javaSources/SampleEntity.java").toPath(), + Charset.forName("UTF-8")); List templates = cobiGen.getMatchingTemplates(input); boolean methodTemplateFound = false; diff --git a/documentation/master-cobigen.asciidoc b/documentation/master-cobigen.asciidoc index cba5025c6a..f2fac2da6f 100644 --- a/documentation/master-cobigen.asciidoc +++ b/documentation/master-cobigen.asciidoc @@ -18,7 +18,7 @@ DISCLAIMER: All Cobigen plugins are compatible with the latest release of Devonf --- * CobiGen v7.0.0 -* CobiGen - Java Plug-in v2.2.3 +* CobiGen - Java Plug-in v7.0.0 * CobiGen - XML Plug-in v4.2.0 * CobiGen - TypeScript Plug-in v2.4.4 * CobiGen - Property Plug-in v2.1.0