Search in sources :

Example 1 with Merger

use of com.devonfw.cobigen.api.extension.Merger 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 2 with Merger

use of com.devonfw.cobigen.api.extension.Merger in project cobigen by devonfw.

the class XmlPluginActivator method bindMerger.

@Override
public List<Merger> bindMerger() {
    List<Merger> merger = Lists.newLinkedList();
    merger.add(new XmlMergerDelegate(defaultMergeSchemaLocation, MergeType.BASEOVERWRITE, false));
    merger.add(new XmlMergerDelegate(defaultMergeSchemaLocation, MergeType.BASEATTACHOROVERWRITE, false));
    merger.add(new XmlMergerDelegate(defaultMergeSchemaLocation, MergeType.PATCHOVERWRITE, false));
    merger.add(new XmlMergerDelegate(defaultMergeSchemaLocation, MergeType.PATCHATTACHOROVERWRITE, false));
    // mergers with validation enabled
    merger.add(new XmlMergerDelegate(defaultMergeSchemaLocation, MergeType.BASEOVERWRITEVALIDATE, true));
    merger.add(new XmlMergerDelegate(defaultMergeSchemaLocation, MergeType.BASEATTACHOROVERWRITEVALIDATE, true));
    merger.add(new XmlMergerDelegate(defaultMergeSchemaLocation, MergeType.PATCHOVERWRITEVALIDATE, true));
    merger.add(new XmlMergerDelegate(defaultMergeSchemaLocation, MergeType.PATCHATTACHOROVERWRITEVALIDATE, true));
    mergerList = merger;
    return merger;
}
Also used : Merger(com.devonfw.cobigen.api.extension.Merger) XmlMergerDelegate(com.devonfw.cobigen.xmlplugin.merger.delegates.XmlMergerDelegate)

Example 3 with Merger

use of com.devonfw.cobigen.api.extension.Merger in project cobigen by devonfw.

the class TypeScriptMergerTest method testNullAndUndefinedTypes.

/**
 * Tests if TypeScript can handle null- and undefined-aware types
 */
@Test
public void testNullAndUndefinedTypes() {
    Merger tsMerger = this.activator.bindMerger().stream().filter(e -> e.getType().equals(TypeScriptPluginActivator.TSMERGE)).findFirst().get();
    File baseFile = new File(testFileRootPath + "nullBase.ts");
    String mergedContents = tsMerger.merge(baseFile, readTSFile("nullPatch.ts"), "UTF-8");
    assertEquals(false, mergedContents.contains("Not able to merge") || mergedContents.isEmpty());
}
Also used : Merger(com.devonfw.cobigen.api.extension.Merger) File(java.io.File) Test(org.junit.Test)

Example 4 with Merger

use of com.devonfw.cobigen.api.extension.Merger in project cobigen by devonfw.

the class TypeScriptMergerTest method testReadingEncoding.

/**
 * Tests whether the contents will be rewritten after parsing and printing with the right encoding
 *
 * @throws IOException test fails
 */
@Test
public void testReadingEncoding() throws IOException {
    // Arrange
    Merger tsMerger = this.activator.bindMerger().stream().filter(e -> e.getType().equals(TypeScriptPluginActivator.TSMERGE)).findFirst().get();
    File baseFile = new File(testFileRootPath + "baseFile_encoding_UTF-8.ts");
    File patchFile = new File(testFileRootPath + "patchFile.ts");
    String mergedContents = tsMerger.merge(baseFile, FileUtils.readFileToString(patchFile), "UTF-8");
    assertThat(mergedContents.contains("Ñ")).isTrue();
    baseFile = new File(testFileRootPath + "baseFile_encoding_ISO-8859-1.ts");
    mergedContents = "";
    assertThat(mergedContents.contains("Ñ"));
}
Also used : Merger(com.devonfw.cobigen.api.extension.Merger) File(java.io.File) Test(org.junit.Test)

Example 5 with Merger

use of com.devonfw.cobigen.api.extension.Merger in project cobigen by devonfw.

