This is an automated email from the ASF dual-hosted git repository. slachiewicz pushed a commit to branch DOXIATOOLS-79 in repository https://gitbox.apache.org/repos/asf/maven-doxia-converter.git
commit 7f96465f3b35876fd0052516c5ff6ef27c9b68be Author: Sylwester Lachiewicz <[email protected]> AuthorDate: Sat Feb 18 13:08:35 2023 +0100 [DOXIATOOLS-79] apply formatting with spotless:apply --- pom.xml | 16 +- .../java/org/apache/maven/doxia/Converter.java | 17 +- .../org/apache/maven/doxia/ConverterException.java | 17 +- .../org/apache/maven/doxia/DefaultConverter.java | 568 ++++++++------------- .../maven/doxia/UnsupportedFormatException.java | 23 +- .../org/apache/maven/doxia/cli/CLIManager.java | 138 +++-- .../org/apache/maven/doxia/cli/ConverterCli.java | 213 +++----- .../maven/doxia/wrapper/AbstractFileWrapper.java | 69 +-- .../maven/doxia/wrapper/InputFileWrapper.java | 37 +- .../maven/doxia/wrapper/InputReaderWrapper.java | 27 +- .../maven/doxia/wrapper/OutputFileWrapper.java | 35 +- .../maven/doxia/wrapper/OutputStreamWrapper.java | 32 +- .../java/org/apache/maven/doxia/ConverterTest.java | 518 ++++++++----------- 13 files changed, 693 insertions(+), 1017 deletions(-) diff --git a/pom.xml b/pom.xml index 11cdb35..f0873d2 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,4 @@ <?xml version="1.0" encoding="UTF-8"?> - <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file @@ -18,7 +17,6 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> - <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> @@ -38,8 +36,8 @@ under the License. <scm> <connection>scm:git:https://gitbox.apache.org/repos/asf/maven-doxia-converter.git</connection> <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/maven-doxia-converter.git</developerConnection> - <url>https://github.com/apache/maven-doxia-converter/tree/${project.scm.tag}</url> <tag>HEAD</tag> + <url>https://github.com/apache/maven-doxia-converter/tree/${project.scm.tag}</url> </scm> <issueManagement> <system>jira</system> @@ -205,7 +203,7 @@ under the License. <excludes combine.children="append"> <exclude>src/test/resources/unit/**/test.*</exclude> <exclude>src/test/resources/book-1/section-*.apt</exclude> - </excludes> + </excludes> </configuration> </plugin> </plugins> @@ -227,17 +225,17 @@ under the License. <executions> <execution> <id>make-assembly</id> - <phase>package</phase> <goals> <goal>single</goal> </goals> + <phase>package</phase> </execution> </executions> </plugin> <plugin> - <groupId>org.jacoco</groupId> - <artifactId>jacoco-maven-plugin</artifactId> - <version>0.8.8</version> + <groupId>org.jacoco</groupId> + <artifactId>jacoco-maven-plugin</artifactId> + <version>0.8.8</version> <executions> <execution> <goals> @@ -246,10 +244,10 @@ under the License. </execution> <execution> <id>report</id> - <phase>prepare-package</phase> <goals> <goal>report</goal> </goals> + <phase>prepare-package</phase> </execution> </executions> </plugin> diff --git a/src/main/java/org/apache/maven/doxia/Converter.java b/src/main/java/org/apache/maven/doxia/Converter.java index bd16840..034b856 100644 --- a/src/main/java/org/apache/maven/doxia/Converter.java +++ b/src/main/java/org/apache/maven/doxia/Converter.java @@ -1,5 +1,3 @@ -package org.apache.maven.doxia; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ package org.apache.maven.doxia; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.doxia; import org.apache.maven.doxia.logging.LogEnabled; import org.apache.maven.doxia.wrapper.InputFileWrapper; @@ -30,17 +29,15 @@ import org.apache.maven.doxia.wrapper.OutputStreamWrapper; * * @author <a href="mailto:[email protected]">Vincent Siveton</a> */ -public interface Converter - extends LogEnabled -{ +public interface Converter extends LogEnabled { /** * @param input an input file wrapper, not null. * @param output an output file wrapper, not null. * @throws UnsupportedFormatException if any * @throws ConverterException if any */ - void convert( InputFileWrapper input, OutputFileWrapper output ) - throws UnsupportedFormatException, ConverterException; + void convert(InputFileWrapper input, OutputFileWrapper output) + throws UnsupportedFormatException, ConverterException; /** * @param input an input reader wrapper, not null. @@ -48,8 +45,8 @@ public interface Converter * @throws UnsupportedFormatException if any * @throws ConverterException if any */ - void convert( InputReaderWrapper input, OutputStreamWrapper output ) - throws UnsupportedFormatException, ConverterException; + void convert(InputReaderWrapper input, OutputStreamWrapper output) + throws UnsupportedFormatException, ConverterException; /** * Make the generated files human readable. @@ -58,5 +55,5 @@ public interface Converter * * @param formatOutput <code>true</code> to format the generated files, <code>false</code> otherwise. */ - void setFormatOutput( boolean formatOutput ); + void setFormatOutput(boolean formatOutput); } diff --git a/src/main/java/org/apache/maven/doxia/ConverterException.java b/src/main/java/org/apache/maven/doxia/ConverterException.java index 09891a2..e6c60f0 100644 --- a/src/main/java/org/apache/maven/doxia/ConverterException.java +++ b/src/main/java/org/apache/maven/doxia/ConverterException.java @@ -1,5 +1,3 @@ -package org.apache.maven.doxia; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,15 +16,14 @@ package org.apache.maven.doxia; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.doxia; /** * Wrap an exception that occurs during the conversion. * * @author <a href="mailto:[email protected]">Vincent Siveton</a> */ -public class ConverterException - extends Exception -{ +public class ConverterException extends Exception { /** The serialVersionUID */ static final long serialVersionUID = -5251213141888260575L; @@ -36,9 +33,8 @@ public class ConverterException * @param message The detailed message. * This can later be retrieved by the Throwable.getMessage() method. */ - public ConverterException( String message ) - { - super( message ); + public ConverterException(String message) { + super(message); } /** @@ -51,8 +47,7 @@ public class ConverterException * Throwable.getCause() method. (A null value is permitted, and indicates * that the cause is nonexistent or unknown.) */ - public ConverterException( String message, Throwable cause ) - { - super( message, cause ); + public ConverterException(String message, Throwable cause) { + super(message, cause); } } diff --git a/src/main/java/org/apache/maven/doxia/DefaultConverter.java b/src/main/java/org/apache/maven/doxia/DefaultConverter.java index 4970977..4adbb73 100644 --- a/src/main/java/org/apache/maven/doxia/DefaultConverter.java +++ b/src/main/java/org/apache/maven/doxia/DefaultConverter.java @@ -1,5 +1,3 @@ -package org.apache.maven.doxia; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ package org.apache.maven.doxia; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.doxia; import java.io.BufferedInputStream; import java.io.CharArrayWriter; @@ -36,6 +35,9 @@ import java.util.Locale; import java.util.Map; import java.util.Objects; +import com.ibm.icu.text.CharsetDetector; +import com.ibm.icu.text.CharsetMatch; +import org.apache.commons.io.input.XmlStreamReader; import org.apache.maven.doxia.logging.Log; import org.apache.maven.doxia.logging.SystemStreamLog; import org.apache.maven.doxia.parser.ParseException; @@ -58,15 +60,11 @@ import org.codehaus.plexus.util.ReaderFactory; import org.codehaus.plexus.util.SelectorUtils; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.WriterFactory; -import org.apache.commons.io.input.XmlStreamReader; import org.codehaus.plexus.util.xml.XmlUtil; import org.codehaus.plexus.util.xml.pull.MXParser; import org.codehaus.plexus.util.xml.pull.XmlPullParser; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; -import com.ibm.icu.text.CharsetDetector; -import com.ibm.icu.text.CharsetMatch; - import static java.lang.String.format; /** @@ -74,43 +72,40 @@ import static java.lang.String.format; * * @author <a href="mailto:[email protected]">Vincent Siveton</a> */ -public class DefaultConverter - implements Converter -{ +public class DefaultConverter implements Converter { /** * All supported Doxia formats (either only parser, only sink or both) */ - public enum DoxiaFormat - { - APT( "apt", "apt", true, true ), - CONFLUENCE( "confluence", "confluence", true, true ), - DOCBOOK( "docbook", "xml", "article", true, true ), - FML( "fml", "fml", "faqs", true, false ), - FO( "fo", "fo", false, true ), - ITEXT( "itext", "itext", false, true ), - LATEX( "latex", "tex", false, true ), - TWIKI( "twiki", "twiki", true, true ), - RTF( "rtf", "rtf", false, true ), - XDOC( "xdoc", "xml", "document", true, true ), - XHTML( "xhtml", "html", "html", true, true ), - XHTML5( "xhtml5", "html", true, true ), // no autodetect support - MARKDOWN( "markdown", "md", false, true ); + public enum DoxiaFormat { + APT("apt", "apt", true, true), + CONFLUENCE("confluence", "confluence", true, true), + DOCBOOK("docbook", "xml", "article", true, true), + FML("fml", "fml", "faqs", true, false), + FO("fo", "fo", false, true), + ITEXT("itext", "itext", false, true), + LATEX("latex", "tex", false, true), + TWIKI("twiki", "twiki", true, true), + RTF("rtf", "rtf", false, true), + XDOC("xdoc", "xml", "document", true, true), + XHTML("xhtml", "html", "html", true, true), + XHTML5("xhtml5", "html", true, true), // no autodetect support + MARKDOWN("markdown", "md", false, true); /** Plexus role hint for Doxia sink/parser */ private final String roleHint; + private final String extension; /** The name of the first element in case this is an XML format, otherwise {@code null} */ private final String firstElement; + private final boolean hasParser; private final boolean hasSink; - DoxiaFormat( String roleHint, String extension, boolean hasParser, boolean hasSink ) - { - this( roleHint, extension, null, hasParser, hasSink ); + DoxiaFormat(String roleHint, String extension, boolean hasParser, boolean hasSink) { + this(roleHint, extension, null, hasParser, hasSink); } - DoxiaFormat( String roleHint, String extension, String firstElement, boolean hasParser, boolean hasSink ) - { + DoxiaFormat(String roleHint, String extension, String firstElement, boolean hasParser, boolean hasSink) { this.roleHint = roleHint; this.extension = extension; this.firstElement = firstElement; @@ -119,30 +114,26 @@ public class DefaultConverter } /** - * + * * @return the primary extension used with this format */ - public String getExtension() - { + public String getExtension() { return extension; } - public boolean hasParser() - { + public boolean hasParser() { return hasParser; } - public boolean hasSink() - { + public boolean hasSink() { return hasSink; } /** - * + * * @return {@code true} in case this format is XML based */ - public boolean isXml() - { + public boolean isXml() { return firstElement != null; } @@ -152,16 +143,13 @@ public class DefaultConverter * @throws ComponentLookupException if could not find the Parser for the given format. * @throws IllegalArgumentException if any parameter is null */ - public Parser getParser( PlexusContainer plexus ) - throws ComponentLookupException - { - if ( !hasParser ) - { - throw new IllegalStateException( "The format " + this + " is not supported as parser!" ); + public Parser getParser(PlexusContainer plexus) throws ComponentLookupException { + if (!hasParser) { + throw new IllegalStateException("The format " + this + " is not supported as parser!"); } - Objects.requireNonNull( plexus, "plexus is required" ); + Objects.requireNonNull(plexus, "plexus is required"); - return (Parser) plexus.lookup( Parser.ROLE, roleHint ); + return (Parser) plexus.lookup(Parser.ROLE, roleHint); } /** @@ -170,16 +158,13 @@ public class DefaultConverter * @throws ComponentLookupException if could not find the SinkFactory for the given format. * @throws IllegalArgumentException if any parameter is null */ - public SinkFactory getSinkFactory( PlexusContainer plexus ) - throws ComponentLookupException - { - if ( !hasSink ) - { - throw new IllegalStateException( "The format " + this + " is not supported as sink!" ); + public SinkFactory getSinkFactory(PlexusContainer plexus) throws ComponentLookupException { + if (!hasSink) { + throw new IllegalStateException("The format " + this + " is not supported as sink!"); } - Objects.requireNonNull( plexus, "plexus is required" ); + Objects.requireNonNull(plexus, "plexus is required"); - return (SinkFactory) plexus.lookup( SinkFactory.ROLE, roleHint ); + return (SinkFactory) plexus.lookup(SinkFactory.ROLE, roleHint); } /** @@ -194,41 +179,32 @@ public class DefaultConverter * @throws IllegalArgumentException if f is not a file. * @throws UnsupportedOperationException if could not detect the Doxia format. */ - public static DoxiaFormat autoDetectFormat( File f ) - { - if ( !f.isFile() ) - { - throw new IllegalArgumentException( "The path '" + f.getAbsolutePath() - + "' does not locate a file, could not detect format." ); + public static DoxiaFormat autoDetectFormat(File f) { + if (!f.isFile()) { + throw new IllegalArgumentException( + "The path '" + f.getAbsolutePath() + "' does not locate a file, could not detect format."); } - for ( DoxiaFormat format : EnumSet.allOf( DoxiaFormat.class ) ) - { - if ( format.isXml() ) - { + for (DoxiaFormat format : EnumSet.allOf(DoxiaFormat.class)) { + if (format.isXml()) { // Handle XML files - String firstTag = getFirstTag( f ); - if ( firstTag == null ) - { + String firstTag = getFirstTag(f); + if (firstTag == null) { //noinspection UnnecessaryContinue continue; } - if ( firstTag.equals( format.firstElement ) ) - { + if (firstTag.equals(format.firstElement)) { return format; } - } - else - { - if ( hasFileExtensionIgnoreCase( f.getName(), format.getExtension() ) ) - { + } else { + if (hasFileExtensionIgnoreCase(f.getName(), format.getExtension())) { return format; } } } - throw new UnsupportedOperationException( - format( "Could not detect the Doxia format for file: %s%nSpecify explicitly the Doxia format.", - f.getAbsolutePath() ) ); + throw new UnsupportedOperationException(format( + "Could not detect the Doxia format for file: %s%nSpecify explicitly the Doxia format.", + f.getAbsolutePath())); } } @@ -243,8 +219,7 @@ public class DefaultConverter /** {@inheritDoc} */ @Override - public void enableLogging( Log log ) - { + public void enableLogging(Log log) { this.log = log; } @@ -254,10 +229,8 @@ public class DefaultConverter * * @return Log */ - protected Log getLog() - { - if ( log == null ) - { + protected Log getLog() { + if (log == null) { log = new SystemStreamLog(); } @@ -266,131 +239,98 @@ public class DefaultConverter /** {@inheritDoc} */ @Override - public void convert( InputFileWrapper input, OutputFileWrapper output ) - throws UnsupportedFormatException, ConverterException - { - Objects.requireNonNull( input, "input is required" ); - Objects.requireNonNull( output, "output is required" ); - - try - { + public void convert(InputFileWrapper input, OutputFileWrapper output) + throws UnsupportedFormatException, ConverterException { + Objects.requireNonNull(input, "input is required"); + Objects.requireNonNull(output, "output is required"); + + try { startPlexusContainer(); - } - catch ( PlexusContainerException e ) - { - throw new ConverterException( "PlexusContainerException: " + e.getMessage(), e ); + } catch (PlexusContainerException e) { + throw new ConverterException("PlexusContainerException: " + e.getMessage(), e); } - try - { - if ( input.getFile().isFile() ) - { - parse( input.getFile(), input.getEncoding(), input.getFormat(), output ); - } - else - { + try { + if (input.getFile().isFile()) { + parse(input.getFile(), input.getEncoding(), input.getFormat(), output); + } else { List<File> files; - try - { - files = FileUtils.getFiles( input.getFile(), "**/*." + input.getFormat().getExtension(), - StringUtils.join( FileUtils.getDefaultExcludes(), ", " ) ); - } - catch ( IOException e ) - { - throw new ConverterException( "IOException: " + e.getMessage(), e ); - } - catch ( IllegalStateException e ) - { - throw new ConverterException( "IllegalStateException: " + e.getMessage(), e ); + try { + files = FileUtils.getFiles( + input.getFile(), + "**/*." + input.getFormat().getExtension(), + StringUtils.join(FileUtils.getDefaultExcludes(), ", ")); + } catch (IOException e) { + throw new ConverterException("IOException: " + e.getMessage(), e); + } catch (IllegalStateException e) { + throw new ConverterException("IllegalStateException: " + e.getMessage(), e); } - for ( File f : files ) - { - File relativeOutputDirectory = new File( - PathTool.getRelativeFilePath( input.getFile().getAbsolutePath(), f.getParent() ) ); - parse( f, input.getEncoding(), input.getFormat(), output, relativeOutputDirectory ); + for (File f : files) { + File relativeOutputDirectory = new File( + PathTool.getRelativeFilePath(input.getFile().getAbsolutePath(), f.getParent())); + parse(f, input.getEncoding(), input.getFormat(), output, relativeOutputDirectory); } } - } - finally - { + } finally { stopPlexusContainer(); } } /** {@inheritDoc} */ @Override - public void convert( InputReaderWrapper input, OutputStreamWrapper output ) - throws UnsupportedFormatException, ConverterException - { - Objects.requireNonNull( input, "input is required" ); - Objects.requireNonNull( output, "output is required" ); - - try - { + public void convert(InputReaderWrapper input, OutputStreamWrapper output) + throws UnsupportedFormatException, ConverterException { + Objects.requireNonNull(input, "input is required"); + Objects.requireNonNull(output, "output is required"); + + try { startPlexusContainer(); - } - catch ( PlexusContainerException e ) - { - throw new ConverterException( "PlexusContainerException: " + e.getMessage(), e ); + } catch (PlexusContainerException e) { + throw new ConverterException("PlexusContainerException: " + e.getMessage(), e); } - try - { + try { Parser parser; - try - { - parser = input.getFormat().getParser( plexus ); - parser.enableLogging( log ); - } - catch ( ComponentLookupException e ) - { - throw new ConverterException( "ComponentLookupException: " + e.getMessage(), e ); + try { + parser = input.getFormat().getParser(plexus); + parser.enableLogging(log); + } catch (ComponentLookupException e) { + throw new ConverterException("ComponentLookupException: " + e.getMessage(), e); } - if ( getLog().isDebugEnabled() ) - { - getLog().debug( "Parser used: " + parser.getClass().getName() ); + if (getLog().isDebugEnabled()) { + getLog().debug("Parser used: " + parser.getClass().getName()); } SinkFactory sinkFactory; - try - { - sinkFactory = output.getFormat().getSinkFactory( plexus ); - } - catch ( ComponentLookupException e ) - { - throw new ConverterException( "ComponentLookupException: " + e.getMessage(), e ); + try { + sinkFactory = output.getFormat().getSinkFactory(plexus); + } catch (ComponentLookupException e) { + throw new ConverterException("ComponentLookupException: " + e.getMessage(), e); } Sink sink; - try - { - sink = sinkFactory.createSink( output.getOutputStream(), output.getEncoding() ); - } - catch ( IOException e ) - { - throw new ConverterException( "IOException: " + e.getMessage(), e ); + try { + sink = sinkFactory.createSink(output.getOutputStream(), output.getEncoding()); + } catch (IOException e) { + throw new ConverterException("IOException: " + e.getMessage(), e); } - sink.enableLogging( log ); + sink.enableLogging(log); - if ( getLog().isDebugEnabled() ) - { - getLog().debug( "Sink used: " + sink.getClass().getName() ); + if (getLog().isDebugEnabled()) { + getLog().debug("Sink used: " + sink.getClass().getName()); } - parse( parser, input.getReader(), sink ); - } - finally - { + parse(parser, input.getReader(), sink); + } finally { stopPlexusContainer(); } } /** {@inheritDoc} */ @Override - public void setFormatOutput( boolean formatOutput ) - { + public void setFormatOutput(boolean formatOutput) { this.formatOutput = formatOutput; } @@ -406,10 +346,9 @@ public class DefaultConverter * @throws ConverterException if any * @throws UnsupportedFormatException if any */ - private void parse( File inputFile, String inputEncoding, DoxiaFormat parserFormat, OutputFileWrapper output ) - throws ConverterException, UnsupportedFormatException - { - parse( inputFile, inputEncoding, parserFormat, output, null ); + private void parse(File inputFile, String inputEncoding, DoxiaFormat parserFormat, OutputFileWrapper output) + throws ConverterException, UnsupportedFormatException { + parse(inputFile, inputEncoding, parserFormat, output, null); } /** @@ -421,142 +360,112 @@ public class DefaultConverter * @throws ConverterException if any * @throws UnsupportedFormatException if any */ - private void parse( File inputFile, String inputEncoding, DoxiaFormat parserFormat, OutputFileWrapper output, - File relativeOutputDirectory ) - throws ConverterException, UnsupportedFormatException - { - File outputDirectoryOrFile = relativeOutputDirectory != null - ? new File( output.getFile(), relativeOutputDirectory.getPath() ) + private void parse( + File inputFile, + String inputEncoding, + DoxiaFormat parserFormat, + OutputFileWrapper output, + File relativeOutputDirectory) + throws ConverterException, UnsupportedFormatException { + File outputDirectoryOrFile = relativeOutputDirectory != null + ? new File(output.getFile(), relativeOutputDirectory.getPath()) : output.getFile(); - if ( getLog().isDebugEnabled() ) - { - getLog().debug( - "Parsing file from '" + inputFile.getAbsolutePath() + "' with the encoding '" - + inputEncoding + "' to '" + outputDirectoryOrFile.getAbsolutePath() - + "' with the encoding '" + output.getEncoding() + "'" ); + if (getLog().isDebugEnabled()) { + getLog().debug("Parsing file from '" + inputFile.getAbsolutePath() + "' with the encoding '" + + inputEncoding + "' to '" + outputDirectoryOrFile.getAbsolutePath() + + "' with the encoding '" + output.getEncoding() + "'"); } - if ( InputFileWrapper.AUTO_ENCODING.equals( inputEncoding ) ) - { - inputEncoding = autoDetectEncoding( inputFile ); - if ( getLog().isDebugEnabled() ) - { - getLog().debug( "Auto detect encoding: " + inputEncoding ); + if (InputFileWrapper.AUTO_ENCODING.equals(inputEncoding)) { + inputEncoding = autoDetectEncoding(inputFile); + if (getLog().isDebugEnabled()) { + getLog().debug("Auto detect encoding: " + inputEncoding); } } - Parser parser; - try - { - parser = parserFormat.getParser( plexus ); - parser.enableLogging( log ); - } - catch ( ComponentLookupException e ) - { - throw new ConverterException( "ComponentLookupException: " + e.getMessage(), e ); + try { + parser = parserFormat.getParser(plexus); + parser.enableLogging(log); + } catch (ComponentLookupException e) { + throw new ConverterException("ComponentLookupException: " + e.getMessage(), e); } File outputFile; - if ( outputDirectoryOrFile.isDirectory() - || !SelectorUtils.match( "**.*", output.getFile().getName() ) - || relativeOutputDirectory != null ) - { + if (outputDirectoryOrFile.isDirectory() + || !SelectorUtils.match("**.*", output.getFile().getName()) + || relativeOutputDirectory != null) { // assume it is a directory outputDirectoryOrFile.mkdirs(); - outputFile = new File( outputDirectoryOrFile, - FileUtils.removeExtension( inputFile.getName() ) + "." + output.getFormat().getExtension() ); - } - else - { + outputFile = new File( + outputDirectoryOrFile, + FileUtils.removeExtension(inputFile.getName()) + "." + + output.getFormat().getExtension()); + } else { outputDirectoryOrFile.getParentFile().mkdirs(); outputFile = output.getFile(); } Reader reader; - try - { - if ( inputEncoding != null ) - { - if ( parser.getType() == Parser.XML_TYPE ) - { - reader = ReaderFactory.newXmlReader( inputFile ); - } - else - { - reader = ReaderFactory.newReader( inputFile, inputEncoding ); + try { + if (inputEncoding != null) { + if (parser.getType() == Parser.XML_TYPE) { + reader = ReaderFactory.newXmlReader(inputFile); + } else { + reader = ReaderFactory.newReader(inputFile, inputEncoding); } + } else { + reader = ReaderFactory.newPlatformReader(inputFile); } - else - { - reader = ReaderFactory.newPlatformReader( inputFile ); - } - } - catch ( IOException e ) - { - throw new ConverterException( "IOException: " + e.getMessage(), e ); + } catch (IOException e) { + throw new ConverterException("IOException: " + e.getMessage(), e); } SinkFactory sinkFactory; - try - { - sinkFactory = output.getFormat().getSinkFactory( plexus ); - } - catch ( ComponentLookupException e ) - { - throw new ConverterException( "ComponentLookupException: " + e.getMessage(), e ); + try { + sinkFactory = output.getFormat().getSinkFactory(plexus); + } catch (ComponentLookupException e) { + throw new ConverterException("ComponentLookupException: " + e.getMessage(), e); } Sink sink; - try - { + try { String outputEncoding; - if ( StringUtils.isEmpty( output.getEncoding() ) - || output.getEncoding().equals( OutputFileWrapper.AUTO_ENCODING ) ) - { + if (StringUtils.isEmpty(output.getEncoding()) + || output.getEncoding().equals(OutputFileWrapper.AUTO_ENCODING)) { outputEncoding = inputEncoding; - } - else - { + } else { outputEncoding = output.getEncoding(); } - OutputStream out = new FileOutputStream( outputFile ); - sink = sinkFactory.createSink( out, outputEncoding ); - } - catch ( IOException e ) - { - throw new ConverterException( "IOException: " + e.getMessage(), e ); + OutputStream out = new FileOutputStream(outputFile); + sink = sinkFactory.createSink(out, outputEncoding); + } catch (IOException e) { + throw new ConverterException("IOException: " + e.getMessage(), e); } - sink.enableLogging( log ); + sink.enableLogging(log); - if ( getLog().isDebugEnabled() ) - { - getLog().debug( "Sink used: " + sink.getClass().getName() ); + if (getLog().isDebugEnabled()) { + getLog().debug("Sink used: " + sink.getClass().getName()); } - parse( parser, reader, sink ); + parse(parser, reader, sink); - if ( formatOutput && output.getFormat().isXml() ) - { + if (formatOutput && output.getFormat().isXml()) { // format all xml files excluding docbook which is buggy // TODO Add doc book format - if ( DoxiaFormat.DOCBOOK.equals( output.getFormat() ) ) - { + if (DoxiaFormat.DOCBOOK.equals(output.getFormat())) { return; } - - try ( Reader r = ReaderFactory.newXmlReader( outputFile ); - Writer w = WriterFactory.newXmlWriter( outputFile ) ) - { + + try (Reader r = ReaderFactory.newXmlReader(outputFile); + Writer w = WriterFactory.newXmlWriter(outputFile)) { CharArrayWriter caw = new CharArrayWriter(); - XmlUtil.prettyFormat( r, caw ); - w.write( caw.toString() ); - } - catch ( IOException e ) - { - throw new ConverterException( "IOException: " + e.getMessage(), e ); + XmlUtil.prettyFormat(r, caw); + w.write(caw.toString()); + } catch (IOException e) { + throw new ConverterException("IOException: " + e.getMessage(), e); } } } @@ -567,19 +476,12 @@ public class DefaultConverter * @param sink not null * @throws ConverterException if any */ - private void parse( Parser parser, Reader reader, Sink sink ) - throws ConverterException - { - try ( Reader r = reader ) - { - parser.parse( r, sink ); - } - catch ( ParseException | IOException e ) - { - throw new ConverterException( "ParseException: " + e.getMessage(), e ); - } - finally - { + private void parse(Parser parser, Reader reader, Sink sink) throws ConverterException { + try (Reader r = reader) { + parser.parse(r, sink); + } catch (ParseException | IOException e) { + throw new ConverterException("ParseException: " + e.getMessage(), e); + } finally { sink.flush(); sink.close(); } @@ -590,31 +492,26 @@ public class DefaultConverter * * @throws PlexusContainerException if any */ - private void startPlexusContainer() - throws PlexusContainerException - { - if ( plexus != null ) - { + private void startPlexusContainer() throws PlexusContainerException { + if (plexus != null) { return; } Map<Object, Object> context = new HashMap<>(); - context.put( "basedir", new File( "" ).getAbsolutePath() ); + context.put("basedir", new File("").getAbsolutePath()); ContainerConfiguration containerConfiguration = new DefaultContainerConfiguration(); - containerConfiguration.setName( "Doxia" ); - containerConfiguration.setContext( context ); + containerConfiguration.setName("Doxia"); + containerConfiguration.setContext(context); - plexus = new DefaultPlexusContainer( containerConfiguration ); + plexus = new DefaultPlexusContainer(containerConfiguration); } /** * Stop the Plexus container. */ - private void stopPlexusContainer() - { - if ( plexus == null ) - { + private void stopPlexusContainer() { + if (plexus == null) { return; } @@ -630,86 +527,67 @@ public class DefaultConverter * @see XmlStreamReader#getEncoding() for xml files * @see CharsetDetector#detect() for text files */ - static String autoDetectEncoding( File f ) - { - if ( !f.isFile() ) - { - throw new IllegalArgumentException( "The file '" + f.getAbsolutePath() - + "' is not a file, could not detect encoding." ); - } - try - { - if ( XmlUtil.isXml( f ) ) - { - try ( XmlStreamReader reader = new XmlStreamReader( f ) ) - { + static String autoDetectEncoding(File f) { + if (!f.isFile()) { + throw new IllegalArgumentException( + "The file '" + f.getAbsolutePath() + "' is not a file, could not detect encoding."); + } + try { + if (XmlUtil.isXml(f)) { + try (XmlStreamReader reader = new XmlStreamReader(f)) { return reader.getEncoding(); } } - try ( InputStream is = new BufferedInputStream( new FileInputStream( f ) ) ) - { + try (InputStream is = new BufferedInputStream(new FileInputStream(f))) { CharsetDetector detector = new CharsetDetector(); - detector.setText( is ); + detector.setText(is); CharsetMatch match = detector.detect(); - return match.getName().toUpperCase( Locale.ENGLISH ); + return match.getName().toUpperCase(Locale.ENGLISH); } - } - catch ( IOException e ) - { + } catch (IOException e) { // nop } - throw new UnsupportedOperationException( format( "Could not detect the encoding for file: %s\n" - + "Specify explicitly the encoding.", f.getAbsolutePath() ) ); + throw new UnsupportedOperationException(format( + "Could not detect the encoding for file: %s\n" + "Specify explicitly the encoding.", + f.getAbsolutePath())); } - - /** * @param f not null * @param format could be null * @return <code>true</code> if the file extension matches */ - private static boolean hasFileExtensionIgnoreCase( String name, String extension ) - { - Objects.requireNonNull( name, "name is required." ); + private static boolean hasFileExtensionIgnoreCase(String name, String extension) { + Objects.requireNonNull(name, "name is required."); - return extension.equals( FileUtils.getExtension( name.toLowerCase( Locale.ENGLISH ) ) ); + return extension.equals(FileUtils.getExtension(name.toLowerCase(Locale.ENGLISH))); } /** * @param xmlFile not null and should be a file. * @return the first tag name if found, <code>null</code> in other case. */ - private static String getFirstTag( File xmlFile ) - { - if ( xmlFile == null ) - { - throw new IllegalArgumentException( "xmlFile is required." ); + private static String getFirstTag(File xmlFile) { + if (xmlFile == null) { + throw new IllegalArgumentException("xmlFile is required."); } - if ( !xmlFile.isFile() ) - { - throw new IllegalArgumentException( "The file '" + xmlFile.getAbsolutePath() + "' is not a file." ); + if (!xmlFile.isFile()) { + throw new IllegalArgumentException("The file '" + xmlFile.getAbsolutePath() + "' is not a file."); } - - try ( Reader reader = ReaderFactory.newXmlReader( xmlFile ) ) - { + try (Reader reader = ReaderFactory.newXmlReader(xmlFile)) { XmlPullParser parser = new MXParser(); - parser.setInput( reader ); + parser.setInput(reader); int eventType = parser.getEventType(); - while ( eventType != XmlPullParser.END_DOCUMENT ) - { - if ( eventType == XmlPullParser.START_TAG ) - { + while (eventType != XmlPullParser.END_DOCUMENT) { + if (eventType == XmlPullParser.START_TAG) { return parser.getName(); } eventType = parser.nextToken(); } - } - catch ( IOException | XmlPullParserException e ) - { + } catch (IOException | XmlPullParserException e) { return null; } diff --git a/src/main/java/org/apache/maven/doxia/UnsupportedFormatException.java b/src/main/java/org/apache/maven/doxia/UnsupportedFormatException.java index 78b3681..4245e73 100644 --- a/src/main/java/org/apache/maven/doxia/UnsupportedFormatException.java +++ b/src/main/java/org/apache/maven/doxia/UnsupportedFormatException.java @@ -1,5 +1,3 @@ -package org.apache.maven.doxia; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ package org.apache.maven.doxia; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.doxia; import org.codehaus.plexus.util.StringUtils; @@ -26,9 +25,7 @@ import org.codehaus.plexus.util.StringUtils; * * @author <a href="mailto:[email protected]">Vincent Siveton</a> */ -public class UnsupportedFormatException - extends Exception -{ +public class UnsupportedFormatException extends Exception { /** serialVersionUID */ static final long serialVersionUID = -4334290887832961366L; @@ -39,10 +36,9 @@ public class UnsupportedFormatException * @param format the unsupported format, not null * @param supportedFormat the supported formats, not null */ - public UnsupportedFormatException( String format, String[] supportedFormat ) - { - super( "Unsupported format '" + format + "'. The allowed format are: " - + StringUtils.join( supportedFormat, ", " ) ); + public UnsupportedFormatException(String format, String[] supportedFormat) { + super("Unsupported format '" + format + "'. The allowed format are: " + + StringUtils.join(supportedFormat, ", ")); } /** @@ -56,9 +52,10 @@ public class UnsupportedFormatException * Throwable.getCause() method. (A null value is permitted, and indicates * that the cause is nonexistent or unknown.) */ - public UnsupportedFormatException( String format, String[] supportedFormat, Throwable cause ) - { - super( "Unsupported format '" + format + "'. The allowed format are: " - + StringUtils.join( supportedFormat, ", " ), cause ); + public UnsupportedFormatException(String format, String[] supportedFormat, Throwable cause) { + super( + "Unsupported format '" + format + "'. The allowed format are: " + + StringUtils.join(supportedFormat, ", "), + cause); } } diff --git a/src/main/java/org/apache/maven/doxia/cli/CLIManager.java b/src/main/java/org/apache/maven/doxia/cli/CLIManager.java index 6337a4f..24b6801 100644 --- a/src/main/java/org/apache/maven/doxia/cli/CLIManager.java +++ b/src/main/java/org/apache/maven/doxia/cli/CLIManager.java @@ -1,5 +1,3 @@ -package org.apache.maven.doxia.cli; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,10 +16,12 @@ package org.apache.maven.doxia.cli; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.doxia.cli; import java.util.EnumSet; import java.util.stream.Collectors; +import com.ibm.icu.text.CharsetDetector; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.DefaultParser; import org.apache.commons.cli.HelpFormatter; @@ -30,8 +30,6 @@ import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import org.apache.maven.doxia.DefaultConverter; -import com.ibm.icu.text.CharsetDetector; - import static org.codehaus.plexus.util.StringUtils.join; /** @@ -39,8 +37,7 @@ import static org.codehaus.plexus.util.StringUtils.join; * * @author <a href="mailto:[email protected]">Vincent Siveton</a> */ -class CLIManager -{ +class CLIManager { /** h character */ static final String HELP = "h"; @@ -80,56 +77,52 @@ class CLIManager private static final String EOL = System.lineSeparator(); - static - { + static { OPTIONS = new Options(); - OPTIONS.addOption( Option.builder( HELP ) - .longOpt( "help" ) - .desc( "Display help information." ) - .build() ); - OPTIONS.addOption( Option.builder( VERSION ) - .longOpt( "version" ) - .desc( "Display version information." ) - .build() ); - OPTIONS.addOption( Option.builder( IN ) - .longOpt( "input" ) - .desc( "Input file or directory." ) - .hasArg() - .build() ); - OPTIONS.addOption( Option.builder( OUT ) - .longOpt( "output" ) - .desc( "Output file or directory." ) + OPTIONS.addOption(Option.builder(HELP) + .longOpt("help") + .desc("Display help information.") + .build()); + OPTIONS.addOption(Option.builder(VERSION) + .longOpt("version") + .desc("Display version information.") + .build()); + OPTIONS.addOption(Option.builder(IN) + .longOpt("input") + .desc("Input file or directory.") .hasArg() - .build() ); - OPTIONS.addOption( Option.builder( FROM ) - .desc( "From format. If not specified, try to autodetect it." ) + .build()); + OPTIONS.addOption(Option.builder(OUT) + .longOpt("output") + .desc("Output file or directory.") .hasArg() - .build() ); - OPTIONS.addOption( Option.builder( TO ) - .desc( "To format." ) + .build()); + OPTIONS.addOption(Option.builder(FROM) + .desc("From format. If not specified, try to autodetect it.") .hasArg() - .build() ); - OPTIONS.addOption( Option.builder( INENCODING ) - .desc( "Input file encoding. If not specified, try to autodetect it." ) + .build()); + OPTIONS.addOption(Option.builder(TO).desc("To format.").hasArg().build()); + OPTIONS.addOption(Option.builder(INENCODING) + .desc("Input file encoding. If not specified, try to autodetect it.") .hasArg() - .build() ); - OPTIONS.addOption( Option.builder( FORMAT ) - .longOpt( "format" ) - .desc( "Format the output (actually only xml based outputs) to be human readable." ) - .build() ); - OPTIONS.addOption( Option.builder( OUTENCODING ) - .desc( "Output file encoding. If not specified, use the input encoding (or autodetected)." ) + .build()); + OPTIONS.addOption(Option.builder(FORMAT) + .longOpt("format") + .desc("Format the output (actually only xml based outputs) to be human readable.") + .build()); + OPTIONS.addOption(Option.builder(OUTENCODING) + .desc("Output file encoding. If not specified, use the input encoding (or autodetected).") .hasArg() - .build() ); - OPTIONS.addOption( Option.builder( DEBUG ) - .longOpt( "debug" ) - .desc( "Produce execution debug output." ) - .build() ); - OPTIONS.addOption( Option.builder( ERRORS ) - .longOpt( "errors" ) - .desc( "Produce execution error messages." ) - .build() ); + .build()); + OPTIONS.addOption(Option.builder(DEBUG) + .longOpt("debug") + .desc("Produce execution debug output.") + .build()); + OPTIONS.addOption(Option.builder(ERRORS) + .longOpt("errors") + .desc("Produce execution error messages.") + .build()); } /** @@ -138,47 +131,42 @@ class CLIManager * @throws ParseException if any * @throws IllegalArgumentException is args is null */ - CommandLine parse( String[] args ) - throws ParseException - { - if ( args == null ) - { - throw new IllegalArgumentException( "args is required." ); + CommandLine parse(String[] args) throws ParseException { + if (args == null) { + throw new IllegalArgumentException("args is required."); } DefaultParser parser = new DefaultParser(); - return parser.parse( OPTIONS, args ); + return parser.parse(OPTIONS, args); } - static void displayHelp() - { + static void displayHelp() { System.out.println(); HelpFormatter formatter = new HelpFormatter(); - formatter.setWidth( 128 ); - formatter.printHelp( "doxia-converter", EOL + "Options:", OPTIONS, getSupportedFormatAndEncoding(), true ); + formatter.setWidth(128); + formatter.printHelp("doxia-converter", EOL + "Options:", OPTIONS, getSupportedFormatAndEncoding(), true); } - private static String getSupportedFormatAndEncoding() - { + private static String getSupportedFormatAndEncoding() { return getSupportedFormat() + "\n" + getSupportedEncoding(); } - private static String getSupportedFormat() - { - String fromFormats = EnumSet.allOf( DefaultConverter.DoxiaFormat.class ).stream() - .filter( DefaultConverter.DoxiaFormat::hasParser ) - .map( f -> f.toString().toLowerCase() ).collect( Collectors.joining( ", " ) ); - String toFormats = EnumSet.allOf( DefaultConverter.DoxiaFormat.class ).stream() - .filter( DefaultConverter.DoxiaFormat::hasSink ) - .map( f -> f.toString().toLowerCase() ).collect( Collectors.joining( ", " ) ); + private static String getSupportedFormat() { + String fromFormats = EnumSet.allOf(DefaultConverter.DoxiaFormat.class).stream() + .filter(DefaultConverter.DoxiaFormat::hasParser) + .map(f -> f.toString().toLowerCase()) + .collect(Collectors.joining(", ")); + String toFormats = EnumSet.allOf(DefaultConverter.DoxiaFormat.class).stream() + .filter(DefaultConverter.DoxiaFormat::hasSink) + .map(f -> f.toString().toLowerCase()) + .collect(Collectors.joining(", ")); return EOL + "Supported Formats:" + EOL + " from: " + fromFormats - + " or " + AUTO_FORMAT + EOL + " to: " + toFormats - + EOL; + + " or " + AUTO_FORMAT + EOL + " to: " + toFormats + + EOL; } - private static String getSupportedEncoding() - { - return EOL + "Supported Encoding:" + EOL + " " + join( CharsetDetector.getAllDetectableCharsets(), ", " ); + private static String getSupportedEncoding() { + return EOL + "Supported Encoding:" + EOL + " " + join(CharsetDetector.getAllDetectableCharsets(), ", "); } } diff --git a/src/main/java/org/apache/maven/doxia/cli/ConverterCli.java b/src/main/java/org/apache/maven/doxia/cli/ConverterCli.java index 057883c..e8d0229 100644 --- a/src/main/java/org/apache/maven/doxia/cli/ConverterCli.java +++ b/src/main/java/org/apache/maven/doxia/cli/ConverterCli.java @@ -1,5 +1,3 @@ -package org.apache.maven.doxia.cli; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ package org.apache.maven.doxia.cli; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.doxia.cli; import java.io.File; import java.io.FileNotFoundException; @@ -45,8 +44,7 @@ import org.codehaus.plexus.util.Os; * * @author <a href="mailto:[email protected]">Vincent Siveton</a> */ -public class ConverterCli -{ +public class ConverterCli { /** * Default main which terminates the JVM with <code>0</code> if no errors occurs. * @@ -54,20 +52,17 @@ public class ConverterCli * @see #doMain(String[]) * @see System#exit(int) */ - public static void main( String[] args ) - { - if ( args == null || args.length == 0 ) - { - args = new String[] { "-h" }; + public static void main(String[] args) { + if (args == null || args.length == 0) { + args = new String[] {"-h"}; } - System.exit( ConverterCli.doMain( args ) ); + System.exit(ConverterCli.doMain(args)); } /** * @param args The args */ - private static int doMain( String[] args ) - { + private static int doMain(String[] args) { // ---------------------------------------------------------------------- // Setup the command line parser // ---------------------------------------------------------------------- @@ -75,123 +70,98 @@ public class ConverterCli CLIManager cliManager = new CLIManager(); CommandLine commandLine; - try - { - commandLine = cliManager.parse( args ); - } - catch ( ParseException e ) - { - System.err.println( "Unable to parse command line options: " + e.getMessage() ); + try { + commandLine = cliManager.parse(args); + } catch (ParseException e) { + System.err.println("Unable to parse command line options: " + e.getMessage()); CLIManager.displayHelp(); return 1; } - if ( commandLine.hasOption( CLIManager.HELP ) ) - { + if (commandLine.hasOption(CLIManager.HELP)) { CLIManager.displayHelp(); return 0; } - if ( commandLine.hasOption( CLIManager.VERSION ) ) - { + if (commandLine.hasOption(CLIManager.VERSION)) { showVersion(); return 0; } - boolean debug = commandLine.hasOption( CLIManager.DEBUG ); + boolean debug = commandLine.hasOption(CLIManager.DEBUG); - boolean showErrors = debug || commandLine.hasOption( CLIManager.ERRORS ); + boolean showErrors = debug || commandLine.hasOption(CLIManager.ERRORS); - if ( showErrors ) - { - System.out.println( "+ Error stacktraces are turned on." ); + if (showErrors) { + System.out.println("+ Error stacktraces are turned on."); } Converter converter = new DefaultConverter(); Log log = new SystemStreamLog(); - if ( debug ) - { - log.setLogLevel( Log.LEVEL_DEBUG ); + if (debug) { + log.setLogLevel(Log.LEVEL_DEBUG); } - converter.enableLogging( log ); + converter.enableLogging(log); InputFileWrapper input; OutputFileWrapper output; - try - { - String sourceFormat = commandLine.getOptionValue( CLIManager.FROM, CLIManager.AUTO_FORMAT ); + try { + String sourceFormat = commandLine.getOptionValue(CLIManager.FROM, CLIManager.AUTO_FORMAT); final DefaultConverter.DoxiaFormat parserFormat; - if ( CLIManager.AUTO_FORMAT.equalsIgnoreCase( sourceFormat ) ) - { - File inputFile = new File( commandLine.getOptionValue( CLIManager.IN ) ); - parserFormat = DefaultConverter.DoxiaFormat.autoDetectFormat( inputFile ); - if ( log.isDebugEnabled() ) - { - log.debug( "Auto detected input format: " + parserFormat ); + if (CLIManager.AUTO_FORMAT.equalsIgnoreCase(sourceFormat)) { + File inputFile = new File(commandLine.getOptionValue(CLIManager.IN)); + parserFormat = DefaultConverter.DoxiaFormat.autoDetectFormat(inputFile); + if (log.isDebugEnabled()) { + log.debug("Auto detected input format: " + parserFormat); } + } else { + parserFormat = DefaultConverter.DoxiaFormat.valueOf(sourceFormat.toUpperCase()); } - else - { - parserFormat = DefaultConverter.DoxiaFormat.valueOf( sourceFormat.toUpperCase() ); - } - String targetFormat = commandLine.getOptionValue( CLIManager.TO ); - final DefaultConverter.DoxiaFormat sinkFormat = - DefaultConverter.DoxiaFormat.valueOf( targetFormat.toUpperCase() ); - input = - InputFileWrapper.valueOf( commandLine.getOptionValue( CLIManager.IN ), - parserFormat, - commandLine.getOptionValue( CLIManager.INENCODING ) ); - output = - OutputFileWrapper.valueOf( commandLine.getOptionValue( CLIManager.OUT ), - sinkFormat, - commandLine.getOptionValue( CLIManager.OUTENCODING ) ); - } - catch ( IllegalArgumentException e ) - { - showFatalError( "Illegal argument: " + e.getMessage(), e, showErrors ); + String targetFormat = commandLine.getOptionValue(CLIManager.TO); + final DefaultConverter.DoxiaFormat sinkFormat = + DefaultConverter.DoxiaFormat.valueOf(targetFormat.toUpperCase()); + input = InputFileWrapper.valueOf( + commandLine.getOptionValue(CLIManager.IN), + parserFormat, + commandLine.getOptionValue(CLIManager.INENCODING)); + output = OutputFileWrapper.valueOf( + commandLine.getOptionValue(CLIManager.OUT), + sinkFormat, + commandLine.getOptionValue(CLIManager.OUTENCODING)); + } catch (IllegalArgumentException e) { + showFatalError("Illegal argument: " + e.getMessage(), e, showErrors); CLIManager.displayHelp(); return 1; - } - catch ( UnsupportedEncodingException | FileNotFoundException e ) - { - showFatalError( e.getMessage(), e, showErrors ); + } catch (UnsupportedEncodingException | FileNotFoundException e) { + showFatalError(e.getMessage(), e, showErrors); return 1; } - boolean format = commandLine.hasOption( CLIManager.FORMAT ); - converter.setFormatOutput( format ); + boolean format = commandLine.hasOption(CLIManager.FORMAT); + converter.setFormatOutput(format); - try - { - converter.convert( input, output ); - } - catch ( UnsupportedFormatException e ) - { - showFatalError( e.getMessage(), e, showErrors ); + try { + converter.convert(input, output); + } catch (UnsupportedFormatException e) { + showFatalError(e.getMessage(), e, showErrors); return 1; - } - catch ( ConverterException e ) - { - showFatalError( "Converter exception: " + e.getMessage(), e, showErrors ); + } catch (ConverterException e) { + showFatalError("Converter exception: " + e.getMessage(), e, showErrors); return 1; - } - catch ( IllegalArgumentException e ) - { - showFatalError( "Illegal argument: " + e.getMessage(), e, showErrors ); + } catch (IllegalArgumentException e) { + showFatalError("Illegal argument: " + e.getMessage(), e, showErrors); return 1; - } - catch ( RuntimeException e ) - { - showFatalError( "Runtime exception: " + e.getMessage(), e, showErrors ); + } catch (RuntimeException e) { + showFatalError("Runtime exception: " + e.getMessage(), e, showErrors); return 1; } @@ -199,60 +169,47 @@ public class ConverterCli return 0; } - private static void showVersion() - { + private static void showVersion() { InputStream resourceAsStream; - try - { + try { Properties properties = new Properties(); - resourceAsStream = ConverterCli.class.getClassLoader() - .getResourceAsStream( "META-INF/maven/org.apache.maven.doxia/doxia-converter/pom.properties" ); - - if ( resourceAsStream != null ) - { - properties.load( resourceAsStream ); - - if ( properties.getProperty( "builtOn" ) != null ) - { - System.out.println( "Doxia Converter version: " + properties.getProperty( "version", "unknown" ) - + " built on " + properties.getProperty( "builtOn" ) ); + resourceAsStream = ConverterCli.class + .getClassLoader() + .getResourceAsStream("META-INF/maven/org.apache.maven.doxia/doxia-converter/pom.properties"); + + if (resourceAsStream != null) { + properties.load(resourceAsStream); + + if (properties.getProperty("builtOn") != null) { + System.out.println("Doxia Converter version: " + properties.getProperty("version", "unknown") + + " built on " + properties.getProperty("builtOn")); + } else { + System.out.println("Doxia Converter version: " + properties.getProperty("version", "unknown")); } - else - { - System.out.println( "Doxia Converter version: " + properties.getProperty( "version", "unknown" ) ); - } - } - else - { - System.out.println( "Doxia Converter version: " + properties.getProperty( "version", "unknown" ) ); + } else { + System.out.println("Doxia Converter version: " + properties.getProperty("version", "unknown")); } - System.out.println( "Doxia version: " - + FieldUtils.readStaticField( AbstractParser.class, "DOXIA_VERSION", true ) ); + System.out.println( + "Doxia version: " + FieldUtils.readStaticField(AbstractParser.class, "DOXIA_VERSION", true)); - System.out.println( "Java version: " + System.getProperty( "java.version", "<unknown java version>" ) ); + System.out.println("Java version: " + System.getProperty("java.version", "<unknown java version>")); - System.out.println( "OS name: \"" + Os.OS_NAME + "\" version: \"" + Os.OS_VERSION + "\" arch: \"" - + Os.OS_ARCH + "\" family: \"" + Os.OS_FAMILY + "\"" ); + System.out.println("OS name: \"" + Os.OS_NAME + "\" version: \"" + Os.OS_VERSION + "\" arch: \"" + + Os.OS_ARCH + "\" family: \"" + Os.OS_FAMILY + "\""); - } - catch ( IOException | IllegalAccessException e ) - { - System.err.println( "Unable to determine version from JAR file: " + e.getMessage() ); + } catch (IOException | IllegalAccessException e) { + System.err.println("Unable to determine version from JAR file: " + e.getMessage()); } } - private static void showFatalError( String message, Exception e, boolean show ) - { - System.err.println( "FATAL ERROR: " + message ); - if ( show ) - { - System.err.println( "Error stacktrace:" ); + private static void showFatalError(String message, Exception e, boolean show) { + System.err.println("FATAL ERROR: " + message); + if (show) { + System.err.println("Error stacktrace:"); e.printStackTrace(); - } - else - { - System.err.println( "For more information, run with the -e flag" ); + } else { + System.err.println("For more information, run with the -e flag"); } } } diff --git a/src/main/java/org/apache/maven/doxia/wrapper/AbstractFileWrapper.java b/src/main/java/org/apache/maven/doxia/wrapper/AbstractFileWrapper.java index 961542a..e3ebdcd 100644 --- a/src/main/java/org/apache/maven/doxia/wrapper/AbstractFileWrapper.java +++ b/src/main/java/org/apache/maven/doxia/wrapper/AbstractFileWrapper.java @@ -1,5 +1,3 @@ -package org.apache.maven.doxia.wrapper; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,15 +16,15 @@ package org.apache.maven.doxia.wrapper; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.doxia.wrapper; import java.io.File; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import java.util.Objects; -import org.codehaus.plexus.util.StringUtils; - import com.ibm.icu.text.CharsetDetector; +import org.codehaus.plexus.util.StringUtils; import static org.codehaus.plexus.util.StringUtils.isEmpty; import static org.codehaus.plexus.util.StringUtils.isNotEmpty; @@ -36,8 +34,7 @@ import static org.codehaus.plexus.util.StringUtils.isNotEmpty; * * @author <a href="mailto:[email protected]">Vincent Siveton</a> */ -abstract class AbstractFileWrapper -{ +abstract class AbstractFileWrapper { public static final String AUTO_ENCODING = "auto"; private File file; @@ -51,92 +48,76 @@ abstract class AbstractFileWrapper * @throws UnsupportedEncodingException if the encoding is unsupported. * @throws IllegalArgumentException if any */ - AbstractFileWrapper( String absolutePath, String encoding ) - throws UnsupportedEncodingException - { - if ( isEmpty( absolutePath ) ) - { - throw new IllegalArgumentException( "absolutePath is required" ); + AbstractFileWrapper(String absolutePath, String encoding) throws UnsupportedEncodingException { + if (isEmpty(absolutePath)) { + throw new IllegalArgumentException("absolutePath is required"); } - File filetoset = new File( absolutePath ); - if ( !filetoset.isAbsolute() ) - { - filetoset = new File( new File( "" ).getAbsolutePath(), absolutePath ); + File filetoset = new File(absolutePath); + if (!filetoset.isAbsolute()) { + filetoset = new File(new File("").getAbsolutePath(), absolutePath); } this.file = filetoset; - if ( isNotEmpty( encoding ) && !encoding.equalsIgnoreCase( encoding ) - && !Charset.isSupported( encoding ) ) - { - throw new UnsupportedEncodingException( "The encoding '" + encoding + if (isNotEmpty(encoding) && !encoding.equalsIgnoreCase(encoding) && !Charset.isSupported(encoding)) { + throw new UnsupportedEncodingException("The encoding '" + encoding + "' is not a valid one. The supported charsets are: " - + StringUtils.join( CharsetDetector.getAllDetectableCharsets(), ", " ) ); + + StringUtils.join(CharsetDetector.getAllDetectableCharsets(), ", ")); } - this.encoding = ( isNotEmpty( encoding ) ? encoding : AUTO_ENCODING ); + this.encoding = (isNotEmpty(encoding) ? encoding : AUTO_ENCODING); } /** * @return the file */ - public File getFile() - { + public File getFile() { return file; } /** * @param file new file. */ - void setFile( File file ) - { + void setFile(File file) { this.file = file; } /** * @return the encoding used for the file or <code>null</code> if not specified. */ - public String getEncoding() - { + public String getEncoding() { return encoding; } /** * @param encoding new encoding. */ - void setEncoding( String encoding ) - { + void setEncoding(String encoding) { this.encoding = encoding; } @Override - public boolean equals( Object o ) - { - if ( this == o ) - { + public boolean equals(Object o) { + if (this == o) { return true; } - if ( o == null || getClass() != o.getClass() ) - { + if (o == null || getClass() != o.getClass()) { return false; } - if ( !super.equals( o ) ) - { + if (!super.equals(o)) { return false; } AbstractFileWrapper that = (AbstractFileWrapper) o; - return Objects.equals( getFile(), that.getFile() ); + return Objects.equals(getFile(), that.getFile()); } @Override - public int hashCode() - { - return Objects.hash( super.hashCode(), getFile() ); + public int hashCode() { + return Objects.hash(super.hashCode(), getFile()); } /** {@inheritDoc} */ @Override - public java.lang.String toString() - { + public java.lang.String toString() { return super.toString() + "\n" + "file= '" + getFile() + "'"; } } diff --git a/src/main/java/org/apache/maven/doxia/wrapper/InputFileWrapper.java b/src/main/java/org/apache/maven/doxia/wrapper/InputFileWrapper.java index b88ed1c..a0dab50 100644 --- a/src/main/java/org/apache/maven/doxia/wrapper/InputFileWrapper.java +++ b/src/main/java/org/apache/maven/doxia/wrapper/InputFileWrapper.java @@ -1,5 +1,3 @@ -package org.apache.maven.doxia.wrapper; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ package org.apache.maven.doxia.wrapper; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.doxia.wrapper; import java.io.FileNotFoundException; import java.io.UnsupportedEncodingException; @@ -30,9 +29,7 @@ import org.codehaus.plexus.util.WriterFactory; * * @author <a href="mailto:[email protected]">Vincent Siveton</a> */ -public class InputFileWrapper - extends AbstractFileWrapper -{ +public class InputFileWrapper extends AbstractFileWrapper { /** serialVersionUID */ static final long serialVersionUID = 6510443036267371188L; @@ -47,15 +44,13 @@ public class InputFileWrapper * @throws UnsupportedEncodingException if the encoding is unsupported. * @throws FileNotFoundException if the file for absolutePath is not found. */ - private InputFileWrapper( String absolutePath, DefaultConverter.DoxiaFormat format, String charsetName ) - throws UnsupportedEncodingException, FileNotFoundException - { - super( absolutePath, charsetName ); + private InputFileWrapper(String absolutePath, DefaultConverter.DoxiaFormat format, String charsetName) + throws UnsupportedEncodingException, FileNotFoundException { + super(absolutePath, charsetName); this.format = format; - if ( !getFile().exists() ) - { - throw new FileNotFoundException( "The file '" + getFile().getAbsolutePath() + "' doesn't exist." ); + if (!getFile().exists()) { + throw new FileNotFoundException("The file '" + getFile().getAbsolutePath() + "' doesn't exist."); } } @@ -67,10 +62,9 @@ public class InputFileWrapper * @throws FileNotFoundException if the file for absolutePath is not found. * @see #valueOf(String, DefaultConverter.DoxiaFormat, String) using WriterFactory.UTF_8 */ - public static InputFileWrapper valueOf( String absolutePath, DefaultConverter.DoxiaFormat format ) - throws UnsupportedEncodingException, FileNotFoundException - { - return valueOf( absolutePath, format, WriterFactory.UTF_8 ); + public static InputFileWrapper valueOf(String absolutePath, DefaultConverter.DoxiaFormat format) + throws UnsupportedEncodingException, FileNotFoundException { + return valueOf(absolutePath, format, WriterFactory.UTF_8); } /** @@ -81,15 +75,12 @@ public class InputFileWrapper * @throws UnsupportedEncodingException if the encoding is unsupported. * @throws FileNotFoundException if the file for absolutePath is not found. */ - public static InputFileWrapper valueOf( String absolutePath, DefaultConverter.DoxiaFormat format, - String charsetName ) - throws UnsupportedEncodingException, FileNotFoundException - { - return new InputFileWrapper( absolutePath, format, charsetName ); + public static InputFileWrapper valueOf(String absolutePath, DefaultConverter.DoxiaFormat format, String charsetName) + throws UnsupportedEncodingException, FileNotFoundException { + return new InputFileWrapper(absolutePath, format, charsetName); } - public DefaultConverter.DoxiaFormat getFormat() - { + public DefaultConverter.DoxiaFormat getFormat() { return format; } } diff --git a/src/main/java/org/apache/maven/doxia/wrapper/InputReaderWrapper.java b/src/main/java/org/apache/maven/doxia/wrapper/InputReaderWrapper.java index 8c6c688..0d315b1 100644 --- a/src/main/java/org/apache/maven/doxia/wrapper/InputReaderWrapper.java +++ b/src/main/java/org/apache/maven/doxia/wrapper/InputReaderWrapper.java @@ -1,5 +1,3 @@ -package org.apache.maven.doxia.wrapper; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ package org.apache.maven.doxia.wrapper; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.doxia.wrapper; import java.io.Reader; @@ -28,8 +27,7 @@ import org.apache.maven.doxia.DefaultConverter; * * @author <a href="mailto:[email protected]">Vincent Siveton</a> */ -public class InputReaderWrapper -{ +public class InputReaderWrapper { /** serialVersionUID */ static final long serialVersionUID = 3260213754615748766L; @@ -44,13 +42,11 @@ public class InputReaderWrapper * @param supportedFormat not null * @throws IllegalArgumentException if the format equals AUTO_FORMAT. */ - private InputReaderWrapper( Reader reader, String format ) - { - this.format = DefaultConverter.DoxiaFormat.valueOf( format.toUpperCase() ); + private InputReaderWrapper(Reader reader, String format) { + this.format = DefaultConverter.DoxiaFormat.valueOf(format.toUpperCase()); - if ( reader == null ) - { - throw new IllegalArgumentException( "input reader is required" ); + if (reader == null) { + throw new IllegalArgumentException("input reader is required"); } this.reader = reader; } @@ -58,13 +54,11 @@ public class InputReaderWrapper /** * @return the reader */ - public Reader getReader() - { + public Reader getReader() { return this.reader; } - public DefaultConverter.DoxiaFormat getFormat() - { + public DefaultConverter.DoxiaFormat getFormat() { return format; } /** @@ -72,8 +66,7 @@ public class InputReaderWrapper * @param format not null * @return a type safe input reader */ - public static InputReaderWrapper valueOf( Reader reader, String format ) - { - return new InputReaderWrapper( reader, format ); + public static InputReaderWrapper valueOf(Reader reader, String format) { + return new InputReaderWrapper(reader, format); } } diff --git a/src/main/java/org/apache/maven/doxia/wrapper/OutputFileWrapper.java b/src/main/java/org/apache/maven/doxia/wrapper/OutputFileWrapper.java index 141839e..8039054 100644 --- a/src/main/java/org/apache/maven/doxia/wrapper/OutputFileWrapper.java +++ b/src/main/java/org/apache/maven/doxia/wrapper/OutputFileWrapper.java @@ -1,5 +1,3 @@ -package org.apache.maven.doxia.wrapper; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ package org.apache.maven.doxia.wrapper; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.doxia.wrapper; import java.io.UnsupportedEncodingException; import java.util.Objects; @@ -30,9 +29,7 @@ import org.codehaus.plexus.util.WriterFactory; * * @author <a href="mailto:[email protected]">Vincent Siveton</a> */ -public class OutputFileWrapper - extends AbstractFileWrapper -{ +public class OutputFileWrapper extends AbstractFileWrapper { /** serialVersionUID */ static final long serialVersionUID = 804499615902780116L; @@ -48,15 +45,13 @@ public class OutputFileWrapper * @throws IllegalArgumentException if any. * @throws UnsupportedEncodingException if the encoding is unsupported. */ - private OutputFileWrapper( String absolutePath, DefaultConverter.DoxiaFormat format, String charsetName ) - throws UnsupportedEncodingException - { - super( absolutePath, charsetName ); - this.format = Objects.requireNonNull( format, "format is required" ); + private OutputFileWrapper(String absolutePath, DefaultConverter.DoxiaFormat format, String charsetName) + throws UnsupportedEncodingException { + super(absolutePath, charsetName); + this.format = Objects.requireNonNull(format, "format is required"); } - public DefaultConverter.DoxiaFormat getFormat() - { + public DefaultConverter.DoxiaFormat getFormat() { return format; } @@ -66,10 +61,9 @@ public class OutputFileWrapper * @return a type safe output writer * @throws UnsupportedEncodingException if the encoding is unsupported. */ - public static OutputFileWrapper valueOf( String absolutePath, DefaultConverter.DoxiaFormat format ) - throws UnsupportedEncodingException - { - return valueOf( absolutePath, format, WriterFactory.UTF_8 ); + public static OutputFileWrapper valueOf(String absolutePath, DefaultConverter.DoxiaFormat format) + throws UnsupportedEncodingException { + return valueOf(absolutePath, format, WriterFactory.UTF_8); } /** @@ -79,10 +73,9 @@ public class OutputFileWrapper * @return a type safe output writer * @throws UnsupportedEncodingException if the encoding is unsupported. */ - public static OutputFileWrapper valueOf( String absolutePath, DefaultConverter.DoxiaFormat format, - String charsetName ) - throws UnsupportedEncodingException - { - return new OutputFileWrapper( absolutePath, format, charsetName ); + public static OutputFileWrapper valueOf( + String absolutePath, DefaultConverter.DoxiaFormat format, String charsetName) + throws UnsupportedEncodingException { + return new OutputFileWrapper(absolutePath, format, charsetName); } } diff --git a/src/main/java/org/apache/maven/doxia/wrapper/OutputStreamWrapper.java b/src/main/java/org/apache/maven/doxia/wrapper/OutputStreamWrapper.java index 6de7421..7c1c9bf 100644 --- a/src/main/java/org/apache/maven/doxia/wrapper/OutputStreamWrapper.java +++ b/src/main/java/org/apache/maven/doxia/wrapper/OutputStreamWrapper.java @@ -1,5 +1,3 @@ -package org.apache.maven.doxia.wrapper; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ package org.apache.maven.doxia.wrapper; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.doxia.wrapper; import java.io.OutputStream; import java.util.Objects; @@ -31,8 +30,7 @@ import static org.codehaus.plexus.util.StringUtils.isEmpty; * * @author <a href="mailto:[email protected]">Vincent Siveton</a> */ -public class OutputStreamWrapper -{ +public class OutputStreamWrapper { /** serialVersionUID */ static final long serialVersionUID = 3329037527245430610L; @@ -49,31 +47,27 @@ public class OutputStreamWrapper * @param supportedFormat not null * @throws IllegalArgumentException if any. */ - private OutputStreamWrapper( OutputStream out, String format, String encoding ) - { - this.format = DefaultConverter.DoxiaFormat.valueOf( format.toUpperCase() ); + private OutputStreamWrapper(OutputStream out, String format, String encoding) { + this.format = DefaultConverter.DoxiaFormat.valueOf(format.toUpperCase()); this.out = out; this.encoding = encoding; } - public DefaultConverter.DoxiaFormat getFormat() - { + public DefaultConverter.DoxiaFormat getFormat() { return format; } /** * @return the output stream */ - public OutputStream getOutputStream() - { + public OutputStream getOutputStream() { return this.out; } /** * @return the encoding */ - public String getEncoding() - { + public String getEncoding() { return encoding; } @@ -83,14 +77,12 @@ public class OutputStreamWrapper * @param encoding not null * @return a type safe output stream wrapper */ - public static OutputStreamWrapper valueOf( OutputStream out, String format, String encoding ) - { - Objects.requireNonNull( out, "output writer is required" ); - if ( isEmpty( format ) ) - { - throw new IllegalArgumentException( "output format is required" ); + public static OutputStreamWrapper valueOf(OutputStream out, String format, String encoding) { + Objects.requireNonNull(out, "output writer is required"); + if (isEmpty(format)) { + throw new IllegalArgumentException("output format is required"); } - return new OutputStreamWrapper( out, format, encoding ); + return new OutputStreamWrapper(out, format, encoding); } } diff --git a/src/test/java/org/apache/maven/doxia/ConverterTest.java b/src/test/java/org/apache/maven/doxia/ConverterTest.java index ab067fa..154a001 100644 --- a/src/test/java/org/apache/maven/doxia/ConverterTest.java +++ b/src/test/java/org/apache/maven/doxia/ConverterTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.doxia; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ package org.apache.maven.doxia; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.doxia; import java.io.ByteArrayOutputStream; import java.io.File; @@ -43,30 +42,24 @@ import org.codehaus.plexus.util.WriterFactory; * * @author <a href="mailto:[email protected]">Vincent Siveton</a> */ -public class ConverterTest - extends PlexusTestCase -{ +public class ConverterTest extends PlexusTestCase { private Converter converter; private boolean formatOutput; /** {@inheritDoc} */ @Override - protected void setUp() - throws Exception - { + protected void setUp() throws Exception { super.setUp(); converter = new DefaultConverter(); - formatOutput = Boolean.parseBoolean( System.getProperty( "format", "false" ) ); + formatOutput = Boolean.parseBoolean(System.getProperty("format", "false")); } /** {@inheritDoc} */ @Override - protected void tearDown() - throws Exception - { + protected void tearDown() throws Exception { super.tearDown(); converter = null; @@ -78,23 +71,19 @@ public class ConverterTest * @see Converter#convert(InputFileWrapper, OutputFileWrapper) * @throws Exception if any */ - public void testFileConverterWithInputFileOutputDir() - throws Exception - { + public void testFileConverterWithInputFileOutputDir() throws Exception { String in = getBasedir() + "/src/test/resources/unit/Doxia.htm"; String out = getBasedir() + "/target/unit/"; - InputFileWrapper input = - InputFileWrapper.valueOf( in, DoxiaFormat.XHTML, ReaderFactory.UTF_8 ); - OutputFileWrapper output = - OutputFileWrapper.valueOf( out, DoxiaFormat.APT, WriterFactory.UTF_8 ); + InputFileWrapper input = InputFileWrapper.valueOf(in, DoxiaFormat.XHTML, ReaderFactory.UTF_8); + OutputFileWrapper output = OutputFileWrapper.valueOf(out, DoxiaFormat.APT, WriterFactory.UTF_8); - converter.setFormatOutput( formatOutput ); - converter.convert( input, output ); - assertTrue( new File( out, "Doxia.apt" ).exists() ); - assertTrue( new File( out, "Doxia.apt" ).length() != 0 ); + converter.setFormatOutput(formatOutput); + converter.convert(input, output); + assertTrue(new File(out, "Doxia.apt").exists()); + assertTrue(new File(out, "Doxia.apt").length() != 0); - FileUtils.deleteDirectory( new File( getBasedir() + "/target/unit/" ) ); + FileUtils.deleteDirectory(new File(getBasedir() + "/target/unit/")); } /** @@ -103,25 +92,21 @@ public class ConverterTest * @see Converter#convert(InputFileWrapper, OutputFileWrapper) * @throws Exception if any */ - public void testFileConverterWithInputDirOutputDir() - throws Exception - { + public void testFileConverterWithInputDirOutputDir() throws Exception { String in = getBasedir() + "/src/test/resources/unit/apt"; String out = getBasedir() + "/target/unit/"; - InputFileWrapper input = - InputFileWrapper.valueOf( in, DoxiaFormat.APT, ReaderFactory.UTF_8 ); - OutputFileWrapper output = - OutputFileWrapper.valueOf( out, DoxiaFormat.MARKDOWN, WriterFactory.UTF_8 ); + InputFileWrapper input = InputFileWrapper.valueOf(in, DoxiaFormat.APT, ReaderFactory.UTF_8); + OutputFileWrapper output = OutputFileWrapper.valueOf(out, DoxiaFormat.MARKDOWN, WriterFactory.UTF_8); - converter.setFormatOutput( formatOutput ); - converter.convert( input, output ); - assertTrue( new File( out, "test.md" ).exists() ); - assertTrue( new File( out, "test.md" ).length() != 0 ); - assertTrue( new File( out, "child/test.md" ).exists() ); - assertTrue( new File( out, "child/test.md" ).length() != 0 ); + converter.setFormatOutput(formatOutput); + converter.convert(input, output); + assertTrue(new File(out, "test.md").exists()); + assertTrue(new File(out, "test.md").length() != 0); + assertTrue(new File(out, "child/test.md").exists()); + assertTrue(new File(out, "child/test.md").length() != 0); - FileUtils.deleteDirectory( new File( getBasedir() + "/target/unit/" ) ); + FileUtils.deleteDirectory(new File(getBasedir() + "/target/unit/")); } /** @@ -130,23 +115,19 @@ public class ConverterTest * @see Converter#convert(InputFileWrapper, OutputFileWrapper) * @throws Exception if any */ - public void testFileConverterWithInputFileOutputFile() - throws Exception - { + public void testFileConverterWithInputFileOutputFile() throws Exception { String in = getBasedir() + "/src/test/resources/unit/Doxia.htm"; String out = getBasedir() + "/target/unit/Doxia.apt"; - InputFileWrapper input = - InputFileWrapper.valueOf( in, DoxiaFormat.XHTML, ReaderFactory.UTF_8 ); - OutputFileWrapper output = - OutputFileWrapper.valueOf( out, DoxiaFormat.APT, WriterFactory.UTF_8 ); + InputFileWrapper input = InputFileWrapper.valueOf(in, DoxiaFormat.XHTML, ReaderFactory.UTF_8); + OutputFileWrapper output = OutputFileWrapper.valueOf(out, DoxiaFormat.APT, WriterFactory.UTF_8); - converter.setFormatOutput( formatOutput ); - converter.convert( input, output ); - assertTrue( new File( out ).exists() ); - assertTrue( new File( out ).length() != 0 ); + converter.setFormatOutput(formatOutput); + converter.convert(input, output); + assertTrue(new File(out).exists()); + assertTrue(new File(out).length() != 0); - FileUtils.deleteDirectory( new File( getBasedir() + "/target/unit/" ) ); + FileUtils.deleteDirectory(new File(getBasedir() + "/target/unit/")); } /** @@ -155,32 +136,28 @@ public class ConverterTest * @see Converter#convert(InputFileWrapper, OutputFileWrapper) * @throws Exception if any */ - public void testAptFileConverter() - throws Exception - { + public void testAptFileConverter() throws Exception { String in = getBasedir() + "/src/test/resources/unit/apt/test.apt"; String out = getBasedir() + "/target/unit/file/apt/test.apt.xhtml"; - InputFileWrapper input = - InputFileWrapper.valueOf( in, DoxiaFormat.APT, ReaderFactory.UTF_8 ); - OutputFileWrapper output = - OutputFileWrapper.valueOf( out, DoxiaFormat.XHTML, WriterFactory.UTF_8 ); + InputFileWrapper input = InputFileWrapper.valueOf(in, DoxiaFormat.APT, ReaderFactory.UTF_8); + OutputFileWrapper output = OutputFileWrapper.valueOf(out, DoxiaFormat.XHTML, WriterFactory.UTF_8); - converter.setFormatOutput( formatOutput ); - converter.convert( input, output ); - assertTrue( new File( out ).exists() ); - assertTrue( new File( out ).length() != 0 ); + converter.setFormatOutput(formatOutput); + converter.convert(input, output); + assertTrue(new File(out).exists()); + assertTrue(new File(out).length() != 0); in = getBasedir() + "/target/unit/file/apt/test.apt.xhtml"; out = getBasedir() + "/target/unit/file/apt/test.apt"; - input = InputFileWrapper.valueOf( in, DoxiaFormat.XHTML, ReaderFactory.UTF_8 ); - output = OutputFileWrapper.valueOf( out, DoxiaFormat.APT, WriterFactory.UTF_8 ); + input = InputFileWrapper.valueOf(in, DoxiaFormat.XHTML, ReaderFactory.UTF_8); + output = OutputFileWrapper.valueOf(out, DoxiaFormat.APT, WriterFactory.UTF_8); - converter.setFormatOutput( formatOutput ); - converter.convert( input, output ); - assertTrue( new File( out ).exists() ); - assertTrue( new File( out ).length() != 0 ); + converter.setFormatOutput(formatOutput); + converter.convert(input, output); + assertTrue(new File(out).exists()); + assertTrue(new File(out).length() != 0); } /** @@ -189,30 +166,26 @@ public class ConverterTest * @see Converter#convert(InputFileWrapper, OutputFileWrapper) * @throws Exception if any */ - public void testConfluenceFileConverter() - throws Exception - { + public void testConfluenceFileConverter() throws Exception { String in = getBasedir() + "/src/test/resources/unit/confluence/test.confluence"; String out = getBasedir() + "/target/unit/file/confluence/test.confluence.xhtml"; - InputFileWrapper input = - InputFileWrapper.valueOf( in, DoxiaFormat.CONFLUENCE, ReaderFactory.UTF_8 ); - OutputFileWrapper output = - OutputFileWrapper.valueOf( out, DoxiaFormat.XHTML, WriterFactory.UTF_8 ); + InputFileWrapper input = InputFileWrapper.valueOf(in, DoxiaFormat.CONFLUENCE, ReaderFactory.UTF_8); + OutputFileWrapper output = OutputFileWrapper.valueOf(out, DoxiaFormat.XHTML, WriterFactory.UTF_8); - converter.setFormatOutput( formatOutput ); - converter.convert( input, output ); - assertTrue( new File( out ).exists() ); - assertTrue( new File( out ).length() != 0 ); + converter.setFormatOutput(formatOutput); + converter.convert(input, output); + assertTrue(new File(out).exists()); + assertTrue(new File(out).length() != 0); in = getBasedir() + "/target/unit/file/confluence/test.confluence.xhtml"; out = getBasedir() + "/target/unit/file/confluence/test.confluence"; - input = InputFileWrapper.valueOf( in, DoxiaFormat.XHTML, ReaderFactory.UTF_8 ); - output = OutputFileWrapper.valueOf( out, DoxiaFormat.CONFLUENCE, WriterFactory.UTF_8 ); + input = InputFileWrapper.valueOf(in, DoxiaFormat.XHTML, ReaderFactory.UTF_8); + output = OutputFileWrapper.valueOf(out, DoxiaFormat.CONFLUENCE, WriterFactory.UTF_8); - converter.setFormatOutput( formatOutput ); - converter.convert( input, output ); + converter.setFormatOutput(formatOutput); + converter.convert(input, output); } /** @@ -221,31 +194,27 @@ public class ConverterTest * @see Converter#convert(InputFileWrapper, OutputFileWrapper) * @throws Exception if any */ - public void testDocbookFileConverter() - throws Exception - { + public void testDocbookFileConverter() throws Exception { String in = getBasedir() + "/src/test/resources/unit/docbook/test.xml"; String out = getBasedir() + "/target/unit/file/docbook/test.docbook.xhtml"; - InputFileWrapper input = - InputFileWrapper.valueOf( in, DoxiaFormat.DOCBOOK, ReaderFactory.UTF_8 ); - OutputFileWrapper output = - OutputFileWrapper.valueOf( out, DoxiaFormat.XHTML, WriterFactory.UTF_8 ); + InputFileWrapper input = InputFileWrapper.valueOf(in, DoxiaFormat.DOCBOOK, ReaderFactory.UTF_8); + OutputFileWrapper output = OutputFileWrapper.valueOf(out, DoxiaFormat.XHTML, WriterFactory.UTF_8); - converter.setFormatOutput( formatOutput ); - converter.convert( input, output ); - assertTrue( new File( out ).exists() ); - assertTrue( new File( out ).length() != 0 ); + converter.setFormatOutput(formatOutput); + converter.convert(input, output); + assertTrue(new File(out).exists()); + assertTrue(new File(out).length() != 0); - in = getBasedir() + "/target/unit/file/docbook/test.docbook.xhtml"; - out = getBasedir() + "/target/unit/file/docbook/test.docbook"; + in = getBasedir() + "/target/unit/file/docbook/test.docbook.xhtml"; + out = getBasedir() + "/target/unit/file/docbook/test.docbook"; - input = InputFileWrapper.valueOf( in, DoxiaFormat.XHTML ); - output = OutputFileWrapper.valueOf( out, DoxiaFormat.DOCBOOK ); + input = InputFileWrapper.valueOf(in, DoxiaFormat.XHTML); + output = OutputFileWrapper.valueOf(out, DoxiaFormat.DOCBOOK); - converter.setFormatOutput( formatOutput ); - converter.convert( input, output ); - assertTrue( new File( out ).exists() ); + converter.setFormatOutput(formatOutput); + converter.convert(input, output); + assertTrue(new File(out).exists()); } /** @@ -254,21 +223,17 @@ public class ConverterTest * @see Converter#convert(InputFileWrapper, OutputFileWrapper) * @throws Exception if any */ - public void testFmlFileConverter() - throws Exception - { + public void testFmlFileConverter() throws Exception { String in = getBasedir() + "/src/test/resources/unit/fml/test.fml"; String out = getBasedir() + "/target/unit/file/fml/test.fml.xhtml"; - InputFileWrapper input = - InputFileWrapper.valueOf( in, DoxiaFormat.FML, ReaderFactory.UTF_8 ); - OutputFileWrapper output = - OutputFileWrapper.valueOf( out, DoxiaFormat.XHTML, WriterFactory.UTF_8 ); + InputFileWrapper input = InputFileWrapper.valueOf(in, DoxiaFormat.FML, ReaderFactory.UTF_8); + OutputFileWrapper output = OutputFileWrapper.valueOf(out, DoxiaFormat.XHTML, WriterFactory.UTF_8); - converter.setFormatOutput( formatOutput ); - converter.convert( input, output ); - assertTrue( new File( out ).exists() ); - assertTrue( new File( out ).length() != 0 ); + converter.setFormatOutput(formatOutput); + converter.convert(input, output); + assertTrue(new File(out).exists()); + assertTrue(new File(out).length() != 0); // opposite conversion not supported } @@ -279,38 +244,30 @@ public class ConverterTest * @see Converter#convert(InputFileWrapper, OutputFileWrapper) * @throws Exception if any */ - public void testTwikiFileConverter() - throws Exception - { + public void testTwikiFileConverter() throws Exception { String in = getBasedir() + "/src/test/resources/unit/twiki/test.twiki"; String out = getBasedir() + "/target/unit/file/twiki/test.twiki.xhtml"; - InputFileWrapper input = - InputFileWrapper.valueOf( in, DoxiaFormat.TWIKI, ReaderFactory.UTF_8 ); - OutputFileWrapper output = - OutputFileWrapper.valueOf( out, DoxiaFormat.XHTML, WriterFactory.UTF_8 ); + InputFileWrapper input = InputFileWrapper.valueOf(in, DoxiaFormat.TWIKI, ReaderFactory.UTF_8); + OutputFileWrapper output = OutputFileWrapper.valueOf(out, DoxiaFormat.XHTML, WriterFactory.UTF_8); - converter.setFormatOutput( formatOutput ); - converter.convert( input, output ); - assertTrue( new File( out ).exists() ); - assertTrue( new File( out ).length() != 0 ); + converter.setFormatOutput(formatOutput); + converter.convert(input, output); + assertTrue(new File(out).exists()); + assertTrue(new File(out).length() != 0); in = getBasedir() + "/target/unit/file/twiki/test.twiki.xhtml"; out = getBasedir() + "/target/unit/file/twiki/test.twiki"; - input = InputFileWrapper.valueOf( in, DoxiaFormat.XHTML, ReaderFactory.UTF_8 ); - output = OutputFileWrapper.valueOf( out, DoxiaFormat.TWIKI, WriterFactory.UTF_8 ); + input = InputFileWrapper.valueOf(in, DoxiaFormat.XHTML, ReaderFactory.UTF_8); + output = OutputFileWrapper.valueOf(out, DoxiaFormat.TWIKI, WriterFactory.UTF_8); - converter.setFormatOutput( formatOutput ); - try - { - converter.convert( input, output ); - } - catch ( ConverterException e ) - { + converter.setFormatOutput(formatOutput); + try { + converter.convert(input, output); + } catch (ConverterException e) { // The TWiki parser is wrong for * <pre>some text</pre> - if ( !e.getMessage().contains( "Error validating the model" ) ) - { + if (!e.getMessage().contains("Error validating the model")) { throw e; } } @@ -322,32 +279,28 @@ public class ConverterTest * @see Converter#convert(InputFileWrapper, OutputFileWrapper) * @throws Exception if any */ - public void testXdocFileConverter() - throws Exception - { + public void testXdocFileConverter() throws Exception { String in = getBasedir() + "/src/test/resources/unit/xdoc/test.xml"; String out = getBasedir() + "/target/unit/file/xdoc/test.xdoc.xhtml"; - InputFileWrapper input = - InputFileWrapper.valueOf( in, DoxiaFormat.XDOC, ReaderFactory.UTF_8 ); - OutputFileWrapper output = - OutputFileWrapper.valueOf( out, DoxiaFormat.XHTML, WriterFactory.UTF_8 ); + InputFileWrapper input = InputFileWrapper.valueOf(in, DoxiaFormat.XDOC, ReaderFactory.UTF_8); + OutputFileWrapper output = OutputFileWrapper.valueOf(out, DoxiaFormat.XHTML, WriterFactory.UTF_8); - converter.setFormatOutput( formatOutput ); - converter.convert( input, output ); - assertTrue( new File( out ).exists() ); - assertTrue( new File( out ).length() != 0 ); + converter.setFormatOutput(formatOutput); + converter.convert(input, output); + assertTrue(new File(out).exists()); + assertTrue(new File(out).length() != 0); in = getBasedir() + "/target/unit/file/xdoc/test.xdoc.xhtml"; out = getBasedir() + "/target/unit/file/xdoc/test.xdoc"; - input = InputFileWrapper.valueOf( in, DoxiaFormat.XHTML, ReaderFactory.UTF_8 ); - output = OutputFileWrapper.valueOf( out, DoxiaFormat.XDOC, WriterFactory.UTF_8 ); + input = InputFileWrapper.valueOf(in, DoxiaFormat.XHTML, ReaderFactory.UTF_8); + output = OutputFileWrapper.valueOf(out, DoxiaFormat.XDOC, WriterFactory.UTF_8); - converter.setFormatOutput( formatOutput ); - converter.convert( input, output ); - assertTrue( new File( out ).exists() ); - assertTrue( new File( out ).length() != 0 ); + converter.setFormatOutput(formatOutput); + converter.convert(input, output); + assertTrue(new File(out).exists()); + assertTrue(new File(out).length() != 0); } /** @@ -356,32 +309,28 @@ public class ConverterTest * @see Converter#convert(InputFileWrapper, OutputFileWrapper) * @throws Exception if any */ - public void testXhtmlFileConverter() - throws Exception - { + public void testXhtmlFileConverter() throws Exception { String in = getBasedir() + "/src/test/resources/unit/xhtml/test.xhtml"; String out = getBasedir() + "/target/unit/file/xhtml/test.xhtml.xhtml"; - InputFileWrapper input = - InputFileWrapper.valueOf( in, DoxiaFormat.XHTML, ReaderFactory.UTF_8 ); - OutputFileWrapper output = - OutputFileWrapper.valueOf( out, DoxiaFormat.XHTML, WriterFactory.UTF_8 ); + InputFileWrapper input = InputFileWrapper.valueOf(in, DoxiaFormat.XHTML, ReaderFactory.UTF_8); + OutputFileWrapper output = OutputFileWrapper.valueOf(out, DoxiaFormat.XHTML, WriterFactory.UTF_8); - converter.setFormatOutput( formatOutput ); - converter.convert( input, output ); - assertTrue( new File( out ).exists() ); - assertTrue( new File( out ).length() != 0 ); + converter.setFormatOutput(formatOutput); + converter.convert(input, output); + assertTrue(new File(out).exists()); + assertTrue(new File(out).length() != 0); in = getBasedir() + "/target/unit/file/xhtml/test.xhtml.xhtml"; out = getBasedir() + "/target/unit/file/xhtml/test.xhtml"; - input = InputFileWrapper.valueOf( in, DoxiaFormat.XHTML, ReaderFactory.UTF_8 ); - output = OutputFileWrapper.valueOf( out, DoxiaFormat.XHTML, WriterFactory.UTF_8 ); + input = InputFileWrapper.valueOf(in, DoxiaFormat.XHTML, ReaderFactory.UTF_8); + output = OutputFileWrapper.valueOf(out, DoxiaFormat.XHTML, WriterFactory.UTF_8); - converter.setFormatOutput( formatOutput ); - converter.convert( input, output ); - assertTrue( new File( out ).exists() ); - assertTrue( new File( out ).length() != 0 ); + converter.setFormatOutput(formatOutput); + converter.convert(input, output); + assertTrue(new File(out).exists()); + assertTrue(new File(out).length() != 0); } /** * Input xhtml5 file / output dir @@ -389,32 +338,28 @@ public class ConverterTest * @see Converter#convert(InputFileWrapper, OutputFileWrapper) * @throws Exception if any */ - public void testXhtml5FileConverter() - throws Exception - { + public void testXhtml5FileConverter() throws Exception { String in = getBasedir() + "/src/test/resources/unit/xhtml/test.xhtml5"; String out = getBasedir() + "/target/unit/file/xhtml/test.xhtml.xhtml5"; - InputFileWrapper input = - InputFileWrapper.valueOf( in, DoxiaFormat.XHTML5, ReaderFactory.UTF_8 ); - OutputFileWrapper output = - OutputFileWrapper.valueOf( out, DoxiaFormat.XHTML5, WriterFactory.UTF_8 ); + InputFileWrapper input = InputFileWrapper.valueOf(in, DoxiaFormat.XHTML5, ReaderFactory.UTF_8); + OutputFileWrapper output = OutputFileWrapper.valueOf(out, DoxiaFormat.XHTML5, WriterFactory.UTF_8); - converter.setFormatOutput( formatOutput ); - converter.convert( input, output ); - assertTrue( new File( out ).exists() ); - assertTrue( new File( out ).length() != 0 ); + converter.setFormatOutput(formatOutput); + converter.convert(input, output); + assertTrue(new File(out).exists()); + assertTrue(new File(out).length() != 0); in = getBasedir() + "/target/unit/file/xhtml/test.xhtml.xhtml5"; out = getBasedir() + "/target/unit/file/xhtml/test.xhtml5"; - input = InputFileWrapper.valueOf( in, DoxiaFormat.XHTML5, ReaderFactory.UTF_8 ); - output = OutputFileWrapper.valueOf( out, DoxiaFormat.XHTML5, WriterFactory.UTF_8 ); + input = InputFileWrapper.valueOf(in, DoxiaFormat.XHTML5, ReaderFactory.UTF_8); + output = OutputFileWrapper.valueOf(out, DoxiaFormat.XHTML5, WriterFactory.UTF_8); - converter.setFormatOutput( formatOutput ); - converter.convert( input, output ); - assertTrue( new File( out ).exists() ); - assertTrue( new File( out ).length() != 0 ); + converter.setFormatOutput(formatOutput); + converter.convert(input, output); + assertTrue(new File(out).exists()); + assertTrue(new File(out).length() != 0); } /** @@ -423,33 +368,30 @@ public class ConverterTest * @see Converter#convert(InputReaderWrapper, OutputStreamWrapper) * @throws Exception if any */ - public void testAptWriterConverter() - throws Exception - { + public void testAptWriterConverter() throws Exception { String in = getBasedir() + "/src/test/resources/unit/apt/test.apt"; String from = "apt"; String out = getBasedir() + "/target/unit/writer/apt/test.apt.xhtml"; String to = "xhtml"; - File inFile = new File( in ); - File outFile = new File( out ); + File inFile = new File(in); + File outFile = new File(out); outFile.getParentFile().mkdirs(); - try ( OutputStream fo = new FileOutputStream( outFile ) ) - { + try (OutputStream fo = new FileOutputStream(outFile)) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - InputReaderWrapper input = InputReaderWrapper.valueOf( new FileReader( inFile ), from ); - OutputStreamWrapper output = OutputStreamWrapper.valueOf( outputStream, to, "UTF-8" ); + InputReaderWrapper input = InputReaderWrapper.valueOf(new FileReader(inFile), from); + OutputStreamWrapper output = OutputStreamWrapper.valueOf(outputStream, to, "UTF-8"); - converter.setFormatOutput( formatOutput ); - converter.convert( input, output ); + converter.setFormatOutput(formatOutput); + converter.convert(input, output); - IOUtil.copy( outputStream.toByteArray(), fo ); + IOUtil.copy(outputStream.toByteArray(), fo); } - assertTrue( outFile.exists() ); - assertTrue( outFile.length() != 0 ); + assertTrue(outFile.exists()); + assertTrue(outFile.length() != 0); } /** @@ -458,33 +400,30 @@ public class ConverterTest * @see Converter#convert(InputReaderWrapper, OutputStreamWrapper) * @throws Exception if any */ - public void testConfluenceWriterConverter() - throws Exception - { + public void testConfluenceWriterConverter() throws Exception { String in = getBasedir() + "/src/test/resources/unit/confluence/test.confluence"; String from = "confluence"; String out = getBasedir() + "/target/unit/writer/confluence/test.confluence.xhtml"; String to = "xhtml"; - File inFile = new File( in ); - File outFile = new File( out ); + File inFile = new File(in); + File outFile = new File(out); outFile.getParentFile().mkdirs(); - try ( OutputStream fo = new FileOutputStream( outFile ) ) - { + try (OutputStream fo = new FileOutputStream(outFile)) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - InputReaderWrapper input = InputReaderWrapper.valueOf( new FileReader( inFile ), from ); - OutputStreamWrapper output = OutputStreamWrapper.valueOf( outputStream, to, "UTF-8" ); + InputReaderWrapper input = InputReaderWrapper.valueOf(new FileReader(inFile), from); + OutputStreamWrapper output = OutputStreamWrapper.valueOf(outputStream, to, "UTF-8"); - converter.setFormatOutput( formatOutput ); - converter.convert( input, output ); + converter.setFormatOutput(formatOutput); + converter.convert(input, output); - IOUtil.copy( outputStream.toByteArray(), fo ); + IOUtil.copy(outputStream.toByteArray(), fo); } - assertTrue( outFile.exists() ); - assertTrue( outFile.length() != 0 ); + assertTrue(outFile.exists()); + assertTrue(outFile.length() != 0); } /** @@ -493,166 +432,143 @@ public class ConverterTest * @see Converter#convert(InputReaderWrapper, OutputStreamWrapper) * @throws Exception if any */ - public void testAutoDetectConverter() - throws Exception - { + public void testAutoDetectConverter() throws Exception { String in = getBasedir() + "/src/test/resources/unit/xdoc/test.xml"; String out = getBasedir() + "/target/unit/writer/apt/test.xdoc.apt"; - File inFile = new File( in ); - File outFile = new File( out ); + File inFile = new File(in); + File outFile = new File(out); outFile.getParentFile().mkdirs(); - try (FileWriter fw = new FileWriter( outFile )) - { + try (FileWriter fw = new FileWriter(outFile)) { StringWriter writer = new StringWriter(); InputFileWrapper input = - InputFileWrapper.valueOf( inFile.getAbsolutePath(), DoxiaFormat.autoDetectFormat( inFile ) ); - OutputFileWrapper output = - OutputFileWrapper.valueOf( outFile.getAbsolutePath(), DoxiaFormat.XHTML ); + InputFileWrapper.valueOf(inFile.getAbsolutePath(), DoxiaFormat.autoDetectFormat(inFile)); + OutputFileWrapper output = OutputFileWrapper.valueOf(outFile.getAbsolutePath(), DoxiaFormat.XHTML); - converter.setFormatOutput( formatOutput ); - converter.convert( input, output ); + converter.setFormatOutput(formatOutput); + converter.convert(input, output); - IOUtil.copy( writer.toString(), fw ); + IOUtil.copy(writer.toString(), fw); - assertTrue( outFile.exists() ); - assertTrue( outFile.length() != 0 ); + assertTrue(outFile.exists()); + assertTrue(outFile.length() != 0); } in = getBasedir() + "/src/test/resources/unit/apt/test.apt"; out = getBasedir() + "/target/unit/writer/apt/test.apt.xhtml"; - inFile = new File( in ); - outFile = new File( out ); + inFile = new File(in); + outFile = new File(out); outFile.getParentFile().mkdirs(); - try (FileWriter fw = new FileWriter( outFile )) - { + try (FileWriter fw = new FileWriter(outFile)) { StringWriter writer = new StringWriter(); InputFileWrapper input = - InputFileWrapper.valueOf( inFile.getAbsolutePath(), DoxiaFormat.autoDetectFormat( inFile ) ); - OutputFileWrapper output = - OutputFileWrapper.valueOf( outFile.getAbsolutePath(), DoxiaFormat.XHTML ); + InputFileWrapper.valueOf(inFile.getAbsolutePath(), DoxiaFormat.autoDetectFormat(inFile)); + OutputFileWrapper output = OutputFileWrapper.valueOf(outFile.getAbsolutePath(), DoxiaFormat.XHTML); - converter.setFormatOutput( formatOutput ); - converter.convert( input, output ); + converter.setFormatOutput(formatOutput); + converter.convert(input, output); - IOUtil.copy( writer.toString(), fw ); + IOUtil.copy(writer.toString(), fw); - assertTrue( outFile.exists() ); - assertTrue( outFile.length() != 0 ); + assertTrue(outFile.exists()); + assertTrue(outFile.length() != 0); } in = getBasedir() + "/src/test/resources/unit/apt/test.unknown"; out = getBasedir() + "/target/unit/writer/apt/test.apt.xhtml"; - inFile = new File( in ); - outFile = new File( out ); + inFile = new File(in); + outFile = new File(out); outFile.getParentFile().mkdirs(); - try (FileWriter fw = new FileWriter( outFile )) - { + try (FileWriter fw = new FileWriter(outFile)) { InputFileWrapper input = - InputFileWrapper.valueOf( inFile.getAbsolutePath(), DoxiaFormat.autoDetectFormat( inFile ) ); - OutputFileWrapper output = - OutputFileWrapper.valueOf( outFile.getAbsolutePath(), DoxiaFormat.XHTML ); + InputFileWrapper.valueOf(inFile.getAbsolutePath(), DoxiaFormat.autoDetectFormat(inFile)); + OutputFileWrapper output = OutputFileWrapper.valueOf(outFile.getAbsolutePath(), DoxiaFormat.XHTML); - converter.setFormatOutput( formatOutput ); - converter.convert( input, output ); + converter.setFormatOutput(formatOutput); + converter.convert(input, output); fail(); - } - catch ( UnsupportedOperationException e ) - { - assertTrue( true ); + } catch (UnsupportedOperationException e) { + assertTrue(true); } in = getBasedir() + "/src/test/resources/unit/xhtml/test.xhtml5"; out = getBasedir() + "/target/unit/writer/xhtml/test.html5.xhtml5"; - inFile = new File( in ); - outFile = new File( out ); + inFile = new File(in); + outFile = new File(out); outFile.getParentFile().mkdirs(); - try (FileWriter fw = new FileWriter( outFile )) - { + try (FileWriter fw = new FileWriter(outFile)) { StringWriter writer = new StringWriter(); InputFileWrapper input = - InputFileWrapper.valueOf( inFile.getAbsolutePath(), DoxiaFormat.autoDetectFormat( inFile ) ); - OutputFileWrapper output = - OutputFileWrapper.valueOf( outFile.getAbsolutePath(), DoxiaFormat.XHTML5 ); + InputFileWrapper.valueOf(inFile.getAbsolutePath(), DoxiaFormat.autoDetectFormat(inFile)); + OutputFileWrapper output = OutputFileWrapper.valueOf(outFile.getAbsolutePath(), DoxiaFormat.XHTML5); - converter.setFormatOutput( formatOutput ); - converter.convert( input, output ); + converter.setFormatOutput(formatOutput); + converter.convert(input, output); - IOUtil.copy( writer.toString(), fw ); + IOUtil.copy(writer.toString(), fw); - assertTrue( outFile.exists() ); - assertTrue( outFile.length() != 0 ); + assertTrue(outFile.exists()); + assertTrue(outFile.length() != 0); } - - } - private String autoDetectEncoding( File f ) - { - return DefaultConverter.autoDetectEncoding( f ); + private String autoDetectEncoding(File f) { + return DefaultConverter.autoDetectEncoding(f); } - private String autoDetectEncoding( String filename ) - { - return autoDetectEncoding( new File( getBasedir() + "/src/test/resources/unit/" + filename ) ); + private String autoDetectEncoding(String filename) { + return autoDetectEncoding(new File(getBasedir() + "/src/test/resources/unit/" + filename)); } /** * Test {@link DefaultConverter#autoDetectEncoding(File)} */ - public void testAutodetectEncoding() - { - assertEquals( "ISO-8859-1", autoDetectEncoding( "apt/test.apt" ) ); - assertEquals( "ISO-8859-1", autoDetectEncoding( "confluence/test.confluence" ) ); - assertEquals( "UTF-8", autoDetectEncoding( "docbook/test.xml" ) ); - assertEquals( "UTF-8", autoDetectEncoding( "fml/test.fml" ) ); // plexus-utils should detect ISO-8859-1 - assertEquals( "ISO-8859-1", autoDetectEncoding( "twiki/test.twiki" ) ); - assertEquals( "UTF-8", autoDetectEncoding( "xhtml/test.xhtml" ) ); + public void testAutodetectEncoding() { + assertEquals("ISO-8859-1", autoDetectEncoding("apt/test.apt")); + assertEquals("ISO-8859-1", autoDetectEncoding("confluence/test.confluence")); + assertEquals("UTF-8", autoDetectEncoding("docbook/test.xml")); + assertEquals("UTF-8", autoDetectEncoding("fml/test.fml")); // plexus-utils should detect ISO-8859-1 + assertEquals("ISO-8859-1", autoDetectEncoding("twiki/test.twiki")); + assertEquals("UTF-8", autoDetectEncoding("xhtml/test.xhtml")); } - private DoxiaFormat autoDetectFormat( File f ) - { - return DefaultConverter.DoxiaFormat.autoDetectFormat( f ); + private DoxiaFormat autoDetectFormat(File f) { + return DefaultConverter.DoxiaFormat.autoDetectFormat(f); } - private DoxiaFormat autoDetectFormat( String filename ) - { - return autoDetectFormat( new File( getBasedir() + "/src/test/resources/unit/" + filename ) ); + private DoxiaFormat autoDetectFormat(String filename) { + return autoDetectFormat(new File(getBasedir() + "/src/test/resources/unit/" + filename)); } /** * Test {@link DefaultConverter.DoxiaFormat#autoDetectFormat(File)} * */ - public void testAutodetectFormat() - { - assertEquals( autoDetectFormat( "apt/test.apt" ), DoxiaFormat.APT ); + public void testAutodetectFormat() { + assertEquals(autoDetectFormat("apt/test.apt"), DoxiaFormat.APT); - try - { - autoDetectFormat( "apt/test.unknown" ); + try { + autoDetectFormat("apt/test.unknown"); fail(); - } - catch ( UnsupportedOperationException e ) - { - assertTrue( true ); + } catch (UnsupportedOperationException e) { + assertTrue(true); } - assertEquals( autoDetectFormat( "confluence/test.confluence" ), DoxiaFormat.CONFLUENCE ); - assertEquals( autoDetectFormat( "docbook/test.xml" ), DoxiaFormat.DOCBOOK ); - assertEquals( autoDetectFormat( "fml/test.fml" ), DoxiaFormat.FML ); - assertEquals( autoDetectFormat( "twiki/test.twiki" ), DoxiaFormat.TWIKI ); - assertEquals( autoDetectFormat( "xhtml/test.xhtml" ), DoxiaFormat.XHTML ); + assertEquals(autoDetectFormat("confluence/test.confluence"), DoxiaFormat.CONFLUENCE); + assertEquals(autoDetectFormat("docbook/test.xml"), DoxiaFormat.DOCBOOK); + assertEquals(autoDetectFormat("fml/test.fml"), DoxiaFormat.FML); + assertEquals(autoDetectFormat("twiki/test.twiki"), DoxiaFormat.TWIKI); + assertEquals(autoDetectFormat("xhtml/test.xhtml"), DoxiaFormat.XHTML); } }
