Skip to content

Commit

Permalink
#1231 Merge branch 'dev_javaplugin' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
maybeec committed Sep 14, 2020
2 parents 1b72d08 + 039ba42 commit 495fe52
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<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>
<artifactId>javaplugin-model</artifactId>
<version>2.2.3</version>
<version>7.0.0</version>
<name>CobiGen Javaplugin Model</name>
<packaging>jar</packaging>
<description>CobiGen - Java Plug-in Model</description>
Expand Down
10 changes: 5 additions & 5 deletions cobigen/cobigen-javaplugin-parent/cobigen-javaplugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>javaplugin</artifactId>
<name>CobiGen - Java Plug-in</name>
<version>2.2.3</version>
<version>7.0.0</version>
<packaging>jar</packaging>
<description>CobiGen - Java Plug-in</description>

Expand All @@ -27,7 +27,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>core-api</artifactId>
<version>6.1.0</version>
<version>7.0.0</version>
</dependency>

<dependency>
Expand All @@ -39,19 +39,19 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>core-test</artifactId>
<version>6.1.0</version>
<version>7.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>core</artifactId>
<version>6.1.0</version>
<version>7.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>tempeng-freemarker</artifactId>
<version>2.0.0</version>
<version>[7.0.0-SNAPSHOT,)</version>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Merger> bindMerger() {
List<Merger> 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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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<TemplateTo> templates = cobiGen.getMatchingTemplates(input);

boolean methodTemplateFound = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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<TemplateTo> templates = cobiGen.getMatchingTemplates(input);

boolean methodTemplateFound = false;
Expand Down Expand Up @@ -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<TemplateTo> templates = cobiGen.getMatchingTemplates(input);

boolean methodTemplateFound = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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<TemplateTo> templates = cobiGen.getMatchingTemplates(input);

boolean methodTemplateFound = false;
Expand Down
2 changes: 1 addition & 1 deletion documentation/master-cobigen.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 495fe52

Please sign in to comment.