Skip to content

Commit

Permalink
Merge 3ed11e4 into 484f489
Browse files Browse the repository at this point in the history
  • Loading branch information
bvedrenne committed Jan 6, 2022
2 parents 484f489 + 3ed11e4 commit a6a7155
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ So your config would become something like :
<artifactId>arch-unit-maven-plugin</artifactId>
<version>2.7.2</version>
<configuration>

<!-- optional - you can avoid build fail if there is issue. True to avoid build failure, default is false -->
<noFailOnError>true</noFailOnError>

<!-- optional - you can exclude classes that have a path containing any of the mentioned paths -->
<excludedPaths>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public class ArchUnitMojo extends AbstractMojo {
@Parameter(defaultValue = "${project.build.directory}")
private String projectBuildDir;

@Parameter(property = "noFailOnError", defaultValue = "false")
private boolean noFailOnError;

public MavenRules getRules() {
return rules;
}
Expand Down Expand Up @@ -96,7 +99,11 @@ public void execute() throws MojoFailureException {
}

if (!StringUtils.isEmpty(ruleFailureMessage)) {
throw new MojoFailureException(PREFIX_ARCH_VIOLATION_MESSAGE + ruleFailureMessage);
if(!noFailOnError) {
throw new MojoFailureException(PREFIX_ARCH_VIOLATION_MESSAGE + ruleFailureMessage);
}

getLog().info(PREFIX_ARCH_VIOLATION_MESSAGE + ruleFailureMessage);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.societegenerale.commons.plugin.maven;

import java.io.File;
import java.io.StringReader;

import com.societegenerale.aut.test.TestClassWithPowerMock;
import com.societegenerale.commons.plugin.rules.MyCustomAndDummyRules;
import com.societegenerale.commons.plugin.rules.NoPowerMockRuleTest;
Expand All @@ -12,6 +9,7 @@
import org.apache.maven.model.Build;
import org.apache.maven.plugin.Mojo;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugin.testing.MojoRule;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.configuration.DefaultPlexusConfiguration;
Expand All @@ -27,13 +25,16 @@
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;

import java.io.File;
import java.io.StringReader;

import static com.tngtech.junit.dataprovider.DataProviders.testForEach;
import static java.util.Arrays.stream;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@RunWith(DataProviderRunner.class)
Expand Down Expand Up @@ -108,6 +109,27 @@ public void shouldExecuteSinglePreconfiguredRule() throws Exception {
.withDetails("Favor Mockito and proper dependency injection - " + TestClassWithPowerMock.class.getName()));
}

@Test
public void shouldExecuteSinglePreconfiguredRuleWithNoFailOnError() throws Exception {

// add single rule

PlexusConfiguration preConfiguredRules = pluginConfiguration.getChild("rules").getChild("preConfiguredRules");
preConfiguredRules.addChild("rule", NoPowerMockRuleTest.class.getName());

pluginConfiguration.addChild("noFailOnError","true");

ArchUnitMojo mojo = (ArchUnitMojo) mojoRule.configureMojo(archUnitMojo, pluginConfiguration);

Log log = mock(Log.class);
mojo.setLog(log);
mojo.execute();

verify(log, times(1)).info("ArchUnit Maven plugin reported architecture failures listed below :Rule Violated - " + NoPowerMockRuleTest.class.getName() + System.lineSeparator() +
"java.lang.AssertionError: Architecture Violation [Priority: MEDIUM] - Rule 'classes should not use Powermock' was violated (1 times):" + System.lineSeparator() +
"Favor Mockito and proper dependency injection - " + TestClassWithPowerMock.class.getName() + System.lineSeparator());
}

@Test
public void shouldFailWronglyDefinedConfigurableRule() throws Exception {
PlexusConfiguration configurableRule = new DefaultPlexusConfiguration("configurableRule");
Expand Down

0 comments on commit a6a7155

Please sign in to comment.