Skip to content

Commit

Permalink
Merge branch 'dev_xmlplugin' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
maybeec committed Sep 14, 2020
2 parents 1530464 + 58b00f7 commit d269336
Show file tree
Hide file tree
Showing 29 changed files with 26,498 additions and 103 deletions.
14 changes: 7 additions & 7 deletions cobigen/cobigen-xmlplugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>xmlplugin</artifactId>
<name>CobiGen - XML Plug-In</name>
<version>4.2.0</version>
<version>7.0.0</version>
<packaging>jar</packaging>
<description>CobiGen - XML Plug-In</description>

Expand All @@ -21,18 +21,18 @@
<dependency>
<groupId>com.devonfw.cobigen</groupId>
<artifactId>core-api</artifactId>
<version>5.3.0</version>
<version>[7.0.0,)</version>
</dependency>
<dependency>
<artifactId>lexeme</artifactId>
<groupId>com.github.maybeec</groupId>
<version>1.0.0</version>
<artifactId>lexeme</artifactId>
<version>1.1.0</version>
</dependency>

<dependency>
<groupId>com.devonfw.cobigen</groupId>
<artifactId>core-test</artifactId>
<version>6.0.0</version>
<version>7.0.0</version>
<scope>test</scope>
</dependency>

Expand All @@ -47,13 +47,13 @@
<dependency>
<groupId>com.devonfw.cobigen</groupId>
<artifactId>core</artifactId>
<version>6.0.0</version>
<version>7.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.devonfw.cobigen</groupId>
<artifactId>tempeng-freemarker</artifactId>
<version>2.0.0</version>
<version>7.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.devonfw.cobigen.xmlplugin;

