Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -243,15 +245,16 @@ protected Collection<File> getXARXMLFiles() throws MojoFailureException
/**
* Guess the {@code &lt;defaultLanguage&gt;} value to use for the passed file using the following algorithm:
* <ul>
* <li>If the page name matches one of the regexes defined by the user as a translated page, then check that
* the default language is {@link #defaultLanguage}.</li>
* <li>Otherwise, if the page name matches one of the regexes defined by the user as a content page, then check
* that the default language is {@link #defaultLanguage}.</li>
* <li>Otherwise, if there's no other translation of the file then check that the default language is empty
* since it's a technical page.</li>
* <li>Otherwise, if there are other translations ("(prefix).(language).xml" format) then check that the default
* language should is {@link #defaultLanguage}</li>
* <li>If the page name matches one of the regexes defined by the user as a translated page, then check that the
* default language is {@link #defaultLanguage}.</li>
* <li>Otherwise, if the page name matches one of the regexes defined by the user as a content page, then check that
* the default language is {@link #defaultLanguage}.</li>
* <li>Otherwise, if there's no other translation of the file then check that the default language is empty since
* it's a technical page.</li>
* <li>Otherwise, if there are other translations ("(prefix).(language).xml" format) then check that the default
* language should is {@link #defaultLanguage}</li>
* </ul>
*
* @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)
Expand Down Expand Up @@ -306,9 +309,15 @@ protected boolean isVisibleTechnicalPage(String filePath)

private boolean isMatchingPage(String filePath, List<Pattern> 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;
}
}
Expand Down Expand Up @@ -347,25 +356,11 @@ protected void executeLicenseGoal(String goal) throws MojoExecutionException
throw new MojoExecutionException("License plugin could not be found in <pluginManagement>");
}

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

/**
Expand All @@ -51,9 +52,7 @@ void defaultLanguageForDefaultDocumentWhenTranslation()
mojo.defaultLanguage = "en";

File file = new File("Some/Space/Document.xml");
List<File> files = Arrays.asList(
new File("Some/Space/Document.xml"),
new File("Some/Space/Document.fr.xml"));
List<File> files = Arrays.asList(new File("Some/Space/Document.xml"), new File("Some/Space/Document.fr.xml"));

assertEquals(Locale.ENGLISH, mojo.guessDefaultLocale(file, files));
}
Expand Down Expand Up @@ -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<File> files = Arrays.asList(
new File("Space2/Document.xml"),
new File("Space2/Document.fr.xml"));
List<File> files = Arrays.asList(new File("Space2/Document.xml"), new File("Space2/Document.fr.xml"));

assertEquals(Locale.ROOT, mojo.guessDefaultLocale(file, files));
}
Expand All @@ -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);
}
}
}