diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriter.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriter.java index a9df0cd..95a5a04 100644 --- a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriter.java +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriter.java @@ -93,10 +93,10 @@ class CheckstyleWriter implements CommandLineRunner { log.info("Writing xmlFile: {}", xmlFile); Files.write(xmlFile, output, StandardCharsets.UTF_8); } else { - throw new IOException("Missing template: " + checkstyleXmlTemplate.toString()); + throw new TemplateNotFoundException(checkstyleXmlTemplate); } } catch (IOException e) { - throw new RuntimeException(e); + throw new CheckstyleWriterException(e); } } diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterException.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterException.java new file mode 100644 index 0000000..641d96e --- /dev/null +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterException.java @@ -0,0 +1,39 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017 Paul Campbell + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies + * or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE + * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package net.kemitix.checkstyle.ruleset.builder; + +/** + * Raised when there was an error writing a Checkstyle ruleset. + * + * @author Paul Campbell (pcampbell@kemitix.net) + */ +class CheckstyleWriterException extends RuntimeException { + + /** + * Constructor. + * + * @param cause the cause + */ + CheckstyleWriterException(final Throwable cause) { + super(cause); + } +} diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/TemplateNotFoundException.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/TemplateNotFoundException.java new file mode 100644 index 0000000..08d1521 --- /dev/null +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/TemplateNotFoundException.java @@ -0,0 +1,41 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017 Paul Campbell + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies + * or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE + * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package net.kemitix.checkstyle.ruleset.builder; + +import java.nio.file.Path; + +/** + * Raised when a rule template is not found. + * + * @author Paul Campbell (pcampbell@kemitix.net) + */ +class TemplateNotFoundException extends RuntimeException { + + /** + * Constructor. + * + * @param template the missing template + */ + TemplateNotFoundException(final Path template) { + super("Missing template: " + template.toString()); + } +} diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterTest.java index a409d3d..1ad7836 100644 --- a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterTest.java +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/CheckstyleWriterTest.java @@ -2,6 +2,7 @@ package net.kemitix.checkstyle.ruleset.builder; import lombok.val; import me.andrz.builder.map.MapBuilder; +import org.assertj.core.api.ThrowableAssert; import org.junit.Before; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -20,6 +21,7 @@ import java.util.List; import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.BDDMockito.given; import static org.mockito.Matchers.any; @@ -56,8 +58,6 @@ public class CheckstyleWriterTest { private Path outputDirectory; - private Path checkstyleTemplate; - @Mock private RuleClassLocator ruleClassLocator; @@ -78,8 +78,8 @@ public class CheckstyleWriterTest { .toPath(); outputProperties.setDirectory(outputDirectory); templateProperties = new TemplateProperties(); - checkstyleTemplate = folder.newFile("checkstyle-template.xml") - .toPath(); + val checkstyleTemplate = folder.newFile("checkstyle-template.xml") + .toPath(); Files.write( checkstyleTemplate, TEMPLATE.getBytes(StandardCharsets.UTF_8), StandardOpenOption.TRUNCATE_EXISTING); templateProperties.setCheckstyleXml(checkstyleTemplate); @@ -204,10 +204,11 @@ public class CheckstyleWriterTest { public void throwRteIfTemplateNotFound() throws Exception { //given templateProperties.setCheckstyleXml(Paths.get("garbage")); - exception.expect(RuntimeException.class); - exception.expectMessage("Missing template: garbage"); //when - checkstyleWriter.run(); + final ThrowableAssert.ThrowingCallable action = () -> checkstyleWriter.run(); + //then + assertThatThrownBy(action).isInstanceOf(TemplateNotFoundException.class) + .hasMessage("Missing template: garbage"); } // throw RTE if error writing file @@ -216,10 +217,13 @@ public class CheckstyleWriterTest { //given final String imaginary = String.join(FILE_SEPARATOR, "", "..", "imaginary"); outputProperties.setDirectory(Paths.get(imaginary)); - exception.expect(RuntimeException.class); - exception.expectMessage( - "java.nio.file.NoSuchFileException: " + imaginary + FILE_SEPARATOR + "checkstyle-LAYOUT.xml"); //when - checkstyleWriter.run(); + final ThrowableAssert.ThrowingCallable action = () -> checkstyleWriter.run(); + //then + assertThatThrownBy(action).isInstanceOf(CheckstyleWriterException.class) + .hasMessage( + String.format("java.nio.file.NoSuchFileException: %scheckstyle-LAYOUT.xml", + imaginary + FILE_SEPARATOR + )); } } diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleReadmeLoaderTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleReadmeLoaderTest.java index 708d4d2..f7a05f2 100644 --- a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleReadmeLoaderTest.java +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/DefaultRuleReadmeLoaderTest.java @@ -23,12 +23,8 @@ public class DefaultRuleReadmeLoaderTest { private RuleReadmeLoader loader; - private TemplateProperties templateProperties; - private Rule rule; - private Path fragment; - private Path fragments; @org.junit.Rule @@ -39,7 +35,7 @@ public class DefaultRuleReadmeLoaderTest { @Before public void setUp() throws Exception { - templateProperties = new TemplateProperties(); + final TemplateProperties templateProperties = new TemplateProperties(); fragments = folder.newFolder("fragments") .toPath(); templateProperties.setReadmeFragments(fragments); @@ -53,8 +49,8 @@ public class DefaultRuleReadmeLoaderTest { public void loadEnabledOkay() throws IOException { //given rule.setEnabled(true); - fragment = fragments.resolve("name.md"); - Files.write(fragment, Arrays.asList("", "body")); + final Path fragment1 = fragments.resolve("name.md"); + Files.write(fragment1, Arrays.asList("", "body")); //when val fragment = loader.load(rule); //then diff --git a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriterTest.java b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriterTest.java index bc45598..51ad769 100644 --- a/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriterTest.java +++ b/builder/src/test/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriterTest.java @@ -25,10 +25,6 @@ public class ReadmeWriterTest { private ReadmeWriter readmeWriter; - private TemplateProperties templateProperties; - - private OutputProperties outputProperties; - private RulesProperties rulesProperties; @Mock @@ -37,10 +33,6 @@ public class ReadmeWriterTest { @Mock private ReadmeIndexBuilder indexBuilder; - private Path template; - - private Path fragments; - private Path readme; @org.junit.Rule @@ -49,17 +41,17 @@ public class ReadmeWriterTest { @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - template = folder.newFile("README-template.md") - .toPath(); + final Path template = folder.newFile("README-template.md") + .toPath(); Files.write(template, Arrays.asList("i:%s", "ce:%s", "se:%s", "cd:%s", "sd:%s")); - fragments = folder.newFolder("fragments") - .toPath(); + final TemplateProperties templateProperties = new TemplateProperties(); + templateProperties.setReadmeTemplate(template); + final Path fragments = folder.newFolder("fragments") + .toPath(); + templateProperties.setReadmeFragments(fragments); + final OutputProperties outputProperties = new OutputProperties(); readme = folder.newFile("README.md") .toPath(); - templateProperties = new TemplateProperties(); - templateProperties.setReadmeTemplate(template); - templateProperties.setReadmeFragments(fragments); - outputProperties = new OutputProperties(); outputProperties.setReadme(readme); rulesProperties = new RulesProperties(); readmeWriter = diff --git a/plugin/src/test/java/net/kemitix/checkstyle/ruleset/plugin/DefaultCheckstyleExecutorTest.java b/plugin/src/test/java/net/kemitix/checkstyle/ruleset/plugin/DefaultCheckstyleExecutorTest.java index b230eeb..8abc7b1 100644 --- a/plugin/src/test/java/net/kemitix/checkstyle/ruleset/plugin/DefaultCheckstyleExecutorTest.java +++ b/plugin/src/test/java/net/kemitix/checkstyle/ruleset/plugin/DefaultCheckstyleExecutorTest.java @@ -72,8 +72,6 @@ public class DefaultCheckstyleExecutorTest { @Mock private Artifact artifact; - private File artifactFile; - @Mock private MavenXpp3Reader mavenXpp3Reader; @@ -122,8 +120,8 @@ public class DefaultCheckstyleExecutorTest { .level(level) .build(); - artifactFile = folder.newFile("pom.xml"); given(artifactRepository.find(any())).willReturn(artifact); + final File artifactFile = folder.newFile("pom.xml"); given(artifact.getFile()).willReturn(artifactFile); given(mavenXpp3Reader.read(any(FileReader.class))).willReturn(pomModel); final Properties properties = new Properties(); diff --git a/regressions/src/main/java/net/kemitix/checkstyle/regressions/MoveVariableInsideIf.java b/regressions/src/main/java/net/kemitix/checkstyle/regressions/MoveVariableInsideIf.java index bfdb49d..6e6151f 100644 --- a/regressions/src/main/java/net/kemitix/checkstyle/regressions/MoveVariableInsideIf.java +++ b/regressions/src/main/java/net/kemitix/checkstyle/regressions/MoveVariableInsideIf.java @@ -33,7 +33,7 @@ class MoveVariableInsideIf { private boolean condition; private String method(final String variable) { - return "value"; + return "value: " + variable; } /** @@ -42,7 +42,7 @@ class MoveVariableInsideIf { * @return value */ @SuppressWarnings("movevariableinsideif") - String invalid() { + protected String invalid() { String variable = input.substring(1); if (condition) { return method(variable); @@ -55,7 +55,7 @@ class MoveVariableInsideIf { * * @return value */ - String valid() { + protected String valid() { if (condition) { String variable = input.substring(1); return method(variable); diff --git a/shippable.yml b/shippable.yml new file mode 100644 index 0000000..3d074c8 --- /dev/null +++ b/shippable.yml @@ -0,0 +1,8 @@ +language: java +jdk: +- oraclejdk8 +cache: + directories: + - "$HOME/.m2" +install: true +script: "./mvnw clean install" diff --git a/travis-ci/travis-coveralls-report.sh b/travis-ci/travis-coveralls-report.sh index 5ef727d..aab1704 100755 --- a/travis-ci/travis-coveralls-report.sh +++ b/travis-ci/travis-coveralls-report.sh @@ -1,7 +1,3 @@ #!/usr/bin/env bash -## Only send coveralls reports from Travis-CI. Some CIs, like Shippable, lie by setting TRAVIS=true. -## Currently, Shippable, does not set TRAVIS_LANGUAGE, but Travis-CI does. -if [ "$TRAVIS_LANGUAGE" = "java" ];then - ./mvnw --projects builder,plugin test jacoco:report coveralls:report -fi +./mvnw --projects builder,plugin test jacoco:report coveralls:report