Search in sources :

Example 6 with JavaMerger

use of com.devonfw.cobigen.javaplugin.merger.JavaMerger in project cobigen by devonfw.

the class JavaPluginActivator method bindMerger.

@Override
public List<Merger> bindMerger() {
    List<Merger> merger = Lists.newLinkedList();
    merger.add(new JavaMerger(JAVAMERGE, false));
    merger.add(new JavaMerger(JAVAMERGE_OVERRIDE, true));
    return merger;
}
Also used : Merger(com.devonfw.cobigen.api.extension.Merger) JavaMerger(com.devonfw.cobigen.javaplugin.merger.JavaMerger) JavaMerger(com.devonfw.cobigen.javaplugin.merger.JavaMerger)

Example 7 with JavaMerger

use of com.devonfw.cobigen.javaplugin.merger.JavaMerger in project cobigen by devonfw.

the class JavaMergerTest method testBaseLineEndings.

/**
 * Tests whether the output file contains line endings of base file (linux line endings)
 *
 * @throws IOException test fails
 * @throws MergeException test fails
 */
@Test
public void testBaseLineEndings() throws IOException, MergeException {
    File baseFile = new File(testFileRootPath + "BaseFile_Eol.java");
    File patchFile = new File(testFileRootPath + "PatchFile_Eol.java");
    File mergedFile = new File(testFileRootPath + "MergedFile_Eol.java");
    String expectedContent = FileUtils.readFileToString(mergedFile, StandardCharsets.UTF_8);
    String mergedContents = new JavaMerger("", false).merge(baseFile, FileUtils.readFileToString(patchFile, StandardCharsets.UTF_8), "UTF-8");
    assertThat(mergedContents).isEqualTo(expectedContent);
}
Also used : JavaMerger(com.devonfw.cobigen.javaplugin.merger.JavaMerger) File(java.io.File) Test(org.junit.Test)

Example 8 with JavaMerger

use of com.devonfw.cobigen.javaplugin.merger.JavaMerger in project cobigen by devonfw.

the class JavaMergerTest method testMergeMethodsWithoutExtendingMethodBodyWithWhitespaces.

/**
 * Tests merging java without adding new lines to method bodies (was a bug)
 *
 * @throws IOException test fails
 * @throws MergeException test fails
 */
@Test
public void testMergeMethodsWithoutExtendingMethodBodyWithWhitespaces() throws IOException, MergeException {
    File file = new File(testFileRootPath + "PatchFile_method.java");
    ClassLibraryBuilder classLibraryBuilder = new ModifyableClassLibraryBuilder();
    try (FileInputStream fileInputStream = new FileInputStream(file)) {
        JavaSource source = classLibraryBuilder.addSource(fileInputStream);
        JavaClass origClazz = source.getClasses().get(0);
        String mergedContents = new JavaMerger("", true).merge(file, FileUtils.readFileToString(file, Charset.forName("UTF-8")), "UTF-8");
        classLibraryBuilder = new ModifyableClassLibraryBuilder();
        try (StringReader stringReader = new StringReader(mergedContents)) {
            source = classLibraryBuilder.addSource(stringReader);
            JavaClass resultClazz = source.getClasses().get(0);
            for (JavaMethod method : resultClazz.getMethods()) {
                JavaMethod origMethod = origClazz.getMethodBySignature(method.getName(), method.getParameterTypes());
                assertThat(method.getCodeBlock()).isEqualTo(origMethod.getCodeBlock());
            }
        }
    }
}
Also used : JavaParserUtil.getFirstJavaClass(com.devonfw.cobigen.javaplugin.inputreader.JavaParserUtil.getFirstJavaClass) JavaClass(com.thoughtworks.qdox.model.JavaClass) ModifyableClassLibraryBuilder(com.devonfw.cobigen.javaplugin.merger.libextension.ModifyableClassLibraryBuilder) ClassLibraryBuilder(com.thoughtworks.qdox.library.ClassLibraryBuilder) JavaMerger(com.devonfw.cobigen.javaplugin.merger.JavaMerger) JavaSource(com.thoughtworks.qdox.model.JavaSource) StringReader(java.io.StringReader) JavaMethod(com.thoughtworks.qdox.model.JavaMethod) ModifyableClassLibraryBuilder(com.devonfw.cobigen.javaplugin.merger.libextension.ModifyableClassLibraryBuilder) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 9 with JavaMerger

