Merge branch 'develop' into upgrade-checkstyle
* develop: wercker.yml: rewritten wercker.yml: added travis-ci: remove defensive checks shippable.yml: added travis-ci: only deploy from Travis-CI KCR37+38: MoveVariableInsideIf: avoid unused private methods KCR39: regressions: MoveVariableInsideIf: method(): use parameter KCR38: regressions: MoveVariableInsideIf: valid(): use explicit scope KCR37: regressions: MoveVariableInsideIf: invalid(): use explicit scope KXR36: plugin: DefaultCheckstyleExecutorTest: artifactFile: make local variable builder: ReadmeWriterTest: templateProperties: make local variable KCR35: builder: ReadmeWriterTest: fragments: make local variable KCR34: builder: ReadmeWriterTest: template: make local variable KCR33: builder: ReadmeWriterTest: outputProperties: make local KCR31: builder: DefaultRuleReadmeLoaderTest: make field local KCr30: CheckstyleWriterTest: checkstyleTemplate: make field local variable KCR28: builder: remove empty test class builder: CheckstyleWriter: avoid throwing raw exception types
This commit is contained in:
commit
0503156bd0
10 changed files with 121 additions and 47 deletions
|
@ -93,10 +93,10 @@ class CheckstyleWriter implements CommandLineRunner {
|
||||||
log.info("Writing xmlFile: {}", xmlFile);
|
log.info("Writing xmlFile: {}", xmlFile);
|
||||||
Files.write(xmlFile, output, StandardCharsets.UTF_8);
|
Files.write(xmlFile, output, StandardCharsets.UTF_8);
|
||||||
} else {
|
} else {
|
||||||
throw new IOException("Missing template: " + checkstyleXmlTemplate.toString());
|
throw new TemplateNotFoundException(checkstyleXmlTemplate);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new CheckstyleWriterException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ package net.kemitix.checkstyle.ruleset.builder;
|
||||||
|
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import me.andrz.builder.map.MapBuilder;
|
import me.andrz.builder.map.MapBuilder;
|
||||||
|
import org.assertj.core.api.ThrowableAssert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
import org.junit.rules.ExpectedException;
|
||||||
|
@ -20,6 +21,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
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.BDDMockito.given;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
|
|
||||||
|
@ -56,8 +58,6 @@ public class CheckstyleWriterTest {
|
||||||
|
|
||||||
private Path outputDirectory;
|
private Path outputDirectory;
|
||||||
|
|
||||||
private Path checkstyleTemplate;
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private RuleClassLocator ruleClassLocator;
|
private RuleClassLocator ruleClassLocator;
|
||||||
|
|
||||||
|
@ -78,8 +78,8 @@ public class CheckstyleWriterTest {
|
||||||
.toPath();
|
.toPath();
|
||||||
outputProperties.setDirectory(outputDirectory);
|
outputProperties.setDirectory(outputDirectory);
|
||||||
templateProperties = new TemplateProperties();
|
templateProperties = new TemplateProperties();
|
||||||
checkstyleTemplate = folder.newFile("checkstyle-template.xml")
|
val checkstyleTemplate = folder.newFile("checkstyle-template.xml")
|
||||||
.toPath();
|
.toPath();
|
||||||
Files.write(
|
Files.write(
|
||||||
checkstyleTemplate, TEMPLATE.getBytes(StandardCharsets.UTF_8), StandardOpenOption.TRUNCATE_EXISTING);
|
checkstyleTemplate, TEMPLATE.getBytes(StandardCharsets.UTF_8), StandardOpenOption.TRUNCATE_EXISTING);
|
||||||
templateProperties.setCheckstyleXml(checkstyleTemplate);
|
templateProperties.setCheckstyleXml(checkstyleTemplate);
|
||||||
|
@ -204,10 +204,11 @@ public class CheckstyleWriterTest {
|
||||||
public void throwRteIfTemplateNotFound() throws Exception {
|
public void throwRteIfTemplateNotFound() throws Exception {
|
||||||
//given
|
//given
|
||||||
templateProperties.setCheckstyleXml(Paths.get("garbage"));
|
templateProperties.setCheckstyleXml(Paths.get("garbage"));
|
||||||
exception.expect(RuntimeException.class);
|
|
||||||
exception.expectMessage("Missing template: garbage");
|
|
||||||
//when
|
//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
|
// throw RTE if error writing file
|
||||||
|
@ -216,10 +217,13 @@ public class CheckstyleWriterTest {
|
||||||
//given
|
//given
|
||||||
final String imaginary = String.join(FILE_SEPARATOR, "", "..", "imaginary");
|
final String imaginary = String.join(FILE_SEPARATOR, "", "..", "imaginary");
|
||||||
outputProperties.setDirectory(Paths.get(imaginary));
|
outputProperties.setDirectory(Paths.get(imaginary));
|
||||||
exception.expect(RuntimeException.class);
|
|
||||||
exception.expectMessage(
|
|
||||||
"java.nio.file.NoSuchFileException: " + imaginary + FILE_SEPARATOR + "checkstyle-LAYOUT.xml");
|
|
||||||
//when
|
//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
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,12 +23,8 @@ public class DefaultRuleReadmeLoaderTest {
|
||||||
|
|
||||||
private RuleReadmeLoader loader;
|
private RuleReadmeLoader loader;
|
||||||
|
|
||||||
private TemplateProperties templateProperties;
|
|
||||||
|
|
||||||
private Rule rule;
|
private Rule rule;
|
||||||
|
|
||||||
private Path fragment;
|
|
||||||
|
|
||||||
private Path fragments;
|
private Path fragments;
|
||||||
|
|
||||||
@org.junit.Rule
|
@org.junit.Rule
|
||||||
|
@ -39,7 +35,7 @@ public class DefaultRuleReadmeLoaderTest {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
templateProperties = new TemplateProperties();
|
final TemplateProperties templateProperties = new TemplateProperties();
|
||||||
fragments = folder.newFolder("fragments")
|
fragments = folder.newFolder("fragments")
|
||||||
.toPath();
|
.toPath();
|
||||||
templateProperties.setReadmeFragments(fragments);
|
templateProperties.setReadmeFragments(fragments);
|
||||||
|
@ -53,8 +49,8 @@ public class DefaultRuleReadmeLoaderTest {
|
||||||
public void loadEnabledOkay() throws IOException {
|
public void loadEnabledOkay() throws IOException {
|
||||||
//given
|
//given
|
||||||
rule.setEnabled(true);
|
rule.setEnabled(true);
|
||||||
fragment = fragments.resolve("name.md");
|
final Path fragment1 = fragments.resolve("name.md");
|
||||||
Files.write(fragment, Arrays.asList("", "body"));
|
Files.write(fragment1, Arrays.asList("", "body"));
|
||||||
//when
|
//when
|
||||||
val fragment = loader.load(rule);
|
val fragment = loader.load(rule);
|
||||||
//then
|
//then
|
||||||
|
|
|
@ -25,10 +25,6 @@ public class ReadmeWriterTest {
|
||||||
|
|
||||||
private ReadmeWriter readmeWriter;
|
private ReadmeWriter readmeWriter;
|
||||||
|
|
||||||
private TemplateProperties templateProperties;
|
|
||||||
|
|
||||||
private OutputProperties outputProperties;
|
|
||||||
|
|
||||||
private RulesProperties rulesProperties;
|
private RulesProperties rulesProperties;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
|
@ -37,10 +33,6 @@ public class ReadmeWriterTest {
|
||||||
@Mock
|
@Mock
|
||||||
private ReadmeIndexBuilder indexBuilder;
|
private ReadmeIndexBuilder indexBuilder;
|
||||||
|
|
||||||
private Path template;
|
|
||||||
|
|
||||||
private Path fragments;
|
|
||||||
|
|
||||||
private Path readme;
|
private Path readme;
|
||||||
|
|
||||||
@org.junit.Rule
|
@org.junit.Rule
|
||||||
|
@ -49,17 +41,17 @@ public class ReadmeWriterTest {
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
template = folder.newFile("README-template.md")
|
final Path template = folder.newFile("README-template.md")
|
||||||
.toPath();
|
.toPath();
|
||||||
Files.write(template, Arrays.asList("i:%s", "ce:%s", "se:%s", "cd:%s", "sd:%s"));
|
Files.write(template, Arrays.asList("i:%s", "ce:%s", "se:%s", "cd:%s", "sd:%s"));
|
||||||
fragments = folder.newFolder("fragments")
|
final TemplateProperties templateProperties = new TemplateProperties();
|
||||||
.toPath();
|
templateProperties.setReadmeTemplate(template);
|
||||||
|
final Path fragments = folder.newFolder("fragments")
|
||||||
|
.toPath();
|
||||||
|
templateProperties.setReadmeFragments(fragments);
|
||||||
|
final OutputProperties outputProperties = new OutputProperties();
|
||||||
readme = folder.newFile("README.md")
|
readme = folder.newFile("README.md")
|
||||||
.toPath();
|
.toPath();
|
||||||
templateProperties = new TemplateProperties();
|
|
||||||
templateProperties.setReadmeTemplate(template);
|
|
||||||
templateProperties.setReadmeFragments(fragments);
|
|
||||||
outputProperties = new OutputProperties();
|
|
||||||
outputProperties.setReadme(readme);
|
outputProperties.setReadme(readme);
|
||||||
rulesProperties = new RulesProperties();
|
rulesProperties = new RulesProperties();
|
||||||
readmeWriter =
|
readmeWriter =
|
||||||
|
|
|
@ -72,8 +72,6 @@ public class DefaultCheckstyleExecutorTest {
|
||||||
@Mock
|
@Mock
|
||||||
private Artifact artifact;
|
private Artifact artifact;
|
||||||
|
|
||||||
private File artifactFile;
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private MavenXpp3Reader mavenXpp3Reader;
|
private MavenXpp3Reader mavenXpp3Reader;
|
||||||
|
|
||||||
|
@ -122,8 +120,8 @@ public class DefaultCheckstyleExecutorTest {
|
||||||
.level(level)
|
.level(level)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
artifactFile = folder.newFile("pom.xml");
|
|
||||||
given(artifactRepository.find(any())).willReturn(artifact);
|
given(artifactRepository.find(any())).willReturn(artifact);
|
||||||
|
final File artifactFile = folder.newFile("pom.xml");
|
||||||
given(artifact.getFile()).willReturn(artifactFile);
|
given(artifact.getFile()).willReturn(artifactFile);
|
||||||
given(mavenXpp3Reader.read(any(FileReader.class))).willReturn(pomModel);
|
given(mavenXpp3Reader.read(any(FileReader.class))).willReturn(pomModel);
|
||||||
final Properties properties = new Properties();
|
final Properties properties = new Properties();
|
||||||
|
|
|
@ -33,7 +33,7 @@ class MoveVariableInsideIf {
|
||||||
private boolean condition;
|
private boolean condition;
|
||||||
|
|
||||||
private String method(final String variable) {
|
private String method(final String variable) {
|
||||||
return "value";
|
return "value: " + variable;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,7 +42,7 @@ class MoveVariableInsideIf {
|
||||||
* @return value
|
* @return value
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("movevariableinsideif")
|
@SuppressWarnings("movevariableinsideif")
|
||||||
String invalid() {
|
protected String invalid() {
|
||||||
String variable = input.substring(1);
|
String variable = input.substring(1);
|
||||||
if (condition) {
|
if (condition) {
|
||||||
return method(variable);
|
return method(variable);
|
||||||
|
@ -55,7 +55,7 @@ class MoveVariableInsideIf {
|
||||||
*
|
*
|
||||||
* @return value
|
* @return value
|
||||||
*/
|
*/
|
||||||
String valid() {
|
protected String valid() {
|
||||||
if (condition) {
|
if (condition) {
|
||||||
String variable = input.substring(1);
|
String variable = input.substring(1);
|
||||||
return method(variable);
|
return method(variable);
|
||||||
|
|
8
shippable.yml
Normal file
8
shippable.yml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
language: java
|
||||||
|
jdk:
|
||||||
|
- oraclejdk8
|
||||||
|
cache:
|
||||||
|
directories:
|
||||||
|
- "$HOME/.m2"
|
||||||
|
install: true
|
||||||
|
script: "./mvnw clean install"
|
|
@ -1,7 +1,3 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
## Only send coveralls reports from Travis-CI. Some CIs, like Shippable, lie by setting TRAVIS=true.
|
./mvnw --projects builder,plugin test jacoco:report coveralls:report
|
||||||
## 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
|
|
||||||
|
|
Loading…
Reference in a new issue