Skip to content

Commit

Permalink
[MENFORCER-434] Regression bannedDependencies - matching with not exi…
Browse files Browse the repository at this point in the history
…sting versions
  • Loading branch information
slawekjaranowski committed Jan 7, 2023
1 parent 7e14899 commit 6d2b727
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 0 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.buildResult = failure
94 changes: 94 additions & 0 deletions maven-enforcer-plugin/src/it/projects/MENFORCER-434/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?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 xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>maven.sample.issue</groupId>
<artifactId>MENFORCER-434</artifactId>
<packaging>jar</packaging>
<version>1.0.0-SNAPSHOT</version>
<name>MENFORCER-434</name>
<url>https://issues.apache.org/jira/browse/MENFORCER-434</url>
<description>Sample Project to Demo https://issues.apache.org/jira/browse/MENFORCER-434</description>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>enforce-versions</id>

<goals>
<goal>enforce</goal>
</goals>

<configuration>
<rules>
<bannedDependencies>
<searchTransitive>true</searchTransitive>
<excludes>
<!-- Using non-existent version 3.0.0 to force failure. Fail if any version less than 3.0.0 -->
<exclude>org.apache.logging.log4j:*:(,3.0.0)</exclude>
<exclude>log4j:log4j</exclude>
</excludes>
<includes>
<!-- allow this one ... in order to see transitive banned -->
<include>org.apache.logging.log4j:log4j-core</include>
</includes>
</bannedDependencies>
</rules>
</configuration>
</execution>
</executions>
</plugin>

</plugins>
</build>

<dependencies>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.19.0</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.19.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jul</artifactId>
<version>2.19.0</version>
<scope>compile</scope>
</dependency>

</dependencies>

</project>
26 changes: 26 additions & 0 deletions maven-enforcer-plugin/src/it/projects/MENFORCER-434/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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('[ERROR] Rule 0: org.apache.maven.plugins.enforcer.BannedDependencies failed with message:')

assert buildLog.contains(' org.apache.logging.log4j:log4j-core:jar:2.19.0')
assert buildLog.contains(' org.apache.logging.log4j:log4j-api:jar:2.19.0 <--- banned via the exclude/include list')
assert buildLog.contains(' org.apache.logging.log4j:log4j-slf4j-impl:jar:2.19.0 <--- banned via the exclude/include list')
assert buildLog.contains(' org.apache.logging.log4j:log4j-jul:jar:2.19.0 <--- banned via the exclude/include list')

0 comments on commit 6d2b727

Please sign in to comment.