the class TypeScriptMergerTest method testMergingOverrides.

/**
 * Checks if the ts-merger can be launched and if the output is correct with patchOverrides = true
 */
@Test
public void testMergingOverrides() {
    // arrange
    Merger tsMerger = this.activator.bindMerger().stream().filter(e -> e.getType().equals(TypeScriptPluginActivator.TSMERGE_OVERRIDE)).findFirst().get();
    File baseFile = new File(testFileRootPath + "baseFile.ts");
    // act
    String mergedContents = tsMerger.merge(baseFile, readTSFile("patchFile.ts"), "UTF-8");
    assertThat(mergedContents).contains("bProperty");
    assertThat(mergedContents).contains("aProperty: number = 3");
    assertThat(mergedContents).contains("bMethod");
    assertThat(mergedContents).contains("aMethod");
    assertThat(mergedContents).contains("bProperty");
    assertThat(mergedContents).contains("import { c, f } from 'd'");
    assertThat(mergedContents).contains("import { a, e } from 'b'");
    assertThat(mergedContents).contains("export { e, g } from 'f';");
    assertThat(mergedContents).contains("interface a {");
    assertThat(mergedContents).contains("private b: string;");
    // Should merge comments
    assertThat(mergedContents).contains("// Should contain this comment");
    mergedContents = tsMerger.merge(baseFile, readTSFile("patchFile.ts"), "ISO-8859-1");
    assertThat(mergedContents).contains("aProperty: number = 3");
    assertThat(mergedContents).contains("bProperty");
    assertThat(mergedContents).contains("bMethod");
    assertThat(mergedContents).contains("aMethod");
    assertThat(mergedContents).contains("bProperty");
    assertThat(mergedContents).contains("import { c, f } from 'd'");
    assertThat(mergedContents).contains("import { a, e } from 'b'");
    assertThat(mergedContents).contains("export { e, g } from 'f';");
    assertThat(mergedContents).contains("interface a {");
    assertThat(mergedContents).contains("private b: string;");
    // Should merge comments
    assertThat(mergedContents).contains("// Should contain this comment");
}
Also used : Merger(com.devonfw.cobigen.api.extension.Merger) File(java.io.File) Test(org.junit.Test)

Aggregations

Merger (com.devonfw.cobigen.api.extension.Merger)14 File (java.io.File)7 Test (org.junit.Test)6 CobiGenRuntimeException (com.devonfw.cobigen.api.exception.CobiGenRuntimeException)2 Activation (com.devonfw.cobigen.api.annotation.Activation)1 MergeException (com.devonfw.cobigen.api.exception.MergeException)1 PluginNotAvailableException (com.devonfw.cobigen.api.exception.PluginNotAvailableException)1 GeneratorPluginActivator (com.devonfw.cobigen.api.extension.GeneratorPluginActivator)1 InputReader (com.devonfw.cobigen.api.extension.InputReader)1 TextTemplateEngine (com.devonfw.cobigen.api.extension.TextTemplateEngine)1 TriggerInterpreter (com.devonfw.cobigen.api.extension.TriggerInterpreter)1 AngularMerger (com.devonfw.cobigen.htmlplugin.merger.AngularMerger)1 TemplatesConfiguration (com.devonfw.cobigen.impl.config.TemplatesConfiguration)1 Template (com.devonfw.cobigen.impl.config.entity.Template)1 Trigger (com.devonfw.cobigen.impl.config.entity.Trigger)1 PathExpressionResolver (com.devonfw.cobigen.impl.config.resolver.PathExpressionResolver)1 PluginProcessingException (com.devonfw.cobigen.impl.exceptions.PluginProcessingException)1 UnknownTemplateException (com.devonfw.cobigen.impl.exceptions.UnknownTemplateException)1 JavaMerger (com.devonfw.cobigen.javaplugin.merger.JavaMerger)1 JSONMerger (com.devonfw.cobigen.jsonplugin.merger.JSONMerger)1