-
Notifications
You must be signed in to change notification settings - Fork 136
xwiki-commons-tool-xar-plugin - Various changes due to issues building/running on Windows. #1220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
770d6ac
44d8e48
55328cb
4dab427
2e9ae6e
93ff58b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,23 +19,26 @@ | |
| */ | ||
| package org.xwiki.tool.xar; | ||
|
|
||
| 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; | ||
|
|
||
| import java.io.ByteArrayOutputStream; | ||
| import java.io.File; | ||
| import java.io.InputStream; | ||
| import java.nio.charset.Charset; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Locale; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| import org.apache.commons.io.IOUtils; | ||
| import org.dom4j.Document; | ||
| import org.dom4j.io.OutputFormat; | ||
| import org.dom4j.io.SAXReader; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.xwiki.tool.xar.internal.XMLUtils.getSAXReader; | ||
|
|
||
| /** | ||
| * Unit tests for {@link FormatMojo}. | ||
| * | ||
|
|
@@ -51,9 +54,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)); | ||
| } | ||
|
|
@@ -79,7 +80,7 @@ void defaultLanguageForMatchingContentPage() | |
| mojo.contentPages = Arrays.asList(".*/Document\\.xml"); | ||
| mojo.initializePatterns(); | ||
|
|
||
| File file = new File("Some/Space/Document.xml"); | ||
| File file = new File("Some" + File.separator + "Space" + File.separator + "Document.xml"); | ||
jameswartell marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| assertEquals(Locale.ENGLISH, mojo.guessDefaultLocale(file, Collections.emptyList())); | ||
| } | ||
|
|
@@ -118,9 +119,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)); | ||
| } | ||
|
|
@@ -132,8 +131,13 @@ void defaultLanguageForDocumentWhenNoTranslationButFileWithSameNameInOtherSpace( | |
| void formatSpecialContentFailingWithXercesFromJDK8() throws Exception | ||
| { | ||
| SAXReader reader = getSAXReader(); | ||
| reader.setEncoding("UTF-8"); | ||
jameswartell marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("XWikiSyntaxLinks.it.xml"); | ||
| String expectedContent = IOUtils.toString(is, "UTF-8"); | ||
| // github clients may automatically convert the file to use windows line returns. | ||
|
||
| if (!System.lineSeparator().equals("\n")) { | ||
| expectedContent = expectedContent.replaceAll(Pattern.quote(System.lineSeparator()), "\n"); | ||
| } | ||
|
|
||
| is = Thread.currentThread().getContextClassLoader().getResourceAsStream("XWikiSyntaxLinks.it.xml"); | ||
| Document domdoc = reader.read(is); | ||
|
|
@@ -146,7 +150,28 @@ void formatSpecialContentFailingWithXercesFromJDK8() throws Exception | |
| writer.setVersion("1.1"); | ||
| writer.write(domdoc); | ||
| writer.close(); | ||
|
|
||
| assertEquals(expectedContent, baos.toString()); | ||
| String actual = baos.toString(Charset.forName("UTF-8")); | ||
jameswartell marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import static are supposed to be at the end according to XWiki codestyle (I also doubt this change in needed for what this PR is about, so better avoid it in general).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The eclipse formatter moved it. I needed to add this to the end in eclipse. I'll see about adding that to the section on setting up formatting in Eclipse.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to take a look at the various Eclipse related configurations on https://github.com/xwiki/xwiki-commons/tree/master/xwiki-commons-tools/xwiki-commons-tool-verification-resources/src/main/resources (and in this specific case import eclipse.importorder). But in general you should avoid auto format.