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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/src/main/java/de/obqo/decycle/check/Constraint.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public String displayString() {
}

public static String displayString(final List<Violation> violations) {
return violations.stream().map(Constraint.Violation::displayString).collect(joining("\n"));
return violations.stream().map(Constraint.Violation::displayString).collect(joining(System.lineSeparator()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public class Configuration {
*/
@Builder
private Configuration(
final String classpath,
@NonNull final String classpath,
final List<String> including,
final List<String> excluding,
final List<IgnoredDependency> ignoring,
Expand Down Expand Up @@ -191,13 +191,14 @@ public List<Violation> check() {
*/
@Override
public String toString() {
final StringBuilder builder = new StringBuilder("Decycle {\n");
builder.append(" classpath: ").append(this.classpath).append("\n");
builder.append(" including: ").append(this.including).append("\n");
builder.append(" excluding: ").append(this.excluding).append("\n");
builder.append(" ignoring: ").append(this.ignoring).append("\n");
builder.append(" slicings: ").append(this.slicings).append("\n");
builder.append(" constraints: ").append(this.constraints).append("\n");
final String nl = System.lineSeparator();
final StringBuilder builder = new StringBuilder("Decycle {").append(nl);
builder.append(" classpath: ").append(this.classpath).append(nl);
builder.append(" including: ").append(this.including).append(nl);
builder.append(" excluding: ").append(this.excluding).append(nl);
builder.append(" ignoring: ").append(this.ignoring).append(nl);
builder.append(" slicings: ").append(this.slicings).append(nl);
builder.append(" constraints: ").append(this.constraints).append(nl);
builder.append("}");
return builder.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,30 +65,35 @@ public void execute() {
builder.reportResourcesPrefix(resourcesDirName);
builder.reportTitle(reportTitle);

buildAndCheck(builder, configuration.isIgnoreFailures(), "\nSee the report at: " + reportFile);
buildAndCheck(builder, configuration.isIgnoreFailures(), reportFile);
} catch (final IOException ioException) {
throw new GradleException(ioException.getMessage(), ioException);
}
} else { // reports not enabled
buildAndCheck(builder, configuration.isIgnoreFailures(), "");
buildAndCheck(builder, configuration.isIgnoreFailures(), null);
}
}

private void buildAndCheck(final ConfigurationBuilder builder, final boolean ignoreFailures,
final String violationsInfo) {
final File reportFile) {
final Configuration decycleConfig = builder.build();
logger.info("Decycle configuration: {}", decycleConfig);

final List<Constraint.Violation> violations = decycleConfig.check();
logger.debug("decycle result: {}", violations);

if (!violations.isEmpty()) {
final String message = Constraint.Violation.displayString(violations) + violationsInfo;
final StringBuilder message = new StringBuilder(Constraint.Violation.displayString(violations));
if (reportFile != null) {
message.append(System.lineSeparator()).append("See the report at: ").append(reportFile.toURI());
}
if (ignoreFailures) {
logger.warn("Violations detected: {}", message);
} else {
throw new GradleException(message);
throw new GradleException(message.toString());
}
} else if (reportFile != null) {
logger.info("Decycle HTML report is available at: {}", reportFile.toURI());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,11 @@ void shouldFailBecauseOfWrongIgnoringMapConfiguration() {
@Test
void shouldSucceedWithIgnoreFailures() {
final BuildResult result = build("ignoreFailures.gradle");
final String nl = System.lineSeparator();
assertBuildResult(result, TaskOutcome.SUCCESS, "decycleMain")
.contains("\nViolations detected: Violation(slicing=Package, name=cycle, " +
"dependencies=[demo.cycle.a → demo.cycle.b, demo.cycle.b → demo.cycle.a])\n")
.contains("See the report at: ");
.contains(nl + "Violations detected: Violation(slicing=Package, name=cycle, " +
"dependencies=[demo.cycle.a → demo.cycle.b, demo.cycle.b → demo.cycle.a])" + nl)
.contains(nl + "See the report at: file:/");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,10 @@ private List<Constraint.Violation> check(final Configuration config, final File
if (!violations.isEmpty()) {
logHandler.accept("Violations detected: " + Constraint.Violation.displayString(violations));
if (report != null) {
logHandler.accept("See the report at: " + report);
logHandler.accept("See the report at: " + report.toURI());
}
} else if (report != null) {
log.info("Decycle HTML report is available at: " + report.toURI());
}
return violations;
}
Expand Down