diff --git a/.gitattributes b/.gitattributes index 523a688c25..72fbe9dac4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,6 +1,6 @@ * text=auto *.java text ident diff=java -*.xml text ident diff=html +*.xml eol=lf ident diff=html *.vm text ident *.js text ident *.css text ident diff --git a/xwiki-commons-tools/xwiki-commons-tool-xar/xwiki-commons-tool-xar-plugin/src/main/java/org/xwiki/tool/xar/AbstractVerifyMojo.java b/xwiki-commons-tools/xwiki-commons-tool-xar/xwiki-commons-tool-xar-plugin/src/main/java/org/xwiki/tool/xar/AbstractVerifyMojo.java index 6d45d429d1..06024cab0f 100644 --- a/xwiki-commons-tools/xwiki-commons-tool-xar/xwiki-commons-tool-xar-plugin/src/main/java/org/xwiki/tool/xar/AbstractVerifyMojo.java +++ b/xwiki-commons-tools/xwiki-commons-tool-xar/xwiki-commons-tool-xar-plugin/src/main/java/org/xwiki/tool/xar/AbstractVerifyMojo.java @@ -73,6 +73,8 @@ public abstract class AbstractVerifyMojo extends AbstractXARMojo private static final Pattern TRANSLATION_PATTERN = Pattern.compile("(.*)\\..*\\.xml"); + private static final String UNIX_STYLE_FILE_SEPARATOR = "/"; + /** * If true then don't check if the packaging is XAR before running mojos. */ @@ -150,8 +152,8 @@ public abstract class AbstractVerifyMojo extends AbstractXARMojo /** * Explicitly define a list of pages (it's a regex) that are technical pages but that should be visible (not - * hidden). For example, home pages of applications. These pages must have their default langue set to empty so - * that a search in a given language doesn't return them as they're not content. + * hidden). For example, home pages of applications. These pages must have their default langue set to empty so that + * a search in a given language doesn't return them as they're not content. * * @since 12.3RC1 */ @@ -243,15 +245,16 @@ protected Collection getXARXMLFiles() throws MojoFailureException /** * Guess the {@code <defaultLanguage>} value to use for the passed file using the following algorithm: * + * * @param file the XML file for which to guess the default language that it should have * @param xwikiXmlFiles the list of all XML files that is used to check for translations of the passed XML file * @return the default language as a string (e.g. "en" for English or "" for an empty default language) @@ -306,9 +309,15 @@ protected boolean isVisibleTechnicalPage(String filePath) private boolean isMatchingPage(String filePath, List patterns) { - if (patterns != null) { + + if (patterns != null && patterns.size() > 0) { + String tranformedFilePath = filePath; + // we use the unix file.seperator even if we're currently running on windows. + if (!File.separator.equals(UNIX_STYLE_FILE_SEPARATOR)) { + tranformedFilePath = filePath.replaceAll(Pattern.quote(File.separator), UNIX_STYLE_FILE_SEPARATOR); + } for (Pattern pattern : patterns) { - if (pattern.matcher(filePath).matches()) { + if (pattern.matcher(tranformedFilePath).matches()) { return true; } } @@ -347,25 +356,11 @@ protected void executeLicenseGoal(String goal) throws MojoExecutionException throw new MojoExecutionException("License plugin could not be found in "); } - executeMojo( - licensePlugin, - goal(goal), - configuration( - element(name("licenseSets"), - element(name("licenseSet"), - element(name("header"), "license.txt"), - element(name("headerDefinitions"), - element(name("headerDefinition"), "license-xml-definition.xml")), - element(name("includes"), - element(name("include"), "src/main/resources/**/*.xml")) - ) - ) - ), - executionEnvironment( - this.project, - this.mavenSession, - this.pluginManager - ) - ); + executeMojo(licensePlugin, goal(goal), + configuration(element(name("licenseSets"), + element(name("licenseSet"), element(name("header"), "license.txt"), + element(name("headerDefinitions"), element(name("headerDefinition"), "license-xml-definition.xml")), + element(name("includes"), element(name("include"), "src/main/resources/**/*.xml"))))), + executionEnvironment(this.project, this.mavenSession, this.pluginManager)); } } diff --git a/xwiki-commons-tools/xwiki-commons-tool-xar/xwiki-commons-tool-xar-plugin/src/test/java/org/xwiki/tool/xar/FormatMojoTest.java b/xwiki-commons-tools/xwiki-commons-tool-xar/xwiki-commons-tool-xar-plugin/src/test/java/org/xwiki/tool/xar/FormatMojoTest.java index 553701840d..59e3209ed2 100644 --- a/xwiki-commons-tools/xwiki-commons-tool-xar/xwiki-commons-tool-xar-plugin/src/test/java/org/xwiki/tool/xar/FormatMojoTest.java +++ b/xwiki-commons-tools/xwiki-commons-tool-xar/xwiki-commons-tool-xar-plugin/src/test/java/org/xwiki/tool/xar/FormatMojoTest.java @@ -34,6 +34,7 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.xwiki.tool.xar.internal.XMLUtils.getSAXReader; /** @@ -51,9 +52,7 @@ void defaultLanguageForDefaultDocumentWhenTranslation() mojo.defaultLanguage = "en"; File file = new File("Some/Space/Document.xml"); - List files = Arrays.asList( - new File("Some/Space/Document.xml"), - new File("Some/Space/Document.fr.xml")); + List files = Arrays.asList(new File("Some/Space/Document.xml"), new File("Some/Space/Document.fr.xml")); assertEquals(Locale.ENGLISH, mojo.guessDefaultLocale(file, files)); } @@ -118,9 +117,7 @@ void defaultLanguageForDocumentWhenNoTranslationButFileWithSameNameInOtherSpace( File file = new File("Space1/Document.xml"); // Simulate a page with the same name and with a translation but in a different space. - List files = Arrays.asList( - new File("Space2/Document.xml"), - new File("Space2/Document.fr.xml")); + List files = Arrays.asList(new File("Space2/Document.xml"), new File("Space2/Document.fr.xml")); assertEquals(Locale.ROOT, mojo.guessDefaultLocale(file, files)); } @@ -146,7 +143,28 @@ void formatSpecialContentFailingWithXercesFromJDK8() throws Exception writer.setVersion("1.1"); writer.write(domdoc); writer.close(); - - assertEquals(expectedContent, baos.toString()); + String actual = baos.toString(java.nio.charset.StandardCharsets.UTF_8); + + int offset = -1; + if (!expectedContent.equals(actual)) { + for (int i = 0; i < Math.min(((String) expectedContent).length(), ((String) actual).length()); i++) { + char c1 = expectedContent.charAt(i); + char c2 = actual.charAt(i); + if (c1 != c2) { + offset = i; + break; + } + } + String result = ""; + if (offset != -1) { + result += "Offset of first difference: " + offset + " expected char: " + expectedContent.charAt(offset) + + " (" + ((int) expectedContent.charAt(offset)) + ")" + " actual char: " + actual.charAt(offset) + + " (" + ((int) actual.charAt(offset)) + ")" + System.lineSeparator(); + } + result += "Expected:" + System.lineSeparator() + expectedContent + System.lineSeparator() + + System.lineSeparator() + " Does not match actual: " + System.lineSeparator() + actual + + System.lineSeparator() + System.lineSeparator(); + assertTrue(false, result); + } } }