import java.nio.file.Path;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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;
Expand All @@ -12,21 +17,37 @@
/**
* Plug-in activator to be detected by CobiGen's service loader lookup.
*/
@Activation(byMergeStrategy = { "xmlmerge_override", "xmlmerge", "xmlmerge_attachTexts",
"xmlmerge_override_attachTexts", "xmlmerge_override_validate", "xmlmerge_validate", "xmlmerge_attachTexts_validate",
"xmlmerge_override_attachTexts_validate" }, byFileExtension = { "xml", "xmi" })
public class XmlPluginActivator implements GeneratorPluginActivator {

/**
* defining the default location of the merge schemas
*/
static private String defaultMergeSchemaLocation = "src/main/resources/mergeSchemas";

/** Static Logger instance */
private static final Logger LOG = LoggerFactory.getLogger(XmlPluginActivator.class);

/**
* List of mergers to update
*/
private static List<Merger> mergerList = Lists.newLinkedList();

@Override
public List<Merger> bindMerger() {
List<Merger> merger = Lists.newLinkedList();

merger.add(new XmlMergerDelegate(defaultMergeSchemaLocation, MergeType.BASEOVERWRITE));
merger.add(new XmlMergerDelegate(defaultMergeSchemaLocation, MergeType.BASEATTACHOROVERWRITE));
merger.add(new XmlMergerDelegate(defaultMergeSchemaLocation, MergeType.PATCHOVERWRITE));
merger.add(new XmlMergerDelegate(defaultMergeSchemaLocation, MergeType.PATCHATTACHOROVERWRITE));
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;
}

Expand All @@ -35,4 +56,14 @@ public List<TriggerInterpreter> bindTriggerInterpreter() {
return Lists.<TriggerInterpreter> newArrayList(new XmlTriggerInterpreter("xml"));
}

@Override
public void setProjectRoot(Path path) {
LOG.debug("updated project root path {}", path);
for (Merger merger : mergerList) {
if (merger instanceof XmlMergerDelegate) {
((XmlMergerDelegate) merger).updateMergeSchemaPath(path);
}
}
}

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package com.devonfw.cobigen.xmlplugin;

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.xmlplugin.inputreader.XmlInputReader;
import com.devonfw.cobigen.xmlplugin.matcher.XmlMatcher;

/**
* {@link TriggerInterpreter} implementation of a Xml Interpreter
*/
@ReaderPriority(Priority.LOW)
public class XmlTriggerInterpreter implements TriggerInterpreter {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,26 @@ public enum MergeType {
* In case of a conflict the patch document is preferred. Attributes and text nodes will be attached where
* possible
*/
PATCHATTACHOROVERWRITE("xmlmerge_override_attachTexts", ConflictHandlingType.PATCHATTACHOROVERWRITE);
PATCHATTACHOROVERWRITE("xmlmerge_override_attachTexts", ConflictHandlingType.PATCHATTACHOROVERWRITE),
/**
* In case of a conflict the patch document is preferred. Validation will be enabled.
*/
PATCHOVERWRITEVALIDATE("xmlmerge_override_validate", ConflictHandlingType.PATCHOVERWRITEVALIDATE),
/**
* In case of a conflict the base document is preferred. Validation will be enabled.
*/
BASEOVERWRITEVALIDATE("xmlmerge_validate", ConflictHandlingType.BASEOVERWRITEVALIDATE),
/**
* In case of a conflict the base document is preferred. Attributes and text nodes will be attached where
* possible. Validation will be enabled.
*/
BASEATTACHOROVERWRITEVALIDATE("xmlmerge_attachTexts_validate", ConflictHandlingType.BASEATTACHOROVERWRITEVALIDATE),
/**
* In case of a conflict the patch document is preferred. Attributes and text nodes will be attached where
* possible. Validation will be enabled.
*/
PATCHATTACHOROVERWRITEVALIDATE("xmlmerge_override_attachTexts_validate",
ConflictHandlingType.PATCHATTACHOROVERWRITEVALIDATE);

/**
* The ConflictHandlingType
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package com.devonfw.cobigen.xmlplugin.merger.delegates;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.devonfw.cobigen.api.constants.ConfigurationConstants;
import com.devonfw.cobigen.api.exception.MergeException;
import com.devonfw.cobigen.api.extension.Merger;
import com.github.maybeec.lexeme.LeXeMerger;
Expand All @@ -20,30 +25,73 @@ public class XmlMergerDelegate implements Merger {
/** {@link LeXeMerger} instance to be used. */
private LeXeMerger merger;

/**
* Path to merge schema files
*/
private Path mergeSchemaPath;

/**
* Required to pass validation state to new LeXeMerger if path to root template was changed
*/
private boolean validationEnabled = false;

private static final Logger LOG = LoggerFactory.getLogger(XmlMergerDelegate.class);

/**
*
* @param mergeSchemaLocation
* path to the folder containing the merge schemas to be used
* String of a path to the folder containing the merge schemas to be used
* @param mergeType
* the way how conflicts will be handled
* @param validate
* use validator
* @author sholzer (Aug 27, 2015)
*/
public XmlMergerDelegate(String mergeSchemaLocation, MergeType mergeType) {
public XmlMergerDelegate(String mergeSchemaLocation, MergeType mergeType, Boolean validate) {
this.mergeType = mergeType;

merger = new LeXeMerger(mergeSchemaLocation);
setValidation(validate);
validationEnabled = validate;
}

/**
*
* @param mergeSchemaLocation
* path to the folder containing the merge schemas to be used
* Path to the folder containing the merge schemas to be used
* @param mergeType
* the way how conflicts will be handled
* @param validate
* use validator
* @author sholzer (Aug 27, 2015)
*/
public XmlMergerDelegate(Path mergeSchemaLocation, MergeType mergeType) {
public XmlMergerDelegate(Path mergeSchemaLocation, MergeType mergeType, Boolean validate) {
this.mergeType = mergeType;

merger = new LeXeMerger(mergeSchemaLocation);
setValidation(validate);
validationEnabled = validate;
}

/**
* Updates path of merge schema location with new template root path
*
* @param path
* Path to resolve with MERGE_SCHEMA_RESOURCE_FOLDER path
*/
public void updateMergeSchemaPath(Path path) {
if (path != null) {
Path newMergeSchemaPath = path.resolve(ConfigurationConstants.MERGE_SCHEMA_RESOURCE_FOLDER);
if (Files.exists(newMergeSchemaPath)) {
mergeSchemaPath = newMergeSchemaPath;
merger = new LeXeMerger(mergeSchemaPath);
setValidation(validationEnabled);
} else {
mergeSchemaPath = null;
}
} else {
throw new IllegalArgumentException("rootPath path cannot be null.");
}
}

@Override
Expand All @@ -63,7 +111,7 @@ public String merge(File base, String patch, String targetCharset) throws MergeE
/**
* Sets the validation flag
* @param validation
* true if a validation is desired. false otherwise. Default is true
* true if a validation is desired. false otherwise. Default is false
* @author sholzer (Sep 1, 2015)
*/
public void setValidation(boolean validation) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<ms:merge-schema for="" xmlns:ms="http://maybeec.github.io/lexeme/mergeschema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maybeec.github.io/lexeme/mergeschema ../../../../../lexeme/src/main/resources/xsd/MergeSchema.xsd ">
<ms:definition namespace="http://java.sun.com/jsf/html"/>

<!-- Incomplete and dependent MergeSchema. The namespace http://java.sun.com/jsf/core needs to use the prefix 'f' -->

<ms:definition location="src/main/resources/mergeSchemas/xsd/myfaces_facelets_html_2_2.xsd" type="xsd" namespace="http://xmlns.jcp.org/jsf/html">
<ms:additional-namespace location="src/main/resources/mergeSchemas/xsd/html-basic-2.0.xsd" namespace="http://java.sun.com/jsf/html"/>
</ms:definition>

<!-- Incomplete and dependent MergeSchema. The namespace http://java.sun.com/jsf/core needs to use the prefix 'f' -->

<ms:handling for="dataTable"><ms:criterion xpath="./@id"/></ms:handling>
<ms:handling for="column"><ms:criterion xpath="./*[namespace-uri()='http://java.sun.com/jsf/core' and local-name()='facet' and @name='header']/text()"/></ms:handling>
<ms:handling for="define"><ms:criterion xpath="./@name"/></ms:handling>
<ms:handling for="include"><ms:criterion xpath="./@src"/></ms:handling>

</ms:merge-schema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<ms:merge-schema for="" xmlns:ms="http://maybeec.github.io/lexeme/mergeschema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maybeec.github.io/lexeme/mergeschema ../../../../../lexeme/src/main/resources/xsd/MergeSchema.xsd ">
<ms:definition location="src/main/resources/mergeSchemas/xsd/myfaces_facelets_core_2_1.xsd" type="xsd" namespace="http://xmlns.jcp.org/jsf/core"/>

<!-- Incomplete and dependent MergeSchema. The namespace http://java.sun.com/jsf/core needs to use the prefix 'f' -->

<ms:handling for="define"><ms:criterion xpath="./@name"/></ms:handling>
<ms:handling for="include"><ms:criterion xpath="./@src"/></ms:handling>

</ms:merge-schema>
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<ms:merge-schema for="composition" xmlns:ms="http://maybeec.github.io/lexeme/mergeschema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maybeec.github.io/lexeme/mergeschema ../../../../../../../lexeme/src/main/resources/xsd/MergeSchema.xsd ">
<ms:definition namespace="http://java.sun.com/jsf/facelets"/>

<!-- This MergeSchema is far from beeing complete since the document definition couldn't be found. The merge rules are derived from different unit tests -->

<ms:merge-schema for="" xmlns:ms="http://maybeec.github.io/lexeme/mergeschema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maybeec.github.io/lexeme/mergeschema ../../../../../../../lexeme/src/main/resources/xsd/MergeSchema.xsd ">
<ms:definition location="src/main/resources/mergeSchemas/xsd/myfaces_facelets_ui_2_2.xsd" type="xsd" namespace = "http://xmlns.jcp.org/jsf/facelets">
<ms:additional-namespace location="src/main/resources/mergeSchemas/xsd/facelets-ui-2.0.xsd" namespace="http://java.sun.com/jsf/facelets"/>
</ms:definition>

<!-- This MergeSchema is far from beeing complete since the document definition couldn't be found. The merge rules are derived from different unit tests -->

<ms:handling for="define"><ms:criterion xpath="./@name"/></ms:handling>
<ms:handling for="include"><ms:criterion xpath="./@src"/></ms:handling>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<ms:merge-schema for="html" xmlns:ms="http://maybeec.github.io/lexeme/mergeschema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maybeec.github.io/lexeme/mergeschema ../../../../../lexeme/src/main/resources/xsd/MergeSchema.xsd ">
<ms:definition namespace="http://www.w3.org/1999/xhtml" type="dtd">
<ms:definition namespace="http://www.w3.org/1999/xhtml" type="xsd" location="https://www.w3.org/MarkUp/SCHEMA/xhtml11.xsd">
<ms:additional-namespace namespace="//W3C//ENTITIES Latin 1 for XHTML//EN"/>
</ms:definition>

Expand Down

Large diffs are not rendered by default.

Loading

0 comments on commit d269336

Please sign in to comment.