Skip to content

Commit

Permalink
[MENFORCER-454] Deprecate 'rules' property and introduce 'enforcer.ru…
Browse files Browse the repository at this point in the history
…les' as a replacement

 * updated the ITs to verify the rules are indeed getting fully replaced
   with the list from the property
  • Loading branch information
psiroky committed Dec 29, 2022
1 parent b4427e8 commit ebb0434
Show file tree
Hide file tree
Showing 13 changed files with 272 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
invoker.goals = validate -Drules=AlwaysFail
invoker.buildResult = failure
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?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
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

<project>
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.its.enforcer</groupId>
<artifactId>test</artifactId>
<version>1.0</version>

<description>
</description>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>test</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<AlwaysPass/> <!-- Should be replaced by 'AlwaysFail' via command line property -->
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
def buildLog = new File(basedir, 'build.log').text
assert !buildLog.contains('[INFO] Always pass!')
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:enforce -Drules=alwaysFail
invoker.goals = validate -Denforcer.rules=AlwaysFail
invoker.buildResult = failure
14 changes: 14 additions & 0 deletions maven-enforcer-plugin/src/it/projects/cli-always-fail/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ under the License.
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>test</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<AlwaysPass/> <!-- Should be replaced by 'AlwaysFail' via command line property -->
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
def buildLog = new File(basedir, 'build.log').text
assert !buildLog.contains('[INFO] Always pass!')
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
invoker.goals = validate -Drules=AlwaysPass
invoker.buildResult = success
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?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
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

<project>
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.its.enforcer</groupId>
<artifactId>test</artifactId>
<version>1.0</version>

<description>
</description>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>test</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<AlwaysFail/> <!-- Should be replaced by 'AlwaysPass' via command line property -->
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
def buildLog = new File(basedir, 'build.log').text
assert buildLog.contains('[INFO] Always pass!')
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:enforce -Drules=alwaysPass
invoker.goals = validate -Denforcer.rules=AlwaysPass
invoker.buildResult = success
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ under the License.
</goals>
<configuration>
<rules>
<AlwaysPass/>
<AlwaysFail/> <!-- Should be replaced by 'AlwaysPass' via command line property -->
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
def buildLog = new File(basedir, 'build.log').text
assert buildLog.contains('[INFO] Always pass!')
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public class EnforceMojo extends AbstractMojo {
* &lt;message&gt;message for rule&lt;/message&gt;
* &lt;/alwaysPass&gt;
* &lt;myRule implementation="org.example.MyRule"/&gt;
* &lt;/rules>
* &lt;/rules&gt;
* </pre>
*
* @since 1.0.0
Expand All @@ -127,11 +127,22 @@ public class EnforceMojo extends AbstractMojo {
private PlexusConfiguration rules;

/**
* List of strings that matches the EnforcerRules to execute.
* List of strings that matches the EnforcerRules to execute. Use <code>enforcer.rules</code> property instead.
*
* @deprecated
*/
@Parameter(required = false, property = "rules")
private List<String> commandLineRules;

/**
* List of strings that matches the EnforcerRules to execute. Replacement for the <code>rules</code> property.
* If both are specified, this one has a higher precedence.
*
* @since 3.2.0
*/
@Parameter(required = false, property = "enforcer.rules")
private List<String> rulesToExecute;

/**
* List of strings that matches the EnforcerRules to skip.
*
Expand Down Expand Up @@ -274,21 +285,28 @@ public void execute() throws MojoExecutionException {
*/
private Optional<PlexusConfiguration> createRulesFromCommandLineOptions() {

if (commandLineRules == null || commandLineRules.isEmpty()) {
return Optional.empty();
if (rulesToExecute != null && !rulesToExecute.isEmpty()) {
PlexusConfiguration configuration = new DefaultPlexusConfiguration("rules");
for (String rule : rulesToExecute) {
configuration.addChild(new DefaultPlexusConfiguration(rule));
}
return Optional.of(configuration);
}

PlexusConfiguration configuration = new DefaultPlexusConfiguration("rules");

for (String rule : commandLineRules) {
configuration.addChild(new DefaultPlexusConfiguration(rule));
// if the new configuration option was not used, try the old (deprecated) one
if (commandLineRules != null && !commandLineRules.isEmpty()) {
PlexusConfiguration configuration = new DefaultPlexusConfiguration("rules");
for (String rule : commandLineRules) {
configuration.addChild(new DefaultPlexusConfiguration(rule));
}
return Optional.of(configuration);
}

return Optional.of(configuration);
return Optional.empty();
}

/**
* Filter our (remove) rules that have been specifically skipped via additional configuration.
* Filter out (remove) rules that have been specifically skipped via additional configuration.
*
* @param allRules list of enforcer rules to go through and filter
*
Expand Down

0 comments on commit ebb0434

Please sign in to comment.