use of com.devonfw.cobigen.javaplugin.merger.JavaMerger in project cobigen by devonfw.

the class JavaMergerTest method testMergeWithGenerics.

/**
 * Tests whether all generics of the original file will be existent after merging
 *
 * @throws IOException test fails
 * @throws MergeException test fails
 * @author mbrunnli (17.06.2013)
 */
@Test
public void testMergeWithGenerics() throws IOException, MergeException {
    File baseFile = new File(testFileRootPath + "BaseFile_generics.java");
    File patchFile = new File(testFileRootPath + "PatchFile_generics.java");
    String mergedContents = new JavaMerger("", false).merge(baseFile, FileUtils.readFileToString(patchFile, StandardCharsets.UTF_8), "UTF-8");
    assertThat(mergedContents).contains("class Clazz<T extends Object>");
    assertThat(mergedContents).contains("Map<String,T>");
    assertThat(mergedContents).contains("private T t;");
    assertThat(mergedContents).contains("public T get()");
    assertThat(mergedContents).contains("public <U extends Number> void inspect(U u)");
}
Also used : JavaMerger(com.devonfw.cobigen.javaplugin.merger.JavaMerger) File(java.io.File) Test(org.junit.Test)

Example 10 with JavaMerger

use of com.devonfw.cobigen.javaplugin.merger.JavaMerger in project cobigen by devonfw.

the class JavaMergerTest method testMergeInterfacesWithoutSuperClass.

/**
 * Tests whether two interfaces without a super class are getting merged
 * https://github.com/devonfw/cobigen/issues/1439
 *
 * @throws IOException shouldn't happen
 * @throws MergeException shouldn't happen either
 */
@Test
public void testMergeInterfacesWithoutSuperClass() throws IOException, MergeException {
    File baseFile = new File(testFileRootPath + "BaseFile_InterfaceWOSuperClass.java");
    File patchFile = new File(testFileRootPath + "PatchFile_InterfaceWOSuperClass.java");
    String mergedContents = new JavaMerger("", true).merge(baseFile, FileUtils.readFileToString(patchFile, StandardCharsets.UTF_8), "UTF-8");
    assertThat(mergedContents).contains("public void testMethod();");
    assertThat(mergedContents).contains("public void anotherTestMethod();");
}
Also used : JavaMerger(com.devonfw.cobigen.javaplugin.merger.JavaMerger) File(java.io.File) Test(org.junit.Test)

Aggregations

JavaMerger (com.devonfw.cobigen.javaplugin.merger.JavaMerger)11 File (java.io.File)10 Test (org.junit.Test)10 StringReader (java.io.StringReader)3 JavaParserUtil.getFirstJavaClass (com.devonfw.cobigen.javaplugin.inputreader.JavaParserUtil.getFirstJavaClass)2 JavaClass (com.thoughtworks.qdox.model.JavaClass)2 JavaSource (com.thoughtworks.qdox.model.JavaSource)2 Merger (com.devonfw.cobigen.api.extension.Merger)1 ModifyableClassLibraryBuilder (com.devonfw.cobigen.javaplugin.merger.libextension.ModifyableClassLibraryBuilder)1 ClassLibraryBuilder (com.thoughtworks.qdox.library.ClassLibraryBuilder)1 JavaMethod (com.thoughtworks.qdox.model.JavaMethod)1 FileInputStream (java.io.FileInputStream)1 FileReader (java.io.FileReader)1