diff --git a/Java-base/maven-enforcer/Dockerfile b/Java-base/maven-enforcer/Dockerfile new file mode 100644 index 000000000..e208c4890 --- /dev/null +++ b/Java-base/maven-enforcer/Dockerfile @@ -0,0 +1,28 @@ +FROM ubuntu:22.04 + +RUN export DEBIAN_FRONTEND=noninteractive \ + && apt-get update \ + && apt-get install -y software-properties-common \ + && add-apt-repository ppa:deadsnakes/ppa \ + && apt-get update \ + && apt-get install -y \ + build-essential \ + git \ + vim \ + jq \ + && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/list/* + +RUN apt-get -y install sudo \ + openjdk-8-jdk \ + maven + +RUN bash -c "echo 2 | update-alternatives --config java" + +COPY src /workspace +WORKDIR /workspace + +RUN mvn install -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false + +RUN mvn test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 + +ENV TZ=Asia/Seoul diff --git a/Java-base/maven-enforcer/src/CONTRIBUTING.md b/Java-base/maven-enforcer/src/CONTRIBUTING.md new file mode 100644 index 000000000..dc07b9fca --- /dev/null +++ b/Java-base/maven-enforcer/src/CONTRIBUTING.md @@ -0,0 +1,80 @@ + +Contributing to Apache Maven Enforcer +====================== + +You have found a bug or you have an idea for a cool new feature? Contributing +code is a great way to give something back to the open source community. Before +you dig right into the code there are a few guidelines that we need +contributors to follow so that we can have a chance of keeping on top of +things. + +Getting Started +--------------- + ++ Make sure you have a [JIRA account](https://issues.apache.org/jira/). ++ Make sure you have a [GitHub account](https://github.com/signup/free). ++ If you're planning to implement a new feature it makes sense to discuss your changes + on the [dev list](https://maven.apache.org/mail-lists.html) first. + This way you can make sure you're not wasting your time on something that isn't + considered to be in Apache Maven Enforcer's scope. ++ Submit a ticket for your issue, assuming one does not already exist. + + Clearly describe the issue including steps to reproduce when it is a bug. + + Make sure you fill in the earliest version that you know has the issue. ++ Fork the repository on GitHub. + +Making Changes +-------------- + ++ Create a topic branch from where you want to base your work (this is usually the master branch). ++ Make commits of logical units. ++ Respect the original code style: + + Only use spaces for indentation. + + Create minimal diffs - disable on save actions like reformat source code or organize imports. + If you feel the source code should be reformatted create a separate PR for this change. + + Check for unnecessary whitespace with git diff --check before committing. ++ Make sure your commit messages are in the proper format. Your commit message should contain the key of the JIRA issue. ++ Make sure you have added the necessary tests for your changes. ++ Run all the tests with `mvn -Prun-its clean verify` to assure nothing else was accidentally broken. + +Making Trivial Changes +---------------------- + +For changes of a trivial nature to comments and documentation, it is not always +necessary to create a new ticket in JIRA. In this case, it is appropriate to +start the first line of a commit with '(doc)' instead of a ticket number. + +Submitting Changes +------------------ + ++ Sign the [Contributor License Agreement][cla] if you haven't already. ++ Push your changes to a topic branch in your fork of the repository. ++ Submit a pull request to the repository in the apache organization. ++ Update your JIRA ticket and include a link to the pull request in the ticket. + +Additional Resources +-------------------- + ++ [Contributing patches](https://maven.apache.org/guides/development/guide-maven-development.html#Creating_and_submitting_a_patch) ++ [Apache Maven Enforcer JIRA project page](https://issues.apache.org/jira/projects/MENFORCER/) ++ [Contributor License Agreement][cla] ++ [General GitHub documentation](https://help.github.com/) ++ [GitHub pull request documentation](https://help.github.com/send-pull-requests/) ++ [Apache Maven Twitter Account](https://twitter.com/ASFMavenProject) ++ #Maven IRC channel on freenode.org + +[cla]:https://www.apache.org/licenses/#clas diff --git a/Java-base/maven-enforcer/src/Jenkinsfile b/Java-base/maven-enforcer/src/Jenkinsfile new file mode 100644 index 000000000..e9f05f7d9 --- /dev/null +++ b/Java-base/maven-enforcer/src/Jenkinsfile @@ -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. + */ + +asfMavenTlpPlgnBuild() diff --git a/Java-base/maven-enforcer/src/LICENSE b/Java-base/maven-enforcer/src/LICENSE new file mode 100644 index 000000000..d64569567 --- /dev/null +++ b/Java-base/maven-enforcer/src/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. diff --git a/Java-base/maven-enforcer/src/NOTICE b/Java-base/maven-enforcer/src/NOTICE new file mode 100644 index 000000000..32337608e --- /dev/null +++ b/Java-base/maven-enforcer/src/NOTICE @@ -0,0 +1,5 @@ +Apache Maven Enforcer +Copyright 2007-2013 The Apache Software Foundation + +This product includes software developed at +The Apache Software Foundation (http://www.apache.org/). diff --git a/Java-base/maven-enforcer/src/README.md b/Java-base/maven-enforcer/src/README.md new file mode 100644 index 000000000..e285ee17f --- /dev/null +++ b/Java-base/maven-enforcer/src/README.md @@ -0,0 +1,98 @@ + +Maven Enforcer Plugin - The Loving Iron Fist of Maven™ +====================================================== + +[![ASF Jira](https://img.shields.io/endpoint?url=https%3A%2F%2Fmaven.apache.org%2Fbadges%2Fasf_jira-MENFORCER.json)][jira] +[![Apache License, Version 2.0, January 2004](https://img.shields.io/github/license/apache/maven-enforcer.svg?label=License)][license] +[![Maven Central](https://img.shields.io/maven-central/v/org.apache.maven.plugins/maven-enforcer-plugin.svg?label=Maven%20Central)](https://search.maven.org/artifact/org.apache.maven.plugins/maven-enforcer-plugin) +[![Jenkins Status](https://img.shields.io/jenkins/s/https/builds.apache.org/job/maven-box/job/maven-enforcer/job/master.svg?)][build] +[![Jenkins tests](https://img.shields.io/jenkins/t/https/builds.apache.org/job/maven-box/job/maven-enforcer/job/master.svg?)][test-results] + +The Enforcer plugin provides goals to control certain environmental constraints +such as Maven version, JDK version and OS family along with many more built-in +rules and user created rules. + +Documentation +------------- + +More information can be found on [Apache Maven Enforcer Plugin Homepage][enforcer-home]. +Question related to the usage of the Maven Enforcer Plugin should be posted on +the [Maven User List][users-list]. + + +Where can I get the latest release? +----------------------------------- +You can download release source from our [download page][enforcer-download]. + +You can get the Maven Enforcer plugin via the following coordinates from central: + +```xml + + org.apache.maven.plugins + maven-enforcer-plugin + 3.0.0-M3 + +``` + +Contributing +------------ + +We accept Pull Requests via GitHub. The [developer mailing list][dev-ml-list] is the +main channel of communication for contributors. +There are some guidelines which will make applying PRs easier for us: ++ No tabs! Please use spaces for indentation. ++ Respect the [code style][code-style]. ++ Create minimal diffs - disable on save actions like reformat source code or + organize imports. If you feel the source code should be reformatted create a + separate PR for this change. ++ Provide JUnit/Invoker tests for your changes and make sure your changes don't break + any existing tests by running ```mvn -Prun-its verify```. + +If you plan to contribute on a regular basis, please consider filing a [contributor license agreement](https://www.apache.org/licenses/#clas). +You can learn more about contributing via GitHub in our [contribution guidelines](CONTRIBUTING.md). + + +License +------- +This code is under the [Apache Licence v2][license] + +See the `NOTICE` file for required notices and attributions. + + +Donations +--------- +You like Apache Maven? Then [donate back to the ASF](https://www.apache.org/foundation/contributing.html) to support the development. + + +License +------- +[Apache License, Version 2.0, January 2004][license] + + +[home]: https://maven.apache.org/enforcer/maven-enforcer-plugin +[jira]: https://issues.apache.org/jira/projects/MENFORCER/ +[license]: https://www.apache.org/licenses/LICENSE-2.0 +[build]: https://builds.apache.org/job/maven-box/job/maven-enforcer/ +[test-results]: https://builds.apache.org/job/maven-box/job/maven-enforcer/job/master/lastCompletedBuild/testReport/ +[build-status]: https://img.shields.io/jenkins/s/https/builds.apache.org/job/maven-box/job/maven-enforcer/job/master.svg? +[build-tests]: https://img.shields.io/jenkins/t/https/builds.apache.org/job/maven-box/job/maven-enforcer/job/master.svg? +[enforcer-home]: https://maven.apache.org/enforcer/maven-enforcer-plugin/ +[enforcer-download]: https://maven.apache.org/enforcer/download.cgi +[users-list]: https://maven.apache.org/mailing-lists.html +[dev-ml-list]: https://www.mail-archive.com/dev@maven.apache.org/ +[code-style]: https://maven.apache.org/developers/conventions/code.html diff --git a/Java-base/maven-enforcer/src/deploySite.bat b/Java-base/maven-enforcer/src/deploySite.bat new file mode 100644 index 000000000..24510e9c8 --- /dev/null +++ b/Java-base/maven-enforcer/src/deploySite.bat @@ -0,0 +1,21 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +mvn -Preporting clean site site:stage %* +mvn scm-publish:publish-scm %* diff --git a/Java-base/maven-enforcer/src/deploySite.sh b/Java-base/maven-enforcer/src/deploySite.sh new file mode 100755 index 000000000..7d693d222 --- /dev/null +++ b/Java-base/maven-enforcer/src/deploySite.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +# +# 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. +# + +mvn -Preporting clean site site:stage $@ +mvn scm-publish:publish-scm $@ diff --git a/Java-base/maven-enforcer/src/enforcer-api/pom.xml b/Java-base/maven-enforcer/src/enforcer-api/pom.xml new file mode 100644 index 000000000..c27ddd6b8 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-api/pom.xml @@ -0,0 +1,81 @@ + + + + 4.0.0 + + + org.apache.maven.enforcer + enforcer + 3.0.0-M4-SNAPSHOT + + + enforcer-api + jar + + Apache Maven Enforcer API + + This component provides the generic interfaces needed to implement custom rules for the maven-enforcer-plugin. + + + + + org.apache.maven + maven-plugin-api + + + org.codehaus.plexus + plexus-container-default + 1.0-alpha-9 + + + com.google.code.findbugs + jsr305 + 3.0.0 + provided + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + custom-rule + pre-site + + single + + + custom-rule + target/site + + src/main/assembly/custom-rule-sample.xml + + false + + + + + + + diff --git a/Java-base/maven-enforcer/src/enforcer-api/src/custom-rule-sample/pom.xml b/Java-base/maven-enforcer/src/enforcer-api/src/custom-rule-sample/pom.xml new file mode 100644 index 000000000..5ae0f9eeb --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-api/src/custom-rule-sample/pom.xml @@ -0,0 +1,73 @@ + + + + 4.0.0 + custom-rule + custom-rule-sample + jar + 1.0 + My Custom Rule + This is my custom rule. + + 1.0-beta-1 + 2.0.9 + + + + + + org.apache.maven.enforcer + enforcer-api + ${api.version} + + + org.apache.maven + maven-project + ${maven.version} + + + org.apache.maven + maven-core + ${maven.version} + + + org.apache.maven + maven-artifact + ${maven.version} + + + org.apache.maven + maven-plugin-api + ${maven.version} + + + org.codehaus.plexus + plexus-container-default + 1.0-alpha-9 + + + junit + junit + 3.8.1 + test + + + diff --git a/Java-base/maven-enforcer/src/enforcer-api/src/custom-rule-sample/src/main/java/org/apache/maven/enforcer/rule/MyCustomRule.java b/Java-base/maven-enforcer/src/enforcer-api/src/custom-rule-sample/src/main/java/org/apache/maven/enforcer/rule/MyCustomRule.java new file mode 100644 index 000000000..b9792d18e --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-api/src/custom-rule-sample/src/main/java/org/apache/maven/enforcer/rule/MyCustomRule.java @@ -0,0 +1,120 @@ +package org.apache.maven.enforcer.rule; + +/* + * 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. + */ + +import org.apache.maven.artifact.resolver.ArtifactResolver; +import org.apache.maven.enforcer.rule.api.EnforcerRule; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.execution.RuntimeInformation; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; + +/** + * @author Brian Fox + */ +public class MyCustomRule + implements EnforcerRule +{ + /** + * Simple param. This rule will fail if the value is true. + */ + private boolean shouldIfail = false; + + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + Log log = helper.getLog(); + + try + { + // get the various expressions out of the helper. + MavenProject project = (MavenProject) helper.evaluate( "${project}" ); + MavenSession session = (MavenSession) helper.evaluate( "${session}" ); + String target = (String) helper.evaluate( "${project.build.directory}" ); + String artifactId = (String) helper.evaluate( "${project.artifactId}" ); + + // retreive any component out of the session directly + ArtifactResolver resolver = (ArtifactResolver) helper.getComponent( ArtifactResolver.class ); + RuntimeInformation rti = (RuntimeInformation) helper.getComponent( RuntimeInformation.class ); + + log.info( "Retrieved Target Folder: " + target ); + log.info( "Retrieved ArtifactId: " +artifactId ); + log.info( "Retrieved Project: " + project ); + log.info( "Retrieved RuntimeInfo: " + rti ); + log.info( "Retrieved Session: " + session ); + log.info( "Retrieved Resolver: " + resolver ); + + if ( this.shouldIfail ) + { + throw new EnforcerRuleException( "Failing because my param said so." ); + } + } + catch ( ComponentLookupException e ) + { + throw new EnforcerRuleException( "Unable to lookup a component " + e.getLocalizedMessage(), e ); + } + catch ( ExpressionEvaluationException e ) + { + throw new EnforcerRuleException( "Unable to lookup an expression " + e.getLocalizedMessage(), e ); + } + } + + /** + * If your rule is cacheable, you must return a unique id when parameters or conditions + * change that would cause the result to be different. Multiple cached results are stored + * based on their id. + * + * The easiest way to do this is to return a hash computed from the values of your parameters. + * + * If your rule is not cacheable, then the result here is not important, you may return anything. + */ + public String getCacheId() + { + //no hash on boolean...only parameter so no hash is needed. + return ""+this.shouldIfail; + } + + /** + * This tells the system if the results are cacheable at all. Keep in mind that during + * forked builds and other things, a given rule may be executed more than once for the same + * project. This means that even things that change from project to project may still + * be cacheable in certain instances. + */ + public boolean isCacheable() + { + return false; + } + + /** + * If the rule is cacheable and the same id is found in the cache, the stored results + * are passed to this method to allow double checking of the results. Most of the time + * this can be done by generating unique ids, but sometimes the results of objects returned + * by the helper need to be queried. You may for example, store certain objects in your rule + * and then query them later. + */ + public boolean isResultValid( EnforcerRule arg0 ) + { + return false; + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-api/src/custom-rule-sample/src/usage-pom.xml b/Java-base/maven-enforcer/src/enforcer-api/src/custom-rule-sample/src/usage-pom.xml new file mode 100644 index 000000000..713b269c3 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-api/src/custom-rule-sample/src/usage-pom.xml @@ -0,0 +1,64 @@ + + + + 4.0.0 + org.apache.maven.plugins + maven-enforcer-plugin-it1 + 1 + pom + + + + org.apache.maven.plugins + maven-enforcer-plugin + 1.0-SNAPSHOT + + + custom-rule + custom-rule-sample + 1.0 + + + + + enforce + + + + [1.3,1.6] + + + 2.0.6 + + + true + + + + + enforce + + + + + + + diff --git a/Java-base/maven-enforcer/src/enforcer-api/src/custom-rule-sample/usage-pom.xml b/Java-base/maven-enforcer/src/enforcer-api/src/custom-rule-sample/usage-pom.xml new file mode 100644 index 000000000..0a4efb4d7 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-api/src/custom-rule-sample/usage-pom.xml @@ -0,0 +1,59 @@ + + + + 4.0.0 + org.apache.maven.plugins + maven-enforcer-plugin-sample-usage + 1 + jar + + + + org.apache.maven.plugins + maven-enforcer-plugin + 1.0-beta-1 + + + custom-rule + custom-rule-sample + 1.0 + + + + + enforce + + + + false + + + + + enforce + + + + + + + + diff --git a/Java-base/maven-enforcer/src/enforcer-api/src/main/assembly/custom-rule-sample.xml b/Java-base/maven-enforcer/src/enforcer-api/src/main/assembly/custom-rule-sample.xml new file mode 100644 index 000000000..1abdf30a4 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-api/src/main/assembly/custom-rule-sample.xml @@ -0,0 +1,35 @@ + + + + sample + false + + zip + + + + src/custom-rule-sample + /custom-rule-sample + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerLevel.java b/Java-base/maven-enforcer/src/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerLevel.java new file mode 100644 index 000000000..ec9936458 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerLevel.java @@ -0,0 +1,37 @@ +package org.apache.maven.enforcer.rule.api; + +/* + * 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. + */ + +/** + * Levels steering whether a rule should fail a build or just display a warning. + * + * @author Mirko Friedenhagen + * + * @since 1.4 + */ +public enum EnforcerLevel +{ + + /** Fail the build. */ + ERROR, + /** Just warn. */ + WARN + +} diff --git a/Java-base/maven-enforcer/src/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerRule.java b/Java-base/maven-enforcer/src/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerRule.java new file mode 100644 index 000000000..4ba99dcf0 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerRule.java @@ -0,0 +1,81 @@ +package org.apache.maven.enforcer.rule.api; + +/* + * 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. + */ + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * Interface to be implemented by any rules executed by the enforcer. + * + * @author Brian Fox + */ +public interface EnforcerRule +{ + + /** + * This is the interface into the rule. This method should throw an exception + * containing a reason message if the rule fails the check. The plugin will + * then decide based on the fail flag if it should stop or just log the + * message as a warning. + * + * @param helper The helper provides access to the log, MavenSession and has + * helpers to get common components. It is also able to lookup components + * by class name. + * + * @throws EnforcerRuleException the enforcer rule exception + */ + void execute( @Nonnull EnforcerRuleHelper helper ) + throws EnforcerRuleException; + + /** + * This method tells the enforcer if the rule results may be cached. If the result is true, + * the results will be remembered for future executions in the same build (ie children). Subsequent + * iterations of the rule will be queried to see if they are also cacheable. This will allow the rule to be + * uncached further down the tree if needed. + * + * @return true if rule is cacheable + */ + boolean isCacheable(); + + /** + * If the rule is cacheable and the same id is found in the cache, the stored results are passed to this method to + * allow double checking of the results. Most of the time this can be done by generating unique ids, but sometimes + * the results of objects returned by the helper need to be queried. You may for example, store certain objects in + * your rule and then query them later. + * + * @param cachedRule the last cached instance of the rule. This is to be used by the rule to + * potentially determine if the results are still valid (ie if the configuration has been overridden) + * + * @return true if the stored results are valid for the same id. + */ + boolean isResultValid( @Nonnull EnforcerRule cachedRule ); + + /** + * If the rule is to be cached, this id is used as part of the key. This can allow rules to take parameters + * that allow multiple results of the same rule to be cached. + * + * @return id to be used by the enforcer to determine uniqueness of cache results. The ids only need to be unique + * within a given rule implementation as the full key will be [classname]-[id] + */ + @Nullable + String getCacheId(); + +} diff --git a/Java-base/maven-enforcer/src/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerRule2.java b/Java-base/maven-enforcer/src/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerRule2.java new file mode 100644 index 000000000..afd7c5ea7 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerRule2.java @@ -0,0 +1,40 @@ +package org.apache.maven.enforcer.rule.api; + +/* + * 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. + */ + +import javax.annotation.Nonnull; + +/** + * Interface to be implemented by any rules as of version 2.0 executed by the enforcer. + * + * @author Mirko Friedenhagen + * @since 1.4 + */ +public interface EnforcerRule2 extends EnforcerRule +{ + /** + * Returns the level of enforcement. + * + * @return level + */ + @Nonnull + EnforcerLevel getLevel(); + +} diff --git a/Java-base/maven-enforcer/src/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerRuleException.java b/Java-base/maven-enforcer/src/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerRuleException.java new file mode 100644 index 000000000..d90c8e325 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerRuleException.java @@ -0,0 +1,113 @@ +package org.apache.maven.enforcer.rule.api; + +/* + * 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. + */ + +/** + * An exception occurring during the execution of a rule. Based off of + * EnforcerRuleException, but separated to keep the rule dependencies to a + * minimum. + * + * @author Brian Fox + */ +public class EnforcerRuleException + extends Exception +{ + + /** serialVersionUID. */ + private static final long serialVersionUID = 1L; + + /** The source. */ + protected Object source; + + /** The long message. */ + protected String longMessage; + + /** + * Gets the long message. + * + * @return the long message + */ + public String getLongMessage() + { + return longMessage; + } + + /** + * Gets the source. + * + * @return the source + */ + public Object getSource() + { + return source; + } + + /** + * Construct a new EnforcerRuleException exception providing + * the source and a short and long message. + * + * @param source the source + * @param shortMessage the short message + * @param longMessage the long message + */ + public EnforcerRuleException( Object source, String shortMessage, String longMessage ) + { + super( shortMessage ); + this.source = source; + this.longMessage = longMessage; + } + + /** + * Construct a new EnforcerRuleException exception wrapping + * an underlying Exception and providing a + * message. + * + * @param message the message + * @param cause the cause + */ + public EnforcerRuleException( String message, Exception cause ) + { + super( message, cause ); + } + + /** + * Construct a new EnforcerRuleException exception wrapping + * an underlying Throwable and providing a + * message. + * + * @param message the message + * @param cause the cause + */ + public EnforcerRuleException( String message, Throwable cause ) + { + super( message, cause ); + } + + /** + * Construct a new EnforcerRuleException exception providing + * a message. + * + * @param message the message + */ + public EnforcerRuleException( String message ) + { + super( message ); + } +} \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerRuleHelper.java b/Java-base/maven-enforcer/src/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerRuleHelper.java new file mode 100644 index 000000000..403be73da --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerRuleHelper.java @@ -0,0 +1,134 @@ +package org.apache.maven.enforcer.rule.api; + +/* + * 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. + */ + +import java.util.List; +import java.util.Map; + +import javax.annotation.Nonnull; + +import org.apache.maven.plugin.logging.Log; +import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; + + +/** + * This is the interface that all helpers will use. This + * provides access to the log, session and components to the + * rules. + * + * @author Brian Fox + */ +public interface EnforcerRuleHelper + extends ExpressionEvaluator +{ + + /** + * Gets the log. + * + * @return the log + */ + @Nonnull + Log getLog (); + + /** + * Gets the component. + * + * @param clazz the clazz + * + * @return the component + * + * @throws ComponentLookupException the component lookup exception + */ + @Nonnull + T getComponent ( Class clazz ) + throws ComponentLookupException; + + /** + * Gets the component. + * + * @param componentKey the component key + * + * @return the component + * + * @throws ComponentLookupException the component lookup exception + */ + @Nonnull + Object getComponent ( String componentKey ) + throws ComponentLookupException; + + /** + * Gets the component. + * + * @param role the role + * @param roleHint the role hint + * + * @return the component + * + * @throws ComponentLookupException the component lookup exception + */ + Object getComponent ( String role, String roleHint ) + throws ComponentLookupException; + + /** + * Gets the component. + * + * @param clazz the clazz + * @param roleHint the role hint + * + * @return the component + * + * @throws ComponentLookupException the component lookup exception + */ + T getComponent ( Class clazz, String roleHint ) + throws ComponentLookupException; + + /** + * Gets the component map. + * + * @param role the role + * + * @return the component map + * + * @throws ComponentLookupException the component lookup exception + */ + Map getComponentMap ( String role ) + throws ComponentLookupException; + + /** + * Gets the component list. + * + * @param role the role + * + * @return the component list + * + * @throws ComponentLookupException the component lookup exception + */ + List getComponentList ( String role ) + throws ComponentLookupException; + + /** + * Gets the container. + * + * @return the container + */ + PlexusContainer getContainer(); +} diff --git a/Java-base/maven-enforcer/src/enforcer-api/src/site/apt/index.apt b/Java-base/maven-enforcer/src/enforcer-api/src/site/apt/index.apt new file mode 100644 index 000000000..5454a6f56 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-api/src/site/apt/index.apt @@ -0,0 +1,32 @@ +~~ 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. + + ------ + Introduction + ------ + Brian Fox + ------ + Mar 2007 + ------ + +Maven Enforcer Rule API - Extending The Loving Iron Fist of Maven\x99 + + Custom rules are easy to make with the <<>>. These rules can then be invoked with the + {{{../../plugins/maven-enforcer-plugin/}maven-enforcer-plugin}}. + + See {{{./writing-a-custom-rule.html}Writing a Custom Rule}} for instructions on how to make your own rule. + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/enforcer-api/src/site/apt/writing-a-custom-rule.apt.vm b/Java-base/maven-enforcer/src/enforcer-api/src/site/apt/writing-a-custom-rule.apt.vm new file mode 100644 index 000000000..feeb30a23 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-api/src/site/apt/writing-a-custom-rule.apt.vm @@ -0,0 +1,292 @@ +~~ 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. + + ------ + Writing a custom rule + ------ + Brian Fox + ------ + Nov 2007 + ------ + +Writing a custom rule + + Custom rules are easy to make with the <<>>. These rules can then be invoked with the + {{{http://maven.apache.org/plugins/maven-enforcer-plugin/}maven-enforcer-plugin}}. + + Note: The files shown below may be downloaded here: {{{./custom-rule.zip}custom-rule.zip}} + + [[1]] First make a new jar project starting with the sample pom below: + ++---+ + + + 4.0.0 + + custom-rule + custom-rule-sample + jar + 1.0 + + My Custom Rule + This is my custom rule. + + + ${project.version} + 2.0.9 + + + + + org.apache.maven.enforcer + enforcer-api + ${api.version} + + + org.apache.maven + maven-project + ${maven.version} + + + org.apache.maven + maven-core + ${maven.version} + + + org.apache.maven + maven-artifact + ${maven.version} + + + org.apache.maven + maven-plugin-api + ${maven.version} + + + org.codehaus.plexus + plexus-container-default + 1.0-alpha-9 + + + junit + junit + 3.8.2 + test + + + + + + ++---+ + + [[2]] Create your rule class. The rule must implement the {{{./apidocs/index.html}EnforcerRule}} interface. + The rule can get access to components and the log via the {{{./apidocs/index.html}EnforcerRuleHelper}} interface. + If the rule succeeds, it should just simply return. If the rule fails, it should throw an {{{./apidocs/index.html}EnforcerRuleException}} with a descriptive message telling the user why the rule failed. + + There are several methods that must be implemented related to caching. + + Here's a sample class that shows how to access the helper methods and retrieve components by class name from the helper: + ++---+ +package org.apache.maven.enforcer.rule; + +import org.apache.maven.artifact.resolver.ArtifactResolver; +import org.apache.maven.enforcer.rule.api.EnforcerRule; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.execution.RuntimeInformation; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; + +/** + * @author Brian Fox + */ +public class MyCustomRule + implements EnforcerRule +{ + /** + * Simple param. This rule will fail if the value is true. + */ + private boolean shouldIfail = false; + + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + Log log = helper.getLog(); + + try + { + // get the various expressions out of the helper. + MavenProject project = (MavenProject) helper.evaluate( "\${project}" ); + MavenSession session = (MavenSession) helper.evaluate( "${session}" ); + String target = (String) helper.evaluate( "\${project.build.directory}" ); + String artifactId = (String) helper.evaluate( "\${project.artifactId}" ); + + // retrieve any component out of the session directly + ArtifactResolver resolver = (ArtifactResolver) helper.getComponent( ArtifactResolver.class ); + RuntimeInformation rti = (RuntimeInformation) helper.getComponent( RuntimeInformation.class ); + + log.info( "Retrieved Target Folder: " + target ); + log.info( "Retrieved ArtifactId: " +artifactId ); + log.info( "Retrieved Project: " + project ); + log.info( "Retrieved RuntimeInfo: " + rti ); + log.info( "Retrieved Session: " + session ); + log.info( "Retrieved Resolver: " + resolver ); + + if ( this.shouldIfail ) + { + throw new EnforcerRuleException( "Failing because my param said so." ); + } + } + catch ( ComponentLookupException e ) + { + throw new EnforcerRuleException( "Unable to lookup a component " + e.getLocalizedMessage(), e ); + } + catch ( ExpressionEvaluationException e ) + { + throw new EnforcerRuleException( "Unable to lookup an expression " + e.getLocalizedMessage(), e ); + } + } + + /** + * If your rule is cacheable, you must return a unique id when parameters or conditions + * change that would cause the result to be different. Multiple cached results are stored + * based on their id. + * + * The easiest way to do this is to return a hash computed from the values of your parameters. + * + * If your rule is not cacheable, then the result here is not important, you may return anything. + */ + public String getCacheId() + { + //no hash on boolean...only parameter so no hash is needed. + return ""+this.shouldIfail; + } + + /** + * This tells the system if the results are cacheable at all. Keep in mind that during + * forked builds and other things, a given rule may be executed more than once for the same + * project. This means that even things that change from project to project may still + * be cacheable in certain instances. + */ + public boolean isCacheable() + { + return false; + } + + /** + * If the rule is cacheable and the same id is found in the cache, the stored results + * are passed to this method to allow double checking of the results. Most of the time + * this can be done by generating unique ids, but sometimes the results of objects returned + * by the helper need to be queried. You may for example, store certain objects in your rule + * and then query them later. + */ + public boolean isResultValid( EnforcerRule arg0 ) + { + return false; + } +} ++---+ + + [[3]] Build and Install or Deploy your custom rule. + + [[4]] Add your custom-rule artifact as a dependency of the <<>> in your build: + ++---+ + + ... + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + custom-rule + custom-rule-sample + 1.0 + + + ... + + + + ... + ++---+ + + [[5]] Add your rule to the configuration section of the <<>>. The name of your class will be the name of the rule, and + you must add an <<>> hint that contains the fully qualified class name: + ++---+ + ... + + + + true + + + + ... ++---+ + + [[6]] That's it. The full plugin config may look like this: + ++---+ + + ... + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + custom-rule + custom-rule-sample + 1.0 + + + + + enforce + + + + false + + + + + enforce + + + + + + + ... + ++---+ \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/enforcer-api/src/site/site.xml b/Java-base/maven-enforcer/src/enforcer-api/src/site/site.xml new file mode 100644 index 000000000..a32d776be --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-api/src/site/site.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/enforcer-rules/pom.xml b/Java-base/maven-enforcer/src/enforcer-rules/pom.xml new file mode 100644 index 000000000..03077da51 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/pom.xml @@ -0,0 +1,129 @@ + + + + 4.0.0 + + + org.apache.maven.enforcer + enforcer + 3.0.0-M4-SNAPSHOT + + + enforcer-rules + + Apache Maven Enforcer Built-In Rules + This component contains the built-in Enforcer Rules + + + + org.apache.maven + maven-artifact + + + org.apache.maven + maven-plugin-api + + + org.apache.maven + maven-core + + + org.apache.maven.shared + maven-common-artifact-filters + + + org.codehaus.plexus + plexus-utils + + + org.apache.maven.plugin-testing + maven-plugin-testing-harness + test + + + org.apache.commons + commons-lang3 + + + commons-codec + commons-codec + + + org.apache.maven.enforcer + enforcer-api + + + org.beanshell + bsh + 2.0b4 + + + junit + junit + test + + + org.mockito + mockito-core + test + + + org.apache.maven.shared + maven-dependency-tree + + + org.eclipse.aether + aether-util + + + + + org.apache.maven.resolver + maven-resolver-util + + + org.apache.maven + maven-compat + + + org.assertj + assertj-core + test + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + test-jar + + + + + + + diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractBanDependencies.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractBanDependencies.java new file mode 100644 index 000000000..8a8a3315b --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractBanDependencies.java @@ -0,0 +1,192 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.plugins.enforcer.utils.ArtifactUtils; +import org.apache.maven.project.MavenProject; +import org.apache.maven.shared.dependency.graph.DependencyGraphBuilder; +import org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException; +import org.apache.maven.shared.dependency.graph.DependencyNode; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * Abstract Rule for banning dependencies. + * + * @author Brian Fox + */ +public abstract class AbstractBanDependencies + extends AbstractNonCacheableEnforcerRule +{ + + /** Specify if transitive dependencies should be searched (default) or only look at direct dependencies. */ + private boolean searchTransitive = true; + + private transient DependencyGraphBuilder graphBuilder; + + /** + * Contains the full list of projects in the reactor. + */ + private transient List reactorProjects; + + @Override + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + + // get the project + MavenProject project = null; + try + { + project = (MavenProject) helper.evaluate( "${project}" ); + } + catch ( ExpressionEvaluationException eee ) + { + throw new EnforcerRuleException( "Unable to retrieve the MavenProject: ", eee ); + } + + // get the reactor projects + try + { + reactorProjects = (List) helper.evaluate( "${reactorProjects}" ); + } + catch ( ExpressionEvaluationException eee ) + { + throw new EnforcerRuleException( "Unable to retrieve the reactor MavenProject: ", eee ); + } + + try + { + graphBuilder = (DependencyGraphBuilder) helper.getComponent( DependencyGraphBuilder.class ); + } + catch ( ComponentLookupException e ) + { + // real cause is probably that one of the Maven3 graph builder could not be initiated and fails with a + // ClassNotFoundException + try + { + graphBuilder = + (DependencyGraphBuilder) helper.getComponent( DependencyGraphBuilder.class.getName(), "maven2" ); + } + catch ( ComponentLookupException e1 ) + { + throw new EnforcerRuleException( "Unable to lookup DependencyGraphBuilder: ", e ); + } + } + + // get the correct list of dependencies + Set dependencies = getDependenciesToCheck( project ); + + // look for banned dependencies + Set foundExcludes = checkDependencies( dependencies, helper.getLog() ); + + // if any are found, fail the check but list all of them + if ( foundExcludes != null && !foundExcludes.isEmpty() ) + { + String message = getMessage(); + + StringBuilder buf = new StringBuilder(); + if ( message != null ) + { + buf.append( message + System.lineSeparator() ); + } + for ( Artifact artifact : foundExcludes ) + { + buf.append( getErrorMessage( artifact ) ); + } + message = buf.toString() + "Use 'mvn dependency:tree' to locate the source of the banned dependencies."; + + throw new EnforcerRuleException( message ); + } + + } + + protected CharSequence getErrorMessage( Artifact artifact ) + { + return "Found Banned Dependency: " + artifact.getId() + System.lineSeparator(); + } + + protected Set getDependenciesToCheck( MavenProject project ) + { + Set dependencies = null; + try + { + DependencyNode node = graphBuilder.buildDependencyGraph( project, null, reactorProjects ); + if ( searchTransitive ) + { + dependencies = ArtifactUtils.getAllDescendants( node ); + } + else if ( node.getChildren() != null ) + { + dependencies = new HashSet<>(); + for ( DependencyNode depNode : node.getChildren() ) + { + dependencies.add( depNode.getArtifact() ); + } + } + } + catch ( DependencyGraphBuilderException e ) + { + // otherwise we need to change the signature of this protected method + throw new RuntimeException( e ); + } + return dependencies; + } + + /** + * Checks the set of dependencies against the list of excludes. + * + * @param dependencies the dependencies + * @param log the log + * @return the sets the + * @throws EnforcerRuleException the enforcer rule exception + */ + protected abstract Set checkDependencies( Set dependencies, Log log ) + throws EnforcerRuleException; + + /** + * Checks if is search transitive. + * + * @return the searchTransitive + */ + public boolean isSearchTransitive() + { + return this.searchTransitive; + } + + /** + * Sets the search transitive. + * + * @param theSearchTransitive the searchTransitive to set + */ + public void setSearchTransitive( boolean theSearchTransitive ) + { + this.searchTransitive = theSearchTransitive; + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractNonCacheableEnforcerRule.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractNonCacheableEnforcerRule.java new file mode 100644 index 000000000..169c641dd --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractNonCacheableEnforcerRule.java @@ -0,0 +1,50 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import org.apache.maven.enforcer.rule.api.EnforcerRule; + +/** + * The Class AbstractNonCacheableEnforcerRule. This is to be used by rules + * that don't need caching... it saves implementing a bunch of methods. + * + * @author Brian Fox + */ +public abstract class AbstractNonCacheableEnforcerRule + extends AbstractStandardEnforcerRule +{ + @Override + public String getCacheId() + { + return "0"; + } + + @Override + public boolean isCacheable() + { + return false; + } + + @Override + public boolean isResultValid( EnforcerRule cachedRule ) + { + return false; + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractPropertyEnforcerRule.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractPropertyEnforcerRule.java new file mode 100755 index 000000000..fade2a218 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractPropertyEnforcerRule.java @@ -0,0 +1,143 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; + +/** + * Abstract enforcer rule that give a foundation to validate properties from multiple sources. + * + * @author Paul Gier + * @author Marvin Froeder + */ +public abstract class AbstractPropertyEnforcerRule + extends AbstractNonCacheableEnforcerRule +{ + + /** + * Match the property value to a given regular expression. Defaults to null (any value is ok). + * + * @see {@link #setRegex(String)} + * @see {@link #getRegex()} + */ + private String regex = null; + + /** + * Specify a warning message if the regular expression is not matched. + * + * @see {@link #setRegexMessage(String)} + * @see {@link #getRegexMessage()} + */ + private String regexMessage = null; + + public AbstractPropertyEnforcerRule() + { + super(); + } + + /** + * Set the property value to a given regular expression. Defaults to null (any value is ok). + * + * @param regex The regular expression + */ + public final void setRegex( String regex ) + { + this.regex = regex; + } + + /** + * Get the property value to a given regular expression. Defaults to null (any value is ok). + * + * @return the regular expression + */ + public final String getRegex() + { + return regex; + } + + /** + * Set a warning message if the regular expression is not matched. + * + * @param regexMessage the regex message + */ + public final void setRegexMessage( String regexMessage ) + { + this.regexMessage = regexMessage; + } + + /** + * Get a warning message if the regular expression is not matched. + * + * @return the regex message + */ + public final String getRegexMessage() + { + return regexMessage; + } + + @Override + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + Object propValue = resolveValue( helper ); + + // Check that the property is not null or empty string + if ( propValue == null ) + { + String message = getMessage(); + if ( message == null ) + { + message = getName() + " \"" + getPropertyName() + "\" is required for this build."; + } + throw new EnforcerRuleException( message ); + } + // If there is a regex, check that the property matches it + if ( regex != null && !propValue.toString().matches( regex ) ) + { + if ( regexMessage == null ) + { + regexMessage = getName() + " \"" + getPropertyName() + "\" evaluates to \"" + propValue + "\". " + + "This does not match the regular expression \"" + regex + "\""; + } + throw new EnforcerRuleException( regexMessage ); + } + } + + /** + * How the property that is being evaluated is called + */ + public abstract String getName(); + + /** + * The name of the property currently being evaluated, this is used for default message pourpouses only + */ + public abstract String getPropertyName(); + + /** + * Resolves the property value + * + * @param helper + * @throws EnforcerRuleException + */ + public abstract Object resolveValue( EnforcerRuleHelper helper ) + throws EnforcerRuleException; + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractRequireFiles.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractRequireFiles.java new file mode 100644 index 000000000..6b1de7467 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractRequireFiles.java @@ -0,0 +1,171 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import org.apache.maven.enforcer.rule.api.EnforcerRule; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; + +/** + * Contains the common code to compare an array of files against a requirement. + * + * @author Brian Fox + */ +public abstract class AbstractRequireFiles + extends AbstractStandardEnforcerRule +{ + + /** Array of files to check. */ + private File[] files; + + /** if null file handles should be allowed. If they are allowed, it means treat it as a success. */ + private boolean allowNulls = false; + + // check the file for the specific condition + /** + * Check one file. + * + * @param file the file + * @return true if successful + */ + abstract boolean checkFile( File file ); + + // return standard error message + /** + * Gets the error msg. + * + * @return the error msg + */ + abstract String getErrorMsg(); + + @Override + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + + if ( !allowNulls && files.length == 0 ) + { + throw new EnforcerRuleException( "The file list is empty and Null files are disabled." ); + } + + List failures = new ArrayList<>(); + for ( File file : files ) + { + if ( !allowNulls && file == null ) + { + failures.add( file ); + } + else if ( !checkFile( file ) ) + { + failures.add( file ); + } + } + + // if anything was found, log it with the optional message. + if ( !failures.isEmpty() ) + { + String message = getMessage(); + + StringBuilder buf = new StringBuilder(); + if ( message != null ) + { + buf.append( message + System.lineSeparator() ); + } + buf.append( getErrorMsg() ); + + for ( File file : failures ) + { + if ( file != null ) + { + buf.append( file.getAbsolutePath() + System.lineSeparator() ); + } + else + { + buf.append( "(an empty filename was given and allowNulls is false)" + System.lineSeparator() ); + } + } + + throw new EnforcerRuleException( buf.toString() ); + } + } + + @Override + public String getCacheId() + { + return Integer.toString( hashCode( files ) ); + } + + /** + * Calculates a hash code for the specified array as Arrays.hashCode() would do. Unfortunately, the + * mentioned method is only available for Java 1.5 and later. + * + * @param items The array for which to compute the hash code, may be null. + * @return The hash code for the array. + */ + private static int hashCode( Object[] items ) + { + int hash = 0; + if ( items != null ) + { + hash = 1; + for ( Object item : items ) + { + hash = 31 * hash + ( item == null ? 0 : item.hashCode() ); + } + } + return hash; + } + + @Override + public boolean isCacheable() + { + return true; + } + + @Override + public boolean isResultValid( EnforcerRule cachedRule ) + { + return true; + } + + public File[] getFiles() + { + return files; + } + + public void setFiles( File[] files ) + { + this.files = files; + } + + public boolean isAllowNulls() + { + return allowNulls; + } + + public void setAllowNulls( boolean allowNulls ) + { + this.allowNulls = allowNulls; + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractStandardEnforcerRule.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractStandardEnforcerRule.java new file mode 100644 index 000000000..fecdb0900 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractStandardEnforcerRule.java @@ -0,0 +1,63 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import org.apache.maven.enforcer.rule.api.EnforcerLevel; +import org.apache.maven.enforcer.rule.api.EnforcerRule2; + +/** + * The Class AbstractStandardEnforcerRule. + */ +public abstract class AbstractStandardEnforcerRule + implements EnforcerRule2 +{ + + /** + * Specify a friendly message if the rule fails. + * + * @see {@link #setMessage(String)} + * @see {@link #getMessage()} + */ + private String message; + + private EnforcerLevel level = EnforcerLevel.ERROR; + + public final void setMessage( String message ) + { + this.message = message; + } + + public final String getMessage() + { + return message; + } + + @Override + public EnforcerLevel getLevel() + { + return level; + } + + public void setLevel( EnforcerLevel level ) + { + this.level = level; + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractVersionEnforcer.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractVersionEnforcer.java new file mode 100644 index 000000000..bedf7ddc8 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractVersionEnforcer.java @@ -0,0 +1,209 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.util.List; + +import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; +import org.apache.maven.artifact.versioning.Restriction; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.enforcer.rule.api.EnforcerRule; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.plugin.logging.Log; +import org.codehaus.plexus.util.StringUtils; + +/** + * Contains the common code to compare a version against a version range. + * + * @author Brian Fox + */ +public abstract class AbstractVersionEnforcer + extends AbstractStandardEnforcerRule +{ + + /** + * Specify the required version. Some examples are: + *
    + *
  • 2.0.4 Version 2.0.4 and higher (different from Maven meaning)
  • + *
  • [2.0,2.1) Versions 2.0 (included) to 2.1 (not included)
  • + *
  • [2.0,2.1] Versions 2.0 to 2.1 (both included)
  • + *
  • [2.0.5,) Versions 2.0.5 and higher
  • + *
  • (,2.0.5],[2.1.1,) Versions up to 2.0.5 (included) and 2.1.1 or higher
  • + *
+ * + * @see {@link #setVersion(String)} + * @see {@link #getVersion()} + */ + private String version; + + /** + * Compares the specified version to see if it is allowed by the defined version range. + * + * @param log the log + * @param variableName name of variable to use in messages (Example: "Maven" or "Java" etc). + * @param requiredVersionRange range of allowed versions. + * @param actualVersion the version to be checked. + * @throws EnforcerRuleException the enforcer rule exception + */ + // CHECKSTYLE_OFF: LineLength + public void enforceVersion( Log log, String variableName, String requiredVersionRange, ArtifactVersion actualVersion ) + throws EnforcerRuleException + // CHECKSTYLE_ON: LineLength + { + if ( StringUtils.isEmpty( requiredVersionRange ) ) + { + throw new EnforcerRuleException( variableName + " version can't be empty." ); + } + else + { + + VersionRange vr; + String msg = "Detected " + variableName + " Version: " + actualVersion; + + // short circuit check if the strings are exactly equal + if ( actualVersion.toString().equals( requiredVersionRange ) ) + { + log.debug( msg + " is allowed in the range " + requiredVersionRange + "." ); + } + else + { + try + { + vr = VersionRange.createFromVersionSpec( requiredVersionRange ); + + if ( containsVersion( vr, actualVersion ) ) + { + log.debug( msg + " is allowed in the range " + requiredVersionRange + "." ); + } + else + { + String message = getMessage(); + + if ( StringUtils.isEmpty( message ) ) + { + message = msg + " is not in the allowed range " + vr + "."; + } + + throw new EnforcerRuleException( message ); + } + } + catch ( InvalidVersionSpecificationException e ) + { + throw new EnforcerRuleException( "The requested " + variableName + " version " + + requiredVersionRange + " is invalid.", e ); + } + } + } + } + + /** + * Copied from Artifact.VersionRange. This is tweaked to handle singular ranges properly. Currently the default + * containsVersion method assumes a singular version means allow everything. This method assumes that "2.0.4" == + * "[2.0.4,)" + * + * @param allowedRange range of allowed versions. + * @param theVersion the version to be checked. + * @return true if the version is contained by the range. + */ + public static boolean containsVersion( VersionRange allowedRange, ArtifactVersion theVersion ) + { + boolean matched = false; + ArtifactVersion recommendedVersion = allowedRange.getRecommendedVersion(); + if ( recommendedVersion == null ) + { + List restrictions = allowedRange.getRestrictions(); + for ( Restriction restriction : restrictions ) + { + if ( restriction.containsVersion( theVersion ) ) + { + matched = true; + break; + } + } + } + else + { + // only singular versions ever have a recommendedVersion + @SuppressWarnings( "unchecked" ) + int compareTo = recommendedVersion.compareTo( theVersion ); + matched = ( compareTo <= 0 ); + } + return matched; + } + + @Override + public String getCacheId() + { + if ( StringUtils.isNotEmpty( version ) ) + { + // return the hashcodes of the parameter that matters + return "" + version.hashCode(); + } + else + { + return "0"; + } + + } + + @Override + public boolean isCacheable() + { + // the maven version is not going to change between projects in the same build. + return true; + } + + @Override + public boolean isResultValid( EnforcerRule theCachedRule ) + { + // i will always return the hash of the parameters as my id. If my parameters are the same, this + // rule must always have the same result. + return true; + } + + /** + * Gets the required version. + * + * @return the required version + */ + public final String getVersion() + { + return this.version; + } + + /** + * Specify the required version. Some examples are: + *
    + *
  • 2.0.4 Version 2.0.4 and higher (different from Maven meaning)
  • + *
  • [2.0,2.1) Versions 2.0 (included) to 2.1 (not included)
  • + *
  • [2.0,2.1] Versions 2.0 to 2.1 (both included)
  • + *
  • [2.0.5,) Versions 2.0.5 and higher
  • + *
  • (,2.0.5],[2.1.1,) Versions up to 2.0.5 (included) and 2.1.1 or higher
  • + *
+ * + * @param theVersion the required version to set + */ + public final void setVersion( String theVersion ) + { + this.version = theVersion; + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AlwaysFail.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AlwaysFail.java new file mode 100644 index 000000000..e40a7b59c --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AlwaysFail.java @@ -0,0 +1,48 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; + +/** + * Always fail. This rule is useful for testing the Enforcer configuration, or to always fail the build if a particular + * profile is enabled. + * @author Ben Lidgey + */ +public class AlwaysFail + extends AbstractNonCacheableEnforcerRule +{ + + @Override + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + String message = getMessage(); + + StringBuilder buf = new StringBuilder(); + if ( message != null ) + { + buf.append( message ).append( System.lineSeparator() ); + } + buf.append( "Always fails!" ); + throw new EnforcerRuleException( buf.toString() ); + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AlwaysPass.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AlwaysPass.java new file mode 100644 index 000000000..f5906e1ae --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AlwaysPass.java @@ -0,0 +1,51 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.plugin.logging.Log; + +/** + * Always pass. This rule is useful for testing the Enforcer configuration. + * @author Ben Lidgey + */ +public class AlwaysPass + extends AbstractNonCacheableEnforcerRule +{ + + @Override + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + final Log log = helper.getLog(); + + String message = getMessage(); + + StringBuilder buf = new StringBuilder(); + if ( message != null ) + { + buf.append( message ).append( System.lineSeparator() ); + } + buf.append( "Always pass!" ); + log.info( buf.toString() ); + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BanDistributionManagement.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BanDistributionManagement.java new file mode 100644 index 000000000..601b56f12 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BanDistributionManagement.java @@ -0,0 +1,128 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.plugins.enforcer.utils.DistributionManagementCheck; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; + +/** + * This rule will check if a pom contains a distributionManagement part. This should be by best practice + * only defined once. It could happen that you like to check the parent as well. This can be activated by using the + * ignoreParent which is by default turned off (true) which means not to check the parent. + * + * @author Karl Heinz Marbaise + * @since 1.4 + */ +public class BanDistributionManagement + extends AbstractNonCacheableEnforcerRule +{ + + /** + * Allow using a repository entry in the distributionManagement area. + */ + private boolean allowRepository = false; + + /** + * Allow snapshotRepository entry in the distributionManagement area. + */ + private boolean allowSnapshotRepository = false; + + /** + * Allow site entry in the distributionManagement area. + */ + private boolean allowSite = false; + + private Log logger; + + @Override + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + logger = helper.getLog(); + + try + { + MavenProject project = (MavenProject) helper.evaluate( "${project}" ); + + if ( project.isExecutionRoot() ) + { + if ( project.getParent() == null ) + { + // Does it make sense to check something? If yes please make a JIRA ticket for it. + logger.debug( "We have no parent and in the root of a build we don't check anything," ); + logger.debug( "because that is the location where we defined maven-enforcer-plugin." ); + } + else + { + logger.debug( "We are in the root of the execution and we have a parent." ); + + DistributionManagementCheck check = new DistributionManagementCheck( project ); + check.execute( isAllowRepository(), isAllowSnapshotRepository(), isAllowSite() ); + } + } + else + { + logger.debug( "We are in a deeper level." ); + DistributionManagementCheck check = new DistributionManagementCheck( project ); + check.execute( isAllowRepository(), isAllowSnapshotRepository(), isAllowSite() ); + + } + } + catch ( ExpressionEvaluationException e ) + { + throw new EnforcerRuleException( e.getMessage(), e ); + } + } + + public boolean isAllowRepository() + { + return allowRepository; + } + + public void setAllowRepository( boolean allowRepository ) + { + this.allowRepository = allowRepository; + } + + public boolean isAllowSnapshotRepository() + { + return allowSnapshotRepository; + } + + public void setAllowSnapshotRepository( boolean allowSnapshotRepository ) + { + this.allowSnapshotRepository = allowSnapshotRepository; + } + + public boolean isAllowSite() + { + return allowSite; + } + + public void setAllowSite( boolean allowSite ) + { + this.allowSite = allowSite; + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BanDuplicatePomDependencyVersions.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BanDuplicatePomDependencyVersions.java new file mode 100644 index 000000000..311eea669 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BanDuplicatePomDependencyVersions.java @@ -0,0 +1,201 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.io.FileInputStream; +import java.io.IOException; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Model; +import org.apache.maven.model.Profile; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +/** + * Since Maven 3 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique. Early versions of Maven + * 3 already warn, this rule can force to break a build for this reason. + * + * @author Robert Scholte + * @since 1.3 + */ +public class BanDuplicatePomDependencyVersions + extends AbstractNonCacheableEnforcerRule +{ + @Override + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + // get the project + MavenProject project; + try + { + project = (MavenProject) helper.evaluate( "${project}" ); + } + catch ( ExpressionEvaluationException eee ) + { + throw new EnforcerRuleException( "Unable to retrieve the MavenProject: ", eee ); + } + + // re-read model, because M3 uses optimized model + MavenXpp3Reader modelReader = new MavenXpp3Reader(); + + Model model; + try ( FileInputStream pomInputStream = new FileInputStream( project.getFile() ) ) + { + model = modelReader.read( pomInputStream, false ); + } + catch ( IOException | XmlPullParserException e ) + { + throw new EnforcerRuleException( "Unable to retrieve the MavenProject: ", e ); + } + + // @todo reuse ModelValidator when possible + + // Object modelValidator = null; + // try + // { + // modelValidator = helper.getComponent( "org.apache.maven.model.validation.ModelValidator" ); + // } + // catch ( ComponentLookupException e1 ) + // { + // // noop + // } + + // if( modelValidator == null ) + // { + maven2Validation( helper, model ); + // } + // else + // { + // } + } + + private void maven2Validation( EnforcerRuleHelper helper, Model model ) + throws EnforcerRuleException + { + List dependencies = model.getDependencies(); + Map duplicateDependencies = validateDependencies( dependencies ); + + int duplicates = duplicateDependencies.size(); + + StringBuilder summary = new StringBuilder(); + messageBuilder( duplicateDependencies, "dependencies.dependency", summary ); + + if ( model.getDependencyManagement() != null ) + { + List managementDependencies = model.getDependencies(); + Map duplicateManagementDependencies = validateDependencies( managementDependencies ); + duplicates += duplicateManagementDependencies.size(); + + messageBuilder( duplicateManagementDependencies, "dependencyManagement.dependencies.dependency", summary ); + } + + List profiles = model.getProfiles(); + for ( Profile profile : profiles ) + { + List profileDependencies = profile.getDependencies(); + + Map duplicateProfileDependencies = validateDependencies( profileDependencies ); + + duplicates += duplicateProfileDependencies.size(); + + messageBuilder( duplicateProfileDependencies, "profiles.profile[" + profile.getId() + + "].dependencies.dependency", summary ); + + if ( model.getDependencyManagement() != null ) + { + List profileManagementDependencies = profile.getDependencies(); + + Map duplicateProfileManagementDependencies = + validateDependencies( profileManagementDependencies ); + + duplicates += duplicateProfileManagementDependencies.size(); + + messageBuilder( duplicateProfileManagementDependencies, "profiles.profile[" + profile.getId() + + "].dependencyManagement.dependencies.dependency", summary ); + } + } + + if ( summary.length() > 0 ) + { + StringBuilder message = new StringBuilder(); + message.append( "Found " ) + .append( duplicates ) + .append( " duplicate dependency " ); + message.append( duplicateDependencies.size() == 1 ? "declaration" : "declarations" ) + .append( " in this project:" + System.lineSeparator() ); + message.append( summary ); + throw new EnforcerRuleException( message.toString() ); + } + } + + private void messageBuilder( Map duplicateDependencies, String prefix, StringBuilder message ) + { + if ( !duplicateDependencies.isEmpty() ) + { + for ( Map.Entry entry : duplicateDependencies.entrySet() ) + { + message.append( " - " ) + .append( prefix ) + .append( '[' ) + .append( entry.getKey() ) + .append( "] ( " ) + .append( entry.getValue() ) + .append( " times )" + System.lineSeparator() ); + } + } + } + + private Map validateDependencies( List dependencies ) + throws EnforcerRuleException + { + Map duplicateDeps = new HashMap<>(); + Set deps = new HashSet<>(); + for ( Dependency dependency : dependencies ) + { + String key = dependency.getManagementKey(); + + if ( deps.contains( key ) ) + { + int times = 1; + if ( duplicateDeps.containsKey( key ) ) + { + times = duplicateDeps.get( key ); + } + duplicateDeps.put( key, times + 1 ); + } + else + { + deps.add( key ); + } + } + return duplicateDeps; + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BanTransitiveDependencies.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BanTransitiveDependencies.java new file mode 100644 index 000000000..d307fdad9 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BanTransitiveDependencies.java @@ -0,0 +1,204 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.util.Collections; +import java.util.List; + +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; +import org.apache.maven.enforcer.rule.api.EnforcerRule; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.plugins.enforcer.utils.ArtifactMatcher; +import org.apache.maven.project.MavenProject; +import org.apache.maven.shared.dependency.graph.DependencyGraphBuilder; +import org.apache.maven.shared.dependency.graph.DependencyNode; +import org.apache.maven.shared.dependency.graph.internal.DefaultDependencyGraphBuilder; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import org.codehaus.plexus.logging.console.ConsoleLogger; + +/** + * This rule bans all transitive dependencies. There is a configuration option to exclude certain artifacts from being + * checked. + * + * @author Jakub Senko + */ +public class BanTransitiveDependencies + extends AbstractNonCacheableEnforcerRule + implements EnforcerRule +{ + + private EnforcerRuleHelper helper; + + /** + * Specify the dependencies that will be ignored. This can be a list of artifacts in the format + * groupId[:artifactId][:version][:type][:scope]. Wildcard '*' can be used to in place of specific + * section (ie group:*:1.0 will match both 'group:artifact:1.0' and 'group:anotherArtifact:1.0')
+ * You can override this patterns by using includes. Version is a string representing standard maven version range. + * Empty patterns will be ignored. + */ + private List excludes; + + /** + * Specify the dependencies that will be checked. These are exceptions to excludes intended for more convenient and + * finer settings. This can be a list of artifacts in the format + * groupId[:artifactId][:version][:type][:scope]. Wildcard '*' can be used to in place of specific + * section (ie group:*:1.0 will match both 'group:artifact:1.0' and 'group:anotherArtifact:1.0')
+ * Version is a string representing standard maven version range. Empty patterns will be ignored. + */ + private List includes; + + /** + * Searches dependency tree recursively for transitive dependencies that are not excluded, while generating nice + * info message along the way. + * + * @throws InvalidVersionSpecificationException + */ + private static boolean searchTree( DependencyNode node, int level, ArtifactMatcher excludes, StringBuilder message ) + throws InvalidVersionSpecificationException + { + + List children = node.getChildren(); + + /* + * if the node is deeper than direct dependency and is empty, it is transitive. + */ + boolean hasTransitiveDependencies = level > 1; + + boolean excluded = false; + + /* + * holds recursive message from children, will be appended to current message if this node has any transitive + * descendants if message is null, don't generate recursive message. + */ + StringBuilder messageFromChildren = message == null ? null : new StringBuilder(); + + if ( excludes.match( node.getArtifact() ) ) + { + // is excluded, we don't care about descendants + excluded = true; + hasTransitiveDependencies = false; + } + else + { + for ( DependencyNode childNode : children ) + { + /* + * if any of the children has transitive d. so does the parent + */ + hasTransitiveDependencies = + ( searchTree( childNode, level + 1, excludes, messageFromChildren ) || hasTransitiveDependencies ); + } + } + + if ( ( excluded || hasTransitiveDependencies ) && message != null ) // then generate message + { + for ( int i = 0; i < level; i++ ) + { + message.append( " " ); + } + + message.append( node.getArtifact() ); + + if ( excluded ) + { + message.append( " [excluded]" + System.lineSeparator() ); + } + + if ( hasTransitiveDependencies ) + { + if ( level == 1 ) + { + message.append( " has transitive dependencies:" ); + } + + message.append( System.lineSeparator() ).append( messageFromChildren ); + } + } + + return hasTransitiveDependencies; + } + + @Override + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + this.helper = helper; + + if ( excludes == null ) + { + excludes = Collections.emptyList(); + } + if ( includes == null ) + { + includes = Collections.emptyList(); + } + + final ArtifactMatcher exclusions = new ArtifactMatcher( excludes, includes ); + + DependencyNode rootNode = null; + + try + { + MavenProject project = (MavenProject) helper.evaluate( "${project}" ); + List reactorProjects = (List) helper.evaluate( "${reactorProjects}" ); + rootNode = createDependencyGraphBuilder().buildDependencyGraph( project, null, reactorProjects ); + } + catch ( Exception e ) + { + throw new EnforcerRuleException( "Error: Could not construct dependency tree.", e ); + } + + String message = getMessage(); + StringBuilder generatedMessage = null; + if ( message == null ) + { + generatedMessage = new StringBuilder(); + } + + try + { + if ( searchTree( rootNode, 0, exclusions, generatedMessage ) ) + { + throw new EnforcerRuleException( message == null ? generatedMessage.toString() : message ); + } + } + catch ( InvalidVersionSpecificationException e ) + { + throw new EnforcerRuleException( "Error: Invalid version range.", e ); + } + + } + + private DependencyGraphBuilder createDependencyGraphBuilder() + throws ComponentLookupException + { + // CHECKSTYLE_OFF: LineLength + DefaultDependencyGraphBuilder builder = + (DefaultDependencyGraphBuilder) helper.getContainer().lookup( DependencyGraphBuilder.class.getCanonicalName(), + "default" ); + // CHECKSTYLE_ON: LineLength + + builder.enableLogging( new ConsoleLogger( ConsoleLogger.LEVEL_DISABLED, "DefaultDependencyGraphBuilder" ) ); + + return builder; + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BannedDependencies.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BannedDependencies.java new file mode 100644 index 000000000..29785faa8 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BannedDependencies.java @@ -0,0 +1,140 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.util.List; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.plugins.enforcer.utils.ArtifactUtils; + +/** + * This rule checks that lists of dependencies are not included. + * + * @author Brian Fox + */ +public class BannedDependencies + extends AbstractBanDependencies +{ + + /** + * Specify the banned dependencies. This can be a list of artifacts in the format + * groupId[:artifactId][:version]. Any of the sections can be a wildcard + * by using '*' (ie group:*:1.0)
+ * The rule will fail if any dependency matches any exclude, unless it also matches + * an include rule. + * + * @see {@link #setExcludes(List)} + * @see {@link #getExcludes()} + */ + private List excludes = null; + + /** + * Specify the allowed dependencies. This can be a list of artifacts in the format + * groupId[:artifactId][:version]. Any of the sections can be a wildcard + * by using '*' (ie group:*:1.0)
+ * Includes override the exclude rules. It is meant to allow wide exclusion rules + * with wildcards and still allow a + * smaller set of includes.
+ * For example, to ban all xerces except xerces-api -> exclude "xerces", include "xerces:xerces-api" + * + * @see {@link #setIncludes(List)} + * @see {@link #getIncludes()} + */ + private List includes = null; + + @Override + protected Set checkDependencies( Set theDependencies, Log log ) + throws EnforcerRuleException + { + + Set excluded = ArtifactUtils.checkDependencies( theDependencies, excludes ); + + // anything specifically included should be removed + // from the ban list. + if ( excluded != null ) + { + Set included = ArtifactUtils.checkDependencies( theDependencies, includes ); + + if ( included != null ) + { + excluded.removeAll( included ); + } + } + return excluded; + + } + + /** + * Gets the excludes. + * + * @return the excludes + */ + public List getExcludes() + { + return this.excludes; + } + + /** + * Specify the banned dependencies. This can be a list of artifacts in the format + * groupId[:artifactId][:version]. Any of the sections can be a wildcard + * by using '*' (ie group:*:1.0)
+ * The rule will fail if any dependency matches any exclude, unless it also matches an + * include rule. + * + * @see #getExcludes() + * @param theExcludes the excludes to set + */ + public void setExcludes( List theExcludes ) + { + this.excludes = theExcludes; + } + + /** + * Gets the includes. + * + * @return the includes + */ + public List getIncludes() + { + return this.includes; + } + + /** + * Specify the allowed dependencies. This can be a list of artifacts in the format + * groupId[:artifactId][:version]. Any of the sections can be a wildcard + * by using '*' (ie group:*:1.0)
+ * Includes override the exclude rules. It is meant to allow wide exclusion rules with + * wildcards and still allow a + * smaller set of includes.
+ * For example, to ban all xerces except xerces-api → exclude "xerces", + * include "xerces:xerces-api" + * + * @see #setIncludes(List) + * @param theIncludes the includes to set + */ + public void setIncludes( List theIncludes ) + { + this.includes = theIncludes; + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BannedPlugins.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BannedPlugins.java new file mode 100644 index 000000000..03201fdc1 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BannedPlugins.java @@ -0,0 +1,47 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.project.MavenProject; + +/** + * This rule checks that lists of plugins are not included. + * + * @author Marvin Froeder + */ +public class BannedPlugins + extends BannedDependencies +{ + @Override + protected Set getDependenciesToCheck( MavenProject project ) + { + return project.getPluginArtifacts(); + } + + @Override + protected CharSequence getErrorMessage( Artifact artifact ) + { + return "Found Banned Plugin: " + artifact.getId() + System.lineSeparator(); + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BannedRepositories.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BannedRepositories.java new file mode 100644 index 000000000..95b1cd05b --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BannedRepositories.java @@ -0,0 +1,216 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.codehaus.plexus.util.StringUtils; + +/** + * This rule checks that this project's maven session whether have banned repositories. + * + * @author Simon Wang + */ +public class BannedRepositories + extends AbstractNonCacheableEnforcerRule +{ + + // ---------------------------------------------------------------------- + // Mojo parameters + // ---------------------------------------------------------------------- + + /** + * Specify explicitly banned non-plugin repositories. This is a list of repository url patterns. Support wildcard + * "*". + * + * @see {@link #setBannedRepositories(List)} + */ + private List bannedRepositories = Collections.emptyList(); + + /** + * Specify explicitly banned plugin repositories. This is a list of repository url patterns. Support wildcard "*". + * + * @see {@link #setBannedPluginRepositories(List)} + */ + private List bannedPluginRepositories = Collections.emptyList(); + + /** + * Specify explicitly allowed non-plugin repositories, then all others repositories would be banned. This is a list + * of repository url patterns. Support wildcard "*". + * + * @see {@link #setAllowedRepositories(List)} + */ + private List allowedRepositories = Collections.emptyList(); + + /** + * Specify explicitly allowed plugin repositories, then all others repositories would be banned. This is a list of + * repository url patterns. Support wildcard "*". + * + * @see {@link #setAllowedPluginRepositories(List)} + */ + private List allowedPluginRepositories = Collections.emptyList(); + + // ---------------------------------------------------------------------- + // Public methods + // ---------------------------------------------------------------------- + + @Override + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + MavenProject project; + try + { + project = (MavenProject) helper.evaluate( "${project}" ); + + List resultBannedRepos = + checkRepositories( project.getRemoteArtifactRepositories(), this.allowedRepositories, + this.bannedRepositories ); + + List resultBannedPluginRepos = + checkRepositories( project.getPluginArtifactRepositories(), this.allowedPluginRepositories, + this.bannedPluginRepositories ); + + String repoErrMsg = populateErrorMessage( resultBannedRepos, " " ); + String pluginRepoErrMsg = populateErrorMessage( resultBannedPluginRepos, " plugin " ); + + String errMsg = repoErrMsg + pluginRepoErrMsg; + + if ( errMsg != null && !StringUtils.isEmpty( errMsg ) ) + { + throw new EnforcerRuleException( errMsg ); + } + + } + catch ( ExpressionEvaluationException e ) + { + throw new EnforcerRuleException( e.getLocalizedMessage() ); + } + } + + // ---------------------------------------------------------------------- + // Protected methods + // ---------------------------------------------------------------------- + + protected void setBannedRepositories( List bannedRepositories ) + { + this.bannedRepositories = bannedRepositories; + } + + protected void setBannedPluginRepositories( List bannedPluginRepositories ) + { + this.bannedPluginRepositories = bannedPluginRepositories; + } + + protected void setAllowedRepositories( List allowedRepositories ) + { + this.allowedRepositories = allowedRepositories; + } + + protected void setAllowedPluginRepositories( List allowedPluginRepositories ) + { + this.allowedPluginRepositories = allowedPluginRepositories; + } + + // ---------------------------------------------------------------------- + // Private methods + // ---------------------------------------------------------------------- + + /** + * Check whether specified repositories have banned repositories. + * + * @param repositories: candidate repositories. + * @param includes : 'include' patterns. + * @param excludes : 'exclude' patterns. + * @return Banned repositories. + */ + private List checkRepositories( List repositories, List includes, + List excludes ) + { + List bannedRepos = new ArrayList<>(); + + for ( ArtifactRepository repo : repositories ) + { + String url = repo.getUrl().trim(); + if ( includes.size() > 0 && !match( url, includes ) ) + { + bannedRepos.add( repo ); + continue; + } + + if ( excludes.size() > 0 && match( url, excludes ) ) + { + bannedRepos.add( repo ); + } + + } + + return bannedRepos; + } + + private boolean match( String url, List patterns ) + { + for ( String pattern : patterns ) + { + if ( this.match( url, pattern ) ) + { + return true; + } + } + + return false; + } + + private boolean match( String text, String pattern ) + { + return text.matches( pattern.replace( "?", ".?" ).replace( "*", ".*?" ) ); + } + + private String populateErrorMessage( List resultBannedRepos, String errorMessagePrefix ) + { + StringBuffer errMsg = new StringBuffer( "" ); + if ( !resultBannedRepos.isEmpty() ) + { + errMsg.append( "Current maven session contains banned" + errorMessagePrefix + + "repository urls, please double check your pom or settings.xml:" + System.lineSeparator() + + getRepositoryUrlString( resultBannedRepos ) + System.lineSeparator() + System.lineSeparator() ); + } + + return errMsg.toString(); + } + + private String getRepositoryUrlString( List resultBannedRepos ) + { + StringBuilder urls = new StringBuilder( "" ); + for ( ArtifactRepository repo : resultBannedRepos ) + { + urls.append( repo.getId() + " - " + repo.getUrl() + System.lineSeparator() ); + } + return urls.toString(); + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/DefaultEnforcementRuleHelper.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/DefaultEnforcementRuleHelper.java new file mode 100644 index 000000000..e1c885852 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/DefaultEnforcementRuleHelper.java @@ -0,0 +1,142 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.io.File; +import java.util.List; +import java.util.Map; + +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.logging.Log; +import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; + +/** + * Default implementation of the EnforcementRuleHelper interface. This is used to help retrieve information from the + * session and provide useful elements like the log. + * + * @author Brian Fox + */ +public class DefaultEnforcementRuleHelper + implements EnforcerRuleHelper +{ + + /** The log. */ + private Log log; + + /** The evaluator. */ + private ExpressionEvaluator evaluator; + + /** The container. */ + private PlexusContainer container; + + /** + * Instantiates a new default enforcement rule helper. + * + * @param session the session + * @param evaluator the evaluator + * @param log the log + * @param container the container + */ + public DefaultEnforcementRuleHelper( MavenSession session, ExpressionEvaluator evaluator, Log log, + PlexusContainer container ) + { + this.evaluator = evaluator; + this.log = log; + if ( container != null ) + { + this.container = container; + } + else + { + this.container = session.getContainer(); + } + } + + @Override + public Log getLog() + { + return log; + } + + @Override + public File alignToBaseDirectory( File theFile ) + { + return evaluator.alignToBaseDirectory( theFile ); + } + + @Override + public Object evaluate( String theExpression ) + throws ExpressionEvaluationException + { + return evaluator.evaluate( theExpression ); + } + + @Override + public T getComponent( Class clazz ) + throws ComponentLookupException + { + return container.lookup( clazz ); + } + + @Override + public Object getComponent( String theComponentKey ) + throws ComponentLookupException + { + return container.lookup( theComponentKey ); + } + + @Override + public Object getComponent( String theRole, String theRoleHint ) + throws ComponentLookupException + { + return container.lookup( theRole, theRoleHint ); + } + + @Override + public List getComponentList( String theRole ) + throws ComponentLookupException + { + return container.lookupList( theRole ); + } + + @Override + public Map getComponentMap( String theRole ) + throws ComponentLookupException + { + return container.lookupMap( theRole ); + } + + @Override + public T getComponent( Class clazz, String roleHint ) + throws ComponentLookupException + { + return container.lookup( clazz, roleHint ); + } + + @Override + public PlexusContainer getContainer() + { + return container; + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/DependencyConvergence.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/DependencyConvergence.java new file mode 100644 index 000000000..7366cfaf6 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/DependencyConvergence.java @@ -0,0 +1,203 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.metadata.ArtifactMetadataSource; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.ArtifactCollector; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.enforcer.rule.api.EnforcerRule; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.plugins.enforcer.utils.DependencyVersionMap; +import org.apache.maven.project.MavenProject; +import org.apache.maven.shared.dependency.tree.DependencyNode; +import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder; +import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; + +/** + * @author Rex Hoffman + */ +public class DependencyConvergence + implements EnforcerRule +{ + + private static Log log; + + private boolean uniqueVersions; + + public void setUniqueVersions( boolean uniqueVersions ) + { + this.uniqueVersions = uniqueVersions; + } + + // CHECKSTYLE_OFF: LineLength + /** + * Uses the {@link EnforcerRuleHelper} to populate the values of the + * {@link DependencyTreeBuilder#buildDependencyTree(MavenProject, ArtifactRepository, ArtifactFactory, ArtifactMetadataSource, ArtifactFilter, ArtifactCollector)} + * factory method.
+ * This method simply exists to hide all the ugly lookup that the {@link EnforcerRuleHelper} has to do. + * + * @param helper + * @return a Dependency Node which is the root of the project's dependency tree + * @throws EnforcerRuleException + */ + // CHECKSTYLE_ON: LineLength + private DependencyNode getNode( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + try + { + MavenProject project = (MavenProject) helper.evaluate( "${project}" ); + DependencyTreeBuilder dependencyTreeBuilder = helper.getComponent( DependencyTreeBuilder.class ); + ArtifactRepository repository = (ArtifactRepository) helper.evaluate( "${localRepository}" ); + ArtifactFactory factory = helper.getComponent( ArtifactFactory.class ); + ArtifactMetadataSource metadataSource = helper.getComponent( ArtifactMetadataSource.class ); + ArtifactCollector collector = helper.getComponent( ArtifactCollector.class ); + ArtifactFilter filter = null; // we need to evaluate all scopes + DependencyNode node = dependencyTreeBuilder.buildDependencyTree( project, repository, factory, + metadataSource, filter, collector ); + return node; + } + catch ( ExpressionEvaluationException | ComponentLookupException e ) + { + throw new EnforcerRuleException( "Unable to lookup a component " + e.getLocalizedMessage(), e ); + } + catch ( DependencyTreeBuilderException e ) + { + throw new EnforcerRuleException( "Could not build dependency tree " + e.getLocalizedMessage(), e ); + } + } + + @Override + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + if ( log == null ) + { + log = helper.getLog(); + } + try + { + DependencyNode node = getNode( helper ); + DependencyVersionMap visitor = new DependencyVersionMap( log ); + visitor.setUniqueVersions( uniqueVersions ); + node.accept( visitor ); + List errorMsgs = new ArrayList<>(); + errorMsgs.addAll( getConvergenceErrorMsgs( visitor.getConflictedVersionNumbers() ) ); + for ( CharSequence errorMsg : errorMsgs ) + { + log.warn( errorMsg ); + } + if ( errorMsgs.size() > 0 ) + { + throw new EnforcerRuleException( "Failed while enforcing releasability. " + + "See above detailed error message." ); + } + } + catch ( Exception e ) + { + throw new EnforcerRuleException( e.getLocalizedMessage(), e ); + } + } + + private String getFullArtifactName( Artifact artifact ) + { + return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion(); + } + + private StringBuilder buildTreeString( DependencyNode node ) + { + List loc = new ArrayList<>(); + DependencyNode currentNode = node; + while ( currentNode != null ) + { + loc.add( getFullArtifactName( currentNode.getArtifact() ) ); + currentNode = currentNode.getParent(); + } + Collections.reverse( loc ); + StringBuilder builder = new StringBuilder(); + for ( int i = 0; i < loc.size(); i++ ) + { + for ( int j = 0; j < i; j++ ) + { + builder.append( " " ); + } + builder.append( "+-" + loc.get( i ) ); + builder.append( System.lineSeparator() ); + } + return builder; + } + + private List getConvergenceErrorMsgs( List> errors ) + { + List errorMsgs = new ArrayList<>(); + for ( List nodeList : errors ) + { + errorMsgs.add( buildConvergenceErrorMsg( nodeList ) ); + } + return errorMsgs; + } + + private String buildConvergenceErrorMsg( List nodeList ) + { + StringBuilder builder = new StringBuilder(); + builder.append( System.lineSeparator() + "Dependency convergence error for " + + getFullArtifactName( nodeList.get( 0 ).getArtifact() ) + + " paths to dependency are:" + System.lineSeparator() ); + if ( nodeList.size() > 0 ) + { + builder.append( buildTreeString( nodeList.get( 0 ) ) ); + } + for ( DependencyNode node : nodeList.subList( 1, nodeList.size() ) ) + { + builder.append( "and" + System.lineSeparator() ); + builder.append( buildTreeString( node ) ); + } + return builder.toString(); + } + + @Override + public String getCacheId() + { + return ""; + } + + @Override + public boolean isCacheable() + { + return false; + } + + @Override + public boolean isResultValid( EnforcerRule rule ) + { + return false; + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/EnforcerExpressionEvaluator.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/EnforcerExpressionEvaluator.java new file mode 100644 index 000000000..c7385e9b6 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/EnforcerExpressionEvaluator.java @@ -0,0 +1,47 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.MojoExecution; +import org.apache.maven.plugin.PluginParameterExpressionEvaluator; + +/** + * The Class EnforcerExpressionEvaluator. This class wraps the PluginParameterExpressionEvaluator because it can't be + * accessed directly in 2.0.x so we must create a new one. + * + * @author Brian Fox + */ +public class EnforcerExpressionEvaluator + extends PluginParameterExpressionEvaluator +{ + + /** + * The Constructor. + * + * @param mavenSession {@link MavenSession} + * @param theExecution {@link MojoExecution} + */ + public EnforcerExpressionEvaluator( MavenSession mavenSession, MojoExecution theExecution ) + { + super( mavenSession, theExecution ); + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/EvaluateBeanshell.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/EvaluateBeanshell.java new file mode 100644 index 000000000..e29f78625 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/EvaluateBeanshell.java @@ -0,0 +1,118 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.plugin.logging.Log; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.codehaus.plexus.util.StringUtils; + +import bsh.EvalError; +import bsh.Interpreter; + +/** + * Rule for Maven Enforcer using Beanshell to evaluate a conditional expression. + * + * @author hugonnem + */ +public class EvaluateBeanshell + extends AbstractNonCacheableEnforcerRule +{ + + /** Beanshell interpreter. */ + private static final ThreadLocal INTERPRETER = new ThreadLocal() + { + @Override + protected Interpreter initialValue() + { + return new Interpreter(); + } + }; + + /** The condition to be evaluated. + * + * @see {@link #setCondition(String)} + * @see {@link #getCondition()} + * */ + private String condition; + + public final void setCondition( String condition ) + { + this.condition = condition; + } + + public final String getCondition() + { + return condition; + } + + @Override + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + Log log = helper.getLog(); + + try + { + log.debug( "Echo condition : " + this.condition ); + // Evaluate condition within Plexus Container + String script = (String) helper.evaluate( this.condition ); + log.debug( "Echo script : " + script ); + if ( !evaluateCondition( script, log ) ) + { + String message = getMessage(); + if ( StringUtils.isEmpty( message ) ) + { + message = "The expression \"" + condition + "\" is not true."; + } + throw new EnforcerRuleException( message ); + } + } + catch ( ExpressionEvaluationException e ) + { + throw new EnforcerRuleException( "Unable to evaluate an expression '" + condition + "'", e ); + } + } + + /** + * Evaluate expression using Beanshell. + * + * @param script the expression to be evaluated + * @param log the logger + * @return boolean the evaluation of the expression + * @throws EnforcerRuleException if the script could not be evaluated + */ + protected boolean evaluateCondition( String script, Log log ) + throws EnforcerRuleException + { + Boolean evaluation; + try + { + evaluation = (Boolean) INTERPRETER.get().eval( script ); + log.debug( "Echo evaluating : " + evaluation ); + } + catch ( EvalError ex ) + { + throw new EnforcerRuleException( "Couldn't evaluate condition: " + script, ex ); + } + return evaluation.booleanValue(); + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/ReactorModuleConvergence.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/ReactorModuleConvergence.java new file mode 100644 index 000000000..e5dd9aff3 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/ReactorModuleConvergence.java @@ -0,0 +1,480 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.apache.commons.lang3.SystemUtils; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.model.Dependency; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.codehaus.plexus.util.StringUtils; + +/** + * This rule will check if a multi module build will follow the best practices. + * + * @author Karl-Heinz Marbaise + * @since 1.4 + */ +public class ReactorModuleConvergence + extends AbstractNonCacheableEnforcerRule +{ + private static final String MODULE_TEXT = " module: "; + + private boolean ignoreModuleDependencies = false; + + private Log logger; + + @Override + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + logger = helper.getLog(); + + MavenSession session; + try + { + session = (MavenSession) helper.evaluate( "${session}" ); + } + catch ( ExpressionEvaluationException eee ) + { + throw new EnforcerRuleException( "Unable to retrieve the MavenSession: ", eee ); + } + + List sortedProjects = session.getProjectDependencyGraph().getSortedProjects(); + if ( sortedProjects != null && !sortedProjects.isEmpty() ) + { + checkReactor( sortedProjects ); + checkParentsInReactor( sortedProjects ); + checkMissingParentsInReactor( sortedProjects ); + checkParentsPartOfTheReactor( sortedProjects ); + if ( !isIgnoreModuleDependencies() ) + { + checkDependenciesWithinReactor( sortedProjects ); + } + } + + } + + private void checkParentsPartOfTheReactor( List sortedProjects ) + throws EnforcerRuleException + { + List parentsWhichAreNotPartOfTheReactor = + existParentsWhichAreNotPartOfTheReactor( sortedProjects ); + if ( !parentsWhichAreNotPartOfTheReactor.isEmpty() ) + { + StringBuilder sb = new StringBuilder().append( SystemUtils.LINE_SEPARATOR ); + addMessageIfExist( sb ); + for ( MavenProject mavenProject : parentsWhichAreNotPartOfTheReactor ) + { + sb.append( MODULE_TEXT ); + sb.append( mavenProject.getId() ); + sb.append( System.lineSeparator() ); + } + throw new EnforcerRuleException( "Module parents have been found which could not be found in the reactor." + + sb.toString() ); + } + } + + /** + * Convenience method to create a user readable message. + * + * @param sortedProjects The list of reactor projects. + * @throws EnforcerRuleException In case of a violation. + */ + private void checkMissingParentsInReactor( List sortedProjects ) + throws EnforcerRuleException + { + List modulesWithoutParentsInReactor = existModulesWithoutParentsInReactor( sortedProjects ); + if ( !modulesWithoutParentsInReactor.isEmpty() ) + { + StringBuilder sb = new StringBuilder().append( System.lineSeparator() ); + addMessageIfExist( sb ); + for ( MavenProject mavenProject : modulesWithoutParentsInReactor ) + { + sb.append( MODULE_TEXT ); + sb.append( mavenProject.getId() ); + sb.append( System.lineSeparator() ); + } + throw new EnforcerRuleException( "Reactor contains modules without parents." + sb.toString() ); + } + } + + private void checkDependenciesWithinReactor( List sortedProjects ) + throws EnforcerRuleException + { + // After we are sure having consistent version we can simply use the first one? + String reactorVersion = sortedProjects.get( 0 ).getVersion(); + + Map> areThereDependenciesWhichAreNotPartOfTheReactor = + areThereDependenciesWhichAreNotPartOfTheReactor( reactorVersion, sortedProjects ); + if ( !areThereDependenciesWhichAreNotPartOfTheReactor.isEmpty() ) + { + StringBuilder sb = new StringBuilder().append( System.lineSeparator() ); + addMessageIfExist( sb ); + // CHECKSTYLE_OFF: LineLength + for ( Entry> item : areThereDependenciesWhichAreNotPartOfTheReactor.entrySet() ) + { + sb.append( MODULE_TEXT ); + sb.append( item.getKey().getId() ); + sb.append( System.lineSeparator() ); + for ( Dependency dependency : item.getValue() ) + { + String id = + dependency.getGroupId() + ":" + dependency.getArtifactId() + ":" + dependency.getVersion(); + sb.append( " dependency: " ); + sb.append( id ); + sb.append( System.lineSeparator() ); + } + } + throw new EnforcerRuleException( + "Reactor modules contains dependencies which do not reference the reactor." + + sb.toString() ); + // CHECKSTYLE_ON: LineLength + } + } + + /** + * Convenience method to create a user readable message. + * + * @param sortedProjects The list of reactor projects. + * @throws EnforcerRuleException In case of a violation. + */ + private void checkParentsInReactor( List sortedProjects ) + throws EnforcerRuleException + { + // After we are sure having consistent version we can simply use the first one? + String reactorVersion = sortedProjects.get( 0 ).getVersion(); + + List areParentsFromTheReactor = areParentsFromTheReactor( reactorVersion, sortedProjects ); + if ( !areParentsFromTheReactor.isEmpty() ) + { + StringBuilder sb = new StringBuilder().append( System.lineSeparator() ); + addMessageIfExist( sb ); + for ( MavenProject mavenProject : areParentsFromTheReactor ) + { + sb.append( " --> " ); + sb.append( mavenProject.getId() ); + sb.append( " parent:" ); + sb.append( mavenProject.getParent().getId() ); + sb.append( System.lineSeparator() ); + } + throw new EnforcerRuleException( "Reactor modules have parents which contain a wrong version." + + sb.toString() ); + } + } + + /** + * Convenience method to create user readable message. + * + * @param sortedProjects The list of reactor projects. + * @throws EnforcerRuleException In case of a violation. + */ + private void checkReactor( List sortedProjects ) + throws EnforcerRuleException + { + List consistenceCheckResult = isReactorVersionConsistent( sortedProjects ); + if ( !consistenceCheckResult.isEmpty() ) + { + StringBuilder sb = new StringBuilder().append( System.lineSeparator() ); + addMessageIfExist( sb ); + for ( MavenProject mavenProject : consistenceCheckResult ) + { + sb.append( " --> " ); + sb.append( mavenProject.getId() ); + sb.append( System.lineSeparator() ); + } + throw new EnforcerRuleException( "The reactor contains different versions." + sb.toString() ); + } + } + + private List areParentsFromTheReactor( String reactorVersion, List sortedProjects ) + { + List result = new ArrayList<>(); + + for ( MavenProject mavenProject : sortedProjects ) + { + logger.debug( "Project: " + mavenProject.getId() ); + if ( hasParent( mavenProject ) ) + { + if ( !mavenProject.isExecutionRoot() ) + { + MavenProject parent = mavenProject.getParent(); + if ( !reactorVersion.equals( parent.getVersion() ) ) + { + logger.debug( "The project: " + mavenProject.getId() + + " has a parent which version does not match the other elements in reactor" ); + result.add( mavenProject ); + } + } + } + else + { + // This situation is currently ignored, cause it's handled by existModulesWithoutParentsInReactor() + } + } + + return result; + } + + private List existParentsWhichAreNotPartOfTheReactor( List sortedProjects ) + { + List result = new ArrayList<>(); + + for ( MavenProject mavenProject : sortedProjects ) + { + logger.debug( "Project: " + mavenProject.getId() ); + if ( hasParent( mavenProject ) ) + { + if ( !mavenProject.isExecutionRoot() ) + { + MavenProject parent = mavenProject.getParent(); + if ( !isProjectPartOfTheReactor( parent, sortedProjects ) ) + { + result.add( mavenProject ); + } + } + } + } + + return result; + } + + /** + * This will check of the groupId/artifactId can be found in any reactor project. The version will be ignored cause + * versions are checked before. + * + * @param project The project which should be checked if it is contained in the sortedProjects. + * @param sortedProjects The list of existing projects. + * @return true if the project has been found within the list false otherwise. + */ + private boolean isProjectPartOfTheReactor( MavenProject project, List sortedProjects ) + { + return isGAPartOfTheReactor( project.getGroupId(), project.getArtifactId(), sortedProjects ); + } + + private boolean isDependencyPartOfTheReactor( Dependency dependency, List sortedProjects ) + { + return isGAPartOfTheReactor( dependency.getGroupId(), dependency.getArtifactId(), sortedProjects ); + } + + /** + * This will check if the given groupId/artifactId is part of the current reactor. + * + * @param groupId The groupId + * @param artifactId The artifactId + * @param sortedProjects The list of projects within the reactor. + * @return true if the groupId/artifactId is part of the reactor false otherwise. + */ + private boolean isGAPartOfTheReactor( String groupId, String artifactId, List sortedProjects ) + { + boolean result = false; + for ( MavenProject mavenProject : sortedProjects ) + { + String parentId = groupId + ":" + artifactId; + String projectId = mavenProject.getGroupId() + ":" + mavenProject.getArtifactId(); + if ( parentId.equals( projectId ) ) + { + result = true; + } + } + return result; + } + + /** + * Assume we have a module which is a child of a multi module build but this child does not have a parent. This + * method will exactly search for such cases. + * + * @param sortedProjects The sorted list of the reactor modules. + * @return The resulting list will contain the modules in the reactor which do not have a parent. The list will + * never null. If the list is empty no violation have happened. + */ + private List existModulesWithoutParentsInReactor( List sortedProjects ) + { + List result = new ArrayList<>(); + + for ( MavenProject mavenProject : sortedProjects ) + { + logger.debug( "Project: " + mavenProject.getId() ); + if ( !hasParent( mavenProject ) ) + { + // TODO: Should add an option to force having a parent? + if ( mavenProject.isExecutionRoot() ) + { + logger.debug( "The root does not need having a parent." ); + } + else + { + logger.debug( "The module: " + mavenProject.getId() + " has no parent." ); + result.add( mavenProject ); + } + } + } + + return result; + } + + /** + * Convenience method to handle adding a dependency to the Map of List. + * + * @param result The result List which should be handled. + * @param project The MavenProject which will be added. + * @param dependency The dependency which will be added. + */ + private void addDep( Map> result, MavenProject project, Dependency dependency ) + { + if ( result.containsKey( project ) ) + { + List list = result.get( project ); + if ( list == null ) + { + list = new ArrayList<>(); + } + list.add( dependency ); + result.put( project, list ); + } + else + { + List list = new ArrayList<>(); + list.add( dependency ); + result.put( project, list ); + } + } + + /** + * Go through the list of modules in the builds and check if we have dependencies. If yes we will check every + * dependency based on groupId/artifactId if it belongs to the multi module build. In such a case it will be checked + * if the version does fit the version in the rest of build. + * + * @param reactorVersion The version of the reactor. + * @param sortedProjects The list of existing projects within this build. + * @return List of violations. Never null. If the list is empty than no violation has happened. + */ + // CHECKSTYLE_OFF: LineLength + private Map> areThereDependenciesWhichAreNotPartOfTheReactor( String reactorVersion, + List sortedProjects ) + // CHECKSTYLE_ON: LineLength + { + Map> result = new HashMap<>(); + for ( MavenProject mavenProject : sortedProjects ) + { + logger.debug( "Project: " + mavenProject.getId() ); + + List dependencies = mavenProject.getDependencies(); + if ( hasDependencies( dependencies ) ) + { + for ( Dependency dependency : dependencies ) + { + logger.debug( " -> Dep:" + dependency.getGroupId() + ":" + dependency.getArtifactId() + ":" + + dependency.getVersion() ); + if ( isDependencyPartOfTheReactor( dependency, sortedProjects ) ) + { + if ( !dependency.getVersion().equals( reactorVersion ) ) + { + addDep( result, mavenProject, dependency ); + } + } + } + } + } + + return result; + } + + /** + * This method will check the following situation within a multi-module build. + * + *
+     *  <parent>
+     *    <groupId>...</groupId>
+     *    <artifactId>...</artifactId>
+     *    <version>1.0-SNAPSHOT</version>
+     *  </parent>
+     *  
+     *  <version>1.1-SNAPSHOT</version>
+     * 
+ * + * @param projectList The sorted list of the reactor modules. + * @return The resulting list will contain the modules in the reactor which do the thing in the example above. The + * list will never null. If the list is empty no violation have happened. + */ + private List isReactorVersionConsistent( List projectList ) + { + List result = new ArrayList<>(); + + if ( projectList != null && !projectList.isEmpty() ) + { + String version = projectList.get( 0 ).getVersion(); + logger.debug( "First version:" + version ); + for ( MavenProject mavenProject : projectList ) + { + logger.debug( " -> checking " + mavenProject.getId() ); + if ( !version.equals( mavenProject.getVersion() ) ) + { + result.add( mavenProject ); + } + } + } + return result; + } + + private boolean hasDependencies( List dependencies ) + { + return dependencies != null && !dependencies.isEmpty(); + } + + private boolean hasParent( MavenProject mavenProject ) + { + return mavenProject.getParent() != null; + } + + public boolean isIgnoreModuleDependencies() + { + return ignoreModuleDependencies; + } + + public void setIgnoreModuleDependencies( boolean ignoreModuleDependencies ) + { + this.ignoreModuleDependencies = ignoreModuleDependencies; + } + + /** + * This will add the given user message to the output. + * + * @param sb The already initialized exception message part. + */ + private void addMessageIfExist( StringBuilder sb ) + { + if ( !StringUtils.isEmpty( getMessage() ) ) + { + sb.append( getMessage() ); + sb.append( System.lineSeparator() ); + } + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireActiveProfile.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireActiveProfile.java new file mode 100644 index 000000000..31fde9cd9 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireActiveProfile.java @@ -0,0 +1,153 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.util.ArrayList; +import java.util.List; + +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.model.Profile; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.codehaus.plexus.util.StringUtils; + +/** + * This rule checks that some profiles are active. + * + * @author Brian Fox + */ +public class RequireActiveProfile + extends AbstractNonCacheableEnforcerRule +{ + + /** Comma separated list of profiles to check. + * + * @see {@link #setProfiles(String)} + * @see {@link #getProfiles()} + */ + private String profiles = null; + + /** If all profiles must be active. If false, only one must be active + * + * @see {@link #setAll(boolean)} + * @see {@link #isAll()} + */ + private boolean all = true; + + public final String getProfiles() + { + return profiles; + } + + public final void setProfiles( String profiles ) + { + this.profiles = profiles; + } + + public final boolean isAll() + { + return all; + } + + public final void setAll( boolean all ) + { + this.all = all; + } + + @Override + public void execute( EnforcerRuleHelper theHelper ) + throws EnforcerRuleException + { + List missingProfiles = new ArrayList<>(); + try + { + MavenProject project = (MavenProject) theHelper.evaluate( "${project}" ); + if ( StringUtils.isNotEmpty( profiles ) ) + { + String[] profs = profiles.split( "," ); + for ( String profile : profs ) + { + if ( !isProfileActive( project, profile ) ) + { + missingProfiles.add( profile ); + } + } + + boolean fail = false; + if ( !missingProfiles.isEmpty() ) + { + if ( all || missingProfiles.size() == profs.length ) + { + fail = true; + } + } + + if ( fail ) + { + String message = getMessage(); + StringBuilder buf = new StringBuilder(); + if ( message != null ) + { + buf.append( message + System.lineSeparator() ); + } + + for ( String profile : missingProfiles ) + { + buf.append( "Profile \"" + profile + "\" is not activated." + System.lineSeparator() ); + } + + throw new EnforcerRuleException( buf.toString() ); + } + + } + + } + catch ( ExpressionEvaluationException e ) + { + throw new EnforcerRuleException( "Unable to retrieve the project.", e ); + } + + } + + /** + * Checks if profile is active. + * + * @param project the project + * @param profileName the profile name + * @return true if profile is active, otherwise false + */ + protected boolean isProfileActive( MavenProject project, String profileName ) + { + List activeProfiles = project.getActiveProfiles(); + if ( activeProfiles != null && !activeProfiles.isEmpty() ) + { + for ( Profile profile : activeProfiles ) + { + if ( profile.getId().equals( profileName ) ) + { + return true; + } + } + } + + return false; + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireEnvironmentVariable.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireEnvironmentVariable.java new file mode 100755 index 000000000..d325f98c1 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireEnvironmentVariable.java @@ -0,0 +1,94 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import org.apache.maven.enforcer.rule.api.EnforcerRule; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; + +/** + * This rule checks that certain environment variable is set. + * + * @author Marvin Froeder + */ +public class RequireEnvironmentVariable + extends AbstractPropertyEnforcerRule +{ + + /** + * Specify the required variable. + */ + private String variableName = null; + + /** + * @param variableName the variable name + * + * @see #setVariableName(String) + * @see #getVariableName() + */ + public final void setVariableName( String variableName ) + { + this.variableName = variableName; + } + + public final String getVariableName() + { + return variableName; + } + + @Override + public String resolveValue( EnforcerRuleHelper helper ) + { + String envValue = System.getenv( variableName ); + return envValue; + } + + @Override + public boolean isCacheable() + { + // environment variables won't change while maven is on the run + return true; + } + + @Override + public boolean isResultValid( EnforcerRule cachedRule ) + { + // this rule shall always have the same result, since environment + // variables are set before maven is launched + return true; + } + + @Override + public String getCacheId() + { + return variableName; + } + + @Override + public String getPropertyName() + { + return variableName; + } + + @Override + public String getName() + { + return "Environment variable"; + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireFileChecksum.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireFileChecksum.java new file mode 100644 index 000000000..bbed9e7ea --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireFileChecksum.java @@ -0,0 +1,180 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +import org.apache.commons.codec.digest.DigestUtils; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; + +/** + * Rule to validate a file to match the specified checksum. + * + * @author Edward Samson + * @author Lyubomyr Shaydariv + */ +public class RequireFileChecksum + extends AbstractNonCacheableEnforcerRule +{ + + private File file; + + private String checksum; + + private String type; + + private String nonexistentFileMessage; + + @Override + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + if ( this.file == null ) + { + throw new EnforcerRuleException( "Input file unspecified" ); + } + + if ( this.type == null ) + { + throw new EnforcerRuleException( "Hash type unspecified" ); + } + + if ( this.checksum == null ) + { + throw new EnforcerRuleException( "Checksum unspecified" ); + } + + if ( !this.file.exists() ) + { + String message = nonexistentFileMessage; + if ( message == null ) + { + message = "File does not exist: " + this.file.getAbsolutePath(); + } + throw new EnforcerRuleException( message ); + } + + if ( this.file.isDirectory() ) + { + throw new EnforcerRuleException( "Cannot calculate the checksum of directory: " + + this.file.getAbsolutePath() ); + } + + if ( !this.file.canRead() ) + { + throw new EnforcerRuleException( "Cannot read file: " + this.file.getAbsolutePath() ); + } + + String checksum = calculateChecksum(); + + if ( !checksum.equalsIgnoreCase( this.checksum ) ) + { + String exceptionMessage = getMessage(); + if ( exceptionMessage == null ) + { + exceptionMessage = this.type + " hash of " + this.file + " was " + checksum + + " but expected " + this.checksum; + } + throw new EnforcerRuleException( exceptionMessage ); + } + } + + /** + * The file to check. + * + * @param file file + */ + public void setFile( File file ) + { + this.file = file; + } + + /** + * The expected checksum value. + * + * @param checksum checksum + */ + public void setChecksum( String checksum ) + { + this.checksum = checksum; + } + + /** + * The checksum algorithm to use. Possible values: "md5", "sha1", "sha256", "sha384", "sha512". + * + * @param type algorithm + */ + public void setType( String type ) + { + this.type = type; + } + + /** + * The friendly message to use when the file does not exist. + * + * @param nonexistentFileMessage message + */ + public void setNonexistentFileMessage( String nonexistentFileMessage ) + { + this.nonexistentFileMessage = nonexistentFileMessage; + } + + private String calculateChecksum() + throws EnforcerRuleException + { + try ( InputStream inputStream = new FileInputStream( this.file ) ) + { + String checksum; + if ( "md5".equals( this.type ) ) + { + checksum = DigestUtils.md5Hex( inputStream ); + } + else if ( "sha1".equals( this.type ) ) + { + checksum = DigestUtils.shaHex( inputStream ); + } + else if ( "sha256".equals( this.type ) ) + { + checksum = DigestUtils.sha256Hex( inputStream ); + } + else if ( "sha384".equals( this.type ) ) + { + checksum = DigestUtils.sha384Hex( inputStream ); + } + else if ( "sha512".equals( this.type ) ) + { + checksum = DigestUtils.sha512Hex( inputStream ); + } + else + { + throw new EnforcerRuleException( "Unsupported hash type: " + this.type ); + } + return checksum; + } + catch ( IOException e ) + { + throw new EnforcerRuleException( "Unable to calculate checksum", e ); + } + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireFilesDontExist.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireFilesDontExist.java new file mode 100644 index 000000000..7ad08f568 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireFilesDontExist.java @@ -0,0 +1,43 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.io.File; + +/** + * The Class RequireFilesDontExist. + */ +public class RequireFilesDontExist + extends AbstractRequireFiles +{ + @Override + boolean checkFile( File file ) + { + // if we get here and the handle is null, treat it as a success + return file == null ? true : !file.exists(); + } + + @Override + String getErrorMsg() + { + return "Some files should not exist:" + System.lineSeparator(); + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireFilesExist.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireFilesExist.java new file mode 100644 index 000000000..5727bd811 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireFilesExist.java @@ -0,0 +1,43 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.io.File; + +/** + * The Class RequireFilesExist. + */ +public class RequireFilesExist + extends AbstractRequireFiles +{ + @Override + boolean checkFile( File file ) + { + // if we get here and the handle is null, treat it as a success + return file == null ? true : file.exists(); + } + + @Override + String getErrorMsg() + { + return "Some required files are missing:" + System.lineSeparator(); + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireFilesSize.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireFilesSize.java new file mode 100644 index 000000000..6ad928539 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireFilesSize.java @@ -0,0 +1,164 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.io.File; + +import org.apache.maven.enforcer.rule.api.EnforcerRule; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; + +/** + * Rule to validate the main artifact is within certain size constraints. + * + * @author brianf + * @author Roman Stumm + */ +public class RequireFilesSize + extends AbstractRequireFiles +{ + + private static final long MAXSIZE = 10000; + + /** the max size allowed. */ + private long maxsize = MAXSIZE; + + /** the min size allowed. */ + private long minsize = 0; + + /** The error msg. */ + private String errorMsg; + + /** The log. */ + private Log log; + + @Override + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + this.log = helper.getLog(); + + // if the file is already defined, use that. Otherwise get the main artifact. + if ( getFiles().length == 0 ) + { + try + { + MavenProject project = (MavenProject) helper.evaluate( "${project}" ); + setFiles( new File[1] ); + getFiles()[0] = project.getArtifact().getFile(); + + super.execute( helper ); + } + catch ( ExpressionEvaluationException e ) + { + throw new EnforcerRuleException( "Unable to retrieve the project.", e ); + } + } + else + { + super.execute( helper ); + } + + } + + @Override + public boolean isCacheable() + { + return false; + } + + @Override + public boolean isResultValid( EnforcerRule cachedRule ) + { + return false; + } + + @Override + boolean checkFile( File file ) + { + if ( file == null ) + { + // if we get here and it's null, treat it as a success. + return true; + } + + // check the file now + if ( file.exists() ) + { + long length = file.length(); + if ( length < minsize ) + { + this.errorMsg = ( file + " size (" + length + ") too small. Min. is " + minsize ); + return false; + } + else if ( length > maxsize ) + { + this.errorMsg = ( file + " size (" + length + ") too large. Max. is " + maxsize ); + return false; + } + else + { + + this.log.debug( file + + " size (" + + length + + ") is OK (" + + ( minsize == maxsize || minsize == 0 ? ( "max. " + maxsize ) + : ( "between " + minsize + " and " + maxsize ) ) + " byte)." ); + + return true; + } + } + else + { + this.errorMsg = ( file + " does not exist!" ); + return false; + } + } + + @Override + String getErrorMsg() + { + return this.errorMsg; + } + + public long getMaxsize() + { + return maxsize; + } + + public void setMaxsize( long maxsize ) + { + this.maxsize = maxsize; + } + + public long getMinsize() + { + return minsize; + } + + public void setMinsize( long minsize ) + { + this.minsize = minsize; + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireJavaVersion.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireJavaVersion.java new file mode 100644 index 000000000..4076ac8f8 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireJavaVersion.java @@ -0,0 +1,101 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +import org.apache.commons.lang3.SystemUtils; +import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.apache.maven.artifact.versioning.DefaultArtifactVersion; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.plugin.logging.Log; +import org.codehaus.plexus.util.StringUtils; + +/** + * This rule checks that the Java version is allowed. + * + * @author Brian Fox + */ +public class RequireJavaVersion + extends AbstractVersionEnforcer +{ + @Override + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + String javaVersion = SystemUtils.JAVA_VERSION; + Log log = helper.getLog(); + + log.debug( "Detected Java String: '" + javaVersion + "'" ); + javaVersion = normalizeJDKVersion( javaVersion ); + log.debug( "Normalized Java String: '" + javaVersion + "'" ); + + ArtifactVersion detectedJdkVersion = new DefaultArtifactVersion( javaVersion ); + + log.debug( "Parsed Version: Major: " + detectedJdkVersion.getMajorVersion() + " Minor: " + + detectedJdkVersion.getMinorVersion() + " Incremental: " + detectedJdkVersion.getIncrementalVersion() + + " Build: " + detectedJdkVersion.getBuildNumber() + " Qualifier: " + detectedJdkVersion.getQualifier() ); + + enforceVersion( helper.getLog(), "JDK", getVersion(), detectedJdkVersion ); + } + + /** + * Converts a jdk string from 1.5.0-11b12 to a single 3 digit version like 1.5.0-11 + * + * @param theJdkVersion to be converted. + * @return the converted string. + */ + public static String normalizeJDKVersion( String theJdkVersion ) + { + + theJdkVersion = theJdkVersion.replaceAll( "_|-", "." ); + String tokenArray[] = StringUtils.split( theJdkVersion, "." ); + List tokens = Arrays.asList( tokenArray ); + StringBuilder buffer = new StringBuilder( theJdkVersion.length() ); + + Iterator iter = tokens.iterator(); + for ( int i = 0; i < tokens.size() && i < 4; i++ ) + { + String section = iter.next(); + section = section.replaceAll( "[^0-9]", "" ); + + if ( StringUtils.isNotEmpty( section ) ) + { + buffer.append( Integer.parseInt( section ) ); + + if ( i != 2 ) + { + buffer.append( '.' ); + } + else + { + buffer.append( '-' ); + } + } + } + + String version = buffer.toString(); + version = StringUtils.stripEnd( version, "-" ); + return StringUtils.stripEnd( version, "." ); + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireMavenVersion.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireMavenVersion.java new file mode 100644 index 000000000..50ba8697a --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireMavenVersion.java @@ -0,0 +1,55 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import org.apache.maven.artifact.versioning.DefaultArtifactVersion; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.execution.MavenSession; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; + +/** + * This rule checks that the Maven version is allowed. + * + * @author Brian Fox + */ +public class RequireMavenVersion + extends AbstractVersionEnforcer +{ + @Override + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + try + { + MavenSession mavenSession = (MavenSession) helper.evaluate( "${session}" ); + String mavenVersion = mavenSession.getSystemProperties().getProperty( "maven.version" ); + helper.getLog().debug( "Detected Maven Version: " + mavenVersion ); + DefaultArtifactVersion detectedVersion = new DefaultArtifactVersion( mavenVersion ); + enforceVersion( helper.getLog(), "Maven", getVersion(), detectedVersion ); + } + catch ( ExpressionEvaluationException e ) + { + throw new EnforcerRuleException( "Unable to retrieve the session.", e ); + } + + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireNoRepositories.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireNoRepositories.java new file mode 100644 index 000000000..23a21dde0 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireNoRepositories.java @@ -0,0 +1,229 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.model.Model; +import org.apache.maven.model.Repository; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.codehaus.plexus.util.StringUtils; + +/** + * This rule checks that this pom or its parents don't define a repository. + * + * @author Brian Fox + */ +public class RequireNoRepositories + extends AbstractNonCacheableEnforcerRule +{ + private static final String VERSION = " version:"; + + /** + * Whether to ban non-plugin repositories. By default they are banned. + * + * @see #setBanRepositories(boolean) + */ + private boolean banRepositories = true; + + /** + * Whether to ban plugin repositories. By default they are banned. + * + * @see #setBanPluginRepositories(boolean) + */ + private boolean banPluginRepositories = true; + + /** + * Specify explicitly allowed non-plugin repositories. This is a list of ids. + * + * @see #setAllowedRepositories(List) + */ + private List allowedRepositories = Collections.emptyList(); + + /** + * Specify explicitly allowed plugin repositories. This is a list of ids. + * + * @see #setAllowedPluginRepositories(List) + */ + private List allowedPluginRepositories = Collections.emptyList(); + + /** + * Whether to allow repositories which only resolve snapshots. By default they are banned. + * + * @see #setAllowSnapshotRepositories(boolean) + */ + private boolean allowSnapshotRepositories = false; + + /** + * Whether to allow plugin repositories which only resolve snapshots. By default they are banned. + * + * @see {@link #setAllowSnapshotPluginRepositories(boolean)} + */ + private boolean allowSnapshotPluginRepositories = false; + + public final void setBanRepositories( boolean banRepositories ) + { + this.banRepositories = banRepositories; + } + + public final void setBanPluginRepositories( boolean banPluginRepositories ) + { + this.banPluginRepositories = banPluginRepositories; + } + + public final void setAllowedRepositories( List allowedRepositories ) + { + this.allowedRepositories = allowedRepositories; + } + + public final void setAllowedPluginRepositories( List allowedPluginRepositories ) + { + this.allowedPluginRepositories = allowedPluginRepositories; + } + + public final void setAllowSnapshotRepositories( boolean allowSnapshotRepositories ) + { + this.allowSnapshotRepositories = allowSnapshotRepositories; + } + + public final void setAllowSnapshotPluginRepositories( boolean allowSnapshotPluginRepositories ) + { + this.allowSnapshotPluginRepositories = allowSnapshotPluginRepositories; + } + + private Log logger; + + @Override + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + logger = helper.getLog(); + + MavenSession session; + try + { + session = (MavenSession) helper.evaluate( "${session}" ); + + List sortedProjects = session.getProjectDependencyGraph().getSortedProjects(); + + List models = new ArrayList<>(); + for ( MavenProject mavenProject : sortedProjects ) + { + logger.debug( "Scanning project: " + mavenProject.getGroupId() + ":" + mavenProject.getArtifactId() + + VERSION + mavenProject.getVersion() ); + models.add( mavenProject.getOriginalModel() ); + } + + List badModels = new ArrayList<>(); + + StringBuilder newMsg = new StringBuilder(); + newMsg.append( "Some poms have repositories defined:" + System.lineSeparator() ); + + for ( Model model : models ) + { + if ( banRepositories ) + { + List repos = model.getRepositories(); + if ( repos != null && !repos.isEmpty() ) + { + List bannedRepos = + findBannedRepositories( repos, allowedRepositories, allowSnapshotRepositories ); + if ( !bannedRepos.isEmpty() ) + { + badModels.add( model ); + newMsg.append( + model.getGroupId() + ":" + model.getArtifactId() + VERSION + model.getVersion() + + " has repositories " + bannedRepos ); + } + } + } + if ( banPluginRepositories ) + { + List repos = model.getPluginRepositories(); + if ( repos != null && !repos.isEmpty() ) + { + List bannedRepos = + findBannedRepositories( repos, allowedPluginRepositories, allowSnapshotPluginRepositories ); + if ( !bannedRepos.isEmpty() ) + { + badModels.add( model ); + newMsg.append( + model.getGroupId() + ":" + model.getArtifactId() + VERSION + model.getVersion() + + " has plugin repositories " + bannedRepos ); + } + } + } + } + + // if anything was found, log it then append the + // optional message. + if ( !badModels.isEmpty() ) + { + String message = getMessage(); + if ( StringUtils.isNotEmpty( message ) ) + { + newMsg.append( message ); + } + + throw new EnforcerRuleException( newMsg.toString() ); + } + + } + catch ( ExpressionEvaluationException e ) + { + throw new EnforcerRuleException( e.getLocalizedMessage() ); + } + } + + /** + * + * @param repos all repositories, never {@code null} + * @param allowedRepos allowed repositories, never {@code null} + * @param allowSnapshots + * @return List of banned repositoreis. + */ + private static List findBannedRepositories( List repos, List allowedRepos, + boolean allowSnapshots ) + { + List bannedRepos = new ArrayList<>( allowedRepos.size() ); + for ( Repository r : repos ) + { + if ( !allowedRepos.contains( r.getId() ) ) + { + if ( !allowSnapshots || r.getReleases() == null || r.getReleases().isEnabled() ) + { + // if we are not allowing snapshots and this repo is enabled for releases + // it is banned. We don't care whether it is enabled for snapshots + // if you define a repo and don't enable it for anything, then we have nothing + // to worry about + bannedRepos.add( r.getId() ); + } + } + } + return bannedRepos; + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireOS.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireOS.java new file mode 100644 index 000000000..abc4c3678 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireOS.java @@ -0,0 +1,421 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.util.Iterator; + +import org.apache.maven.enforcer.rule.api.EnforcerRule; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.model.Activation; +import org.apache.maven.model.ActivationOS; +import org.apache.maven.model.Profile; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.model.profile.activation.ProfileActivator; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import org.codehaus.plexus.util.Os; +import org.codehaus.plexus.util.StringUtils; + +/** + * This rule checks that the OS is allowed by combinations of family, name, version and cpu architecture. The behavior + * is exactly the same as the Maven Os profile activation so the same values are allowed here. + * + * @author Brian Fox + */ +public class RequireOS + extends AbstractStandardEnforcerRule +{ + private ProfileActivator activator; + + /** + * The OS family type desired
+ * Possible values: + *
    + *
  • dos
  • + *
  • mac
  • + *
  • netware
  • + *
  • os/2
  • + *
  • tandem
  • + *
  • unix
  • + *
  • windows
  • + *
  • win9x
  • + *
  • z/os
  • + *
  • os/400
  • + *
+ * + * @see {@link #setFamily(String)} + * @see {@link #getFamily()} + */ + private String family = null; + + /** + * The OS name desired. + * + * @see {@link #setName(String)} + * @see {@link #getName()} + */ + private String name = null; + + /** + * The OS version desired. + * + * @see {@link #setVersion(String)} + * @see {@link #getVersion()} + */ + private String version = null; + + /** + * The OS architecture desired. + * + * @see {@link #setArch(String)} + * @see {@link #getArch()} + */ + private String arch = null; + + /** + * Display detected OS information. + * + * @see {@link #setDisplay(boolean)} + * @see {@link #isDisplay()} + */ + private boolean display = false; + + /** + * Instantiates a new RequireOS. + */ + public RequireOS() + { + + } + + // For testing + RequireOS( ProfileActivator activator ) + { + this.activator = activator; + } + + + @Override + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + + displayOSInfo( helper.getLog(), display ); + + if ( allParamsEmpty() ) + { + throw new EnforcerRuleException( "All parameters can not be empty. " + + "You must pick at least one of (family, name, version, arch) " + + "or use -Denforcer.os.display=true to see the current OS information." ); + } + + try + { + activator = helper.getComponent( ProfileActivator.class, "os" ); + } + catch ( ComponentLookupException e ) + { + throw new EnforcerRuleException( e.getMessage() ); + } + + if ( isValidFamily( this.family ) ) + { + if ( !isAllowed() ) + { + String message = getMessage(); + if ( StringUtils.isEmpty( message ) ) + { + //@formatter:off + message = + ( "OS Arch: " + + Os.OS_ARCH + " Family: " + + Os.OS_FAMILY + " Name: " + + Os.OS_NAME + " Version: " + + Os.OS_VERSION + " is not allowed by" + ( arch != null ? " Arch=" + arch : "" ) + + ( family != null ? " Family=" + family : "" ) + + ( name != null ? " Name=" + name : "" ) + + ( version != null ? " Version=" + version : "" ) ); + //@formatter:on + } + throw new EnforcerRuleException( message ); + } + } + else + { + final int minimumBufferSize = 50; + StringBuilder buffer = new StringBuilder( minimumBufferSize ); + Iterator iter = Os.getValidFamilies().iterator(); + while ( iter.hasNext() ) + { + buffer.append( iter.next() ); + buffer.append( ", " ); + } + String help = StringUtils.stripEnd( buffer.toString().trim(), "." ); + throw new EnforcerRuleException( "Invalid Family type used. Valid family types are: " + help ); + } + } + + /** + * Log the current OS information. + * + * @param log the log + * @param info the info + */ + public void displayOSInfo( Log log, boolean info ) + { + String string = + "OS Info: Arch: " + Os.OS_ARCH + " Family: " + Os.OS_FAMILY + " Name: " + Os.OS_NAME + " Version: " + + Os.OS_VERSION; + + if ( !info ) + { + log.debug( string ); + } + else + { + log.info( string ); + } + } + + /** + * Helper method to determine if the current OS is allowed based on the injected values for family, name, version + * and arch. + * + * @return true if the version is allowed. + */ + public boolean isAllowed() + { + return activator.isActive( createProfile(), null, null ); + } + + /** + * Helper method to check that at least one of family, name, version or arch is set. + * + * @return true if all parameters are empty. + */ + public boolean allParamsEmpty() + { + // CHECKSTYLE_OFF: LineLength + return ( StringUtils.isEmpty( family ) && StringUtils.isEmpty( arch ) && StringUtils.isEmpty( name ) && StringUtils.isEmpty( version ) ); + // CHECKSTYLE_ON: LineLength + } + + /** + * Creates a Profile object that contains the activation information. + * + * @return a properly populated profile to be used for OS validation. + */ + private Profile createProfile() + { + Profile profile = new Profile(); + profile.setActivation( createActivation() ); + return profile; + } + + /** + * Creates an Activation object that contains the ActivationOS information. + * + * @return a properly populated Activation object. + */ + private Activation createActivation() + { + Activation activation = new Activation(); + activation.setActiveByDefault( false ); + activation.setOs( createOsBean() ); + return activation; + } + + /** + * Creates an ActivationOS object containing family, name, version and arch. + * + * @return a properly populated ActivationOS object. + */ + private ActivationOS createOsBean() + { + ActivationOS os = new ActivationOS(); + + os.setArch( arch ); + os.setFamily( family ); + os.setName( name ); + os.setVersion( version ); + + return os; + } + + /** + * Helper method to check if the given family is in the following list: + *
    + *
  • dos
  • + *
  • mac
  • + *
  • netware
  • + *
  • os/2
  • + *
  • tandem
  • + *
  • unix
  • + *
  • windows
  • + *
  • win9x
  • + *
  • z/os
  • + *
  • os/400
  • + *
+ * Note: '!' is allowed at the beginning of the string and still considered valid. + * + * @param theFamily the family to check. + * @return true if one of the valid families. + */ + public boolean isValidFamily( String theFamily ) + { + + // in case they are checking !family + theFamily = StringUtils.stripStart( theFamily, "!" ); + + return ( StringUtils.isEmpty( theFamily ) || Os.getValidFamilies().contains( theFamily ) ); + } + + /** + * Gets the arch. + * + * @return the arch + */ + public String getArch() + { + return this.arch; + } + + /** + * Sets the arch. + * + * @param theArch the arch to set + */ + public void setArch( String theArch ) + { + this.arch = theArch; + } + + /** + * Gets the family. + * + * @return the family + */ + public String getFamily() + { + return this.family; + } + + /** + * Sets the family. + * + * @param theFamily the family to set + */ + public void setFamily( String theFamily ) + { + this.family = theFamily; + } + + /** + * Gets the name. + * + * @return the name + */ + public String getName() + { + return this.name; + } + + /** + * Sets the name. + * + * @param theName the name to set + */ + public void setName( String theName ) + { + this.name = theName; + } + + /** + * Gets the version. + * + * @return the version + */ + public String getVersion() + { + return this.version; + } + + /** + * Sets the version. + * + * @param theVersion the version to set + */ + public void setVersion( String theVersion ) + { + this.version = theVersion; + } + + /** + * @param display The value for the display. + */ + public final void setDisplay( boolean display ) + { + this.display = display; + } + + public final boolean isDisplay() + { + return display; + } + + @Override + public String getCacheId() + { + // return the hashcodes of all the parameters + StringBuilder b = new StringBuilder(); + if ( StringUtils.isNotEmpty( version ) ) + { + b.append( version.hashCode() ); + } + if ( StringUtils.isNotEmpty( name ) ) + { + b.append( name.hashCode() ); + } + if ( StringUtils.isNotEmpty( arch ) ) + { + b.append( arch.hashCode() ); + } + if ( StringUtils.isNotEmpty( family ) ) + { + b.append( family.hashCode() ); + } + return b.toString(); + } + + @Override + public boolean isCacheable() + { + // the os is not going to change between projects in the same build. + return true; + } + + @Override + public boolean isResultValid( EnforcerRule theCachedRule ) + { + // i will always return the hash of the parameters as my id. If my parameters are the same, this + // rule must always have the same result. + return true; + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java new file mode 100644 index 000000000..c96793b48 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java @@ -0,0 +1,1272 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.maven.BuildFailureException; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.ArtifactNotFoundException; +import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.artifact.resolver.ArtifactResolver; +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.lifecycle.Lifecycle; +import org.apache.maven.lifecycle.LifecycleExecutionException; +import org.apache.maven.lifecycle.LifecycleExecutor; +import org.apache.maven.lifecycle.mapping.LifecycleMapping; +import org.apache.maven.model.BuildBase; +import org.apache.maven.model.Model; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.Profile; +import org.apache.maven.model.ReportPlugin; +import org.apache.maven.plugin.InvalidPluginException; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.PluginManager; +import org.apache.maven.plugin.PluginManagerException; +import org.apache.maven.plugin.PluginNotFoundException; +import org.apache.maven.plugin.descriptor.PluginDescriptor; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.plugin.version.PluginVersionNotFoundException; +import org.apache.maven.plugin.version.PluginVersionResolutionException; +import org.apache.maven.plugins.enforcer.utils.EnforcerRuleUtils; +import org.apache.maven.plugins.enforcer.utils.PluginWrapper; +import org.apache.maven.project.MavenProject; +import org.apache.maven.settings.Settings; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import org.codehaus.plexus.util.ReflectionUtils; +import org.codehaus.plexus.util.StringUtils; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +/** + * This rule will enforce that all plugins specified in the poms have a version declared. + * + * @author Brian Fox + */ +public class RequirePluginVersions + extends AbstractNonCacheableEnforcerRule +{ + + private EnforcerRuleHelper helper; + + /** + * Don't allow the LATEST identifier. + * + * @see {@link #setBanLatest(boolean)} + * @see {@link #isBanLatest()} + */ + private boolean banLatest = true; + + /** + * Don't allow the RELEASE identifier. + * + * @see {@link #setBanRelease(boolean)} + * @see {@link #isBanRelease()} + */ + private boolean banRelease = true; + + /** + * Don't allow snapshot plugins. + * + * @see {@link #setBanSnapshots(boolean)} + * @see {@link #isBanSnapshots()} + */ + private boolean banSnapshots = true; + + /** + * Don't allow timestamp snapshot plugins. + * + * @see {@link #setBanTimestamps(boolean)} + * @see {@link #isBanTimestamps()} + */ + private boolean banTimestamps = true; + + /** + * The comma separated list of phases that should be used to find lifecycle plugin bindings. The default value is + * "clean,deploy,site". + * + * @see {@link #setPhases(String)} + * @see {@link #getPhases()} + */ + private String phases = "clean,deploy,site"; + + /** + * Additional plugins to enforce have versions. These are plugins that may not be in the poms but are used anyway, + * like help, eclipse etc.
+ * The plugins should be specified in the form: group:artifactId. + * + * @see {@link #setAdditionalPlugins(List)} + * @see {@link #getAdditionalPlugins()} + */ + private List additionalPlugins; + + /** + * Plugins to skip for version enforcement. The plugins should be specified in the form: + * group:artifactId. NOTE: This is deprecated, use unCheckedPluginList instead. + * + * @see {@link #setUnCheckedPlugins(List)} + * @see {@link #getUnCheckedPlugins()} + */ + private List unCheckedPlugins; + + /** + * Same as unCheckedPlugins but as a comma list to better support properties. Sample form: + * group:artifactId,group2:artifactId2 + * + * @since 1.0-beta-1 + * @see {@link #setUnCheckedPlugins(List)} + * @see {@link #getUnCheckedPlugins()} + */ + private String unCheckedPluginList; + + /** The plugin manager. */ + private PluginManager pluginManager; + + /** The phase to lifecycle map. */ + private Map phaseToLifecycleMap; + + /** The lifecycles. */ + private Collection lifecycles; + + /** The factory. */ + private ArtifactFactory factory; + + /** The resolver. */ + private ArtifactResolver resolver; + + /** The local. */ + private ArtifactRepository local; + + /** The remote repositories. */ + private List remoteRepositories; + + /** The log. */ + private Log log; + + /** The session. */ + private MavenSession session; + + /** The utils. */ + private EnforcerRuleUtils utils; + + @Override + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + this.log = helper.getLog(); + this.helper = helper; + + MavenProject project; + try + { + // get the various expressions out of the helper. + + project = (MavenProject) helper.evaluate( "${project}" ); + LifecycleExecutor life; + life = helper.getComponent( LifecycleExecutor.class ); + + Object defaultLifeCycles = ReflectionUtils.getValueIncludingSuperclasses( "defaultLifeCycles", life ); + Map lifecyclesMap = (Map) ReflectionUtils.getValueIncludingSuperclasses( "lifecycles", defaultLifeCycles ); + lifecycles = lifecyclesMap.values(); + + session = (MavenSession) helper.evaluate( "${session}" ); + pluginManager = helper.getComponent( PluginManager.class ); + factory = helper.getComponent( ArtifactFactory.class ); + resolver = helper.getComponent( ArtifactResolver.class ); + local = (ArtifactRepository) helper.evaluate( "${localRepository}" ); + remoteRepositories = project.getRemoteArtifactRepositories(); + + utils = new EnforcerRuleUtils( helper ); + + // get all the plugins that are bound to the specified lifecycles + Set allPlugins = getBoundPlugins( life, project, phases ); + + // insert any additional plugins specified by the user. + allPlugins = addAdditionalPlugins( allPlugins, additionalPlugins ); + allPlugins.addAll( getProfilePlugins( project ) ); + + // pull out any we should skip + allPlugins = + removeUncheckedPlugins( combineUncheckedPlugins( unCheckedPlugins, unCheckedPluginList ), allPlugins ); + + // there's nothing to do here + if ( allPlugins.isEmpty() ) + { + log.info( "No plugin bindings found." ); + return; + } + else + { + log.debug( "All Plugins in use: " + allPlugins ); + } + + // get all the plugins that are mentioned in the pom (and parents) + List pluginWrappers = getAllPluginEntries( project ); + + for ( PluginWrapper pluginWrapper : pluginWrappers ) + { + log.debug( "pluginWrappers: " + pluginWrapper.getGroupId() + ":" + pluginWrapper.getArtifactId() + ":" + + pluginWrapper.getVersion() + " source:" + pluginWrapper.getSource() ); + } + // now look for the versions that aren't valid and add to a list. + List failures = new ArrayList(); + + for ( Plugin plugin : allPlugins ) + { + if ( !hasValidVersionSpecified( helper, plugin, pluginWrappers ) ) + { + failures.add( plugin ); + } + } + + // if anything was found, log it then append the optional message. + if ( !failures.isEmpty() ) + { + handleMessagesToTheUser( project, failures ); + } + } + catch ( ExpressionEvaluationException e ) + { + throw new EnforcerRuleException( "Unable to Evaluate an Expression:" + e.getLocalizedMessage() ); + } + catch ( ComponentLookupException e ) + { + throw new EnforcerRuleException( "Unable to lookup a component:" + e.getLocalizedMessage() ); + } + catch ( Exception e ) + { + throw new EnforcerRuleException( e.getLocalizedMessage() ); + } + } + + private void handleMessagesToTheUser( MavenProject project, List failures ) + throws EnforcerRuleException + { + StringBuilder newMsg = new StringBuilder(); + newMsg.append( "Some plugins are missing valid versions:" ); + handleBanMessages( newMsg ); + newMsg.append( "\n" ); + for ( Plugin plugin : failures ) + { + newMsg.append( plugin.getGroupId() ); + newMsg.append( ":" ); + newMsg.append( plugin.getArtifactId() ); + + try + { + newMsg.append( ". \tThe version currently in use is " ); + + Plugin currentPlugin = findCurrentPlugin( plugin, project ); + + if ( currentPlugin != null ) + { + newMsg.append( currentPlugin.getVersion() ); + } + else + { + newMsg.append( "unknown" ); + } + } + catch ( Exception e ) + { + // lots can go wrong here. Don't allow any issues trying to + // determine the issue stop me + log.debug( "Exception while determining plugin Version.", e ); + newMsg.append( ". Unable to determine the plugin version." ); + } + newMsg.append( "\n" ); + } + String message = getMessage(); + if ( StringUtils.isNotEmpty( message ) ) + { + newMsg.append( message ); + } + + throw new EnforcerRuleException( newMsg.toString() ); + } + + private void handleBanMessages( StringBuilder newMsg ) + { + if ( banLatest || banRelease || banSnapshots || banTimestamps ) + { + newMsg.append( " (" ); + if ( banLatest ) + { + newMsg.append( "LATEST " ); + } + if ( banRelease ) + { + newMsg.append( "RELEASE " ); + } + if ( banSnapshots || banTimestamps ) + { + newMsg.append( "SNAPSHOT " ); + } + newMsg.append( "are not allowed)" ); + } + } + + /** + * Remove the plugins that the user doesn't want to check. + * + * @param uncheckedPlugins + * @param plugins + * @throws MojoExecutionException + * @return The plugins which have been removed. + */ + public Set removeUncheckedPlugins( Collection uncheckedPlugins, Set plugins ) + throws MojoExecutionException + { + if ( uncheckedPlugins != null && !uncheckedPlugins.isEmpty() ) + { + for ( String pluginKey : uncheckedPlugins ) + { + Plugin plugin = parsePluginString( pluginKey, "UncheckedPlugins" ); + plugins.remove( plugin ); + } + } + return plugins; + } + + /** + * Combines the old Collection with the new comma separated list. + * + * @param uncheckedPlugins + * @param uncheckedPluginsList + * @return List of unchecked plugins. + */ + // CHECKSTYLE_OFF: LineLength + public Collection combineUncheckedPlugins( Collection uncheckedPlugins, + String uncheckedPluginsList ) + // CHECKSTYLE_ON: LineLength + { + // if the comma list is empty, then there's nothing to do here. + if ( StringUtils.isNotEmpty( uncheckedPluginsList ) ) + { + // make sure there is a collection to add to. + if ( uncheckedPlugins == null ) + { + uncheckedPlugins = new HashSet(); + } + else if ( !uncheckedPlugins.isEmpty() && log != null ) + { + log.warn( "The parameter 'unCheckedPlugins' is deprecated. Use 'unCheckedPluginList' instead" ); + } + + uncheckedPlugins.addAll( Arrays.asList( uncheckedPluginsList.split( "," ) ) ); + } + return uncheckedPlugins; + } + + /** + * Add the additional plugins if they don't exist yet. + * + * @param existing the existing + * @param additional the additional + * @return the sets the + * @throws MojoExecutionException the mojo execution exception + */ + public Set addAdditionalPlugins( Set existing, List additional ) + throws MojoExecutionException + { + if ( additional != null ) + { + for ( String pluginString : additional ) + { + Plugin plugin = parsePluginString( pluginString, "AdditionalPlugins" ); + + if ( existing == null ) + { + existing = new HashSet<>(); + existing.add( plugin ); + } + else if ( !existing.contains( plugin ) ) + { + existing.add( plugin ); + } + } + } + return existing; + } + + /** + * Helper method to parse and inject a Plugin. + * + * @param pluginString + * @param field + * @throws MojoExecutionException + * @return the plugin + */ + protected Plugin parsePluginString( String pluginString, String field ) + throws MojoExecutionException + { + if ( pluginString != null ) + { + String[] pluginStrings = pluginString.split( ":" ); + if ( pluginStrings.length == 2 ) + { + Plugin plugin = new Plugin(); + plugin.setGroupId( StringUtils.strip( pluginStrings[0] ) ); + plugin.setArtifactId( StringUtils.strip( pluginStrings[1] ) ); + + return plugin; + } + else + { + throw new MojoExecutionException( "Invalid " + field + " string: " + pluginString ); + } + } + else + { + throw new MojoExecutionException( "Invalid " + field + " string: " + pluginString ); + } + + } + + /** + * Finds the plugins that are listed in active profiles. + * + * @param project the project + * @return the profile plugins + */ + public Set getProfilePlugins( MavenProject project ) + { + Set result = new HashSet<>(); + List profiles = project.getActiveProfiles(); + if ( profiles != null && !profiles.isEmpty() ) + { + for ( Profile p : profiles ) + { + BuildBase b = p.getBuild(); + if ( b != null ) + { + List plugins = b.getPlugins(); + if ( plugins != null ) + { + result.addAll( plugins ); + } + } + } + } + return result; + } + + /** + * Given a plugin, this will retrieve the matching plugin artifact from the model. + * + * @param plugin plugin to lookup + * @param project project to search + * @return matching plugin, null if not found. + */ + protected Plugin findCurrentPlugin( Plugin plugin, MavenProject project ) + { + Plugin found = null; + try + { + Model model = project.getModel(); + Map plugins = model.getBuild().getPluginsAsMap(); + found = plugins.get( plugin.getKey() ); + } + catch ( NullPointerException e ) + { + // nothing to do here + } + + if ( found == null ) + { + found = resolvePlugin( plugin, project ); + } + + return found; + } + + /** + * Resolve plugin. + * + * @param plugin the plugin + * @param project the project + * @return the plugin + */ + protected Plugin resolvePlugin( Plugin plugin, MavenProject project ) + { + + List pluginRepositories = project.getPluginArtifactRepositories(); + Artifact artifact = factory.createPluginArtifact( plugin.getGroupId(), plugin.getArtifactId(), + VersionRange.createFromVersion( "LATEST" ) ); + + try + { + this.resolver.resolve( artifact, pluginRepositories, this.local ); + plugin.setVersion( artifact.getVersion() ); + } + catch ( ArtifactResolutionException | ArtifactNotFoundException e ) + { + // What does this mean? + } + + return plugin; + } + + /** + * Gets the plugins that are bound to the defined phases. This does not find plugins bound in the pom to a phase + * later than the plugin is executing. + * + * @param life the life + * @param project the project + * @param thePhases the the phases + * @return the bound plugins + * @throws PluginNotFoundException the plugin not found exception + * @throws LifecycleExecutionException the lifecycle execution exception + * @throws IllegalAccessException the illegal access exception + */ + protected Set getBoundPlugins( LifecycleExecutor life, MavenProject project, String thePhases ) + throws PluginNotFoundException, LifecycleExecutionException, IllegalAccessException + { + + Set allPlugins = new HashSet<>(); + + // lookup the bindings for all the passed in phases + String[] lifecyclePhases = thePhases.split( "," ); + for ( int i = 0; i < lifecyclePhases.length; i++ ) + { + String lifecyclePhase = lifecyclePhases[i]; + if ( StringUtils.isNotEmpty( lifecyclePhase ) ) + { + try + { + Lifecycle lifecycle = getLifecycleForPhase( lifecyclePhase ); + log.debug( "getBoundPlugins(): " + project.getId() + " " + lifecyclePhase + " " + + lifecycle.getId() ); + allPlugins.addAll( getAllPlugins( project, lifecycle ) ); + } + catch ( BuildFailureException e ) + { + // i'm going to swallow this because the + // user may have declared a phase that + // doesn't exist for every module. + } + } + } + return allPlugins; + } + + /** + * Checks for valid version specified. Checks to see if the version is specified for the plugin. Can optionally ban + * "RELEASE" or "LATEST" even if specified. + * + * @param helper the helper + * @param source the source + * @param pluginWrappers the plugins + * @return true, if successful + */ + protected boolean hasValidVersionSpecified( EnforcerRuleHelper helper, Plugin source, + List pluginWrappers ) + { + boolean found = false; + boolean status = false; + for ( PluginWrapper plugin : pluginWrappers ) + { + // find the matching plugin entry + if ( isMatchingPlugin( source, plugin ) ) + { + found = true; + // found the entry. now see if the version is specified + String version = plugin.getVersion(); + try + { + version = (String) helper.evaluate( version ); + } + catch ( ExpressionEvaluationException e ) + { + return false; + } + + if ( isValidVersion( version ) ) + { + helper.getLog().debug( "checking for notEmpty and notIsWhitespace(): " + version ); + if ( banRelease && version.equals( "RELEASE" ) ) + { + return false; + } + + if ( banLatest && version.equals( "LATEST" ) ) + { + return false; + } + + if ( banSnapshots && isSnapshot( version ) ) + { + return false; + } + // the version was specified and not + // banned. It's ok. Keep looking through the list to make + // sure it's not using a banned version somewhere else. + + status = true; + + if ( !banRelease && !banLatest && !banSnapshots ) + { + // no need to keep looking + break; + } + } + } + } + if ( !found ) + { + helper.getLog().debug( "plugin " + source.getGroupId() + ":" + source.getArtifactId() + " not found" ); + } + return status; + } + + private boolean isValidVersion( String version ) + { + return StringUtils.isNotEmpty( version ) && !StringUtils.isWhitespace( version ); + } + + private boolean isMatchingPlugin( Plugin source, PluginWrapper plugin ) + { + return source.getArtifactId().equals( plugin.getArtifactId() ) + && source.getGroupId().equals( plugin.getGroupId() ); + } + + /** + * Checks if is snapshot. + * + * @param baseVersion the base version + * @return true, if is snapshot + */ + protected boolean isSnapshot( String baseVersion ) + { + if ( banTimestamps ) + { + return Artifact.VERSION_FILE_PATTERN.matcher( baseVersion ).matches() + || baseVersion.endsWith( Artifact.SNAPSHOT_VERSION ); + } + else + { + return baseVersion.endsWith( Artifact.SNAPSHOT_VERSION ); + } + } + + /* + * Uses borrowed lifecycle code to get a list of all plugins bound to the lifecycle. + */ + /** + * Gets the all plugins. + * + * @param project the project + * @param lifecycle the lifecycle + * @return the all plugins + * @throws PluginNotFoundException the plugin not found exception + * @throws LifecycleExecutionException the lifecycle execution exception + */ + private Set getAllPlugins( MavenProject project, Lifecycle lifecycle ) + throws PluginNotFoundException, LifecycleExecutionException + + { + log.debug( "RequirePluginVersions.getAllPlugins:" ); + + Set plugins = new HashSet<>(); + // first, bind those associated with the packaging + Map mappings = findMappingsForLifecycle( project, lifecycle ); + + for ( Map.Entry entry : mappings.entrySet() ) + { + log.debug( " lifecycleMapping = " + entry.getKey() ); + String pluginsForLifecycle = (String) entry.getValue(); + log.debug( " plugins = " + pluginsForLifecycle ); + if ( StringUtils.isNotEmpty( pluginsForLifecycle ) ) + { + String pluginList[] = pluginsForLifecycle.split( "," ); + for ( String plugin : pluginList ) + { + plugin = StringUtils.strip( plugin ); + log.debug( " plugin = " + plugin ); + String tokens[] = plugin.split( ":" ); + log.debug( " GAV = " + Arrays.asList( tokens ) ); + + Plugin p = new Plugin(); + p.setGroupId( tokens[0] ); + p.setArtifactId( tokens[1] ); + plugins.add( p ); + } + } + } + + List mojos = findOptionalMojosForLifecycle( project, lifecycle ); + for ( String value : mojos ) + { + String tokens[] = value.split( ":" ); + + Plugin plugin = new Plugin(); + plugin.setGroupId( tokens[0] ); + plugin.setArtifactId( tokens[1] ); + plugins.add( plugin ); + } + + plugins.addAll( project.getBuildPlugins() ); + + return plugins; + } + + /* + * NOTE: All the code following this point was scooped from the DefaultLifecycleExecutor. There must be a better way + * but for now it should work. + */ + /** + * Gets the phase to lifecycle map. + * + * @return the phase to lifecycle map + * @throws LifecycleExecutionException the lifecycle execution exception + */ + public Map getPhaseToLifecycleMap() + throws LifecycleExecutionException + { + if ( phaseToLifecycleMap == null ) + { + phaseToLifecycleMap = new HashMap<>(); + + for ( Lifecycle lifecycle : lifecycles ) + { + List phases = lifecycle.getPhases(); + for ( String phase : phases ) + { + log.debug( "getPhaseToLifecycleMap(): phase: " + phase ); + if ( phaseToLifecycleMap.containsKey( phase ) ) + { + Lifecycle prevLifecycle = (Lifecycle) phaseToLifecycleMap.get( phase ); + throw new LifecycleExecutionException( "Phase '" + phase + + "' is defined in more than one lifecycle: '" + lifecycle.getId() + "' and '" + + prevLifecycle.getId() + "'" ); + } + else + { + phaseToLifecycleMap.put( phase, lifecycle ); + } + } + } + } + return phaseToLifecycleMap; + } + + /** + * Gets the lifecycle for phase. + * + * @param phase the phase + * @return the lifecycle for phase + * @throws BuildFailureException the build failure exception + * @throws LifecycleExecutionException the lifecycle execution exception + */ + private Lifecycle getLifecycleForPhase( String phase ) + throws BuildFailureException, LifecycleExecutionException + { + Lifecycle lifecycle = getPhaseToLifecycleMap().get( phase ); + + if ( lifecycle == null ) + { + throw new BuildFailureException( "Unable to find lifecycle for phase '" + phase + "'" ); + } + return lifecycle; + } + + /** + * Find mappings for lifecycle. + * + * @param project the project + * @param lifecycle the lifecycle + * @return the map + * @throws LifecycleExecutionException the lifecycle execution exception + * @throws PluginNotFoundException the plugin not found exception + */ + private Map findMappingsForLifecycle( MavenProject project, Lifecycle lifecycle ) + throws LifecycleExecutionException, PluginNotFoundException + { + String packaging = project.getPackaging(); + Map mappings = null; + + LifecycleMapping m = (LifecycleMapping) findExtension( project, LifecycleMapping.ROLE, packaging, + session.getSettings(), session.getLocalRepository() ); + if ( m != null ) + { + mappings = m.getPhases( lifecycle.getId() ); + } + + Map defaultMappings = lifecycle.getDefaultPhases(); + + if ( mappings == null ) + { + try + { + m = helper.getComponent( LifecycleMapping.class, packaging ); + mappings = m.getPhases( lifecycle.getId() ); + } + catch ( ComponentLookupException e ) + { + if ( defaultMappings == null ) + { + throw new LifecycleExecutionException( "Cannot find lifecycle mapping for packaging: \'" + packaging + + "\'.", e ); + } + } + } + + if ( mappings == null ) + { + if ( defaultMappings == null ) + { + throw new LifecycleExecutionException( "Cannot find lifecycle mapping for packaging: \'" + packaging + + "\', and there is no default" ); + } + else + { + mappings = defaultMappings; + } + } + + return mappings; + } + + /** + * Find optional mojos for lifecycle. + * + * @param project the project + * @param lifecycle the lifecycle + * @return the list + * @throws LifecycleExecutionException the lifecycle execution exception + * @throws PluginNotFoundException the plugin not found exception + */ + private List findOptionalMojosForLifecycle( MavenProject project, Lifecycle lifecycle ) + throws LifecycleExecutionException, PluginNotFoundException + { + String packaging = project.getPackaging(); + List optionalMojos = null; + + LifecycleMapping m = (LifecycleMapping) findExtension( project, LifecycleMapping.ROLE, packaging, + session.getSettings(), session.getLocalRepository() ); + + if ( m != null ) + { + optionalMojos = m.getOptionalMojos( lifecycle.getId() ); + } + + if ( optionalMojos == null ) + { + try + { + m = helper.getComponent( LifecycleMapping.class, packaging ); + optionalMojos = m.getOptionalMojos( lifecycle.getId() ); + } + catch ( ComponentLookupException e ) + { + log.debug( "Error looking up lifecycle mapping to retrieve optional mojos. Lifecycle ID: " + + lifecycle.getId() + ". Error: " + e.getMessage(), e ); + } + } + + if ( optionalMojos == null ) + { + optionalMojos = Collections.emptyList(); + } + + return optionalMojos; + } + + /** + * Find extension. + * + * @param project the project + * @param role the role + * @param roleHint the role hint + * @param settings the settings + * @param localRepository the local repository + * @return the object + * @throws LifecycleExecutionException the lifecycle execution exception + * @throws PluginNotFoundException the plugin not found exception + */ + private Object findExtension( MavenProject project, String role, String roleHint, Settings settings, + ArtifactRepository localRepository ) + throws LifecycleExecutionException, PluginNotFoundException + { + Object pluginComponent = null; + + List buildPlugins = project.getBuildPlugins(); + for ( Plugin plugin : buildPlugins ) + { + if ( plugin.isExtensions() ) + { + verifyPlugin( plugin, project, settings, localRepository ); + + // TODO: if moved to the plugin manager we + // already have the descriptor from above + // and so do can lookup the container + // directly + try + { + pluginComponent = pluginManager.getPluginComponent( plugin, role, roleHint ); + + if ( pluginComponent != null ) + { + break; + } + } + catch ( ComponentLookupException e ) + { + log.debug( "Unable to find the lifecycle component in the extension", e ); + } + catch ( PluginManagerException e ) + { + throw new LifecycleExecutionException( "Error getting extensions from the plugin '" + + plugin.getKey() + "': " + e.getMessage(), e ); + } + } + } + return pluginComponent; + } + + /** + * Verify plugin. + * + * @param plugin the plugin + * @param project the project + * @param settings the settings + * @param localRepository the local repository + * @return the plugin descriptor + * @throws LifecycleExecutionException the lifecycle execution exception + * @throws PluginNotFoundException the plugin not found exception + */ + private PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings, + ArtifactRepository localRepository ) + throws LifecycleExecutionException, PluginNotFoundException + { + PluginDescriptor pluginDescriptor; + try + { + pluginDescriptor = pluginManager.verifyPlugin( plugin, project, settings, localRepository ); + } + catch ( PluginManagerException e ) + { + throw new LifecycleExecutionException( "Internal error in the plugin manager getting plugin '" + + plugin.getKey() + "': " + e.getMessage(), e ); + } + catch ( PluginVersionResolutionException | InvalidVersionSpecificationException | InvalidPluginException + | ArtifactNotFoundException | ArtifactResolutionException | PluginVersionNotFoundException e ) + { + throw new LifecycleExecutionException( e.getMessage(), e ); + } + return pluginDescriptor; + } + + /** + * Gets all plugin entries in build.plugins, build.pluginManagement.plugins, profile.build.plugins, reporting and + * profile.reporting in this project and all parents + * + * @param project the project + * @return the all plugin entries wrapped in a PluginWrapper Object + * @throws ArtifactResolutionException the artifact resolution exception + * @throws ArtifactNotFoundException the artifact not found exception + * @throws IOException Signals that an I/O exception has occurred. + * @throws XmlPullParserException the xml pull parser exception + */ + protected List getAllPluginEntries( MavenProject project ) + throws ArtifactResolutionException, ArtifactNotFoundException, IOException, XmlPullParserException + { + List models = new ArrayList<>(); + + List sortedProjects = session.getProjectDependencyGraph().getSortedProjects(); + + if ( !sortedProjects.isEmpty() && sortedProjects.get( 0 ).getParent() != null ) + { + getOriginalModelFromAllParents( models, sortedProjects ); + } + + for ( MavenProject mavenProject : sortedProjects ) + { + models.add( mavenProject.getOriginalModel() ); + } + + List plugins = new ArrayList<>(); + // now find all the plugin entries, either in + // build.plugins or build.pluginManagement.plugins, profiles.plugins and reporting + for ( Model model : models ) + { + getPlugins( plugins, model ); + getReportingPlugins( plugins, model ); + getPluginManagementPlugins( plugins, model ); + + addPluginsInProfiles( plugins, model ); + } + + return plugins; + } + + private void getOriginalModelFromAllParents( List models, List sortedProjects ) + { + MavenProject parent = sortedProjects.get( 0 ).getParent(); + do + { + models.add( parent.getOriginalModel() ); + parent = parent.getParent(); + } + while ( parent != null ); + } + + private void addPluginsInProfiles( List plugins, Model model ) + { + List profiles = model.getProfiles(); + for ( Profile profile : profiles ) + { + getProfilePlugins( plugins, model, profile ); + getProfileReportingPlugins( plugins, model, profile ); + getProfilePluginManagementPlugins( plugins, model, profile ); + } + } + + private void getProfilePluginManagementPlugins( List plugins, Model model, Profile profile ) + { + try + { + List modelPlugins = profile.getBuild().getPluginManagement().getPlugins(); + plugins.addAll( PluginWrapper.addAll( utils.resolvePlugins( modelPlugins ), model.getId() + "profile[" + + profile.getId() + "].build.pluginManagement.plugins" ) ); + } + catch ( NullPointerException e ) + { + // guess there are no plugins here. + } + } + + private void getProfileReportingPlugins( List plugins, Model model, Profile profile ) + { + try + { + List modelReportPlugins = profile.getReporting().getPlugins(); + // add the reporting plugins + plugins.addAll( PluginWrapper.addAll( utils.resolveReportPlugins( modelReportPlugins ), model.getId() + + "profile[" + profile.getId() + "].reporting.plugins" ) ); + } + catch ( NullPointerException e ) + { + // guess there are no plugins here. + } + } + + private void getProfilePlugins( List plugins, Model model, Profile profile ) + { + try + { + List modelPlugins = profile.getBuild().getPlugins(); + plugins.addAll( PluginWrapper.addAll( utils.resolvePlugins( modelPlugins ), model.getId() + + ".profiles.profile[" + profile.getId() + "].build.plugins" ) ); + } + catch ( NullPointerException e ) + { + // guess there are no plugins here. + } + } + + private void getPlugins( List plugins, Model model ) + { + try + { + List modelPlugins = model.getBuild().getPlugins(); + plugins.addAll( PluginWrapper.addAll( utils.resolvePlugins( modelPlugins ), + model.getId() + ".build.plugins" ) ); + } + catch ( NullPointerException e ) + { + // guess there are no plugins here. + } + } + + private void getPluginManagementPlugins( List plugins, Model model ) + { + try + { + List modelPlugins = model.getBuild().getPluginManagement().getPlugins(); + plugins.addAll( PluginWrapper.addAll( utils.resolvePlugins( modelPlugins ), + model.getId() + ".build.pluginManagement.plugins" ) ); + } + catch ( NullPointerException e ) + { + // guess there are no plugins here. + } + } + + private void getReportingPlugins( List plugins, Model model ) + { + try + { + List modelReportPlugins = model.getReporting().getPlugins(); + // add the reporting plugins + plugins.addAll( PluginWrapper.addAll( utils.resolveReportPlugins( modelReportPlugins ), + model.getId() + ".reporting" ) ); + } + catch ( NullPointerException e ) + { + // guess there are no plugins here. + } + } + + /** + * Checks if is ban latest. + * + * @return the banLatest + */ + protected boolean isBanLatest() + { + return this.banLatest; + } + + /** + * Sets the ban latest. + * + * @param theBanLatest the banLatest to set + */ + protected void setBanLatest( boolean theBanLatest ) + { + this.banLatest = theBanLatest; + } + + /** + * Checks if is ban release. + * + * @return the banRelease + */ + protected boolean isBanRelease() + { + return this.banRelease; + } + + /** + * Sets the ban release. + * + * @param theBanRelease the banRelease to set + */ + protected void setBanRelease( boolean theBanRelease ) + { + this.banRelease = theBanRelease; + } + + /** + * Gets the utils. + * + * @return the utils + */ + protected EnforcerRuleUtils getUtils() + { + return this.utils; + } + + /** + * Sets the utils. + * + * @param theUtils the utils to set + */ + protected void setUtils( EnforcerRuleUtils theUtils ) + { + this.utils = theUtils; + } + + /** + * Checks if is ban snapshots. + * + * @return the banSnapshots + */ + public boolean isBanSnapshots() + { + return this.banSnapshots; + } + + /** + * Sets the ban snapshots. + * + * @param theBanSnapshots the banSnapshots to set + */ + public void setBanSnapshots( boolean theBanSnapshots ) + { + this.banSnapshots = theBanSnapshots; + } + + /** + * Checks if is ban timestamps. + * + * @return the banTimestamps + */ + public boolean isBanTimestamps() + { + return this.banTimestamps; + } + + /** + * Sets the ban timestamps. + * + * @param theBanTimestamps the banTimestamps to set + */ + public void setBanTimestamps( boolean theBanTimestamps ) + { + this.banTimestamps = theBanTimestamps; + } + + public List getUnCheckedPlugins() + { + return unCheckedPlugins; + } + + public void setUnCheckedPlugins( List unCheckedPlugins ) + { + this.unCheckedPlugins = unCheckedPlugins; + } + + public final void setPhases( String phases ) + { + this.phases = phases; + } + + public final String getPhases() + { + return phases; + } + + public final void setAdditionalPlugins( List additionalPlugins ) + { + this.additionalPlugins = additionalPlugins; + } + + public final List getAdditionalPlugins() + { + return additionalPlugins; + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePrerequisite.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePrerequisite.java new file mode 100644 index 000000000..725f2aab3 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePrerequisite.java @@ -0,0 +1,132 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.util.List; + +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.model.Prerequisites; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; + +/** + * @author Robert Scholte + * @since 1.3 + */ +public class RequirePrerequisite + extends AbstractNonCacheableEnforcerRule +{ + /** + * Only the projects with one of these packagings will be enforced to have the correct prerequisite. + * + * @since 1.4 + */ + private List packagings; + + /** + * Can either be version or a range, e.g. {@code 2.2.1} or {@code [2.2.1,)} + */ + private String mavenVersion; + + /** + * Set the mavenVersion Can either be version or a range, e.g. {@code 2.2.1} or {@code [2.2.1,)} + * + * @param mavenVersion the version or {@code null} + */ + public void setMavenVersion( String mavenVersion ) + { + this.mavenVersion = mavenVersion; + } + + /** + * Only the projects with one of these packagings will be enforced to have the correct prerequisite. + * + * @since 1.4 + * @param packagings the list of packagings + */ + public void setPackagings( List packagings ) + { + this.packagings = packagings; + } + + @Override + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + try + { + MavenProject project = (MavenProject) helper.evaluate( "${project}" ); + + if ( "pom".equals( project.getPackaging() ) ) + { + helper.getLog().debug( "Packaging is pom, skipping requirePrerequisite rule" ); + return; + } + + if ( packagings != null && !packagings.contains( project.getPackaging() ) ) + { + // CHECKSTYLE_OFF: LineLength + helper.getLog().debug( "Packaging is " + project.getPackaging() + ", skipping requirePrerequisite rule" ); + return; + // CHECKSTYLE_ON: LineLength + } + + Prerequisites prerequisites = project.getPrerequisites(); + + if ( prerequisites == null ) + { + throw new EnforcerRuleException( "Requires prerequisite not set" ); + } + + if ( mavenVersion != null ) + { + + VersionRange requiredVersionRange = VersionRange.createFromVersionSpec( mavenVersion ); + + if ( !requiredVersionRange.hasRestrictions() ) + { + requiredVersionRange = VersionRange.createFromVersionSpec( "[" + mavenVersion + ",)" ); + } + + VersionRange specifiedVersion = VersionRange.createFromVersionSpec( prerequisites.getMaven() ); + + VersionRange restrictedVersionRange = requiredVersionRange.restrict( specifiedVersion ); + + if ( restrictedVersionRange.getRecommendedVersion() == null ) + { + throw new EnforcerRuleException( "The specified Maven prerequisite( " + specifiedVersion + + " ) doesn't match the required version: " + mavenVersion ); + } + } + } + catch ( ExpressionEvaluationException e ) + { + throw new EnforcerRuleException( e.getMessage(), e ); + } + catch ( InvalidVersionSpecificationException e ) + { + throw new EnforcerRuleException( e.getMessage(), e ); + } + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireProfileIdsExist.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireProfileIdsExist.java new file mode 100644 index 000000000..e213b08b0 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireProfileIdsExist.java @@ -0,0 +1,101 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.util.ArrayList; +import java.util.List; + +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.codehaus.plexus.util.StringUtils; + +/** + * Ensure that all profiles mentioned on the commandline do exist. + * + * @author Robert Scholte + * @author Gabriel Belingueres + */ +public class RequireProfileIdsExist extends AbstractNonCacheableEnforcerRule +{ + @Override + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + try + { + MavenSession session = (MavenSession) helper.evaluate( "${session}" ); + + List profileIds = new ArrayList<>(); + profileIds.addAll( session.getProjectBuildingRequest().getActiveProfileIds() ); + profileIds.addAll( session.getProjectBuildingRequest().getInactiveProfileIds() ); + + for ( MavenProject project : session.getProjects() ) + { + // iterate over all parents + MavenProject currentProject = project; + do + { + for ( org.apache.maven.model.Profile profile : currentProject.getModel().getProfiles() ) + { + profileIds.remove( profile.getId() ); + + if ( profileIds.isEmpty() ) + { + return; + } + } + + currentProject = currentProject.getParent(); + } + while ( currentProject != null ); + } + + for ( org.apache.maven.settings.Profile profile : session.getSettings().getProfiles() ) + { + profileIds.remove( profile.getId() ); + } + + if ( profileIds.isEmpty() ) + { + return; + } + + StringBuilder sb = new StringBuilder(); + if ( profileIds.size() > 1 ) + { + sb.append( "The requested profiles don't exist: " ); + } + else + { + sb.append( "The requested profile doesn't exist: " ); + } + sb.append( StringUtils.join( profileIds.iterator(), ", " ) ); + + throw new EnforcerRuleException( sb.toString() ); + } + catch ( ExpressionEvaluationException e ) + { + throw new EnforcerRuleException( e.getMessage() ); + } + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireProperty.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireProperty.java new file mode 100644 index 000000000..b915475e9 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireProperty.java @@ -0,0 +1,80 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; + +/** + * This rule checks that certain properties are set. + * + * @author Paul Gier + */ +public class RequireProperty + extends AbstractPropertyEnforcerRule +{ + + /** + * Specify the required property. + * + * @see {@link #setProperty(String)} + * @see {@link #getPropertyName()} + */ + private String property = null; + + public final void setProperty( String property ) + { + this.property = property; + } + + @Override + public Object resolveValue( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + Object propValue = null; + try + { + propValue = helper.evaluate( "${" + property + "}" ); + } + catch ( ExpressionEvaluationException eee ) + { + throw new EnforcerRuleException( "Unable to evaluate property: " + property, eee ); + } + return propValue; + } + + protected String resolveValue() + { + return null; + } + + @Override + public String getPropertyName() + { + return property; + } + + @Override + public String getName() + { + return "Property"; + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireReleaseDeps.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireReleaseDeps.java new file mode 100644 index 000000000..888cfd822 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireReleaseDeps.java @@ -0,0 +1,232 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.resolver.filter.AndArtifactFilter; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.project.MavenProject; +import org.apache.maven.shared.artifact.filter.StrictPatternExcludesArtifactFilter; +import org.apache.maven.shared.artifact.filter.StrictPatternIncludesArtifactFilter; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; + +/** + * This rule checks that no snapshots are included. + * + * @author Brian Fox + */ +public class RequireReleaseDeps + extends AbstractBanDependencies +{ + + /** + * Allows this rule to execute only when this project is a release. + * + * @parameter + * + * @see {@link #setOnlyWhenRelease(boolean)} + * @see {@link #isOnlyWhenRelease()} + + */ + private boolean onlyWhenRelease = false; + + /** + * Allows this rule to fail when the parent is defined as a snapshot. + * + * @parameter + * + * @see {@link #setFailWhenParentIsSnapshot(boolean)} + * @see {@link #isFailWhenParentIsSnapshot()} + */ + private boolean failWhenParentIsSnapshot = true; + + /** + * Dependencies to ignore when checking for release versions. For example, inter-module dependencies + * can be excluded from the check and therefore allowed to contain snapshot versions. + * + * @see {@link #setExcludes(List)} + * @see {@link #getExcludes()} + */ + private List excludes = null; + + /** + * Dependencies to include when checking for release versions. If any of the included dependencies + * have snapshot versions, the rule will fail. + * + * @see {@link #setIncludes(List)} + * @see {@link #getIncludes()} + */ + private List includes = null; + + // Override parent to allow optional ignore of this rule. + @Override + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + boolean callSuper; + MavenProject project = null; + if ( onlyWhenRelease ) + { + // get the project + project = getProject( helper ); + + // only call super if this project is a release + callSuper = !project.getArtifact().isSnapshot(); + } + else + { + callSuper = true; + } + if ( callSuper ) + { + super.execute( helper ); + if ( failWhenParentIsSnapshot ) + { + if ( project == null ) + { + project = getProject( helper ); + } + Artifact parentArtifact = project.getParentArtifact(); + if ( parentArtifact != null && parentArtifact.isSnapshot() ) + { + throw new EnforcerRuleException( "Parent Cannot be a snapshot: " + parentArtifact.getId() ); + } + } + } + } + + /** + * @param helper + * @return The evaluated {@link MavenProject}. + * @throws EnforcerRuleException + */ + private MavenProject getProject( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + try + { + return (MavenProject) helper.evaluate( "${project}" ); + } + catch ( ExpressionEvaluationException eee ) + { + throw new EnforcerRuleException( "Unable to retrieve the MavenProject: ", eee ); + } + } + + @Override + protected Set checkDependencies( Set dependencies, Log log ) + throws EnforcerRuleException + { + Set foundSnapshots = new HashSet<>(); + + Set filteredDependencies = filterArtifacts( dependencies ); + + for ( Artifact artifact : filteredDependencies ) + { + if ( artifact.isSnapshot() ) + { + foundSnapshots.add( artifact ); + } + } + + return foundSnapshots; + } + + /* + * Filter the dependency artifacts according to the includes and excludes + * If includes and excludes are both null, the original set is returned. + * + * @param dependencies the list of dependencies to filter + * @return the resulting set of dependencies + */ + public Set filterArtifacts( Set dependencies ) + { + if ( includes == null && excludes == null ) + { + return dependencies; + } + + AndArtifactFilter filter = new AndArtifactFilter( ); + if ( includes != null ) + { + filter.add( new StrictPatternIncludesArtifactFilter( includes ) ); + } + if ( excludes != null ) + { + filter.add( new StrictPatternExcludesArtifactFilter( excludes ) ); + } + + Set result = new HashSet<>(); + for ( Artifact artifact : dependencies ) + { + if ( filter.include( artifact ) ) + { + result.add( artifact ); + } + } + return result; + } + + public final boolean isOnlyWhenRelease() + { + return onlyWhenRelease; + } + + public final void setOnlyWhenRelease( boolean onlyWhenRelease ) + { + this.onlyWhenRelease = onlyWhenRelease; + } + + public final boolean isFailWhenParentIsSnapshot() + { + return failWhenParentIsSnapshot; + } + + public final void setFailWhenParentIsSnapshot( boolean failWhenParentIsSnapshot ) + { + this.failWhenParentIsSnapshot = failWhenParentIsSnapshot; + } + + public final void setExcludes( List excludes ) + { + this.excludes = excludes; + } + + public final List getExcludes() + { + return excludes; + } + + public void setIncludes( List includes ) + { + this.includes = includes; + } + + public List getIncludes() + { + return includes; + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireReleaseVersion.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireReleaseVersion.java new file mode 100644 index 000000000..fd6c6fd98 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireReleaseVersion.java @@ -0,0 +1,103 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; + +/** + * This rule checks that the current project is not a snapshot. + * + * @author Brian Fox + */ +public class RequireReleaseVersion + extends AbstractNonCacheableEnforcerRule +{ + + /** + * Allows this rule to fail when the parent is defined as a snapshot. + * + * @parameter + * + * @see {@link #setFailWhenParentIsSnapshot(boolean)} + * @see {@link #isFailWhenParentIsSnapshot()} + */ + private boolean failWhenParentIsSnapshot = true; + + @Override + public void execute( EnforcerRuleHelper theHelper ) + throws EnforcerRuleException + { + + MavenProject project = getProject( theHelper ); + + if ( project.getArtifact().isSnapshot() ) + { + String message = getMessage(); + StringBuilder buf = new StringBuilder(); + if ( message != null ) + { + buf.append( message ).append( System.lineSeparator() ); + } + buf.append( "This project cannot be a snapshot:" ).append( project.getArtifact().getId() ); + throw new EnforcerRuleException( buf.toString() ); + } + if ( failWhenParentIsSnapshot ) + { + Artifact parentArtifact = project.getParentArtifact(); + if ( parentArtifact != null && parentArtifact.isSnapshot() ) + { + throw new EnforcerRuleException( "Parent Cannot be a snapshot: " + parentArtifact.getId() ); + } + } + + } + + /** + * @param helper + * @return The evaluated {@link MavenProject}. + * @throws EnforcerRuleException + */ + private MavenProject getProject( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + try + { + return (MavenProject) helper.evaluate( "${project}" ); + } + catch ( ExpressionEvaluationException eee ) + { + throw new EnforcerRuleException( "Unable to retrieve the MavenProject: ", eee ); + } + } + + public final boolean isFailWhenParentIsSnapshot() + { + return failWhenParentIsSnapshot; + } + + public final void setFailWhenParentIsSnapshot( boolean failWhenParentIsSnapshot ) + { + this.failWhenParentIsSnapshot = failWhenParentIsSnapshot; + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireSameVersions.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireSameVersions.java new file mode 100644 index 000000000..d50cabab8 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireSameVersions.java @@ -0,0 +1,131 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.regex.Pattern; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; + +/** + * @author Robert Scholte + * @since 1.3 + */ +public class RequireSameVersions + extends AbstractNonCacheableEnforcerRule +{ + private boolean uniqueVersions; + + private Set dependencies = new HashSet<>(); + + private Set plugins = new HashSet<>(); + + private Set buildPlugins = new HashSet<>(); + + private Set reportPlugins = new HashSet<>(); + + @Override + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + // get the project + MavenProject project; + try + { + project = (MavenProject) helper.evaluate( "${project}" ); + } + catch ( ExpressionEvaluationException eee ) + { + throw new EnforcerRuleException( "Unable to retrieve the MavenProject: ", eee ); + } + + // consider including profile based artifacts + Map> versionMembers = new LinkedHashMap<>(); + + Set buildPluginSet = new HashSet<>( buildPlugins ); + buildPluginSet.addAll( plugins ); + Set reportPluginSet = new HashSet<>( reportPlugins ); + reportPluginSet.addAll( plugins ); + + // CHECKSTYLE_OFF: LineLength + versionMembers.putAll( collectVersionMembers( project.getArtifacts(), dependencies, " (dependency)" ) ); + versionMembers.putAll( collectVersionMembers( project.getPluginArtifacts(), buildPlugins, " (buildPlugin)" ) ); + versionMembers.putAll( collectVersionMembers( project.getReportArtifacts(), reportPlugins, " (reportPlugin)" ) ); + // CHECKSTYLE_ON: LineLength + + if ( versionMembers.size() > 1 ) + { + StringBuilder builder = new StringBuilder( "Found entries with different versions" + + System.lineSeparator() ); + for ( Map.Entry> entry : versionMembers.entrySet() ) + { + builder.append( "Entries with version " ).append( entry.getKey() ).append( System.lineSeparator() ); + for ( String conflictId : entry.getValue() ) + { + builder.append( "- " ).append( conflictId ).append( System.lineSeparator() ); + } + } + throw new EnforcerRuleException( builder.toString() ); + } + } + + private Map> collectVersionMembers( Set artifacts, Collection patterns, + String source ) + { + Map> versionMembers = new LinkedHashMap<>(); + + List regExs = new ArrayList<>(); + for ( String pattern : patterns ) + { + String regex = pattern.replace( ".", "\\." ).replace( "*", ".*" ).replace( ":", "\\:" ).replace( '?', '.' ); + + // pattern is groupId[:artifactId[:type[:classifier]]] + regExs.add( Pattern.compile( regex + "(\\:.+)?" ) ); + } + + for ( Artifact artifact : artifacts ) + { + for ( Pattern regEx : regExs ) + { + if ( regEx.matcher( artifact.getDependencyConflictId() ).matches() ) + { + String version = uniqueVersions ? artifact.getVersion() : artifact.getBaseVersion(); + if ( !versionMembers.containsKey( version ) ) + { + versionMembers.put( version, new ArrayList() ); + } + versionMembers.get( version ).add( artifact.getDependencyConflictId() + source ); + } + } + } + return versionMembers; + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireSnapshotVersion.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireSnapshotVersion.java new file mode 100644 index 000000000..a631d2a1f --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireSnapshotVersion.java @@ -0,0 +1,95 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; + +/** + * This rule checks that the current project is not a release. + */ +public class RequireSnapshotVersion + extends AbstractNonCacheableEnforcerRule +{ + + /** + * Allows this rule to fail when the parent is defined as a release. + */ + private boolean failWhenParentIsRelease = true; + + @Override + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + + MavenProject project = getProject( false, helper ); + Artifact artifact = project.getArtifact(); + + if ( !artifact.isSnapshot() ) + { + String message = getMessage(); + StringBuilder sb = new StringBuilder(); + if ( message != null ) + { + sb.append( message ).append( System.lineSeparator() ); + } + sb.append( "This project cannot be a release:" ).append( artifact.getId() ); + throw new EnforcerRuleException( sb.toString() ); + } + if ( failWhenParentIsRelease && project.hasParent() ) + { + // project.getParentArtifact() does not work here if a "CI Friendly Version" is used (e.g. ${revision}) + Artifact parentArtifact = getProject( true, helper ).getArtifact(); + if ( parentArtifact != null && !parentArtifact.isSnapshot() ) + { + throw new EnforcerRuleException( "Parent cannot be a release: " + parentArtifact.getId() ); + } + } + + } + + private MavenProject getProject( boolean parent, EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + String expression = parent ? "${project.parent}" : "${project}"; + try + { + return (MavenProject) helper.evaluate( expression ); + } + catch ( ExpressionEvaluationException eee ) + { + throw new EnforcerRuleException( "Unable to retrieve the MavenProject: ", eee ); + } + } + + public boolean isFailWhenParentIsRelease() + { + return failWhenParentIsRelease; + } + + public void setFailWhenParentIsRelease( boolean failWhenParentIsRelease ) + { + this.failWhenParentIsRelease = failWhenParentIsRelease; + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireUpperBoundDeps.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireUpperBoundDeps.java new file mode 100644 index 000000000..348d056a6 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireUpperBoundDeps.java @@ -0,0 +1,391 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.metadata.ArtifactMetadataSource; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.ArtifactCollector; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.apache.maven.artifact.versioning.DefaultArtifactVersion; +import org.apache.maven.artifact.versioning.OverConstrainedVersionException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.project.MavenProject; +import org.apache.maven.shared.dependency.tree.DependencyNode; +import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder; +import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException; +import org.apache.maven.shared.dependency.tree.traversal.DependencyNodeVisitor; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; + +/** + * Rule to enforce that the resolved dependency is also the most recent one of all transitive dependencies. + * + * @author Geoffrey De Smet + * @since 1.1 + */ +public class RequireUpperBoundDeps + extends AbstractNonCacheableEnforcerRule +{ + private static Log log; + + /** + * @since 1.3 + */ + private boolean uniqueVersions; + + /** + * Dependencies to ignore. + * + * @since TBD + */ + private List excludes = null; + + /** + * Set to {@code true} if timestamped snapshots should be used. + * + * @param uniqueVersions + * @since 1.3 + */ + public void setUniqueVersions( boolean uniqueVersions ) + { + this.uniqueVersions = uniqueVersions; + } + + /** + * Sets dependencies to exclude. + * @param excludes a list of {@code groupId:artifactId} names + */ + public void setExcludes( List excludes ) + { + this.excludes = excludes; + } + + // CHECKSTYLE_OFF: LineLength + /** + * Uses the {@link EnforcerRuleHelper} to populate the values of the + * {@link DependencyTreeBuilder#buildDependencyTree(MavenProject, ArtifactRepository, ArtifactFactory, ArtifactMetadataSource, ArtifactFilter, ArtifactCollector)} + * factory method.
+ * This method simply exists to hide all the ugly lookup that the {@link EnforcerRuleHelper} has to do. + * + * @param helper + * @return a Dependency Node which is the root of the project's dependency tree + * @throws EnforcerRuleException when the build should fail + */ + // CHECKSTYLE_ON: LineLength + private DependencyNode getNode( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + try + { + MavenProject project = (MavenProject) helper.evaluate( "${project}" ); + DependencyTreeBuilder dependencyTreeBuilder = helper.getComponent( DependencyTreeBuilder.class ); + ArtifactRepository repository = (ArtifactRepository) helper.evaluate( "${localRepository}" ); + ArtifactFactory factory = helper.getComponent( ArtifactFactory.class ); + ArtifactMetadataSource metadataSource = helper.getComponent( ArtifactMetadataSource.class ); + ArtifactCollector collector = helper.getComponent( ArtifactCollector.class ); + ArtifactFilter filter = null; // we need to evaluate all scopes + DependencyNode node = + dependencyTreeBuilder.buildDependencyTree( project, repository, factory, metadataSource, filter, + collector ); + return node; + } + catch ( ExpressionEvaluationException e ) + { + throw new EnforcerRuleException( "Unable to lookup an expression " + e.getLocalizedMessage(), e ); + } + catch ( ComponentLookupException e ) + { + throw new EnforcerRuleException( "Unable to lookup a component " + e.getLocalizedMessage(), e ); + } + catch ( DependencyTreeBuilderException e ) + { + throw new EnforcerRuleException( "Could not build dependency tree " + e.getLocalizedMessage(), e ); + } + } + + @Override + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + if ( log == null ) + { + log = helper.getLog(); + } + try + { + DependencyNode node = getNode( helper ); + RequireUpperBoundDepsVisitor visitor = new RequireUpperBoundDepsVisitor(); + visitor.setUniqueVersions( uniqueVersions ); + node.accept( visitor ); + List errorMessages = buildErrorMessages( visitor.getConflicts() ); + if ( errorMessages.size() > 0 ) + { + throw new EnforcerRuleException( "Failed while enforcing RequireUpperBoundDeps. The error(s) are " + + errorMessages ); + } + } + catch ( Exception e ) + { + throw new EnforcerRuleException( e.getLocalizedMessage(), e ); + } + } + + private List buildErrorMessages( List> conflicts ) + { + List errorMessages = new ArrayList<>( conflicts.size() ); + for ( List conflict : conflicts ) + { + Artifact artifact = conflict.get( 0 ).getArtifact(); + String groupArt = artifact.getGroupId() + ":" + artifact.getArtifactId(); + if ( excludes != null && excludes.contains( groupArt ) ) + { + log.info( "Ignoring requireUpperBoundDeps in " + groupArt ); + } + else + { + errorMessages.add( buildErrorMessage( conflict ) ); + } + } + return errorMessages; + } + + private String buildErrorMessage( List conflict ) + { + StringBuilder errorMessage = new StringBuilder(); + errorMessage.append( System.lineSeparator() + "Require upper bound dependencies error for " + + getFullArtifactName( conflict.get( 0 ), false ) + " paths to dependency are:" + System.lineSeparator() ); + if ( conflict.size() > 0 ) + { + errorMessage.append( buildTreeString( conflict.get( 0 ) ) ); + } + for ( DependencyNode node : conflict.subList( 1, conflict.size() ) ) + { + errorMessage.append( "and" + System.lineSeparator() ); + errorMessage.append( buildTreeString( node ) ); + } + return errorMessage.toString(); + } + + private StringBuilder buildTreeString( DependencyNode node ) + { + List loc = new ArrayList<>(); + DependencyNode currentNode = node; + while ( currentNode != null ) + { + StringBuilder line = new StringBuilder( getFullArtifactName( currentNode, false ) ); + + if ( currentNode.getPremanagedVersion() != null ) + { + line.append( " (managed) <-- " ); + line.append( getFullArtifactName( currentNode, true ) ); + } + + loc.add( line.toString() ); + currentNode = currentNode.getParent(); + } + Collections.reverse( loc ); + StringBuilder builder = new StringBuilder(); + for ( int i = 0; i < loc.size(); i++ ) + { + for ( int j = 0; j < i; j++ ) + { + builder.append( " " ); + } + builder.append( "+-" ).append( loc.get( i ) ); + builder.append( System.lineSeparator() ); + } + return builder; + } + + private String getFullArtifactName( DependencyNode node, boolean usePremanaged ) + { + Artifact artifact = node.getArtifact(); + + String version = node.getPremanagedVersion(); + if ( !usePremanaged || version == null ) + { + version = uniqueVersions ? artifact.getVersion() : artifact.getBaseVersion(); + } + return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + version; + } + + private static class RequireUpperBoundDepsVisitor + implements DependencyNodeVisitor + { + + private boolean uniqueVersions; + + public void setUniqueVersions( boolean uniqueVersions ) + { + this.uniqueVersions = uniqueVersions; + } + + private Map> keyToPairsMap = + new LinkedHashMap<>(); + + public boolean visit( DependencyNode node ) + { + DependencyNodeHopCountPair pair = new DependencyNodeHopCountPair( node ); + String key = pair.constructKey(); + List pairs = keyToPairsMap.get( key ); + if ( pairs == null ) + { + pairs = new ArrayList<>(); + keyToPairsMap.put( key, pairs ); + } + pairs.add( pair ); + Collections.sort( pairs ); + return true; + } + + public boolean endVisit( DependencyNode node ) + { + return true; + } + + public List> getConflicts() + { + List> output = new ArrayList<>(); + for ( List pairs : keyToPairsMap.values() ) + { + if ( containsConflicts( pairs ) ) + { + List outputSubList = new ArrayList<>( pairs.size() ); + for ( DependencyNodeHopCountPair pair : pairs ) + { + outputSubList.add( pair.getNode() ); + } + output.add( outputSubList ); + } + } + return output; + } + + @SuppressWarnings( "unchecked" ) + private boolean containsConflicts( List pairs ) + { + DependencyNodeHopCountPair resolvedPair = pairs.get( 0 ); + + // search for artifact with lowest hopCount + for ( DependencyNodeHopCountPair hopPair : pairs.subList( 1, pairs.size() ) ) + { + if ( hopPair.getHopCount() < resolvedPair.getHopCount() ) + { + resolvedPair = hopPair; + } + } + + ArtifactVersion resolvedVersion = resolvedPair.extractArtifactVersion( uniqueVersions, false ); + + for ( DependencyNodeHopCountPair pair : pairs ) + { + ArtifactVersion version = pair.extractArtifactVersion( uniqueVersions, true ); + if ( resolvedVersion.compareTo( version ) < 0 ) + { + return true; + } + } + return false; + } + + } + + private static class DependencyNodeHopCountPair + implements Comparable + { + + private DependencyNode node; + + private int hopCount; + + private DependencyNodeHopCountPair( DependencyNode node ) + { + this.node = node; + countHops(); + } + + private void countHops() + { + hopCount = 0; + DependencyNode parent = node.getParent(); + while ( parent != null ) + { + hopCount++; + parent = parent.getParent(); + } + } + + private String constructKey() + { + Artifact artifact = node.getArtifact(); + return artifact.getGroupId() + ":" + artifact.getArtifactId(); + } + + public DependencyNode getNode() + { + return node; + } + + private ArtifactVersion extractArtifactVersion( boolean uniqueVersions, boolean usePremanagedVersion ) + { + if ( usePremanagedVersion && node.getPremanagedVersion() != null ) + { + return new DefaultArtifactVersion( node.getPremanagedVersion() ); + } + + Artifact artifact = node.getArtifact(); + String version = uniqueVersions ? artifact.getVersion() : artifact.getBaseVersion(); + if ( version != null ) + { + return new DefaultArtifactVersion( version ); + } + try + { + return artifact.getSelectedVersion(); + } + catch ( OverConstrainedVersionException e ) + { + throw new RuntimeException( "Version ranges problem with " + node.getArtifact(), e ); + } + } + + public int getHopCount() + { + return hopCount; + } + + public int compareTo( DependencyNodeHopCountPair other ) + { + return Integer.valueOf( hopCount ).compareTo( Integer.valueOf( other.getHopCount() ) ); + } + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/ArtifactMatcher.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/ArtifactMatcher.java new file mode 100644 index 000000000..ff5803b78 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/ArtifactMatcher.java @@ -0,0 +1,219 @@ +package org.apache.maven.plugins.enforcer.utils; + +/* + * 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. + */ + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.versioning.DefaultArtifactVersion; +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.plugins.enforcer.AbstractVersionEnforcer; +import java.util.Collection; +import java.util.LinkedList; + +/** + * This class is used for matching Artifacts against a list of patterns. + * + * @author Jakub Senko + * @see org.apache.maven.plugins.enforcer.BanTransitiveDependencies + */ +public final class ArtifactMatcher +{ + + /** + * @author I don't know + */ + public static class Pattern + { + private String pattern; + + private String[] parts; + + public Pattern( String pattern ) + { + if ( pattern == null ) + { + throw new NullPointerException( "pattern" ); + } + + this.pattern = pattern; + + parts = pattern.split( ":", 7 ); + + if ( parts.length == 7 ) + { + throw new IllegalArgumentException( "Pattern contains too many delimiters." ); + } + + for ( String part : parts ) + { + if ( "".equals( part ) ) + { + throw new IllegalArgumentException( "Pattern or its part is empty." ); + } + } + } + + public boolean match( Artifact artifact ) + throws InvalidVersionSpecificationException + { + if ( artifact == null ) + { + throw new NullPointerException( "artifact" ); + } + + switch ( parts.length ) + { + case 6: + String classifier = artifact.getClassifier(); + if ( !matches( parts[5], classifier ) ) + { + return false; + } + case 5: + String scope = artifact.getScope(); + if ( scope == null || scope.equals( "" ) ) + { + scope = Artifact.SCOPE_COMPILE; + } + + if ( !matches( parts[4], scope ) ) + { + return false; + } + case 4: + String type = artifact.getType(); + if ( type == null || type.equals( "" ) ) + { + type = "jar"; + } + + if ( !matches( parts[3], type ) ) + { + return false; + } + + case 3: + if ( !matches( parts[2], artifact.getVersion() ) ) + { + // CHECKSTYLE_OFF: LineLength + if ( !AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( parts[2] ), + new DefaultArtifactVersion( + artifact.getVersion() ) ) ) + // CHECKSTYLE_ON: LineLength + { + return false; + } + } + + case 2: + if ( !matches( parts[1], artifact.getArtifactId() ) ) + { + return false; + } + case 1: + return matches( parts[0], artifact.getGroupId() ); + default: + throw new AssertionError(); + } + } + + private boolean matches( String expression, String input ) + { + String regex = + expression.replace( ".", "\\." ).replace( "*", ".*" ).replace( ":", "\\:" ).replace( '?', '.' ) + .replace( "[", "\\[" ).replace( "]", "\\]" ).replace( "(", "\\(" ).replace( ")", "\\)" ); + + // TODO: Check if this can be done better or prevented earlier. + if ( input == null ) + { + input = ""; + } + + return java.util.regex.Pattern.matches( regex, input ); + } + + @Override + public String toString() + { + return pattern; + } + } + + private Collection patterns = new LinkedList<>(); + + private Collection ignorePatterns = new LinkedList<>(); + + /** + * Construct class by providing patterns as strings. Empty strings are ignored. + * + * @throws NullPointerException if any of the arguments is null + */ + public ArtifactMatcher( final Collection patterns, final Collection ignorePatterns ) + { + if ( patterns == null ) + { + throw new NullPointerException( "patterns" ); + } + if ( ignorePatterns == null ) + { + throw new NullPointerException( "ignorePatterns" ); + } + for ( String pattern : patterns ) + { + if ( pattern != null && !"".equals( pattern ) ) + { + this.patterns.add( new Pattern( pattern ) ); + } + } + + for ( String ignorePattern : ignorePatterns ) + { + if ( ignorePattern != null && !"".equals( ignorePattern ) ) + { + this.ignorePatterns.add( new Pattern( ignorePattern ) ); + } + } + } + + /** + * Check if artifact matches patterns. + * + * @throws InvalidVersionSpecificationException + */ + public boolean match( Artifact artifact ) + throws InvalidVersionSpecificationException + { + for ( Pattern pattern : patterns ) + { + if ( pattern.match( artifact ) ) + { + for ( Pattern ignorePattern : ignorePatterns ) + { + if ( ignorePattern.match( artifact ) ) + { + return false; + } + } + return true; + } + } + return false; + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/ArtifactUtils.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/ArtifactUtils.java new file mode 100644 index 000000000..b9a04afd0 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/ArtifactUtils.java @@ -0,0 +1,129 @@ +package org.apache.maven.plugins.enforcer.utils; + +/* + * 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. + */ + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.apache.commons.lang3.StringUtils; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.plugins.enforcer.utils.ArtifactMatcher.Pattern; +import org.apache.maven.shared.dependency.graph.DependencyNode; + +/** + * + * @author Robert Scholte + * @since 3.0.0 + */ +public final class ArtifactUtils +{ + private ArtifactUtils() + { + } + + public static Set getAllDescendants( DependencyNode node ) + { + Set children = null; + if ( node.getChildren() != null ) + { + children = new HashSet<>(); + for ( DependencyNode depNode : node.getChildren() ) + { + children.add( depNode.getArtifact() ); + Set subNodes = getAllDescendants( depNode ); + if ( subNodes != null ) + { + children.addAll( subNodes ); + } + } + } + return children; + } + + /** + * Checks the set of dependencies against the list of patterns. + * + * @param thePatterns the patterns + * @param dependencies the dependencies + * @return a set containing artifacts matching one of the patterns or null + * @throws EnforcerRuleException the enforcer rule exception + */ + public static Set checkDependencies( Set dependencies, List thePatterns ) + throws EnforcerRuleException + { + Set foundMatches = null; + + if ( thePatterns != null && thePatterns.size() > 0 ) + { + + for ( String pattern : thePatterns ) + { + String[] subStrings = pattern.split( ":" ); + subStrings = StringUtils.stripAll( subStrings ); + String resultPattern = StringUtils.join( subStrings, ":" ); + + for ( Artifact artifact : dependencies ) + { + if ( compareDependency( resultPattern, artifact ) ) + { + // only create if needed + if ( foundMatches == null ) + { + foundMatches = new HashSet(); + } + foundMatches.add( artifact ); + } + } + } + } + return foundMatches; + } + + /** + * Compares the given pattern against the given artifact. The pattern should follow the format + * groupId:artifactId:version:type:scope:classifier. + * + * @param pattern The pattern to compare the artifact with. + * @param artifact the artifact + * @return true if the artifact matches one of the patterns + * @throws EnforcerRuleException the enforcer rule exception + */ + private static boolean compareDependency( String pattern, Artifact artifact ) + throws EnforcerRuleException + { + + ArtifactMatcher.Pattern am = new Pattern( pattern ); + boolean result; + try + { + result = am.match( artifact ); + } + catch ( InvalidVersionSpecificationException e ) + { + throw new EnforcerRuleException( "Invalid Version Range: ", e ); + } + + return result; + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/DependencyVersionMap.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/DependencyVersionMap.java new file mode 100644 index 000000000..b2807607a --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/DependencyVersionMap.java @@ -0,0 +1,135 @@ +package org.apache.maven.plugins.enforcer.utils; + +/* + * 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. + */ + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.shared.dependency.tree.DependencyNode; +import org.apache.maven.shared.dependency.tree.traversal.DependencyNodeVisitor; + +/** + * @author Brian Fox + * + */ +public class DependencyVersionMap + implements DependencyNodeVisitor +{ + private boolean uniqueVersions; + + private Map> idsToNode; + + public DependencyVersionMap( Log log ) + { + idsToNode = new HashMap<>(); + } + + public void setUniqueVersions( boolean uniqueVersions ) + { + this.uniqueVersions = uniqueVersions; + } + + @Override + public boolean visit( DependencyNode node ) + { + addDependency( node ); + return !containsConflicts( node ); + } + + @Override + public boolean endVisit( DependencyNode node ) + { + return true; + } + + private String constructKey( DependencyNode node ) + { + return constructKey( node.getArtifact() ); + } + + private String constructKey( Artifact artifact ) + { + return artifact.getGroupId() + ":" + artifact.getArtifactId(); + } + + public void addDependency( DependencyNode node ) + { + String key = constructKey( node ); + List nodes = idsToNode.get( key ); + if ( nodes == null ) + { + nodes = new ArrayList<>(); + idsToNode.put( key, nodes ); + } + nodes.add( node ); + } + + private String getVersion( Artifact artifact ) + { + return uniqueVersions ? artifact.getVersion() : artifact.getBaseVersion(); + } + + private boolean containsConflicts( DependencyNode node ) + { + return containsConflicts( node.getArtifact() ); + } + + private boolean containsConflicts( Artifact artifact ) + { + return containsConflicts( idsToNode.get( constructKey( artifact ) ) ); + } + + private boolean containsConflicts( List nodes ) + { + String version = null; + for ( DependencyNode node : nodes ) + { + if ( version == null ) + { + version = getVersion( node.getArtifact() ); + } + else + { + if ( version.compareTo( getVersion( node.getArtifact() ) ) != 0 ) + { + return true; + } + } + } + return false; + } + + public List> getConflictedVersionNumbers() + { + List> output = new ArrayList<>(); + for ( List nodes : idsToNode.values() ) + { + if ( containsConflicts( nodes ) ) + { + output.add( nodes ); + } + } + return output; + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/DistributionManagementCheck.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/DistributionManagementCheck.java new file mode 100644 index 000000000..e96122210 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/DistributionManagementCheck.java @@ -0,0 +1,87 @@ +package org.apache.maven.plugins.enforcer.utils; + +/* + * 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. + */ + +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.model.DistributionManagement; +import org.apache.maven.project.MavenProject; + +/** + * @author Karl Heinz Marbaise khmarbaise@apache.org + */ +public class DistributionManagementCheck +{ + private DistributionManagement distributionManagement; + + public DistributionManagementCheck( MavenProject project ) + { + this.distributionManagement = project.getOriginalModel().getDistributionManagement(); + } + + public void execute( boolean isAllowRepository, boolean isAllowSnapshotRepository, boolean isAllowSite ) + throws EnforcerRuleException + { + if ( hasDistributionManagement() ) + { + if ( !isAllowRepository && hasRepository() ) + { + throw new EnforcerRuleException( "You have defined a repository in distributionManagement." ); + } + else if ( !isAllowSnapshotRepository && hasSnapshotRepository() ) + { + throw new EnforcerRuleException( "You have defined a snapshotRepository in distributionManagement." ); + } + else if ( !isAllowSite && hasSite() ) + { + throw new EnforcerRuleException( "You have defined a site in distributionManagement." ); + } + } + } + + private boolean hasRepository() + { + return getDistributionManagement().getRepository() != null; + } + + public DistributionManagement getDistributionManagement() + { + return distributionManagement; + } + + public void setDistributionManagement( DistributionManagement distributionManagement ) + { + this.distributionManagement = distributionManagement; + } + + private boolean hasSnapshotRepository() + { + return getDistributionManagement().getSnapshotRepository() != null; + } + + private boolean hasSite() + { + return getDistributionManagement().getSite() != null; + } + + private boolean hasDistributionManagement() + { + return getDistributionManagement() != null; + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/EnforcerRuleUtils.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/EnforcerRuleUtils.java new file mode 100644 index 000000000..00b56b4b8 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/EnforcerRuleUtils.java @@ -0,0 +1,152 @@ +package org.apache.maven.plugins.enforcer.utils; + +/* + * 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. + */ + +import java.util.List; + +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.ArtifactResolver; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.ReportPlugin; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; + +/** + * The Class EnforcerRuleUtils. + * + * @author Brian Fox + */ +public class EnforcerRuleUtils +{ + + /** The resolver. */ + ArtifactResolver resolver; + + /** The local. */ + ArtifactRepository local; + + /** The remote repositories. */ + List remoteRepositories; + + /** The log. */ + Log log; + + /** The project. */ + MavenProject project; + + private EnforcerRuleHelper helper; + + /** + * Instantiates a new enforcer rule utils. + * + * @param theFactory unused + * @param theResolver the the resolver + * @param theLocal the the local + * @param theRemoteRepositories the the remote repositories + * @param project the project + * @param theLog the the log + */ + public EnforcerRuleUtils( ArtifactFactory theFactory, ArtifactResolver theResolver, ArtifactRepository theLocal, + List theRemoteRepositories, MavenProject project, Log theLog ) + { + super(); + this.resolver = theResolver; + this.local = theLocal; + this.remoteRepositories = theRemoteRepositories; + this.log = theLog; + this.project = project; + } + + /** + * Instantiates a new enforcer rule utils. + * + * @param helper the helper + */ + public EnforcerRuleUtils( EnforcerRuleHelper helper ) + { + + this.helper = helper; + // get the various expressions out of the + // helper. + try + { + resolver = helper.getComponent( ArtifactResolver.class ); + local = (ArtifactRepository) helper.evaluate( "${localRepository}" ); + project = (MavenProject) helper.evaluate( "${project}" ); + remoteRepositories = project.getRemoteArtifactRepositories(); + } + catch ( ComponentLookupException | ExpressionEvaluationException e ) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + private void resolve( Plugin plugin ) + { + try + { + plugin.setGroupId( (String) helper.evaluate( plugin.getGroupId() ) ); + plugin.setArtifactId( (String) helper.evaluate( plugin.getArtifactId() ) ); + plugin.setVersion( (String) helper.evaluate( plugin.getVersion() ) ); + } + catch ( ExpressionEvaluationException e ) + { + // this should have gone already before + } + } + + private void resolve( ReportPlugin plugin ) + { + try + { + plugin.setGroupId( (String) helper.evaluate( plugin.getGroupId() ) ); + plugin.setArtifactId( (String) helper.evaluate( plugin.getArtifactId() ) ); + plugin.setVersion( (String) helper.evaluate( plugin.getVersion() ) ); + } + catch ( ExpressionEvaluationException e ) + { + // this should have gone already before + } + } + + public List resolvePlugins( List plugins ) + { + for ( Plugin plugin : plugins ) + { + resolve( plugin ); + } + return plugins; + } + + public List resolveReportPlugins( List reportPlugins ) + { + for ( ReportPlugin plugin : reportPlugins ) + { + resolve( plugin ); + } + return reportPlugins; + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/PluginWrapper.java b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/PluginWrapper.java new file mode 100644 index 000000000..30690c475 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/PluginWrapper.java @@ -0,0 +1,123 @@ +package org.apache.maven.plugins.enforcer.utils; + +/* + * 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. + */ + +import java.util.ArrayList; +import java.util.List; + +import org.apache.maven.model.Plugin; +import org.apache.maven.model.ReportPlugin; + +/** + * @author Brian Fox + * + */ +public class PluginWrapper +{ + private String groupId; + + private String artifactId; + + private String version; + + private String source; + + public static List addAll( List plugins, String source ) + { + List results = null; + + if ( !plugins.isEmpty() ) + { + results = new ArrayList<>( plugins.size() ); + for ( Object o : plugins ) + { + if ( o instanceof Plugin ) + { + results.add( new PluginWrapper( (Plugin) o, source ) ); + } + else + { + if ( o instanceof ReportPlugin ) + { + results.add( new PluginWrapper( (ReportPlugin) o, source ) ); + } + } + + } + } + return results; + } + + public PluginWrapper( Plugin plugin, String source ) + { + setGroupId( plugin.getGroupId() ); + setArtifactId( plugin.getArtifactId() ); + setVersion( plugin.getVersion() ); + setSource( source ); + } + + public PluginWrapper( ReportPlugin plugin, String source ) + { + setGroupId( plugin.getGroupId() ); + setArtifactId( plugin.getArtifactId() ); + setVersion( plugin.getVersion() ); + setSource( source ); + } + + public String getGroupId() + { + return groupId; + } + + public void setGroupId( String groupId ) + { + this.groupId = groupId; + } + + public String getArtifactId() + { + return artifactId; + } + + public void setArtifactId( String artifactId ) + { + this.artifactId = artifactId; + } + + public String getVersion() + { + return version; + } + + public void setVersion( String version ) + { + this.version = version; + } + + public String getSource() + { + return source; + } + + public void setSource( String source ) + { + this.source = source; + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/Images.odp b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/Images.odp new file mode 100644 index 000000000..02653cd55 Binary files /dev/null and b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/Images.odp differ diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/alwaysFail.apt.vm b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/alwaysFail.apt.vm new file mode 100644 index 000000000..d00b91861 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/alwaysFail.apt.vm @@ -0,0 +1,61 @@ +~~ 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. + + ------ + Always Fail + ------ + Brian Fox + ------ + August 2008 + ------ + +Always Fail + + This rule will always fail. It is useful for testing proper plugin configuration. + + + Sample Plugin Configuration: + ++---+ + + [...] + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + enforce + + enforce + + + + + + true + + + + + + + [...] + ++---+ diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/alwaysPass.apt.vm b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/alwaysPass.apt.vm new file mode 100644 index 000000000..569ac665b --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/alwaysPass.apt.vm @@ -0,0 +1,61 @@ +~~ 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. + + ------ + AlwaysPass + ------ + Brian Fox + ------ + August 2008 + ------ + +Always Pass + + This rule will always succeed. It is useful for testing proper plugin configuration. + + + Sample Plugin Configuration: + ++---+ + + [...] + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + enforce + + enforce + + + + + + true + + + + + + + [...] + ++---+ diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/banDistributionManagement.apt.vm b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/banDistributionManagement.apt.vm new file mode 100644 index 000000000..6012d7872 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/banDistributionManagement.apt.vm @@ -0,0 +1,174 @@ +~~ 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. + + ------ + Ban DistributionManagement + ------ + Karl-Heinz Marbaise + ------ + June 2014 + ------ + +Ban Distribution Management + + This rule can be used to force the absence of distributionManagement + in your pom files. + + The following parameters are supported by this rule: + + * message - an optional message to the user if the rule fails. + + * allowRepository - You can allow repository entry (default: false). + + * allowSnapshotRepository - you can allow snapshotRepository entry (default: false). + + * allowSite - You can allow site entry (default: false). + + * ignoreParent - You can control if the parent will be checked or not (default: true) (deprecated don't use it anymore). + + [] + + + Sample Plugin Configuration: + ++------+ + + [...] + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + no-distribution-management-at-all + + enforce + + + + + + + + + + + + [...] + ++-------+ + +* Best Practice + + Usually you should define the <> only in a limited number of cases. + If you are in a corporate environment it makes usually only sense to define the <> + in the corporate pom and forbid the usage in any other pom's. Sometimes it makes sense to + allow for example the site repository definition in your other pom's which can be defined by using the + <> rule. For this use case the following has to be defined in your + corporate pom file: + + ++------+ + + [...] + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + no-distribution-management-at-all + + enforce + + + + + true + + + + + + + + + [...] + ++------+ + + +* The Project Types + + If we take a closer look to the possible project structures you will find the following cases where + the green arrow will show our current position. + + * The Project without Parent. + + We have no parent and no modules at all. This could be the situation where we are creating + a corporate pom file or another simple Maven project. So the definition of maven-enforcer-plugin + is within this pom file. + +[images/root.png] Root Project. + + In consequence it does not really make sense to check if the pom contains distributionManagement + entries or not. + + * Project with Parent. + + We have a project with a parent. The parent is likely a kind of a corporate pom file which + contains the definition of maven-enforcer-plugin. So in this case it makes sense to check + if distributionManagement entries are made or not. + + <>: At the moment it is not possible to + check if the parent does not contain the definition of maven-enforcer-plugin which would change + the situation. + +[images/root-with-parent.png] Root project. + + + * Project with Parent and Modules. + + This situation is more or less the same as the one before. So banDistributionManagement rule will check + the distributionManagement entries. + +[images/root-with-parent-and-modules.png] Root project with parent and modules. + + + * Root Project With Modules. + + If we don't have a parent this means the definition of maven-enforcer-plugin + is likely done in the current pom file which means it does not make really sense + to check the distributionManagement. + +[images/root-with-modules.png] Root with Modules. + + + * Module of a Multi Module Build + + In this case we have the scenario that the module m1 has a parent <> which could contain + the definition of the maven-enforcer-plugin or the <> of which in consequence means to check the + distributionManagement entries. + +[images/module.png] Root with Modules. + + + [] diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/banDuplicatePomDependencyVersions.apt.vm b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/banDuplicatePomDependencyVersions.apt.vm new file mode 100644 index 000000000..0ae6ba1de --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/banDuplicatePomDependencyVersions.apt.vm @@ -0,0 +1,67 @@ +~~ 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. + + ------ + Ban Duplicate Pom Dependency Versions + ------ + Guillaume Boue + ------ + November 2016 + ------ + +Ban Duplicate Pom Dependency Versions + + This rule checks that there are no duplicate dependencies declared in the POM of the project. + Duplicate dependencies are dependencies which have the same group id, artifact id, type and classifier. + + The following parameters are supported by this rule: + + * message - an optional supplemental message to the user if the rule fails. + + [] + + + Sample Plugin Configuration: + ++------+ + + [...] + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + no-duplicate-declared-dependencies + + enforce + + + + + + + + + + + + [...] + ++-------+ diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/banTransitiveDependencies.apt.vm b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/banTransitiveDependencies.apt.vm new file mode 100644 index 000000000..95265ca62 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/banTransitiveDependencies.apt.vm @@ -0,0 +1,89 @@ +~~ 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. + + ------ + Ban Transitive Dependencies + ------ + ------ + August 2012 + ------ + +Ban Transitive Dependencies + + This rule bans all transitive dependencies. + + + The following parameters are supported by this rule: + + * excludes - specify the dependencies that will be ignored.\ + This can be a list of artifacts in the format + groupId[:artifactId[:version[:type[:scope[:classifier]]]]] . + Wildcard '*' can be used to in place of specific section (e.g. group:*:1.0 will match both 'group:artifact:1.0' and 'group:anotherArtifact:1.0') + Version is a string representing standard maven version range. Empty patterns will be ignored. + + * includes - specify the dependencies that will be checked.\ + These are exceptions to excludes intended for more convenient configuration. This can be a list of artifacts in the format + groupId[:artifactId[:version[:type[:scope[:classifier]]]]] as above. + + * message - an optional message to the user if the rule fails. Will replace generated report message. + + [] + + + Sample Plugin Configuration: + ++---+ + + [...] + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + enforce-banned-dependencies + + enforce + + + + + + + org.apache.maven:ignoredArtifact + *:anotherIgnoredArtifact + + + + org.apache.maven:ignoredArtifact:[1.0] + + + + + + + + + + [...] + ++---+ \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/bannedDependencies.apt.vm b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/bannedDependencies.apt.vm new file mode 100644 index 000000000..c73256933 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/bannedDependencies.apt.vm @@ -0,0 +1,142 @@ +~~ 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. + + ------ + Banned Dependencies + ------ + Brian Fox + ------ + November 2007 + ------ + +Banned Dependencies + + This rule checks the dependencies and fails if any of the matching excludes are found. + + + The following parameters are supported by this rule: + + * searchTransitive - if transitive dependencies should be checked. Default is true. + + * excludes - a list of artifacts to ban. The format is groupId[:artifactId][:version][:type][:scope][:classifier] where artifactId, version, type, scope and classifier are optional. Wildcards may be used to replace an entire or just parts of a section. + Examples: + + * org.apache.maven + + * org.apache.maven:badArtifact + + * org.apache.maven:artifact:badVersion + + * org.apache.maven:*:1.2 (exclude version 1.2 and above, equivalent to [1.2,) ) + + * org.apache.maven:*:[1.2] (explicit exclude of version 1.2) + + * org.apache.maven:*:*:jar:test + + * *:*:*:jar:compile:tests + + * org.apache.*:maven-*:* + + [] + + * includes - a list of artifacts to include. These are exceptions to the excludes. It is meant to allow wide exclusion rules with wildcards and fine tune using includes. If nothing has been excluded, then the includes have no effect. In otherwords, includes only subtract from artifacts that matched an exclude rule. + + For example, to ban all xerces except xerces-api you would exclude "xerces" (groupId) and include "xerces:xerces-api" + + * message - an optional message to the user if the rule fails. + + [] + + + Sample Plugin Configuration: + ++---+ + + [...] + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + enforce-banned-dependencies + + enforce + + + + + + org.apache.maven + org.apache.maven:badArtifact + *:badArtifact + + + + org.apache.maven:badArtifact:1.0 + + + + true + + + + + + + [...] + ++---+ + + Example plugin configuration which ignores transitive dependencies: + ++---+ + + [...] + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + enforce-banned-dependencies + + enforce + + + + + + commons-lang:commons-lang + + false + + + true + + + + + + + [...] + ++---+ diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/bannedPlugins.apt.vm b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/bannedPlugins.apt.vm new file mode 100644 index 000000000..8c91ca647 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/bannedPlugins.apt.vm @@ -0,0 +1,87 @@ +~~ 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. + + ------ + Banned Plugins + ------ + Paul Gier + ------ + November 2012 + ------ + +Banned Plugins + + This rule checks the set of plugins used during the build and enforces that specific excluded plugins are not used. + + The following parameters are supported by this rule: + + * excludes - a list of plugin artifacts to ban. The format is groupId[:artifactId][:version] where artifactId and version are optional. Wildcards may be used to replace an entire section. + Examples: + + * org.apache.maven + + * org.apache.maven:bad-plugin + + * org.apache.maven:my-plugin:badVersion + + * org.apache.maven:*:1.2 + + [] + + * includes - a list of plugin artifacts to include. These are exceptions to the excludes. It is meant to allow wide exclusion rules with wildcards and fine tune using includes. + If nothing has been excluded, then the includes have no effect. In otherwords, includes only subtract from artifacts that matched an exclude rule. + + * message - an optional message to the user if the rule fails. + + [] + + + Sample Plugin Configuration: + ++---+ + + [...] + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + enforce-banned-dependencies + + enforce + + + + + + org.codehaus.mojo:build-helper-maven-plugin + + + + true + + + + + + + [...] + ++---+ diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/bannedRepositories.apt.vm b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/bannedRepositories.apt.vm new file mode 100644 index 000000000..88f717a14 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/bannedRepositories.apt.vm @@ -0,0 +1,119 @@ +~~ 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. + + ------ + Banned Specified Repositories + ------ + Simon Wang + ------ + June 2014 + ------ + +Banned Specified Repositories + + This rule checks whether this maven session (defined in pom files or even settings.xml) include specified banned repository. + +* What's difference from "requireNoRepositories"? + + The purpose for "requireNoRepositories" is: Detect whether pom and pom’s parents contains repositories definition. That guide users to use correct convention (not define repositories in pom files). So it only analyze current pom and its parent pom files. + + But “BannedRepositories” is different purpose, it’s just like “BannedDependencies”. It will detect banned repositories from maven session context instead of only pom.xml and parents. It's trying to avoid misuse incorrect repositories. It will detect banned repositories from current maven session context. + +* Support Parameters + + * banRepositories - Specify banned non-plugin repositories. This is a black list of http/https url patterns. + + * banPluginRepositories - Specify banned plugin repositories. This is a black list of http/https url patterns. + + * allowedRepositories - Specify explicitly allowed non-plugin repositories. This is a white list of http/https url patterns. + + * allowedPluginRepositories - Specify explicitly allowed plugin repositories. This is a white list of http/https url patternes. + +* Sample Configuration + + For example, one company want to limit repositories usage. But different developers might use different settings.xml. + Even their projects' pom defined different repostories too. + For this case, could leverage this enforcer rule to banned specified repositories or even use allowedRepositories/allowedPluginRepositories to banned others unexpected repositories. + + Ex. http://repo1/xyz is the repository that want to be banned. + http://repo2/xyz is the repository that want to use now. + + Sample Plugin Configuration: + ++---+ + + [...] + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + enforce-banned-repositories + + enforce + + + + + + http://repo1/* + + + http://repo1/* + + + + + + + + + + + + + [...] + ++---+ + +* Worth to Note + + * http/https url patterns support wildcard "*" + + * This rule will detect banned repositories on maven session itself istead of pom or settings, so if users defined "mirrorOf" in settings.xml, even defined banned repositories in pom.xml, it won't be detected. + ++---+ + + + nexus + * + http://.../nexus/.. + + ++---+ diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/dependencyConvergence.apt.vm b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/dependencyConvergence.apt.vm new file mode 100644 index 000000000..55a9b02e8 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/dependencyConvergence.apt.vm @@ -0,0 +1,130 @@ + ~~ 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. + + ----- + Dependency Convergence + ----- + ----- + 2008-09-13 + ----- + +Dependency Convergence + + This rule requires that dependency version numbers converge. If a project has two dependencies, A and B, both depending on the same artifact, C, this rule will fail the build if A depends on a different version of C than the version of C depended on by B. + + Here is a concrete example. + + This will cause a build to fail. + ++----------------------------------------------------------------------------------- + + + + org.slf4j + slf4j-jdk14 + 1.6.1 + + + org.slf4j + slf4j-nop + 1.6.0 + + ++----------------------------------------------------------------------------------- + + With this being logged during compilation + ++----------------------------------------------------------------------------------- +Dependency convergence error for org.slf4j:slf4j-api1.6.1 paths to dependency are: + +[ERROR] +Dependency convergence error for org.slf4j:slf4j-api:1.6.1 paths to dependency are: ++-org.myorg:my-project:1.0.0-SNAPSHOT + +-org.slf4j:slf4j-jdk14:1.6.1 + +-org.slf4j:slf4j-api:1.6.1 +and ++-org.myorg:my-project:1.0.0-SNAPSHOT + +-org.slf4j:slf4j-nop:1.6.0 + +-org.slf4j:slf4j-api:1.6.0 ++----------------------------------------------------------------------------------- + + And this will succeed. + ++----------------------------------------------------------------------------------- + + org.slf4j + slf4j-jdk14 + 1.6.1 + + + org.slf4j + slf4j-nop + 1.6.0 + + + org.slf4j + slf4j-api + + + ++----------------------------------------------------------------------------------- + + + Here is how a project should be setup to use this rule + ++----------------------------------------------------------------------------------- + + ... + + + ... + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + enforce + + + + + + + enforce + + + + + ... + + + ... + ++----------------------------------------------------------------------------------- + +* Timestamped version + + By default the non-unique versions are matched, which means the <<>> instead of the timestamped versions. + If you want to use the unique versions of the dependencies, you can set its property to <<>>. + ++--------------------------------------------- + + true + ++--------------------------------------------- + diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/evaluateBeanshell.apt.vm b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/evaluateBeanshell.apt.vm new file mode 100644 index 000000000..2efabb5ab --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/evaluateBeanshell.apt.vm @@ -0,0 +1,80 @@ +~~ 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. + + ------ + Beanshell + ------ + Brian Fox + ------ + June 2007 + ------ + +Beanshell + + This rule can execute a beanshell script and evaluate the result. + + + The following parameters are supported by this rule: + + * condition - the beanshell statement to evaluate. + + * message - an optional message to the user if the rule fails. + + [] + + + Sample Plugin Configuration: + ++---+ + + [...] + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + enforce-beanshell + + enforce + + + + + \${project.artifactId} == foo + + + true + + + + + + + [...] + ++---+ + + The condition can be a complex script or a simple expression. As long as it results in True, the rule will succeed. This means code can be executed as long as the last line results in true. + ++---+ + + for (int i = 0;i!=10;i++){print ("Hello World "+i);};1==1 + ++---+ \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/index.apt b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/index.apt new file mode 100644 index 000000000..fe43cc989 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/index.apt @@ -0,0 +1,92 @@ +~~ 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. + + ------ + Built-In Rules + ------ + Brian Fox + ------ + 2015-01-27 + ------ + +Built-In Rules + + The following built-in rules ship along with the enforcer plugin: + + * {{{./alwaysFail.html}alwaysFail}} - Always fail... used to test plugin configuration. + + * {{{./alwaysPass.html}alwaysPass}} - Always passes... used to test plugin configuration. + + * {{{./banDistributionManagement.html}banDistributionManagement}} - enforces that project doesn't have distributionManagement. + + * {{{./banDuplicatePomDependencyVersions.html}banDuplicatePomDependencyVersions}} - enforces that the project doesn't have duplicate declared dependencies. + + * {{{./bannedDependencies.html}bannedDependencies}} - enforces that excluded dependencies aren't included. + + * {{{./bannedPlugins.html}bannedPlugins}} - enforces that specific plugins aren't included in the build. + + * {{{./bannedRepositories.html}bannedRepositories}} - enforces to not include banned repositories. + + * {{{./banTransitiveDependencies.html}banTransitiveDependencies}} - enforces that project doesn't have transitive dependencies. + + * {{{./dependencyConvergence.html}dependencyConvergence}} - ensure all dependencies converge to the same version. + + * {{{./evaluateBeanshell.html}evaluateBeanshell}} - evaluates a beanshell script. + + * {{{./reactorModuleConvergence.html}reactorModuleConvergence}} - enforces that a multi module build follows best practice. + + * {{{./requireActiveProfile.html}requireActiveProfile}} - enforces one or more active profiles. + + * {{{./requireEnvironmentVariable.html}requireEnvironmentVariable}} - enforces the existence of an environment variable + + * {{{./requireFileChecksum.html}requireFileChecksum}} - enforces that the specified file has a certain checksum. + + * {{{./requireFilesDontExist.html}requireFilesDontExist}} - enforces that the list of files does not exist. + + * {{{./requireFilesExist.html}requireFilesExist}} - enforces that the list of files does exist. + + * {{{./requireFilesSize.html}requireFilesSize}} - enforces that the list of files exists and is within a certain size range. + + * {{{./requireJavaVersion.html}requireJavaVersion}} - enforces the JDK version. + + * {{{./requireMavenVersion.html}requireMavenVersion}} - enforces the Maven version. + + * {{{./requireNoRepositories.html}requireNoRepositories}} - enforces to not include repositories. + + * {{{./requireOS.html}requireOS}} - enforces the OS / CPU Architecture. + + * {{{./requirePluginVersions.html}requirePluginVersions}} - enforces that all plugins have a specified version. + + * {{{./requirePrerequisite.html}requirePrerequisite}} - enforces that prerequisites have been specified. + + * {{{./requireProfileIdsExist.html}requireProfileIdsExist}} - enforces the existence of profiles specified on the commandline. + + * {{{./requireProperty.html}requireProperty}} - enforces the existence and values of properties. + + * {{{./requireReleaseDeps.html}requireReleaseDeps}} - enforces that no snapshots are included as dependencies. + + * {{{./requireReleaseVersion.html}requireReleaseVersion}} - enforces that the artifact is not a snapshot. + + * {{{./requireSnapshotVersion.html}requireSnapshotVersion}} - enforces that the artifact is not a release. + + * {{{./requireSameVersions.html}requireSameVersions}} - enforces that specific dependencies and/or plugins have the same version. + + * {{{./requireUpperBoundDeps.html}requireUpperBoundDeps}} - ensures that every (transitive) dependency is resolved to its specified version or higher. + + [] + + You may also create and inject your own custom rules by following the {{{http://maven.apache.org/enforcer/enforcer-api/writing-a-custom-rule.html}maven-enforcer-rule-api}} instructions. diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/noSnapshots.apt.vm b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/noSnapshots.apt.vm new file mode 100644 index 000000000..8465b5605 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/noSnapshots.apt.vm @@ -0,0 +1,72 @@ +~~ 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. + + ------ + Require Release Dependencies + ------ + Brian Fox + ------ + November 2007 + ------ + +Require Release Dependencies + + This rule checks the dependencies and fails if any snapshots are found. + + + The following parameters are supported by this rule: + + * searchTransitive - if transitive dependencies should be checked. + + * message - an optional message to the user if the rule fails. + + [] + + + Sample Plugin Configuration: + ++---+ + + [...] + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + enforce-no-snapshots + + enforce + + + + + No Snapshots Allowed! + + + true + + + + + + + [...] + ++---+ \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/reactorModuleConvergence.apt.vm b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/reactorModuleConvergence.apt.vm new file mode 100644 index 000000000..931866727 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/reactorModuleConvergence.apt.vm @@ -0,0 +1,257 @@ +~~ 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. + + ------ + Reactor Module Convergence + ------ + Karl-Heinz Marbaise + ------ + March 2014 + ------ + +Reactor Module Convergence + + This rule checks that the versions within the reactor are consistent furthermore + it will check that every module within the project contains a parent and that the + parent is part of the reactor build. Furthermore it will be checked if dependencies + are intermodule dependencies that they using the same version as given by the reactor. + + The following parameters are supported by this rule: + + * message - an optional supplemental message to the user if the rule fails. + + * ignoreModuleDependencies - Ignore module dependencies which references modules within the + the reactor (default: false). + + Note: The current state does not correctly handle a situation like this {{mvn -pl subproject validate}}. + This will be handled correctly with the next major release (2.X) of enforcer. + + [] + + + Sample Plugin Configuration: + ++---+ + + [...] + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + enforce-no-snapshots + + enforce + + + + + The reactor is not valid + true + + + true + + + + + + + [...] + ++---+ + + There are different situations within a multi module build which can lead to problems + (for example not working with maven-release-plugin etc.). + This rule is intended to prevent such problems. + + Let us assume we have the following (simple) project structure for a multi module setup. + ++----- + root (pom.xml) + +--- module1 (pom.xml) + +--- module2 (pom.xml) ++----- + + The root <> looks like this: + ++----- + com.mycompany.project + parent + 1.0-SNAPSHOT + (..) ++----- + + The best practice in Maven is that all childs inherit the version from their parent + and don't define a new version which looks like this: + ++----- + + ... + ... + 1.0-SNAPSHOT + + + module1 + (..) ++----- + + But sometimes people mistaken things or violate the best-practice which + looks like this: + ++----- + + ... + ... + 1.0-SNAPSHOT + + + module1 + 1.1-SNAPSHOT ++----- + + By using this rule you would get a message during the build + with the following resulting output: + ++----- +[WARNING] Rule 0: org.apache.maven.plugins.enforcer.ReactorModuleConvergence failed with message: +The reactor contains different versions. + --> com.mycompany.project:myproject:pom:1.1-SNAPSHOT ++----- + + The next which happens is that the parent in a reactor is sometimes + the wrong one like the following situation: + ++----- + + ... + ... + 1.1-SNAPSHOT + + + module1 + 1.0-SNAPSHOT + (..) ++----- + + This will prompted by the following message: + ++----- +[WARNING] Rule 0: org.apache.maven.plugins.enforcer.ReactorModuleConvergence failed with message: +Reactor modules have parents which contain a wrong version. + --> com.mycompany.project:myproject:pom:1.1-SNAPSHOT parent:com.mycompany.project:myproject:pom:1.0-SNAPSHOT ++----- + + If you have only changed a parent by accident with the wrong version + like this: + ++----- + + ... + ... + 1.1-SNAPSHOT + + + module1 + (..) ++----- + + you will get the same message as above: + ++----- +[WARNING] Rule 0: org.apache.maven.plugins.enforcer.ReactorModuleConvergence failed with message: +The reactor contains different versions. + --> com.mycompany.project:myproject:pom:1.1-SNAPSHOT ++----- + + An other things which happens that simply the parent will be forgotten which + produces a message like this: + ++---- +[WARNING] Rule 0: org.apache.maven.plugins.enforcer.ReactorModuleConvergence failed with message: +Reactor contains modules without parents. + module: com.mycompany.project:myproject:pom:1.2-SNAPSHOT ++---- + + In larger mutli-module builds it happens also that the defined parent is given + but does not belong to the reactor like this: + ++----- + + org.apache.enforcer + something-different + 1.1 + + + module1 + (..) ++----- + + Usually already the Maven warning like this should be paid attention to: + ++----- +[WARNING] +[WARNING] Some problems were encountered while building the effective model for org.apache.enforcer:pom:1.0.4-SNAPSHOT +[WARNING] 'parent.relativePath' points at org.apache.enforcer:something-different instead of org.apache.enforcer:something-different, please verify your project structure @ line 7, column 11 +[WARNING] ++----- + + but this will oversight often. So the enforcer rule will break simply + such mail formed build via the message (This required that the parent + has the same version as the rest of the build which happens): + ++----- +[WARNING] Rule 0: org.apache.maven.plugins.enforcer.ReactorModuleConvergence failed with message: +Module parents have been found which could not be found in the reactor. + module: org.apache.enforcer:something-different:pom:1.0.4-SNAPSHOT ++----- + + + An other case which happens (for example by merging from a branch into trunk/master) + is that an intermodule dependency contains the wrong version like this: + ++----- + + ... + ... + 1.2-SNAPSHOT + + + module1 + + + + com.mycompany.project + myproject + 1.1 + + (..) + + (..) ++----- + + This will result in the following message: + ++----- +[WARNING] Rule 0: org.apache.maven.plugins.enforcer.ReactorModuleConvergence failed with message: +Reactor modules contains dependencies which do not reference the reactor. + module: com.mycompany.project:myproject-x:jar:1.2-SNAPSHOT + dependency: com.mycompany.project:myproject:1.1 ++----- diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireActiveProfile.apt.vm b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireActiveProfile.apt.vm new file mode 100644 index 000000000..f63922397 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireActiveProfile.apt.vm @@ -0,0 +1,109 @@ +~~ 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. + + ------ + Require Active Profile + ------ + Karl-Heinz Marbaise + ------ + December 2013 + ------ + +Require Active Profile + + This rule checks that a specified list of profiles is activated. + + + The following parameters are supported by this rule: + + * message - an optional message to the user if the rule fails. + + * profiles - A comma separated list of profile to check. + + * all - Checks if all given profiles are active. Default is true. + + [] + + + Sample Plugin Configuration: + ++---+ + + [...] + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + enforce-all-profiles-are-activated + + enforce + + + + + first,second + + + true + + + + + + + [...] + ++---+ + + Sample Plugin Configuration to check if one of the given profiles is active: + ++---+ + + [...] + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + enforce-first-or-second-profile-is-active + + enforce + + + + + first,second + false + + + true + + + + + + + [...] + ++---+ diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireEnvironmentVariable.apt.vm b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireEnvironmentVariable.apt.vm new file mode 100644 index 000000000..1ec072ae7 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireEnvironmentVariable.apt.vm @@ -0,0 +1,72 @@ +~~ 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. + + ------ + Require Environment Variable + ------ + Karl-Heinz Marbaise + ------ + December 2013 + ------ + +Require Environment Variable + + This rule checks that a specified environment variable is set. + + + The following parameters are supported by this rule: + + * message - an optional message to the user if the rule fails. + + * variableName - The name of the environment variable to be checked for. + + [] + + + Sample Plugin Configuration: + ++---+ + + [...] + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + enforce-environment-variable-is-set + + enforce + + + + + the_name_you_wish_to_be_checked + + + true + + + + + + + [...] + ++---+ diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireFileChecksum.apt.vm b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireFileChecksum.apt.vm new file mode 100644 index 000000000..c4606cda1 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireFileChecksum.apt.vm @@ -0,0 +1,98 @@ +~~ 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. + + ------ + Require Files Checksum + ------ + Edward Samson, Lyubomyr Shaydariv + ------ + February 2016 + ------ + +Require Files Checksum + + This rule checks that the specified file has an given checksum. + + + The following parameters are supported by this rule: + + * message - an optional message to the user if the rule fails. + + * file - A file to check. + + * checksum - Expected file checksum. + + * type - Type of hashing algorithm to calculate the checksum. May be one of "md5", "sha1", "sha256", "sha384", or "sha512". + + [] + + + Sample Plugin Configuration: + ++---+ + + [...] + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + enforce-checksum + + enforce + + + + + ${project.build.outputDirectory}/foo.txt + d41d8cd98f00b204e9800998ecf8427e + md5 + + + ${project.build.outputDirectory}/bar.txt + da39a3ee5e6b4b0d3255bfef95601890afd80709 + sha1 + + + ${project.build.outputDirectory}/baz.txt + e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + sha256 + + + ${project.build.outputDirectory}/qux.txt + 38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b + sha384 + + + ${project.build.outputDirectory}/quux.txt + cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e + sha512 + + + true + + + + + + + [...] + ++---+ diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireFilesDontExist.apt.vm b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireFilesDontExist.apt.vm new file mode 100644 index 000000000..4172ed43b --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireFilesDontExist.apt.vm @@ -0,0 +1,77 @@ +~~ 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. + + ------ + Require Files Dont Exist + ------ + Brian Fox + ------ + August 2008 + ------ + +Require Files Don't Exist + + This rule checks that the specified list of files do not exist. + + + The following parameters are supported by this rule: + + * message - an optional message to the user if the rule fails. + + * files - A list of files to check. + + * allowNulls - If null files should be allowed. If allowed, they will be treated as if they do not exist. Default is false. + + [] + + + Sample Plugin Configuration: + ++---+ + + [...] + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + enforce-dont-exist + + enforce + + + + + + \${project.build.outputDirectory}/foo.txt + \${project.build.outputDirectory}/foo2.txt + + + + true + + + + + + + [...] + ++---+ diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireFilesExist.apt.vm b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireFilesExist.apt.vm new file mode 100644 index 000000000..820ae9da1 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireFilesExist.apt.vm @@ -0,0 +1,77 @@ +~~ 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. + + ------ + Require Files Exist + ------ + Brian Fox + ------ + August 2008 + ------ + +Require Files Exist + + This rule checks that the specified list of files exist. + + + The following parameters are supported by this rule: + + * message - an optional message to the user if the rule fails. + + * files - A list of files to check. + + * allowNulls - If null files should be allowed. If allowed, they will be treated as if they do exist. Default is false. + + [] + + + Sample Plugin Configuration: + ++---+ + + [...] + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + enforce-files-exist + + enforce + + + + + + \${project.build.outputDirectory}/foo.txt + \${project.build.outputDirectory}/foo2.txt + + + + true + + + + + + + [...] + ++---+ diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireFilesSize.apt.vm b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireFilesSize.apt.vm new file mode 100644 index 000000000..f5ff81d42 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireFilesSize.apt.vm @@ -0,0 +1,83 @@ +~~ 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. + + ------ + Require File Size + ------ + Brian Fox + ------ + August 2008 + ------ + +Require File Size + + This rule checks that the specified list of files exist and are within the specified size range. + + + The following parameters are supported by this rule: + + * message - an optional message to the user if the rule fails. + + * files - A list of files to check. If this list is empty, the main project artifact will be checked. + + * maxsize - maximum size in bytes for this file + + * minsize - minimum size in bytes for this file + + * allowNulls - If null files should be allowed. If allowed, they will be treated as if they do exist. Default is false. + + [] + + + Sample Plugin Configuration: + ++---+ + + [...] + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + enforce-file-size + + enforce + + + + + 10000 + 90 + + \${project.build.outputDirectory}/foo.txt + \${project.build.outputDirectory}/foo2.txt + + + + true + + + + + + + [...] + ++---+ diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireJavaVersion.apt.vm b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireJavaVersion.apt.vm new file mode 100644 index 000000000..4022ccae4 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireJavaVersion.apt.vm @@ -0,0 +1,95 @@ +~~ 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. + + ------ + Require Java Version + ------ + Brian Fox + ------ + June 2007 + ------ + +Require Java Version + + This rule enforces certain Java JDK versions. The rule uses the {{{./versionRanges.html}Enforcer version range syntax}} to define allowed versions. + + The following parameters are supported by this rule: + + * message - an optional message to the user if the rule fails. + + * {{{../apidocs/org/apache/maven/plugins/enforcer/AbstractVersionEnforcer.html#version}version}} - {{{./versionRanges.html}range}} of allowed JDKs. + + [] + + The JDK version is retrieved and the following processing occurs before being checked: + + [[1]] Drop all non-numeric characters preceeding the first number. (build 1.5.0_07-b03 becomes 1.5.0_07-b03) + + [[2]] Replace all '_' and '-' with '.' (1.5.0_07-b03 becomes 1.5.0.07.b03) + + [[3]] Remove all non digit characters "[^0-9] and convert each section using Integer.parseInt() (1.5.0_07-b03 becomes 1.5.0.7.3) + + [[3]] Split the string on '.' and take the first 3 sections, separated by '.' and add '-' followed by the fourth section (1.5.0.7.3 becomes 1.5.0-7) + + [] + + This preprocessing normalizes various JDK version strings into a standard x.y.z-b version number. Your required range should therefore use the x.y.z-b format for comparison. + There is an easy way to see how your current JDK string will be normalized: + ++---+ +mvn enforcer:display-info +... +[enforcer:display-info] +Maven Version: 2.0.8 +JDK Version: 1.5.0_11 normalized as: 1.5.0-11 +OS Info: Arch: x86 Family: windows Name: windows xp Version: 5.1 ++---+ + + Sample Plugin Configuration: + ++---+ + + [...] + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + enforce-java + + enforce + + + + + 1.6.0 + + + + + + + + + [...] + ++---+ + + If you would like to enforce a certain vendor string for the JDK, you would use the {{{./requireProperty.html}RequireProperty}} rule, and check the java.vendor property with a regular expression. diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireMavenVersion.apt.vm b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireMavenVersion.apt.vm new file mode 100644 index 000000000..268f2bd48 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireMavenVersion.apt.vm @@ -0,0 +1,69 @@ +~~ 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. + + ------ + Require Maven Version + ------ + Brian Fox + ------ + June 2007 + ------ + +Require Maven Version + + This rule enforces certain Maven versions. The rule uses the {{{./versionRanges.html}Enforcer version range syntax}} to define allowed versions. + + The following parameters are supported by this rule: + + * message - an optional message to the user if the rule fails. + + * {{{../enforcer-rules/apidocs/org/apache/maven/plugins/enforcer/AbstractVersionEnforcer.html#version}version}} - {{{./versionRanges.html}range}} of allowed Maven versions. + + [] + + Sample Plugin Configuration: + ++---+ + + [...] + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + enforce-maven + + enforce + + + + + 3.0 + + + + + + + + + [...] + ++---+ diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireNoRepositories.apt.vm b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireNoRepositories.apt.vm new file mode 100644 index 000000000..351e401cf --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireNoRepositories.apt.vm @@ -0,0 +1,77 @@ +~~ 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. + + ------ + Require No Repositories + ------ + Brian Fox + ------ + Novemer 2007 + ------ + +Require No Repositories + + This rule checks that this pom or its parents don't define a repository. + + The following parameters are supported by this rule: + + * banRepositories - Whether to ban non-plugin repositories. By default they are banned (true). + + * banPluginRepositories - Whether to ban plugin repositories. By default they are banned (true). + + * allowedRepositories - Specify explicitly allowed non-plugin repositories. This is a list of ids. + + * allowedPluginRepositories - Specify explicitly allowed plugin repositories. This is a list of ids. + + * allowSnapshotRepositories - Whether to allow repositories which only resolve snapshots. By default they are banned (false). + + * allowSnapshotPluginRepositories - Whether to allow plugin repositories which only resolve snapshots. By default they are banned (false). + + [] + + Sample Plugin Configuration (showing some defaults, defaults can be skipped): + ++---+ + + [...] + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + enforce-no-repositories + + enforce + + + + + Best Practice is to never define repositories in pom.xml (use a repository manager instead) + + + + + + + + + [...] + ++---+ \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireOS.apt.vm b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireOS.apt.vm new file mode 100644 index 000000000..49024f5eb --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireOS.apt.vm @@ -0,0 +1,143 @@ +~~ 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. + + ------ + Require OS Version + ------ + Brian Fox + ------ + June 2007 + ------ + +Require OS Version + + This rule can enforce certain values about the Operating System and processor architecture. + The values and code used to determine if an OS is allowed are exactly the same as the OS Profile activation in Maven. + + + The following parameters are supported by this rule: + + * message - an optional message to the user if the rule fails. + + * {{{../apidocs/org/apache/maven/plugins/enforcer/RequireOS.html#arch}arch}} - the cpu architecture. + + * {{{../apidocs/org/apache/maven/plugins/enforcer/RequireOS.html#family}family}} - the family of OS. Possible families are: + + * dos + + * mac + + * netware + + * os/2 + + * tandem + + * unix + + * windows + + * win9x + + * z/os + + * os/400 + + [] + + + * {{{../apidocs/org/apache/maven/plugins/enforcer/RequireOS.html#name}name}} - the name of the OS. + + * {{{../apidocs/org/apache/maven/plugins/enforcer/RequireOS.html#version}version}} - the version of the OS. + + * {{{../apidocs/org/apache/maven/plugins/enforcer/RequireOS.html#display}display}} - flag to display the detected OS informatin. + + [] + + + Family is calculated based on testing against the name string retreived from the JDK. The name, arch and version values are retreived from the JDK using the following code: + ++---+ + public static final String OS_NAME = System.getProperty( "os.name" ).toLowerCase( Locale.US ); + + public static final String OS_ARCH = System.getProperty( "os.arch" ).toLowerCase( Locale.US ); + + public static final String OS_VERSION = System.getProperty( "os.version" ).toLowerCase( Locale.US ); ++---+ + + Possible arch, name, and version values can be found here: + + * {{{http://lopica.sourceforge.net/os.html}lopica.sourceforge.net}} + + * {{{http://tolstoy.com/samizdat/sysprops.html}Sysprops}} + + [] + + The various options are considered to be "and'd" together but any number can be specified. + (ie family = windows means windows, but family = windows and arch = x86 means only windows on x86 processors) + + Any parameter may also be used in the negative by prepending a "!" in front of it. For example !dos means everything but dos. (who uses dos anyway?) + + Since the various names, versions and architecture values cannot be listed exhaustively, there is an easy way to display the + information for the current system: + ++---+ +mvn enforcer:display-info +... +[enforcer:display-info] +Maven Version: 2.0.6 +JDK Version: 1.5.0_11 normalized as: 1.5.0 +OS Info: Arch: x86 Family: windows Name: windows xp Version: 5.1 ++---+ + + Sample Plugin Configuration: + ++---+ + + [...] + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + enforce-os + + enforce + + + + + Windows XP + windows + x86 + 5.1.2600 + + + true + + + + + + + [...] + ++---+ + diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requirePluginVersions.apt.vm b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requirePluginVersions.apt.vm new file mode 100644 index 000000000..e654b71d1 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requirePluginVersions.apt.vm @@ -0,0 +1,94 @@ +~~ 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. + + ------ + Require Plugin Versions + ------ + Brian Fox + ------ + November 2009 + ------ + +Require Plugin Versions + + This rule enforces that all plugins have a version defined, either in the plugin or pluginManagement section of the pom or a parent pom. + + The following parameters are supported by this rule: + + * message - an optional message to the user if the rule fails. + + * banLatest - disallow any use of "LATEST" as a version for any plugin. Default = true. + + * banRelease - disallow any use of "RELEASE" as a version for any plugin. Default = true. + + * banSnapshots - disallow any use of SNAPSHOT plugins. Default = true. + + * banTimestamps - disallow any use of snapshot plugins with timestamp version (only enabled when banSnapshots is true). Default = true. + + * phases - The comma separated list of phases that should be used to find + lifecycle plugin bindings. The default value is "clean,deploy,site". + + * additionalPlugins - A list of additional plugins to enforce have versions. These + are plugins that may not be in the poms but are used anyway, like help, eclipse etc. + The plugins should be specified in the form: group:artifactId. + + * unCheckedPluginList - A comma separated list of plugins to skip version checking. Ie allow no version, or snapshots, etc. The plugins should be specified in the form: group:artifactId. + + + [] + + Sample Plugin Configuration (showing some defaults, defaults can be skipped): + ++---+ + + [...] + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + enforce-plugin-versions + + enforce + + + + + Best Practice is to always define plugin versions! + true + true + true + clean,deploy,site + + org.apache.maven.plugins:maven-eclipse-plugin + org.apache.maven.plugins:maven-reactor-plugin + + org.apache.maven.plugins:maven-enforcer-plugin,org.apache.maven.plugins:maven-idea-plugin + + + + + + + + + [...] + ++---+ \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requirePrerequisite.apt.vm b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requirePrerequisite.apt.vm new file mode 100644 index 000000000..8a079874f --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requirePrerequisite.apt.vm @@ -0,0 +1,74 @@ + ~~ 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. + + ----- + Require Same Version + ----- + Robert Scholte + ----- + 2013-06-16 + ----- + + Require Prerequisites + + This rule enforces that the prerequisite is specified since it is not inherited from its parent. + Defining the prerequisites is especially useful for plugins to enforce at least a certain version of Maven. + + + The following parameters are supported by this rule: + + * mavenVersion - an optional value contain a versionrange or the version at least required. + + [] + + + Sample Plugin Configuration: + ++---+ + + [...] + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + enforce-prerequisites + + enforce + + + + + 2.2.1 + + + + [2.2.1,) + + + + + + + + + [...] + ++---+ diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireProfileIdsExist.apt.vm b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireProfileIdsExist.apt.vm new file mode 100644 index 000000000..49e84ac7e --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireProfileIdsExist.apt.vm @@ -0,0 +1,61 @@ + ~~ 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. + + ----- + Require Existence of Profiles Specified on the Commandline + ----- + ----- + 2017-09-25 + ----- + + When running Maven with one or more unknown profile ids, Maven will give you a warning. + This rule will actually break the build for that reason. + + Here is how a project should be setup to use this rule + +----------------------------------------------------------------------------------- + + ... + + + ... + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + enforce + + + + + + + enforce + + + + + ... + + + ... + +----------------------------------------------------------------------------------- + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireProperty.apt.vm b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireProperty.apt.vm new file mode 100644 index 000000000..002305631 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireProperty.apt.vm @@ -0,0 +1,87 @@ +~~ 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. + + ------ + Require Property + ------ + Brian Fox + ------ + June 2007 + ------ + +Require Property + + This rule can enforce that a declared property is set and optionally evaluate it against a regular expression. + + The following parameters are supported by this rule: + + * property - the property to evaluate. + + * message - an optional message to the user if the rule fails. Default is: "Property 'xxx' is required for this build". + + * regex - a regular expression used to check the value of the property. + + * regexMessage - an optional message to the user if the regex check fails. + + [] + + The regex is applied to the entire value of the property (i.e. using the regex "match" method), + and not just a substring of the property value. + + Sample Plugin Configuration: + ++---+ + + [...] + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + enforce-property + + enforce + + + + + basedir + You must set a basedir property! + .*\d.* + The basedir property must contain at least one digit. + + + project.version + "Project version must be specified." + .*(\d|-SNAPSHOT)$ + "Project version must end in a number or -SNAPSHOT." + + + true + + + + + + + [...] + ++---+ + diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireReleaseDeps.apt.vm b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireReleaseDeps.apt.vm new file mode 100644 index 000000000..83cf07b90 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireReleaseDeps.apt.vm @@ -0,0 +1,119 @@ +~~ 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. + + ------ + Require Release Dependencies + ------ + Brian Fox + ------ + Auguest 2008 + ------ + +Require Release Dependencies + + This rule checks the dependencies and fails if any snapshots are found. + + + The following parameters are supported by this rule: + + * searchTransitive - if transitive dependencies should be checked. Default: true + + * message - an optional message to the user if the rule fails. + + * onlyWhenRelease - if this rule should only be executed when the version is a non-SNAPSHOT version. Default: false + + * failWhenParentIsSnapshot - if the parent should be checked. Default: true + + * includes - List of dependency patterns to include when checking for snapshot versions + + * excludes - List of dependency patterns to exclude when checking for snapshot versions + + [] + + + Sample Plugin Configuration: + ++---+ + + [...] + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + enforce-no-snapshots + + enforce + + + + + No Snapshots Allowed! + + + true + + + + + + + [...] + ++---+ + + Includes/Excludes Plugin Configuration: + ++---+ + + [...] + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + enforce-no-snapshots + + enforce + + + + + No Snapshots Allowed! + + org.apache.maven:maven-core + org.apache.maven.plugins:* + + + + true + + + + + + + [...] + ++---+ + diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireReleaseVersion.apt.vm b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireReleaseVersion.apt.vm new file mode 100644 index 000000000..738e4b066 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireReleaseVersion.apt.vm @@ -0,0 +1,72 @@ +~~ 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. + + ------ + Require Release Version + ------ + Brian Fox + ------ + August 2008 + ------ + +Require Release Version + + This rule checks that the current project is not a snapshot. + + + The following parameters are supported by this rule: + + * message - an optional message to the user if the rule fails. + + * failWhenParentIsSnapshot - if the parent should be checked. Default: true + + [] + + + Sample Plugin Configuration: + ++---+ + + [...] + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + enforce-no-snapshots + + enforce + + + + + No Snapshots Allowed! + + + true + + + + + + + [...] + ++---+ diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireSameVersions.apt.vm b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireSameVersions.apt.vm new file mode 100644 index 000000000..f3c99e122 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireSameVersions.apt.vm @@ -0,0 +1,86 @@ + ~~ 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. + + ----- + Require Same Version + ----- + Robert Scholte + ----- + 2013-06-13 + ----- + + Require Same Versions + + This rule enforces that specific dependencies and/or plugins have the same version. + + + The following parameters are supported by this rule: + + * dependencies - an optional list of dependency patterns + + * buildPlugins - an optional list of build plugin patterns + + * reportPlugins - an optional list of report plugin patterns + + * plugins - an optional list of both build and report plugin patterns + + * uniqueVersions - if SNAPSHOTs should be compared by their timestamped version or not. Default: false + + [] + + + Sample Plugin Configuration: + ++---+ + + [...] + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + enforce-no-snapshots + + enforce + + + + + + org.apache.maven.plugins:maven-surefire-plugin + org.apache.maven.plugins:maven-failsafe-plugin + org.apache.maven.plugins:maven-surefire-report-plugin + + + + + org.apache.maven + + + + + + + + + + [...] + ++---+ \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireSnapshotVersion.apt.vm b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireSnapshotVersion.apt.vm new file mode 100644 index 000000000..446acf573 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireSnapshotVersion.apt.vm @@ -0,0 +1,72 @@ +~~ 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. + + ------ + Require Snapshot Version + ------ + Guillaume Boue + ------ + September 2016 + ------ + +Require Snapshot Version + + This rule checks that the current project is not a release. + + + The following parameters are supported by this rule: + + * message - an optional message to the user if the rule fails. + + * failWhenParentIsRelease - if the parent should be checked. Default: true + + [] + + + Sample Plugin Configuration: + ++---+ + + [...] + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + enforce-no-releases + + enforce + + + + + No Releases Allowed! + + + true + + + + + + + [...] + ++---+ diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireUpperBoundDeps.apt.vm b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireUpperBoundDeps.apt.vm new file mode 100644 index 000000000..b34a6f42d --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/requireUpperBoundDeps.apt.vm @@ -0,0 +1,128 @@ + ~~ 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. + + ----- + Require Upper Bound Dependencies + ----- + ----- + 2012-02-08 + ----- + + This rule requires that the version for each dependency resolved during a build, is equal + to or higher than all transitive dependency declarations. The version of each dependency + resolved during the build will normally be the version specified in the POM or the + version with the least transitive steps (the "nearest" definition). For more + information about Maven dependency resolution, see + {{{http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html}the Maven site}}. + + Here is a concrete example. This will cause a build to fail: + +----------------------------------------------------------------------------------- + + + org.slf4j + slf4j-api + 1.4.0 + + + ch.qos.logback + logback-classic + 0.9.9 + + + +----------------------------------------------------------------------------------- + + Because the project will run logback-classic 0.9.9 with slf4j-api 1.4.0 + and slf4j-api 1.4.0 is probably not forwards compatible with slf4j-api 1.5.0. + + This is the log message: + +----------------------------------------------------------------------------------- + +Failed while enforcing RequireUpperBoundDeps. The error(s) are [ +RequireUpperBoundDeps error for org.slf4j:slf4j-api:1.4.0 paths to dependency are: ++-test:TestParent:1.0-SNAPSHOT + +-org.slf4j:slf4j-api:1.4.0 +and ++-test:TestParent:1.0-SNAPSHOT + +-ch.qos.logback:logback-classic:0.9.9 + +-org.slf4j:slf4j-api:1.5.0 +] + +----------------------------------------------------------------------------------- + + And this will succeed. + +----------------------------------------------------------------------------------- + + + org.slf4j + slf4j-api + 1.6.0 + + + ch.qos.logback + logback-classic + 0.9.9 + + + +----------------------------------------------------------------------------------- + + Here is how a project should be setup to use this rule + +----------------------------------------------------------------------------------- + + ... + + + ... + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + enforce + + + + + + + + + + + enforce + + + + + ... + + + ... + +----------------------------------------------------------------------------------- + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/versionRanges.apt b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/versionRanges.apt new file mode 100644 index 000000000..a27213b37 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/apt/versionRanges.apt @@ -0,0 +1,54 @@ +~~ 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. + + ------ + Version Range Specification + ------ + Brian Fox + ------ + May 2007 + ------ + +Version Range Specification + + The {{{./requireMavenVersion.html}RequireMavenVersion}} and {{{./requireJavaVersion.html}RequireJavaVersion}} rules use the {{{https://cwiki.apache.org/confluence/display/MAVENOLD/Dependency+Mediation+and+Conflict+Resolution#DependencyMediationandConflictResolution-DependencyVersionRanges}standard Maven version range syntax}} with one minor change for ease of use (denoted with *): + + +*----------*--------------+ +| Range | Meaning | +*----------*--------------+ +| 1.0 | x \>\= 1.0 \* The default Maven meaning for 1.0 is everything (,) but with 1.0 recommended. Obviously this doesn't work for enforcing versions here, so it has been redefined as a minimum version. + | +*----------*--------------+ +| (,1.0] | x \<\= 1.0 | +*----------*--------------+ +| (,1.0) | x \< 1.0 | +*----------*--------------+ +| [1.0] | x \=\= 1.0 | +*----------*--------------+ +| [1.0,) | x \>\= 1.0 | +*----------*--------------+ +| (1.0,) | x \> 1.0 | +*----------*--------------+ +| (1.0,2.0)| 1.0 \< x \< 2.0 | +*----------*--------------+ +| [1.0,2.0]| 1.0 \<\= x \<\= 2.0 | +*----------*--------------+ +| (,1.0],[1.2,) |x \<\= 1.0 or x \>\= 1.2. Multiple sets are comma-separated | +*----------*--------------+ +| (,1.1),(1.1,) |x !\= 1.1 | +*----------*--------------+ diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/resources/images/module.png b/Java-base/maven-enforcer/src/enforcer-rules/src/site/resources/images/module.png new file mode 100644 index 000000000..0bac49a11 Binary files /dev/null and b/Java-base/maven-enforcer/src/enforcer-rules/src/site/resources/images/module.png differ diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/resources/images/root-with-modules.png b/Java-base/maven-enforcer/src/enforcer-rules/src/site/resources/images/root-with-modules.png new file mode 100644 index 000000000..d0586bfbe Binary files /dev/null and b/Java-base/maven-enforcer/src/enforcer-rules/src/site/resources/images/root-with-modules.png differ diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/resources/images/root-with-parent-and-modules.png b/Java-base/maven-enforcer/src/enforcer-rules/src/site/resources/images/root-with-parent-and-modules.png new file mode 100644 index 000000000..eb254fb97 Binary files /dev/null and b/Java-base/maven-enforcer/src/enforcer-rules/src/site/resources/images/root-with-parent-and-modules.png differ diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/resources/images/root-with-parent.png b/Java-base/maven-enforcer/src/enforcer-rules/src/site/resources/images/root-with-parent.png new file mode 100644 index 000000000..4cb70418c Binary files /dev/null and b/Java-base/maven-enforcer/src/enforcer-rules/src/site/resources/images/root-with-parent.png differ diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/resources/images/root.png b/Java-base/maven-enforcer/src/enforcer-rules/src/site/resources/images/root.png new file mode 100644 index 000000000..67597a5b5 Binary files /dev/null and b/Java-base/maven-enforcer/src/enforcer-rules/src/site/resources/images/root.png differ diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/site/site.xml b/Java-base/maven-enforcer/src/enforcer-rules/src/site/site.xml new file mode 100644 index 000000000..fef88e58f --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/site/site.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/BanDistributionManagementTest.java b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/BanDistributionManagementTest.java new file mode 100644 index 000000000..c1af1741f --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/BanDistributionManagementTest.java @@ -0,0 +1,284 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.model.DeploymentRepository; +import org.apache.maven.model.DistributionManagement; +import org.apache.maven.model.Model; +import org.apache.maven.model.Site; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.junit.Test; + +/** + * This class is intended to test the {@link BanDistributionManagement} rule. + * + * @author Karl Heinz Marbaise + */ +public class BanDistributionManagementTest +{ + private MavenProject project; + + private EnforcerRuleHelper helper; + + @Test + public void shouldNotFailWithoutDistributionManagement() + throws Exception + { + BanDistributionManagement rule = setupProjectWithoutDistributionManagement(); + rule.execute( helper ); + // intentionally no assert cause in case of an exception the test will be red. + } + + /** + *
+     * <distributionManagement>
+     *   <repository>
+     *    ...
+     *   </repository>
+     * </distributionManagement>
+     * 
+ * + * @throws Exception + */ + @Test( expected = EnforcerRuleException.class ) + public void shouldThrowExceptionIfDistributionManagementIsDefinedWithRepository() + throws Exception + { + BanDistributionManagement rule = + setupProjectWithDistributionManagement( new DeploymentRepository(), null, null ); + rule.execute( helper ); + // intentionally no assert cause we expect an exception. + } + + /** + *
+     * <distributionManagement>
+     *   <repository>
+     *    ...
+     *   </repository>
+     *   <snapshotRepository>
+     *    ...
+     *   </snapshotRepository>
+     * </distributionManagement>
+     * 
+ */ + @Test( expected = EnforcerRuleException.class ) + public void shouldThrowExceptionIfDistributionManagementIsDefinedWithRepositorySnapshotRepository() + throws Exception + { + BanDistributionManagement rule = + setupProjectWithDistributionManagement( new DeploymentRepository(), new DeploymentRepository(), null ); + rule.execute( helper ); + // intentionally no assert cause we expect an exception. + } + + /** + *
+     * <distributionManagement>
+     *   <repository>
+     *    ...
+     *   </repository>
+     *   <snapshotRepository>
+     *    ...
+     *   </snapshotRepository>
+     *   <site>
+     *    ...
+     *   </site>
+     * </distributionManagement>
+     * 
+ */ + @Test( expected = EnforcerRuleException.class ) + public void shouldThrowExceptionIfDistributionManagementIsDefinedWithRepositorySnapshotRepositorySite() + throws Exception + { + BanDistributionManagement rule = + setupProjectWithDistributionManagement( new DeploymentRepository(), new DeploymentRepository(), + new Site() ); + rule.execute( helper ); + // intentionally no assert cause we expect an exception. + } + + /** + *
+     * <distributionManagement>
+     *   <repository>
+     *    ...
+     *   </repository>
+     * </distributionManagement>
+     * 
+ */ + @Test + public void shouldAllowDistributionManagementHavingRepository() + throws Exception + { + BanDistributionManagement rule = + setupProjectWithDistributionManagement( new DeploymentRepository(), null, null ); + rule.setAllowRepository( true ); + rule.execute( helper ); + // intentionally no assert cause in case of an exception the test will be red. + } + + /** + *
+     * <distributionManagement>
+     *   <repository>
+     *    ...
+     *   </repository>
+     *   <snapshotRepository>
+     *    ...
+     *   </snapshotRepository>
+     * </distributionManagement>
+     * 
+ */ + @Test + public void shouldAllowDistributionManagementHavingRepositorySnapshotRepository() + throws Exception + { + BanDistributionManagement rule = + setupProjectWithDistributionManagement( new DeploymentRepository(), new DeploymentRepository(), null ); + rule.setAllowRepository( true ); + rule.setAllowSnapshotRepository( true ); + rule.execute( helper ); + // intentionally no assert cause in case of an exception the test will be red. + } + + /** + *
+     * <distributionManagement>
+     *   <repository>
+     *    ...
+     *   </repository>
+     *   <snapshotRepository>
+     *    ...
+     *   </snapshotRepository>
+     *   <site>
+     *    ...
+     *   </site>
+     * </distributionManagement>
+     * 
+ */ + @Test + public void shouldAllowDistributionManagementHavingRepositorySnapshotRepositorySite() + throws Exception + { + BanDistributionManagement rule = + setupProjectWithDistributionManagement( new DeploymentRepository(), new DeploymentRepository(), + new Site() ); + rule.setAllowRepository( true ); + rule.setAllowSnapshotRepository( true ); + rule.setAllowSite( true ); + rule.execute( helper ); + // intentionally no assert cause in case of an exception the test will be red. + } + + @Test + public void shouldThrowExceptionCauseParentProjectHasDistributionManagementSnapshotRepository() + throws Exception + { + BanDistributionManagement rule = + setupProjectWithParentDistributionManagement( null, new DeploymentRepository(), null ); + + rule.setAllowSnapshotRepository( true ); + + rule.execute( helper ); + } + + private BanDistributionManagement setupProjectWithParentDistributionManagement( DeploymentRepository repository, + DeploymentRepository snapshotRepository, + Site site ) + throws ExpressionEvaluationException + { + project = setupProject( null ); + + DistributionManagement dmParent = mock( DistributionManagement.class ); + when( dmParent.getRepository() ).thenReturn( repository ); + when( dmParent.getSnapshotRepository() ).thenReturn( snapshotRepository ); + when( dmParent.getSite() ).thenReturn( site ); + + MavenProject parentProject = mock( MavenProject.class ); + Model model = mock( Model.class ); + when( model.getDistributionManagement() ).thenReturn( dmParent ); + when( parentProject.getOriginalModel() ).thenReturn( model ); + when( project.getParent() ).thenReturn( parentProject ); + + BanDistributionManagement rule = setupEnforcerRule(); + + return rule; + } + + private BanDistributionManagement setupProjectWithoutDistributionManagement() + throws ExpressionEvaluationException + { + project = setupProject( null ); + + BanDistributionManagement rule = setupEnforcerRule(); + + return rule; + } + + private BanDistributionManagement setupProjectWithDistributionManagement( DeploymentRepository repository, + DeploymentRepository snapshotRepository, + Site site ) + throws ExpressionEvaluationException + { + DistributionManagement dm = mock( DistributionManagement.class ); + when( dm.getRepository() ).thenReturn( repository ); + when( dm.getSnapshotRepository() ).thenReturn( snapshotRepository ); + when( dm.getSite() ).thenReturn( site ); + + project = setupProject( dm ); + + when( project.getParent() ).thenReturn( mock( MavenProject.class ) ); + when( project.isExecutionRoot() ).thenReturn( true ); + + BanDistributionManagement rule = setupEnforcerRule(); + + return rule; + } + + private MavenProject setupProject( DistributionManagement distributionManagement ) + { + MavenProject project = mock( MavenProject.class ); + when( project.getPackaging() ).thenReturn( "jar" ); + Model mavenModel = mock( Model.class ); + when( project.getOriginalModel() ).thenReturn( mavenModel ); + when( mavenModel.getDistributionManagement() ).thenReturn( distributionManagement ); + return project; + } + + private BanDistributionManagement setupEnforcerRule() + throws ExpressionEvaluationException + { + helper = mock( EnforcerRuleHelper.class ); + when( helper.evaluate( "${project}" ) ).thenReturn( project ); + BanDistributionManagement rule = new BanDistributionManagement(); + + when( helper.getLog() ).thenReturn( mock( Log.class ) ); + return rule; + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/BannedDependenciesTestSetup.java b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/BannedDependenciesTestSetup.java new file mode 100644 index 000000000..1d36ef763 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/BannedDependenciesTestSetup.java @@ -0,0 +1,109 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.plugin.testing.ArtifactStubFactory; +import org.apache.maven.project.MavenProject; + +public class BannedDependenciesTestSetup +{ + public BannedDependenciesTestSetup() + throws IOException + { + this.excludes = new ArrayList(); + this.includes = new ArrayList(); + + ArtifactStubFactory factory = new ArtifactStubFactory(); + + MockProject project = new MockProject(); + project.setArtifacts( factory.getMixedArtifacts() ); + project.setDependencyArtifacts( factory.getScopedArtifacts() ); + + this.helper = EnforcerTestUtils.getHelper( project ); + + this.rule = newBannedDependenciesRule(); + this.rule.setMessage( null ); + + this.rule.setExcludes( this.excludes ); + this.rule.setIncludes( this.includes ); + } + + private List excludes; + private List includes; + + private BannedDependencies rule; + + private EnforcerRuleHelper helper; + + public void setSearchTransitive( boolean searchTransitive ) + { + rule.setSearchTransitive( searchTransitive ); + } + + public void addExcludeAndRunRule( String toAdd ) + throws EnforcerRuleException + { + excludes.add( toAdd ); + rule.execute( helper ); + } + + public void addIncludeExcludeAndRunRule (String incAdd, String excAdd) throws EnforcerRuleException { + excludes.add( excAdd ); + includes.add( incAdd ); + rule.execute( helper ); + } + + public List getExcludes() + { + return excludes; + } + + public void setExcludes( List excludes ) + { + this.excludes = excludes; + } + + private BannedDependencies newBannedDependenciesRule() + { + BannedDependencies rule = new BannedDependencies() + { + @SuppressWarnings( "unchecked" ) + @Override + protected Set getDependenciesToCheck( MavenProject project ) + { + // the integration with dependencyGraphTree is verified with the integration tests + // for unit-testing + return isSearchTransitive() ? project.getArtifacts() : project.getDependencyArtifacts(); + } + }; + return rule; + } + + +} + diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/EnforcerTestUtils.java b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/EnforcerTestUtils.java new file mode 100644 index 000000000..29014a549 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/EnforcerTestUtils.java @@ -0,0 +1,153 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.Properties; + +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.execution.MavenExecutionRequest; +import org.apache.maven.execution.MavenExecutionResult; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.model.Plugin; +import org.apache.maven.plugin.MojoExecution; +import org.apache.maven.plugin.PluginParameterExpressionEvaluator; +import org.apache.maven.plugin.logging.SystemStreamLog; +import org.apache.maven.plugins.enforcer.utils.MockEnforcerExpressionEvaluator; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; +import org.sonatype.aether.RepositorySystemSession; + +/** + * The Class EnforcerTestUtils. + * + * @author Brian Fox + */ +public final class EnforcerTestUtils +{ + /** + * Gets the maven session. + * + * @return the maven session + */ + public static MavenSession getMavenSession() + { + PlexusContainer mock = mock( PlexusContainer.class ); + + MavenExecutionRequest mer = mock( MavenExecutionRequest.class ); + + Properties systemProperties = new Properties(); + systemProperties.put( "maven.version", "3.0" ); + when( mer.getUserProperties() ).thenReturn( new Properties() ); + when( mer.getSystemProperties() ).thenReturn( systemProperties ); + + MavenExecutionResult meresult = mock( MavenExecutionResult.class ); + return new MavenSession( mock, (RepositorySystemSession) null, mer, meresult ); + } + + /** + * Gets the helper. + * + * @return the helper + */ + public static EnforcerRuleHelper getHelper() + { + return getHelper( new MockProject(), false ); + } + + /** + * Gets the helper. + * + * @param mockExpression the mock expression + * @return the helper + */ + public static EnforcerRuleHelper getHelper( boolean mockExpression ) + { + return getHelper( new MockProject(), mockExpression ); + } + + /** + * Gets the helper. + * + * @param project the project + * @return the helper + */ + public static EnforcerRuleHelper getHelper( MavenProject project ) + { + return getHelper( project, false ); + } + + /** + * Gets the helper. + * + * @param project the project + * @param mockExpression the mock expression + * @return the helper + */ + public static EnforcerRuleHelper getHelper( MavenProject project, boolean mockExpression ) + { + MavenSession session = getMavenSession(); + ExpressionEvaluator eval; + if ( mockExpression ) + { + eval = new MockEnforcerExpressionEvaluator( session ); + } + else + { + MojoExecution mockExecution = mock( MojoExecution.class ); + session.setCurrentProject( project ); + eval = new PluginParameterExpressionEvaluator( session, mockExecution ); + } + return new DefaultEnforcementRuleHelper( session, eval, new SystemStreamLog(), null ); + } + + /** + * Gets the helper. + * + * @param project the project + * @param eval the expression evaluator to use + * @return the helper + */ + public static EnforcerRuleHelper getHelper( MavenProject project, ExpressionEvaluator eval ) + { + MavenSession session = getMavenSession(); + return new DefaultEnforcementRuleHelper( session, eval, new SystemStreamLog(), null ); + } + + /** + * New plugin. + * + * @param groupId the group id + * @param artifactId the artifact id + * @param version the version + * @return the plugin + */ + public static Plugin newPlugin( String groupId, String artifactId, String version ) + { + Plugin plugin = new Plugin(); + plugin.setArtifactId( artifactId ); + plugin.setGroupId( groupId ); + plugin.setVersion( version ); + return plugin; + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/MockPlexusContainer.java b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/MockPlexusContainer.java new file mode 100644 index 000000000..a73cbbdc6 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/MockPlexusContainer.java @@ -0,0 +1,662 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.io.File; +import java.io.Reader; +import java.util.Date; +import java.util.List; +import java.util.Map; + +import org.apache.maven.execution.RuntimeInformation; +import org.apache.maven.project.MavenProject; +import org.codehaus.classworlds.ClassRealm; +import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.PlexusContainerException; +import org.codehaus.plexus.component.composition.UndefinedComponentComposerException; +import org.codehaus.plexus.component.discovery.ComponentDiscoveryListener; +import org.codehaus.plexus.component.factory.ComponentInstantiationException; +import org.codehaus.plexus.component.repository.ComponentDescriptor; +import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import org.codehaus.plexus.component.repository.exception.ComponentRepositoryException; +import org.codehaus.plexus.configuration.PlexusConfigurationException; +import org.codehaus.plexus.configuration.PlexusConfigurationResourceException; +import org.codehaus.plexus.context.Context; +import org.codehaus.plexus.logging.Logger; +import org.codehaus.plexus.logging.LoggerManager; + +/** + * The Class MockPlexusContainer. + * + * @author Brian Fox + */ +public class MockPlexusContainer + implements PlexusContainer +{ + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#lookup(java.lang.String) + */ + public Object lookup( String theComponentKey ) + throws ComponentLookupException + { + if ( theComponentKey.equals( MavenProject.class.getName() ) ) + { + return new MavenProject(); + } + else if ( theComponentKey.equals( RuntimeInformation.class.getName() ) ) + { + return new MockRuntimeInformation(); + } + + return null; + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#addComponentDescriptor(org.codehaus.plexus.component.repository.ComponentDescriptor) + */ + public void addComponentDescriptor( ComponentDescriptor theComponentDescriptor ) + { + // TODO Auto-generated method stub + + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#addContextValue(java.lang.Object, java.lang.Object) + */ + public void addContextValue( Object theKey, Object theValue ) + { + // TODO Auto-generated method stub + + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#addJarRepository(java.io.File) + */ + public void addJarRepository( File theRepository ) + { + // TODO Auto-generated method stub + + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#addJarResource(java.io.File) + */ + public void addJarResource( File theResource ) + throws PlexusContainerException + { + // TODO Auto-generated method stub + + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#composeComponent(java.lang.Object, + * org.codehaus.plexus.component.repository.ComponentDescriptor) + */ + public void composeComponent( Object theComponent, ComponentDescriptor theComponentDescriptor ) + throws UndefinedComponentComposerException + { + // TODO Auto-generated method stub + + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#createChildContainer(java.lang.String, java.util.List, java.util.Map) + */ + public PlexusContainer createChildContainer( String theName, List theClasspathJars, Map theContext ) + throws PlexusContainerException + { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#createChildContainer(java.lang.String, java.util.List, java.util.Map, + * java.util.List) + */ + public PlexusContainer createChildContainer( String theName, List theClasspathJars, Map theContext, + List theDiscoveryListeners ) + throws PlexusContainerException + { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#createComponentInstance(org.codehaus.plexus.component.repository.ComponentDescriptor) + */ + public Object createComponentInstance( ComponentDescriptor theComponentDescriptor ) + throws ComponentInstantiationException, ComponentLifecycleException + { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#dispose() + */ + public void dispose() + { + // TODO Auto-generated method stub + + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#getChildContainer(java.lang.String) + */ + public PlexusContainer getChildContainer( String theName ) + { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#getComponentDescriptor(java.lang.String) + */ + public ComponentDescriptor getComponentDescriptor( String theComponentKey ) + { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#getComponentDescriptorList(java.lang.String) + */ + public List getComponentDescriptorList( String theRole ) + { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#getComponentDescriptorMap(java.lang.String) + */ + public Map getComponentDescriptorMap( String theRole ) + { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#getComponentRealm(java.lang.String) + */ + public ClassRealm getComponentRealm( String theComponentKey ) + { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#getContext() + */ + public Context getContext() + { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#getCreationDate() + */ + public Date getCreationDate() + { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#getLogger() + */ + public Logger getLogger() + { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#getLoggerManager() + */ + public LoggerManager getLoggerManager() + { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#hasChildContainer(java.lang.String) + */ + public boolean hasChildContainer( String theName ) + { + // TODO Auto-generated method stub + return false; + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#hasComponent(java.lang.String) + */ + public boolean hasComponent( String theComponentKey ) + { + // TODO Auto-generated method stub + return false; + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#hasComponent(java.lang.String, java.lang.String) + */ + public boolean hasComponent( String theRole, String theRoleHint ) + { + // TODO Auto-generated method stub + return false; + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#initialize() + */ + public void initialize() + throws PlexusContainerException + { + // TODO Auto-generated method stub + + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#isInitialized() + */ + public boolean isInitialized() + { + // TODO Auto-generated method stub + return false; + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#isStarted() + */ + public boolean isStarted() + { + // TODO Auto-generated method stub + return false; + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#lookup(java.lang.String, java.lang.String) + */ + public Object lookup( String theRole, String theRoleHint ) + throws ComponentLookupException + { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#lookupList(java.lang.String) + */ + public List lookupList( String theRole ) + throws ComponentLookupException + { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#lookupMap(java.lang.String) + */ + public Map lookupMap( String theRole ) + throws ComponentLookupException + { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#registerComponentDiscoveryListener(org.codehaus.plexus.component.discovery.ComponentDiscoveryListener) + */ + public void registerComponentDiscoveryListener( ComponentDiscoveryListener theListener ) + { + // TODO Auto-generated method stub + + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#release(java.lang.Object) + */ + public void release( Object theComponent ) + throws ComponentLifecycleException + { + // TODO Auto-generated method stub + + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#releaseAll(java.util.Map) + */ + public void releaseAll( Map theComponents ) + throws ComponentLifecycleException + { + // TODO Auto-generated method stub + + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#releaseAll(java.util.List) + */ + public void releaseAll( List theComponents ) + throws ComponentLifecycleException + { + // TODO Auto-generated method stub + + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#removeChildContainer(java.lang.String) + */ + public void removeChildContainer( String theName ) + { + // TODO Auto-generated method stub + + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#removeComponentDiscoveryListener(org.codehaus.plexus.component.discovery.ComponentDiscoveryListener) + */ + public void removeComponentDiscoveryListener( ComponentDiscoveryListener theListener ) + { + // TODO Auto-generated method stub + + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#resume(java.lang.Object) + */ + public void resume( Object theComponent ) + throws ComponentLifecycleException + { + // TODO Auto-generated method stub + + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#setConfigurationResource(java.io.Reader) + */ + public void setConfigurationResource( Reader theConfiguration ) + throws PlexusConfigurationResourceException + { + // TODO Auto-generated method stub + + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#setLoggerManager(org.codehaus.plexus.logging.LoggerManager) + */ + public void setLoggerManager( LoggerManager theLoggerManager ) + { + // TODO Auto-generated method stub + + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#setParentPlexusContainer(org.codehaus.plexus.PlexusContainer) + */ + public void setParentPlexusContainer( PlexusContainer theParentContainer ) + { + // TODO Auto-generated method stub + + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#start() + */ + public void start() + throws PlexusContainerException + { + // TODO Auto-generated method stub + + } + + /* + * (non-Javadoc) + * + * @see org.codehaus.plexus.PlexusContainer#suspend(java.lang.Object) + */ + public void suspend( Object theComponent ) + throws ComponentLifecycleException + { + // TODO Auto-generated method stub + + } + + @Override + public T lookup( Class role ) + throws ComponentLookupException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public T lookup( Class role, String hint ) + throws ComponentLookupException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public T lookup( Class type, String role, String hint ) + throws ComponentLookupException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public List lookupList( Class role ) + throws ComponentLookupException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public Map lookupMap( Class role ) + throws ComponentLookupException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean hasComponent( Class role ) + { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean hasComponent( Class role, String hint ) + { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean hasComponent( Class type, String role, String hint ) + { + // TODO Auto-generated method stub + return false; + } + + @Override + public void addComponent( Object component, String role ) + { + // TODO Auto-generated method stub + + } + + @Override + public void addComponent( T component, Class role, String hint ) + { + // TODO Auto-generated method stub + + } + + @Override + public ComponentDescriptor getComponentDescriptor( String role, String hint ) + { + // TODO Auto-generated method stub + return null; + } + + @Override + public ComponentDescriptor getComponentDescriptor( Class type, String role, String hint ) + { + // TODO Auto-generated method stub + return null; + } + + @Override + public List> getComponentDescriptorList( Class type, String role ) + { + // TODO Auto-generated method stub + return null; + } + + @Override + public Map> getComponentDescriptorMap( Class type, String role ) + { + // TODO Auto-generated method stub + return null; + } + + @Override + public List> discoverComponents( org.codehaus.plexus.classworlds.realm.ClassRealm classRealm ) + throws PlexusConfigurationException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public org.codehaus.plexus.classworlds.realm.ClassRealm getContainerRealm() + { + // TODO Auto-generated method stub + return null; + } + + @Override + public org.codehaus.plexus.classworlds.realm.ClassRealm setLookupRealm( org.codehaus.plexus.classworlds.realm.ClassRealm realm ) + { + // TODO Auto-generated method stub + return null; + } + + @Override + public org.codehaus.plexus.classworlds.realm.ClassRealm getLookupRealm() + { + // TODO Auto-generated method stub + return null; + } + + @Override + public org.codehaus.plexus.classworlds.realm.ClassRealm createChildRealm( String id ) + { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/MockProject.java b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/MockProject.java new file mode 100644 index 000000000..2a025f264 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/MockProject.java @@ -0,0 +1,1928 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.io.File; +import java.io.IOException; +import java.io.Writer; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.DependencyResolutionRequiredException; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.model.Build; +import org.apache.maven.model.CiManagement; +import org.apache.maven.model.Contributor; +import org.apache.maven.model.DependencyManagement; +import org.apache.maven.model.Developer; +import org.apache.maven.model.DistributionManagement; +import org.apache.maven.model.IssueManagement; +import org.apache.maven.model.License; +import org.apache.maven.model.MailingList; +import org.apache.maven.model.Model; +import org.apache.maven.model.Organization; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.PluginManagement; +import org.apache.maven.model.Prerequisites; +import org.apache.maven.model.Reporting; +import org.apache.maven.model.Resource; +import org.apache.maven.model.Scm; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.artifact.InvalidDependencyVersionException; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.util.xml.Xpp3Dom; + +/** + * very simple stub of maven project, going to take a lot of work to make it useful as a stub though. + */ +public class MockProject + extends MavenProject +{ + + /** The group id. */ + private String groupId; + + /** The artifact id. */ + private String artifactId; + + /** The name. */ + private String name; + + /** The model. */ + private Model model; + + /** The parent. */ + private MavenProject parent; + + /** The dependencies. */ + private List dependencies; + + /** The file. */ + private File file; + + /** The collected projects. */ + private List collectedProjects; + + /** The attached artifacts. */ + private List attachedArtifacts; + + /** The compile source roots. */ + private List compileSourceRoots; + + /** The test compile source roots. */ + private List testCompileSourceRoots; + + /** The script source roots. */ + private List scriptSourceRoots; + + /** The plugin artifact repositories. */ + private List pluginArtifactRepositories; + + /** The artifact repositories. */ + private List artifactRepositories; + + // private ArtifactRepository releaseArtifactRepository; + + // private ArtifactRepository snapshotArtifactRepository; + + /** The active profiles. */ + private List activeProfiles; + + /** The dependency artifacts. */ + private Set dependencyArtifacts; + + /** The dependency management. */ + private DependencyManagement dependencyManagement; + + /** The artifact. */ + private Artifact artifact; + + // private Map artifactMap; + + /** The original model. */ + private Model originalModel; + + // private Map pluginArtifactMap; + + // private Map reportArtifactMap; + + // private Map extensionArtifactMap; + + // private Map projectReferences; + + // private Build buildOverlay; + + /** The execution root. */ + private boolean executionRoot; + + /** The compile artifacts. */ + private List compileArtifacts; + + /** The compile dependencies. */ + private List compileDependencies; + + /** The system dependencies. */ + private List systemDependencies; + + /** The test classpath elements. */ + private List testClasspathElements; + + /** The test dependencies. */ + private List testDependencies; + + /** The system classpath elements. */ + private List systemClasspathElements; + + /** The system artifacts. */ + private List systemArtifacts; + + /** The test artifacts. */ + private List testArtifacts; + + /** The runtime artifacts. */ + private List runtimeArtifacts; + + /** The runtime dependencies. */ + private List runtimeDependencies; + + /** The runtime classpath elements. */ + private List runtimeClasspathElements; + + /** The model version. */ + private String modelVersion; + + /** The packaging. */ + private String packaging; + + /** The inception year. */ + private String inceptionYear; + + /** The url. */ + private String url; + + /** The description. */ + private String description; + + /** The version. */ + private String version; + + /** The default goal. */ + private String defaultGoal; + + /** The artifacts. */ + private Set artifacts; + + /** The properties. */ + private Properties properties = new Properties(); + + /** The base dir. */ + private File baseDir = null; + + /** + * Instantiates a new mock project. + */ + public MockProject() + { + super( (Model) null ); + } + + // kinda dangerous... + /** + * Instantiates a new mock project. + * + * @param model the model + */ + public MockProject( Model model ) + { + // super(model); + super( (Model) null ); + } + + // kinda dangerous... + /** + * Instantiates a new mock project. + * + * @param project the project + */ + public MockProject( MavenProject project ) + { + // super(project); + super( (Model) null ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getModulePathAdjustment(org.apache.maven.project.MavenProject) + */ + public String getModulePathAdjustment( MavenProject mavenProject ) + throws IOException + { + return ""; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getArtifact() + */ + public Artifact getArtifact() + { + return artifact; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setArtifact(org.apache.maven.artifact.Artifact) + */ + public void setArtifact( Artifact artifact ) + { + this.artifact = artifact; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getModel() + */ + public Model getModel() + { + return model; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getParent() + */ + public MavenProject getParent() + { + return parent; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setParent(org.apache.maven.project.MavenProject) + */ + public void setParent( MavenProject mavenProject ) + { + this.parent = mavenProject; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setRemoteArtifactRepositories(java.util.List) + */ + public void setRemoteArtifactRepositories( List list ) + { + this.artifactRepositories = list; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getRemoteArtifactRepositories() + */ + public List getRemoteArtifactRepositories() + { + return artifactRepositories; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#hasParent() + */ + public boolean hasParent() + { + if ( parent != null ) + { + return true; + } + else + { + return false; + } + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getFile() + */ + public File getFile() + { + return file; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setFile(java.io.File) + */ + public void setFile( File file ) + { + this.file = file; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getBasedir() + */ + public File getBasedir() + { + if ( baseDir == null ) + { + baseDir = new File( PlexusTestCase.getBasedir() ); + } + return baseDir; + } + + /** + * Sets the base dir. + * + * @param base the new base dir + */ + public void setBaseDir( File base ) + { + baseDir = base; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setDependencies(java.util.List) + */ + public void setDependencies( List list ) + { + dependencies = list; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getDependencies() + */ + public List getDependencies() + { + if ( dependencies == null ) + { + dependencies = Collections.EMPTY_LIST; + } + return dependencies; + } + + /** + * Sets the dependency management. + * + * @param depMgt the new dependency management + */ + public void setDependencyManagement( DependencyManagement depMgt ) + { + this.dependencyManagement = depMgt; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getDependencyManagement() + */ + public DependencyManagement getDependencyManagement() + { + if ( dependencyManagement == null ) + { + dependencyManagement = new DependencyManagement(); + } + + return dependencyManagement; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addCompileSourceRoot(java.lang.String) + */ + public void addCompileSourceRoot( String string ) + { + if ( compileSourceRoots == null ) + { + compileSourceRoots = Collections.singletonList( string ); + } + else + { + compileSourceRoots.add( string ); + } + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addScriptSourceRoot(java.lang.String) + */ + public void addScriptSourceRoot( String string ) + { + if ( scriptSourceRoots == null ) + { + scriptSourceRoots = Collections.singletonList( string ); + } + else + { + scriptSourceRoots.add( string ); + } + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addTestCompileSourceRoot(java.lang.String) + */ + public void addTestCompileSourceRoot( String string ) + { + if ( testCompileSourceRoots == null ) + { + testCompileSourceRoots = Collections.singletonList( string ); + } + else + { + testCompileSourceRoots.add( string ); + } + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getCompileSourceRoots() + */ + public List getCompileSourceRoots() + { + return compileSourceRoots; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getScriptSourceRoots() + */ + public List getScriptSourceRoots() + { + return scriptSourceRoots; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getTestCompileSourceRoots() + */ + public List getTestCompileSourceRoots() + { + return testCompileSourceRoots; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getCompileClasspathElements() + */ + public List getCompileClasspathElements() + throws DependencyResolutionRequiredException + { + return compileSourceRoots; + } + + /** + * Sets the compile artifacts. + * + * @param compileArtifacts the new compile artifacts + */ + public void setCompileArtifacts( List compileArtifacts ) + { + this.compileArtifacts = compileArtifacts; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getCompileArtifacts() + */ + public List getCompileArtifacts() + { + return compileArtifacts; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getCompileDependencies() + */ + public List getCompileDependencies() + { + return compileDependencies; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getTestClasspathElements() + */ + public List getTestClasspathElements() + throws DependencyResolutionRequiredException + { + return testClasspathElements; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getTestArtifacts() + */ + public List getTestArtifacts() + { + return testArtifacts; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getTestDependencies() + */ + public List getTestDependencies() + { + return testDependencies; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getRuntimeClasspathElements() + */ + public List getRuntimeClasspathElements() + throws DependencyResolutionRequiredException + { + return runtimeClasspathElements; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getRuntimeArtifacts() + */ + public List getRuntimeArtifacts() + { + return runtimeArtifacts; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getRuntimeDependencies() + */ + public List getRuntimeDependencies() + { + return runtimeDependencies; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getSystemClasspathElements() + */ + public List getSystemClasspathElements() + throws DependencyResolutionRequiredException + { + return systemClasspathElements; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getSystemArtifacts() + */ + public List getSystemArtifacts() + { + return systemArtifacts; + } + + /** + * Sets the runtime classpath elements. + * + * @param runtimeClasspathElements the new runtime classpath elements + */ + public void setRuntimeClasspathElements( List runtimeClasspathElements ) + { + this.runtimeClasspathElements = runtimeClasspathElements; + } + + /** + * Sets the attached artifacts. + * + * @param attachedArtifacts the new attached artifacts + */ + public void setAttachedArtifacts( List attachedArtifacts ) + { + this.attachedArtifacts = attachedArtifacts; + } + + /** + * Sets the compile source roots. + * + * @param compileSourceRoots the new compile source roots + */ + public void setCompileSourceRoots( List compileSourceRoots ) + { + this.compileSourceRoots = compileSourceRoots; + } + + /** + * Sets the test compile source roots. + * + * @param testCompileSourceRoots the new test compile source roots + */ + public void setTestCompileSourceRoots( List testCompileSourceRoots ) + { + this.testCompileSourceRoots = testCompileSourceRoots; + } + + /** + * Sets the script source roots. + * + * @param scriptSourceRoots the new script source roots + */ + public void setScriptSourceRoots( List scriptSourceRoots ) + { + this.scriptSourceRoots = scriptSourceRoots; + } + + /** + * Sets the artifact map. + * + * @param artifactMap the new artifact map + */ + public void setArtifactMap( Map artifactMap ) + { + // this.artifactMap = artifactMap; + } + + /** + * Sets the plugin artifact map. + * + * @param pluginArtifactMap the new plugin artifact map + */ + public void setPluginArtifactMap( Map pluginArtifactMap ) + { + // this.pluginArtifactMap = pluginArtifactMap; + } + + /** + * Sets the report artifact map. + * + * @param reportArtifactMap the new report artifact map + */ + public void setReportArtifactMap( Map reportArtifactMap ) + { + // this.reportArtifactMap = reportArtifactMap; + } + + /** + * Sets the extension artifact map. + * + * @param extensionArtifactMap the new extension artifact map + */ + public void setExtensionArtifactMap( Map extensionArtifactMap ) + { + // this.extensionArtifactMap = extensionArtifactMap; + } + + /** + * Sets the project references. + * + * @param projectReferences the new project references + */ + public void setProjectReferences( Map projectReferences ) + { + // this.projectReferences = projectReferences; + } + + /** + * Sets the builds the overlay. + * + * @param buildOverlay the new builds the overlay + */ + public void setBuildOverlay( Build buildOverlay ) + { + // this.buildOverlay = buildOverlay; + } + + /** + * Sets the compile dependencies. + * + * @param compileDependencies the new compile dependencies + */ + public void setCompileDependencies( List compileDependencies ) + { + this.compileDependencies = compileDependencies; + } + + /** + * Sets the system dependencies. + * + * @param systemDependencies the new system dependencies + */ + public void setSystemDependencies( List systemDependencies ) + { + this.systemDependencies = systemDependencies; + } + + /** + * Sets the test classpath elements. + * + * @param testClasspathElements the new test classpath elements + */ + public void setTestClasspathElements( List testClasspathElements ) + { + this.testClasspathElements = testClasspathElements; + } + + /** + * Sets the test dependencies. + * + * @param testDependencies the new test dependencies + */ + public void setTestDependencies( List testDependencies ) + { + this.testDependencies = testDependencies; + } + + /** + * Sets the system classpath elements. + * + * @param systemClasspathElements the new system classpath elements + */ + public void setSystemClasspathElements( List systemClasspathElements ) + { + this.systemClasspathElements = systemClasspathElements; + } + + /** + * Sets the system artifacts. + * + * @param systemArtifacts the new system artifacts + */ + public void setSystemArtifacts( List systemArtifacts ) + { + this.systemArtifacts = systemArtifacts; + } + + /** + * Sets the test artifacts. + * + * @param testArtifacts the new test artifacts + */ + public void setTestArtifacts( List testArtifacts ) + { + this.testArtifacts = testArtifacts; + } + + /** + * Sets the runtime artifacts. + * + * @param runtimeArtifacts the new runtime artifacts + */ + public void setRuntimeArtifacts( List runtimeArtifacts ) + { + this.runtimeArtifacts = runtimeArtifacts; + } + + /** + * Sets the runtime dependencies. + * + * @param runtimeDependencies the new runtime dependencies + */ + public void setRuntimeDependencies( List runtimeDependencies ) + { + this.runtimeDependencies = runtimeDependencies; + } + + /** + * Sets the model. + * + * @param model the new model + */ + public void setModel( Model model ) + { + this.model = model; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getSystemDependencies() + */ + public List getSystemDependencies() + { + return systemDependencies; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setModelVersion(java.lang.String) + */ + public void setModelVersion( String string ) + { + this.modelVersion = string; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getModelVersion() + */ + public String getModelVersion() + { + return modelVersion; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getId() + */ + public String getId() + { + return ""; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setGroupId(java.lang.String) + */ + public void setGroupId( String string ) + { + this.groupId = string; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getGroupId() + */ + public String getGroupId() + { + return groupId; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setArtifactId(java.lang.String) + */ + public void setArtifactId( String string ) + { + this.artifactId = string; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getArtifactId() + */ + public String getArtifactId() + { + return artifactId; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setName(java.lang.String) + */ + public void setName( String string ) + { + this.name = string; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getName() + */ + public String getName() + { + return name; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setVersion(java.lang.String) + */ + public void setVersion( String string ) + { + this.version = string; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getVersion() + */ + public String getVersion() + { + return version; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getPackaging() + */ + public String getPackaging() + { + return packaging; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setPackaging(java.lang.String) + */ + public void setPackaging( String string ) + { + this.packaging = string; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setInceptionYear(java.lang.String) + */ + public void setInceptionYear( String string ) + { + this.inceptionYear = string; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getInceptionYear() + */ + public String getInceptionYear() + { + return inceptionYear; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setUrl(java.lang.String) + */ + public void setUrl( String string ) + { + this.url = string; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getUrl() + */ + public String getUrl() + { + return url; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getPrerequisites() + */ + public Prerequisites getPrerequisites() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setIssueManagement(org.apache.maven.model.IssueManagement) + */ + public void setIssueManagement( IssueManagement issueManagement ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getCiManagement() + */ + public CiManagement getCiManagement() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setCiManagement(org.apache.maven.model.CiManagement) + */ + public void setCiManagement( CiManagement ciManagement ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getIssueManagement() + */ + public IssueManagement getIssueManagement() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setDistributionManagement(org.apache.maven.model.DistributionManagement) + */ + public void setDistributionManagement( DistributionManagement distributionManagement ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getDistributionManagement() + */ + public DistributionManagement getDistributionManagement() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setDescription(java.lang.String) + */ + public void setDescription( String string ) + { + this.description = string; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getDescription() + */ + public String getDescription() + { + return description; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setOrganization(org.apache.maven.model.Organization) + */ + public void setOrganization( Organization organization ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getOrganization() + */ + public Organization getOrganization() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setScm(org.apache.maven.model.Scm) + */ + public void setScm( Scm scm ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getScm() + */ + public Scm getScm() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setMailingLists(java.util.List) + */ + public void setMailingLists( List list ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getMailingLists() + */ + public List getMailingLists() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addMailingList(org.apache.maven.model.MailingList) + */ + public void addMailingList( MailingList mailingList ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setDevelopers(java.util.List) + */ + public void setDevelopers( List list ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getDevelopers() + */ + public List getDevelopers() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addDeveloper(org.apache.maven.model.Developer) + */ + public void addDeveloper( Developer developer ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setContributors(java.util.List) + */ + public void setContributors( List list ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getContributors() + */ + public List getContributors() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addContributor(org.apache.maven.model.Contributor) + */ + public void addContributor( Contributor contributor ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setBuild(org.apache.maven.model.Build) + */ + public void setBuild( Build build ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getBuild() + */ + public Build getBuild() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getResources() + */ + public List getResources() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getTestResources() + */ + public List getTestResources() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addResource(org.apache.maven.model.Resource) + */ + public void addResource( Resource resource ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addTestResource(org.apache.maven.model.Resource) + */ + public void addTestResource( Resource resource ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setReporting(org.apache.maven.model.Reporting) + */ + public void setReporting( Reporting reporting ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getReporting() + */ + public Reporting getReporting() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setLicenses(java.util.List) + */ + public void setLicenses( List list ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getLicenses() + */ + public List getLicenses() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addLicense(org.apache.maven.model.License) + */ + public void addLicense( License license ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setArtifacts(java.util.Set) + */ + public void setArtifacts( Set set ) + { + this.artifacts = set; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getArtifacts() + */ + public Set getArtifacts() + { + if ( artifacts == null ) + { + return Collections.EMPTY_SET; + } + else + { + return artifacts; + } + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getArtifactMap() + */ + public Map getArtifactMap() + { + return Collections.singletonMap( "", "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setPluginArtifacts(java.util.Set) + */ + public void setPluginArtifacts( Set set ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getPluginArtifacts() + */ + public Set getPluginArtifacts() + { + return Collections.singleton( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getPluginArtifactMap() + */ + public Map getPluginArtifactMap() + { + return Collections.singletonMap( "", "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setReportArtifacts(java.util.Set) + */ + public void setReportArtifacts( Set set ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getReportArtifacts() + */ + public Set getReportArtifacts() + { + return Collections.singleton( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getReportArtifactMap() + */ + public Map getReportArtifactMap() + { + return Collections.singletonMap( "", "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setExtensionArtifacts(java.util.Set) + */ + public void setExtensionArtifacts( Set set ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getExtensionArtifacts() + */ + public Set getExtensionArtifacts() + { + return Collections.singleton( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getExtensionArtifactMap() + */ + public Map getExtensionArtifactMap() + { + return Collections.singletonMap( "", "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setParentArtifact(org.apache.maven.artifact.Artifact) + */ + public void setParentArtifact( Artifact artifact ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getParentArtifact() + */ + public Artifact getParentArtifact() + { + if (parent !=null) + { + return parent.getArtifact(); + } + else + return null; + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getRepositories() + */ + public List getRepositories() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getReportPlugins() + */ + public List getReportPlugins() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getBuildPlugins() + */ + public List getBuildPlugins() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getModules() + */ + public List getModules() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getPluginManagement() + */ + public PluginManagement getPluginManagement() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addPlugin(org.apache.maven.model.Plugin) + */ + public void addPlugin( Plugin plugin ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#injectPluginManagementInfo(org.apache.maven.model.Plugin) + */ + public void injectPluginManagementInfo( Plugin plugin ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getCollectedProjects() + */ + public List getCollectedProjects() + { + return collectedProjects; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setCollectedProjects(java.util.List) + */ + public void setCollectedProjects( List list ) + { + this.collectedProjects = list; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setPluginArtifactRepositories(java.util.List) + */ + public void setPluginArtifactRepositories( List list ) + { + this.pluginArtifactRepositories = list; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getPluginArtifactRepositories() + */ + public List getPluginArtifactRepositories() + { + return pluginArtifactRepositories; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getDistributionManagementArtifactRepository() + */ + public ArtifactRepository getDistributionManagementArtifactRepository() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getPluginRepositories() + */ + public List getPluginRepositories() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setActiveProfiles(java.util.List) + */ + public void setActiveProfiles( List list ) + { + activeProfiles = list; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getActiveProfiles() + */ + public List getActiveProfiles() + { + return activeProfiles; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addAttachedArtifact(org.apache.maven.artifact.Artifact) + */ + public void addAttachedArtifact( Artifact theArtifact ) + { + if ( attachedArtifacts == null ) + { + this.attachedArtifacts = Collections.singletonList( theArtifact ); + } + else + { + attachedArtifacts.add( theArtifact ); + } + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getAttachedArtifacts() + */ + public List getAttachedArtifacts() + { + return attachedArtifacts; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getGoalConfiguration(java.lang.String, java.lang.String, + * java.lang.String, java.lang.String) + */ + public Xpp3Dom getGoalConfiguration( String string, String string1, String string2, String string3 ) + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getReportConfiguration(java.lang.String, java.lang.String, + * java.lang.String) + */ + public Xpp3Dom getReportConfiguration( String string, String string1, String string2 ) + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getExecutionProject() + */ + public MavenProject getExecutionProject() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setExecutionProject(org.apache.maven.project.MavenProject) + */ + public void setExecutionProject( MavenProject mavenProject ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#writeModel(java.io.Writer) + */ + public void writeModel( Writer writer ) + throws IOException + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#writeOriginalModel(java.io.Writer) + */ + public void writeOriginalModel( Writer writer ) + throws IOException + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getDependencyArtifacts() + */ + public Set getDependencyArtifacts() + { + return dependencyArtifacts; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setDependencyArtifacts(java.util.Set) + */ + public void setDependencyArtifacts( Set set ) + { + this.dependencyArtifacts = set; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setReleaseArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) + */ + public void setReleaseArtifactRepository( ArtifactRepository artifactRepository ) + { + // this.releaseArtifactRepository = artifactRepository; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setSnapshotArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) + */ + public void setSnapshotArtifactRepository( ArtifactRepository artifactRepository ) + { + // this.snapshotArtifactRepository = artifactRepository; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setOriginalModel(org.apache.maven.model.Model) + */ + public void setOriginalModel( Model model ) + { + this.originalModel = model; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getOriginalModel() + */ + public Model getOriginalModel() + { + return originalModel; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getBuildExtensions() + */ + public List getBuildExtensions() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#createArtifacts(org.apache.maven.artifact.factory.ArtifactFactory, + * java.lang.String, org.apache.maven.artifact.resolver.filter.ArtifactFilter) + */ + public Set createArtifacts( ArtifactFactory artifactFactory, String string, ArtifactFilter artifactFilter ) + throws InvalidDependencyVersionException + { + return Collections.EMPTY_SET; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addProjectReference(org.apache.maven.project.MavenProject) + */ + public void addProjectReference( MavenProject mavenProject ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#attachArtifact(java.lang.String, java.lang.String, java.io.File) + */ + public void attachArtifact( String string, String string1, File theFile ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getProperties() + */ + public Properties getProperties() + { + return this.properties; + } + + /** + * Sets the property. + * + * @param key the key + * @param value the value + */ + public void setProperty( String key, String value ) + { + properties.setProperty( key, value ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getFilters() + */ + public List getFilters() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getProjectReferences() + */ + public Map getProjectReferences() + { + return Collections.singletonMap( "", "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#isExecutionRoot() + */ + public boolean isExecutionRoot() + { + return executionRoot; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setExecutionRoot(boolean) + */ + public void setExecutionRoot( boolean b ) + { + this.executionRoot = b; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getDefaultGoal() + */ + public String getDefaultGoal() + { + return defaultGoal; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#replaceWithActiveArtifact(org.apache.maven.artifact.Artifact) + */ + public Artifact replaceWithActiveArtifact( Artifact theArtifact ) + { + return null; + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/MockRuntimeInformation.java b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/MockRuntimeInformation.java new file mode 100644 index 000000000..b62dec51f --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/MockRuntimeInformation.java @@ -0,0 +1,45 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.apache.maven.artifact.versioning.DefaultArtifactVersion; +import org.apache.maven.execution.RuntimeInformation; + +/** + * Just a mock object hard coded to return version 2.0.5 + * + * @author Brian Fox + */ +public class MockRuntimeInformation + implements RuntimeInformation +{ + + /* + * (non-Javadoc) + * + * @see org.apache.maven.execution.RuntimeInformation#getApplicationVersion() + */ + public ArtifactVersion getApplicationVersion() + { + return new DefaultArtifactVersion( "2.0.5" ); + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/ReactorModuleConvergenceTest.java b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/ReactorModuleConvergenceTest.java new file mode 100644 index 000000000..4eab0cb5e --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/ReactorModuleConvergenceTest.java @@ -0,0 +1,342 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.execution.ProjectDependencyGraph; +import org.apache.maven.model.Dependency; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * Check reactorModuleConvergence rule. + * + * @author Karl Heinz Marbaise + */ +public class ReactorModuleConvergenceTest +{ + private MavenSession session; + + private EnforcerRuleHelper helper; + + private ReactorModuleConvergence rule; + + @Before + public void before() + throws ExpressionEvaluationException + { + session = mock( MavenSession.class ); + helper = mock( EnforcerRuleHelper.class ); + when( helper.evaluate( "${session}" ) ).thenReturn( session ); + when( helper.getLog() ).thenReturn( mock( Log.class ) ); + + rule = new ReactorModuleConvergence(); + } + + private void setupSortedProjects( List projectList ) + { + ProjectDependencyGraph pdg = mock( ProjectDependencyGraph.class ); + when( session.getProjectDependencyGraph() ).thenReturn( pdg ); + when( pdg.getSortedProjects() ).thenReturn( projectList ); + } + + @Test + public void shouldNotFailWithNoProject() + throws EnforcerRuleException + { + setupSortedProjects( Collections.emptyList() ); + + rule.execute( helper ); + + // intentionally only assertTrue cause we don't expect an exception. + assertTrue( true ); + } + + @Test + public void shouldNotFailWithAValidProject() + throws EnforcerRuleException, ExpressionEvaluationException + { + MavenProject mp1 = createProjectParent(); + MavenProject mp2 = createProjectChild1( mp1 ); + MavenProject mp3 = createProjectChild2( mp1 ); + + List theList = Arrays.asList( mp1, mp2, mp3 ); + setupSortedProjects( theList ); + + rule.execute( helper ); + + // intentionally only assertTrue cause we don't expect an exception. + assertTrue( true ); + } + + @Test( expected = EnforcerRuleException.class ) + public void shouldFailWithWrongVersionInOneChild() + throws EnforcerRuleException, ExpressionEvaluationException + { + MavenProject mp1 = createProjectParent(); + MavenProject mp2 = createProjectChild1( mp1 ); + MavenProject mp3 = createProjectChild2WithWrongVersion( mp1 ); + + List theList = Arrays.asList( mp1, mp2, mp3 ); + setupSortedProjects( theList ); + + rule.execute( helper ); + + // intentionally no assertTrue() cause we expect getting an exception. + } + + @Test( expected = EnforcerRuleException.class ) + public void shouldFailWithWrongParent() + throws EnforcerRuleException, ExpressionEvaluationException + { + MavenProject mp1 = createProjectParent(); + + MavenProject wrongParentVerison = mock( MavenProject.class ); + when( wrongParentVerison.getGroupId() ).thenReturn( "org.apache.enforcer" ); + when( wrongParentVerison.getArtifactId() ).thenReturn( "m1" ); + when( wrongParentVerison.getVersion() ).thenReturn( "1.1-SNAPSHOT" ); + when( wrongParentVerison.getId() ).thenReturn( "org.apache.enforcer:m1:jar:1.1-SNAPSHOT" ); + when( wrongParentVerison.getDependencies() ).thenReturn( Collections.emptyList() ); + + MavenProject mp2 = createProjectChild2( wrongParentVerison ); + MavenProject mp3 = createProjectChild2( mp1 ); + + List theList = Arrays.asList( mp1, mp2, mp3 ); + setupSortedProjects( theList ); + + rule.execute( helper ); + + // intentionally no assertTrue() cause we expect getting an exception. + } + + @Test + public void shouldNotFailWithACompanyParent() + throws EnforcerRuleException, ExpressionEvaluationException + { + MavenProject companyParent = createCompanyParent(); + MavenProject mp1 = createProjectParent( companyParent ); + + MavenProject mp2 = createProjectChild1( mp1 ); + MavenProject mp3 = createProjectChild2( mp1 ); + + List theList = Arrays.asList( mp1, mp2, mp3 ); + setupSortedProjects( theList ); + + rule.execute( helper ); + + // intentionally only assertTrue cause we don't expect an exception. + assertTrue( true ); + } + + @Test( expected = EnforcerRuleException.class ) + public void shouldFailWithMissingParentsInReactory() + throws EnforcerRuleException, ExpressionEvaluationException + { + MavenProject mp1 = createProjectParent(); + MavenProject mp2 = createProjectChild1( mp1 ); + MavenProject mp3 = createProjectChild2( null ); + + List theList = Arrays.asList( mp1, mp2, mp3 ); + setupSortedProjects( theList ); + + rule.execute( helper ); + + // intentionally only assertTrue cause we don't expect an exception. + assertTrue( true ); + } + + @Test( expected = EnforcerRuleException.class ) + public void shouldFailWithAParentWhichIsNotPartOfTheReactory() + throws EnforcerRuleException, ExpressionEvaluationException + { + MavenProject mp1 = createProjectParent(); + + MavenProject wrongParentVerison = mock( MavenProject.class ); + when( wrongParentVerison.getGroupId() ).thenReturn( "org.apache" ); + when( wrongParentVerison.getArtifactId() ).thenReturn( "m1" ); + when( wrongParentVerison.getVersion() ).thenReturn( "1.0-SNAPSHOT" ); + when( wrongParentVerison.getId() ).thenReturn( "org.apache.enforcer:m1:jar:1.0-SNAPSHOT" ); + when( wrongParentVerison.getDependencies() ).thenReturn( Collections.emptyList() ); + + MavenProject mp2 = createProjectChild2( wrongParentVerison ); + MavenProject mp3 = createProjectChild2( mp1 ); + + List theList = Arrays.asList( mp1, mp2, mp3 ); + setupSortedProjects( theList ); + + rule.execute( helper ); + + // intentionally no assertTrue() cause we expect getting an exception. + } + + @Test + public void shouldNotFailWithDependencyInReactory() + throws EnforcerRuleException, ExpressionEvaluationException + { + MavenProject mp1 = createProjectParent(); + MavenProject mp2 = createProjectChild1( mp1 ); + + Dependency goodDependency = createDependency( "org.junit", "junit", "2.0" ); + List depListMP2 = Arrays.asList( goodDependency ); + when( mp2.getDependencies() ).thenReturn( depListMP2 ); + + MavenProject mp3 = createProjectChild2( mp1 ); + Dependency dep1_MP3 = createDependency( "org.apache.commons", "commons-io", "1.0.4" ); + List depListMP3 = Arrays.asList( dep1_MP3 ); + when( mp3.getDependencies() ).thenReturn( depListMP3 ); + + List theList = Arrays.asList( mp1, mp2, mp3 ); + setupSortedProjects( theList ); + + rule.execute( helper ); + + // intentionally no assertTrue() cause we do not expect to get an exception. + assertTrue( true ); + } + + @Test( expected = EnforcerRuleException.class ) + public void shouldFailWithWrongDependencyInReactor() + throws EnforcerRuleException, ExpressionEvaluationException + { + MavenProject mp1 = createProjectParent(); + MavenProject mp2 = createProjectChild1( mp1 ); + + Dependency goodDependency = createDependency( "org.junit", "junit", "2.0" ); + + Dependency wrongDepFromReactor = createDependency( "org.apache.enforcer", "m2", "1.1-SNAPSHOT" ); + List depList = Arrays.asList( goodDependency, wrongDepFromReactor ); + when( mp2.getDependencies() ).thenReturn( depList ); + + MavenProject mp3 = createProjectChild2( mp1 ); + + List theList = Arrays.asList( mp1, mp2, mp3 ); + setupSortedProjects( theList ); + + rule.execute( helper ); + + // intentionally no assertTrue() cause we expect getting an exception. + } + + /** + * This small setup is equivalent to the following situation: + * + *
+     *  <parent>
+     *    <groupId>...</groupId>
+     *    <artifactId>...</artifactId>
+     *    <version>1.0-SNAPSHOT</version>
+     *  </parent>
+     *  
+     *  <version>1.1-SNAPSHOT</version>
+     * 
+ * + * @param parent + * @return Create MavenProject mock. + */ + private MavenProject createProjectChild2WithWrongVersion( MavenProject parent ) + { + MavenProject mp2 = mock( MavenProject.class ); + when( mp2.getParent() ).thenReturn( parent ); + when( mp2.getGroupId() ).thenReturn( "org.apache.enforcer" ); + when( mp2.getArtifactId() ).thenReturn( "m1" ); + when( mp2.getVersion() ).thenReturn( "1.1-SNAPSHOT" ); + when( mp2.getId() ).thenReturn( "org.apache.enforcer:m1:jar:1.1-SNAPSHOT" ); + when( mp2.getDependencies() ).thenReturn( Collections.emptyList() ); + return mp2; + } + + private MavenProject createProjectChild2( MavenProject parent ) + { + MavenProject mp3 = mock( MavenProject.class ); + when( mp3.getParent() ).thenReturn( parent ); + when( mp3.getGroupId() ).thenReturn( "org.apache.enforcer" ); + when( mp3.getArtifactId() ).thenReturn( "m2" ); + when( mp3.getVersion() ).thenReturn( "1.0-SNAPSHOT" ); + when( mp3.getId() ).thenReturn( "org.apache.enforcer:m2:jar:1.0-SNAPSHOT" ); + when( mp3.getDependencies() ).thenReturn( Collections.emptyList() ); + return mp3; + } + + private MavenProject createProjectChild1( MavenProject parent ) + { + MavenProject mp2 = mock( MavenProject.class ); + when( mp2.getParent() ).thenReturn( parent ); + when( mp2.getGroupId() ).thenReturn( "org.apache.enforcer" ); + when( mp2.getArtifactId() ).thenReturn( "m1" ); + when( mp2.getVersion() ).thenReturn( "1.0-SNAPSHOT" ); + when( mp2.getId() ).thenReturn( "org.apache.enforcer:m1:jar:1.0-SNAPSHOT" ); + when( mp2.getDependencies() ).thenReturn( Collections.emptyList() ); + return mp2; + } + + private MavenProject createCompanyParent() + { + MavenProject nonReactorParent = mock( MavenProject.class ); + when( nonReactorParent.getGroupId() ).thenReturn( "org.apache.enforcer.parent" ); + when( nonReactorParent.getArtifactId() ).thenReturn( "parent" ); + when( nonReactorParent.getVersion() ).thenReturn( "1.1" ); + when( nonReactorParent.getId() ).thenReturn( "org.apache.enforcer.parent:parent:jar:1.1" ); + when( nonReactorParent.getDependencies() ).thenReturn( Collections.emptyList() ); + return nonReactorParent; + } + + private MavenProject createProjectParent( MavenProject nonReactorParent ) + { + MavenProject m = createProjectParent(); + when( m.isExecutionRoot() ).thenReturn( true ); + when( m.getParent() ).thenReturn( nonReactorParent ); + return m; + } + + private MavenProject createProjectParent() + { + MavenProject mp1 = mock( MavenProject.class ); + when( mp1.isExecutionRoot() ).thenReturn( true ); + when( mp1.getParent() ).thenReturn( null ); + when( mp1.getGroupId() ).thenReturn( "org.apache.enforcer" ); + when( mp1.getArtifactId() ).thenReturn( "parent" ); + when( mp1.getVersion() ).thenReturn( "1.0-SNAPSHOT" ); + when( mp1.getId() ).thenReturn( "org.apache.enforcer:parent:pom:1.0-SNAPSHOT" ); + when( mp1.getDependencies() ).thenReturn( Collections.emptyList() ); + return mp1; + } + + private Dependency createDependency( String groupId, String artifactId, String version ) + { + Dependency dep = mock( Dependency.class ); + when( dep.getGroupId() ).thenReturn( groupId ); + when( dep.getArtifactId() ).thenReturn( artifactId ); + when( dep.getVersion() ).thenReturn( version ); + return dep; + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/RequireActiveProfileTest.java b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/RequireActiveProfileTest.java new file mode 100644 index 000000000..f6713c89a --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/RequireActiveProfileTest.java @@ -0,0 +1,193 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.model.Profile; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.junit.Before; +import org.junit.Test; + +/** + * Check the profile rule. + * + * @author Karl Heinz Marbaise + */ +public class RequireActiveProfileTest +{ + private MavenProject project; + + private EnforcerRuleHelper helper; + + private RequireActiveProfile rule; + + @Before + public void before() + throws ExpressionEvaluationException + { + project = mock( MavenProject.class ); + helper = mock( EnforcerRuleHelper.class ); + when( helper.evaluate( "${project}" ) ).thenReturn( project ); + rule = new RequireActiveProfile(); + } + + @Test + public void testNoActiveProfilesInProjectAndNoProfilesExpectedToBeActivated() + throws EnforcerRuleException + { + when( project.getActiveProfiles() ).thenReturn( Collections. emptyList() ); + + rule.execute( helper ); + + assertTrue( true ); + } + + @Test + public void testActiveProfileAndExpectedActiveProfile() + throws EnforcerRuleException + { + List profiles = Collections. singletonList( createProfile( "profile-2" ) ); + + when( project.getActiveProfiles() ).thenReturn( profiles ); + + rule.setProfiles( "profile-2" ); + + rule.execute( helper ); + assertTrue( true ); + } + + @Test( expected = EnforcerRuleException.class ) + public void testNoActiveProfileButTheRuleRequestedAnActiveProfile() + throws EnforcerRuleException + { + when( project.getActiveProfiles() ).thenReturn( Collections. emptyList() ); + + rule.setProfiles( "profile-2" ); + + rule.execute( helper ); + // intentionally no assertTrue(...) + } + + @Test( expected = EnforcerRuleException.class ) + public void testNoActiveProfileButWeExpectToGetAnExceptionWithAll() + throws EnforcerRuleException + { + when( project.getActiveProfiles() ).thenReturn( Collections. emptyList() ); + + rule.setProfiles( "profile-2" ); + rule.setAll( true ); + + rule.execute( helper ); + // intentionally no assertTrue(...) + } + + @Test + public void testTwoActiveProfilesWithOneRequiredProfile() + throws EnforcerRuleException + { + List profiles = Arrays.asList( createProfile( "profile-1" ), createProfile( "profile-2" ) ); + + when( project.getActiveProfiles() ).thenReturn( profiles ); + + rule.setProfiles( "profile-2" ); + + rule.execute( helper ); + assertTrue( true ); + } + + @Test + public void testTwoActiveProfilesWhereOneProfileIsRequiredToBeActivated() + throws EnforcerRuleException + { + List profiles = Arrays.asList( createProfile( "profile-1" ), createProfile( "profile-2" ) ); + + when( project.getActiveProfiles() ).thenReturn( profiles ); + + rule.setProfiles( "profile-2" ); + rule.setAll( true ); + + rule.execute( helper ); + assertTrue( true ); + } + + @Test( expected = EnforcerRuleException.class ) + public void testTwoActiveProfilesWithTwoRequiredProfilesWhereOneOfThemIsNotPartOfTheActiveProfiles() + throws EnforcerRuleException, ExpressionEvaluationException + { + + List profiles = Arrays.asList( createProfile( "profile-X" ), createProfile( "profile-Y" ) ); + + when( project.getActiveProfiles() ).thenReturn( profiles ); + + rule.setProfiles( "profile-Z,profile-X" ); + rule.setAll( true ); + + rule.execute( helper ); + // intentionally no assertTrue(..) + } + + @Test( expected = EnforcerRuleException.class ) + public void testOneActiveProfilesWithTwoRequiredProfiles() + throws EnforcerRuleException, ExpressionEvaluationException + { + List profiles = Collections.singletonList( createProfile( "profile-X" ) ); + + when( project.getActiveProfiles() ).thenReturn( profiles ); + + rule.setProfiles( "profile-X,profile-Y" ); + rule.setAll( true ); + + rule.execute( helper ); + // intentionally no assertTrue(..) + } + + @Test + public void testOneActiveProfileWithTwoProfilesButNotAll() + throws EnforcerRuleException, ExpressionEvaluationException + { + List profiles = Collections.singletonList( createProfile( "profile-X" ) ); + + when( project.getActiveProfiles() ).thenReturn( profiles ); + + rule.setProfiles( "profile-X,profile-Y" ); + rule.setAll( false ); + + rule.execute( helper ); + // intentionally no assertTrue(..) + } + + private Profile createProfile( String profileId ) + { + Profile p = new Profile(); + p.setId( profileId ); + return p; + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/RequirePrerequisiteTest.java b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/RequirePrerequisiteTest.java new file mode 100644 index 000000000..dec1d7384 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/RequirePrerequisiteTest.java @@ -0,0 +1,165 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Collections; + +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.model.Prerequisites; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.junit.Before; +import org.junit.Test; + +public class RequirePrerequisiteTest +{ + private MavenProject project; + + private EnforcerRuleHelper helper; + + @Before + public void before() + throws ExpressionEvaluationException + { + project = mock( MavenProject.class ); + when( project.getPackaging() ).thenReturn( "maven-plugin" ); + + helper = mock( EnforcerRuleHelper.class ); + when( helper.evaluate( "${project}" ) ).thenReturn( project ); + } + + @Test( expected = EnforcerRuleException.class ) + public void testNoPrerequisite() + throws Exception + { + RequirePrerequisite rule = new RequirePrerequisite(); + rule.execute( helper ); + } + + @Test + public void testNoSpecifiedPrerequisite() + throws Exception + { + when( project.getPrerequisites() ).thenReturn( new Prerequisites() ); + + RequirePrerequisite rule = new RequirePrerequisite(); + rule.execute( helper ); + } + + @Test( expected = EnforcerRuleException.class ) + public void testLowerMavenPrerequisite() + throws Exception + { + when( project.getPrerequisites() ).thenReturn( new Prerequisites() ); + + RequirePrerequisite rule = new RequirePrerequisite(); + rule.setMavenVersion( "3.0" ); + rule.execute( helper ); + } + + @Test( expected = EnforcerRuleException.class ) + public void testLowerMavenRangePrerequisite() + throws Exception + { + when( project.getPrerequisites() ).thenReturn( new Prerequisites() ); + + RequirePrerequisite rule = new RequirePrerequisite(); + rule.setMavenVersion( "[3.0,)" ); + + rule.execute( helper ); + } + + @Test( expected = EnforcerRuleException.class ) + public void testMavenRangesPrerequisite() + throws Exception + { + Prerequisites prerequisites = new Prerequisites(); + prerequisites.setMaven( "2.2.0" ); + when( project.getPrerequisites() ).thenReturn( prerequisites ); + + RequirePrerequisite rule = new RequirePrerequisite(); + rule.setMavenVersion( "[2.0.6,2.1.0),(2.1.0,2.2.0),(2.2.0,)" ); + + rule.execute( helper ); + } + + @Test + public void testValidPrerequisite() + throws Exception + { + Prerequisites prerequisites = new Prerequisites(); + prerequisites.setMaven( "3.0" ); + when( project.getPrerequisites() ).thenReturn( prerequisites ); + + RequirePrerequisite rule = new RequirePrerequisite(); + rule.setMavenVersion( "2.2.1" ); + + rule.execute( helper ); + } + + @Test + public void testPomPackaging() + throws Exception + { + when( project.getPackaging() ).thenReturn( "pom" ); + + Log log = mock( Log.class ); + when( helper.getLog() ).thenReturn( log ); + + RequirePrerequisite rule = new RequirePrerequisite(); + rule.execute( helper ); + + verify( log ).debug( "Packaging is pom, skipping requirePrerequisite rule" ); + } + + @Test( expected = EnforcerRuleException.class ) + public void testMatchingPackagings() + throws Exception + { + when( project.getPackaging() ).thenReturn( "maven-plugin" ); + + RequirePrerequisite rule = new RequirePrerequisite(); + rule.setPackagings( Collections.singletonList( "maven-plugin" ) ); + rule.execute( helper ); + } + + @Test + public void testNotMatchingPackagings() + throws Exception + { + when( project.getPackaging() ).thenReturn( "jar" ); + + Log log = mock( Log.class ); + when( helper.getLog() ).thenReturn( log ); + + RequirePrerequisite rule = new RequirePrerequisite(); + rule.setPackagings( Collections.singletonList( "maven-plugin" ) ); + rule.execute( helper ); + + verify( log ).debug( "Packaging is jar, skipping requirePrerequisite rule" ); + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestAbstractVersionEnforcer.java b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestAbstractVersionEnforcer.java new file mode 100644 index 000000000..0cbb82748 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestAbstractVersionEnforcer.java @@ -0,0 +1,161 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import junit.framework.TestCase; + +import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.apache.maven.artifact.versioning.DefaultArtifactVersion; +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.plugin.logging.SystemStreamLog; + +/** + * The Class TestAbstractVersionEnforcer. + * + * @author Brian Fox + */ +public class TestAbstractVersionEnforcer + extends TestCase +{ + + /** + * Test contains version. + * + * @throws InvalidVersionSpecificationException the invalid version specification exception + */ + public void testContainsVersion() + throws InvalidVersionSpecificationException + { + ArtifactVersion version = new DefaultArtifactVersion( "2.0.5" ); + // test ranges + assertTrue( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "[2.0.5,)" ), version ) ); + assertTrue( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "[2.0.4,)" ), version ) ); + assertTrue( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "[2.0.4,2.0.5]" ), + version ) ); + assertTrue( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "[2.0.4,2.0.6]" ), + version ) ); + assertTrue( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "[2.0.4,2.0.6)" ), + version ) ); + assertTrue( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "[2.0,)" ), version ) ); + assertTrue( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "[2.0.0,)" ), version ) ); + // not matching versions + assertFalse( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "[2.0.4,2.0.5)" ), + version ) ); + assertFalse( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "[2.0.6,)" ), version ) ); + assertFalse( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "(2.0.5,)" ), version ) ); + + // test singular versions -> 2.0.5 == [2.0.5,) or x >= 2.0.5 + assertTrue( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "2.0" ), version ) ); + assertTrue( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "2.0.4" ), version ) ); + assertTrue( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "2.0.5" ), version ) ); + + assertFalse( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "2.0.6" ), version ) ); + + version = new DefaultArtifactVersion( "1.5.0-7" ); + assertTrue( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "[1.5.0,)" ), version ) ); + assertTrue( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "[1.5,1.6)" ), version ) ); + + version = new DefaultArtifactVersion( RequireJavaVersion.normalizeJDKVersion( "1.5.0-07" ) ); + assertTrue( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "[1.5.0,)" ), version ) ); + assertTrue( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "[1.5,1.6)" ), version ) ); + + //MENFORCER-50 + version = new DefaultArtifactVersion ("2.1.0-M1-RC12"); + assertTrue( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "[2.1.0-M1-RC12,)" ), version ) ); + assertFalse( AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( "[2.1.0-M1,)" ), version ) ); + + } + + /** + * Enforce false. + * + * @param rule the rule + * @param log the log + * @param var the var + * @param range the range + * @param version the version + */ + private void enforceFalse( AbstractVersionEnforcer rule, Log log, String var, String range, ArtifactVersion version ) + { + try + { + rule.enforceVersion( log, var, range, version ); + fail( "Expected to receive EnforcerRuleException because:" + version + " is not contained by " + range ); + } + catch ( Exception e ) + { + if ( e instanceof EnforcerRuleException ) + { + // log.info( "Caught Expected Exception: " + + // e.getLocalizedMessage() ); + } + else + { + fail( "Received wrong exception. Expected EnforcerRuleExeption. Received:" + e.toString() ); + } + } + } + + /** + * Test enforce version. + */ + public void testEnforceVersion() + { + RequireMavenVersion rule = new RequireMavenVersion(); + ArtifactVersion version = new DefaultArtifactVersion( "2.0.5" ); + SystemStreamLog log = new SystemStreamLog(); + // test ranges + + // not matching versions + try + { + rule.enforceVersion( log, "test", "[2.0.5,)", version ); + rule.enforceVersion( log, "test", "[2.0.4,)", version ); + rule.enforceVersion( log, "test", "[2.0.4,2.0.5]", version ); + rule.enforceVersion( log, "test", "[2.0.4,2.0.6]", version ); + rule.enforceVersion( log, "test", "[2.0.4,2.0.6)", version ); + rule.enforceVersion( log, "test", "[2.0,)", version ); + rule.enforceVersion( log, "test", "[2.0.0,)", version ); + + // test singular versions -> 2.0.5 == [2.0.5,) or x >= 2.0.5 + rule.enforceVersion( log, "test", "2.0", version ); + rule.enforceVersion( log, "test", "2.0.4", version ); + rule.enforceVersion( log, "test", "2.0.5", version ); + } + catch ( Exception e ) + { + fail( "No Exception expected. Caught:" + e.getLocalizedMessage() ); + + } + + enforceFalse( rule, log, "test", "[2.0.6,)", version ); + enforceFalse( rule, log, "test", "(2.0.5,)", version ); + enforceFalse( rule, log, "test", "2.0.6", version ); + + enforceFalse( rule, log, "test", "[2.0.4,2.0.5)", version ); + + // make sure to handle the invalid range specification + enforceFalse( rule, log, "test", "[[2.0.4,2.0.5)", version ); + + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestAlwaysFail.java b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestAlwaysFail.java new file mode 100644 index 000000000..cf34d3337 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestAlwaysFail.java @@ -0,0 +1,49 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import junit.framework.TestCase; + +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; + +/** + * Test AlwaysFail rule. + * @author Ben Lidgey + * @see AlwaysFail + */ +public class TestAlwaysFail extends TestCase +{ + + public void testExecute() + { + final AlwaysFail rule = new AlwaysFail(); + try + { + // execute rule -- should throw EnforcerRuleException + rule.execute( EnforcerTestUtils.getHelper() ); + fail( "Should throw EnforcerRuleException" ); + } + catch ( EnforcerRuleException e ) + { + assertTrue( true ); + } + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestAlwaysPass.java b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestAlwaysPass.java new file mode 100644 index 000000000..60b1cc575 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestAlwaysPass.java @@ -0,0 +1,49 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import junit.framework.TestCase; + +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; + +/** + * Test AlwaysPass rule. + * @author Ben Lidgey + * @see AlwaysPass + */ +public class TestAlwaysPass extends TestCase +{ + + public void testExecute() + { + final AlwaysPass rule = new AlwaysPass(); + try + { + // execute rule -- should NOT throw EnforcerRuleException + rule.execute( EnforcerTestUtils.getHelper() ); + assertTrue( true ); + } + catch ( EnforcerRuleException e ) + { + fail( "Should NOT throw EnforcerRuleException" ); + } + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestBannedDependencies.java b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestBannedDependencies.java new file mode 100644 index 000000000..06f2b5568 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestBannedDependencies.java @@ -0,0 +1,312 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.io.IOException; + +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.runners.Enclosed; +import org.junit.runner.RunWith; + +/** + * The Class TestBannedDependencies. + * + * @author Brian Fox + */ +@RunWith( Enclosed.class ) +public class TestBannedDependencies +{ + + public static class ExcludesDoNotUseTransitiveDependencies + { + private BannedDependenciesTestSetup setup; + + @Before + public void beforeMethod() + throws IOException + { + this.setup = new BannedDependenciesTestSetup(); + this.setup.setSearchTransitive( false ); + } + + private void addExcludeAndRunRule( String toAdd ) + throws EnforcerRuleException + { + this.setup.addExcludeAndRunRule( toAdd ); + } + + @Test + public void testGroupIdArtifactIdVersion() + throws Exception + { + addExcludeAndRunRule( "testGroupId:release:1.0" ); + } + + @Test + public void testGroupIdArtifactId() + throws Exception + { + addExcludeAndRunRule( "testGroupId:release" ); + } + + @Test + public void testGroupId() + throws Exception + { + addExcludeAndRunRule( "testGroupId" ); + } + + } + + public static class ExcludesUsingTransitiveDependencies + { + + private BannedDependenciesTestSetup setup; + + @Before + public void beforeMethod() + throws IOException + { + this.setup = new BannedDependenciesTestSetup(); + this.setup.setSearchTransitive( true ); + } + + private void addExcludeAndRunRule( String toAdd ) + throws EnforcerRuleException + { + this.setup.addExcludeAndRunRule( toAdd ); + } + + @Test( expected = EnforcerRuleException.class ) + public void testGroupIdArtifactIdVersion() + throws Exception + { + addExcludeAndRunRule( "testGroupId:release:1.0" ); + } + + @Test( expected = EnforcerRuleException.class ) + public void testGroupIdArtifactId() + throws Exception + { + addExcludeAndRunRule( "testGroupId:release" ); + } + + @Test( expected = EnforcerRuleException.class ) + public void testGroupId() + throws Exception + { + addExcludeAndRunRule( "testGroupId" ); + } + + @Test( expected = EnforcerRuleException.class ) + public void testSpaceTrimmingGroupIdArtifactIdVersion() + throws Exception + { + addExcludeAndRunRule( " testGroupId : release : 1.0 " ); + } + + @Test( expected = EnforcerRuleException.class ) + public void groupIdArtifactIdVersionType() + throws Exception + { + addExcludeAndRunRule( "g:a:1.0:war" ); + } + + @Test( expected = EnforcerRuleException.class ) + public void groupIdArtifactIdVersionTypeScope() + throws Exception + { + addExcludeAndRunRule( "g:a:1.0:war:compile" ); + } + + // @Test(expected = EnforcerRuleException.class) + // public void groupIdArtifactIdVersionTypeScopeClassifier() throws Exception { + // addExcludeAndRunRule("g:compile:1.0:jar:compile:one"); + // } + // + } + + public static class WildcardExcludesUsingTransitiveDependencies + { + + private BannedDependenciesTestSetup setup; + + @Before + public void beforeMethod() + throws IOException + { + this.setup = new BannedDependenciesTestSetup(); + this.setup.setSearchTransitive( true ); + } + + private void addExcludeAndRunRule( String toAdd ) + throws EnforcerRuleException + { + this.setup.addExcludeAndRunRule( toAdd ); + } + + @Test + public void testWildcardForGroupIdArtifactIdVersion() + throws Exception + { + addExcludeAndRunRule( "*:release:1.2" ); + } + + @Test( expected = EnforcerRuleException.class ) + public void testWildCardForGroupIdArtifactId() + throws Exception + { + addExcludeAndRunRule( "*:release" ); + } + + @Test( expected = EnforcerRuleException.class ) + public void testWildcardForGroupIdWildcardForArtifactIdVersion() + throws Exception + { + addExcludeAndRunRule( "*:*:1.0" ); + } + + @Test( expected = EnforcerRuleException.class ) + public void testWildcardForGroupIdArtifactIdWildcardForVersion() + throws Exception + { + addExcludeAndRunRule( "*:release:*" ); + } + + } + + public static class PartialWildcardExcludesUsingTransitiveDependencies + { + + private BannedDependenciesTestSetup setup; + + @Before + public void beforeMethod() + throws IOException + { + this.setup = new BannedDependenciesTestSetup(); + this.setup.setSearchTransitive( true ); + } + + private void addExcludeAndRunRule( String toAdd ) + throws EnforcerRuleException + { + this.setup.addExcludeAndRunRule( toAdd ); + } + + @Test( expected = EnforcerRuleException.class ) + public void groupIdArtifactIdWithWildcard() + throws EnforcerRuleException + { + addExcludeAndRunRule( "testGroupId:re*" ); + } + + @Test( expected = EnforcerRuleException.class ) + public void groupIdArtifactIdVersionTypeWildcardScope() + throws EnforcerRuleException + { + addExcludeAndRunRule( "g:a:1.0:war:co*" ); + } + + @Test( expected = EnforcerRuleException.class ) + public void groupIdArtifactIdVersionWildcardTypeScope() + throws EnforcerRuleException + { + addExcludeAndRunRule( "g:a:1.0:w*:compile" ); + } + } + + public static class IllegalFormatsTests + { + private BannedDependenciesTestSetup setup; + + @Before + public void beforeMethod() + throws IOException + { + this.setup = new BannedDependenciesTestSetup(); + this.setup.setSearchTransitive( true ); + } + + private void addExcludeAndRunRule( String toAdd ) + throws EnforcerRuleException + { + this.setup.addExcludeAndRunRule( toAdd ); + } + + @Test( expected = IllegalArgumentException.class ) + public void onlyThreeColonsWithoutAnythingElse() + throws EnforcerRuleException + { + addExcludeAndRunRule( ":::" ); + } + + @Test( expected = IllegalArgumentException.class ) + public void onlySevenColonsWithoutAnythingElse() + throws EnforcerRuleException + { + addExcludeAndRunRule( ":::::::" ); + } + + } + + public static class IncludesExcludesNoTransitive + { + private BannedDependenciesTestSetup setup; + + @Before + public void beforeMethod() + throws IOException + { + this.setup = new BannedDependenciesTestSetup(); + this.setup.setSearchTransitive( false ); + } + + private void addIncludeExcludeAndRunRule( String incAdd, String excAdd ) + throws EnforcerRuleException + { + this.setup.addIncludeExcludeAndRunRule( incAdd, excAdd ); + } + + @Test + public void includeEverythingAndExcludeEverythign() + throws EnforcerRuleException + { + addIncludeExcludeAndRunRule( "*", "*" ); + } + + @Test + public void includeEverythingAndExcludeEveryGroupIdAndScopeRuntime() + throws EnforcerRuleException + { + addIncludeExcludeAndRunRule( "*", "*:runtime" ); + } + + @Test( expected = EnforcerRuleException.class ) + public void includeEverythingAndExcludeEveryGroupIdAndScopeRuntimeYYYY() + throws EnforcerRuleException + { + addIncludeExcludeAndRunRule( "*:test", "*:runtime" ); + } + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestBannedRepositories.java b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestBannedRepositories.java new file mode 100644 index 000000000..e27ee8672 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestBannedRepositories.java @@ -0,0 +1,159 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.util.ArrayList; +import java.util.List; + +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.DefaultArtifactRepository; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.codehaus.plexus.PlexusTestCase; + +/** + * Test the "banned repositories" rule. + * + * @author Simon Wang + */ +public class TestBannedRepositories + extends PlexusTestCase +{ + private EnforcerRuleHelper helper; + + private BannedRepositories rule; + + private MockProject project; + + public void setUp() + throws Exception + { + super.setUp(); + + rule = new BannedRepositories(); + rule.setMessage( "my message" ); + + project = new MockProject(); + project.setGroupId( "org.apache.maven.plugins.enforcer.test" ); + project.setVersion( "1.0-SNAPSHOT" ); + + helper = EnforcerTestUtils.getHelper( project ); + } + + public void testNoCheckRules() + throws EnforcerRuleException + { + DefaultArtifactRepository repo1 = new DefaultArtifactRepository( "repo1", "http://repo1/", null ); + List repos = new ArrayList(); + repos.add( repo1 ); + + project.setRemoteArtifactRepositories( repos ); + project.setPluginArtifactRepositories( repos ); + + rule.execute( helper ); + } + + public void testBannedRepositories() + { + DefaultArtifactRepository repo1 = new DefaultArtifactRepository( "repo1", "http://repo1/", null ); + DefaultArtifactRepository repo2 = new DefaultArtifactRepository( "repo1", "http://repo1/test", null ); + DefaultArtifactRepository repo3 = new DefaultArtifactRepository( "repo1", "http://repo2/test", null ); + List repos = new ArrayList(); + repos.add( repo1 ); + repos.add( repo2 ); + repos.add( repo3 ); + + project.setRemoteArtifactRepositories( repos ); + project.setPluginArtifactRepositories( repos ); + + List bannedRepositories = new ArrayList(); + String pattern1 = "http://repo1/*"; + + bannedRepositories.add( pattern1 ); + + rule.setBannedRepositories( bannedRepositories ); + + try + { + rule.execute( helper ); + fail( "should throw exception" ); + } + catch ( EnforcerRuleException e ) + { + } + + } + + public void testAllowedRepositoriesAllOK() + throws EnforcerRuleException + { + DefaultArtifactRepository repo1 = new DefaultArtifactRepository( "repo1", "http://repo1/", null ); + DefaultArtifactRepository repo2 = new DefaultArtifactRepository( "repo1", "http://repo1/test", null ); + + List repos = new ArrayList(); + repos.add( repo1 ); + repos.add( repo2 ); + + project.setRemoteArtifactRepositories( repos ); + project.setPluginArtifactRepositories( repos ); + + List bannedRepositories = new ArrayList(); + String pattern1 = "http://repo1/*"; + + bannedRepositories.add( pattern1 ); + + rule.setAllowedRepositories( bannedRepositories ); + rule.setAllowedPluginRepositories( bannedRepositories ); + + rule.execute( helper ); + } + + public void testAllowedRepositoriesException() + { + DefaultArtifactRepository repo1 = new DefaultArtifactRepository( "repo1", "http://repo1/", null ); + DefaultArtifactRepository repo2 = new DefaultArtifactRepository( "repo1", "http://repo1/test", null ); + DefaultArtifactRepository repo3 = new DefaultArtifactRepository( "repo1", "http://repo2/test", null ); + List repos = new ArrayList(); + repos.add( repo1 ); + repos.add( repo2 ); + repos.add( repo3 ); + + project.setRemoteArtifactRepositories( repos ); + project.setPluginArtifactRepositories( repos ); + + List patterns = new ArrayList(); + String pattern1 = "http://repo1/*"; + + patterns.add( pattern1 ); + + rule.setAllowedPluginRepositories( patterns ); + rule.setAllowedRepositories( patterns ); + + try + { + rule.execute( helper ); + fail( "should throw exception" ); + } + catch ( EnforcerRuleException e ) + { + } + + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestEvaluateBeanshell.java b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestEvaluateBeanshell.java new file mode 100644 index 000000000..f78729f18 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestEvaluateBeanshell.java @@ -0,0 +1,255 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import junit.framework.TestCase; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +import static org.mockito.Mockito.*; + +/** + * The Class TestEvaluateBeanshell. + * + * @author hugonnem + */ +public class TestEvaluateBeanshell + extends TestCase +{ + private MockProject project; + + public void setUp() + { + project = new MockProject(); + project.setProperty( "env", "\"This is a test.\"" ); + } + + /** + * Test rule. + */ + public void testRulePass() + throws EnforcerRuleException, ExpressionEvaluationException + { + EvaluateBeanshell rule = new EvaluateBeanshell(); + // this property should not be set + rule.setCondition( "${env} == \"This is a test.\"" ); + rule.setMessage( "We have a variable : ${env}" ); + + EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( project ); + rule.execute( helper ); + } + + public void testRuleFail() + throws EnforcerRuleException, ExpressionEvaluationException + { + EvaluateBeanshell rule = new EvaluateBeanshell(); + // this property should be set by the surefire + // plugin + rule.setCondition( "${env} == null" ); + rule.setMessage( "We have a variable : ${env}" ); + + try + { + EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( project ); + rule.execute( helper ); + fail( "Expected an exception." ); + } + catch ( EnforcerRuleException e ) + { + assertEquals( e.getLocalizedMessage(), rule.getMessage() ); + } + } + + public void testRuleFailNoMessage() + throws EnforcerRuleException, ExpressionEvaluationException + { + EvaluateBeanshell rule = new EvaluateBeanshell(); + // this property should be set by the surefire + // plugin + rule.setCondition( "${env} == null" ); + try + { + EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( project ); + rule.execute( helper ); + fail( "Expected an exception." ); + } + catch ( EnforcerRuleException e ) + { + assertEquals( e.getLocalizedMessage(), "The expression \"${env} == null\" is not true." ); + assertTrue( e.getLocalizedMessage().length() > 0 ); + } + } + + public void testRuleInvalidExpression() + throws EnforcerRuleException, ExpressionEvaluationException + { + EvaluateBeanshell rule = new EvaluateBeanshell(); + rule.setCondition( "${env} == null" ); + rule.setMessage( "We have a variable : ${env}" ); + + ExpressionEvaluator eval = mock( ExpressionEvaluator.class ); + when( eval.evaluate( rule.getCondition() ) ).thenThrow( new ExpressionEvaluationException( "expected error" ) ); + try + { + EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( project, eval ); + rule.execute( helper ); + fail( "Expected an exception." ); + } + catch ( EnforcerRuleException e ) + { + assertFalse( e.getLocalizedMessage().equals( rule.getMessage() ) ); + } + } + + public void testRuleInvalidBeanshell() + throws EnforcerRuleException, ExpressionEvaluationException + { + EvaluateBeanshell rule = new EvaluateBeanshell(); + rule.setCondition( "this is not valid beanshell" ); + rule.setMessage( "We have a variable : ${env}" ); + try + { + EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( project ); + rule.execute( helper ); + fail( "Expected an exception." ); + } + catch ( EnforcerRuleException e ) + { + assertFalse( e.getLocalizedMessage().equals( rule.getMessage() ) ); + } + } + + + public void testRuleCanExecuteMultipleThreads() throws InterruptedException { + final String condition = "String property1 = \"${property1}\";\n" + + "(property1.equals(\"prop0\") && \"${property2}\".equals(\"prop0\"))\n" + + "|| (property1.equals(\"prop1\") && \"${property2}\".equals(\"prop1\"))\n" + + "|| (property1.equals(\"prop2\") && \"${property2}\".equals(\"prop2\"))\n"; + + final List runnables = new ArrayList<>(); + + runnables.add(new Runnable() { + @Override + public void run() { + final int threadNumber = 0; + MockProject multiProject = new MockProject(); + multiProject.setProperty("property1", "prop" + threadNumber); + multiProject.setProperty("property2", "prop" + threadNumber); + + EvaluateBeanshell rule = new EvaluateBeanshell(); + rule.setCondition(condition); + rule.setMessage("Race condition in thread " + threadNumber); + EnforcerRuleHelper helper = EnforcerTestUtils.getHelper(multiProject); + try { + rule.execute(helper); + + } catch (EnforcerRuleException e) { + throw new RuntimeException(e); + } + } + }); + runnables.add(new Runnable() { + @Override + public void run() { + final int threadNumber = 1; + MockProject multiProject = new MockProject(); + multiProject.setProperty("property1", "prop" + threadNumber); + multiProject.setProperty("property2", "prop" + threadNumber); + + EvaluateBeanshell rule = new EvaluateBeanshell(); + rule.setCondition(condition); + rule.setMessage("Race condition in thread " + threadNumber); + EnforcerRuleHelper helper = EnforcerTestUtils.getHelper(multiProject); + try { + rule.execute(helper); + + } catch (EnforcerRuleException e) { + throw new RuntimeException(e); + } + + } + }); + runnables.add(new Runnable() { + @Override + public void run() { + final int threadNumber = 2; + MockProject multiProject = new MockProject(); + multiProject.setProperty("property1", "prop" + threadNumber); + multiProject.setProperty("property2", "prop" + threadNumber); + + EvaluateBeanshell rule = new EvaluateBeanshell(); + rule.setCondition(condition); + rule.setMessage("Race condition in thread " + threadNumber); + EnforcerRuleHelper helper = EnforcerTestUtils.getHelper(multiProject); + try { + rule.execute(helper); + } catch (EnforcerRuleException e) { + throw new RuntimeException(e); + } + } + }); + + assertConcurrent( runnables, 4); + } + + private static void assertConcurrent(final List runnables, final int maxTimeoutSeconds) throws InterruptedException { + final int numThreads = runnables.size(); + final List exceptions = Collections.synchronizedList(new ArrayList()); + final ExecutorService threadPool = Executors.newFixedThreadPool(numThreads); + try { + final CountDownLatch allExecutorThreadsReady = new CountDownLatch(numThreads); + final CountDownLatch afterInitBlocker = new CountDownLatch(1); + final CountDownLatch allDone = new CountDownLatch(numThreads); + for (final Runnable submittedTestRunnable : runnables) { + threadPool.submit(new Runnable() { + public void run() { + allExecutorThreadsReady.countDown(); + try { + afterInitBlocker.await(); + submittedTestRunnable.run(); + } catch (final Throwable e) { + exceptions.add(e); + } finally { + allDone.countDown(); + } + } + }); + } + // wait until all threads are ready + assertTrue("Timeout initializing threads! Perform long lasting initializations before passing runnables to assertConcurrent", allExecutorThreadsReady.await(runnables.size() * 10, TimeUnit.MILLISECONDS)); + // start all test runners + afterInitBlocker.countDown(); + assertTrue("Timeout! More than" + maxTimeoutSeconds + "seconds", allDone.await(maxTimeoutSeconds, TimeUnit.SECONDS)); + } finally { + threadPool.shutdownNow(); + } + assertTrue("Failed with exception(s)" + exceptions, exceptions.isEmpty()); + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestMavenVersion.java b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestMavenVersion.java new file mode 100644 index 000000000..581bd8281 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestMavenVersion.java @@ -0,0 +1,80 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; + +import junit.framework.TestCase; + +/** + * The Class TestMavenVersion. + * + * @author Brian Fox + */ +public class TestMavenVersion + extends TestCase +{ + + /** + * Test rule. + * + * @throws EnforcerRuleException the enforcer rule exception + */ + public void testRule() + throws EnforcerRuleException + { + + RequireMavenVersion rule = new RequireMavenVersion(); + rule.setVersion( "2.0.5" ); + + EnforcerRuleHelper helper = EnforcerTestUtils.getHelper(); + + // test the singular version + rule.execute( helper ); + + // exclude this version + rule.setVersion( "(2.0.5" ); + + try + { + rule.execute( helper ); + fail( "Expected an exception." ); + } + catch ( EnforcerRuleException e ) + { + // expected to catch this. + } + + // this shouldn't crash + rule.setVersion( "2.0.5_01" ); + rule.execute( helper ); + + } + + /** + * Test id. + */ + public void testId() + { + RequireMavenVersion rule = new RequireMavenVersion(); + rule.getCacheId(); + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireEnvironmentVariable.java b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireEnvironmentVariable.java new file mode 100755 index 000000000..27ba381ca --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireEnvironmentVariable.java @@ -0,0 +1,111 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import junit.framework.TestCase; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; + +/** + * Unit test for {@link RequireEnvironmentVariable}} + * + * @author Marvin Froeder + */ +public class TestRequireEnvironmentVariable + extends TestCase +{ + + /** + * Test rule. + * + * @throws EnforcerRuleException the enforcer rule exception + */ + public void testRule() + throws EnforcerRuleException + { + MockProject project = new MockProject(); + project.setProperty( "testProp", "This is a test." ); + EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( project ); + + RequireEnvironmentVariable rule = new RequireEnvironmentVariable(); + // this env variable should not be set + rule.setVariableName( "JUNK" ); + + try + { + rule.execute( helper ); + fail( "Expected an exception." ); + } + catch ( EnforcerRuleException e ) + { + // expected to catch this. + } + + // PATH shall be common to windows and linux + rule.setVariableName( "PATH" ); + try + { + rule.execute( helper ); + } + catch ( EnforcerRuleException e ) + { + fail( "This should not throw an exception" ); + } + } + + /** + * Test rule with regex. + * + * @throws EnforcerRuleException the enforcer rule exception + */ + public void testRuleWithRegex() + throws EnforcerRuleException + { + EnforcerRuleHelper helper = EnforcerTestUtils.getHelper(); + + RequireEnvironmentVariable rule = new RequireEnvironmentVariable(); + rule.setVariableName( "PATH" ); + // This expression should not match the property + // value + rule.setRegex( "[^abc]" ); + + try + { + rule.execute( helper ); + fail( "Expected an exception." ); + } + catch ( EnforcerRuleException e ) + { + // expected to catch this. + } + + // can't really predict what a PATH will looks like, just enforce it ain't empty + rule.setRegex( ".{1,}" ); + try + { + rule.execute( helper ); + } + catch ( EnforcerRuleException e ) + { + fail( "This should not throw an exception" ); + } + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireFileChecksum.java b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireFileChecksum.java new file mode 100644 index 000000000..c7075ce60 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireFileChecksum.java @@ -0,0 +1,287 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.io.File; +import java.io.IOException; + +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.codehaus.plexus.util.FileUtils; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.rules.TemporaryFolder; + +/** + * Test the "RequireFileChecksum" rule + * + * @author Lyubomyr Shaydariv + */ +public class TestRequireFileChecksum +{ + + private RequireFileChecksum rule = new RequireFileChecksum(); + + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + @Test + public void testFileChecksumMd5() + throws IOException, EnforcerRuleException + { + File f = temporaryFolder.newFile(); + FileUtils.fileWrite( f, "message" ); + + rule.setFile( f ); + rule.setChecksum( "78e731027d8fd50ed642340b7c9a63b3" ); + rule.setType( "md5" ); + + rule.execute( EnforcerTestUtils.getHelper() ); + } + + @Test + public void testFileChecksumMd5UpperCase() + throws IOException, EnforcerRuleException + { + File f = temporaryFolder.newFile(); + FileUtils.fileWrite( f, "message" ); + + rule.setFile( f ); + rule.setChecksum( "78E731027D8FD50ED642340B7C9A63B3" ); + rule.setType( "md5" ); + + rule.execute( EnforcerTestUtils.getHelper() ); + } + + @Test + public void testFileChecksumMd5GivenFileDoesNotExistFailure() + throws IOException, EnforcerRuleException + { + File f = new File( "nonExistent" ); + + expectedException.expect( EnforcerRuleException.class ); + expectedException.expectMessage( "File does not exist: " + f.getAbsolutePath() ); + + rule.setFile( f ); + rule.setChecksum( "78e731027d8fd50ed642340b7c9a63b3" ); + rule.setType( "md5" ); + + rule.execute( EnforcerTestUtils.getHelper() ); + } + + @Test + public void testFileChecksumMd5GivenFileDoesNotExistFailureWithMessage() + throws IOException, EnforcerRuleException + { + File f = new File( "nonExistent" ); + String configuredMessage = "testMessageFileDoesNotExist"; + + expectedException.expect( EnforcerRuleException.class ); + expectedException.expectMessage( configuredMessage ); + + rule.setFile( f ); + rule.setChecksum( "78e731027d8fd50ed642340b7c9a63b3" ); + rule.setType( "md5" ); + rule.setNonexistentFileMessage( configuredMessage ); + + rule.execute( EnforcerTestUtils.getHelper() ); + } + + @Test + public void testFileChecksumMd5GivenFileIsNotReadableFailure() + throws IOException, EnforcerRuleException + { + File f = temporaryFolder.newFile(); + f = new File( f.getAbsolutePath() ) + { + private static final long serialVersionUID = 6987790643999338089L; + + @Override + public boolean canRead() + { + return false; + } + }; + + expectedException.expect( EnforcerRuleException.class ); + expectedException.expectMessage( "Cannot read file: " + f.getAbsolutePath() ); + + rule.setFile( f ); + rule.setChecksum( "78e731027d8fd50ed642340b7c9a63b3" ); + rule.setType( "md5" ); + + rule.execute( EnforcerTestUtils.getHelper() ); + } + + @Test + public void testFileChecksumMd5GivenFileIsADirectoryFailure() + throws IOException, EnforcerRuleException + { + File f = temporaryFolder.newFolder(); + + expectedException.expect( EnforcerRuleException.class ); + expectedException.expectMessage( "Cannot calculate the checksum of directory: " + f.getAbsolutePath() ); + + rule.setFile( f ); + rule.setChecksum( "78e731027d8fd50ed642340b7c9a63b3" ); + rule.setType( "md5" ); + + rule.execute( EnforcerTestUtils.getHelper() ); + } + + @Test + public void testFileChecksumMd5NoFileSpecifiedFailure() + throws IOException, EnforcerRuleException + { + expectedException.expect( EnforcerRuleException.class ); + expectedException.expectMessage( "Input file unspecified" ); + + rule.setChecksum( "78e731027d8fd50ed642340b7c9a63b3" ); + rule.setType( "md5" ); + + rule.execute( EnforcerTestUtils.getHelper() ); + } + + @Test + public void testFileChecksumMd5NoChecksumSpecifiedFailure() + throws IOException, EnforcerRuleException + { + expectedException.expect( EnforcerRuleException.class ); + expectedException.expectMessage( "Checksum unspecified" ); + + File f = temporaryFolder.newFile(); + + rule.setFile( f ); + rule.setType( "md5" ); + + rule.execute( EnforcerTestUtils.getHelper() ); + } + + @Test + public void testFileChecksumMd5NoTypeSpecifiedFailure() + throws IOException, EnforcerRuleException + { + expectedException.expect( EnforcerRuleException.class ); + expectedException.expectMessage( "Hash type unspecified" ); + + File f = temporaryFolder.newFile(); + + rule.setFile( f ); + rule.setChecksum( "78e731027d8fd50ed642340b7c9a63b3" ); + + rule.execute( EnforcerTestUtils.getHelper() ); + } + + @Test + public void testFileChecksumMd5ChecksumMismatchFailure() + throws IOException, EnforcerRuleException + { + File f = temporaryFolder.newFile(); + FileUtils.fileWrite( f, "message" ); + + expectedException.expect( EnforcerRuleException.class ); + expectedException.expectMessage( "md5 hash of " + f.getAbsolutePath() + + " was 78e731027d8fd50ed642340b7c9a63b3 but expected ffeeddccbbaa99887766554433221100" ); + + rule.setFile( f ); + rule.setChecksum( "ffeeddccbbaa99887766554433221100" ); + rule.setType( "md5" ); + + rule.execute( EnforcerTestUtils.getHelper() ); + } + + @Test + public void testFileChecksumMd5ChecksumMismatchFailureWithMessage() + throws IOException, EnforcerRuleException + { + File f = temporaryFolder.newFile(); + FileUtils.fileWrite( f, "message" ); + String configuredMessage = "testMessage"; + + expectedException.expect( EnforcerRuleException.class ); + expectedException.expectMessage( configuredMessage ); + + rule.setFile( f ); + rule.setChecksum( "ffeeddccbbaa99887766554433221100" ); + rule.setType( "md5" ); + rule.setMessage( configuredMessage ); + + rule.execute( EnforcerTestUtils.getHelper() ); + } + + @Test + public void testFileChecksumSha1() + throws IOException, EnforcerRuleException + { + File f = temporaryFolder.newFile(); + FileUtils.fileWrite( f, "message" ); + + rule.setFile( f ); + rule.setChecksum( "6f9b9af3cd6e8b8a73c2cdced37fe9f59226e27d" ); + rule.setType( "sha1" ); + + rule.execute( EnforcerTestUtils.getHelper() ); + } + + @Test + public void testFileChecksumSha256() + throws IOException, EnforcerRuleException + { + File f = temporaryFolder.newFile(); + FileUtils.fileWrite( f, "message" ); + + rule.setFile( f ); + rule.setChecksum( "ab530a13e45914982b79f9b7e3fba994cfd1f3fb22f71cea1afbf02b460c6d1d" ); + rule.setType( "sha256" ); + + rule.execute( EnforcerTestUtils.getHelper() ); + } + + @Test + public void testFileChecksumSha384() + throws IOException, EnforcerRuleException + { + File f = temporaryFolder.newFile(); + FileUtils.fileWrite( f, "message" ); + + rule.setFile( f ); + rule.setChecksum( "353eb7516a27ef92e96d1a319712d84b902eaa828819e53a8b09af7028103a9978ba8feb6161e33c3619c5da4c4666a5" ); + rule.setType( "sha384" ); + + rule.execute( EnforcerTestUtils.getHelper() ); + } + + @Test + public void testFileChecksumSha512() + throws IOException, EnforcerRuleException + { + File f = temporaryFolder.newFile(); + FileUtils.fileWrite( f, "message" ); + + rule.setFile( f ); + rule.setChecksum( "f8daf57a3347cc4d6b9d575b31fe6077e2cb487f60a96233c08cb479dbf31538cc915ec6d48bdbaa96ddc1a16db4f4f96f37276cfcb3510b8246241770d5952c" ); + rule.setType( "sha512" ); + + rule.execute( EnforcerTestUtils.getHelper() ); + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireFilesDontExist.java b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireFilesDontExist.java new file mode 100644 index 000000000..22287a4d0 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireFilesDontExist.java @@ -0,0 +1,142 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.io.File; +import java.io.IOException; + +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; + +import junit.framework.TestCase; + +/** + * Test the "require files don't exist" rule. + * + * @author Brian Fox + */ +public class TestRequireFilesDontExist + extends TestCase +{ + RequireFilesDontExist rule = new RequireFilesDontExist(); + + public void testFileExists() + throws EnforcerRuleException, IOException + { + File f = File.createTempFile( "enforcer", "tmp" ); + f.deleteOnExit(); + + rule.setFiles( new File[] { f } ); + + try + { + rule.execute( EnforcerTestUtils.getHelper() ); + fail( "Expected an Exception." ); + } + catch ( EnforcerRuleException e ) + { + assertTrue( true ); + } + f.delete(); + } + + public void testEmptyFile() + throws EnforcerRuleException, IOException + { + rule.setFiles( new File[] { null } ); + try + { + rule.execute( EnforcerTestUtils.getHelper() ); + fail( "Should get exception" ); + } + catch ( EnforcerRuleException e ) + { + assertTrue( true ); + } + } + + public void testEmptyFileAllowNull() + throws EnforcerRuleException, IOException + { + rule.setFiles( new File[] { null } ); + rule.setAllowNulls( true ); + try + { + rule.execute( EnforcerTestUtils.getHelper() ); + } + catch ( EnforcerRuleException e ) + { + fail( "Unexpected Exception:" + e.getLocalizedMessage() ); + } + } + + public void testEmptyFileList() + throws EnforcerRuleException, IOException + { + rule.setFiles( new File[] {} ); + assertEquals( 0, rule.getFiles().length ); + try + { + rule.execute( EnforcerTestUtils.getHelper() ); + fail( "Should get exception" ); + } + catch ( EnforcerRuleException e ) + { + assertTrue( true ); + } + } + + public void testEmptyFileListAllowNull() + throws EnforcerRuleException, IOException + { + rule.setFiles( new File[] {} ); + assertEquals( 0, rule.getFiles().length ); + rule.setAllowNulls( true ); + try + { + rule.execute( EnforcerTestUtils.getHelper() ); + } + catch ( EnforcerRuleException e ) + { + fail( "Unexpected Exception:" + e.getLocalizedMessage() ); + } + } + + public void testFileDoesNotExist() + throws EnforcerRuleException, IOException + { + File f = File.createTempFile( "enforcer", "tmp" ); + f.delete(); + + assertTrue( !f.exists() ); + + rule.setFiles( new File[] { f } ); + + rule.execute( EnforcerTestUtils.getHelper() ); + } + + /** + * Test id. + */ + public void testId() + { + rule.getCacheId(); + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireFilesExist.java b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireFilesExist.java new file mode 100644 index 000000000..b05a4fb6e --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireFilesExist.java @@ -0,0 +1,141 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.io.File; +import java.io.IOException; + +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; + +import junit.framework.TestCase; + +/** + * Test the "require files exist" rule. + * + * @author Brett Porter + */ +public class TestRequireFilesExist + extends TestCase +{ + RequireFilesExist rule = new RequireFilesExist(); + + public void testFileExists() + throws EnforcerRuleException, IOException + { + File f = File.createTempFile( "enforcer", "tmp" ); + f.deleteOnExit(); + + rule.setFiles( new File[] { f } ); + + rule.execute( EnforcerTestUtils.getHelper() ); + + f.delete(); + } + + public void testEmptyFile() + throws EnforcerRuleException, IOException + { + rule.setFiles( new File[] { null } ); + try + { + rule.execute( EnforcerTestUtils.getHelper() ); + fail( "Should get exception" ); + } + catch ( EnforcerRuleException e ) + { + assertTrue( true ); + } + } + + public void testEmptyFileAllowNull() + throws EnforcerRuleException, IOException + { + rule.setFiles( new File[] { null } ); + rule.setAllowNulls( true ); + try + { + rule.execute( EnforcerTestUtils.getHelper() ); + } + catch ( EnforcerRuleException e ) + { + fail( "Unexpected Exception:" + e.getLocalizedMessage() ); + } + } + + public void testEmptyFileList() + throws EnforcerRuleException, IOException + { + rule.setFiles( new File[] {} ); + assertEquals( 0, rule.getFiles().length ); + try + { + rule.execute( EnforcerTestUtils.getHelper() ); + fail( "Should get exception" ); + } + catch ( EnforcerRuleException e ) + { + assertTrue( true ); + } + } + + public void testEmptyFileListAllowNull() + throws EnforcerRuleException, IOException + { + rule.setFiles( new File[] {} ); + assertEquals( 0, rule.getFiles().length ); + rule.setAllowNulls( true ); + try + { + rule.execute( EnforcerTestUtils.getHelper() ); + } + catch ( EnforcerRuleException e ) + { + fail( "Unexpected Exception:" + e.getLocalizedMessage() ); + } + } + + public void testFileDoesNotExist() + throws EnforcerRuleException, IOException + { + File f = File.createTempFile( "enforcer", "tmp" ); + f.delete(); + assertTrue( !f.exists() ); + rule.setFiles( new File[] { f } ); + + try + { + rule.execute( EnforcerTestUtils.getHelper() ); + fail( "Should get exception" ); + } + catch ( EnforcerRuleException e ) + { + assertTrue( true ); + } + } + + /** + * Test id. + */ + public void testId() + { + rule.getCacheId(); + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireFilesSize.java b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireFilesSize.java new file mode 100644 index 000000000..93996cff3 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireFilesSize.java @@ -0,0 +1,188 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.plugin.testing.ArtifactStubFactory; + +import junit.framework.TestCase; + +/** + * Test the "require files exist" rule. + * + * @author Brian Fox + */ +public class TestRequireFilesSize + extends TestCase +{ + RequireFilesSize rule = new RequireFilesSize(); + + public void testFileExists() + throws EnforcerRuleException, IOException + { + File f = File.createTempFile( "enforcer", "tmp" ); + f.deleteOnExit(); + + rule.setFiles( new File[] { f } ); + + rule.execute( EnforcerTestUtils.getHelper() ); + + f.delete(); + } + + public void testEmptyFile() + throws EnforcerRuleException, IOException + { + rule.setFiles( new File[] { null } ); + try + { + rule.execute( EnforcerTestUtils.getHelper() ); + fail( "Should get exception" ); + } + catch ( EnforcerRuleException e ) + { + assertTrue( true ); + } + } + + public void testEmptyFileAllowNull() + throws EnforcerRuleException, IOException + { + rule.setFiles( new File[] { null } ); + rule.setAllowNulls( true ); + try + { + rule.execute( EnforcerTestUtils.getHelper() ); + } + catch ( EnforcerRuleException e ) + { + fail( "Unexpected Exception:" + e.getLocalizedMessage() ); + } + } + + public void testEmptyFileList() + throws EnforcerRuleException, IOException + { + rule.setFiles( new File[] {} ); + + assertEquals( 0, rule.getFiles().length ); + + MockProject project = new MockProject(); + File f = File.createTempFile( "enforcer", "tmp" ); + f.deleteOnExit(); + ArtifactStubFactory factory = new ArtifactStubFactory(); + Artifact a = factory.getReleaseArtifact(); + a.setFile( f ); + + project.setArtifact( a ); + + // sanity check the mockProject + assertSame( f, project.getArtifact().getFile() ); + + rule.execute( EnforcerTestUtils.getHelper( project ) ); + + } + + public void testFileDoesNotExist() + throws EnforcerRuleException, IOException + { + File f = File.createTempFile( "enforcer", "tmp" ); + f.delete(); + assertTrue( !f.exists() ); + rule.setFiles( new File[] { f } ); + + try + { + rule.execute( EnforcerTestUtils.getHelper() ); + fail( "Should get exception" ); + } + catch ( EnforcerRuleException e ) + { + assertTrue( true ); + } + } + + public void testFileTooSmall() + throws EnforcerRuleException, IOException + { + File f = File.createTempFile( "enforcer", "tmp" ); + f.deleteOnExit(); + rule.setFiles( new File[] { f } ); + rule.setMinsize( 10 ); + try + { + rule.execute( EnforcerTestUtils.getHelper() ); + fail( "Should get exception" ); + } + catch ( EnforcerRuleException e ) + { + assertTrue( true ); + } + } + + public void testFileTooBig() + throws EnforcerRuleException, IOException + { + File f = File.createTempFile( "enforcer", "tmp" ); + f.deleteOnExit(); + try + { + // Create file + FileWriter fstream = new FileWriter( f ); + BufferedWriter out = new BufferedWriter( fstream ); + out.write( "123456789101112131415" ); + // Close the output stream + out.close(); + fstream.close(); + } + catch ( Exception e ) + {// Catch exception if any + System.err.println( "Error: " + e.getMessage() ); + } + + rule.setFiles( new File[] { f } ); + rule.setMaxsize( 10 ); + assertTrue( f.length() > 10 ); + try + { + rule.execute( EnforcerTestUtils.getHelper() ); + fail( "Should get exception" ); + } + catch ( EnforcerRuleException e ) + { + assertTrue( true ); + } + } + + /** + * Test id. + */ + public void testId() + { + rule.getCacheId(); + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireJavaVersion.java b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireJavaVersion.java new file mode 100644 index 000000000..9a45741de --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireJavaVersion.java @@ -0,0 +1,126 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import static org.assertj.core.api.Assertions.assertThat; + +import org.apache.commons.lang3.SystemUtils; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.junit.Ignore; +import org.junit.Test; + +/** + * The Class TestRequireJavaVersion. + * + * @author Brian Fox + */ +public class TestRequireJavaVersion +{ + + /** + * Test fix jdk version. + */ + @Test + public void testFixJDKVersion() + { + // test that we only take the first 3 versions for + // comparison + assertThat( RequireJavaVersion.normalizeJDKVersion( "1.5.0_11" ) ).isEqualTo( "1.5.0-11" ); + assertThat( RequireJavaVersion.normalizeJDKVersion( "1.5.1" ) ).isEqualTo( "1.5.1" ); + assertThat( RequireJavaVersion.normalizeJDKVersion( "1.5.2-1.b11" ) ).isEqualTo( "1.5.2-1" ); + assertThat( RequireJavaVersion.normalizeJDKVersion( "1.5.3_11" ) ).isEqualTo( "1.5.3-11" ); + assertThat( RequireJavaVersion.normalizeJDKVersion( "1.5.4.5_11" ) ).isEqualTo( "1.5.4-5" ); + assertThat( RequireJavaVersion.normalizeJDKVersion( "1.5.5.6_11.2" ) ).isEqualTo( "1.5.5-6" ); + + // test for non-standard versions + assertThat( RequireJavaVersion.normalizeJDKVersion( "1-5-0-11" ) ).isEqualTo( "1.5.0-11" ); + assertThat( RequireJavaVersion.normalizeJDKVersion( "1-_5-_0-_11" ) ).isEqualTo( "1.5.0-11" ); + assertThat( RequireJavaVersion.normalizeJDKVersion( "1_5_0_11" ) ).isEqualTo( "1.5.0-11" ); + assertThat( RequireJavaVersion.normalizeJDKVersion( "1.5.0-07" ) ).isEqualTo( "1.5.0-7" ); + assertThat( RequireJavaVersion.normalizeJDKVersion( "1.5.0-b7" ) ).isEqualTo( "1.5.0-7" ); + assertThat( RequireJavaVersion.normalizeJDKVersion( "1.5.0-;7" ) ).isEqualTo( "1.5.0-7" ); + assertThat( RequireJavaVersion.normalizeJDKVersion( "1.6.0-dp" ) ).isEqualTo( "1.6.0" ); + assertThat( RequireJavaVersion.normalizeJDKVersion( "1.6.0-dp2" ) ).isEqualTo( "1.6.0-2" ); + assertThat( RequireJavaVersion.normalizeJDKVersion( "1.8.0_73" ) ).isEqualTo( "1.8.0-73" ); + assertThat( RequireJavaVersion.normalizeJDKVersion( "9" ) ).isEqualTo( "9" ); + + } + + /** + * Test rule. + * + * @throws EnforcerRuleException the enforcer rule exception + */ + @Test + public void settingsTheJavaVersionAsNormalizedVersionShouldNotFail() + throws EnforcerRuleException + { + String normalizedJDKVersion = RequireJavaVersion.normalizeJDKVersion( SystemUtils.JAVA_VERSION ); + + RequireJavaVersion rule = new RequireJavaVersion(); + rule.setVersion( normalizedJDKVersion ); + + EnforcerRuleHelper helper = EnforcerTestUtils.getHelper(); + + // test the singular version + rule.execute( helper ); + // intentionally no assertThat(...) because we don't expect and exception. + } + + @Test( expected = EnforcerRuleException.class ) + public void excludingTheCurrentJavaVersionViaRangeThisShouldFailWithException() + throws EnforcerRuleException + { + String thisVersion = RequireJavaVersion.normalizeJDKVersion( SystemUtils.JAVA_VERSION ); + + RequireJavaVersion rule = new RequireJavaVersion(); + // exclude this version + rule.setVersion( "(" + thisVersion ); + + EnforcerRuleHelper helper = EnforcerTestUtils.getHelper(); + rule.execute( helper ); + // intentionally no assertThat(...) because we expect and exception. + } + + @Test + @Ignore + // TODO: Think about the intention of this test? What should it prove? + public void thisShouldNotCrash() + throws EnforcerRuleException + { + RequireJavaVersion rule = new RequireJavaVersion(); + rule.setVersion( SystemUtils.JAVA_VERSION ); + + EnforcerRuleHelper helper = EnforcerTestUtils.getHelper(); + rule.execute( helper ); + // intentionally no assertThat(...) because we don't expect and exception. + } + + /** + * Test id. + */ + @Test + public void testId() + { + RequireJavaVersion rule = new RequireJavaVersion(); + assertThat( rule.getCacheId() ).isEqualTo( "0" ); + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireNoRepositories.java b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireNoRepositories.java new file mode 100644 index 000000000..0da2d64be --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireNoRepositories.java @@ -0,0 +1,397 @@ +package org.apache.maven.plugins.enforcer; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; + +/* + * 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. + */ + +import java.util.Collections; +import java.util.List; + +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.execution.ProjectDependencyGraph; +import org.apache.maven.model.Model; +import org.apache.maven.model.Repository; +import org.apache.maven.model.RepositoryPolicy; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.junit.Before; +import org.junit.Test; + +/** + * Test the "require no repositories" rule. + * + * @author Brett Porter + * @author Karl Heinz Marbaise + */ +public class TestRequireNoRepositories +{ + private EnforcerRuleHelper helper; + + private RequireNoRepositories rule; + + private MavenSession session; + + @Before + public void before() + throws ExpressionEvaluationException + { + session = mock( MavenSession.class ); + helper = mock( EnforcerRuleHelper.class ); + + when( helper.evaluate( "${session}" ) ).thenReturn( session ); + + Log log = mock( Log.class ); + when( helper.getLog() ).thenReturn( log ); + + rule = new RequireNoRepositories(); + rule.setMessage( "my message" ); + } + + private MavenProject createMavenProject() + { + MavenProject mp = mock( MavenProject.class ); + when( mp.getGroupId() ).thenReturn( "org.apache.maven.plugins.enforcer.test" ); + when( mp.getArtifactId() ).thenReturn( "no-repositories-child" ); + when( mp.getVersion() ).thenReturn( "1.0-SNAPSHOT" ); + + return mp; + } + + private Model createOriginalModel() + { + Model m = mock( Model.class ); + when( m.getGroupId() ).thenReturn( "org.apache.maven.plugins.enforcer.test" ); + when( m.getArtifactId() ).thenReturn( "no-repositories" ); + when( m.getVersion() ).thenReturn( "1.0-SNAPSHOT" ); + return m; + } + + private MavenProject createStandAloneProject() + { + MavenProject mp = createMavenProject(); + Model originalModel = createOriginalModel(); + // This means the interpolated model is the same + // as the non interpolated. + when( mp.getModel() ).thenReturn( originalModel ); + when( mp.getOriginalModel() ).thenReturn( originalModel ); + return mp; + } + + private void setupSortedProjects( List projectList ) + { + ProjectDependencyGraph pdg = mock( ProjectDependencyGraph.class ); + when( session.getProjectDependencyGraph() ).thenReturn( pdg ); + when( pdg.getSortedProjects() ).thenReturn( projectList ); + } + + private Repository createRepository( String id, String url ) + { + Repository r = new Repository(); + r.setId( id ); + r.setUrl( url ); + RepositoryPolicy snapshotPolicy = new RepositoryPolicy(); + snapshotPolicy.setEnabled( false ); + snapshotPolicy.setUpdatePolicy( "daily" ); + r.setSnapshots( snapshotPolicy ); + + RepositoryPolicy releasePolicy = new RepositoryPolicy(); + releasePolicy.setEnabled( true ); + releasePolicy.setUpdatePolicy( "never" ); + r.setReleases( releasePolicy ); + + return r; + } + + private Repository createSnapshotRepository( String id, String url ) + { + Repository r = new Repository(); + r.setId( id ); + r.setUrl( url ); + + RepositoryPolicy snapshotPolicy = new RepositoryPolicy(); + snapshotPolicy.setEnabled( true ); + snapshotPolicy.setUpdatePolicy( "daily" ); + r.setSnapshots( snapshotPolicy ); + + RepositoryPolicy releasePolicy = new RepositoryPolicy(); + releasePolicy.setEnabled( false ); + r.setReleases( releasePolicy ); + + return r; + } + + private MavenProject addRepository( MavenProject project, Repository r ) + { + Model originalModel = project.getOriginalModel(); + List repositories = new ArrayList(); + repositories.add( r ); + when( originalModel.getRepositories() ).thenReturn( repositories ); + return project; + } + + private MavenProject addEmptyRepository( MavenProject project ) + { + Model originalModel = project.getOriginalModel(); + List repositories = new ArrayList(); + when( originalModel.getRepositories() ).thenReturn( repositories ); + return project; + } + + private MavenProject addPluginRepository( MavenProject project, Repository r ) + { + Model originalModel = project.getOriginalModel(); + List repositories = new ArrayList(); + repositories.add( r ); + when( originalModel.getPluginRepositories() ).thenReturn( repositories ); + return project; + } + + private MavenProject addEmptyPluginRepository( MavenProject project ) + { + Model originalModel = project.getOriginalModel(); + List repositories = new ArrayList(); + when( originalModel.getPluginRepositories() ).thenReturn( repositories ); + return project; + } + + /** + * This model contains a single module maven project without any repository. + */ + @Test + public void testAllBannedNoRepositories() + throws EnforcerRuleException + { + MavenProject baseProject = createStandAloneProject(); + setupSortedProjects( Collections.singletonList( baseProject ) ); + + rule.execute( helper ); + } + + /** + * The model contains a single repository which is is not allowed by the default rules. + */ + @Test( expected = EnforcerRuleException.class ) + public void testAllBannedWithRepository() + throws EnforcerRuleException + { + MavenProject baseProject = createStandAloneProject(); + addRepository( baseProject, createRepository( "repo", "http://example.com/repo" ) ); + setupSortedProjects( Collections.singletonList( baseProject ) ); + + rule.execute( helper ); + } + + /** + * The model contains a single plugin repository which is is not allowed by the default rules. + */ + @Test( expected = EnforcerRuleException.class ) + public void testAllBannedWithPluginRepository() + throws EnforcerRuleException + { + MavenProject baseProject = createStandAloneProject(); + addPluginRepository( baseProject, createRepository( "repo", "http://example.com/repo" ) ); + setupSortedProjects( Collections.singletonList( baseProject ) ); + + rule.execute( helper ); + } + + /** + * The model contains a single repository which is allowed by setting allowedRepositories to the id. + */ + @Test + public void testAllBannedWithAllowedRepositories() + throws EnforcerRuleException + { + final String repositoryId = "repo"; + rule.setAllowedRepositories( Collections.singletonList( repositoryId ) ); + + MavenProject baseProject = createStandAloneProject(); + addRepository( baseProject, createRepository( repositoryId, "http://example.com/repo" ) ); + setupSortedProjects( Collections.singletonList( baseProject ) ); + + rule.execute( helper ); + } + + /** + * The model contains a single repository. Turned off ban repositories. + */ + @Test + public void testRepositoriesNotBannedWithSingleRepository() + throws EnforcerRuleException + { + final String repositoryId = "repo"; + + rule.setBanRepositories( false ); + + MavenProject baseProject = createStandAloneProject(); + addRepository( baseProject, createRepository( repositoryId, "http://example.com/repo" ) ); + setupSortedProjects( Collections.singletonList( baseProject ) ); + + rule.execute( helper ); + } + + /** + * The model contains no repository at all. Turned off ban repositories. + */ + @Test + public void testRepositoriesNotBannedWithOutAnyRepository() + throws EnforcerRuleException + { + rule.setBanRepositories( false ); + + MavenProject baseProject = createStandAloneProject(); + setupSortedProjects( Collections.singletonList( baseProject ) ); + + rule.execute( helper ); + } + + /** + * This model contains a single plugin repository. The given plugin repository is added to the list of allowed + * plugin repositories. + */ + @Test + public void testAllBannedWithAllowedPluginRepositories() + throws EnforcerRuleException + { + final String repositoryId = "repo"; + rule.setAllowedPluginRepositories( Collections.singletonList( repositoryId ) ); + + MavenProject baseProject = createStandAloneProject(); + addPluginRepository( baseProject, createRepository( repositoryId, "http://example.com/repo" ) ); + setupSortedProjects( Collections.singletonList( baseProject ) ); + + rule.execute( helper ); + } + + /** + * The model contains a single plugin repository. Turned off ban plugin repositories. + */ + @Test + public void testPluginRepositoriesNotBannedWithSinglePluginRepository() + throws EnforcerRuleException + { + final String repositoryId = "repo"; + + rule.setBanPluginRepositories( false ); + + MavenProject baseProject = createStandAloneProject(); + addPluginRepository( baseProject, createRepository( repositoryId, "http://example.com/repo" ) ); + setupSortedProjects( Collections.singletonList( baseProject ) ); + + rule.execute( helper ); + } + + /** + * The model contains no repository at all. Turned off ban plugin repositories. + */ + @Test + public void testPluginRepositoriesNotBannedWithOutAnyRepository() + throws EnforcerRuleException + { + rule.setBanPluginRepositories( false ); + + MavenProject baseProject = createStandAloneProject(); + setupSortedProjects( Collections.singletonList( baseProject ) ); + + rule.execute( helper ); + } + + @Test( expected = EnforcerRuleException.class ) + public void testAllBannedWithSnapshotRepository() + throws EnforcerRuleException + { + MavenProject baseProject = createStandAloneProject(); + addRepository( baseProject, createSnapshotRepository( "repo", "http://example.com/repo" ) ); + setupSortedProjects( Collections.singletonList( baseProject ) ); + + rule.execute( helper ); + } + + @Test + public void testAllBannedWithSnapshotRepositoryAllowedRepositories() + throws EnforcerRuleException + { + final String repositoryId = "repo"; + rule.setAllowedRepositories( Collections.singletonList( repositoryId ) ); + + MavenProject baseProject = createStandAloneProject(); + addRepository( baseProject, createSnapshotRepository( repositoryId, "http://example.com/repo" ) ); + setupSortedProjects( Collections.singletonList( baseProject ) ); + + rule.execute( helper ); + } + + @Test + public void testAllBannedWithSnapshotRepositoryAndSetAllowSnapshotRepositories() + throws EnforcerRuleException + { + final String repositoryId = "repo"; + rule.setAllowSnapshotRepositories( true ); + + MavenProject baseProject = createStandAloneProject(); + addRepository( baseProject, createSnapshotRepository( repositoryId, "http://example.com/repo" ) ); + setupSortedProjects( Collections.singletonList( baseProject ) ); + + rule.execute( helper ); + } + + @Test + public void testAllBannedWithSnapshotPluginRepositoryAndSetAllowSnapshotPluginRepositories() + throws EnforcerRuleException + { + final String repositoryId = "repo"; + rule.setAllowSnapshotPluginRepositories( true ); + + MavenProject baseProject = createStandAloneProject(); + addPluginRepository( baseProject, createSnapshotRepository( repositoryId, "http://example.com/repo" ) ); + setupSortedProjects( Collections.singletonList( baseProject ) ); + + rule.execute( helper ); + } + + @Test + public void testAllBannedWithEmptyRepository() + throws EnforcerRuleException + { + MavenProject baseProject = createStandAloneProject(); + addEmptyRepository( baseProject ); + setupSortedProjects( Collections.singletonList( baseProject ) ); + + rule.execute( helper ); + } + + @Test + public void testAllBannedWithEmptyPluginRepository() + throws EnforcerRuleException + { + MavenProject baseProject = createStandAloneProject(); + addEmptyPluginRepository( baseProject ); + setupSortedProjects( Collections.singletonList( baseProject ) ); + + rule.execute( helper ); + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireOS.java b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireOS.java new file mode 100644 index 000000000..353a763b8 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireOS.java @@ -0,0 +1,144 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import static org.hamcrest.CoreMatchers.startsWith; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.Iterator; + +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.model.profile.activation.OperatingSystemProfileActivator; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.plugin.logging.SystemStreamLog; +import org.codehaus.plexus.util.Os; +import org.junit.Test; + +/** + * Exhaustively check the OS mojo. + * + * @author Brian Fox + */ +public class TestRequireOS +{ + + /** + * Test os. + */ + @Test + public void testOS() + { + Log log = new SystemStreamLog(); + + RequireOS rule = new RequireOS( new OperatingSystemProfileActivator() ); + + rule.displayOSInfo( log, true ); + + Iterator iter = Os.getValidFamilies().iterator(); + String validFamily = null; + String invalidFamily = null; + while ( iter.hasNext() ) + { + String fam = (String) iter.next(); + if ( !Os.isFamily( fam ) ) + { + invalidFamily = fam; + break; + } + } + + validFamily = Os.OS_FAMILY; + + log.info( "Testing Mojo Using Valid Family: " + validFamily + " Invalid Family: " + invalidFamily ); + + rule.setFamily( validFamily ); + assertTrue( rule.isAllowed() ); + + rule.setFamily( invalidFamily ); + assertFalse( rule.isAllowed() ); + + rule.setFamily( "!" + invalidFamily ); + assertTrue( rule.isAllowed() ); + + rule.setFamily( null ); + rule.setArch( Os.OS_ARCH ); + assertTrue( rule.isAllowed() ); + + rule.setArch( "somecrazyarch" ); + assertFalse( rule.isAllowed() ); + + rule.setArch( "!somecrazyarch" ); + assertTrue( rule.isAllowed() ); + + rule.setArch( null ); + + rule.setName( Os.OS_NAME ); + assertTrue( rule.isAllowed() ); + + rule.setName( "somecrazyname" ); + assertFalse( rule.isAllowed() ); + + rule.setName( "!somecrazyname" ); + assertTrue( rule.isAllowed() ); + + rule.setName( null ); + + rule.setVersion( Os.OS_VERSION ); + assertTrue( rule.isAllowed() ); + + rule.setVersion( "somecrazyversion" ); + assertFalse( rule.isAllowed() ); + + rule.setVersion( "!somecrazyversion" ); + assertTrue( rule.isAllowed() ); + } + + @Test + public void testInvalidFamily() throws Exception + { + RequireOS rule = new RequireOS(); + + EnforcerRuleHelper helper = EnforcerTestUtils.getHelper(); + helper.getContainer().addComponent( new OperatingSystemProfileActivator(), "os" ); + + rule.setFamily( "junk" ); + try + { + rule.execute( helper ); + fail( "Expected MojoExecution Exception because of invalid family type" ); + } + catch ( EnforcerRuleException e ) + { + assertThat( e.getMessage(), startsWith( "Invalid Family type used. Valid family types are: " ) ); + } + } + + @Test + public void testId() + { + RequireOS rule = new RequireOS(); + rule.getCacheId(); + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequirePluginVersions.java b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequirePluginVersions.java new file mode 100644 index 000000000..48974cd8c --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequirePluginVersions.java @@ -0,0 +1,481 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.model.Plugin; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.testing.AbstractMojoTestCase; +import org.apache.maven.plugins.enforcer.utils.PluginWrapper; + +/** + * The Class TestRequirePluginVersions. + * + * @author Brian Fox + */ +public class TestRequirePluginVersions + extends AbstractMojoTestCase +{ + + /** + * Test has version specified. + */ + public void testHasVersionSpecified() + { + Plugin source = new Plugin(); + source.setArtifactId( "foo" ); + source.setGroupId( "group" ); + + // setup the plugins. I'm setting up the foo group + // with a few bogus entries and then a real one. + // to test that the list is exhaustively + // searched for versions before giving up. + // banLatest/Release will fail if it is found + // anywhere in the list. + List plugins = new ArrayList(); + plugins.add( EnforcerTestUtils.newPlugin( "group", "a-artifact", "1.0" ) ); + plugins.add( EnforcerTestUtils.newPlugin( "group", "foo", null ) ); + plugins.add( EnforcerTestUtils.newPlugin( "group", "foo", "" ) ); + plugins.add( EnforcerTestUtils.newPlugin( "group", "b-artifact", "1.0" ) ); + plugins.add( EnforcerTestUtils.newPlugin( "group", "foo", "1.0" ) ); + plugins.add( EnforcerTestUtils.newPlugin( "group", "c-artifact", "LATEST" ) ); + plugins.add( EnforcerTestUtils.newPlugin( "group", "c-artifact", "1.0" ) ); + plugins.add( EnforcerTestUtils.newPlugin( "group", "d-artifact", "RELEASE" ) ); + plugins.add( EnforcerTestUtils.newPlugin( "group", "d-artifact", "1.0" ) ); + plugins.add( EnforcerTestUtils.newPlugin( "group", "e-artifact", "1.0" ) ); + plugins.add( EnforcerTestUtils.newPlugin( "group", "e-artifact", "RELEASE" ) ); + plugins.add( EnforcerTestUtils.newPlugin( "group", "f-artifact", "1.0" ) ); + plugins.add( EnforcerTestUtils.newPlugin( "group", "f-artifact", "LATEST" ) ); + plugins.add( EnforcerTestUtils.newPlugin( "group", "f-artifact", "1.0-SNAPSHOT" ) ); + plugins.add( EnforcerTestUtils.newPlugin( "group", "g-artifact", "1.0-12345678.123456-1" ) ); + + + List pluginWrappers = PluginWrapper.addAll( plugins, "unit" ); + + RequirePluginVersions rule = new RequirePluginVersions(); + rule.setBanLatest( false ); + rule.setBanRelease( false ); + rule.setBanSnapshots( false ); + + + EnforcerRuleHelper helper = EnforcerTestUtils.getHelper(); + + assertTrue( rule.hasValidVersionSpecified( helper, source, pluginWrappers ) ); + + // check that LATEST is allowed + source.setArtifactId( "c-artifact" ); + assertTrue( rule.hasValidVersionSpecified( helper, source, pluginWrappers ) ); + + // check that LATEST is banned + rule.setBanLatest( true ); + assertFalse( rule.hasValidVersionSpecified( helper, source, pluginWrappers ) ); + + // check that LATEST is exhaustively checked + rule.setBanSnapshots( false ); + source.setArtifactId( "f-artifact" ); + assertFalse( rule.hasValidVersionSpecified( helper, source, pluginWrappers ) ); + + rule.setBanLatest( false ); + rule.setBanSnapshots( true ); + assertFalse( rule.hasValidVersionSpecified( helper, source, pluginWrappers ) ); + + // check that TIMESTAMP is allowed + rule.setBanTimestamps( false ); + source.setArtifactId( "g-artifact" ); + assertTrue( rule.hasValidVersionSpecified( helper, source, pluginWrappers ) ); + + // check that RELEASE is allowed + source.setArtifactId( "d-artifact" ); + assertTrue( rule.hasValidVersionSpecified( helper, source, pluginWrappers ) ); + + // check that RELEASE is banned + rule.setBanRelease( true ); + assertFalse( rule.hasValidVersionSpecified( helper, source, pluginWrappers ) ); + + // check that RELEASE is exhaustively checked + source.setArtifactId( "e-artifact" ); + assertFalse( rule.hasValidVersionSpecified( helper, source, pluginWrappers ) ); + } + + /** + * Test has version specified with properties. + */ + public void testHasVersionSpecifiedWithProperties() + { + Plugin source = new Plugin(); + source.setGroupId( "group" ); + + // setup the plugins. + List plugins = new ArrayList(); + plugins.add( EnforcerTestUtils.newPlugin( "group", "a-artifact", "1.0-${SNAPSHOT}" ) ); + plugins.add( EnforcerTestUtils.newPlugin( "group", "b-artifact", "${1.0}" ) ); + plugins.add( EnforcerTestUtils.newPlugin( "group", "c-artifact", "${LATEST}" ) ); + plugins.add( EnforcerTestUtils.newPlugin( "group", "d-artifact", "${RELEASE}" ) ); + plugins.add( EnforcerTestUtils.newPlugin( "group", "e-artifact", "${}" ) ); + plugins.add( EnforcerTestUtils.newPlugin( "group", "f-artifact", "${ }" ) ); + + List pluginWrappers = PluginWrapper.addAll( plugins, "unit" ); + + RequirePluginVersions rule = new RequirePluginVersions(); + rule.setBanLatest( false ); + rule.setBanRelease( false ); + rule.setBanSnapshots( false ); + + EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( true ); + + source.setArtifactId( "a-artifact" ); + assertTrue( rule.hasValidVersionSpecified( helper, source, pluginWrappers ) ); + + source.setArtifactId( "b-artifact" ); + assertTrue( rule.hasValidVersionSpecified( helper, source, pluginWrappers ) ); + + source.setArtifactId( "c-artifact" ); + assertTrue( rule.hasValidVersionSpecified( helper, source, pluginWrappers ) ); + + source.setArtifactId( "d-artifact" ); + assertTrue( rule.hasValidVersionSpecified( helper, source, pluginWrappers ) ); + + // this one checks empty property values + source.setArtifactId( "e-artifact" ); + assertFalse( rule.hasValidVersionSpecified( helper, source, pluginWrappers ) ); + + // this one checks empty property values + source.setArtifactId( "f-artifact" ); + assertFalse( rule.hasValidVersionSpecified( helper, source, pluginWrappers ) ); + + rule.setBanLatest( true ); + source.setArtifactId( "c-artifact" ); + assertFalse( rule.hasValidVersionSpecified( helper, source, pluginWrappers ) ); + + rule.setBanRelease( true ); + source.setArtifactId( "d-artifact" ); + assertFalse( rule.hasValidVersionSpecified( helper, source, pluginWrappers ) ); + + rule.setBanSnapshots( true ); + source.setArtifactId( "a-artifact" ); + assertFalse( rule.hasValidVersionSpecified( helper, source, pluginWrappers ) ); + + // release versions should pass everything + source.setArtifactId( "b-artifact" ); + assertTrue( rule.hasValidVersionSpecified( helper, source, pluginWrappers ) ); + } + + /** + * Test get additional plugins null. + * + * @throws MojoExecutionException the mojo execution exception + */ + public void testGetAdditionalPluginsNull() + throws MojoExecutionException + { + RequirePluginVersions rule = new RequirePluginVersions(); + rule.addAdditionalPlugins( null, null ); + } + + /** + * Test get additional plugins invalid format. + */ + public void testGetAdditionalPluginsInvalidFormat() + { + RequirePluginVersions rule = new RequirePluginVersions(); + + List additional = new ArrayList(); + + // invalid format (not enough sections) + additional.add( "group" ); + + Set plugins = new HashSet(); + try + { + rule.addAdditionalPlugins( plugins, additional ); + fail( "Expected Exception because the format is invalid" ); + } + catch ( MojoExecutionException e ) + { + } + + // invalid format (too many sections) + additional.clear(); + additional.add( "group:i:i" ); + try + { + rule.addAdditionalPlugins( plugins, additional ); + fail( "Expected Exception because the format is invalid" ); + } + catch ( MojoExecutionException e ) + { + } + + } + + /** + * Test get additional plugins empty set. + * + * @throws MojoExecutionException the mojo execution exception + */ + public void testGetAdditionalPluginsEmptySet() + throws MojoExecutionException + { + RequirePluginVersions rule = new RequirePluginVersions(); + + Set plugins = new HashSet(); + plugins.add( EnforcerTestUtils.newPlugin( "group", "a-artifact", "1.0" ) ); + plugins.add( EnforcerTestUtils.newPlugin( "group", "foo", null ) ); + plugins.add( EnforcerTestUtils.newPlugin( "group", "foo2", "" ) ); + + List additional = new ArrayList(); + additional.add( "group:a-artifact" ); + additional.add( "group:another-artifact" ); + + // make sure a null set can be handled + Set results = rule.addAdditionalPlugins( null, additional ); + + assertNotNull( results ); + assertContainsPlugin( "group", "a-artifact", results ); + assertContainsPlugin( "group", "another-artifact", results ); + + } + + /** + * Test get additional plugins. + * + * @throws MojoExecutionException the mojo execution exception + */ + public void testGetAdditionalPlugins() + throws MojoExecutionException + { + RequirePluginVersions rule = new RequirePluginVersions(); + + Set plugins = new HashSet(); + plugins.add( EnforcerTestUtils.newPlugin( "group", "a-artifact", "1.0" ) ); + plugins.add( EnforcerTestUtils.newPlugin( "group", "foo", null ) ); + plugins.add( EnforcerTestUtils.newPlugin( "group", "foo2", "" ) ); + + List additional = new ArrayList(); + additional.add( "group:a-artifact" ); + additional.add( "group:another-artifact" ); + + Set results = rule.addAdditionalPlugins( plugins, additional ); + + // make sure only one new plugin has been added + assertNotNull( results ); + assertEquals( 4, results.size() ); + assertContainsPlugin( "group", "a-artifact", results ); + assertContainsPlugin( "group", "another-artifact", results ); + + } + + /** + * Test remove Unchecked plugins. + * + * @throws MojoExecutionException the mojo execution exception + */ + public void testGetUncheckedPlugins() + throws MojoExecutionException + { + RequirePluginVersions rule = new RequirePluginVersions(); + + Set plugins = new HashSet(); + plugins.add( EnforcerTestUtils.newPlugin( "group", "a-artifact", "1.0" ) ); + plugins.add( EnforcerTestUtils.newPlugin( "group", "foo", null ) ); + plugins.add( EnforcerTestUtils.newPlugin( "group", "foo2", "" ) ); + + List unchecked = new ArrayList(); + //intentionally inserting spaces to make sure they are handled correctly. + unchecked.add( "group : a-artifact" ); + + Collection results = rule.removeUncheckedPlugins( unchecked, plugins ); + + + // make sure only one new plugin has been added + assertNotNull( results ); + assertEquals( 2, results.size() ); + assertContainsPlugin( "group", "foo", results ); + assertContainsPlugin( "group", "foo2", results ); + assertNotContainPlugin( "group", "a-artifact", results ); + + } + + /** + * Test combining values from both lists + */ + public void testCombinePlugins() + { + RequirePluginVersions rule = new RequirePluginVersions(); + + Set plugins = new HashSet(); + plugins.add( "group:a-artifact" ); + plugins.add( "group:foo" ); + plugins.add( "group:foo2" ); + + Collection results = rule.combineUncheckedPlugins( plugins, "group2:a,group3:b" ); + + // make sure only one new plugin has been added + assertNotNull( results ); + assertEquals( 5, results.size() ); + assertTrue( results.contains( "group:foo") ); + assertTrue( results.contains( "group:foo2") ); + assertTrue( results.contains( "group:a-artifact") ); + assertTrue( results.contains( "group2:a") ); + assertTrue( results.contains( "group3:b") ); + } + + /** + * Test combining with an empty list + */ + public void testCombinePlugins1() + { + RequirePluginVersions rule = new RequirePluginVersions(); + + Set plugins = new HashSet(); + Collection results = rule.combineUncheckedPlugins( plugins, "group2:a,group3:b" ); + + + // make sure only one new plugin has been added + assertNotNull( results ); + assertEquals( 2, results.size() ); + assertTrue( results.contains( "group2:a") ); + assertTrue( results.contains( "group3:b") ); + } + + /** + * Test combining with a null list + */ + public void testCombinePlugins2() + { + RequirePluginVersions rule = new RequirePluginVersions(); + + Collection results = rule.combineUncheckedPlugins( null, "group2:a,group3:b" ); + + + // make sure only one new plugin has been added + assertNotNull( results ); + assertEquals( 2, results.size() ); + assertTrue( results.contains( "group2:a") ); + assertTrue( results.contains( "group3:b") ); + } + + /** + * Test combining with an empty string + */ + public void testCombinePlugins3() + { + RequirePluginVersions rule = new RequirePluginVersions(); + + Set plugins = new HashSet(); + plugins.add( "group:a-artifact" ); + plugins.add( "group:foo" ); + plugins.add( "group:foo2" ); + + Collection results = rule.combineUncheckedPlugins( plugins, "" ); + assertNotNull( results ); + assertEquals( 3, results.size() ); + assertTrue( results.contains( "group:foo") ); + assertTrue( results.contains( "group:foo2") ); + assertTrue( results.contains( "group:a-artifact") ); + } + + /** + * Test combining with a null string + */ + public void testCombinePlugins4() + { + RequirePluginVersions rule = new RequirePluginVersions(); + + Set plugins = new HashSet(); + plugins.add( "group:a-artifact" ); + plugins.add( "group:foo" ); + plugins.add( "group:foo2" ); + + Collection results = rule.combineUncheckedPlugins( plugins, null ); + assertNotNull( results ); + assertEquals( 3, results.size() ); + assertTrue( results.contains( "group:foo") ); + assertTrue( results.contains( "group:foo2") ); + assertTrue( results.contains( "group:a-artifact") ); + } + + /** + * Test combining with an invalid plugin string + */ + public void testCombinePlugins5() + { + RequirePluginVersions rule = new RequirePluginVersions(); + + Set plugins = new HashSet(); + plugins.add( "group:a-artifact" ); + plugins.add( "group:foo" ); + plugins.add( "group:foo2" ); + + Collection results = rule.combineUncheckedPlugins( plugins, "a" ); + assertNotNull( results ); + assertEquals( 4, results.size() ); + assertTrue( results.contains( "group:foo") ); + assertTrue( results.contains( "group:foo2") ); + //this should be here, the checking of a valid plugin string happens in another method. + assertTrue( results.contains( "a") ); + } + + + /** + * Assert contains plugin. + * + * @param group the group + * @param artifact the artifact + * @param theSet the the set + */ + private void assertContainsPlugin( String group, String artifact, Collection theSet ) + { + Plugin p = new Plugin(); + p.setGroupId( group ); + p.setArtifactId( artifact ); + assertTrue( theSet.contains( p ) ); + } + + /** + * Assert doesn't contain plugin. + * + * @param group the group + * @param artifact the artifact + * @param theSet the the set + */ + private void assertNotContainPlugin( String group, String artifact, Collection theSet ) + { + Plugin p = new Plugin(); + p.setGroupId( group ); + p.setArtifactId( artifact ); + assertFalse( theSet.contains( p ) ); + } + + /** + * Test id. + */ + public void testId() + { + RequirePluginVersions rule = new RequirePluginVersions(); + rule.getCacheId(); + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireProperty.java b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireProperty.java new file mode 100644 index 000000000..2685277b2 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireProperty.java @@ -0,0 +1,123 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import junit.framework.TestCase; + +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; + +/** + * The Class TestRequireProperty. + * + * @author Paul Gier + */ +public class TestRequireProperty + extends TestCase +{ + + /** + * Test rule. + * + * @throws EnforcerRuleException the enforcer rule exception + */ + public void testRule() + throws EnforcerRuleException + { + MockProject project = new MockProject(); + project.setProperty( "testProp", "This is a test." ); + EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( project ); + + RequireProperty rule = new RequireProperty(); + // this property should not be set + rule.setProperty( "testPropJunk" ); + + try + { + rule.execute( helper ); + fail( "Expected an exception." ); + } + catch ( EnforcerRuleException e ) + { + // expected to catch this. + } + + // this property should be set by the surefire + // plugin + rule.setProperty( "testProp" ); + try + { + rule.execute( helper ); + } + catch ( EnforcerRuleException e ) + { + fail( "This should not throw an exception" ); + } + } + + /** + * Test rule with regex. + * + * @throws EnforcerRuleException the enforcer rule exception + */ + public void testRuleWithRegex() + throws EnforcerRuleException + { + MockProject project = new MockProject(); + project.setProperty( "testProp", "This is a test." ); + EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( project ); + + RequireProperty rule = new RequireProperty(); + rule.setProperty( "testProp" ); + // This expression should not match the property + // value + rule.setRegex( "[^abc]" ); + + try + { + rule.execute( helper ); + fail( "Expected an exception." ); + } + catch ( EnforcerRuleException e ) + { + // expected to catch this. + } + + // this expr should match the property + rule.setRegex( "[This].*[.]" ); + try + { + rule.execute( helper ); + } + catch ( EnforcerRuleException e ) + { + fail( "This should not throw an exception" ); + } + } + + /** + * Test id. + */ + public void testId() + { + RequireProperty rule = new RequireProperty(); + rule.getCacheId(); + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireReleaseDeps.java b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireReleaseDeps.java new file mode 100644 index 000000000..858e60f31 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireReleaseDeps.java @@ -0,0 +1,117 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.io.IOException; +import java.util.Set; + +import junit.framework.TestCase; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.plugin.testing.ArtifactStubFactory; +import org.apache.maven.plugins.enforcer.utils.EnforcerRuleUtilsHelper; +import org.apache.maven.project.MavenProject; + +/** + * The Class TestNoSnapshots. + * + * @author Brian Fox + */ +public class TestRequireReleaseDeps + extends TestCase +{ + + /** + * Test rule. + * + * @throws IOException Signals that an I/O exception has occurred. + */ + public void testRule() + throws IOException + { + + ArtifactStubFactory factory = new ArtifactStubFactory(); + MockProject project = new MockProject(); + EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( project ); + project.setArtifacts( factory.getMixedArtifacts() ); + project.setDependencyArtifacts( factory.getScopedArtifacts() ); + RequireReleaseDeps rule = newRequireReleaseDeps(); + rule.setSearchTransitive( false ); + + EnforcerRuleUtilsHelper.execute( rule, helper, false ); + + rule.setSearchTransitive( true ); + + EnforcerRuleUtilsHelper.execute( rule, helper, true ); + + // test onlyWhenRelease in each case + + project.setArtifact( factory.getSnapshotArtifact() ); + + EnforcerRuleUtilsHelper.execute( rule, helper, true ); + + rule.setOnlyWhenRelease( true ); + + EnforcerRuleUtilsHelper.execute( rule, helper, false ); + + project.setArtifact( factory.getReleaseArtifact() ); + + EnforcerRuleUtilsHelper.execute( rule, helper, true ); + + MockProject parent = new MockProject(); + parent.setArtifact( factory.getSnapshotArtifact() ); + project.setParent( parent ); + project.setArtifacts( null ); + project.setDependencyArtifacts( null ); + helper = EnforcerTestUtils.getHelper(project); + + rule.setFailWhenParentIsSnapshot( true ); + EnforcerRuleUtilsHelper.execute( rule, helper, true ); + + rule.setFailWhenParentIsSnapshot( false ); + EnforcerRuleUtilsHelper.execute( rule, helper, false ); + + + } + + private RequireReleaseDeps newRequireReleaseDeps() + { + RequireReleaseDeps rule = new RequireReleaseDeps() + { + protected Set getDependenciesToCheck( MavenProject project ) + { + // the integration with dependencyGraphTree is verified with the integration tests + // for unit-testing + return isSearchTransitive() ? project.getArtifacts() : project.getDependencyArtifacts(); + } + }; + return rule; + } + + /** + * Test id. + */ + public void testId() + { + RequireReleaseDeps rule = newRequireReleaseDeps(); + rule.getCacheId(); + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireReleaseVersion.java b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireReleaseVersion.java new file mode 100644 index 000000000..286008e46 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireReleaseVersion.java @@ -0,0 +1,88 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.io.IOException; + +import junit.framework.TestCase; + +import org.apache.maven.enforcer.rule.api.EnforcerRule; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.plugin.testing.ArtifactStubFactory; +import org.apache.maven.plugins.enforcer.utils.EnforcerRuleUtilsHelper; + +/** + * The Class TestRequireReleaseVersion. + * + * @author Brian Fox + */ +public class TestRequireReleaseVersion + extends TestCase +{ + + /** + * Test mojo. + * + * @throws IOException Signals that an I/O exception has occurred. + */ + public void testMojo() + throws IOException + { + ArtifactStubFactory factory = new ArtifactStubFactory(); + MockProject project = new MockProject(); + EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( project ); + + project.setArtifact( factory.getReleaseArtifact() ); + + EnforcerRule rule = new RequireReleaseVersion(); + + EnforcerRuleUtilsHelper.execute( rule, helper, false ); + + project.setArtifact( factory.getSnapshotArtifact() ); + + EnforcerRuleUtilsHelper.execute( rule, helper, true ); + + project.setArtifact( factory.getReleaseArtifact() ); + + MockProject parent = new MockProject(); + parent.setArtifact( factory.getSnapshotArtifact() ); + project.setParent( parent ); + helper = EnforcerTestUtils.getHelper(project); + + ( (RequireReleaseVersion) rule ).setFailWhenParentIsSnapshot( true ); + EnforcerRuleUtilsHelper.execute( rule, helper, true ); + + ( (RequireReleaseVersion) rule ).setFailWhenParentIsSnapshot( false ); + EnforcerRuleUtilsHelper.execute( rule, helper, false ); + + } + + /** + * Test cache. + */ + public void testCache() + { + EnforcerRule rule = new RequireReleaseVersion(); + assertFalse( rule.isCacheable() ); + assertFalse( rule.isResultValid( null ) ); + assertEquals( "0", rule.getCacheId() ); + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireSnapshotVersion.java b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireSnapshotVersion.java new file mode 100644 index 000000000..2fd08a905 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireSnapshotVersion.java @@ -0,0 +1,101 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.plugin.testing.ArtifactStubFactory; +import org.apache.maven.plugins.enforcer.utils.EnforcerRuleUtilsHelper; +import org.apache.maven.project.MavenProject; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; + +/** + * Test class for the RequireSnapshotVersion rule. + */ +public class TestRequireSnapshotVersion +{ + + private MavenProject project; + + private EnforcerRuleHelper helper; + + private ArtifactStubFactory factory; + + private RequireSnapshotVersion rule; + + @Before + public void before() + { + project = new MockProject(); + helper = EnforcerTestUtils.getHelper( project ); + factory = new ArtifactStubFactory(); + rule = new RequireSnapshotVersion(); + } + + @Test + public void testRequireSnapshot() + throws IOException + { + project.setArtifact( factory.getReleaseArtifact() ); + EnforcerRuleUtilsHelper.execute( rule, helper, true ); + + project.setArtifact( factory.getSnapshotArtifact() ); + EnforcerRuleUtilsHelper.execute( rule, helper, false ); + } + + @Test + public void testWithParentShouldFail() + throws IOException + { + project.setArtifact( factory.getSnapshotArtifact() ); + rule.setFailWhenParentIsRelease( true ); + + MockProject parent = new MockProject(); + parent.setArtifact( factory.getReleaseArtifact() ); + project.setParent( parent ); + EnforcerRuleUtilsHelper.execute( rule, helper, true ); + + parent = new MockProject(); + parent.setArtifact( factory.getSnapshotArtifact() ); + project.setParent( parent ); + EnforcerRuleUtilsHelper.execute( rule, helper, false ); + } + + @Test + public void testWithParentShouldPass() + throws IOException + { + project.setArtifact( factory.getSnapshotArtifact() ); + rule.setFailWhenParentIsRelease( false ); + + MockProject parent = new MockProject(); + parent.setArtifact( factory.getReleaseArtifact() ); + project.setParent( parent ); + EnforcerRuleUtilsHelper.execute( rule, helper, false ); + + parent = new MockProject(); + parent.setArtifact( factory.getSnapshotArtifact() ); + project.setParent( parent ); + EnforcerRuleUtilsHelper.execute( rule, helper, false ); + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/utils/EnforcerRuleUtilsHelper.java b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/utils/EnforcerRuleUtilsHelper.java new file mode 100644 index 000000000..37d98bcfe --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/utils/EnforcerRuleUtilsHelper.java @@ -0,0 +1,62 @@ +package org.apache.maven.plugins.enforcer.utils; + +import static org.junit.Assert.fail; + +/* + * 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. + */ + +import org.apache.maven.enforcer.rule.api.EnforcerRule; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; + +/** + * The Class TestEnforcerRuleUtils. + * + * @author Brian Fox + */ +public class EnforcerRuleUtilsHelper +{ + + /** + * Simpler wrapper to execute and deal with the expected result. + * + * @param rule the rule + * @param helper the helper + * @param shouldFail the should fail + */ + public static void execute( EnforcerRule rule, EnforcerRuleHelper helper, boolean shouldFail ) + { + try + { + rule.execute( helper ); + if ( shouldFail ) + { + fail( "Exception expected." ); + } + } + catch ( EnforcerRuleException e ) + { + if ( !shouldFail ) + { + fail( "No Exception expected:" + e.getLocalizedMessage() ); + } + helper.getLog().debug( e.getMessage() ); + } + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/utils/MockEnforcerExpressionEvaluator.java b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/utils/MockEnforcerExpressionEvaluator.java new file mode 100644 index 000000000..df1e62de3 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/utils/MockEnforcerExpressionEvaluator.java @@ -0,0 +1,59 @@ +package org.apache.maven.plugins.enforcer.utils; + +/* + * 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. + */ + +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.MojoExecution; +import org.apache.maven.plugin.descriptor.MojoDescriptor; +import org.apache.maven.plugins.enforcer.EnforcerExpressionEvaluator; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; + +/** + * The Class MockEnforcerExpressionEvaluator. + */ +public class MockEnforcerExpressionEvaluator + extends EnforcerExpressionEvaluator +{ + /** + * Instantiates a new mock enforcer expression evaluator. + * + * @param theContext the context + */ + public MockEnforcerExpressionEvaluator( MavenSession theContext ) + { + super( theContext, new MojoExecution( new MojoDescriptor() ) ); + } + + @Override + public Object evaluate( String expr ) + throws ExpressionEvaluationException + { + if ( expr != null ) + { + // just remove the ${ } and return the name as the value + return expr.replaceAll( "\\$\\{|}", "" ); + } + else + { + return expr; + } + } + +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/utils/TestArtifactMatcher.java b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/utils/TestArtifactMatcher.java new file mode 100644 index 000000000..874063581 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/utils/TestArtifactMatcher.java @@ -0,0 +1,163 @@ +package org.apache.maven.plugins.enforcer.utils; + +/* + * 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. + */ + +import junit.framework.TestCase; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.DefaultArtifact; +import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.artifact.handler.DefaultArtifactHandler; +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.plugins.enforcer.utils.ArtifactMatcher.Pattern; +import java.util.ArrayList; +import java.util.Collection; + +public class TestArtifactMatcher extends TestCase +{ + private ArtifactMatcher matcher; + + Collection patterns = new ArrayList(); + + Collection ignorePatterns = new ArrayList(); + + public void testPatternInvalidInput() throws InvalidVersionSpecificationException + { + try + { + new Pattern(null); + fail("NullPointerException expected."); + } + catch(NullPointerException e){} + + try + { + new Pattern("a:b:c:d:e:f:g"); + fail("IllegalArgumentException expected."); + } + catch(IllegalArgumentException e){} + + try + { + new Pattern("a::"); + fail("IllegalArgumentException expected."); + } + catch(IllegalArgumentException e){} + + try + { + Pattern p = new Pattern("*"); + p.match(null); + fail("NullPointerException expected."); + } + catch(NullPointerException e){} + } + + public void testPattern() throws InvalidVersionSpecificationException + { + executePatternMatch("groupId:artifactId:1.0:jar:compile", "groupId", "artifactId", "1.0", "compile", "jar", true); + + executePatternMatch("groupId:artifactId:1.0:jar:compile", "groupId", "artifactId", "1.0", "", "", true); + + executePatternMatch("groupId:artifactId:1.0", "groupId", "artifactId", "1.0", "", "", true); + + executePatternMatch("groupId:artifactId:1.0", "groupId", "artifactId", "1.1", "", "", true); + + executePatternMatch("groupId:artifactId:[1.0]", "groupId", "artifactId", "1.1", "", "", false); + + executePatternMatch("groupId:*:1.0", "groupId", "artifactId", "1.0", "test", "", true); + + executePatternMatch("*:*:1.0", "groupId", "artifactId", "1.0", "", "", true); + + executePatternMatch("*:artifactId:*", "groupId", "artifactId", "1.0", "", "", true); + + executePatternMatch("*", "groupId", "artifactId", "1.0", "", "", true); + + // MENFORCER-74/75 + executePatternMatch("*:*:*:jar:compile:tests", "groupId", "artifactId", "1.0", "", "", "tests", true); + + // MENFORCER-83 + executePatternMatch("*upId", "groupId", "artifactId", "1.0", "", "", true); + + executePatternMatch("gr*pId:?rt?f?ct?d:1.0", "groupId", "artifactId", "1.0", "", "", true); + + executePatternMatch("org.apache.*:maven-*:*", "org.apache.maven", "maven-core", "3.0", "", "", true); + } + + public void testMatch() throws InvalidVersionSpecificationException + { + patterns.add("groupId:artifactId:1.0"); + patterns.add("*:anotherArtifact"); + + ignorePatterns.add("badGroup:*:*:test"); + ignorePatterns.add("*:anotherArtifact:1.1"); + + matcher = new ArtifactMatcher(patterns, ignorePatterns); + + executeMatch(matcher, "groupId", "artifactId", "1.0", "", "", true); + + executeMatch(matcher, "groupId", "anotherArtifact", "1.0", "", "", true); + + executeMatch(matcher, "badGroup", "artifactId", "1.0", "", "test", false); + + executeMatch(matcher, "badGroup", "anotherArtifact", "1.0", "", "", true); + + executeMatch(matcher, "groupId", "anotherArtifact", "1.1", "", "", false); + } + + private void executePatternMatch( final String pattern, final String groupId, final String artifactId, + final String versionRange, final String scope, final String type, + boolean expectedResult ) + throws InvalidVersionSpecificationException + { + executePatternMatch( pattern, groupId, artifactId, versionRange, scope, type, "", expectedResult ); + } + + private void executePatternMatch( final String pattern, final String groupId, final String artifactId, + final String versionRange, final String scope, final String type, + final String classifier, boolean expectedResult ) + throws InvalidVersionSpecificationException + { + assertEquals( expectedResult, new ArtifactMatcher.Pattern( pattern ).match( createMockArtifact( groupId, + artifactId, + versionRange, + scope, type, + classifier ) ) ); + } + + private void executeMatch( final ArtifactMatcher matcher, final String groupId, final String artifactId, + final String versionRange, final String scope, final String type, + final boolean expectedResult ) + throws InvalidVersionSpecificationException + { + assertEquals( expectedResult, + matcher.match( createMockArtifact( groupId, artifactId, versionRange, scope, type, "" ) ) ); + } + + private static Artifact createMockArtifact( final String groupId, final String artifactId, + final String versionRange, final String scope, final String type, + final String classifier ) + { + ArtifactHandler artifactHandler = new DefaultArtifactHandler(); + + VersionRange version = VersionRange.createFromVersion( versionRange ); + return new DefaultArtifact( groupId, artifactId, version, scope, type, classifier, artifactHandler ); + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/utils/TestMockEnforcerExpressionEvaluator.java b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/utils/TestMockEnforcerExpressionEvaluator.java new file mode 100644 index 000000000..ef8ba8736 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/utils/TestMockEnforcerExpressionEvaluator.java @@ -0,0 +1,70 @@ +package org.apache.maven.plugins.enforcer.utils; + +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugins.enforcer.EnforcerExpressionEvaluator; +import org.apache.maven.plugins.enforcer.EnforcerTestUtils; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; + +/* + * 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. + */ + +import junit.framework.TestCase; + +/** + * The Class TestMockEnforcerExpressionEvaluator. + */ +public class TestMockEnforcerExpressionEvaluator + extends TestCase +{ + + /** + * Test evaluate. + */ + public void testEvaluate() + { + MavenSession session = EnforcerTestUtils.getMavenSession(); + + EnforcerExpressionEvaluator ev = + new MockEnforcerExpressionEvaluator( session ); + assertMatch( ev, "SNAPSHOT" ); + assertMatch( ev, "RELEASE" ); + assertMatch( ev, "SNAPSHOT" ); + assertMatch( ev, "LATEST" ); + assertMatch( ev, "1.0" ); + } + + /** + * Assert match. + * + * @param ev the ev + * @param exp the exp + */ + public void assertMatch( EnforcerExpressionEvaluator ev, String exp ) + { + // the mock enforcer should return the name of the expression as the value. + try + { + assertEquals( exp, ev.evaluate( "${" + exp + "}" ) ); + } + catch ( ExpressionEvaluationException e ) + { + fail( e.getLocalizedMessage() ); + } + } +} diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/resources/requirePluginVersions/checkPluginPropertyVersion/pom.xml b/Java-base/maven-enforcer/src/enforcer-rules/src/test/resources/requirePluginVersions/checkPluginPropertyVersion/pom.xml new file mode 100644 index 000000000..d7ac40b36 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/resources/requirePluginVersions/checkPluginPropertyVersion/pom.xml @@ -0,0 +1,73 @@ + + + + 4.0.0 + a + group + 1.0 + + 2.2-SNAPSHOT + RELEASE + LATEST + SNAPSHOT + + + + + org.apache.maven.plugins + maven-install-plugin + ${my.latest} + + + org.apache.maven.plugins + maven-clean-plugin + ${my.release} + + + org.apache.maven.plugins + maven-jar-plugin + ${my.version} + + + org.apache.maven.plugins + maven-enforcer-plugin + 1.0-${my.snap} + + + + enforce + + + + + + org.apache.maven.plugins:maven-enforcer-plugin + + + + + + + + + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/resources/requirePluginVersions/checkPluginVersionProfile/pom.xml b/Java-base/maven-enforcer/src/enforcer-rules/src/test/resources/requirePluginVersions/checkPluginVersionProfile/pom.xml new file mode 100644 index 000000000..48a688a4a --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/resources/requirePluginVersions/checkPluginVersionProfile/pom.xml @@ -0,0 +1,75 @@ + + + + 4.0.0 + a + group + 1.0 + + 2.2-SNAPSHOT + RELEASE + LATEST + SNAPSHOT + + + + + org.apache.maven.plugins + maven-enforcer-plugin + 1.0-${my.snap} + + + + enforce + + + + + none + + + + + + + + + + + prof + + + + org.apache.maven.plugins + maven-site-plugin + RELEASE + + + site + + validate + + + + + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/resources/requirePluginVersions/getPomRecursively/b/c/pom.xml b/Java-base/maven-enforcer/src/enforcer-rules/src/test/resources/requirePluginVersions/getPomRecursively/b/c/pom.xml new file mode 100644 index 000000000..40ff1c6c3 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/resources/requirePluginVersions/getPomRecursively/b/c/pom.xml @@ -0,0 +1,38 @@ + + + + + b + group + 1.0 + + c + + + + + org.apache.maven.plugins + maven-deploy-plugin + + + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/resources/requirePluginVersions/getPomRecursively/b/pom.xml b/Java-base/maven-enforcer/src/enforcer-rules/src/test/resources/requirePluginVersions/getPomRecursively/b/pom.xml new file mode 100644 index 000000000..43c4f2e4f --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/resources/requirePluginVersions/getPomRecursively/b/pom.xml @@ -0,0 +1,36 @@ + + + + + a + group + 1.0 + + b + + + + org.apache.maven.plugins + maven-clean-plugin + + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/resources/requirePluginVersions/getPomRecursively/pom.xml b/Java-base/maven-enforcer/src/enforcer-rules/src/test/resources/requirePluginVersions/getPomRecursively/pom.xml new file mode 100644 index 000000000..763f933d1 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/resources/requirePluginVersions/getPomRecursively/pom.xml @@ -0,0 +1,33 @@ + + + + a + group + 1.0 + + + + org.apache.maven.plugins + maven-dependency-plugin + + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/resources/requirePluginVersions/parentExpression/child/pom.xml b/Java-base/maven-enforcer/src/enforcer-rules/src/test/resources/requirePluginVersions/parentExpression/child/pom.xml new file mode 100644 index 000000000..b67803ab7 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/resources/requirePluginVersions/parentExpression/child/pom.xml @@ -0,0 +1,33 @@ + + + + 4.0.0 + + org.apache.maven.plugins.enforcer.test + + parentExpression + 1.0-SNAPSHOT + + ${project.parent.groupId} + child + ${project.parent.version} + MENFORCER-30 + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/resources/requirePluginVersions/parentExpression/pom.xml b/Java-base/maven-enforcer/src/enforcer-rules/src/test/resources/requirePluginVersions/parentExpression/pom.xml new file mode 100644 index 000000000..4149be70d --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/resources/requirePluginVersions/parentExpression/pom.xml @@ -0,0 +1,27 @@ + + + + 4.0.0 + org.apache.maven.plugins.enforcer.test + parentExpression + 1.0-SNAPSHOT + MENFORCER-30 + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/resources/requirePluginVersions/parentRelativePath/parent/pom.xml b/Java-base/maven-enforcer/src/enforcer-rules/src/test/resources/requirePluginVersions/parentRelativePath/parent/pom.xml new file mode 100644 index 000000000..bccf61737 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/resources/requirePluginVersions/parentRelativePath/parent/pom.xml @@ -0,0 +1,28 @@ + + + + 4.0.0 + org.apache.maven.plugins.enforcer.test + + parent + 1.0-SNAPSHOT + pom + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/resources/requirePluginVersions/parentRelativePath/pom.xml b/Java-base/maven-enforcer/src/enforcer-rules/src/test/resources/requirePluginVersions/parentRelativePath/pom.xml new file mode 100644 index 000000000..f4db837b0 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/resources/requirePluginVersions/parentRelativePath/pom.xml @@ -0,0 +1,33 @@ + + + + 4.0.0 + + org.apache.maven.plugins.enforcer.test + + parent + 1.0-SNAPSHOT + parent/pom.xml + + org.apache.maven.plugins.enforcer.test + aggregate + 1.0-SNAPSHOT + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/resources/requirePluginVersions/parentRelativePathDirectory/parent/pom.xml b/Java-base/maven-enforcer/src/enforcer-rules/src/test/resources/requirePluginVersions/parentRelativePathDirectory/parent/pom.xml new file mode 100644 index 000000000..bccf61737 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/resources/requirePluginVersions/parentRelativePathDirectory/parent/pom.xml @@ -0,0 +1,28 @@ + + + + 4.0.0 + org.apache.maven.plugins.enforcer.test + + parent + 1.0-SNAPSHOT + pom + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/enforcer-rules/src/test/resources/requirePluginVersions/parentRelativePathDirectory/pom.xml b/Java-base/maven-enforcer/src/enforcer-rules/src/test/resources/requirePluginVersions/parentRelativePathDirectory/pom.xml new file mode 100644 index 000000000..de0ec6217 --- /dev/null +++ b/Java-base/maven-enforcer/src/enforcer-rules/src/test/resources/requirePluginVersions/parentRelativePathDirectory/pom.xml @@ -0,0 +1,33 @@ + + + + 4.0.0 + + org.apache.maven.plugins.enforcer.test + + parent + 1.0-SNAPSHOT + parent + + org.apache.maven.plugins.enforcer.test + aggregate + 1.0-SNAPSHOT + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/pom.xml new file mode 100644 index 000000000..78a56f588 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/pom.xml @@ -0,0 +1,218 @@ + + + + 4.0.0 + + + org.apache.maven.enforcer + enforcer + 3.0.0-M4-SNAPSHOT + + + org.apache.maven.plugins + maven-enforcer-plugin + maven-plugin + + + ${maven.version} + + + Apache Maven Enforcer Plugin + The Loving Iron Fist of Maven + + + + org.apache.maven + maven-artifact + + + org.apache.maven + maven-plugin-api + + + org.apache.maven + maven-core + + + org.codehaus.plexus + plexus-utils + + + org.apache.maven.enforcer + enforcer-api + + + org.apache.maven.enforcer + enforcer-rules + + + org.apache.maven.enforcer + enforcer-rules + test-jar + + + org.apache.maven.plugin-testing + maven-plugin-testing-harness + test + + + org.apache.maven.plugin-tools + maven-plugin-annotations + provided + + + org.mockito + mockito-core + test + + + junit + junit + test + + + + + + + + org.apache.rat + apache-rat-plugin + + + + src/it/projects/require-plugin-versions-plugin-with-integration-test-lifecycle/META-INF/MANIFEST.MF + + + + + + + + + org.apache.maven.plugins + maven-plugin-plugin + + true + + + + descriptor-help + + helpmojo + descriptor + + + + + + + + + ${basedir}/src/main/resources + + + + + + + + org.apache.maven.plugins + maven-plugin-plugin + + + + + + + run-its + + false + + + + + org.apache.maven.plugins + maven-invoker-plugin + 3.2.1 + + true + src/it/projects + ${project.build.directory}/it + setup + verify + ${project.build.directory}/local-repo + src/it/mrm/settings.xml + ${maven.it.failure.ignore} + + validate + + + + ${https.protocols} + ${maven.compiler.source} + ${maven.compiler.target} + + + + + integration-test + + install + run + + + + + + org.codehaus.mojo + mrm-maven-plugin + 1.0.0 + + + + start + stop + + + + + repository.proxy.url + + + src/it/mrm/repository + + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer126_maven-plugin-1.0.pom b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer126_maven-plugin-1.0.pom new file mode 100644 index 000000000..093f5aeeb --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer126_maven-plugin-1.0.pom @@ -0,0 +1,27 @@ + + + + 4.0.0 + org.apache.maven.plugins.enforcer.its + menforcer126_maven-plugin + 1.0 + maven-plugin + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer128_api-1.4.0.pom b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer128_api-1.4.0.pom new file mode 100644 index 000000000..d09821b70 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer128_api-1.4.0.pom @@ -0,0 +1,26 @@ + + + + 4.0.0 + org.apache.maven.plugins.enforcer.its + menforcer128_api + 1.4.0 + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer128_api-1.5.0.pom b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer128_api-1.5.0.pom new file mode 100644 index 000000000..c410d1311 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer128_api-1.5.0.pom @@ -0,0 +1,26 @@ + + + + 4.0.0 + org.apache.maven.plugins.enforcer.its + menforcer128_api + 1.5.0 + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer128_api-1.6.0.pom b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer128_api-1.6.0.pom new file mode 100644 index 000000000..720c462c6 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer128_api-1.6.0.pom @@ -0,0 +1,26 @@ + + + + 4.0.0 + org.apache.maven.plugins.enforcer.its + menforcer128_api + 1.6.0 + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer128_classic-0.9.9.pom b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer128_classic-0.9.9.pom new file mode 100644 index 000000000..1db4f40b0 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer128_classic-0.9.9.pom @@ -0,0 +1,34 @@ + + + + 4.0.0 + org.apache.maven.plugins.enforcer.its + menforcer128_classic + 0.9.9 + + + + org.apache.maven.plugins.enforcer.its + menforcer128_api + 1.5.0 + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer134_model-1.0-20130423.042904-7222.pom b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer134_model-1.0-20130423.042904-7222.pom new file mode 100644 index 000000000..125cc1d17 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer134_model-1.0-20130423.042904-7222.pom @@ -0,0 +1,26 @@ + + + + 4.0.0 + org.apache.maven.plugins.enforcer.its + menforcer134_model + 1.0-SNAPSHOT + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer134_model-1.0-20130423.044324-5638.pom b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer134_model-1.0-20130423.044324-5638.pom new file mode 100644 index 000000000..125cc1d17 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer134_model-1.0-20130423.044324-5638.pom @@ -0,0 +1,26 @@ + + + + 4.0.0 + org.apache.maven.plugins.enforcer.its + menforcer134_model + 1.0-SNAPSHOT + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer134_modelbuilder-1.0-SNAPSHOT.pom b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer134_modelbuilder-1.0-SNAPSHOT.pom new file mode 100644 index 000000000..38cae84f9 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer134_modelbuilder-1.0-SNAPSHOT.pom @@ -0,0 +1,34 @@ + + + + 4.0.0 + org.apache.maven.plugins.enforcer.its + menforcer134_modelbuilder + 1.0-SNAPSHOT + + + + org.apache.maven.plugins.enforcer.its + menforcer134_model + 1.0-20130423.044324-5638 + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer134_project-1.0-SNAPSHOT.pom b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer134_project-1.0-SNAPSHOT.pom new file mode 100644 index 000000000..c36a02aa7 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer134_project-1.0-SNAPSHOT.pom @@ -0,0 +1,39 @@ + + + + 4.0.0 + org.apache.maven.plugins.enforcer.its + menforcer134_project + 1.0-SNAPSHOT + + + + org.apache.maven.plugins.enforcer.its + menforcer134_modelbuilder + 1.0-SNAPSHOT + + + org.apache.maven.plugins.enforcer.its + menforcer134_model + 1.0-20130423.042904-7222 + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer138_archiver-2.1.1.pom b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer138_archiver-2.1.1.pom new file mode 100644 index 000000000..0531deee3 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer138_archiver-2.1.1.pom @@ -0,0 +1,44 @@ + + + + 4.0.0 + org.apache.maven.plugins.enforcer.its + menforcer138_archiver + 2.1.1 + + + + org.apache.maven.plugins.enforcer.its + menforcer138_container-default + 1.0-alpha-9-stable-1 + + + org.apache.maven.plugins.enforcer.its + menforcer138_utils + 3.0 + + + org.apache.maven.plugins.enforcer.its + menforcer138_io + 2.0.3 + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer138_classworlds-1.1-alpha-2.pom b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer138_classworlds-1.1-alpha-2.pom new file mode 100644 index 000000000..cd47f0e36 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer138_classworlds-1.1-alpha-2.pom @@ -0,0 +1,26 @@ + + + + 4.0.0 + org.apache.maven.plugins.enforcer.its + menforcer138_classworlds + 1.1-alpha-2 + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer138_container-default-1.0-alpha-9-stable-1.pom b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer138_container-default-1.0-alpha-9-stable-1.pom new file mode 100644 index 000000000..de898f998 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer138_container-default-1.0-alpha-9-stable-1.pom @@ -0,0 +1,39 @@ + + + + 4.0.0 + org.apache.maven.plugins.enforcer.its + menforcer138_container-default + 1.0-alpha-9-stable-1 + + + + org.apache.maven.plugins.enforcer.its + menforcer1308_utils + 1.0.4 + + + org.apache.maven.plugins.enforcer.its + menforcer138_classworlds + 1.1-alpha-2 + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer138_io-2.0.3.pom b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer138_io-2.0.3.pom new file mode 100644 index 000000000..97ccfe1aa --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer138_io-2.0.3.pom @@ -0,0 +1,34 @@ + + + + 4.0.0 + org.apache.maven.plugins.enforcer.its + menforcer138_io + 2.0.3 + + + + org.apache.maven.plugins.enforcer.its + menforcer138_utils + 3.0 + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer138_utils-1.0.4.pom b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer138_utils-1.0.4.pom new file mode 100644 index 000000000..44a20975b --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer138_utils-1.0.4.pom @@ -0,0 +1,26 @@ + + + + 4.0.0 + org.apache.maven.plugins.enforcer.its + menforcer1308_utils + 1.0.4 + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer138_utils-3.0.pom b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer138_utils-3.0.pom new file mode 100644 index 000000000..f96a3943a --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer138_utils-3.0.pom @@ -0,0 +1,26 @@ + + + + 4.0.0 + org.apache.maven.plugins.enforcer.its + menforcer138_utils + 3.0 + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer146_b-1.0.pom b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer146_b-1.0.pom new file mode 100644 index 000000000..c84682125 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer146_b-1.0.pom @@ -0,0 +1,34 @@ + + + + 4.0.0 + org.apache.maven.plugins.enforcer.its + menforcer146-b + 1.0 + + + + org.apache.maven.plugins.enforcer.its + menforcer146-x + 2.1 + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer146_x-1.1.pom b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer146_x-1.1.pom new file mode 100644 index 000000000..24e781e20 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer146_x-1.1.pom @@ -0,0 +1,26 @@ + + + + 4.0.0 + org.apache.maven.plugins.enforcer.its + menforcer146-x + 1.1 + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer146_x-2.1.pom b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer146_x-2.1.pom new file mode 100644 index 000000000..a7272c903 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer146_x-2.1.pom @@ -0,0 +1,26 @@ + + + + 4.0.0 + org.apache.maven.plugins.enforcer.its + menforcer146-x + 2.1 + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer146_x-3.1.pom b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer146_x-3.1.pom new file mode 100644 index 000000000..20eeb1765 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer146_x-3.1.pom @@ -0,0 +1,26 @@ + + + + 4.0.0 + org.apache.maven.plugins.enforcer.its + menforcer146-x + 3.1 + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer152-1.0.pom b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer152-1.0.pom new file mode 100644 index 000000000..084991b2c --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer152-1.0.pom @@ -0,0 +1,27 @@ + + + + 4.0.0 + org.apache.maven.plugins.enforcer.its + menforcer152 + 1.0 + jar + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer158_utils-1.0.pom b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer158_utils-1.0.pom new file mode 100644 index 000000000..33f8b330d --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer158_utils-1.0.pom @@ -0,0 +1,26 @@ + + + + 4.0.0 + org.apache.maven.plugins.enforcer.its + menforcer158_utils + 1.0 + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer269_project-higher-1.0.0.pom b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer269_project-higher-1.0.0.pom new file mode 100644 index 000000000..2a52e739d --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer269_project-higher-1.0.0.pom @@ -0,0 +1,33 @@ + + + + 4.0.0 + org.apache.maven.plugins.enforcer.its + menforcer269_project-higher + 1.0.0 + + + org.apache.maven.plugins.enforcer.its + menforcer128_api + 1.6.0 + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer269_project-lower-1.0.0.pom b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer269_project-lower-1.0.0.pom new file mode 100644 index 000000000..1b9b3b15b --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer269_project-lower-1.0.0.pom @@ -0,0 +1,33 @@ + + + + 4.0.0 + org.apache.maven.plugins.enforcer.its + menforcer269_project-lower + 1.0.0 + + + org.apache.maven.plugins.enforcer.its + menforcer128_api + 1.4.0 + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer269_project-middle-1.0.0.pom b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer269_project-middle-1.0.0.pom new file mode 100644 index 000000000..c133899e2 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer269_project-middle-1.0.0.pom @@ -0,0 +1,33 @@ + + + + 4.0.0 + org.apache.maven.plugins.enforcer.its + menforcer269_project-middle + 1.0.0 + + + org.apache.maven.plugins.enforcer.its + menforcer128_api + 1.5.0 + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer72_junit-3.8.1.pom b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer72_junit-3.8.1.pom new file mode 100644 index 000000000..1286d9f60 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer72_junit-3.8.1.pom @@ -0,0 +1,26 @@ + + + + 4.0.0 + org.apache.maven.plugins.enforcer.its + menforcer72_junit + 3.8.1 + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer72_logging-1.1.1.pom b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer72_logging-1.1.1.pom new file mode 100644 index 000000000..ddfc314c8 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer72_logging-1.1.1.pom @@ -0,0 +1,27 @@ + + + + 4.0.0 + org.apache.maven.plugins.enforcer.its + menforcer72_logging + 1.1.1 + pom + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer85_api-1.0-SNAPSHOT.pom b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer85_api-1.0-SNAPSHOT.pom new file mode 100644 index 000000000..080c63373 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/repository/menforcer85_api-1.0-SNAPSHOT.pom @@ -0,0 +1,26 @@ + + + + 4.0.0 + org.apache.maven.plugins.enforcer.its + menforcer85_api + 1.0-SNAPSHOT + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/settings.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/settings.xml new file mode 100644 index 000000000..49f701650 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/mrm/settings.xml @@ -0,0 +1,73 @@ + + + + + + mrm-maven-plugin + Mock Repository Manager + @repository.proxy.url@ + * + + + + + it-repo + + + snapshots + @repository.proxy.url@ + + true + ignore + never + + + true + ignore + always + + + + + + snapshots + @repository.proxy.url@ + + true + ignore + never + + + true + ignore + always + + + + + + + it-repo + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/MENFORCER-306/parent/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/MENFORCER-306/parent/pom.xml new file mode 100644 index 000000000..d66827e8c --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/MENFORCER-306/parent/pom.xml @@ -0,0 +1,103 @@ + + + + + 4.0.0 + mbenson.test + test-require-plugin-versions + 0.0.1-SNAPSHOT + pom + + 3.0.0-SNAPSHOT + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + enforce-plugin-versions + + enforce + + + + + false + + + + + + + + + + + org.apache.maven.plugins + maven-clean-plugin + 3.1.0 + + + org.apache.maven.plugins + maven-install-plugin + 2.5.2 + + + org.apache.maven.plugins + maven-site-plugin + 3.7.1 + + + org.apache.maven.plugins + maven-deploy-plugin + 2.8.2 + + + org.apache.maven.plugins + maven-compiler-plugin + 3.7.0 + + + org.apache.maven.plugins + maven-plugin-plugin + 3.5.2 + + + org.apache.maven.plugins + maven-surefire-plugin + 2.21.0 + + + org.apache.maven.plugins + maven-jar-plugin + 3.1.0 + + + org.apache.maven.plugins + maven-resources-plugin + 3.1.0 + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/MENFORCER-306/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/MENFORCER-306/pom.xml new file mode 100644 index 000000000..9ad1574a2 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/MENFORCER-306/pom.xml @@ -0,0 +1,31 @@ + + + + + 4.0.0 + + mbenson.test + test-require-plugin-versions + 0.0.1-SNAPSHOT + parent/pom.xml + + pom + pom + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/always-fail-warn/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/always-fail-warn/invoker.properties new file mode 100644 index 000000000..1dcdc6564 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/always-fail-warn/invoker.properties @@ -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 = success diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/always-fail-warn/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/always-fail-warn/pom.xml new file mode 100644 index 000000000..0f809c61c --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/always-fail-warn/pom.xml @@ -0,0 +1,56 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + 1.0 + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + WARN + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/always-fail-warn/verify.groovy b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/always-fail-warn/verify.groovy new file mode 100644 index 000000000..c05c67724 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/always-fail-warn/verify.groovy @@ -0,0 +1,23 @@ +/* + * 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. + */ +File buildLog = new File( basedir, 'build.log' ) +assert buildLog.text.contains( '[WARNING] Rule 0: org.apache.maven.plugins.enforcer.AlwaysFail warned with message:' ) + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/always-fail/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/always-fail/invoker.properties new file mode 100644 index 000000000..58b6526ec --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/always-fail/invoker.properties @@ -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 diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/always-fail/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/always-fail/pom.xml new file mode 100644 index 000000000..53c77c896 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/always-fail/pom.xml @@ -0,0 +1,54 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + 1.0 + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/always-pass/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/always-pass/pom.xml new file mode 100644 index 000000000..2375f8c6e --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/always-pass/pom.xml @@ -0,0 +1,54 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + 1.0 + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-distribution-management-multi-module-build/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-distribution-management-multi-module-build/invoker.properties new file mode 100644 index 000000000..58b6526ec --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-distribution-management-multi-module-build/invoker.properties @@ -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 diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-distribution-management-multi-module-build/module1/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-distribution-management-multi-module-build/module1/pom.xml new file mode 100644 index 000000000..0271bd19c --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-distribution-management-multi-module-build/module1/pom.xml @@ -0,0 +1,42 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.enforcer + ban-distribution-management-mm + 1.0-SNAPSHOT + + module1 + + + + + first + This is the name + file:///Test + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-distribution-management-multi-module-build/module2/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-distribution-management-multi-module-build/module2/pom.xml new file mode 100644 index 000000000..fda2cd8e4 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-distribution-management-multi-module-build/module2/pom.xml @@ -0,0 +1,39 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.enforcer + ban-distribution-management-mm + 1.0-SNAPSHOT + + module2 + + + + org.apache.maven.its.enforcer + module1 + 1.0-SNAPSHOT + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-distribution-management-multi-module-build/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-distribution-management-multi-module-build/pom.xml new file mode 100644 index 000000000..3c4a0a46c --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-distribution-management-multi-module-build/pom.xml @@ -0,0 +1,68 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + ban-distribution-management-mm + 1.0-SNAPSHOT + pom + + + + + first + This is the name + file:///Test + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + + + + + + + + + module1 + module2 + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-distribution-management-multi-module-build/verify.groovy b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-distribution-management-multi-module-build/verify.groovy new file mode 100644 index 000000000..6ff5ee516 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-distribution-management-multi-module-build/verify.groovy @@ -0,0 +1,22 @@ +/* + * 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. + */ +File buildLog = new File( basedir, 'build.log' ) +assert buildLog.text.contains( '[INFO] BUILD FAILURE' ) +assert buildLog.text.contains( '[WARNING] Rule 0: org.apache.maven.plugins.enforcer.BanDistributionManagement failed with message:' ) +assert buildLog.text.contains( 'You have defined a repository in distributionManagement.' ) diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-distribution-management-multi-module-except-site/module1/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-distribution-management-multi-module-except-site/module1/pom.xml new file mode 100644 index 000000000..e3b22a0d2 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-distribution-management-multi-module-except-site/module1/pom.xml @@ -0,0 +1,40 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.enforcer + ban-distribution-management-mm-except-site + 1.0-SNAPSHOT + + module1 + + + + site-location + This is the site + file:///Test/module1 + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-distribution-management-multi-module-except-site/module2/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-distribution-management-multi-module-except-site/module2/pom.xml new file mode 100644 index 000000000..29ce1ab7a --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-distribution-management-multi-module-except-site/module2/pom.xml @@ -0,0 +1,47 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.enforcer + ban-distribution-management-mm-except-site + 1.0-SNAPSHOT + + module2 + + + + site-location + This is the site + file:///Test/module2 + + + + + + org.apache.maven.its.enforcer + module1 + 1.0-SNAPSHOT + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-distribution-management-multi-module-except-site/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-distribution-management-multi-module-except-site/pom.xml new file mode 100644 index 000000000..b7b4db6df --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-distribution-management-multi-module-except-site/pom.xml @@ -0,0 +1,67 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + ban-distribution-management-mm-except-site + 1.0-SNAPSHOT + pom + + + + site-location + This is the site + file:///Test + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + true + + + + + + + + + + + module1 + module2 + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-distribution-management-multi-module-except-site/verify.groovy b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-distribution-management-multi-module-except-site/verify.groovy new file mode 100644 index 000000000..6db67a725 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-distribution-management-multi-module-except-site/verify.groovy @@ -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. + */ +File buildLog = new File( basedir, 'build.log' ) +assert buildLog.text.contains( '[INFO] BUILD SUCCESS' ) diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-distribution-management/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-distribution-management/pom.xml new file mode 100644 index 000000000..304aa5e2f --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-distribution-management/pom.xml @@ -0,0 +1,55 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + ban-distribution-management + 1.0 + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-distribution-management/verify.groovy b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-distribution-management/verify.groovy new file mode 100644 index 000000000..6db67a725 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-distribution-management/verify.groovy @@ -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. + */ +File buildLog = new File( basedir, 'build.log' ) +assert buildLog.text.contains( '[INFO] BUILD SUCCESS' ) diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-pom-dependency-version-utf8-with-bom/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-pom-dependency-version-utf8-with-bom/invoker.properties new file mode 100644 index 000000000..c98ac4c5b --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-pom-dependency-version-utf8-with-bom/invoker.properties @@ -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 \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-pom-dependency-version-utf8-with-bom/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-pom-dependency-version-utf8-with-bom/pom.xml new file mode 100644 index 000000000..125f87e57 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-pom-dependency-version-utf8-with-bom/pom.xml @@ -0,0 +1,65 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + ban-pom-dependency-version-utf8-with-bom + 1.0-SNAPSHOT + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + + + + + + + + + + org.apache.maven.plugins.enforcer.its + menforcer152 + 1.0 + + + org.apache.maven.plugins.enforcer.its + menforcer152 + 1.0 + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-pom-dependency-version-utf8-with-bom/verify.groovy b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-pom-dependency-version-utf8-with-bom/verify.groovy new file mode 100644 index 000000000..eb917f976 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-pom-dependency-version-utf8-with-bom/verify.groovy @@ -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. + */ +File buildLog = new File( basedir, 'build.log' ) +assert buildLog.text.contains( '[WARNING] Rule 0: org.apache.maven.plugins.enforcer.BanDuplicatePomDependencyVersions failed with message:' ) +assert buildLog.text.contains( 'Found 1 duplicate dependency declaration in this project:' ) +assert buildLog.text.contains( '- dependencies.dependency[org.apache.maven.plugins.enforcer.its:menforcer152:jar] ( 2 times )' ) + + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-pom-dependency-version/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-pom-dependency-version/invoker.properties new file mode 100644 index 000000000..c98ac4c5b --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-pom-dependency-version/invoker.properties @@ -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 \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-pom-dependency-version/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-pom-dependency-version/pom.xml new file mode 100644 index 000000000..95c345a01 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-pom-dependency-version/pom.xml @@ -0,0 +1,65 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + ban-pom-dependency-version + 1.0-SNAPSHOT + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + + + + + + + + + + org.apache.maven.plugins.enforcer.its + menforcer152 + 1.0 + + + org.apache.maven.plugins.enforcer.its + menforcer152 + 1.0 + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-pom-dependency-version/verify.groovy b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-pom-dependency-version/verify.groovy new file mode 100644 index 000000000..0c251289a --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-pom-dependency-version/verify.groovy @@ -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. + */ +File buildLog = new File( basedir, 'build.log' ) +assert buildLog.text.contains( '[WARNING] Rule 0: org.apache.maven.plugins.enforcer.BanDuplicatePomDependencyVersions failed with message:' ) +assert buildLog.text.contains( 'Found 1 duplicate dependency declaration in this project:' ) +assert buildLog.text.contains( '- dependencies.dependency[org.apache.maven.plugins.enforcer.its:menforcer152:jar] ( 2 times )' ) + + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-transitive-dependencies-fail/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-transitive-dependencies-fail/invoker.properties new file mode 100644 index 000000000..58b6526ec --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-transitive-dependencies-fail/invoker.properties @@ -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 diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-transitive-dependencies-fail/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-transitive-dependencies-fail/pom.xml new file mode 100644 index 000000000..071260e16 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-transitive-dependencies-fail/pom.xml @@ -0,0 +1,70 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + ban-transitive-fail-test + 1.0 + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + org.apache.maven.plugins.enforcer.its:menforcer138_classworlds + org.apache.maven.plugins.enforcer.its:menforcer138_io + + + + + + + + + + + + + org.apache.maven.plugins.enforcer.its + menforcer138_archiver + 2.1.1 + + + org.apache.maven.plugins.enforcer.its + menforcer138_utils + 3.0 + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-transitive-dependencies-fail/verify.groovy b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-transitive-dependencies-fail/verify.groovy new file mode 100644 index 000000000..5dacb9434 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-transitive-dependencies-fail/verify.groovy @@ -0,0 +1,21 @@ +/* + * 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. + */ +File buildLog = new File( basedir, 'build.log' ) +assert buildLog.text.contains( '[WARNING] Rule 0: org.apache.maven.plugins.enforcer.BanTransitiveDependencies failed with message:' ) + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-transitive-dependencies/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-transitive-dependencies/pom.xml new file mode 100644 index 000000000..d83287a08 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/ban-transitive-dependencies/pom.xml @@ -0,0 +1,70 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + ban-transitive-test + 1.0 + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + org.apache.maven.plugins.enforcer.its:menforcer138_container-default + org.apache.maven.plugins.enforcer.its:menforcer138_io + + + + + + + + + + + + + org.apache.maven.plugins.enforcer.its + menforcer138_archiver + 2.1.1 + + + org.apache.maven.plugins.enforcer.its + menforcer138_utils + 3.0 + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/banned-dependencies-versionrange-fail/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/banned-dependencies-versionrange-fail/invoker.properties new file mode 100644 index 000000000..58b6526ec --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/banned-dependencies-versionrange-fail/invoker.properties @@ -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 diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/banned-dependencies-versionrange-fail/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/banned-dependencies-versionrange-fail/pom.xml new file mode 100644 index 000000000..c07f13477 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/banned-dependencies-versionrange-fail/pom.xml @@ -0,0 +1,74 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + menforcer72 + 1.0 + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + org.apache.maven.plugins.enforcer.its:menforcer72_junit:[3.8,4.0):jar + org.apache.maven.plugins.enforcer.its:menforcer72_logging:[1.0,2.0) + + + + + + + + + + + + + org.apache.maven.plugins.enforcer.its + menforcer72_logging + 1.1.1 + pom + + + org.apache.maven.plugins.enforcer.its + menforcer72_junit + 3.8.1 + test + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/banned-dependencies-versionrange-fail/verify.groovy b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/banned-dependencies-versionrange-fail/verify.groovy new file mode 100644 index 000000000..c1e09434a --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/banned-dependencies-versionrange-fail/verify.groovy @@ -0,0 +1,21 @@ +/* + * 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. + */ +File buildLog = new File( basedir, 'build.log' ) +assert buildLog.text.contains( '[WARNING] Rule 0: org.apache.maven.plugins.enforcer.BannedDependencies failed with message:' ) + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/banned-dependencies-versionrange/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/banned-dependencies-versionrange/pom.xml new file mode 100644 index 000000000..d934fa6cf --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/banned-dependencies-versionrange/pom.xml @@ -0,0 +1,76 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + menforcer72 + 1.0 + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + org.apache.maven.plugins.enforcer.its:menforcer72_junit:[3.8,4.0):jar + + + org.apache.maven.plugins.enforcer.its:menforcer72_junit:[3.8,4.0):*:test + + + + + + + + + + + + + org.apache.maven.plugins.enforcer.its + menforcer72_logging + 1.1.1 + pom + + + org.apache.maven.plugins.enforcer.its + menforcer72_junit + 3.8.1 + test + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/banned-dependencies-wildcards/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/banned-dependencies-wildcards/pom.xml new file mode 100644 index 000000000..563631e3f --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/banned-dependencies-wildcards/pom.xml @@ -0,0 +1,76 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + menforcer72 + 1.0 + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + *:*:*:jar + + + *:menforcer72_junit:*:*:test + + + + + + + + + + + + + org.apache.maven.plugins.enforcer.its + menforcer72_logging + 1.1.1 + pom + + + org.apache.maven.plugins.enforcer.its + menforcer72_junit + 3.8.1 + test + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/banned-dependencies/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/banned-dependencies/pom.xml new file mode 100644 index 000000000..8fd7fc5de --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/banned-dependencies/pom.xml @@ -0,0 +1,58 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + 1.0 + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + org.apache.maven.plugins.enforcer.its:menforcer72_logging + + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/banned-plugins/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/banned-plugins/pom.xml new file mode 100644 index 000000000..7a59cd89e --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/banned-plugins/pom.xml @@ -0,0 +1,55 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + 1.0 + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/builds_a_pom_noop/module/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/builds_a_pom_noop/module/pom.xml new file mode 100644 index 000000000..f0dfcfddb --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/builds_a_pom_noop/module/pom.xml @@ -0,0 +1,30 @@ + + + + 4.0.0 + + test + TestParent + 1.0-SNAPSHOT + + TestModule + 1.0-SNAPSHOT + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/builds_a_pom_noop/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/builds_a_pom_noop/pom.xml new file mode 100644 index 000000000..0ffa71b65 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/builds_a_pom_noop/pom.xml @@ -0,0 +1,49 @@ + + + + 4.0.0 + test + TestParent + 1.0-SNAPSHOT + pom + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + enforce + + + + + + + enforce + + + + + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/cli-always-fail/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/cli-always-fail/invoker.properties new file mode 100644 index 000000000..ee2da69d8 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/cli-always-fail/invoker.properties @@ -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 = ${project.groupId}:${project.artifactId}:${project.version}:enforce -Drules=alwaysFail +invoker.buildResult = failure diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/cli-always-fail/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/cli-always-fail/pom.xml new file mode 100644 index 000000000..0915303c4 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/cli-always-fail/pom.xml @@ -0,0 +1,41 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + 1.0 + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/cli-always-pass/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/cli-always-pass/invoker.properties new file mode 100644 index 000000000..c67cebe4a --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/cli-always-pass/invoker.properties @@ -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 = ${project.groupId}:${project.artifactId}:${project.version}:enforce -Drules=alwaysPass +invoker.buildResult = success diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/cli-always-pass/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/cli-always-pass/pom.xml new file mode 100644 index 000000000..2375f8c6e --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/cli-always-pass/pom.xml @@ -0,0 +1,54 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + 1.0 + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/dependencies_converge/module/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/dependencies_converge/module/pom.xml new file mode 100644 index 000000000..f0dfcfddb --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/dependencies_converge/module/pom.xml @@ -0,0 +1,30 @@ + + + + 4.0.0 + + test + TestParent + 1.0-SNAPSHOT + + TestModule + 1.0-SNAPSHOT + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/dependencies_converge/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/dependencies_converge/pom.xml new file mode 100644 index 000000000..5cb6be30c --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/dependencies_converge/pom.xml @@ -0,0 +1,67 @@ + + + + 4.0.0 + test + TestParent + 1.0 + jar + + + org.slf4j + slf4j-jdk14 + 1.6.1 + + + org.slf4j + slf4j-nop + 1.6.0 + + + org.slf4j + slf4j-api + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + enforce + + + + + + + enforce + + + + + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/dependencies_converge_exclude_wildcard/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/dependencies_converge_exclude_wildcard/invoker.properties new file mode 100644 index 000000000..c4dc6a185 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/dependencies_converge_exclude_wildcard/invoker.properties @@ -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.maven.version = 3.6.2+ diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/dependencies_converge_exclude_wildcard/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/dependencies_converge_exclude_wildcard/pom.xml new file mode 100644 index 000000000..524019878 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/dependencies_converge_exclude_wildcard/pom.xml @@ -0,0 +1,67 @@ + + + + 4.0.0 + test + TestParent + 1.0 + jar + + + org.apache.maven.plugins.enforcer.its + menforcer269_project-middle + 1.0.0 + + + org.apache.maven.plugins.enforcer.its + menforcer269_project-higher + 1.0.0 + + + * + * + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + enforce + + + + + + + enforce + + + + + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/dependencies_not_converging/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/dependencies_not_converging/invoker.properties new file mode 100644 index 000000000..c98ac4c5b --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/dependencies_not_converging/invoker.properties @@ -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 \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/dependencies_not_converging/module/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/dependencies_not_converging/module/pom.xml new file mode 100644 index 000000000..6d2c1bb52 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/dependencies_not_converging/module/pom.xml @@ -0,0 +1,30 @@ + + + + 4.0.0 + + test + TestParent + 1.0-SNAPSHOT + + TestModule + 1.1-SNAPSHOT + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/dependencies_not_converging/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/dependencies_not_converging/pom.xml new file mode 100644 index 000000000..a33316a31 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/dependencies_not_converging/pom.xml @@ -0,0 +1,61 @@ + + + + 4.0.0 + test + TestParent + 1.0-SNAPSHOT + jar + + + org.slf4j + slf4j-jdk14 + 1.6.1 + + + org.slf4j + slf4j-nop + 1.6.0 + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + enforce + + + + + + + enforce + + + + + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/dependencies_not_converging_test_scope/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/dependencies_not_converging_test_scope/invoker.properties new file mode 100644 index 000000000..c98ac4c5b --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/dependencies_not_converging_test_scope/invoker.properties @@ -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 \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/dependencies_not_converging_test_scope/module/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/dependencies_not_converging_test_scope/module/pom.xml new file mode 100644 index 000000000..6d2c1bb52 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/dependencies_not_converging_test_scope/module/pom.xml @@ -0,0 +1,30 @@ + + + + 4.0.0 + + test + TestParent + 1.0-SNAPSHOT + + TestModule + 1.1-SNAPSHOT + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/dependencies_not_converging_test_scope/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/dependencies_not_converging_test_scope/pom.xml new file mode 100644 index 000000000..223aa9ac0 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/dependencies_not_converging_test_scope/pom.xml @@ -0,0 +1,62 @@ + + + + 4.0.0 + test + TestParent + 1.0-SNAPSHOT + jar + + + org.slf4j + slf4j-jdk14 + 1.6.1 + + + org.slf4j + slf4j-nop + 1.6.0 + test + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + enforce + + + + + + + enforce + + + + + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/display-info/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/display-info/pom.xml new file mode 100644 index 000000000..8746ad7ae --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/display-info/pom.xml @@ -0,0 +1,44 @@ + + + + + + 4.0.0 + org.apache.maven.its.enforcer + display-info + 1.0 + + + + maven-enforcer-plugin + @project.version@ + + + test + validate + + display-info + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/display-info/verify.groovy b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/display-info/verify.groovy new file mode 100644 index 000000000..77b2db98d --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/display-info/verify.groovy @@ -0,0 +1,22 @@ +/* + * 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. + */ + +File buildLog = new File( basedir, 'build.log' ) +assert buildLog.text.contains( 'Maven Version:' ) +assert buildLog.text.contains( 'JDK Version:' ) diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/evaluate-beanshell/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/evaluate-beanshell/pom.xml new file mode 100644 index 000000000..fd6dcea4a --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/evaluate-beanshell/pom.xml @@ -0,0 +1,56 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + 1.0 + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + ${project.artifactId} == test + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-ban-transitive-dependencies/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-ban-transitive-dependencies/invoker.properties new file mode 100644 index 000000000..cfde2fc6c --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-ban-transitive-dependencies/invoker.properties @@ -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 diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-ban-transitive-dependencies/module1/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-ban-transitive-dependencies/module1/pom.xml new file mode 100644 index 000000000..6776bc8ac --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-ban-transitive-dependencies/module1/pom.xml @@ -0,0 +1,44 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.enforcer + multimodule + 1.0-SNAPSHOT + + module1 + + + + org.apache.maven.plugins.enforcer.its + menforcer138_archiver + 2.1.1 + + + org.apache.maven.plugins.enforcer.its + menforcer138_utils + 3.0 + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-ban-transitive-dependencies/module2/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-ban-transitive-dependencies/module2/pom.xml new file mode 100644 index 000000000..bf29ba982 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-ban-transitive-dependencies/module2/pom.xml @@ -0,0 +1,39 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.enforcer + multimodule + 1.0-SNAPSHOT + + module2 + + + + org.apache.maven.its.enforcer + module1 + 1.0-SNAPSHOT + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-ban-transitive-dependencies/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-ban-transitive-dependencies/pom.xml new file mode 100644 index 000000000..3b7b2cd10 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-ban-transitive-dependencies/pom.xml @@ -0,0 +1,62 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + multimodule + 1.0-SNAPSHOT + pom + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + org.apache.maven.plugins.enforcer.its:menforcer138_archiver + org.apache.maven.plugins.enforcer.its:menforcer138_utils + + + + + + + + + + + + module1 + module2 + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-ban-transitive-dependencies_failure/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-ban-transitive-dependencies_failure/invoker.properties new file mode 100644 index 000000000..6c71fcc1e --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-ban-transitive-dependencies_failure/invoker.properties @@ -0,0 +1,19 @@ +# 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 +invoker.buildResult = failure diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-ban-transitive-dependencies_failure/module1/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-ban-transitive-dependencies_failure/module1/pom.xml new file mode 100644 index 000000000..6776bc8ac --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-ban-transitive-dependencies_failure/module1/pom.xml @@ -0,0 +1,44 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.enforcer + multimodule + 1.0-SNAPSHOT + + module1 + + + + org.apache.maven.plugins.enforcer.its + menforcer138_archiver + 2.1.1 + + + org.apache.maven.plugins.enforcer.its + menforcer138_utils + 3.0 + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-ban-transitive-dependencies_failure/module2/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-ban-transitive-dependencies_failure/module2/pom.xml new file mode 100644 index 000000000..bf29ba982 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-ban-transitive-dependencies_failure/module2/pom.xml @@ -0,0 +1,39 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.enforcer + multimodule + 1.0-SNAPSHOT + + module2 + + + + org.apache.maven.its.enforcer + module1 + 1.0-SNAPSHOT + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-ban-transitive-dependencies_failure/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-ban-transitive-dependencies_failure/pom.xml new file mode 100644 index 000000000..735e1a832 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-ban-transitive-dependencies_failure/pom.xml @@ -0,0 +1,62 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + multimodule + 1.0-SNAPSHOT + pom + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + org.apache.maven.plugins.enforcer.its:menforcer138_archiver + org.apache.maven.plugins.enforcer.its:menforcer138_io + + + + + + + + + + + + module1 + module2 + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-ban-transitive-dependencies_failure/verify.groovy b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-ban-transitive-dependencies_failure/verify.groovy new file mode 100644 index 000000000..793e850ec --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-ban-transitive-dependencies_failure/verify.groovy @@ -0,0 +1,22 @@ +/* + * 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. + */ +File buildLog = new File( basedir, 'build.log' ) + +assert buildLog.text.contains( 'Rule 0: org.apache.maven.plugins.enforcer.BanTransitiveDependencies failed with message:' ) +assert buildLog.text.contains( 'org.apache.maven.its.enforcer:module1:jar:1.0-SNAPSHOT:compile has transitive dependencies:' ) diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-exclude/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-exclude/invoker.properties new file mode 100644 index 000000000..cfde2fc6c --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-exclude/invoker.properties @@ -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 diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-exclude/module1/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-exclude/module1/pom.xml new file mode 100644 index 000000000..2e6a22262 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-exclude/module1/pom.xml @@ -0,0 +1,32 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.enforcer + multimodule + 1.0-SNAPSHOT + + module1 + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-exclude/module2/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-exclude/module2/pom.xml new file mode 100644 index 000000000..bf29ba982 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-exclude/module2/pom.xml @@ -0,0 +1,39 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.enforcer + multimodule + 1.0-SNAPSHOT + + module2 + + + + org.apache.maven.its.enforcer + module1 + 1.0-SNAPSHOT + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-exclude/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-exclude/pom.xml new file mode 100644 index 000000000..233d2021d --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-exclude/pom.xml @@ -0,0 +1,62 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + multimodule + 1.0-SNAPSHOT + pom + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + false + + ${project.groupId}:module1 + + + + + + + + + + + + module1 + module2 + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-exclude_failure/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-exclude_failure/invoker.properties new file mode 100644 index 000000000..6c71fcc1e --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-exclude_failure/invoker.properties @@ -0,0 +1,19 @@ +# 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 +invoker.buildResult = failure diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-exclude_failure/module1/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-exclude_failure/module1/pom.xml new file mode 100644 index 000000000..2e6a22262 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-exclude_failure/module1/pom.xml @@ -0,0 +1,32 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.enforcer + multimodule + 1.0-SNAPSHOT + + module1 + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-exclude_failure/module2/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-exclude_failure/module2/pom.xml new file mode 100644 index 000000000..bf29ba982 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-exclude_failure/module2/pom.xml @@ -0,0 +1,39 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.enforcer + multimodule + 1.0-SNAPSHOT + + module2 + + + + org.apache.maven.its.enforcer + module1 + 1.0-SNAPSHOT + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-exclude_failure/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-exclude_failure/pom.xml new file mode 100644 index 000000000..9b061ae0f --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-exclude_failure/pom.xml @@ -0,0 +1,59 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + multimodule + 1.0-SNAPSHOT + pom + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + false + + + + + + + + + + + module1 + module2 + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-exclude_failure/verify.groovy b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-exclude_failure/verify.groovy new file mode 100644 index 000000000..437bb461b --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-exclude_failure/verify.groovy @@ -0,0 +1,22 @@ +/* + * 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. + */ +File buildLog = new File( basedir, 'build.log' ) + +assert buildLog.text.contains( 'Rule 0: org.apache.maven.plugins.enforcer.RequireReleaseDeps failed with message:' ) +assert buildLog.text.contains( 'Found Banned Dependency: org.apache.maven.its.enforcer:module1:jar:1.0-SNAPSHOT' ) diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-snapshot-parent_failure/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-snapshot-parent_failure/invoker.properties new file mode 100644 index 000000000..6c71fcc1e --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-snapshot-parent_failure/invoker.properties @@ -0,0 +1,19 @@ +# 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 +invoker.buildResult = failure diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-snapshot-parent_failure/module1/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-snapshot-parent_failure/module1/pom.xml new file mode 100644 index 000000000..2e6a22262 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-snapshot-parent_failure/module1/pom.xml @@ -0,0 +1,32 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.enforcer + multimodule + 1.0-SNAPSHOT + + module1 + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-snapshot-parent_failure/module2/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-snapshot-parent_failure/module2/pom.xml new file mode 100644 index 000000000..c15aff36f --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-snapshot-parent_failure/module2/pom.xml @@ -0,0 +1,67 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.enforcer + multimodule + 1.0-SNAPSHOT + + module2 + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + + ${project.groupId}:module1 + + + + + + + + + + + + + org.apache.maven.its.enforcer + module1 + 1.0-SNAPSHOT + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-snapshot-parent_failure/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-snapshot-parent_failure/pom.xml new file mode 100644 index 000000000..b39b740d3 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-snapshot-parent_failure/pom.xml @@ -0,0 +1,34 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + multimodule + 1.0-SNAPSHOT + pom + + + module1 + module2 + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-snapshot-parent_failure/verify.groovy b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-snapshot-parent_failure/verify.groovy new file mode 100644 index 000000000..eb308923d --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies-snapshot-parent_failure/verify.groovy @@ -0,0 +1,22 @@ +/* + * 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. + */ +File buildLog = new File( basedir, 'build.log' ) + +assert buildLog.text.contains( 'Rule 0: org.apache.maven.plugins.enforcer.RequireReleaseDeps failed with message:' ) +assert buildLog.text.contains( 'Parent Cannot be a snapshot: org.apache.maven.its.enforcer:multimodule:pom:1.0-SNAPSHOT' ) diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies/invoker.properties new file mode 100644 index 000000000..cfde2fc6c --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies/invoker.properties @@ -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 diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies/module1/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies/module1/pom.xml new file mode 100644 index 000000000..fc47a9775 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies/module1/pom.xml @@ -0,0 +1,32 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.enforcer + multimodule + 1.0 + + module1 + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies/module2/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies/module2/pom.xml new file mode 100644 index 000000000..e439ec5c3 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies/module2/pom.xml @@ -0,0 +1,39 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.enforcer + multimodule + 1.0 + + module2 + + + + org.apache.maven.its.enforcer + module1 + 1.0 + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies/pom.xml new file mode 100644 index 000000000..ec96bd6ee --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule-require-release-dependencies/pom.xml @@ -0,0 +1,57 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + multimodule + 1.0 + pom + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + + + + + + + + + module1 + module2 + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule/invoker.properties new file mode 100644 index 000000000..d77c182d9 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule/invoker.properties @@ -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 diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule/module1/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule/module1/pom.xml new file mode 100644 index 000000000..549ffeb9a --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule/module1/pom.xml @@ -0,0 +1,32 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.enforcer + multimodule + 1.0-SNAPSHOT + + module1 + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule/module2/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule/module2/pom.xml new file mode 100644 index 000000000..f6de11a6b --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule/module2/pom.xml @@ -0,0 +1,39 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.enforcer + multimodule + 1.0-SNAPSHOT + + module2 + + + + org.apache.maven.its.enforcer + module1 + 1.0-SNAPSHOT + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule/pom.xml new file mode 100644 index 000000000..6b45cb2d2 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/multimodule/pom.xml @@ -0,0 +1,57 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + multimodule + 1.0-SNAPSHOT + pom + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + + + + + + + + + module1 + module2 + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-active-profile-all/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-active-profile-all/pom.xml new file mode 100644 index 000000000..c7082ddfe --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-active-profile-all/pom.xml @@ -0,0 +1,78 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + 1.0 + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + it1,it2,it3 + true + + + + + + + + + + + + it1 + + true + + + + it2 + + true + + + + it3 + + true + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-active-profile-from-settings/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-active-profile-from-settings/pom.xml new file mode 100644 index 000000000..bd9359bb7 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-active-profile-from-settings/pom.xml @@ -0,0 +1,79 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + 1.0 + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + it1,it2,it3,it-repo + true + + + + + + + + + + + + it1 + + true + + + + it2 + + true + + + + it3 + + true + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-active-profile/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-active-profile/pom.xml new file mode 100644 index 000000000..b57cce629 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-active-profile/pom.xml @@ -0,0 +1,65 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + 1.0 + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + it + + + + + + + + + + + + it + + true + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-file-checksum/LICENSE b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-file-checksum/LICENSE new file mode 100644 index 000000000..a6301e0de --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-file-checksum/LICENSE @@ -0,0 +1,16 @@ +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. diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-file-checksum/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-file-checksum/pom.xml new file mode 100644 index 000000000..46e5a44ed --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-file-checksum/pom.xml @@ -0,0 +1,78 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + 1.0 + https://issues.apache.org/jira/browse/MENFORCER-247 + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + ${project.basedir}/LICENSE + md5 + 7c5b65d44e8123e70d24d9eef17e9fa2 + + + ${project.basedir}/LICENSE + sha1 + 278661cbaf6a1bcbd34e3877b6de0e8bd7097846 + + + ${project.basedir}/LICENSE + sha256 + 61b825d68516541151e5ce0145e54765c48cd5802b886aee8fb8cf1953f02d10 + + + ${project.basedir}/LICENSE + sha384 + 6f9e6b81487911c5a339c541016a459acaf8312e430ccabe5c10cb2ddf9a307f4595c78555f911377f4fb853ffe87046 + + + ${project.basedir}/LICENSE + sha512 + c51c3cf07c87af78dd7af4407ae3993ea1051d8a7c260cf34bbaa41c468dcd3b62d2be3d9a09807a8595d0065e2d75d1bf9ffc8276d567a983ff057f6b51b0cc + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-file-checksum/setup.groovy b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-file-checksum/setup.groovy new file mode 100644 index 000000000..059795a4e --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-file-checksum/setup.groovy @@ -0,0 +1,22 @@ +/* + * 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 file = new File (basedir,"LICENSE") + + file.write(file.text.normalize()) \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-files-dont-exist/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-files-dont-exist/pom.xml new file mode 100644 index 000000000..544c1a2cc --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-files-dont-exist/pom.xml @@ -0,0 +1,58 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + 1.0 + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + target/unwanted.txt + + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-files-exist/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-files-exist/pom.xml new file mode 100644 index 000000000..ce4612ced --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-files-exist/pom.xml @@ -0,0 +1,58 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + 1.0 + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + pom.xml + + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-files-size/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-files-size/pom.xml new file mode 100644 index 000000000..42235988d --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-files-size/pom.xml @@ -0,0 +1,60 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + 1.0 + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + 10240 + 512 + + pom.xml + + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-java-version/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-java-version/pom.xml new file mode 100644 index 000000000..8e85cffdd --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-java-version/pom.xml @@ -0,0 +1,61 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + 1.0 + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + 1.4 + + + + [1.4,) + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-maven-version/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-maven-version/pom.xml new file mode 100644 index 000000000..e2c26df4d --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-maven-version/pom.xml @@ -0,0 +1,61 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + 1.0 + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + 2.0 + + + + [2.0,) + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories-allow-plugin-repo/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories-allow-plugin-repo/invoker.properties new file mode 100644 index 000000000..c98ac4c5b --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories-allow-plugin-repo/invoker.properties @@ -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 \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories-allow-plugin-repo/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories-allow-plugin-repo/pom.xml new file mode 100644 index 000000000..cc568e264 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories-allow-plugin-repo/pom.xml @@ -0,0 +1,72 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + 1.0 + + This IT makes sure to prevent having pluginRepositories inside the pom. + + + + plugin-repo + http://example.com/repo + + + + + com.asual.maven.public + Asual Public Repository + http://localhost + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + plugin-repo + + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories-allow-plugin-repo/verify.groovy b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories-allow-plugin-repo/verify.groovy new file mode 100644 index 000000000..c0657656b --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories-allow-plugin-repo/verify.groovy @@ -0,0 +1,22 @@ +/* + * 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. + */ +File buildLog = new File( basedir, 'build.log' ) +assert buildLog.text.contains( '[WARNING] Rule 0: org.apache.maven.plugins.enforcer.RequireNoRepositories failed with message:' ) +assert buildLog.text.contains( 'Some poms have repositories defined:' ) +assert buildLog.text.contains( 'org.apache.maven.its.enforcer:test version:1.0 has repositories [com.asual.maven.public]' ) diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories-allow-repo/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories-allow-repo/invoker.properties new file mode 100644 index 000000000..c98ac4c5b --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories-allow-repo/invoker.properties @@ -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 \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories-allow-repo/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories-allow-repo/pom.xml new file mode 100644 index 000000000..9c9aa2788 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories-allow-repo/pom.xml @@ -0,0 +1,72 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + 1.0 + + This IT makes sure to prevent having pluginRepositories inside the pom. + + + + plugin-repo + http://example.com/repo + + + + + com.asual.maven.public + Asual Public Repository + http://localhost + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + com.asual.maven.public + + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories-allow-repo/verify.groovy b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories-allow-repo/verify.groovy new file mode 100644 index 000000000..b9538f39d --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories-allow-repo/verify.groovy @@ -0,0 +1,22 @@ +/* + * 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. + */ +File buildLog = new File( basedir, 'build.log' ) +assert buildLog.text.contains( '[WARNING] Rule 0: org.apache.maven.plugins.enforcer.RequireNoRepositories failed with message:' ) +assert buildLog.text.contains( 'Some poms have repositories defined:' ) +assert buildLog.text.contains( 'org.apache.maven.its.enforcer:test version:1.0 has plugin repositories [plugin-repo]' ) diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories/pom.xml new file mode 100644 index 000000000..bf5d7f903 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories/pom.xml @@ -0,0 +1,56 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + 1.0 + + + This IT demonstrates having no repositories defined at all. + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure/invoker.properties new file mode 100644 index 000000000..c98ac4c5b --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure/invoker.properties @@ -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 \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure/pom.xml new file mode 100644 index 000000000..2075770c1 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure/pom.xml @@ -0,0 +1,60 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + 1.0 + + + + com.asual.maven.public + Asual Public Repository + http://localhost + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure/verify.groovy b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure/verify.groovy new file mode 100644 index 000000000..c0657656b --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure/verify.groovy @@ -0,0 +1,22 @@ +/* + * 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. + */ +File buildLog = new File( basedir, 'build.log' ) +assert buildLog.text.contains( '[WARNING] Rule 0: org.apache.maven.plugins.enforcer.RequireNoRepositories failed with message:' ) +assert buildLog.text.contains( 'Some poms have repositories defined:' ) +assert buildLog.text.contains( 'org.apache.maven.its.enforcer:test version:1.0 has repositories [com.asual.maven.public]' ) diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_allowed-plugin-repo/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_allowed-plugin-repo/invoker.properties new file mode 100644 index 000000000..c98ac4c5b --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_allowed-plugin-repo/invoker.properties @@ -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 \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_allowed-plugin-repo/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_allowed-plugin-repo/pom.xml new file mode 100644 index 000000000..557a44c63 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_allowed-plugin-repo/pom.xml @@ -0,0 +1,73 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + 1.0 + + This IT makes sure to prevent having defined pluginRepository and repository in allowedPluginRepositories + + + + plugin-repo + http://example.com/repo + + + + + com.asual.maven.public + Asual Public Repository + http://localhost + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + plugin-repo + com.asual.maven.public + + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_allowed-plugin-repo/verify.groovy b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_allowed-plugin-repo/verify.groovy new file mode 100644 index 000000000..c0657656b --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_allowed-plugin-repo/verify.groovy @@ -0,0 +1,22 @@ +/* + * 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. + */ +File buildLog = new File( basedir, 'build.log' ) +assert buildLog.text.contains( '[WARNING] Rule 0: org.apache.maven.plugins.enforcer.RequireNoRepositories failed with message:' ) +assert buildLog.text.contains( 'Some poms have repositories defined:' ) +assert buildLog.text.contains( 'org.apache.maven.its.enforcer:test version:1.0 has repositories [com.asual.maven.public]' ) diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_plugin-repositories/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_plugin-repositories/invoker.properties new file mode 100644 index 000000000..c98ac4c5b --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_plugin-repositories/invoker.properties @@ -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 \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_plugin-repositories/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_plugin-repositories/pom.xml new file mode 100644 index 000000000..0ceb88b07 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_plugin-repositories/pom.xml @@ -0,0 +1,59 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + 1.0 + + + + repo + http://example.com/repo + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_plugin-repositories/verify.groovy b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_plugin-repositories/verify.groovy new file mode 100644 index 000000000..b3c2b468b --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_plugin-repositories/verify.groovy @@ -0,0 +1,22 @@ +/* + * 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. + */ +File buildLog = new File( basedir, 'build.log' ) +assert buildLog.text.contains( '[WARNING] Rule 0: org.apache.maven.plugins.enforcer.RequireNoRepositories failed with message:' ) +assert buildLog.text.contains( 'Some poms have repositories defined:' ) +assert buildLog.text.contains( 'org.apache.maven.its.enforcer:test version:1.0 has plugin repositories [repo]' ) diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_repositories/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_repositories/invoker.properties new file mode 100644 index 000000000..c98ac4c5b --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_repositories/invoker.properties @@ -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 \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_repositories/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_repositories/pom.xml new file mode 100644 index 000000000..cc568e264 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_repositories/pom.xml @@ -0,0 +1,72 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + 1.0 + + This IT makes sure to prevent having pluginRepositories inside the pom. + + + + plugin-repo + http://example.com/repo + + + + + com.asual.maven.public + Asual Public Repository + http://localhost + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + plugin-repo + + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_repositories/verify.groovy b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_repositories/verify.groovy new file mode 100644 index 000000000..c0657656b --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_failure_repositories/verify.groovy @@ -0,0 +1,22 @@ +/* + * 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. + */ +File buildLog = new File( basedir, 'build.log' ) +assert buildLog.text.contains( '[WARNING] Rule 0: org.apache.maven.plugins.enforcer.RequireNoRepositories failed with message:' ) +assert buildLog.text.contains( 'Some poms have repositories defined:' ) +assert buildLog.text.contains( 'org.apache.maven.its.enforcer:test version:1.0 has repositories [com.asual.maven.public]' ) diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_mm/child/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_mm/child/pom.xml new file mode 100644 index 000000000..b9c3410ba --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_mm/child/pom.xml @@ -0,0 +1,33 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.enforcer + test + 1.0 + + + child + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_mm/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_mm/pom.xml new file mode 100644 index 000000000..e2651ac73 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_mm/pom.xml @@ -0,0 +1,60 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + 1.0 + pom + + + child + + + This IT demonstrates having no repositories defined at all. + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_mm_ci/child/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_mm_ci/child/pom.xml new file mode 100644 index 000000000..40ed3e689 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_mm_ci/child/pom.xml @@ -0,0 +1,33 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.enforcer + test + ${revision} + + + child + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_mm_ci/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_mm_ci/invoker.properties new file mode 100644 index 000000000..1c82ab60c --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_mm_ci/invoker.properties @@ -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.maven.version = 3.5.0+ \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_mm_ci/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_mm_ci/pom.xml new file mode 100644 index 000000000..2ab44fa0c --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-no-repositories_mm_ci/pom.xml @@ -0,0 +1,63 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + ${revision} + pom + + + 1.0-SNAPSHOT + + + child + + + This IT demonstrates the use of properties for the versions. + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-ci/child/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-ci/child/pom.xml new file mode 100644 index 000000000..40ed3e689 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-ci/child/pom.xml @@ -0,0 +1,33 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.enforcer + test + ${revision} + + + child + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-ci/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-ci/invoker.properties new file mode 100644 index 000000000..adc16148f --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-ci/invoker.properties @@ -0,0 +1,19 @@ +# 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.maven.version = 3.5.0+ +invoker.buildResult=failure \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-ci/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-ci/pom.xml new file mode 100644 index 000000000..dd6501f8b --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-ci/pom.xml @@ -0,0 +1,63 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + ${revision} + pom + + + 1.0-SNAPSHOT + + + child + + + This IT demonstrates the use of properties for the versions for requirePluginVersions. + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-ci/verify.groovy b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-ci/verify.groovy new file mode 100644 index 000000000..d09891728 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-ci/verify.groovy @@ -0,0 +1,21 @@ +/* + * 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. + */ +File buildLog = new File( basedir, 'build.log' ) +assert buildLog.text.contains( '[WARNING] Rule 0: org.apache.maven.plugins.enforcer.RequirePluginVersions failed with message:' ) +assert buildLog.text.contains( 'Some plugins are missing valid versions: (LATEST RELEASE SNAPSHOT are not allowed)' ) diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-custom-packaging/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-custom-packaging/pom.xml new file mode 100644 index 000000000..9a82bfa1e --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-custom-packaging/pom.xml @@ -0,0 +1,72 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + 1.0 + maven-one-plugin + + + + + + + + org.apache.maven.plugins + maven-one-plugin + 1.2 + true + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + false + + org.apache.maven.plugins:maven-clean-plugin, + org.apache.maven.plugins:maven-install-plugin, + org.apache.maven.plugins:maven-deploy-plugin, + org.apache.maven.plugins:maven-site-plugin, + org.apache.maven.plugins:maven-resources-plugin, + org.apache.maven.plugins:maven-compiler-plugin, + org.apache.maven.plugins:maven-surefire-plugin + + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-expressions/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-expressions/invoker.properties new file mode 100644 index 000000000..aa66e8ff8 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-expressions/invoker.properties @@ -0,0 +1,25 @@ +# 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. + +# When running with M2.2.1 Maven already fails to download the pom, so it doesn't even reach the rule. Not sure why MRM can't serve this file, but does with M3 +# +#Caused by: java.io.FileNotFoundException: http://localhost:50910/org/apache/maven/enforcer/its/menforcer126_maven-plugin/1.0/menforcer126_maven-plugin-1.0.pom +# at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1434) +# at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:379) +# at org.apache.maven.wagon.providers.http.LightweightHttpWagon.fillInputData(LightweightHttpWagon.java:115) +# ... 33 more +invoker.maven.version=3.0+ \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-expressions/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-expressions/pom.xml new file mode 100644 index 000000000..33321a93e --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-expressions/pom.xml @@ -0,0 +1,155 @@ + + + + 4.0.0 + org.apache.maven.enforcer.its + requirePluginVersions_Expressions + 1.0-SNAPSHOT + + + org.apache.maven.enforcer.its + menforcer126_maven-plugin + 1.0 + + + + + + + org.apache.maven.plugins + maven-clean-plugin + 2.5 + + + org.apache.maven.plugins + maven-resources-plugin + 2.6 + + + org.apache.maven.plugins + maven-compiler-plugin + 2.5.1 + + + org.apache.maven.plugins + maven-surefire-plugin + 2.12.4 + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + org.apache.maven.plugins + maven-install-plugin + 2.4 + + + org.apache.maven.plugins + maven-deploy-plugin + 2.7 + + + org.apache.maven.plugins + maven-site-plugin + 3.2 + + + ${expressionplugin.groupId} + ${expressionplugin.artifactId} + ${expressionplugin.version} + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + false + + + + + + + + ${expressionplugin.groupId} + ${expressionplugin.artifactId} + ${expressionplugin.version} + + + + + + + + ${expressionplugin.groupId} + ${expressionplugin.artifactId} + ${expressionplugin.version} + + + + + + + menforcer126 + + + + + ${expressionplugin.groupId} + ${expressionplugin.artifactId} + ${expressionplugin.version} + + + + + + ${expressionplugin.groupId} + ${expressionplugin.artifactId} + ${expressionplugin.version} + + + + + + + ${expressionplugin.groupId} + ${expressionplugin.artifactId} + ${expressionplugin.version} + + + + + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-mm-ci-friendly/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-mm-ci-friendly/invoker.properties new file mode 100644 index 000000000..1b780931f --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-mm-ci-friendly/invoker.properties @@ -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.maven.version = 3.5.0+ +invoker.goals = install -Drevision=0.10.0-SNAPSHOT \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-mm-ci-friendly/menforcer281-module/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-mm-ci-friendly/menforcer281-module/pom.xml new file mode 100644 index 000000000..a6807af93 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-mm-ci-friendly/menforcer281-module/pom.xml @@ -0,0 +1,36 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + menforcer281-parent + ${revision} + + + menforcer281-module + pom + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-mm-ci-friendly/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-mm-ci-friendly/pom.xml new file mode 100644 index 000000000..e9d613b72 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-mm-ci-friendly/pom.xml @@ -0,0 +1,115 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + menforcer281-parent + ${revision} + pom + + + + + + 0.0.1-SNAPSHOT + + + + + + + org.apache.maven.plugins + maven-clean-plugin + 2.5 + + + org.apache.maven.plugins + maven-resources-plugin + 2.6 + + + org.apache.maven.plugins + maven-compiler-plugin + 2.5.1 + + + org.apache.maven.plugins + maven-surefire-plugin + 2.12.4 + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + org.apache.maven.plugins + maven-install-plugin + 2.4 + + + org.apache.maven.plugins + maven-deploy-plugin + 2.7 + + + org.apache.maven.plugins + maven-site-plugin + 3.2 + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + false + + + + + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + + + + menforcer281-module + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-plugin-with-extensions/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-plugin-with-extensions/pom.xml new file mode 100644 index 000000000..73faf7bfc --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-plugin-with-extensions/pom.xml @@ -0,0 +1,94 @@ + + + + 4.0.0 + org.apache.maven.its.enforcer + pluginWithExtensions + 1.0-SNAPSHOT + zip + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + false + + org.apache.maven.plugins:maven-clean-plugin,org.apache.maven.plugins:maven-install-plugin,org.apache.maven.plugins:maven-deploy-plugin,org.apache.maven.plugins:maven-site-plugin + + + + + + + + + + org.codehaus.mojo + pde-maven-plugin + 1.0-alpha-1 + true + + + example.product + + + + + + clean-pde + clean + + clean + + + + + + org.apache.maven.plugins + maven-resources-plugin + 2.5 + + + org.apache.maven.plugins + maven-compiler-plugin + 2.5.1 + + + org.apache.maven.plugins + maven-surefire-plugin + 2.12 + + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-plugin-with-integration-test-lifecycle/META-INF/MANIFEST.MF b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-plugin-with-integration-test-lifecycle/META-INF/MANIFEST.MF new file mode 100644 index 000000000..40fd337b7 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-plugin-with-integration-test-lifecycle/META-INF/MANIFEST.MF @@ -0,0 +1,2 @@ +Bundle-SymbolicName: pluginWithIntegrationTestLifecycle +Bundle-Version: 1.0.0.qualifier \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-plugin-with-integration-test-lifecycle/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-plugin-with-integration-test-lifecycle/invoker.properties new file mode 100644 index 000000000..ff7096b57 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-plugin-with-integration-test-lifecycle/invoker.properties @@ -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.maven.version=3.0+ \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-plugin-with-integration-test-lifecycle/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-plugin-with-integration-test-lifecycle/pom.xml new file mode 100644 index 000000000..efbefd77e --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-plugin-with-integration-test-lifecycle/pom.xml @@ -0,0 +1,95 @@ + + + + 4.0.0 + org.apache.maven.its.enforcer + pluginWithIntegrationTestLifecycle + 1.0.0-SNAPSHOT + eclipse-plugin + + 0.22.0 + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + false + + org.apache.maven.plugins:maven-clean-plugin,org.apache.maven.plugins:maven-install-plugin,org.apache.maven.plugins:maven-deploy-plugin,org.apache.maven.plugins:maven-site-plugin + + + + + + + + + + org.eclipse.tycho + tycho-maven-plugin + ${tycho-version} + true + + + org.eclipse.tycho + target-platform-configuration + ${tycho-version} + + + p2 + JavaSE-@maven.compiler.source@ + + + + org.eclipse.tycho + tycho-compiler-plugin + ${tycho-version} + + + org.eclipse.tycho + tycho-packaging-plugin + ${tycho-version} + + + org.eclipse.tycho + tycho-p2-plugin + ${tycho-version} + + + maven-resources-plugin + 2.4.3 + + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-projectGAVexpressions/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-projectGAVexpressions/pom.xml new file mode 100644 index 000000000..f2ed9c778 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions-projectGAVexpressions/pom.xml @@ -0,0 +1,101 @@ + + + + 4.0.0 + ${projectGAV.groupId} + ${projectGAV.artifactId} + ${projectGAV.version} + + + org.apache.maven.enforcer.its + menforcer92 + 1.0 + + + + + + + org.apache.maven.plugins + maven-clean-plugin + 2.5 + + + org.apache.maven.plugins + maven-resources-plugin + 2.6 + + + org.apache.maven.plugins + maven-compiler-plugin + 2.5.1 + + + org.apache.maven.plugins + maven-surefire-plugin + 2.12.4 + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + org.apache.maven.plugins + maven-install-plugin + 2.4 + + + org.apache.maven.plugins + maven-deploy-plugin + 2.7 + + + org.apache.maven.plugins + maven-site-plugin + 3.2 + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + false + + + + + + + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions/pom.xml new file mode 100644 index 000000000..7bd7043fc --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-plugin-versions/pom.xml @@ -0,0 +1,60 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + 1.0 + pom + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + false + + org.apache.maven.plugins:maven-clean-plugin,org.apache.maven.plugins:maven-install-plugin,org.apache.maven.plugins:maven-deploy-plugin,org.apache.maven.plugins:maven-site-plugin + + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-profile-id-exist_defined_in_parent/MENFORCER-322-module/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-profile-id-exist_defined_in_parent/MENFORCER-322-module/pom.xml new file mode 100644 index 000000000..a0540d5e3 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-profile-id-exist_defined_in_parent/MENFORCER-322-module/pom.xml @@ -0,0 +1,65 @@ + + + + + + + 4.0.0 + + + org.apache.maven.its.enforcer + test + 1.0 + .. + + + org.apache.maven.its.enforcer + menforcer-322-module + 1.0 + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + + + + + + + + + + b + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-profile-id-exist_defined_in_parent/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-profile-id-exist_defined_in_parent/invoker.properties new file mode 100644 index 000000000..8d46b164b --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-profile-id-exist_defined_in_parent/invoker.properties @@ -0,0 +1,27 @@ +# 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. + +# MENFORCER-322 + +# test building the top level project +invoker.goals.1 = clean compile +invoker.profiles.1 = a,b + +# test building the module +invoker.project.2 = MENFORCER-322-module +invoker.goals.2 = clean compile +invoker.profiles.2 = a,b diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-profile-id-exist_defined_in_parent/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-profile-id-exist_defined_in_parent/pom.xml new file mode 100644 index 000000000..21adc5c10 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-profile-id-exist_defined_in_parent/pom.xml @@ -0,0 +1,63 @@ + + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + 1.0 + pom + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + + + + + + + + + MENFORCER-322-module + + + + + a + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-profile-id-exist_defined_in_parent/verify.groovy b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-profile-id-exist_defined_in_parent/verify.groovy new file mode 100644 index 000000000..4e5823958 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-profile-id-exist_defined_in_parent/verify.groovy @@ -0,0 +1,22 @@ +/* + * 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' ) +assert !( buildLog.text.contains( "The requested profile doesn't exist: a" ) ) +assert !( buildLog.text.contains( "The requested profile doesn't exist: b" ) ) diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_failure/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_failure/invoker.properties new file mode 100644 index 000000000..bd8df3bcb --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_failure/invoker.properties @@ -0,0 +1,19 @@ +# 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 +invoker.profiles = c \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_failure/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_failure/pom.xml new file mode 100644 index 000000000..ccac8b9df --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_failure/pom.xml @@ -0,0 +1,60 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + 1.0 + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + + + + + + + + + + a + + + b + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_failure/verify.groovy b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_failure/verify.groovy new file mode 100644 index 000000000..1e476fcbc --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_failure/verify.groovy @@ -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' ) +assert buildLog.text.contains( "The requested profile doesn't exist: c" ) diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_success/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_success/invoker.properties new file mode 100644 index 000000000..559c24403 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_success/invoker.properties @@ -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.profiles = a \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_success/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_success/pom.xml new file mode 100644 index 000000000..ccac8b9df --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_success/pom.xml @@ -0,0 +1,60 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + 1.0 + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + + + + + + + + + + a + + + b + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-property/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-property/pom.xml new file mode 100644 index 000000000..da9f99797 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-property/pom.xml @@ -0,0 +1,56 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + 1.0 + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + basedir + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-release-dependencies-excludes/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-release-dependencies-excludes/pom.xml new file mode 100644 index 000000000..a20df3b5f --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-release-dependencies-excludes/pom.xml @@ -0,0 +1,63 @@ + + + + 4.0.0 + org.apache.maven.enforcer.its + requireReleaseDeps + jar + 1.0-SNAPSHOT + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + enforce + + enforce + + + + + No Snapshots Allowed! + + org.apache.maven.plugins.enforcer.its:menforcer85_api + + + + + + + + + + + + + org.apache.maven.plugins.enforcer.its + menforcer85_api + 1.0-SNAPSHOT + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-release-dependencies-excludes_failure/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-release-dependencies-excludes_failure/invoker.properties new file mode 100644 index 000000000..c98ac4c5b --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-release-dependencies-excludes_failure/invoker.properties @@ -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 \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-release-dependencies-excludes_failure/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-release-dependencies-excludes_failure/pom.xml new file mode 100644 index 000000000..cc0de84b8 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-release-dependencies-excludes_failure/pom.xml @@ -0,0 +1,63 @@ + + + + 4.0.0 + org.apache.maven.enforcer.its + requireReleaseDeps + jar + 1.0-SNAPSHOT + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + enforce + + enforce + + + + + No Snapshots Allowed! + + org.apache.maven.plugins.enforcer.its:menforcer85_api:[2.0,) + + + + + + + + + + + + + org.apache.maven.plugins.enforcer.its + menforcer85_api + 1.0-SNAPSHOT + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-release-dependencies/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-release-dependencies/pom.xml new file mode 100644 index 000000000..6693dc62a --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-release-dependencies/pom.xml @@ -0,0 +1,54 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + 1.0 + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-release-version/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-release-version/pom.xml new file mode 100644 index 000000000..2b5d58269 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-release-version/pom.xml @@ -0,0 +1,54 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + test + 1.0 + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-same-versions_failure/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-same-versions_failure/invoker.properties new file mode 100644 index 000000000..c98ac4c5b --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-same-versions_failure/invoker.properties @@ -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 \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-same-versions_failure/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-same-versions_failure/pom.xml new file mode 100644 index 000000000..b920167fc --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-same-versions_failure/pom.xml @@ -0,0 +1,87 @@ + + + + 4.0.0 + org.apache.maven.enforcer.its + requireSameVersion + 1.0-SNAPSHOT + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + enforce + + enforce + + + + + + org.apache.maven.plugins:maven-surefire-plugin + org.apache.maven.plugins:maven-failsafe-plugin + + + org.apache.maven.plugins:maven-surefire-report-plugin + + + + + + org.apache.maven.plugins:maven-surefire-plugin + org.apache.maven.plugins:maven-failsafe-plugin + org.apache.maven.plugins:maven-surefire-report-plugin + + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.14 + + + org.apache.maven.plugins + maven-failsafe-plugin + 2.15 + + + + + + + + org.apache.maven.plugins + maven-surefire-report-plugin + 2.13 + + + + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-same-versions_success/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-same-versions_success/pom.xml new file mode 100644 index 000000000..7e6139657 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-same-versions_success/pom.xml @@ -0,0 +1,88 @@ + + + + 4.0.0 + org.apache.maven.enforcer.its + requireSameVersion + jar + 1.0-SNAPSHOT + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + enforce + + enforce + + + + + + org.apache.maven.plugins:maven-surefire-plugin + org.apache.maven.plugins:maven-failsafe-plugin + + + org.apache.maven.plugins:maven-surefire-report-plugin + + + + + + org.apache.maven.plugins:maven-surefire-plugin + org.apache.maven.plugins:maven-failsafe-plugin + org.apache.maven.plugins:maven-surefire-report-plugin + + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.14 + + + org.apache.maven.plugins + maven-failsafe-plugin + 2.14 + + + + + + + + org.apache.maven.plugins + maven-surefire-report-plugin + 2.14 + + + + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-snapshot-version_failure/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-snapshot-version_failure/invoker.properties new file mode 100644 index 000000000..c98ac4c5b --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-snapshot-version_failure/invoker.properties @@ -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 \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-snapshot-version_failure/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-snapshot-version_failure/pom.xml new file mode 100644 index 000000000..f2e2e1f47 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-snapshot-version_failure/pom.xml @@ -0,0 +1,53 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + menforcer-204 + 1.0 + + https://issues.apache.org/jira/browse/MENFORCER-204 + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-snapshot-version_failure_parent-ci-friendly/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-snapshot-version_failure_parent-ci-friendly/invoker.properties new file mode 100644 index 000000000..4d907992f --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-snapshot-version_failure_parent-ci-friendly/invoker.properties @@ -0,0 +1,19 @@ +# 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.maven.version = 3.5.0+ +invoker.buildResult = failure diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-snapshot-version_failure_parent-ci-friendly/module/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-snapshot-version_failure_parent-ci-friendly/module/pom.xml new file mode 100644 index 000000000..466827e0f --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-snapshot-version_failure_parent-ci-friendly/module/pom.xml @@ -0,0 +1,33 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.enforcer + menforcer-346-parent + ${revision} + + + menforcer-346-module + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-snapshot-version_failure_parent-ci-friendly/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-snapshot-version_failure_parent-ci-friendly/pom.xml new file mode 100644 index 000000000..2c011276a --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-snapshot-version_failure_parent-ci-friendly/pom.xml @@ -0,0 +1,63 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + menforcer-346-parent + ${revision} + pom + + https://issues.apache.org/jira/browse/MENFORCER-346 + + + 1.0 + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + + + + + + + + + module + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-snapshot-version_failure_parent-ci-friendly/verify.groovy b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-snapshot-version_failure_parent-ci-friendly/verify.groovy new file mode 100644 index 000000000..039aef3e1 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-snapshot-version_failure_parent-ci-friendly/verify.groovy @@ -0,0 +1,21 @@ +/* + * 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. + */ +File buildLog = new File( basedir, 'build.log' ) +assert buildLog.text.contains( 'This project cannot be a release:org.apache.maven.its.enforcer:menforcer-346-parent:pom:1.0' ) + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-snapshot-version_success/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-snapshot-version_success/pom.xml new file mode 100644 index 000000000..0c32f53f8 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-snapshot-version_success/pom.xml @@ -0,0 +1,53 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + menforcer-204 + 1.0-SNAPSHOT + + https://issues.apache.org/jira/browse/MENFORCER-204 + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-snapshot-version_success_parent-ci-friendly/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-snapshot-version_success_parent-ci-friendly/invoker.properties new file mode 100644 index 000000000..425ce068b --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-snapshot-version_success_parent-ci-friendly/invoker.properties @@ -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.maven.version = 3.5.0+ diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-snapshot-version_success_parent-ci-friendly/module/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-snapshot-version_success_parent-ci-friendly/module/pom.xml new file mode 100644 index 000000000..466827e0f --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-snapshot-version_success_parent-ci-friendly/module/pom.xml @@ -0,0 +1,33 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.enforcer + menforcer-346-parent + ${revision} + + + menforcer-346-module + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-snapshot-version_success_parent-ci-friendly/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-snapshot-version_success_parent-ci-friendly/pom.xml new file mode 100644 index 000000000..f9b1bd6c2 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-snapshot-version_success_parent-ci-friendly/pom.xml @@ -0,0 +1,63 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + menforcer-346-parent + ${revision} + pom + + https://issues.apache.org/jira/browse/MENFORCER-346 + + + 1.0-SNAPSHOT + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + + + + + + + + + module + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_failure/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_failure/invoker.properties new file mode 100644 index 000000000..c98ac4c5b --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_failure/invoker.properties @@ -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 \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_failure/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_failure/pom.xml new file mode 100644 index 000000000..4ac3887fa --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_failure/pom.xml @@ -0,0 +1,67 @@ + + + + 4.0.0 + org.apache.maven.enforcer.its + menforcer146-a + 1.0-SNAPSHOT + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + enforce + + enforce + + + + + + + + + + + + + + + + org.apache.maven.plugins.enforcer.its + menforcer146-x + 1.1 + + + + + + + org.apache.maven.plugins.enforcer.its + menforcer146-b + 1.0 + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_failure/verify.groovy b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_failure/verify.groovy new file mode 100644 index 000000000..35b2b6646 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_failure/verify.groovy @@ -0,0 +1,29 @@ +/* + * 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 LS = System.getProperty( "line.separator" ) +File buildLog = new File( basedir, 'build.log' ) +assert buildLog.text.contains( 'Rule 0: org.apache.maven.plugins.enforcer.RequireUpperBoundDeps failed with message:' ) + +def message = 'Failed while enforcing RequireUpperBoundDeps. The error(s) are [' + LS+ +'Require upper bound dependencies error for org.apache.maven.plugins.enforcer.its:menforcer146-x:1.1 paths to dependency are:' + LS+ +'+-org.apache.maven.enforcer.its:menforcer146-a:1.0-SNAPSHOT' + LS+ +' +-org.apache.maven.plugins.enforcer.its:menforcer146-b:1.0' + LS+ +' +-org.apache.maven.plugins.enforcer.its:menforcer146-x:1.1 (managed) <-- org.apache.maven.plugins.enforcer.its:menforcer146-x:2.1' + LS+ +']' + LS +assert buildLog.text.contains( message ) \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_success/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_success/pom.xml new file mode 100644 index 000000000..7dd758aba --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-managed_success/pom.xml @@ -0,0 +1,67 @@ + + + + 4.0.0 + org.apache.maven.enforcer.its + menforcer146-a + 1.0-SNAPSHOT + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + enforce + + enforce + + + + + + + + + + + + + + + + org.apache.maven.plugins.enforcer.its + menforcer146-x + 3.1 + + + + + + + org.apache.maven.plugins.enforcer.its + menforcer146-b + 1.0 + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-unique_failure/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-unique_failure/invoker.properties new file mode 100644 index 000000000..c98ac4c5b --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-unique_failure/invoker.properties @@ -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 \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-unique_failure/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-unique_failure/pom.xml new file mode 100644 index 000000000..c2c43666b --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-unique_failure/pom.xml @@ -0,0 +1,60 @@ + + + + 4.0.0 + org.apache.maven.enforcer.its + requireUpperBoundDependenciesUnique + jar + 1.0-SNAPSHOT + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + enforce + + enforce + + + + + true + + + + + + + + + + + + org.apache.maven.plugins.enforcer.its + menforcer134_project + 1.0-SNAPSHOT + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-unique_failure/verify.groovy b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-unique_failure/verify.groovy new file mode 100644 index 000000000..d65ff008f --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-unique_failure/verify.groovy @@ -0,0 +1,21 @@ +/* + * 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. + */ +File buildLog = new File( basedir, 'build.log' ) +assert buildLog.text.contains( 'Rule 0: org.apache.maven.plugins.enforcer.RequireUpperBoundDeps failed with message:' ) +assert buildLog.text.contains( 'Require upper bound dependencies error for org.apache.maven.plugins.enforcer.its:menforcer134_model:1.0-20130423.042904-7222 paths to dependency are:' ) diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-unique_success/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-unique_success/pom.xml new file mode 100644 index 000000000..17e9e2ad0 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-dependencies-unique_success/pom.xml @@ -0,0 +1,58 @@ + + + + 4.0.0 + org.apache.maven.enforcer.its + requireUpperBoundDependenciesUnique + jar + 1.0-SNAPSHOT + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + enforce + + enforce + + + + + + + + + + + + + + + org.apache.maven.plugins.enforcer.its + menforcer134_project + 1.0-SNAPSHOT + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_failure/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_failure/invoker.properties new file mode 100644 index 000000000..c98ac4c5b --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_failure/invoker.properties @@ -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 \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_failure/module/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_failure/module/pom.xml new file mode 100644 index 000000000..6d2c1bb52 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_failure/module/pom.xml @@ -0,0 +1,30 @@ + + + + 4.0.0 + + test + TestParent + 1.0-SNAPSHOT + + TestModule + 1.1-SNAPSHOT + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_failure/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_failure/pom.xml new file mode 100644 index 000000000..49701f543 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_failure/pom.xml @@ -0,0 +1,62 @@ + + + + 4.0.0 + org.apache.maven.plugins.enforcer.its + menforcer128 + 1.0-SNAPSHOT + jar + + + org.apache.maven.plugins.enforcer.its + menforcer128_api + 1.4.0 + + + org.apache.maven.plugins.enforcer.its + menforcer128_classic + 0.9.9 + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + enforce + + + + + + + enforce + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_failure/verify.groovy b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_failure/verify.groovy new file mode 100644 index 000000000..38bb648c1 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_failure/verify.groovy @@ -0,0 +1,32 @@ +/* + * 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 LS = System.getProperty( "line.separator" ) +File buildLog = new File( basedir, 'build.log' ) + +assert buildLog.text.contains( 'Rule 0: org.apache.maven.plugins.enforcer.RequireUpperBoundDeps failed with message:' ) +def message = +'Require upper bound dependencies error for org.apache.maven.plugins.enforcer.its:menforcer128_api:1.4.0 paths to dependency are:'+LS+ +'+-org.apache.maven.plugins.enforcer.its:menforcer128:1.0-SNAPSHOT'+LS+ +' +-org.apache.maven.plugins.enforcer.its:menforcer128_api:1.4.0'+LS+ +'and'+LS+ +'+-org.apache.maven.plugins.enforcer.its:menforcer128:1.0-SNAPSHOT'+LS+ +' +-org.apache.maven.plugins.enforcer.its:menforcer128_classic:0.9.9'+LS+ +' +-org.apache.maven.plugins.enforcer.its:menforcer128_api:1.5.0'+LS +assert buildLog.text.contains( message ) + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_ignored/module/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_ignored/module/pom.xml new file mode 100644 index 000000000..6d2c1bb52 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_ignored/module/pom.xml @@ -0,0 +1,30 @@ + + + + 4.0.0 + + test + TestParent + 1.0-SNAPSHOT + + TestModule + 1.1-SNAPSHOT + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_ignored/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_ignored/pom.xml new file mode 100644 index 000000000..746e074f5 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_ignored/pom.xml @@ -0,0 +1,66 @@ + + + + 4.0.0 + org.apache.maven.plugins.enforcer.its + menforcer128 + 1.0-SNAPSHOT + jar + + + org.apache.maven.plugins.enforcer.its + menforcer128_api + 1.4.0 + + + org.apache.maven.plugins.enforcer.its + menforcer128_classic + 0.9.9 + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + enforce + + + + + org.apache.maven.plugins.enforcer.its:menforcer128_api + + + + + + enforce + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_ignored/verify.groovy b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_ignored/verify.groovy new file mode 100644 index 000000000..a85ae64ee --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_ignored/verify.groovy @@ -0,0 +1,22 @@ +/* + * 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 LS = System.getProperty( "line.separator" ) +File buildLog = new File( basedir, 'build.log' ) + +assert buildLog.text.contains( 'Ignoring requireUpperBoundDeps in org.apache.maven.plugins.enforcer.its:menforcer128_api' ) diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_success/module/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_success/module/pom.xml new file mode 100644 index 000000000..6d2c1bb52 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_success/module/pom.xml @@ -0,0 +1,30 @@ + + + + 4.0.0 + + test + TestParent + 1.0-SNAPSHOT + + TestModule + 1.1-SNAPSHOT + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_success/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_success/pom.xml new file mode 100644 index 000000000..107c55495 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-deps_success/pom.xml @@ -0,0 +1,62 @@ + + + + 4.0.0 + org.apache.maven.plugins.enforcer.its + menforcer128 + 1.0-SNAPSHOT + jar + + + org.apache.maven.plugins.enforcer.its + menforcer128_api + 1.6.0 + + + org.apache.maven.plugins.enforcer.its + menforcer128_classic + 0.9.9 + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + enforce + + + + + + + enforce + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-exclude_wildcard/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-exclude_wildcard/invoker.properties new file mode 100644 index 000000000..c4dc6a185 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-exclude_wildcard/invoker.properties @@ -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.maven.version = 3.6.2+ diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-exclude_wildcard/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-exclude_wildcard/pom.xml new file mode 100644 index 000000000..be90caace --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/require-upper-bound-exclude_wildcard/pom.xml @@ -0,0 +1,72 @@ + + + + 4.0.0 + test + TestParent + 1.0 + jar + + + org.apache.maven.plugins.enforcer.its + menforcer269_project-middle + 1.0.0 + + + org.apache.maven.plugins.enforcer.its + menforcer269_project-lower + 1.0.0 + + + org.apache.maven.plugins.enforcer.its + menforcer269_project-higher + 1.0.0 + + + * + * + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + enforce + + + + + + + enforce + + + + + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/resolve_collect_dependencies/invoker.properties b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/resolve_collect_dependencies/invoker.properties new file mode 100644 index 000000000..cb255e280 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/resolve_collect_dependencies/invoker.properties @@ -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 = clean package \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/resolve_collect_dependencies/pom.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/resolve_collect_dependencies/pom.xml new file mode 100644 index 000000000..fe985df97 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/resolve_collect_dependencies/pom.xml @@ -0,0 +1,72 @@ + + + + + + 4.0.0 + + org.apache.maven.its.enforcer + resolve_collect_dependencies + 1.0 + pom + + + + + org.apache.maven.plugins + maven-enforcer-plugin + @project.version@ + + + test + + enforce + + + + + + false + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 3.0.0 + + + assemble + package + + single + + + + src/assembly/extjars.xml + + + + + + + + + + + org.apache.maven.plugins.enforcer.its + menforcer158_utils + 1.0 + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/resolve_collect_dependencies/src/assembly/extjars.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/resolve_collect_dependencies/src/assembly/extjars.xml new file mode 100644 index 000000000..a3b543370 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/resolve_collect_dependencies/src/assembly/extjars.xml @@ -0,0 +1,31 @@ + + + + extjars + + zip + + false + + + + + 0644 + 0755 + false + false + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/resolve_collect_dependencies/verify.groovy b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/resolve_collect_dependencies/verify.groovy new file mode 100644 index 000000000..48fc91a79 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/it/projects/resolve_collect_dependencies/verify.groovy @@ -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. + */ +assert new File( basedir, 'target/resolve_collect_dependencies-1.0-extjars.zip' ).isFile() + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/DisplayInfoMojo.java b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/DisplayInfoMojo.java new file mode 100644 index 000000000..91fe79514 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/DisplayInfoMojo.java @@ -0,0 +1,89 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecution; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.PlexusConstants; +import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.context.Context; +import org.codehaus.plexus.context.ContextException; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; + +/** + * This goal displays the current platform information. + * + * @author Brian Fox + */ +@Mojo( name = "display-info", threadSafe = true ) +public class DisplayInfoMojo + extends AbstractMojo + implements Contextualizable +{ + + /** + * MojoExecution needed by the ExpressionEvaluator + */ + @Parameter( defaultValue = "${mojoExecution}", readonly = true, required = true ) + protected MojoExecution mojoExecution; + + /** + * The MavenSession + */ + @Parameter( defaultValue = "${session}", readonly = true, required = true ) + protected MavenSession session; + + /** + * POM + */ + @Parameter( defaultValue = "${project}", readonly = true, required = true ) + protected MavenProject project; + + // set by the contextualize method. Only way to get the + // plugin's container in 2.0.x + protected PlexusContainer container; + + public void contextualize( Context context ) + throws ContextException + { + container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); + } + + /** + * Entry point to the mojo + */ + public void execute() + throws MojoExecutionException + { + String mavenVersion = session.getSystemProperties().getProperty( "maven.version" ); + String javaVersion = System.getProperty( "java.version" ); + getLog().info( "Maven Version: " + mavenVersion ); + getLog().info( "JDK Version: " + javaVersion + " normalized as: " + + RequireJavaVersion.normalizeJDKVersion( javaVersion ) ); + RequireOS os = new RequireOS(); + os.displayOSInfo( getLog(), true ); + } + +} diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/EnforceMojo.java b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/EnforceMojo.java new file mode 100644 index 000000000..77fad8df1 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/EnforceMojo.java @@ -0,0 +1,435 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; + +import org.apache.maven.enforcer.rule.api.EnforcerLevel; +import org.apache.maven.enforcer.rule.api.EnforcerRule; +import org.apache.maven.enforcer.rule.api.EnforcerRule2; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecution; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.annotations.ResolutionScope; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.PlexusConstants; +import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.context.Context; +import org.codehaus.plexus.context.ContextException; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; + +/** + * This goal executes the defined enforcer-rules once per module. + * + * @author Brian Fox + */ +// CHECKSTYLE_OFF: LineLength +@Mojo( name = "enforce", defaultPhase = LifecyclePhase.VALIDATE, requiresDependencyCollection = ResolutionScope.TEST, threadSafe = true ) +//CHECKSTYLE_ON: LineLength +public class EnforceMojo + extends AbstractMojo + implements Contextualizable +{ + /** + * This is a static variable used to persist the cached results across plugin invocations. + */ + protected static Hashtable cache = new Hashtable<>(); + + /** + * MojoExecution needed by the ExpressionEvaluator + */ + @Parameter( defaultValue = "${mojoExecution}", readonly = true, required = true ) + protected MojoExecution mojoExecution; + + /** + * The MavenSession + */ + @Parameter( defaultValue = "${session}", readonly = true, required = true ) + protected MavenSession session; + + /** + * POM + */ + @Parameter( defaultValue = "${project}", readonly = true, required = true ) + protected MavenProject project; + + /** + * Flag to easily skip all checks + */ + @Parameter( property = "enforcer.skip", defaultValue = "false" ) + protected boolean skip = false; + + /** + * Flag to fail the build if a version check fails. + */ + @Parameter( property = "enforcer.fail", defaultValue = "true" ) + private boolean fail = true; + + /** + * Fail on the first rule that doesn't pass + */ + @Parameter( property = "enforcer.failFast", defaultValue = "false" ) + private boolean failFast = false; + + /** + * Array of objects that implement the EnforcerRule interface to execute. + */ + @Parameter( required = false ) + private EnforcerRule[] rules; + + /** + * Array of Strings that matches the EnforcerRules to execute. + */ + @Parameter( required = false, property = "rules" ) + private String[] commandLineRules; + + /** + * Use this flag to disable rule result caching. This will cause all rules to execute on each project even if the + * rule indicates it can safely be cached. + */ + @Parameter( property = "enforcer.ignoreCache", defaultValue = "false" ) + protected boolean ignoreCache = false; + + // set by the contextualize method. Only way to get the + // plugin's container in 2.0.x + protected PlexusContainer container; + + @Override + public void contextualize( Context context ) + throws ContextException + { + container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); + } + + private boolean havingRules() + { + return rules != null && rules.length > 0; + } + + /** + * Entry point to the mojo + * + * @throws MojoExecutionException + */ + @Override + public void execute() + throws MojoExecutionException + { + Log log = this.getLog(); + + EnforcerExpressionEvaluator evaluator = + new EnforcerExpressionEvaluator( session, mojoExecution ); + if ( commandLineRules != null && commandLineRules.length > 0 ) + { + this.rules = createRulesFromCommandLineOptions(); + } + + if ( isSkip() ) + { + log.info( "Skipping Rule Enforcement." ); + return; + } + + if ( !havingRules() ) + { + // CHECKSTYLE_OFF: LineLength + throw new MojoExecutionException( "No rules are configured. Use the skip flag if you want to disable execution." ); + // CHECKSTYLE_ON: LineLength + } + + // list to store exceptions + List list = new ArrayList<>(); + + String currentRule = "Unknown"; + + // create my helper + EnforcerRuleHelper helper = new DefaultEnforcementRuleHelper( session, evaluator, log, container ); + + // if we are only warning, then disable + // failFast + if ( !fail ) + { + failFast = false; + } + + boolean hasErrors = false; + + // go through each rule + for ( int i = 0; i < rules.length; i++ ) + { + + // prevent against empty rules + EnforcerRule rule = rules[i]; + final EnforcerLevel level = getLevel( rule ); + if ( rule != null ) + { + // store the current rule for + // logging purposes + currentRule = rule.getClass().getName(); + log.debug( "Executing rule: " + currentRule ); + try + { + if ( ignoreCache || shouldExecute( rule ) ) + { + // execute the rule + // noinspection + // SynchronizationOnLocalVariableOrMethodParameter + synchronized ( rule ) + { + rule.execute( helper ); + } + } + } + catch ( EnforcerRuleException e ) + { + // i can throw an exception + // because failfast will be + // false if fail is false. + if ( failFast && level == EnforcerLevel.ERROR ) + { + throw new MojoExecutionException( currentRule + " failed with message:" + + System.lineSeparator() + e.getMessage(), e ); + } + else + { + // log a warning in case the exception message is missing + // so that the user can figure out what is going on + final String exceptionMessage = e.getMessage(); + if ( exceptionMessage != null ) + { + log.debug( "Adding " + level + " message due to exception", e ); + } + else + { + log.warn( "Rule " + i + ": " + currentRule + " failed without a message", e ); + } + // add the 'failed/warned' message including exceptionMessage + // which might be null in rare cases + if ( level == EnforcerLevel.ERROR ) + { + hasErrors = true; + list.add( "Rule " + i + ": " + currentRule + " failed with message:" + + System.lineSeparator() + exceptionMessage ); + } + else + { + list.add( "Rule " + i + ": " + currentRule + " warned with message:" + + System.lineSeparator() + exceptionMessage ); + } + } + } + } + } + + // if we found anything + // CHECKSTYLE_OFF: LineLength + if ( !list.isEmpty() ) + { + for ( String failure : list ) + { + log.warn( failure ); + } + if ( fail && hasErrors ) + { + throw new MojoExecutionException( "Some Enforcer rules have failed. Look above for specific messages explaining why the rule failed." ); + } + } + // CHECKSTYLE_ON: LineLength + } + + private EnforcerRule[] createRulesFromCommandLineOptions() throws MojoExecutionException + { + EnforcerRule[] rules = new EnforcerRule[commandLineRules.length]; + for ( int i = 0; i < commandLineRules.length; i++ ) + { + String rule = commandLineRules[i]; + if ( !rule.contains( "." ) ) + { + rule = getClass().getPackage().getName() + + "." + Character.toUpperCase( rule.charAt( 0 ) ) + rule.substring( 1 ); + } + + try + { + rules[i] = ( EnforcerRule ) Class.forName( rule ).newInstance(); + } + catch ( Exception e ) + { + throw new MojoExecutionException( "Failed to create enforcer rules from command line argument", e ); + } + } + return rules; + } + + /** + * This method determines if a rule should execute based on the cache + * + * @param rule the rule to verify + * @return {@code true} if rule should be executed, otherwise {@code false} + */ + protected boolean shouldExecute( EnforcerRule rule ) + { + if ( rule.isCacheable() ) + { + Log log = this.getLog(); + log.debug( "Rule " + rule.getClass().getName() + " is cacheable." ); + String key = rule.getClass().getName() + " " + rule.getCacheId(); + if ( EnforceMojo.cache.containsKey( key ) ) + { + log.debug( "Key " + key + " was found in the cache" ); + if ( rule.isResultValid( cache.get( key ) ) ) + { + log.debug( "The cached results are still valid. Skipping the rule: " + rule.getClass().getName() ); + return false; + } + } + + // add it to the cache of executed rules + EnforceMojo.cache.put( key, rule ); + } + return true; + } + + /** + * @return the fail + */ + public boolean isFail() + { + return this.fail; + } + + /** + * @param theFail the fail to set + */ + public void setFail( boolean theFail ) + { + this.fail = theFail; + } + + /** + * @return the rules + */ + public EnforcerRule[] getRules() + { + return this.rules; + } + + /** + * @param theRules the rules to set + */ + public void setRules( EnforcerRule[] theRules ) + { + this.rules = theRules; + } + + /** + * @param theFailFast the failFast to set + */ + public void setFailFast( boolean theFailFast ) + { + this.failFast = theFailFast; + } + + public boolean isFailFast() + { + return failFast; + } + + protected String createRuleMessage( int i, String currentRule, EnforcerRuleException e ) + { + return "Rule " + i + ": " + currentRule + " failed with message:" + System.lineSeparator() + e.getMessage(); + } + + /** + * Returns the level of the rule, defaults to {@link EnforcerLevel#ERROR} for backwards compatibility. + * + * @param rule might be of type {@link EnforcerRule2}. + * @return level of the rule. + */ + private EnforcerLevel getLevel( EnforcerRule rule ) + { + if ( rule instanceof EnforcerRule2 ) + { + return ( (EnforcerRule2) rule ).getLevel(); + } + else + { + return EnforcerLevel.ERROR; + } + } + + /** + * @return the skip + */ + public boolean isSkip() + { + return this.skip; + } + + /** + * @param theSkip the skip to set + */ + public void setSkip( boolean theSkip ) + { + this.skip = theSkip; + } + + /** + * @return the project + */ + public MavenProject getProject() + { + return this.project; + } + + /** + * @param theProject the project to set + */ + public void setProject( MavenProject theProject ) + { + this.project = theProject; + } + + /** + * @return the session + */ + public MavenSession getSession() + { + return this.session; + } + + /** + * @param theSession the session to set + */ + public void setSession( MavenSession theSession ) + { + this.session = theSession; + } + +} diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/util/EnforcerUtils.java b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/util/EnforcerUtils.java new file mode 100644 index 000000000..13974158d --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/util/EnforcerUtils.java @@ -0,0 +1,29 @@ +package org.apache.maven.plugins.enforcer.util; + +/* + * 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. + */ + +/** + * @author Brian Fox + * + */ +public class EnforcerUtils +{ + +} diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml new file mode 100644 index 000000000..eedcd9c5f --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml @@ -0,0 +1,35 @@ + + + + + + + + + + enforce + + + + + + + + \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/site/apt/examples/check-specific-rule-via-cli.apt.vm b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/site/apt/examples/check-specific-rule-via-cli.apt.vm new file mode 100644 index 000000000..4c7389c21 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/site/apt/examples/check-specific-rule-via-cli.apt.vm @@ -0,0 +1,34 @@ + ~~ 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. + + ----- + Check specific rule via CLI + ----- + Sandra Parsick + ------ + 2018-06-19 + ------ + +Check specific rule via CLI + + The <<>> goal can be used via cli to check specific enforcer rule that isn't defined in the POM. + ++---+ +mvn enforcer:enforce -Drules=alwaysPass,alwaysFail ++---+ + + A full list of built-in rules can be found {{{../../../enforcer/enforcer-rules/index.html}here}}. \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/site/apt/index.apt b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/site/apt/index.apt new file mode 100644 index 000000000..1c5cf97dd --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/site/apt/index.apt @@ -0,0 +1,54 @@ +~~ 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. + + ------ + Introduction + ------ + Brian Fox + ------ + Mar 2007 + ------ + +Maven Enforcer Plugin - The Loving Iron Fist of Maven\x99 + + The Enforcer plugin provides goals to control certain environmental constraints such as Maven version, JDK version and OS family + along with many more built-in rules and user created rules. + +* Goals Overview + + The Enforcer plugin has two goals: + + *{{{./enforce-mojo.html}enforcer:enforce}} executes rules for each project in a multi-project build. + + *{{{./display-info-mojo.html}enforcer:display-info}} display the current information as detected by the built-in rules. + +* Usage + + General instructions on how to use the Enforcer Plugin can be found on the {{{./usage.html}usage page}}. + + In case you still have questions regarding the plugin's usage, please have a look at the {{{./faq.html}FAQ}} and feel + free to contact the {{{./mailing-lists.html}user mailing list}}. The posts to the mailing list are archived and could + already contain the answer to your question as part of an older thread. Hence, it is also worth browsing/searching + the {{{./mailing-lists.html}mail archive}}. + + If you feel like the plugin is missing a feature or has a defect, you can fill a feature request or bug report in our + {{{./issue-management.html}issue tracker}}. When creating a new issue, please provide a comprehensive description of your + concern. Especially for fixing bugs it is crucial that the developers can reproduce your problem. For this reason, + entire debug logs, POMs or most preferably little demo projects attached to the issue are very much appreciated. + Of course, patches are welcome, too. Contributors can check out the project from our + {{{./scm.html}source repository}} and will find supplementary information in the + {{{/guides/development/guide-helping.html}guide to helping with Maven}}. diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/site/apt/thirdparty-rules.apt b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/site/apt/thirdparty-rules.apt new file mode 100644 index 000000000..515925b94 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/site/apt/thirdparty-rules.apt @@ -0,0 +1,28 @@ +~~ 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. + + ------ + Thirdparty Rules + ------ + Jason Dillon + ------ + 2018-08-27 + ------ + +Thirdparty Rules + + * {{{https://sonatype.github.io/ossindex-maven/enforcer-rules/}Sonatype OSS Index - Ban Vulnerable Dependencies}} diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/site/apt/usage.apt.vm b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/site/apt/usage.apt.vm new file mode 100644 index 000000000..f4a37902e --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/site/apt/usage.apt.vm @@ -0,0 +1,121 @@ +~~ 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. + + ------ + Usage + ------ + Brian Fox + ------ + Mar 2007 + ------ + +Usage + + Brief examples on how to use the enforcer goals. + +* Generic Plugin configuration information + + See the following links for information about including and configuring plugins in your project: + + *{{{/guides/mini/guide-configuring-plugins.html}Configuring Plugins}} + + *{{{/guides/plugin/guide-java-plugin-development.html}Plugin Development}} + + *{{{/guides/introduction/introduction-to-plugin-prefix-mapping.html}Plugin Prefix}} + + [] + +* The <<>> mojo + + This goal is meant to be bound to a lifecycle phase and configured in your + <<>>. The enforcers execute the configured rules to check for certain constraints. + The available built-in rules are described {{{../enforcer-rules/index.html}here}}. Besides the rules to execute, these goals support three options: + + * {{{./enforce-mojo.html#skip}skip}} - a quick way to skip checks via a profile or using <<<-Denforcer.skip>>> from the command line. + + * {{{./enforce-mojo.html#fail}fail}} - if the goal should fail the build when a rule fails. The default is <<>>. If false, the errors will be logged as warnings. + + * {{{./enforce-mojo.html#failFast}failFast}} - if the goal should stop checking after the first failure. The default is <<>>. + + [] + + Each rule to be executed should be added to the rules element along with the specific configuration for that rule. + + As of version 1.4, you may add a <<>> element to the rules. Valid values are <<>> and <<>>. When + <<>> <<>> is specified, the rule will only spit out a warning but will not fail the build. + + + Sample Plugin Configuration: + ++---+ + + [...] + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${project.version} + + + enforce-versions + + enforce + + + + + + WARN + + org.apache.maven.plugins:maven-verifier-plugin + + Please consider using the maven-invoker-plugin (http://maven.apache.org/plugins/maven-invoker-plugin/)! + + + 2.0.6 + + + 1.5 + + + unix + + + + + + + + + [...] + ++---+ + +* The <<>> mojo + + This goal is used to determine the current information as detected by the standard rules: + ++---+ + mvn enforcer:display-info + ... + [enforcer:display-info] + Maven Version: 2.0.6 + JDK Version: 1.5.0_11 normalized as: 1.5.0-11 + OS Info: Arch: x86 Family: windows Name: windows xp Version: 5.1 ++---+ + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/site/fml/faq.fml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/site/fml/faq.fml new file mode 100644 index 000000000..90482ee19 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/site/fml/faq.fml @@ -0,0 +1,39 @@ + + + + + + + + Why can't I just use the prerequisites tag in the pom? + +

+ The prerequisites tag was designed to be used by tools like plugins. It will work for regular projects, but it isn't + inherited to their children. If it is set in a parent reactor, then Maven will do the check. However if one of the + children are built, the check is not performed. The enforcer plugin is designed to allow centralized control over the build environment from + a single "super-pom", and to allow greater flexibility in version specification by supporting ranges. +

+
+
+
+
diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/site/site.xml b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/site/site.xml new file mode 100644 index 000000000..06e160ecd --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/site/site.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/MockEnforcerRule.java b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/MockEnforcerRule.java new file mode 100644 index 000000000..68ec878c3 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/MockEnforcerRule.java @@ -0,0 +1,139 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import org.apache.maven.enforcer.rule.api.EnforcerRule; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; + +/** + * @author Brian Fox + * + */ +public class MockEnforcerRule + implements EnforcerRule +{ + + public boolean failRule = false; + + public String cacheId=""; + + public boolean isCacheable = false; + + public boolean isResultValid = false; + + public boolean executed = false; + + public MockEnforcerRule( boolean fail ) + { + this.failRule = fail; + } + + public MockEnforcerRule( boolean fail, String cacheId, boolean isCacheable, boolean isResultValid ) + { + this.failRule = fail; + this.isCacheable = isCacheable; + this.isResultValid= isResultValid; + this.cacheId = cacheId; + } + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + executed = true; + if ( isFailRule() ) + { + throw new EnforcerRuleException( " this condition is not allowed." ); + } + } + + /** + * @return the failRule + */ + public boolean isFailRule() + { + return this.failRule; + } + + /** + * @param theFailRule + * the failRule to set + */ + public void setFailRule( boolean theFailRule ) + { + this.failRule = theFailRule; + } + + /** + * @return the isResultValid + */ + public boolean isResultValid () + { + return this.isResultValid; + } + + /** + * @param theIsResultValid the isResultValid to set + */ + public void setResultValid ( boolean theIsResultValid ) + { + this.isResultValid = theIsResultValid; + } + + /** + * @param theCacheId the cacheId to set + */ + public void setCacheId ( String theCacheId ) + { + this.cacheId = theCacheId; + } + + /** + * @param theIsCacheable the isCacheable to set + */ + public void setCacheable ( boolean theIsCacheable ) + { + this.isCacheable = theIsCacheable; + } + + /* (non-Javadoc) + * @see org.apache.maven.enforcer.rule.api.EnforcerRule#getCacheId() + */ + public String getCacheId () + { + return cacheId; + } + + /* (non-Javadoc) + * @see org.apache.maven.enforcer.rule.api.EnforcerRule#isCacheable() + */ + public boolean isCacheable () + { + return isCacheable; + } + + /* (non-Javadoc) + * @see org.apache.maven.enforcer.rule.api.EnforcerRule#isResultValid(org.apache.maven.enforcer.rule.api.EnforcerRule) + */ + public boolean isResultValid ( EnforcerRule theCachedRule ) + { + return isResultValid; + } + +} diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/TestDefaultEnforcementRuleHelper.java b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/TestDefaultEnforcementRuleHelper.java new file mode 100644 index 000000000..0fd3a3db9 --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/TestDefaultEnforcementRuleHelper.java @@ -0,0 +1,44 @@ +package org.apache.maven.plugins.enforcer; + +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; + +/* + * 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. + */ + +import junit.framework.TestCase; + +/** + * @author Brian Fox + * + */ +public class TestDefaultEnforcementRuleHelper + extends TestCase +{ + public void testHelper() + throws ComponentLookupException, ExpressionEvaluationException + { + DefaultEnforcementRuleHelper helper = (DefaultEnforcementRuleHelper) EnforcerTestUtils.getHelper(); + + assertNotNull( helper.getLog() ); + assertNotNull( helper.evaluate( "${session}" ) ); + assertNotNull( helper.evaluate( "${project}" ) ); + + } +} diff --git a/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/TestEnforceMojo.java b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/TestEnforceMojo.java new file mode 100644 index 000000000..c7677d35f --- /dev/null +++ b/Java-base/maven-enforcer/src/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/TestEnforceMojo.java @@ -0,0 +1,312 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.apache.maven.enforcer.rule.api.EnforcerRule; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.logging.Log; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Exhaustively check the enforcer mojo. + * + * @author Brian Fox + */ +@RunWith( MockitoJUnitRunner.class ) +public class TestEnforceMojo +{ + + @InjectMocks + EnforceMojo mojo; + + @Test + public void testEnforceMojo() + throws MojoExecutionException + { + setupBasics( false ); + + try + { + mojo.execute(); + fail( "Expected a Mojo Execution Exception." ); + } + catch ( MojoExecutionException e ) + { + System.out.println( "Caught Expected Exception:" + e.getLocalizedMessage() ); + } + + EnforcerRule[] rules = new EnforcerRule[10]; + rules[0] = new MockEnforcerRule( true ); + rules[1] = new MockEnforcerRule( true ); + mojo.setRules( rules ); + + mojo.execute(); + + try + { + mojo.setFailFast( false ); + mojo.setFail( true ); + mojo.execute(); + fail( "Expected a Mojo Execution Exception." ); + } + catch ( MojoExecutionException e ) + { + System.out.println( "Caught Expected Exception:" + e.getLocalizedMessage() ); + } + + try + { + mojo.setFailFast( true ); + mojo.setFail( true ); + mojo.execute(); + fail( "Expected a Mojo Execution Exception." ); + } + catch ( MojoExecutionException e ) + { + System.out.println( "Caught Expected Exception:" + e.getLocalizedMessage() ); + } + + ( (MockEnforcerRule) rules[0] ).setFailRule( false ); + ( (MockEnforcerRule) rules[1] ).setFailRule( false ); + mojo.execute(); + + } + + @Test + public void testCaching() + throws MojoExecutionException + { + setupBasics( true ); + + MockEnforcerRule[] rules = new MockEnforcerRule[10]; + + // check that basic caching works. + rules[0] = new MockEnforcerRule( false, "", true, true ); + rules[1] = new MockEnforcerRule( false, "", true, true ); + mojo.setRules( rules ); + + EnforceMojo.cache.clear(); + mojo.execute(); + + assertTrue( "Expected this rule to be executed.", rules[0].executed ); + assertFalse( "Expected this rule not to be executed.", rules[1].executed ); + + // check that skip caching works. + rules[0] = new MockEnforcerRule( false, "", true, true ); + rules[1] = new MockEnforcerRule( false, "", true, true ); + mojo.setRules( rules ); + + EnforceMojo.cache.clear(); + mojo.ignoreCache = true; + mojo.execute(); + + assertTrue( "Expected this rule to be executed.", rules[0].executed ); + assertTrue( "Expected this rule to be executed.", rules[1].executed ); + + mojo.ignoreCache = false; + + // check that different ids are compared. + rules[0] = new MockEnforcerRule( false, "1", true, true ); + rules[1] = new MockEnforcerRule( false, "2", true, true ); + rules[2] = new MockEnforcerRule( false, "2", true, true ); + mojo.setRules( rules ); + + EnforceMojo.cache.clear(); + mojo.execute(); + + assertTrue( "Expected this rule to be executed.", rules[0].executed ); + assertTrue( "Expected this rule to be executed.", rules[1].executed ); + assertFalse( "Expected this rule not to be executed.", rules[2].executed ); + + // check that future overrides are working + rules[0] = new MockEnforcerRule( false, "1", true, true ); + rules[1] = new MockEnforcerRule( false, "1", false, true ); + rules[2] = null; + mojo.setRules( rules ); + + EnforceMojo.cache.clear(); + mojo.execute(); + + assertTrue( "Expected this rule to be executed.", rules[0].executed ); + assertTrue( "Expected this rule to be executed.", rules[1].executed ); + + // check that future isResultValid is used + rules[0] = new MockEnforcerRule( false, "1", true, true ); + rules[1] = new MockEnforcerRule( false, "1", true, false ); + rules[2] = null; + mojo.setRules( rules ); + + EnforceMojo.cache.clear(); + mojo.execute(); + + assertTrue( "Expected this rule to be executed.", rules[0].executed ); + assertTrue( "Expected this rule to be executed.", rules[1].executed ); + + } + + @Test + public void testCachePersistence1() + throws MojoExecutionException + { + setupBasics( true ); + + MockEnforcerRule[] rules = new MockEnforcerRule[10]; + + // check that basic caching works. + rules[0] = new MockEnforcerRule( false, "", true, true ); + rules[1] = new MockEnforcerRule( false, "", true, true ); + mojo.setRules( rules ); + + EnforceMojo.cache.clear(); + mojo.execute(); + + assertTrue( "Expected this rule to be executed.", rules[0].executed ); + assertFalse( "Expected this rule not to be executed.", rules[1].executed ); + + } + + @Test + public void testCachePersistence2() + throws MojoExecutionException + { + setupBasics( true ); + + MockEnforcerRule[] rules = new MockEnforcerRule[10]; + + // check that basic caching works. + rules[0] = new MockEnforcerRule( false, "", true, true ); + rules[1] = new MockEnforcerRule( false, "", true, true ); + mojo.setRules( rules ); + + mojo.execute(); + + assertFalse( "Expected this rule not to be executed.", rules[0].executed ); + assertFalse( "Expected this rule not to be executed.", rules[1].executed ); + + } + + @Test + public void testCachePersistence3() + throws MojoExecutionException + { + System.gc(); + + try + { + Thread.sleep( 1000 ); + } + catch ( InterruptedException e ) + { + } + + setupBasics( true ); + + MockEnforcerRule[] rules = new MockEnforcerRule[10]; + + // check that basic caching works. + rules[0] = new MockEnforcerRule( false, "", true, true ); + rules[1] = new MockEnforcerRule( false, "", true, true ); + mojo.setRules( rules ); + + mojo.execute(); + + assertFalse( "Expected this rule not to be executed.", rules[0].executed ); + assertFalse( "Expected this rule not to be executed.", rules[1].executed ); + + } + + @Test + public void testLoggingOnEnforcerRuleExceptionWithMessage() + throws MojoExecutionException, EnforcerRuleException + { + // fail=false because this is out of scope here (also allows for cleaner test code without catch block) + setupBasics( false ); + + // the regular kind of EnforcerRuleException: + EnforcerRuleException ruleException = new EnforcerRuleException( "testMessage" ); + + EnforcerRule ruleMock = Mockito.mock( EnforcerRule.class ); + Mockito.doThrow( ruleException ).when( ruleMock ).execute( Mockito.any( EnforcerRuleHelper.class ) ); + + mojo.setRules( new EnforcerRule[] { ruleMock } ); + + Log logSpy = setupLogSpy(); + + mojo.execute(); + + Mockito.verify( logSpy ).debug( + Mockito.anyString() , Mockito.same( ruleException ) ); + + Mockito.verify( logSpy, Mockito.never() ).warn( + Mockito.anyString(), Mockito.any( Throwable.class ) ); + + Mockito.verify( logSpy ).warn( + Mockito.matches( ".* failed with message:" + System.lineSeparator() + ruleException.getMessage() ) ); + } + + @Test + public void testLoggingOnEnforcerRuleExceptionWithoutMessage() + throws MojoExecutionException, EnforcerRuleException + { + // fail=false because this is out of scope here (also allows for cleaner test code without catch block) + setupBasics( false ); + + // emulate behaviour of various rules that just catch Exception and wrap into EnforcerRuleException: + NullPointerException npe = new NullPointerException(); + EnforcerRuleException enforcerRuleException = new EnforcerRuleException( npe.getLocalizedMessage(), npe ); + + EnforcerRule ruleMock = Mockito.mock( EnforcerRule.class ); + Mockito.doThrow( enforcerRuleException ).when( ruleMock ).execute( Mockito.any( EnforcerRuleHelper.class ) ); + + mojo.setRules( new EnforcerRule[] { ruleMock } ); + + Log logSpy = setupLogSpy(); + + mojo.execute(); + + Mockito.verify( logSpy ).warn( + Mockito.contains("failed without a message"), Mockito.same( enforcerRuleException ) ); + + Mockito.verify( logSpy ).warn( + Mockito.matches( ".* failed with message:" + System.lineSeparator() + "null" ) ); + } + + private void setupBasics( boolean fail ) { + mojo.setFail( fail ); + mojo.setSession( EnforcerTestUtils.getMavenSession() ); + mojo.setProject( new MockProject() ); + } + + private Log setupLogSpy() { + Log spy = Mockito.spy( mojo.getLog() ); + mojo.setLog( spy ); + return spy; + } +} diff --git a/Java-base/maven-enforcer/src/pom.xml b/Java-base/maven-enforcer/src/pom.xml new file mode 100644 index 000000000..f49e71559 --- /dev/null +++ b/Java-base/maven-enforcer/src/pom.xml @@ -0,0 +1,229 @@ + + + + 4.0.0 + + + maven-parent + org.apache.maven + 34 + + org.apache.maven.enforcer + enforcer + 3.0.0-M4-SNAPSHOT + pom + + Apache Maven Enforcer + Enforcer is a build rule execution framework. + https://maven.apache.org/enforcer/ + 2007 + + + enforcer-api + enforcer-rules + maven-enforcer-plugin + + + + scm:git:https://gitbox.apache.org/repos/asf/maven-enforcer.git + scm:git:https://gitbox.apache.org/repos/asf/maven-enforcer.git + https://github.com/apache/maven-enforcer/tree/${project.scm.tag} + HEAD + + + jira + https://issues.apache.org/jira/browse/MENFORCER + + + Jenkins + https://builds.apache.org/job/maven-box/job/maven-enforcer/ + + + + apache.website + scm:svn:https://svn.apache.org/repos/asf/maven/website/components/${maven.site.path} + + + + + 3.0 + enforcer-archives/enforcer-LATEST + 7 + 2020-04-17T21:04:00Z + + + + + + org.apache.maven.enforcer + enforcer-api + ${project.version} + + + org.apache.maven.enforcer + enforcer-rules + ${project.version} + + + org.apache.maven.enforcer + enforcer-rules + ${project.version} + test-jar + test + + + org.apache.maven + maven-artifact + ${maven.version} + + + org.apache.maven + maven-plugin-api + ${maven.version} + + + org.apache.maven + maven-core + ${maven.version} + + + org.apache.maven + maven-compat + ${maven.version} + + + + org.apache.maven.shared + maven-common-artifact-filters + 3.1.0 + + + org.codehaus.plexus + plexus-utils + 3.3.0 + + + junit + junit + 4.13 + + + org.mockito + mockito-core + 2.28.2 + test + + + org.apache.commons + commons-lang3 + 3.8.1 + + + commons-codec + commons-codec + 1.14 + + + org.apache.maven.plugin-testing + maven-plugin-testing-harness + 2.1 + test + + + org.apache.maven.shared + maven-dependency-tree + 2.2 + + + org.apache.maven.resolver + maven-resolver-util + 1.4.1 + + + org.assertj + assertj-core + 1.7.1 + + + + + + + Simon Wang + wangyf2010@gmail.com + eBay Inc. + + + + + + + org.apache.maven.plugins + maven-release-plugin + + true + + + + org.apache.maven.plugins + maven-site-plugin + + scm:svn:https://svn.apache.org/repos/asf/maven/website/components/${maven.site.path} + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + + + org.codehaus.mojo + extra-enforcer-rules + 1.2 + + + + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + true + true + + + + aggregate + false + + aggregate + + + + + + + diff --git a/Java-base/maven-enforcer/src/src/site/resources/download.cgi b/Java-base/maven-enforcer/src/src/site/resources/download.cgi new file mode 100644 index 000000000..1b178d2e6 --- /dev/null +++ b/Java-base/maven-enforcer/src/src/site/resources/download.cgi @@ -0,0 +1,22 @@ +#!/bin/sh +# +# 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. +# +# Just call the standard mirrors.cgi script. It will use download.html +# as the input template. +exec /www/www.apache.org/dyn/mirrors/mirrors.cgi $* \ No newline at end of file diff --git a/Java-base/maven-enforcer/src/src/site/site.xml b/Java-base/maven-enforcer/src/src/site/site.xml new file mode 100644 index 000000000..273dd8e5d --- /dev/null +++ b/Java-base/maven-enforcer/src/src/site/site.xml @@ -0,0 +1,45 @@ + + + + + + true + + + https://maven.apache.org/enforcer/ + + + + + + + + + + + + + + + + + + + diff --git a/Java-base/maven-enforcer/src/src/site/xdoc/download.xml.vm b/Java-base/maven-enforcer/src/src/site/xdoc/download.xml.vm new file mode 100644 index 000000000..71fba5687 --- /dev/null +++ b/Java-base/maven-enforcer/src/src/site/xdoc/download.xml.vm @@ -0,0 +1,126 @@ + + + + + + + Download ${project.name} Source + + +
+ +

${project.name} ${project.version} is distributed in source format. Use a source archive if you intend to build + ${project.name} yourself. Otherwise, simply use the ready-made binary artifacts from central repository.

+ +

You will be prompted for a mirror - if the file is not found on yours, please be patient, as it may take 24 + hours to reach all mirrors.

+ +

In order to guard against corrupted downloads/installations, it is highly recommended to + verify the signature + of the release bundles against the public KEYS used by the Apache Maven + developers.

+ +

${project.name} is distributed under the Apache License, version 2.0.

+ +

We strongly encourage our users to configure a Maven repository mirror closer to their location, please read How to Use Mirrors for Repositories.

+ + + + +

+ [if-any logo] + + logo + + [end] + The currently selected mirror is + [preferred]. + If you encounter a problem with this mirror, + please select another mirror. + If all mirrors are failing, there are + backup + mirrors + (at the end of the mirrors list) that should be available. +

+ +
+ Other mirrors: + + +
+ +

+ You may also consult the + complete list of + mirrors. +

+ + + + + +

This is the current stable version of ${project.name}.

+ + + + + + + + + + + + + + + + + + +
LinkChecksumSignature
${project.name} ${project.version} (Source zip)maven/enforcer/${project.artifactId}-${project.version}-source-release.zipmaven/enforcer/${project.artifactId}-${project.version}-source-release.zip.sha512maven/enforcer/${project.artifactId}-${project.version}-source-release.zip.asc
+
+ + + +

Older non-recommended releases can be found on our archive site.

+ +
+
+ +
+ diff --git a/Java/maven-enforcer-AbstractPropertyEnforcerRule_103/Dockerfile b/Java/maven-enforcer-AbstractPropertyEnforcerRule_103/Dockerfile new file mode 100644 index 000000000..3581e6769 --- /dev/null +++ b/Java/maven-enforcer-AbstractPropertyEnforcerRule_103/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-enforcer + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-enforcer-AbstractPropertyEnforcerRule_103/buggy.java b/Java/maven-enforcer-AbstractPropertyEnforcerRule_103/buggy.java new file mode 100644 index 000000000..327ebb6f9 --- /dev/null +++ b/Java/maven-enforcer-AbstractPropertyEnforcerRule_103/buggy.java @@ -0,0 +1,130 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; + +/** + * Abstract enforcer rule that give a foundation to validate properties from multiple sources. + * + * @author Paul Gier + * @author Marvin Froeder + */ +public abstract class AbstractPropertyEnforcerRule + extends AbstractNonCacheableEnforcerRule +{ + + /** + * Match the property value to a given regular expression. Defaults to null (any value is ok). + * + * @see {@link #setRegex(String)} + * @see {@link #getRegex()} + */ + private String regex = null; + + /** + * Specify a warning message if the regular expression is not matched. + * + * @see {@link #setRegexMessage(String)} + * @see {@link #getRegexMessage()} + */ + private String regexMessage = null; + + public AbstractPropertyEnforcerRule() + { + super(); + } + + /** + * Set the property value to a given regular expression. Defaults to null (any value is ok). + * + * @param regex The regular expression + */ + public final void setRegex( String regex ) + { + this.regex = regex; + } + + /** + * Get the property value to a given regular expression. Defaults to null (any value is ok). + * + * @return the regular expression + */ + public final String getRegex() + { + return regex; + } + + /** + * Set a warning message if the regular expression is not matched. + * + * @param regexMessage the regex message + */ + public final void setRegexMessage( String regexMessage ) + { + this.regexMessage = regexMessage; + } + + /** + * Get a warning message if the regular expression is not matched. + * + * @return the regex message + */ + public final String getRegexMessage() + { + return regexMessage; + } + + @Override +public void execute(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper helper) throws org.apache.maven.enforcer.rule.api.EnforcerRuleException { + java.lang.Object propValue = resolveValue(helper); + { + // If there is a regex, check that the property matches it + if ((regex != null) && (!/* NPEX_NULL_EXP */ + propValue.toString().matches(regex))) { + if (regexMessage == null) { + regexMessage = (((((((getName() + " \"") + getPropertyName()) + "\" evaluates to \"") + propValue) + "\". ") + "This does not match the regular expression \"") + regex) + "\""; + } + throw new org.apache.maven.enforcer.rule.api.EnforcerRuleException(regexMessage); + } + } +} + + /** + * How the property that is being evaluated is called + */ + public abstract String getName(); + + /** + * The name of the property currently being evaluated, this is used for default message pourpouses only + */ + public abstract String getPropertyName(); + + /** + * Resolves the property value + * + * @param helper + * @throws EnforcerRuleException + */ + public abstract Object resolveValue( EnforcerRuleHelper helper ) + throws EnforcerRuleException; + +} diff --git a/Java/maven-enforcer-AbstractPropertyEnforcerRule_103/metadata.json b/Java/maven-enforcer-AbstractPropertyEnforcerRule_103/metadata.json new file mode 100644 index 000000000..109e83008 --- /dev/null +++ b/Java/maven-enforcer-AbstractPropertyEnforcerRule_103/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-enforcer-AbstractPropertyEnforcerRule_103", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn clean test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractPropertyEnforcerRule.java", + "line": 102, + "npe_method": "execute", + "deref_field": "propValue", + "npe_class": "AbstractPropertyEnforcerRule", + "repo": "maven-enforcer", + "bug_id": "AbstractPropertyEnforcerRule_103" + } +} diff --git a/Java/maven-enforcer-AbstractPropertyEnforcerRule_103/npe.json b/Java/maven-enforcer-AbstractPropertyEnforcerRule_103/npe.json new file mode 100644 index 000000000..ddcb1fe3a --- /dev/null +++ b/Java/maven-enforcer-AbstractPropertyEnforcerRule_103/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractPropertyEnforcerRule.java", + "line": 102, + "npe_method": "execute", + "deref_field": "propValue", + "npe_class": "AbstractPropertyEnforcerRule" +} \ No newline at end of file diff --git a/Java/maven-enforcer-AbstractRequireFiles_129/Dockerfile b/Java/maven-enforcer-AbstractRequireFiles_129/Dockerfile new file mode 100644 index 000000000..3581e6769 --- /dev/null +++ b/Java/maven-enforcer-AbstractRequireFiles_129/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-enforcer + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-enforcer-AbstractRequireFiles_129/buggy.java b/Java/maven-enforcer-AbstractRequireFiles_129/buggy.java new file mode 100644 index 000000000..85db7cd17 --- /dev/null +++ b/Java/maven-enforcer-AbstractRequireFiles_129/buggy.java @@ -0,0 +1,177 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import org.apache.maven.enforcer.rule.api.EnforcerRule; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; + +/** + * Contains the common code to compare an array of files against a requirement. + * + * @author Brian Fox + */ +public abstract class AbstractRequireFiles + extends AbstractStandardEnforcerRule +{ + + /** Array of files to check. */ + private File[] files; + + /** if null file handles should be allowed. If they are allowed, it means treat it as a success. */ + private boolean allowNulls = false; + + // check the file for the specific condition + /** + * Check one file. + * + * @param file the file + * @return true if successful + */ + abstract boolean checkFile( File file ); + + // return standard error message + /** + * Gets the error msg. + * + * @return the error msg + */ + abstract String getErrorMsg(); + + @Override + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + + if ( !allowNulls && files.length == 0 ) + { + throw new EnforcerRuleException( "The file list is empty and Null files are disabled." ); + } + + List failures = new ArrayList<>(); + for ( File file : files ) + { + if ( !allowNulls && file == null ) + { + failures.add( file ); + } + else if ( !checkFile( file ) ) + { + failures.add( file ); + } + } + + // if anything was found, log it with the optional message. + if ( !failures.isEmpty() ) + { + String message = getMessage(); + + StringBuilder buf = new StringBuilder(); + if ( message != null ) + { + buf.append( message + System.lineSeparator() ); + } + buf.append( getErrorMsg() ); + + for ( File file : failures ) + { + if ( file != null ) + { + buf.append( file.getAbsolutePath() + System.lineSeparator() ); + } + else + { + buf.append( "(an empty filename was given and allowNulls is false)" + System.lineSeparator() ); + } + } + + throw new EnforcerRuleException( buf.toString() ); + } + } + + @Override + public String getCacheId() + { + return Integer.toString( hashCode( files ) ); + } + + /** + * Calculates a hash code for the specified array as Arrays.hashCode() would do. Unfortunately, the + * mentioned method is only available for Java 1.5 and later. + * + * @param items The array for which to compute the hash code, may be null. + * @return The hash code for the array. + */ +/** + * Calculates a hash code for the specified array as Arrays.hashCode() would do. Unfortunately, the + * mentioned method is only available for Java 1.5 and later. + * + * @param items + * The array for which to compute the hash code, may be null. + * @return The hash code for the array. + */ +private static int hashCode(java.lang.Object[] items) { + int hash = 0; + { + hash = 1; + for (java.lang.Object item : /* NPEX_NULL_EXP */ + items) { + hash = (31 * hash) + (item == null ? 0 : item.hashCode()); + } + } + return hash; +} + + @Override + public boolean isCacheable() + { + return true; + } + + @Override + public boolean isResultValid( EnforcerRule cachedRule ) + { + return true; + } + + public File[] getFiles() + { + return files; + } + + public void setFiles( File[] files ) + { + this.files = files; + } + + public boolean isAllowNulls() + { + return allowNulls; + } + + public void setAllowNulls( boolean allowNulls ) + { + this.allowNulls = allowNulls; + } +} diff --git a/Java/maven-enforcer-AbstractRequireFiles_129/metadata.json b/Java/maven-enforcer-AbstractRequireFiles_129/metadata.json new file mode 100644 index 000000000..4a1f15271 --- /dev/null +++ b/Java/maven-enforcer-AbstractRequireFiles_129/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-enforcer-AbstractRequireFiles_129", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn clean test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractRequireFiles.java", + "line": 139, + "npe_method": "hashCode", + "deref_field": "items", + "npe_class": "AbstractRequireFiles", + "repo": "maven-enforcer", + "bug_id": "AbstractRequireFiles_129" + } +} diff --git a/Java/maven-enforcer-AbstractRequireFiles_129/npe.json b/Java/maven-enforcer-AbstractRequireFiles_129/npe.json new file mode 100644 index 000000000..3db354ceb --- /dev/null +++ b/Java/maven-enforcer-AbstractRequireFiles_129/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractRequireFiles.java", + "line": 139, + "npe_method": "hashCode", + "deref_field": "items", + "npe_class": "AbstractRequireFiles" +} \ No newline at end of file diff --git a/Java/maven-enforcer-AbstractRequireFiles_134/Dockerfile b/Java/maven-enforcer-AbstractRequireFiles_134/Dockerfile new file mode 100644 index 000000000..3581e6769 --- /dev/null +++ b/Java/maven-enforcer-AbstractRequireFiles_134/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-enforcer + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-enforcer-AbstractRequireFiles_134/buggy.java b/Java/maven-enforcer-AbstractRequireFiles_134/buggy.java new file mode 100644 index 000000000..e0f114b45 --- /dev/null +++ b/Java/maven-enforcer-AbstractRequireFiles_134/buggy.java @@ -0,0 +1,177 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import org.apache.maven.enforcer.rule.api.EnforcerRule; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; + +/** + * Contains the common code to compare an array of files against a requirement. + * + * @author Brian Fox + */ +public abstract class AbstractRequireFiles + extends AbstractStandardEnforcerRule +{ + + /** Array of files to check. */ + private File[] files; + + /** if null file handles should be allowed. If they are allowed, it means treat it as a success. */ + private boolean allowNulls = false; + + // check the file for the specific condition + /** + * Check one file. + * + * @param file the file + * @return true if successful + */ + abstract boolean checkFile( File file ); + + // return standard error message + /** + * Gets the error msg. + * + * @return the error msg + */ + abstract String getErrorMsg(); + + @Override + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + + if ( !allowNulls && files.length == 0 ) + { + throw new EnforcerRuleException( "The file list is empty and Null files are disabled." ); + } + + List failures = new ArrayList<>(); + for ( File file : files ) + { + if ( !allowNulls && file == null ) + { + failures.add( file ); + } + else if ( !checkFile( file ) ) + { + failures.add( file ); + } + } + + // if anything was found, log it with the optional message. + if ( !failures.isEmpty() ) + { + String message = getMessage(); + + StringBuilder buf = new StringBuilder(); + if ( message != null ) + { + buf.append( message + System.lineSeparator() ); + } + buf.append( getErrorMsg() ); + + for ( File file : failures ) + { + if ( file != null ) + { + buf.append( file.getAbsolutePath() + System.lineSeparator() ); + } + else + { + buf.append( "(an empty filename was given and allowNulls is false)" + System.lineSeparator() ); + } + } + + throw new EnforcerRuleException( buf.toString() ); + } + } + + @Override + public String getCacheId() + { + return Integer.toString( hashCode( files ) ); + } + + /** + * Calculates a hash code for the specified array as Arrays.hashCode() would do. Unfortunately, the + * mentioned method is only available for Java 1.5 and later. + * + * @param items The array for which to compute the hash code, may be null. + * @return The hash code for the array. + */ +/** + * Calculates a hash code for the specified array as Arrays.hashCode() would do. Unfortunately, the + * mentioned method is only available for Java 1.5 and later. + * + * @param items + * The array for which to compute the hash code, may be null. + * @return The hash code for the array. + */ +private static int hashCode(java.lang.Object[] items) { + int hash = 0; + { + hash = 1; + for (java.lang.Object item : items) { + hash = (31 * hash) + /* NPEX_NULL_EXP */ + item.hashCode(); + } + } + return hash; +} + + @Override + public boolean isCacheable() + { + return true; + } + + @Override + public boolean isResultValid( EnforcerRule cachedRule ) + { + return true; + } + + public File[] getFiles() + { + return files; + } + + public void setFiles( File[] files ) + { + this.files = files; + } + + public boolean isAllowNulls() + { + return allowNulls; + } + + public void setAllowNulls( boolean allowNulls ) + { + this.allowNulls = allowNulls; + } +} diff --git a/Java/maven-enforcer-AbstractRequireFiles_134/metadata.json b/Java/maven-enforcer-AbstractRequireFiles_134/metadata.json new file mode 100644 index 000000000..d7b6dd756 --- /dev/null +++ b/Java/maven-enforcer-AbstractRequireFiles_134/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-enforcer-AbstractRequireFiles_134", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn clean test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractRequireFiles.java", + "line": 140, + "npe_method": "hashCode", + "deref_field": "item", + "npe_class": "AbstractRequireFiles", + "repo": "maven-enforcer", + "bug_id": "AbstractRequireFiles_134" + } +} diff --git a/Java/maven-enforcer-AbstractRequireFiles_134/npe.json b/Java/maven-enforcer-AbstractRequireFiles_134/npe.json new file mode 100644 index 000000000..b9998c093 --- /dev/null +++ b/Java/maven-enforcer-AbstractRequireFiles_134/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractRequireFiles.java", + "line": 140, + "npe_method": "hashCode", + "deref_field": "item", + "npe_class": "AbstractRequireFiles" +} \ No newline at end of file diff --git a/Java/maven-enforcer-AbstractRequireFiles_99/Dockerfile b/Java/maven-enforcer-AbstractRequireFiles_99/Dockerfile new file mode 100644 index 000000000..3581e6769 --- /dev/null +++ b/Java/maven-enforcer-AbstractRequireFiles_99/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-enforcer + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-enforcer-AbstractRequireFiles_99/buggy.java b/Java/maven-enforcer-AbstractRequireFiles_99/buggy.java new file mode 100644 index 000000000..81268337a --- /dev/null +++ b/Java/maven-enforcer-AbstractRequireFiles_99/buggy.java @@ -0,0 +1,151 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import org.apache.maven.enforcer.rule.api.EnforcerRule; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; + +/** + * Contains the common code to compare an array of files against a requirement. + * + * @author Brian Fox + */ +public abstract class AbstractRequireFiles + extends AbstractStandardEnforcerRule +{ + + /** Array of files to check. */ + private File[] files; + + /** if null file handles should be allowed. If they are allowed, it means treat it as a success. */ + private boolean allowNulls = false; + + // check the file for the specific condition + /** + * Check one file. + * + * @param file the file + * @return true if successful + */ + abstract boolean checkFile( File file ); + + // return standard error message + /** + * Gets the error msg. + * + * @return the error msg + */ + abstract String getErrorMsg(); + + @Override +public void execute(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper helper) throws org.apache.maven.enforcer.rule.api.EnforcerRuleException { + if ((!allowNulls) && (files.length == 0)) { + throw new org.apache.maven.enforcer.rule.api.EnforcerRuleException("The file list is empty and Null files are disabled."); + } + java.util.List failures = new java.util.ArrayList<>(); + for (java.io.File file : files) { + if ((!allowNulls) && (file == null)) { + failures.add(file); + } else if (!checkFile(file)) { + failures.add(file); + } + } + // if anything was found, log it with the optional message. + if (!failures.isEmpty()) { + java.lang.String message = getMessage(); + java.lang.StringBuilder buf = new java.lang.StringBuilder(); + if (message != null) { + buf.append(message + java.lang.System.lineSeparator()); + } + buf.append(getErrorMsg()); + for (java.io.File file : failures) { + { + buf.append(/* NPEX_NULL_EXP */ + file.getAbsolutePath() + java.lang.System.lineSeparator()); + } + } + throw new org.apache.maven.enforcer.rule.api.EnforcerRuleException(buf.toString()); + } +} + + @Override + public String getCacheId() + { + return Integer.toString( hashCode( files ) ); + } + + /** + * Calculates a hash code for the specified array as Arrays.hashCode() would do. Unfortunately, the + * mentioned method is only available for Java 1.5 and later. + * + * @param items The array for which to compute the hash code, may be null. + * @return The hash code for the array. + */ + private static int hashCode( Object[] items ) + { + int hash = 0; + if ( items != null ) + { + hash = 1; + for ( Object item : items ) + { + hash = 31 * hash + ( item == null ? 0 : item.hashCode() ); + } + } + return hash; + } + + @Override + public boolean isCacheable() + { + return true; + } + + @Override + public boolean isResultValid( EnforcerRule cachedRule ) + { + return true; + } + + public File[] getFiles() + { + return files; + } + + public void setFiles( File[] files ) + { + this.files = files; + } + + public boolean isAllowNulls() + { + return allowNulls; + } + + public void setAllowNulls( boolean allowNulls ) + { + this.allowNulls = allowNulls; + } +} diff --git a/Java/maven-enforcer-AbstractRequireFiles_99/metadata.json b/Java/maven-enforcer-AbstractRequireFiles_99/metadata.json new file mode 100644 index 000000000..b49a45099 --- /dev/null +++ b/Java/maven-enforcer-AbstractRequireFiles_99/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-enforcer-AbstractRequireFiles_99", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn clean test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractRequireFiles.java", + "line": 86, + "npe_method": "execute", + "deref_field": "file", + "npe_class": "AbstractRequireFiles", + "repo": "maven-enforcer", + "bug_id": "AbstractRequireFiles_99" + } +} diff --git a/Java/maven-enforcer-AbstractRequireFiles_99/npe.json b/Java/maven-enforcer-AbstractRequireFiles_99/npe.json new file mode 100644 index 000000000..7ae5244e6 --- /dev/null +++ b/Java/maven-enforcer-AbstractRequireFiles_99/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractRequireFiles.java", + "line": 86, + "npe_method": "execute", + "deref_field": "file", + "npe_class": "AbstractRequireFiles" +} \ No newline at end of file diff --git a/Java/maven-enforcer-AbstractVersionEnforcer_130/Dockerfile b/Java/maven-enforcer-AbstractVersionEnforcer_130/Dockerfile new file mode 100644 index 000000000..3581e6769 --- /dev/null +++ b/Java/maven-enforcer-AbstractVersionEnforcer_130/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-enforcer + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-enforcer-AbstractVersionEnforcer_130/buggy.java b/Java/maven-enforcer-AbstractVersionEnforcer_130/buggy.java new file mode 100644 index 000000000..3f9effba4 --- /dev/null +++ b/Java/maven-enforcer-AbstractVersionEnforcer_130/buggy.java @@ -0,0 +1,207 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.util.List; + +import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; +import org.apache.maven.artifact.versioning.Restriction; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.enforcer.rule.api.EnforcerRule; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.plugin.logging.Log; +import org.codehaus.plexus.util.StringUtils; + +/** + * Contains the common code to compare a version against a version range. + * + * @author Brian Fox + */ +public abstract class AbstractVersionEnforcer + extends AbstractStandardEnforcerRule +{ + + /** + * Specify the required version. Some examples are: + *
    + *
  • 2.0.4 Version 2.0.4 and higher (different from Maven meaning)
  • + *
  • [2.0,2.1) Versions 2.0 (included) to 2.1 (not included)
  • + *
  • [2.0,2.1] Versions 2.0 to 2.1 (both included)
  • + *
  • [2.0.5,) Versions 2.0.5 and higher
  • + *
  • (,2.0.5],[2.1.1,) Versions up to 2.0.5 (included) and 2.1.1 or higher
  • + *
+ * + * @see {@link #setVersion(String)} + * @see {@link #getVersion()} + */ + private String version; + + /** + * Compares the specified version to see if it is allowed by the defined version range. + * + * @param log the log + * @param variableName name of variable to use in messages (Example: "Maven" or "Java" etc). + * @param requiredVersionRange range of allowed versions. + * @param actualVersion the version to be checked. + * @throws EnforcerRuleException the enforcer rule exception + */ + // CHECKSTYLE_OFF: LineLength + public void enforceVersion( Log log, String variableName, String requiredVersionRange, ArtifactVersion actualVersion ) + throws EnforcerRuleException + // CHECKSTYLE_ON: LineLength + { + if ( StringUtils.isEmpty( requiredVersionRange ) ) + { + throw new EnforcerRuleException( variableName + " version can't be empty." ); + } + else + { + + VersionRange vr; + String msg = "Detected " + variableName + " Version: " + actualVersion; + + // short circuit check if the strings are exactly equal + if ( actualVersion.toString().equals( requiredVersionRange ) ) + { + log.debug( msg + " is allowed in the range " + requiredVersionRange + "." ); + } + else + { + try + { + vr = VersionRange.createFromVersionSpec( requiredVersionRange ); + + if ( containsVersion( vr, actualVersion ) ) + { + log.debug( msg + " is allowed in the range " + requiredVersionRange + "." ); + } + else + { + String message = getMessage(); + + if ( StringUtils.isEmpty( message ) ) + { + message = msg + " is not in the allowed range " + vr + "."; + } + + throw new EnforcerRuleException( message ); + } + } + catch ( InvalidVersionSpecificationException e ) + { + throw new EnforcerRuleException( "The requested " + variableName + " version " + + requiredVersionRange + " is invalid.", e ); + } + } + } + } + + /** + * Copied from Artifact.VersionRange. This is tweaked to handle singular ranges properly. Currently the default + * containsVersion method assumes a singular version means allow everything. This method assumes that "2.0.4" == + * "[2.0.4,)" + * + * @param allowedRange range of allowed versions. + * @param theVersion the version to be checked. + * @return true if the version is contained by the range. + */ +/** + * Copied from Artifact.VersionRange. This is tweaked to handle singular ranges properly. Currently the default + * containsVersion method assumes a singular version means allow everything. This method assumes that "2.0.4" == + * "[2.0.4,)" + * + * @param allowedRange + * range of allowed versions. + * @param theVersion + * the version to be checked. + * @return true if the version is contained by the range. + */ +public static boolean containsVersion(org.apache.maven.artifact.versioning.VersionRange allowedRange, org.apache.maven.artifact.versioning.ArtifactVersion theVersion) { + boolean matched = false; + org.apache.maven.artifact.versioning.ArtifactVersion recommendedVersion = allowedRange.getRecommendedVersion(); + { + // only singular versions ever have a recommendedVersion + @java.lang.SuppressWarnings("unchecked") + int compareTo = /* NPEX_NULL_EXP */ + recommendedVersion.compareTo(theVersion); + matched = compareTo <= 0; + } + return matched; +} + + @Override + public String getCacheId() + { + if ( StringUtils.isNotEmpty( version ) ) + { + // return the hashcodes of the parameter that matters + return "" + version.hashCode(); + } + else + { + return "0"; + } + + } + + @Override + public boolean isCacheable() + { + // the maven version is not going to change between projects in the same build. + return true; + } + + @Override + public boolean isResultValid( EnforcerRule theCachedRule ) + { + // i will always return the hash of the parameters as my id. If my parameters are the same, this + // rule must always have the same result. + return true; + } + + /** + * Gets the required version. + * + * @return the required version + */ + public final String getVersion() + { + return this.version; + } + + /** + * Specify the required version. Some examples are: + *
    + *
  • 2.0.4 Version 2.0.4 and higher (different from Maven meaning)
  • + *
  • [2.0,2.1) Versions 2.0 (included) to 2.1 (not included)
  • + *
  • [2.0,2.1] Versions 2.0 to 2.1 (both included)
  • + *
  • [2.0.5,) Versions 2.0.5 and higher
  • + *
  • (,2.0.5],[2.1.1,) Versions up to 2.0.5 (included) and 2.1.1 or higher
  • + *
+ * + * @param theVersion the required version to set + */ + public final void setVersion( String theVersion ) + { + this.version = theVersion; + } + +} diff --git a/Java/maven-enforcer-AbstractVersionEnforcer_130/metadata.json b/Java/maven-enforcer-AbstractVersionEnforcer_130/metadata.json new file mode 100644 index 000000000..de5a5c5e9 --- /dev/null +++ b/Java/maven-enforcer-AbstractVersionEnforcer_130/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-enforcer-AbstractVersionEnforcer_130", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn clean test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractVersionEnforcer.java", + "line": 144, + "npe_method": "containsVersion", + "deref_field": "recommendedVersion", + "npe_class": "AbstractVersionEnforcer", + "repo": "maven-enforcer", + "bug_id": "AbstractVersionEnforcer_130" + } +} diff --git a/Java/maven-enforcer-AbstractVersionEnforcer_130/npe.json b/Java/maven-enforcer-AbstractVersionEnforcer_130/npe.json new file mode 100644 index 000000000..0000d2b69 --- /dev/null +++ b/Java/maven-enforcer-AbstractVersionEnforcer_130/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractVersionEnforcer.java", + "line": 144, + "npe_method": "containsVersion", + "deref_field": "recommendedVersion", + "npe_class": "AbstractVersionEnforcer" +} \ No newline at end of file diff --git a/Java/maven-enforcer-BannedDependencies_78/Dockerfile b/Java/maven-enforcer-BannedDependencies_78/Dockerfile new file mode 100644 index 000000000..3581e6769 --- /dev/null +++ b/Java/maven-enforcer-BannedDependencies_78/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-enforcer + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-enforcer-BannedDependencies_78/buggy.java b/Java/maven-enforcer-BannedDependencies_78/buggy.java new file mode 100644 index 000000000..c55a84bc2 --- /dev/null +++ b/Java/maven-enforcer-BannedDependencies_78/buggy.java @@ -0,0 +1,132 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.util.List; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.plugins.enforcer.utils.ArtifactUtils; + +/** + * This rule checks that lists of dependencies are not included. + * + * @author Brian Fox + */ +public class BannedDependencies + extends AbstractBanDependencies +{ + + /** + * Specify the banned dependencies. This can be a list of artifacts in the format + * groupId[:artifactId][:version]. Any of the sections can be a wildcard + * by using '*' (ie group:*:1.0)
+ * The rule will fail if any dependency matches any exclude, unless it also matches + * an include rule. + * + * @see {@link #setExcludes(List)} + * @see {@link #getExcludes()} + */ + private List excludes = null; + + /** + * Specify the allowed dependencies. This can be a list of artifacts in the format + * groupId[:artifactId][:version]. Any of the sections can be a wildcard + * by using '*' (ie group:*:1.0)
+ * Includes override the exclude rules. It is meant to allow wide exclusion rules + * with wildcards and still allow a + * smaller set of includes.
+ * For example, to ban all xerces except xerces-api -> exclude "xerces", include "xerces:xerces-api" + * + * @see {@link #setIncludes(List)} + * @see {@link #getIncludes()} + */ + private List includes = null; + + @Override +protected java.util.Set checkDependencies(java.util.Set theDependencies, org.apache.maven.plugin.logging.Log log) throws org.apache.maven.enforcer.rule.api.EnforcerRuleException { + java.util.Set excluded = org.apache.maven.plugins.enforcer.utils.ArtifactUtils.checkDependencies(theDependencies, excludes); + { + java.util.Set included = org.apache.maven.plugins.enforcer.utils.ArtifactUtils.checkDependencies(theDependencies, includes); + { + /* NPEX_NULL_EXP */ + excluded.removeAll(/* NPEX_NULL_EXP */ + included); + } + } + return excluded; +} + + /** + * Gets the excludes. + * + * @return the excludes + */ + public List getExcludes() + { + return this.excludes; + } + + /** + * Specify the banned dependencies. This can be a list of artifacts in the format + * groupId[:artifactId][:version]. Any of the sections can be a wildcard + * by using '*' (ie group:*:1.0)
+ * The rule will fail if any dependency matches any exclude, unless it also matches an + * include rule. + * + * @see #getExcludes() + * @param theExcludes the excludes to set + */ + public void setExcludes( List theExcludes ) + { + this.excludes = theExcludes; + } + + /** + * Gets the includes. + * + * @return the includes + */ + public List getIncludes() + { + return this.includes; + } + + /** + * Specify the allowed dependencies. This can be a list of artifacts in the format + * groupId[:artifactId][:version]. Any of the sections can be a wildcard + * by using '*' (ie group:*:1.0)
+ * Includes override the exclude rules. It is meant to allow wide exclusion rules with + * wildcards and still allow a + * smaller set of includes.
+ * For example, to ban all xerces except xerces-api → exclude "xerces", + * include "xerces:xerces-api" + * + * @see #setIncludes(List) + * @param theIncludes the includes to set + */ + public void setIncludes( List theIncludes ) + { + this.includes = theIncludes; + } + +} diff --git a/Java/maven-enforcer-BannedDependencies_78/metadata.json b/Java/maven-enforcer-BannedDependencies_78/metadata.json new file mode 100644 index 000000000..c892bea7e --- /dev/null +++ b/Java/maven-enforcer-BannedDependencies_78/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-enforcer-BannedDependencies_78", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn clean test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BannedDependencies.java", + "line": 73, + "npe_method": "checkDependencies", + "deref_field": "included", + "npe_class": "BannedDependencies", + "repo": "maven-enforcer", + "bug_id": "BannedDependencies_78" + } +} diff --git a/Java/maven-enforcer-BannedDependencies_78/npe.json b/Java/maven-enforcer-BannedDependencies_78/npe.json new file mode 100644 index 000000000..e6d6f67ee --- /dev/null +++ b/Java/maven-enforcer-BannedDependencies_78/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BannedDependencies.java", + "line": 73, + "npe_method": "checkDependencies", + "deref_field": "included", + "npe_class": "BannedDependencies" +} \ No newline at end of file diff --git a/Java/maven-enforcer-EnforceMojo_190/Dockerfile b/Java/maven-enforcer-EnforceMojo_190/Dockerfile new file mode 100644 index 000000000..3581e6769 --- /dev/null +++ b/Java/maven-enforcer-EnforceMojo_190/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-enforcer + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-enforcer-EnforceMojo_190/buggy.java b/Java/maven-enforcer-EnforceMojo_190/buggy.java new file mode 100644 index 000000000..38e15aec1 --- /dev/null +++ b/Java/maven-enforcer-EnforceMojo_190/buggy.java @@ -0,0 +1,402 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; + +import org.apache.maven.enforcer.rule.api.EnforcerLevel; +import org.apache.maven.enforcer.rule.api.EnforcerRule; +import org.apache.maven.enforcer.rule.api.EnforcerRule2; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecution; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.annotations.ResolutionScope; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.PlexusConstants; +import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.context.Context; +import org.codehaus.plexus.context.ContextException; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; + +/** + * This goal executes the defined enforcer-rules once per module. + * + * @author Brian Fox + */ +// CHECKSTYLE_OFF: LineLength +@Mojo( name = "enforce", defaultPhase = LifecyclePhase.VALIDATE, requiresDependencyCollection = ResolutionScope.TEST, threadSafe = true ) +//CHECKSTYLE_ON: LineLength +public class EnforceMojo + extends AbstractMojo + implements Contextualizable +{ + /** + * This is a static variable used to persist the cached results across plugin invocations. + */ + protected static Hashtable cache = new Hashtable<>(); + + /** + * MojoExecution needed by the ExpressionEvaluator + */ + @Parameter( defaultValue = "${mojoExecution}", readonly = true, required = true ) + protected MojoExecution mojoExecution; + + /** + * The MavenSession + */ + @Parameter( defaultValue = "${session}", readonly = true, required = true ) + protected MavenSession session; + + /** + * POM + */ + @Parameter( defaultValue = "${project}", readonly = true, required = true ) + protected MavenProject project; + + /** + * Flag to easily skip all checks + */ + @Parameter( property = "enforcer.skip", defaultValue = "false" ) + protected boolean skip = false; + + /** + * Flag to fail the build if a version check fails. + */ + @Parameter( property = "enforcer.fail", defaultValue = "true" ) + private boolean fail = true; + + /** + * Fail on the first rule that doesn't pass + */ + @Parameter( property = "enforcer.failFast", defaultValue = "false" ) + private boolean failFast = false; + + /** + * Array of objects that implement the EnforcerRule interface to execute. + */ + @Parameter( required = false ) + private EnforcerRule[] rules; + + /** + * Array of Strings that matches the EnforcerRules to execute. + */ + @Parameter( required = false, property = "rules" ) + private String[] commandLineRules; + + /** + * Use this flag to disable rule result caching. This will cause all rules to execute on each project even if the + * rule indicates it can safely be cached. + */ + @Parameter( property = "enforcer.ignoreCache", defaultValue = "false" ) + protected boolean ignoreCache = false; + + // set by the contextualize method. Only way to get the + // plugin's container in 2.0.x + protected PlexusContainer container; + + @Override + public void contextualize( Context context ) + throws ContextException + { + container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); + } + + private boolean havingRules() + { + return rules != null && rules.length > 0; + } + + /** + * Entry point to the mojo + * + * @throws MojoExecutionException + */ + @Override +/** + * Entry point to the mojo + * + * @throws MojoExecutionException + * + */ +public void execute() throws org.apache.maven.plugin.MojoExecutionException { + org.apache.maven.plugin.logging.Log log = this.getLog(); + org.apache.maven.plugins.enforcer.EnforcerExpressionEvaluator evaluator = new org.apache.maven.plugins.enforcer.EnforcerExpressionEvaluator(session, mojoExecution); + if ((commandLineRules != null) && (commandLineRules.length > 0)) { + this.rules = createRulesFromCommandLineOptions(); + } + if (isSkip()) { + log.info("Skipping Rule Enforcement."); + return; + } + if (!havingRules()) { + // CHECKSTYLE_OFF: LineLength + throw new org.apache.maven.plugin.MojoExecutionException("No rules are configured. Use the skip flag if you want to disable execution."); + // CHECKSTYLE_ON: LineLength + } + // list to store exceptions + java.util.List list = new java.util.ArrayList<>(); + java.lang.String currentRule = "Unknown"; + // create my helper + org.apache.maven.enforcer.rule.api.EnforcerRuleHelper helper = new org.apache.maven.plugins.enforcer.DefaultEnforcementRuleHelper(session, evaluator, log, container); + // if we are only warning, then disable + // failFast + if (!fail) { + failFast = false; + } + boolean hasErrors = false; + // go through each rule + for (int i = 0; i < rules.length; i++) { + // prevent against empty rules + org.apache.maven.enforcer.rule.api.EnforcerRule rule = rules[i]; + final org.apache.maven.enforcer.rule.api.EnforcerLevel level = getLevel(rule); + { + // store the current rule for + // logging purposes + currentRule = /* NPEX_NULL_EXP */ + rule.getClass().getName(); + log.debug("Executing rule: " + currentRule); + try { + if (ignoreCache || shouldExecute(rule)) { + // execute the rule + // noinspection + // SynchronizationOnLocalVariableOrMethodParameter + synchronized(rule) { + rule.execute(helper); + } + } + } catch (org.apache.maven.enforcer.rule.api.EnforcerRuleException e) { + // i can throw an exception + // because failfast will be + // false if fail is false. + if (failFast && (level == org.apache.maven.enforcer.rule.api.EnforcerLevel.ERROR)) { + throw new org.apache.maven.plugin.MojoExecutionException(((currentRule + " failed with message:") + java.lang.System.lineSeparator()) + e.getMessage(), e); + } else { + // log a warning in case the exception message is missing + // so that the user can figure out what is going on + final java.lang.String exceptionMessage = e.getMessage(); + if (exceptionMessage != null) { + log.debug(("Adding " + level) + " message due to exception", e); + } else { + log.warn(((("Rule " + i) + ": ") + currentRule) + " failed without a message", e); + } + // add the 'failed/warned' message including exceptionMessage + // which might be null in rare cases + if (level == org.apache.maven.enforcer.rule.api.EnforcerLevel.ERROR) { + hasErrors = true; + list.add(((((("Rule " + i) + ": ") + currentRule) + " failed with message:") + java.lang.System.lineSeparator()) + exceptionMessage); + } else { + list.add(((((("Rule " + i) + ": ") + currentRule) + " warned with message:") + java.lang.System.lineSeparator()) + exceptionMessage); + } + } + } + } + } + // if we found anything + // CHECKSTYLE_OFF: LineLength + if (!list.isEmpty()) { + for (java.lang.String failure : list) { + log.warn(failure); + } + if (fail && hasErrors) { + throw new org.apache.maven.plugin.MojoExecutionException("Some Enforcer rules have failed. Look above for specific messages explaining why the rule failed."); + } + } + // CHECKSTYLE_ON: LineLength +} + + private EnforcerRule[] createRulesFromCommandLineOptions() throws MojoExecutionException + { + EnforcerRule[] rules = new EnforcerRule[commandLineRules.length]; + for ( int i = 0; i < commandLineRules.length; i++ ) + { + String rule = commandLineRules[i]; + if ( !rule.contains( "." ) ) + { + rule = getClass().getPackage().getName() + + "." + Character.toUpperCase( rule.charAt( 0 ) ) + rule.substring( 1 ); + } + + try + { + rules[i] = ( EnforcerRule ) Class.forName( rule ).newInstance(); + } + catch ( Exception e ) + { + throw new MojoExecutionException( "Failed to create enforcer rules from command line argument", e ); + } + } + return rules; + } + + /** + * This method determines if a rule should execute based on the cache + * + * @param rule the rule to verify + * @return {@code true} if rule should be executed, otherwise {@code false} + */ + protected boolean shouldExecute( EnforcerRule rule ) + { + if ( rule.isCacheable() ) + { + Log log = this.getLog(); + log.debug( "Rule " + rule.getClass().getName() + " is cacheable." ); + String key = rule.getClass().getName() + " " + rule.getCacheId(); + if ( EnforceMojo.cache.containsKey( key ) ) + { + log.debug( "Key " + key + " was found in the cache" ); + if ( rule.isResultValid( cache.get( key ) ) ) + { + log.debug( "The cached results are still valid. Skipping the rule: " + rule.getClass().getName() ); + return false; + } + } + + // add it to the cache of executed rules + EnforceMojo.cache.put( key, rule ); + } + return true; + } + + /** + * @return the fail + */ + public boolean isFail() + { + return this.fail; + } + + /** + * @param theFail the fail to set + */ + public void setFail( boolean theFail ) + { + this.fail = theFail; + } + + /** + * @return the rules + */ + public EnforcerRule[] getRules() + { + return this.rules; + } + + /** + * @param theRules the rules to set + */ + public void setRules( EnforcerRule[] theRules ) + { + this.rules = theRules; + } + + /** + * @param theFailFast the failFast to set + */ + public void setFailFast( boolean theFailFast ) + { + this.failFast = theFailFast; + } + + public boolean isFailFast() + { + return failFast; + } + + protected String createRuleMessage( int i, String currentRule, EnforcerRuleException e ) + { + return "Rule " + i + ": " + currentRule + " failed with message:" + System.lineSeparator() + e.getMessage(); + } + + /** + * Returns the level of the rule, defaults to {@link EnforcerLevel#ERROR} for backwards compatibility. + * + * @param rule might be of type {@link EnforcerRule2}. + * @return level of the rule. + */ + private EnforcerLevel getLevel( EnforcerRule rule ) + { + if ( rule instanceof EnforcerRule2 ) + { + return ( (EnforcerRule2) rule ).getLevel(); + } + else + { + return EnforcerLevel.ERROR; + } + } + + /** + * @return the skip + */ + public boolean isSkip() + { + return this.skip; + } + + /** + * @param theSkip the skip to set + */ + public void setSkip( boolean theSkip ) + { + this.skip = theSkip; + } + + /** + * @return the project + */ + public MavenProject getProject() + { + return this.project; + } + + /** + * @param theProject the project to set + */ + public void setProject( MavenProject theProject ) + { + this.project = theProject; + } + + /** + * @return the session + */ + public MavenSession getSession() + { + return this.session; + } + + /** + * @param theSession the session to set + */ + public void setSession( MavenSession theSession ) + { + this.session = theSession; + } + +} diff --git a/Java/maven-enforcer-EnforceMojo_190/metadata.json b/Java/maven-enforcer-EnforceMojo_190/metadata.json new file mode 100644 index 000000000..fba1eb17b --- /dev/null +++ b/Java/maven-enforcer-EnforceMojo_190/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-enforcer-EnforceMojo_190", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn clean test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/EnforceMojo.java", + "line": 182, + "npe_method": "execute", + "deref_field": "rule", + "npe_class": "EnforceMojo", + "repo": "maven-enforcer", + "bug_id": "EnforceMojo_190" + } +} diff --git a/Java/maven-enforcer-EnforceMojo_190/npe.json b/Java/maven-enforcer-EnforceMojo_190/npe.json new file mode 100644 index 000000000..cacde614c --- /dev/null +++ b/Java/maven-enforcer-EnforceMojo_190/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/EnforceMojo.java", + "line": 182, + "npe_method": "execute", + "deref_field": "rule", + "npe_class": "EnforceMojo" +} \ No newline at end of file diff --git a/Java/maven-enforcer-MockProject_1369/Dockerfile b/Java/maven-enforcer-MockProject_1369/Dockerfile new file mode 100644 index 000000000..3581e6769 --- /dev/null +++ b/Java/maven-enforcer-MockProject_1369/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-enforcer + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-enforcer-MockProject_1369/buggy.java b/Java/maven-enforcer-MockProject_1369/buggy.java new file mode 100644 index 000000000..680eceb3e --- /dev/null +++ b/Java/maven-enforcer-MockProject_1369/buggy.java @@ -0,0 +1,1927 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.io.File; +import java.io.IOException; +import java.io.Writer; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.DependencyResolutionRequiredException; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.model.Build; +import org.apache.maven.model.CiManagement; +import org.apache.maven.model.Contributor; +import org.apache.maven.model.DependencyManagement; +import org.apache.maven.model.Developer; +import org.apache.maven.model.DistributionManagement; +import org.apache.maven.model.IssueManagement; +import org.apache.maven.model.License; +import org.apache.maven.model.MailingList; +import org.apache.maven.model.Model; +import org.apache.maven.model.Organization; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.PluginManagement; +import org.apache.maven.model.Prerequisites; +import org.apache.maven.model.Reporting; +import org.apache.maven.model.Resource; +import org.apache.maven.model.Scm; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.artifact.InvalidDependencyVersionException; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.util.xml.Xpp3Dom; + +/** + * very simple stub of maven project, going to take a lot of work to make it useful as a stub though. + */ +public class MockProject + extends MavenProject +{ + + /** The group id. */ + private String groupId; + + /** The artifact id. */ + private String artifactId; + + /** The name. */ + private String name; + + /** The model. */ + private Model model; + + /** The parent. */ + private MavenProject parent; + + /** The dependencies. */ + private List dependencies; + + /** The file. */ + private File file; + + /** The collected projects. */ + private List collectedProjects; + + /** The attached artifacts. */ + private List attachedArtifacts; + + /** The compile source roots. */ + private List compileSourceRoots; + + /** The test compile source roots. */ + private List testCompileSourceRoots; + + /** The script source roots. */ + private List scriptSourceRoots; + + /** The plugin artifact repositories. */ + private List pluginArtifactRepositories; + + /** The artifact repositories. */ + private List artifactRepositories; + + // private ArtifactRepository releaseArtifactRepository; + + // private ArtifactRepository snapshotArtifactRepository; + + /** The active profiles. */ + private List activeProfiles; + + /** The dependency artifacts. */ + private Set dependencyArtifacts; + + /** The dependency management. */ + private DependencyManagement dependencyManagement; + + /** The artifact. */ + private Artifact artifact; + + // private Map artifactMap; + + /** The original model. */ + private Model originalModel; + + // private Map pluginArtifactMap; + + // private Map reportArtifactMap; + + // private Map extensionArtifactMap; + + // private Map projectReferences; + + // private Build buildOverlay; + + /** The execution root. */ + private boolean executionRoot; + + /** The compile artifacts. */ + private List compileArtifacts; + + /** The compile dependencies. */ + private List compileDependencies; + + /** The system dependencies. */ + private List systemDependencies; + + /** The test classpath elements. */ + private List testClasspathElements; + + /** The test dependencies. */ + private List testDependencies; + + /** The system classpath elements. */ + private List systemClasspathElements; + + /** The system artifacts. */ + private List systemArtifacts; + + /** The test artifacts. */ + private List testArtifacts; + + /** The runtime artifacts. */ + private List runtimeArtifacts; + + /** The runtime dependencies. */ + private List runtimeDependencies; + + /** The runtime classpath elements. */ + private List runtimeClasspathElements; + + /** The model version. */ + private String modelVersion; + + /** The packaging. */ + private String packaging; + + /** The inception year. */ + private String inceptionYear; + + /** The url. */ + private String url; + + /** The description. */ + private String description; + + /** The version. */ + private String version; + + /** The default goal. */ + private String defaultGoal; + + /** The artifacts. */ + private Set artifacts; + + /** The properties. */ + private Properties properties = new Properties(); + + /** The base dir. */ + private File baseDir = null; + + /** + * Instantiates a new mock project. + */ + public MockProject() + { + super( (Model) null ); + } + + // kinda dangerous... + /** + * Instantiates a new mock project. + * + * @param model the model + */ + public MockProject( Model model ) + { + // super(model); + super( (Model) null ); + } + + // kinda dangerous... + /** + * Instantiates a new mock project. + * + * @param project the project + */ + public MockProject( MavenProject project ) + { + // super(project); + super( (Model) null ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getModulePathAdjustment(org.apache.maven.project.MavenProject) + */ + public String getModulePathAdjustment( MavenProject mavenProject ) + throws IOException + { + return ""; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getArtifact() + */ + public Artifact getArtifact() + { + return artifact; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setArtifact(org.apache.maven.artifact.Artifact) + */ + public void setArtifact( Artifact artifact ) + { + this.artifact = artifact; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getModel() + */ + public Model getModel() + { + return model; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getParent() + */ + public MavenProject getParent() + { + return parent; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setParent(org.apache.maven.project.MavenProject) + */ + public void setParent( MavenProject mavenProject ) + { + this.parent = mavenProject; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setRemoteArtifactRepositories(java.util.List) + */ + public void setRemoteArtifactRepositories( List list ) + { + this.artifactRepositories = list; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getRemoteArtifactRepositories() + */ + public List getRemoteArtifactRepositories() + { + return artifactRepositories; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#hasParent() + */ + public boolean hasParent() + { + if ( parent != null ) + { + return true; + } + else + { + return false; + } + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getFile() + */ + public File getFile() + { + return file; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setFile(java.io.File) + */ + public void setFile( File file ) + { + this.file = file; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getBasedir() + */ + public File getBasedir() + { + if ( baseDir == null ) + { + baseDir = new File( PlexusTestCase.getBasedir() ); + } + return baseDir; + } + + /** + * Sets the base dir. + * + * @param base the new base dir + */ + public void setBaseDir( File base ) + { + baseDir = base; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setDependencies(java.util.List) + */ + public void setDependencies( List list ) + { + dependencies = list; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getDependencies() + */ + public List getDependencies() + { + if ( dependencies == null ) + { + dependencies = Collections.EMPTY_LIST; + } + return dependencies; + } + + /** + * Sets the dependency management. + * + * @param depMgt the new dependency management + */ + public void setDependencyManagement( DependencyManagement depMgt ) + { + this.dependencyManagement = depMgt; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getDependencyManagement() + */ + public DependencyManagement getDependencyManagement() + { + if ( dependencyManagement == null ) + { + dependencyManagement = new DependencyManagement(); + } + + return dependencyManagement; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addCompileSourceRoot(java.lang.String) + */ + public void addCompileSourceRoot( String string ) + { + if ( compileSourceRoots == null ) + { + compileSourceRoots = Collections.singletonList( string ); + } + else + { + compileSourceRoots.add( string ); + } + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addScriptSourceRoot(java.lang.String) + */ + public void addScriptSourceRoot( String string ) + { + if ( scriptSourceRoots == null ) + { + scriptSourceRoots = Collections.singletonList( string ); + } + else + { + scriptSourceRoots.add( string ); + } + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addTestCompileSourceRoot(java.lang.String) + */ + public void addTestCompileSourceRoot( String string ) + { + if ( testCompileSourceRoots == null ) + { + testCompileSourceRoots = Collections.singletonList( string ); + } + else + { + testCompileSourceRoots.add( string ); + } + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getCompileSourceRoots() + */ + public List getCompileSourceRoots() + { + return compileSourceRoots; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getScriptSourceRoots() + */ + public List getScriptSourceRoots() + { + return scriptSourceRoots; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getTestCompileSourceRoots() + */ + public List getTestCompileSourceRoots() + { + return testCompileSourceRoots; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getCompileClasspathElements() + */ + public List getCompileClasspathElements() + throws DependencyResolutionRequiredException + { + return compileSourceRoots; + } + + /** + * Sets the compile artifacts. + * + * @param compileArtifacts the new compile artifacts + */ + public void setCompileArtifacts( List compileArtifacts ) + { + this.compileArtifacts = compileArtifacts; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getCompileArtifacts() + */ + public List getCompileArtifacts() + { + return compileArtifacts; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getCompileDependencies() + */ + public List getCompileDependencies() + { + return compileDependencies; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getTestClasspathElements() + */ + public List getTestClasspathElements() + throws DependencyResolutionRequiredException + { + return testClasspathElements; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getTestArtifacts() + */ + public List getTestArtifacts() + { + return testArtifacts; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getTestDependencies() + */ + public List getTestDependencies() + { + return testDependencies; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getRuntimeClasspathElements() + */ + public List getRuntimeClasspathElements() + throws DependencyResolutionRequiredException + { + return runtimeClasspathElements; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getRuntimeArtifacts() + */ + public List getRuntimeArtifacts() + { + return runtimeArtifacts; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getRuntimeDependencies() + */ + public List getRuntimeDependencies() + { + return runtimeDependencies; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getSystemClasspathElements() + */ + public List getSystemClasspathElements() + throws DependencyResolutionRequiredException + { + return systemClasspathElements; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getSystemArtifacts() + */ + public List getSystemArtifacts() + { + return systemArtifacts; + } + + /** + * Sets the runtime classpath elements. + * + * @param runtimeClasspathElements the new runtime classpath elements + */ + public void setRuntimeClasspathElements( List runtimeClasspathElements ) + { + this.runtimeClasspathElements = runtimeClasspathElements; + } + + /** + * Sets the attached artifacts. + * + * @param attachedArtifacts the new attached artifacts + */ + public void setAttachedArtifacts( List attachedArtifacts ) + { + this.attachedArtifacts = attachedArtifacts; + } + + /** + * Sets the compile source roots. + * + * @param compileSourceRoots the new compile source roots + */ + public void setCompileSourceRoots( List compileSourceRoots ) + { + this.compileSourceRoots = compileSourceRoots; + } + + /** + * Sets the test compile source roots. + * + * @param testCompileSourceRoots the new test compile source roots + */ + public void setTestCompileSourceRoots( List testCompileSourceRoots ) + { + this.testCompileSourceRoots = testCompileSourceRoots; + } + + /** + * Sets the script source roots. + * + * @param scriptSourceRoots the new script source roots + */ + public void setScriptSourceRoots( List scriptSourceRoots ) + { + this.scriptSourceRoots = scriptSourceRoots; + } + + /** + * Sets the artifact map. + * + * @param artifactMap the new artifact map + */ + public void setArtifactMap( Map artifactMap ) + { + // this.artifactMap = artifactMap; + } + + /** + * Sets the plugin artifact map. + * + * @param pluginArtifactMap the new plugin artifact map + */ + public void setPluginArtifactMap( Map pluginArtifactMap ) + { + // this.pluginArtifactMap = pluginArtifactMap; + } + + /** + * Sets the report artifact map. + * + * @param reportArtifactMap the new report artifact map + */ + public void setReportArtifactMap( Map reportArtifactMap ) + { + // this.reportArtifactMap = reportArtifactMap; + } + + /** + * Sets the extension artifact map. + * + * @param extensionArtifactMap the new extension artifact map + */ + public void setExtensionArtifactMap( Map extensionArtifactMap ) + { + // this.extensionArtifactMap = extensionArtifactMap; + } + + /** + * Sets the project references. + * + * @param projectReferences the new project references + */ + public void setProjectReferences( Map projectReferences ) + { + // this.projectReferences = projectReferences; + } + + /** + * Sets the builds the overlay. + * + * @param buildOverlay the new builds the overlay + */ + public void setBuildOverlay( Build buildOverlay ) + { + // this.buildOverlay = buildOverlay; + } + + /** + * Sets the compile dependencies. + * + * @param compileDependencies the new compile dependencies + */ + public void setCompileDependencies( List compileDependencies ) + { + this.compileDependencies = compileDependencies; + } + + /** + * Sets the system dependencies. + * + * @param systemDependencies the new system dependencies + */ + public void setSystemDependencies( List systemDependencies ) + { + this.systemDependencies = systemDependencies; + } + + /** + * Sets the test classpath elements. + * + * @param testClasspathElements the new test classpath elements + */ + public void setTestClasspathElements( List testClasspathElements ) + { + this.testClasspathElements = testClasspathElements; + } + + /** + * Sets the test dependencies. + * + * @param testDependencies the new test dependencies + */ + public void setTestDependencies( List testDependencies ) + { + this.testDependencies = testDependencies; + } + + /** + * Sets the system classpath elements. + * + * @param systemClasspathElements the new system classpath elements + */ + public void setSystemClasspathElements( List systemClasspathElements ) + { + this.systemClasspathElements = systemClasspathElements; + } + + /** + * Sets the system artifacts. + * + * @param systemArtifacts the new system artifacts + */ + public void setSystemArtifacts( List systemArtifacts ) + { + this.systemArtifacts = systemArtifacts; + } + + /** + * Sets the test artifacts. + * + * @param testArtifacts the new test artifacts + */ + public void setTestArtifacts( List testArtifacts ) + { + this.testArtifacts = testArtifacts; + } + + /** + * Sets the runtime artifacts. + * + * @param runtimeArtifacts the new runtime artifacts + */ + public void setRuntimeArtifacts( List runtimeArtifacts ) + { + this.runtimeArtifacts = runtimeArtifacts; + } + + /** + * Sets the runtime dependencies. + * + * @param runtimeDependencies the new runtime dependencies + */ + public void setRuntimeDependencies( List runtimeDependencies ) + { + this.runtimeDependencies = runtimeDependencies; + } + + /** + * Sets the model. + * + * @param model the new model + */ + public void setModel( Model model ) + { + this.model = model; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getSystemDependencies() + */ + public List getSystemDependencies() + { + return systemDependencies; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setModelVersion(java.lang.String) + */ + public void setModelVersion( String string ) + { + this.modelVersion = string; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getModelVersion() + */ + public String getModelVersion() + { + return modelVersion; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getId() + */ + public String getId() + { + return ""; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setGroupId(java.lang.String) + */ + public void setGroupId( String string ) + { + this.groupId = string; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getGroupId() + */ + public String getGroupId() + { + return groupId; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setArtifactId(java.lang.String) + */ + public void setArtifactId( String string ) + { + this.artifactId = string; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getArtifactId() + */ + public String getArtifactId() + { + return artifactId; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setName(java.lang.String) + */ + public void setName( String string ) + { + this.name = string; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getName() + */ + public String getName() + { + return name; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setVersion(java.lang.String) + */ + public void setVersion( String string ) + { + this.version = string; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getVersion() + */ + public String getVersion() + { + return version; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getPackaging() + */ + public String getPackaging() + { + return packaging; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setPackaging(java.lang.String) + */ + public void setPackaging( String string ) + { + this.packaging = string; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setInceptionYear(java.lang.String) + */ + public void setInceptionYear( String string ) + { + this.inceptionYear = string; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getInceptionYear() + */ + public String getInceptionYear() + { + return inceptionYear; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setUrl(java.lang.String) + */ + public void setUrl( String string ) + { + this.url = string; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getUrl() + */ + public String getUrl() + { + return url; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getPrerequisites() + */ + public Prerequisites getPrerequisites() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setIssueManagement(org.apache.maven.model.IssueManagement) + */ + public void setIssueManagement( IssueManagement issueManagement ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getCiManagement() + */ + public CiManagement getCiManagement() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setCiManagement(org.apache.maven.model.CiManagement) + */ + public void setCiManagement( CiManagement ciManagement ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getIssueManagement() + */ + public IssueManagement getIssueManagement() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setDistributionManagement(org.apache.maven.model.DistributionManagement) + */ + public void setDistributionManagement( DistributionManagement distributionManagement ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getDistributionManagement() + */ + public DistributionManagement getDistributionManagement() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setDescription(java.lang.String) + */ + public void setDescription( String string ) + { + this.description = string; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getDescription() + */ + public String getDescription() + { + return description; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setOrganization(org.apache.maven.model.Organization) + */ + public void setOrganization( Organization organization ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getOrganization() + */ + public Organization getOrganization() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setScm(org.apache.maven.model.Scm) + */ + public void setScm( Scm scm ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getScm() + */ + public Scm getScm() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setMailingLists(java.util.List) + */ + public void setMailingLists( List list ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getMailingLists() + */ + public List getMailingLists() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addMailingList(org.apache.maven.model.MailingList) + */ + public void addMailingList( MailingList mailingList ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setDevelopers(java.util.List) + */ + public void setDevelopers( List list ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getDevelopers() + */ + public List getDevelopers() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addDeveloper(org.apache.maven.model.Developer) + */ + public void addDeveloper( Developer developer ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setContributors(java.util.List) + */ + public void setContributors( List list ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getContributors() + */ + public List getContributors() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addContributor(org.apache.maven.model.Contributor) + */ + public void addContributor( Contributor contributor ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setBuild(org.apache.maven.model.Build) + */ + public void setBuild( Build build ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getBuild() + */ + public Build getBuild() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getResources() + */ + public List getResources() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getTestResources() + */ + public List getTestResources() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addResource(org.apache.maven.model.Resource) + */ + public void addResource( Resource resource ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addTestResource(org.apache.maven.model.Resource) + */ + public void addTestResource( Resource resource ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setReporting(org.apache.maven.model.Reporting) + */ + public void setReporting( Reporting reporting ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getReporting() + */ + public Reporting getReporting() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setLicenses(java.util.List) + */ + public void setLicenses( List list ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getLicenses() + */ + public List getLicenses() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addLicense(org.apache.maven.model.License) + */ + public void addLicense( License license ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setArtifacts(java.util.Set) + */ + public void setArtifacts( Set set ) + { + this.artifacts = set; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getArtifacts() + */ +/* (non-Javadoc) + +@see org.apache.maven.project.MavenProject#getArtifacts() + */ +public java.util.Set getArtifacts() { + { + return /* NPEX_NULL_EXP */ + artifacts; + } +} + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getArtifactMap() + */ + public Map getArtifactMap() + { + return Collections.singletonMap( "", "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setPluginArtifacts(java.util.Set) + */ + public void setPluginArtifacts( Set set ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getPluginArtifacts() + */ + public Set getPluginArtifacts() + { + return Collections.singleton( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getPluginArtifactMap() + */ + public Map getPluginArtifactMap() + { + return Collections.singletonMap( "", "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setReportArtifacts(java.util.Set) + */ + public void setReportArtifacts( Set set ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getReportArtifacts() + */ + public Set getReportArtifacts() + { + return Collections.singleton( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getReportArtifactMap() + */ + public Map getReportArtifactMap() + { + return Collections.singletonMap( "", "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setExtensionArtifacts(java.util.Set) + */ + public void setExtensionArtifacts( Set set ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getExtensionArtifacts() + */ + public Set getExtensionArtifacts() + { + return Collections.singleton( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getExtensionArtifactMap() + */ + public Map getExtensionArtifactMap() + { + return Collections.singletonMap( "", "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setParentArtifact(org.apache.maven.artifact.Artifact) + */ + public void setParentArtifact( Artifact artifact ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getParentArtifact() + */ + public Artifact getParentArtifact() + { + if (parent !=null) + { + return parent.getArtifact(); + } + else + return null; + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getRepositories() + */ + public List getRepositories() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getReportPlugins() + */ + public List getReportPlugins() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getBuildPlugins() + */ + public List getBuildPlugins() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getModules() + */ + public List getModules() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getPluginManagement() + */ + public PluginManagement getPluginManagement() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addPlugin(org.apache.maven.model.Plugin) + */ + public void addPlugin( Plugin plugin ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#injectPluginManagementInfo(org.apache.maven.model.Plugin) + */ + public void injectPluginManagementInfo( Plugin plugin ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getCollectedProjects() + */ + public List getCollectedProjects() + { + return collectedProjects; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setCollectedProjects(java.util.List) + */ + public void setCollectedProjects( List list ) + { + this.collectedProjects = list; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setPluginArtifactRepositories(java.util.List) + */ + public void setPluginArtifactRepositories( List list ) + { + this.pluginArtifactRepositories = list; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getPluginArtifactRepositories() + */ + public List getPluginArtifactRepositories() + { + return pluginArtifactRepositories; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getDistributionManagementArtifactRepository() + */ + public ArtifactRepository getDistributionManagementArtifactRepository() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getPluginRepositories() + */ + public List getPluginRepositories() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setActiveProfiles(java.util.List) + */ + public void setActiveProfiles( List list ) + { + activeProfiles = list; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getActiveProfiles() + */ + public List getActiveProfiles() + { + return activeProfiles; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addAttachedArtifact(org.apache.maven.artifact.Artifact) + */ + public void addAttachedArtifact( Artifact theArtifact ) + { + if ( attachedArtifacts == null ) + { + this.attachedArtifacts = Collections.singletonList( theArtifact ); + } + else + { + attachedArtifacts.add( theArtifact ); + } + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getAttachedArtifacts() + */ + public List getAttachedArtifacts() + { + return attachedArtifacts; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getGoalConfiguration(java.lang.String, java.lang.String, + * java.lang.String, java.lang.String) + */ + public Xpp3Dom getGoalConfiguration( String string, String string1, String string2, String string3 ) + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getReportConfiguration(java.lang.String, java.lang.String, + * java.lang.String) + */ + public Xpp3Dom getReportConfiguration( String string, String string1, String string2 ) + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getExecutionProject() + */ + public MavenProject getExecutionProject() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setExecutionProject(org.apache.maven.project.MavenProject) + */ + public void setExecutionProject( MavenProject mavenProject ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#writeModel(java.io.Writer) + */ + public void writeModel( Writer writer ) + throws IOException + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#writeOriginalModel(java.io.Writer) + */ + public void writeOriginalModel( Writer writer ) + throws IOException + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getDependencyArtifacts() + */ + public Set getDependencyArtifacts() + { + return dependencyArtifacts; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setDependencyArtifacts(java.util.Set) + */ + public void setDependencyArtifacts( Set set ) + { + this.dependencyArtifacts = set; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setReleaseArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) + */ + public void setReleaseArtifactRepository( ArtifactRepository artifactRepository ) + { + // this.releaseArtifactRepository = artifactRepository; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setSnapshotArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) + */ + public void setSnapshotArtifactRepository( ArtifactRepository artifactRepository ) + { + // this.snapshotArtifactRepository = artifactRepository; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setOriginalModel(org.apache.maven.model.Model) + */ + public void setOriginalModel( Model model ) + { + this.originalModel = model; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getOriginalModel() + */ + public Model getOriginalModel() + { + return originalModel; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getBuildExtensions() + */ + public List getBuildExtensions() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#createArtifacts(org.apache.maven.artifact.factory.ArtifactFactory, + * java.lang.String, org.apache.maven.artifact.resolver.filter.ArtifactFilter) + */ + public Set createArtifacts( ArtifactFactory artifactFactory, String string, ArtifactFilter artifactFilter ) + throws InvalidDependencyVersionException + { + return Collections.EMPTY_SET; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addProjectReference(org.apache.maven.project.MavenProject) + */ + public void addProjectReference( MavenProject mavenProject ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#attachArtifact(java.lang.String, java.lang.String, java.io.File) + */ + public void attachArtifact( String string, String string1, File theFile ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getProperties() + */ + public Properties getProperties() + { + return this.properties; + } + + /** + * Sets the property. + * + * @param key the key + * @param value the value + */ + public void setProperty( String key, String value ) + { + properties.setProperty( key, value ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getFilters() + */ + public List getFilters() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getProjectReferences() + */ + public Map getProjectReferences() + { + return Collections.singletonMap( "", "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#isExecutionRoot() + */ + public boolean isExecutionRoot() + { + return executionRoot; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setExecutionRoot(boolean) + */ + public void setExecutionRoot( boolean b ) + { + this.executionRoot = b; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getDefaultGoal() + */ + public String getDefaultGoal() + { + return defaultGoal; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#replaceWithActiveArtifact(org.apache.maven.artifact.Artifact) + */ + public Artifact replaceWithActiveArtifact( Artifact theArtifact ) + { + return null; + } +} diff --git a/Java/maven-enforcer-MockProject_1369/metadata.json b/Java/maven-enforcer-MockProject_1369/metadata.json new file mode 100644 index 000000000..895f1414c --- /dev/null +++ b/Java/maven-enforcer-MockProject_1369/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-enforcer-MockProject_1369", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn clean test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/MockProject.java", + "line": 1374, + "npe_method": "getArtifacts", + "deref_field": "artifacts", + "npe_class": "MockProject", + "repo": "maven-enforcer", + "bug_id": "MockProject_1369" + } +} diff --git a/Java/maven-enforcer-MockProject_1369/npe.json b/Java/maven-enforcer-MockProject_1369/npe.json new file mode 100644 index 000000000..f5373c0db --- /dev/null +++ b/Java/maven-enforcer-MockProject_1369/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/MockProject.java", + "line": 1374, + "npe_method": "getArtifacts", + "deref_field": "artifacts", + "npe_class": "MockProject" +} \ No newline at end of file diff --git a/Java/maven-enforcer-MockProject_1496/Dockerfile b/Java/maven-enforcer-MockProject_1496/Dockerfile new file mode 100644 index 000000000..3581e6769 --- /dev/null +++ b/Java/maven-enforcer-MockProject_1496/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-enforcer + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-enforcer-MockProject_1496/buggy.java b/Java/maven-enforcer-MockProject_1496/buggy.java new file mode 100644 index 000000000..6a7598454 --- /dev/null +++ b/Java/maven-enforcer-MockProject_1496/buggy.java @@ -0,0 +1,1928 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.io.File; +import java.io.IOException; +import java.io.Writer; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.DependencyResolutionRequiredException; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.model.Build; +import org.apache.maven.model.CiManagement; +import org.apache.maven.model.Contributor; +import org.apache.maven.model.DependencyManagement; +import org.apache.maven.model.Developer; +import org.apache.maven.model.DistributionManagement; +import org.apache.maven.model.IssueManagement; +import org.apache.maven.model.License; +import org.apache.maven.model.MailingList; +import org.apache.maven.model.Model; +import org.apache.maven.model.Organization; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.PluginManagement; +import org.apache.maven.model.Prerequisites; +import org.apache.maven.model.Reporting; +import org.apache.maven.model.Resource; +import org.apache.maven.model.Scm; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.artifact.InvalidDependencyVersionException; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.util.xml.Xpp3Dom; + +/** + * very simple stub of maven project, going to take a lot of work to make it useful as a stub though. + */ +public class MockProject + extends MavenProject +{ + + /** The group id. */ + private String groupId; + + /** The artifact id. */ + private String artifactId; + + /** The name. */ + private String name; + + /** The model. */ + private Model model; + + /** The parent. */ + private MavenProject parent; + + /** The dependencies. */ + private List dependencies; + + /** The file. */ + private File file; + + /** The collected projects. */ + private List collectedProjects; + + /** The attached artifacts. */ + private List attachedArtifacts; + + /** The compile source roots. */ + private List compileSourceRoots; + + /** The test compile source roots. */ + private List testCompileSourceRoots; + + /** The script source roots. */ + private List scriptSourceRoots; + + /** The plugin artifact repositories. */ + private List pluginArtifactRepositories; + + /** The artifact repositories. */ + private List artifactRepositories; + + // private ArtifactRepository releaseArtifactRepository; + + // private ArtifactRepository snapshotArtifactRepository; + + /** The active profiles. */ + private List activeProfiles; + + /** The dependency artifacts. */ + private Set dependencyArtifacts; + + /** The dependency management. */ + private DependencyManagement dependencyManagement; + + /** The artifact. */ + private Artifact artifact; + + // private Map artifactMap; + + /** The original model. */ + private Model originalModel; + + // private Map pluginArtifactMap; + + // private Map reportArtifactMap; + + // private Map extensionArtifactMap; + + // private Map projectReferences; + + // private Build buildOverlay; + + /** The execution root. */ + private boolean executionRoot; + + /** The compile artifacts. */ + private List compileArtifacts; + + /** The compile dependencies. */ + private List compileDependencies; + + /** The system dependencies. */ + private List systemDependencies; + + /** The test classpath elements. */ + private List testClasspathElements; + + /** The test dependencies. */ + private List testDependencies; + + /** The system classpath elements. */ + private List systemClasspathElements; + + /** The system artifacts. */ + private List systemArtifacts; + + /** The test artifacts. */ + private List testArtifacts; + + /** The runtime artifacts. */ + private List runtimeArtifacts; + + /** The runtime dependencies. */ + private List runtimeDependencies; + + /** The runtime classpath elements. */ + private List runtimeClasspathElements; + + /** The model version. */ + private String modelVersion; + + /** The packaging. */ + private String packaging; + + /** The inception year. */ + private String inceptionYear; + + /** The url. */ + private String url; + + /** The description. */ + private String description; + + /** The version. */ + private String version; + + /** The default goal. */ + private String defaultGoal; + + /** The artifacts. */ + private Set artifacts; + + /** The properties. */ + private Properties properties = new Properties(); + + /** The base dir. */ + private File baseDir = null; + + /** + * Instantiates a new mock project. + */ + public MockProject() + { + super( (Model) null ); + } + + // kinda dangerous... + /** + * Instantiates a new mock project. + * + * @param model the model + */ + public MockProject( Model model ) + { + // super(model); + super( (Model) null ); + } + + // kinda dangerous... + /** + * Instantiates a new mock project. + * + * @param project the project + */ + public MockProject( MavenProject project ) + { + // super(project); + super( (Model) null ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getModulePathAdjustment(org.apache.maven.project.MavenProject) + */ + public String getModulePathAdjustment( MavenProject mavenProject ) + throws IOException + { + return ""; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getArtifact() + */ + public Artifact getArtifact() + { + return artifact; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setArtifact(org.apache.maven.artifact.Artifact) + */ + public void setArtifact( Artifact artifact ) + { + this.artifact = artifact; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getModel() + */ + public Model getModel() + { + return model; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getParent() + */ + public MavenProject getParent() + { + return parent; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setParent(org.apache.maven.project.MavenProject) + */ + public void setParent( MavenProject mavenProject ) + { + this.parent = mavenProject; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setRemoteArtifactRepositories(java.util.List) + */ + public void setRemoteArtifactRepositories( List list ) + { + this.artifactRepositories = list; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getRemoteArtifactRepositories() + */ + public List getRemoteArtifactRepositories() + { + return artifactRepositories; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#hasParent() + */ + public boolean hasParent() + { + if ( parent != null ) + { + return true; + } + else + { + return false; + } + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getFile() + */ + public File getFile() + { + return file; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setFile(java.io.File) + */ + public void setFile( File file ) + { + this.file = file; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getBasedir() + */ + public File getBasedir() + { + if ( baseDir == null ) + { + baseDir = new File( PlexusTestCase.getBasedir() ); + } + return baseDir; + } + + /** + * Sets the base dir. + * + * @param base the new base dir + */ + public void setBaseDir( File base ) + { + baseDir = base; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setDependencies(java.util.List) + */ + public void setDependencies( List list ) + { + dependencies = list; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getDependencies() + */ + public List getDependencies() + { + if ( dependencies == null ) + { + dependencies = Collections.EMPTY_LIST; + } + return dependencies; + } + + /** + * Sets the dependency management. + * + * @param depMgt the new dependency management + */ + public void setDependencyManagement( DependencyManagement depMgt ) + { + this.dependencyManagement = depMgt; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getDependencyManagement() + */ + public DependencyManagement getDependencyManagement() + { + if ( dependencyManagement == null ) + { + dependencyManagement = new DependencyManagement(); + } + + return dependencyManagement; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addCompileSourceRoot(java.lang.String) + */ + public void addCompileSourceRoot( String string ) + { + if ( compileSourceRoots == null ) + { + compileSourceRoots = Collections.singletonList( string ); + } + else + { + compileSourceRoots.add( string ); + } + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addScriptSourceRoot(java.lang.String) + */ + public void addScriptSourceRoot( String string ) + { + if ( scriptSourceRoots == null ) + { + scriptSourceRoots = Collections.singletonList( string ); + } + else + { + scriptSourceRoots.add( string ); + } + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addTestCompileSourceRoot(java.lang.String) + */ + public void addTestCompileSourceRoot( String string ) + { + if ( testCompileSourceRoots == null ) + { + testCompileSourceRoots = Collections.singletonList( string ); + } + else + { + testCompileSourceRoots.add( string ); + } + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getCompileSourceRoots() + */ + public List getCompileSourceRoots() + { + return compileSourceRoots; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getScriptSourceRoots() + */ + public List getScriptSourceRoots() + { + return scriptSourceRoots; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getTestCompileSourceRoots() + */ + public List getTestCompileSourceRoots() + { + return testCompileSourceRoots; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getCompileClasspathElements() + */ + public List getCompileClasspathElements() + throws DependencyResolutionRequiredException + { + return compileSourceRoots; + } + + /** + * Sets the compile artifacts. + * + * @param compileArtifacts the new compile artifacts + */ + public void setCompileArtifacts( List compileArtifacts ) + { + this.compileArtifacts = compileArtifacts; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getCompileArtifacts() + */ + public List getCompileArtifacts() + { + return compileArtifacts; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getCompileDependencies() + */ + public List getCompileDependencies() + { + return compileDependencies; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getTestClasspathElements() + */ + public List getTestClasspathElements() + throws DependencyResolutionRequiredException + { + return testClasspathElements; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getTestArtifacts() + */ + public List getTestArtifacts() + { + return testArtifacts; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getTestDependencies() + */ + public List getTestDependencies() + { + return testDependencies; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getRuntimeClasspathElements() + */ + public List getRuntimeClasspathElements() + throws DependencyResolutionRequiredException + { + return runtimeClasspathElements; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getRuntimeArtifacts() + */ + public List getRuntimeArtifacts() + { + return runtimeArtifacts; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getRuntimeDependencies() + */ + public List getRuntimeDependencies() + { + return runtimeDependencies; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getSystemClasspathElements() + */ + public List getSystemClasspathElements() + throws DependencyResolutionRequiredException + { + return systemClasspathElements; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getSystemArtifacts() + */ + public List getSystemArtifacts() + { + return systemArtifacts; + } + + /** + * Sets the runtime classpath elements. + * + * @param runtimeClasspathElements the new runtime classpath elements + */ + public void setRuntimeClasspathElements( List runtimeClasspathElements ) + { + this.runtimeClasspathElements = runtimeClasspathElements; + } + + /** + * Sets the attached artifacts. + * + * @param attachedArtifacts the new attached artifacts + */ + public void setAttachedArtifacts( List attachedArtifacts ) + { + this.attachedArtifacts = attachedArtifacts; + } + + /** + * Sets the compile source roots. + * + * @param compileSourceRoots the new compile source roots + */ + public void setCompileSourceRoots( List compileSourceRoots ) + { + this.compileSourceRoots = compileSourceRoots; + } + + /** + * Sets the test compile source roots. + * + * @param testCompileSourceRoots the new test compile source roots + */ + public void setTestCompileSourceRoots( List testCompileSourceRoots ) + { + this.testCompileSourceRoots = testCompileSourceRoots; + } + + /** + * Sets the script source roots. + * + * @param scriptSourceRoots the new script source roots + */ + public void setScriptSourceRoots( List scriptSourceRoots ) + { + this.scriptSourceRoots = scriptSourceRoots; + } + + /** + * Sets the artifact map. + * + * @param artifactMap the new artifact map + */ + public void setArtifactMap( Map artifactMap ) + { + // this.artifactMap = artifactMap; + } + + /** + * Sets the plugin artifact map. + * + * @param pluginArtifactMap the new plugin artifact map + */ + public void setPluginArtifactMap( Map pluginArtifactMap ) + { + // this.pluginArtifactMap = pluginArtifactMap; + } + + /** + * Sets the report artifact map. + * + * @param reportArtifactMap the new report artifact map + */ + public void setReportArtifactMap( Map reportArtifactMap ) + { + // this.reportArtifactMap = reportArtifactMap; + } + + /** + * Sets the extension artifact map. + * + * @param extensionArtifactMap the new extension artifact map + */ + public void setExtensionArtifactMap( Map extensionArtifactMap ) + { + // this.extensionArtifactMap = extensionArtifactMap; + } + + /** + * Sets the project references. + * + * @param projectReferences the new project references + */ + public void setProjectReferences( Map projectReferences ) + { + // this.projectReferences = projectReferences; + } + + /** + * Sets the builds the overlay. + * + * @param buildOverlay the new builds the overlay + */ + public void setBuildOverlay( Build buildOverlay ) + { + // this.buildOverlay = buildOverlay; + } + + /** + * Sets the compile dependencies. + * + * @param compileDependencies the new compile dependencies + */ + public void setCompileDependencies( List compileDependencies ) + { + this.compileDependencies = compileDependencies; + } + + /** + * Sets the system dependencies. + * + * @param systemDependencies the new system dependencies + */ + public void setSystemDependencies( List systemDependencies ) + { + this.systemDependencies = systemDependencies; + } + + /** + * Sets the test classpath elements. + * + * @param testClasspathElements the new test classpath elements + */ + public void setTestClasspathElements( List testClasspathElements ) + { + this.testClasspathElements = testClasspathElements; + } + + /** + * Sets the test dependencies. + * + * @param testDependencies the new test dependencies + */ + public void setTestDependencies( List testDependencies ) + { + this.testDependencies = testDependencies; + } + + /** + * Sets the system classpath elements. + * + * @param systemClasspathElements the new system classpath elements + */ + public void setSystemClasspathElements( List systemClasspathElements ) + { + this.systemClasspathElements = systemClasspathElements; + } + + /** + * Sets the system artifacts. + * + * @param systemArtifacts the new system artifacts + */ + public void setSystemArtifacts( List systemArtifacts ) + { + this.systemArtifacts = systemArtifacts; + } + + /** + * Sets the test artifacts. + * + * @param testArtifacts the new test artifacts + */ + public void setTestArtifacts( List testArtifacts ) + { + this.testArtifacts = testArtifacts; + } + + /** + * Sets the runtime artifacts. + * + * @param runtimeArtifacts the new runtime artifacts + */ + public void setRuntimeArtifacts( List runtimeArtifacts ) + { + this.runtimeArtifacts = runtimeArtifacts; + } + + /** + * Sets the runtime dependencies. + * + * @param runtimeDependencies the new runtime dependencies + */ + public void setRuntimeDependencies( List runtimeDependencies ) + { + this.runtimeDependencies = runtimeDependencies; + } + + /** + * Sets the model. + * + * @param model the new model + */ + public void setModel( Model model ) + { + this.model = model; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getSystemDependencies() + */ + public List getSystemDependencies() + { + return systemDependencies; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setModelVersion(java.lang.String) + */ + public void setModelVersion( String string ) + { + this.modelVersion = string; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getModelVersion() + */ + public String getModelVersion() + { + return modelVersion; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getId() + */ + public String getId() + { + return ""; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setGroupId(java.lang.String) + */ + public void setGroupId( String string ) + { + this.groupId = string; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getGroupId() + */ + public String getGroupId() + { + return groupId; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setArtifactId(java.lang.String) + */ + public void setArtifactId( String string ) + { + this.artifactId = string; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getArtifactId() + */ + public String getArtifactId() + { + return artifactId; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setName(java.lang.String) + */ + public void setName( String string ) + { + this.name = string; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getName() + */ + public String getName() + { + return name; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setVersion(java.lang.String) + */ + public void setVersion( String string ) + { + this.version = string; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getVersion() + */ + public String getVersion() + { + return version; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getPackaging() + */ + public String getPackaging() + { + return packaging; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setPackaging(java.lang.String) + */ + public void setPackaging( String string ) + { + this.packaging = string; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setInceptionYear(java.lang.String) + */ + public void setInceptionYear( String string ) + { + this.inceptionYear = string; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getInceptionYear() + */ + public String getInceptionYear() + { + return inceptionYear; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setUrl(java.lang.String) + */ + public void setUrl( String string ) + { + this.url = string; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getUrl() + */ + public String getUrl() + { + return url; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getPrerequisites() + */ + public Prerequisites getPrerequisites() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setIssueManagement(org.apache.maven.model.IssueManagement) + */ + public void setIssueManagement( IssueManagement issueManagement ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getCiManagement() + */ + public CiManagement getCiManagement() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setCiManagement(org.apache.maven.model.CiManagement) + */ + public void setCiManagement( CiManagement ciManagement ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getIssueManagement() + */ + public IssueManagement getIssueManagement() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setDistributionManagement(org.apache.maven.model.DistributionManagement) + */ + public void setDistributionManagement( DistributionManagement distributionManagement ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getDistributionManagement() + */ + public DistributionManagement getDistributionManagement() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setDescription(java.lang.String) + */ + public void setDescription( String string ) + { + this.description = string; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getDescription() + */ + public String getDescription() + { + return description; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setOrganization(org.apache.maven.model.Organization) + */ + public void setOrganization( Organization organization ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getOrganization() + */ + public Organization getOrganization() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setScm(org.apache.maven.model.Scm) + */ + public void setScm( Scm scm ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getScm() + */ + public Scm getScm() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setMailingLists(java.util.List) + */ + public void setMailingLists( List list ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getMailingLists() + */ + public List getMailingLists() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addMailingList(org.apache.maven.model.MailingList) + */ + public void addMailingList( MailingList mailingList ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setDevelopers(java.util.List) + */ + public void setDevelopers( List list ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getDevelopers() + */ + public List getDevelopers() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addDeveloper(org.apache.maven.model.Developer) + */ + public void addDeveloper( Developer developer ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setContributors(java.util.List) + */ + public void setContributors( List list ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getContributors() + */ + public List getContributors() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addContributor(org.apache.maven.model.Contributor) + */ + public void addContributor( Contributor contributor ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setBuild(org.apache.maven.model.Build) + */ + public void setBuild( Build build ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getBuild() + */ + public Build getBuild() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getResources() + */ + public List getResources() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getTestResources() + */ + public List getTestResources() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addResource(org.apache.maven.model.Resource) + */ + public void addResource( Resource resource ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addTestResource(org.apache.maven.model.Resource) + */ + public void addTestResource( Resource resource ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setReporting(org.apache.maven.model.Reporting) + */ + public void setReporting( Reporting reporting ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getReporting() + */ + public Reporting getReporting() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setLicenses(java.util.List) + */ + public void setLicenses( List list ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getLicenses() + */ + public List getLicenses() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addLicense(org.apache.maven.model.License) + */ + public void addLicense( License license ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setArtifacts(java.util.Set) + */ + public void setArtifacts( Set set ) + { + this.artifacts = set; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getArtifacts() + */ + public Set getArtifacts() + { + if ( artifacts == null ) + { + return Collections.EMPTY_SET; + } + else + { + return artifacts; + } + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getArtifactMap() + */ + public Map getArtifactMap() + { + return Collections.singletonMap( "", "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setPluginArtifacts(java.util.Set) + */ + public void setPluginArtifacts( Set set ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getPluginArtifacts() + */ + public Set getPluginArtifacts() + { + return Collections.singleton( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getPluginArtifactMap() + */ + public Map getPluginArtifactMap() + { + return Collections.singletonMap( "", "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setReportArtifacts(java.util.Set) + */ + public void setReportArtifacts( Set set ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getReportArtifacts() + */ + public Set getReportArtifacts() + { + return Collections.singleton( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getReportArtifactMap() + */ + public Map getReportArtifactMap() + { + return Collections.singletonMap( "", "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setExtensionArtifacts(java.util.Set) + */ + public void setExtensionArtifacts( Set set ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getExtensionArtifacts() + */ + public Set getExtensionArtifacts() + { + return Collections.singleton( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getExtensionArtifactMap() + */ + public Map getExtensionArtifactMap() + { + return Collections.singletonMap( "", "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setParentArtifact(org.apache.maven.artifact.Artifact) + */ + public void setParentArtifact( Artifact artifact ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getParentArtifact() + */ +/* (non-Javadoc) + +@see org.apache.maven.project.MavenProject#getParentArtifact() + */ +public org.apache.maven.artifact.Artifact getParentArtifact() { + { + return /* NPEX_NULL_EXP */ + parent.getArtifact(); + } +} + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getRepositories() + */ + public List getRepositories() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getReportPlugins() + */ + public List getReportPlugins() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getBuildPlugins() + */ + public List getBuildPlugins() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getModules() + */ + public List getModules() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getPluginManagement() + */ + public PluginManagement getPluginManagement() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addPlugin(org.apache.maven.model.Plugin) + */ + public void addPlugin( Plugin plugin ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#injectPluginManagementInfo(org.apache.maven.model.Plugin) + */ + public void injectPluginManagementInfo( Plugin plugin ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getCollectedProjects() + */ + public List getCollectedProjects() + { + return collectedProjects; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setCollectedProjects(java.util.List) + */ + public void setCollectedProjects( List list ) + { + this.collectedProjects = list; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setPluginArtifactRepositories(java.util.List) + */ + public void setPluginArtifactRepositories( List list ) + { + this.pluginArtifactRepositories = list; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getPluginArtifactRepositories() + */ + public List getPluginArtifactRepositories() + { + return pluginArtifactRepositories; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getDistributionManagementArtifactRepository() + */ + public ArtifactRepository getDistributionManagementArtifactRepository() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getPluginRepositories() + */ + public List getPluginRepositories() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setActiveProfiles(java.util.List) + */ + public void setActiveProfiles( List list ) + { + activeProfiles = list; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getActiveProfiles() + */ + public List getActiveProfiles() + { + return activeProfiles; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addAttachedArtifact(org.apache.maven.artifact.Artifact) + */ + public void addAttachedArtifact( Artifact theArtifact ) + { + if ( attachedArtifacts == null ) + { + this.attachedArtifacts = Collections.singletonList( theArtifact ); + } + else + { + attachedArtifacts.add( theArtifact ); + } + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getAttachedArtifacts() + */ + public List getAttachedArtifacts() + { + return attachedArtifacts; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getGoalConfiguration(java.lang.String, java.lang.String, + * java.lang.String, java.lang.String) + */ + public Xpp3Dom getGoalConfiguration( String string, String string1, String string2, String string3 ) + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getReportConfiguration(java.lang.String, java.lang.String, + * java.lang.String) + */ + public Xpp3Dom getReportConfiguration( String string, String string1, String string2 ) + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getExecutionProject() + */ + public MavenProject getExecutionProject() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setExecutionProject(org.apache.maven.project.MavenProject) + */ + public void setExecutionProject( MavenProject mavenProject ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#writeModel(java.io.Writer) + */ + public void writeModel( Writer writer ) + throws IOException + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#writeOriginalModel(java.io.Writer) + */ + public void writeOriginalModel( Writer writer ) + throws IOException + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getDependencyArtifacts() + */ + public Set getDependencyArtifacts() + { + return dependencyArtifacts; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setDependencyArtifacts(java.util.Set) + */ + public void setDependencyArtifacts( Set set ) + { + this.dependencyArtifacts = set; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setReleaseArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) + */ + public void setReleaseArtifactRepository( ArtifactRepository artifactRepository ) + { + // this.releaseArtifactRepository = artifactRepository; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setSnapshotArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) + */ + public void setSnapshotArtifactRepository( ArtifactRepository artifactRepository ) + { + // this.snapshotArtifactRepository = artifactRepository; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setOriginalModel(org.apache.maven.model.Model) + */ + public void setOriginalModel( Model model ) + { + this.originalModel = model; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getOriginalModel() + */ + public Model getOriginalModel() + { + return originalModel; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getBuildExtensions() + */ + public List getBuildExtensions() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#createArtifacts(org.apache.maven.artifact.factory.ArtifactFactory, + * java.lang.String, org.apache.maven.artifact.resolver.filter.ArtifactFilter) + */ + public Set createArtifacts( ArtifactFactory artifactFactory, String string, ArtifactFilter artifactFilter ) + throws InvalidDependencyVersionException + { + return Collections.EMPTY_SET; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#addProjectReference(org.apache.maven.project.MavenProject) + */ + public void addProjectReference( MavenProject mavenProject ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#attachArtifact(java.lang.String, java.lang.String, java.io.File) + */ + public void attachArtifact( String string, String string1, File theFile ) + { + + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getProperties() + */ + public Properties getProperties() + { + return this.properties; + } + + /** + * Sets the property. + * + * @param key the key + * @param value the value + */ + public void setProperty( String key, String value ) + { + properties.setProperty( key, value ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getFilters() + */ + public List getFilters() + { + return Collections.singletonList( "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getProjectReferences() + */ + public Map getProjectReferences() + { + return Collections.singletonMap( "", "" ); + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#isExecutionRoot() + */ + public boolean isExecutionRoot() + { + return executionRoot; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#setExecutionRoot(boolean) + */ + public void setExecutionRoot( boolean b ) + { + this.executionRoot = b; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#getDefaultGoal() + */ + public String getDefaultGoal() + { + return defaultGoal; + } + + /* + * (non-Javadoc) + * + * @see org.apache.maven.project.MavenProject#replaceWithActiveArtifact(org.apache.maven.artifact.Artifact) + */ + public Artifact replaceWithActiveArtifact( Artifact theArtifact ) + { + return null; + } +} diff --git a/Java/maven-enforcer-MockProject_1496/metadata.json b/Java/maven-enforcer-MockProject_1496/metadata.json new file mode 100644 index 000000000..39c39dc43 --- /dev/null +++ b/Java/maven-enforcer-MockProject_1496/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-enforcer-MockProject_1496", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn clean test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/MockProject.java", + "line": 1501, + "npe_method": "getParentArtifact", + "deref_field": "parent", + "npe_class": "MockProject", + "repo": "maven-enforcer", + "bug_id": "MockProject_1496" + } +} diff --git a/Java/maven-enforcer-MockProject_1496/npe.json b/Java/maven-enforcer-MockProject_1496/npe.json new file mode 100644 index 000000000..3e15a0ad5 --- /dev/null +++ b/Java/maven-enforcer-MockProject_1496/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/MockProject.java", + "line": 1501, + "npe_method": "getParentArtifact", + "deref_field": "parent", + "npe_class": "MockProject" +} \ No newline at end of file diff --git a/Java/maven-enforcer-RequireFileChecksum_53/Dockerfile b/Java/maven-enforcer-RequireFileChecksum_53/Dockerfile new file mode 100644 index 000000000..3581e6769 --- /dev/null +++ b/Java/maven-enforcer-RequireFileChecksum_53/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-enforcer + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-enforcer-RequireFileChecksum_53/buggy.java b/Java/maven-enforcer-RequireFileChecksum_53/buggy.java new file mode 100644 index 000000000..b24e59fe6 --- /dev/null +++ b/Java/maven-enforcer-RequireFileChecksum_53/buggy.java @@ -0,0 +1,160 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +import org.apache.commons.codec.digest.DigestUtils; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; + +/** + * Rule to validate a file to match the specified checksum. + * + * @author Edward Samson + * @author Lyubomyr Shaydariv + */ +public class RequireFileChecksum + extends AbstractNonCacheableEnforcerRule +{ + + private File file; + + private String checksum; + + private String type; + + private String nonexistentFileMessage; + + @Override +public void execute(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper helper) throws org.apache.maven.enforcer.rule.api.EnforcerRuleException { + { + if (this.type == null) { + throw new org.apache.maven.enforcer.rule.api.EnforcerRuleException("Hash type unspecified"); + } + if (this.checksum == null) { + throw new org.apache.maven.enforcer.rule.api.EnforcerRuleException("Checksum unspecified"); + } + if (!/* NPEX_NULL_EXP */ + this.file.exists()) { + java.lang.String message = nonexistentFileMessage; + if (message == null) { + message = "File does not exist: " + this.file.getAbsolutePath(); + } + throw new org.apache.maven.enforcer.rule.api.EnforcerRuleException(message); + } + if (this.file.isDirectory()) { + throw new org.apache.maven.enforcer.rule.api.EnforcerRuleException("Cannot calculate the checksum of directory: " + this.file.getAbsolutePath()); + } + if (!this.file.canRead()) { + throw new org.apache.maven.enforcer.rule.api.EnforcerRuleException("Cannot read file: " + this.file.getAbsolutePath()); + } + java.lang.String checksum = calculateChecksum(); + if (!checksum.equalsIgnoreCase(this.checksum)) { + java.lang.String exceptionMessage = getMessage(); + if (exceptionMessage == null) { + exceptionMessage = (((((this.type + " hash of ") + this.file) + " was ") + checksum) + " but expected ") + this.checksum; + } + throw new org.apache.maven.enforcer.rule.api.EnforcerRuleException(exceptionMessage); + } + } +} + + /** + * The file to check. + * + * @param file file + */ + public void setFile( File file ) + { + this.file = file; + } + + /** + * The expected checksum value. + * + * @param checksum checksum + */ + public void setChecksum( String checksum ) + { + this.checksum = checksum; + } + + /** + * The checksum algorithm to use. Possible values: "md5", "sha1", "sha256", "sha384", "sha512". + * + * @param type algorithm + */ + public void setType( String type ) + { + this.type = type; + } + + /** + * The friendly message to use when the file does not exist. + * + * @param nonexistentFileMessage message + */ + public void setNonexistentFileMessage( String nonexistentFileMessage ) + { + this.nonexistentFileMessage = nonexistentFileMessage; + } + + private String calculateChecksum() + throws EnforcerRuleException + { + try ( InputStream inputStream = new FileInputStream( this.file ) ) + { + String checksum; + if ( "md5".equals( this.type ) ) + { + checksum = DigestUtils.md5Hex( inputStream ); + } + else if ( "sha1".equals( this.type ) ) + { + checksum = DigestUtils.shaHex( inputStream ); + } + else if ( "sha256".equals( this.type ) ) + { + checksum = DigestUtils.sha256Hex( inputStream ); + } + else if ( "sha384".equals( this.type ) ) + { + checksum = DigestUtils.sha384Hex( inputStream ); + } + else if ( "sha512".equals( this.type ) ) + { + checksum = DigestUtils.sha512Hex( inputStream ); + } + else + { + throw new EnforcerRuleException( "Unsupported hash type: " + this.type ); + } + return checksum; + } + catch ( IOException e ) + { + throw new EnforcerRuleException( "Unable to calculate checksum", e ); + } + } +} diff --git a/Java/maven-enforcer-RequireFileChecksum_53/metadata.json b/Java/maven-enforcer-RequireFileChecksum_53/metadata.json new file mode 100644 index 000000000..0eee61086 --- /dev/null +++ b/Java/maven-enforcer-RequireFileChecksum_53/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-enforcer-RequireFileChecksum_53", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn clean test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireFileChecksum.java", + "line": 59, + "npe_method": "execute", + "deref_field": "this.file", + "npe_class": "RequireFileChecksum", + "repo": "maven-enforcer", + "bug_id": "RequireFileChecksum_53" + } +} diff --git a/Java/maven-enforcer-RequireFileChecksum_53/npe.json b/Java/maven-enforcer-RequireFileChecksum_53/npe.json new file mode 100644 index 000000000..1e79b0172 --- /dev/null +++ b/Java/maven-enforcer-RequireFileChecksum_53/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireFileChecksum.java", + "line": 59, + "npe_method": "execute", + "deref_field": "this.file", + "npe_class": "RequireFileChecksum" +} \ No newline at end of file diff --git a/Java/maven-enforcer-RequireFileChecksum_58/Dockerfile b/Java/maven-enforcer-RequireFileChecksum_58/Dockerfile new file mode 100644 index 000000000..3581e6769 --- /dev/null +++ b/Java/maven-enforcer-RequireFileChecksum_58/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-enforcer + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-enforcer-RequireFileChecksum_58/buggy.java b/Java/maven-enforcer-RequireFileChecksum_58/buggy.java new file mode 100644 index 000000000..9ccee3cb2 --- /dev/null +++ b/Java/maven-enforcer-RequireFileChecksum_58/buggy.java @@ -0,0 +1,160 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +import org.apache.commons.codec.digest.DigestUtils; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; + +/** + * Rule to validate a file to match the specified checksum. + * + * @author Edward Samson + * @author Lyubomyr Shaydariv + */ +public class RequireFileChecksum + extends AbstractNonCacheableEnforcerRule +{ + + private File file; + + private String checksum; + + private String type; + + private String nonexistentFileMessage; + + @Override +public void execute(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper helper) throws org.apache.maven.enforcer.rule.api.EnforcerRuleException { + if (this.file == null) { + throw new org.apache.maven.enforcer.rule.api.EnforcerRuleException("Input file unspecified"); + } + { + if (this.checksum == null) { + throw new org.apache.maven.enforcer.rule.api.EnforcerRuleException("Checksum unspecified"); + } + if (!this.file.exists()) { + java.lang.String message = nonexistentFileMessage; + if (message == null) { + message = "File does not exist: " + this.file.getAbsolutePath(); + } + throw new org.apache.maven.enforcer.rule.api.EnforcerRuleException(message); + } + if (this.file.isDirectory()) { + throw new org.apache.maven.enforcer.rule.api.EnforcerRuleException("Cannot calculate the checksum of directory: " + this.file.getAbsolutePath()); + } + if (!this.file.canRead()) { + throw new org.apache.maven.enforcer.rule.api.EnforcerRuleException("Cannot read file: " + this.file.getAbsolutePath()); + } + java.lang.String checksum = calculateChecksum(); + if (!checksum.equalsIgnoreCase(this.checksum)) { + java.lang.String exceptionMessage = getMessage(); + if (exceptionMessage == null) { + exceptionMessage = (((((/* NPEX_NULL_EXP */ + this.type + " hash of ") + this.file) + " was ") + checksum) + " but expected ") + this.checksum; + } + throw new org.apache.maven.enforcer.rule.api.EnforcerRuleException(exceptionMessage); + } + } +} + + /** + * The file to check. + * + * @param file file + */ + public void setFile( File file ) + { + this.file = file; + } + + /** + * The expected checksum value. + * + * @param checksum checksum + */ + public void setChecksum( String checksum ) + { + this.checksum = checksum; + } + + /** + * The checksum algorithm to use. Possible values: "md5", "sha1", "sha256", "sha384", "sha512". + * + * @param type algorithm + */ + public void setType( String type ) + { + this.type = type; + } + + /** + * The friendly message to use when the file does not exist. + * + * @param nonexistentFileMessage message + */ + public void setNonexistentFileMessage( String nonexistentFileMessage ) + { + this.nonexistentFileMessage = nonexistentFileMessage; + } + + private String calculateChecksum() + throws EnforcerRuleException + { + try ( InputStream inputStream = new FileInputStream( this.file ) ) + { + String checksum; + if ( "md5".equals( this.type ) ) + { + checksum = DigestUtils.md5Hex( inputStream ); + } + else if ( "sha1".equals( this.type ) ) + { + checksum = DigestUtils.shaHex( inputStream ); + } + else if ( "sha256".equals( this.type ) ) + { + checksum = DigestUtils.sha256Hex( inputStream ); + } + else if ( "sha384".equals( this.type ) ) + { + checksum = DigestUtils.sha384Hex( inputStream ); + } + else if ( "sha512".equals( this.type ) ) + { + checksum = DigestUtils.sha512Hex( inputStream ); + } + else + { + throw new EnforcerRuleException( "Unsupported hash type: " + this.type ); + } + return checksum; + } + catch ( IOException e ) + { + throw new EnforcerRuleException( "Unable to calculate checksum", e ); + } + } +} diff --git a/Java/maven-enforcer-RequireFileChecksum_58/metadata.json b/Java/maven-enforcer-RequireFileChecksum_58/metadata.json new file mode 100644 index 000000000..b143db453 --- /dev/null +++ b/Java/maven-enforcer-RequireFileChecksum_58/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-enforcer-RequireFileChecksum_58", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn clean test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireFileChecksum.java", + "line": 76, + "npe_method": "execute", + "deref_field": "this.type", + "npe_class": "RequireFileChecksum", + "repo": "maven-enforcer", + "bug_id": "RequireFileChecksum_58" + } +} diff --git a/Java/maven-enforcer-RequireFileChecksum_58/npe.json b/Java/maven-enforcer-RequireFileChecksum_58/npe.json new file mode 100644 index 000000000..655800240 --- /dev/null +++ b/Java/maven-enforcer-RequireFileChecksum_58/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireFileChecksum.java", + "line": 76, + "npe_method": "execute", + "deref_field": "this.type", + "npe_class": "RequireFileChecksum" +} \ No newline at end of file diff --git a/Java/maven-enforcer-RequireFileChecksum_63/Dockerfile b/Java/maven-enforcer-RequireFileChecksum_63/Dockerfile new file mode 100644 index 000000000..3581e6769 --- /dev/null +++ b/Java/maven-enforcer-RequireFileChecksum_63/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-enforcer + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-enforcer-RequireFileChecksum_63/buggy.java b/Java/maven-enforcer-RequireFileChecksum_63/buggy.java new file mode 100644 index 000000000..9bf892127 --- /dev/null +++ b/Java/maven-enforcer-RequireFileChecksum_63/buggy.java @@ -0,0 +1,160 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +import org.apache.commons.codec.digest.DigestUtils; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; + +/** + * Rule to validate a file to match the specified checksum. + * + * @author Edward Samson + * @author Lyubomyr Shaydariv + */ +public class RequireFileChecksum + extends AbstractNonCacheableEnforcerRule +{ + + private File file; + + private String checksum; + + private String type; + + private String nonexistentFileMessage; + + @Override +public void execute(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper helper) throws org.apache.maven.enforcer.rule.api.EnforcerRuleException { + if (this.file == null) { + throw new org.apache.maven.enforcer.rule.api.EnforcerRuleException("Input file unspecified"); + } + if (this.type == null) { + throw new org.apache.maven.enforcer.rule.api.EnforcerRuleException("Hash type unspecified"); + } + { + if (!this.file.exists()) { + java.lang.String message = nonexistentFileMessage; + if (message == null) { + message = "File does not exist: " + this.file.getAbsolutePath(); + } + throw new org.apache.maven.enforcer.rule.api.EnforcerRuleException(message); + } + if (this.file.isDirectory()) { + throw new org.apache.maven.enforcer.rule.api.EnforcerRuleException("Cannot calculate the checksum of directory: " + this.file.getAbsolutePath()); + } + if (!this.file.canRead()) { + throw new org.apache.maven.enforcer.rule.api.EnforcerRuleException("Cannot read file: " + this.file.getAbsolutePath()); + } + java.lang.String checksum = calculateChecksum(); + if (!checksum.equalsIgnoreCase(/* NPEX_NULL_EXP */ + this.checksum)) { + java.lang.String exceptionMessage = getMessage(); + if (exceptionMessage == null) { + exceptionMessage = (((((this.type + " hash of ") + this.file) + " was ") + checksum) + " but expected ") + this.checksum; + } + throw new org.apache.maven.enforcer.rule.api.EnforcerRuleException(exceptionMessage); + } + } +} + + /** + * The file to check. + * + * @param file file + */ + public void setFile( File file ) + { + this.file = file; + } + + /** + * The expected checksum value. + * + * @param checksum checksum + */ + public void setChecksum( String checksum ) + { + this.checksum = checksum; + } + + /** + * The checksum algorithm to use. Possible values: "md5", "sha1", "sha256", "sha384", "sha512". + * + * @param type algorithm + */ + public void setType( String type ) + { + this.type = type; + } + + /** + * The friendly message to use when the file does not exist. + * + * @param nonexistentFileMessage message + */ + public void setNonexistentFileMessage( String nonexistentFileMessage ) + { + this.nonexistentFileMessage = nonexistentFileMessage; + } + + private String calculateChecksum() + throws EnforcerRuleException + { + try ( InputStream inputStream = new FileInputStream( this.file ) ) + { + String checksum; + if ( "md5".equals( this.type ) ) + { + checksum = DigestUtils.md5Hex( inputStream ); + } + else if ( "sha1".equals( this.type ) ) + { + checksum = DigestUtils.shaHex( inputStream ); + } + else if ( "sha256".equals( this.type ) ) + { + checksum = DigestUtils.sha256Hex( inputStream ); + } + else if ( "sha384".equals( this.type ) ) + { + checksum = DigestUtils.sha384Hex( inputStream ); + } + else if ( "sha512".equals( this.type ) ) + { + checksum = DigestUtils.sha512Hex( inputStream ); + } + else + { + throw new EnforcerRuleException( "Unsupported hash type: " + this.type ); + } + return checksum; + } + catch ( IOException e ) + { + throw new EnforcerRuleException( "Unable to calculate checksum", e ); + } + } +} diff --git a/Java/maven-enforcer-RequireFileChecksum_63/metadata.json b/Java/maven-enforcer-RequireFileChecksum_63/metadata.json new file mode 100644 index 000000000..435dce7ea --- /dev/null +++ b/Java/maven-enforcer-RequireFileChecksum_63/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-enforcer-RequireFileChecksum_63", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn clean test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireFileChecksum.java", + "line": 73, + "npe_method": "execute", + "deref_field": "this.checksum", + "npe_class": "RequireFileChecksum", + "repo": "maven-enforcer", + "bug_id": "RequireFileChecksum_63" + } +} diff --git a/Java/maven-enforcer-RequireFileChecksum_63/npe.json b/Java/maven-enforcer-RequireFileChecksum_63/npe.json new file mode 100644 index 000000000..06e31adb7 --- /dev/null +++ b/Java/maven-enforcer-RequireFileChecksum_63/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireFileChecksum.java", + "line": 73, + "npe_method": "execute", + "deref_field": "this.checksum", + "npe_class": "RequireFileChecksum" +} \ No newline at end of file diff --git a/Java/maven-enforcer-RequireFilesDontExist_34/Dockerfile b/Java/maven-enforcer-RequireFilesDontExist_34/Dockerfile new file mode 100644 index 000000000..3581e6769 --- /dev/null +++ b/Java/maven-enforcer-RequireFilesDontExist_34/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-enforcer + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-enforcer-RequireFilesDontExist_34/buggy.java b/Java/maven-enforcer-RequireFilesDontExist_34/buggy.java new file mode 100644 index 000000000..9b3e79260 --- /dev/null +++ b/Java/maven-enforcer-RequireFilesDontExist_34/buggy.java @@ -0,0 +1,43 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.io.File; + +/** + * The Class RequireFilesDontExist. + */ +public class RequireFilesDontExist + extends AbstractRequireFiles +{ + @Override +boolean checkFile(java.io.File file) { + // if we get here and the handle is null, treat it as a success + return !/* NPEX_NULL_EXP */ + file.exists(); +} + + @Override + String getErrorMsg() + { + return "Some files should not exist:" + System.lineSeparator(); + } + +} diff --git a/Java/maven-enforcer-RequireFilesDontExist_34/metadata.json b/Java/maven-enforcer-RequireFilesDontExist_34/metadata.json new file mode 100644 index 000000000..d04395d4a --- /dev/null +++ b/Java/maven-enforcer-RequireFilesDontExist_34/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-enforcer-RequireFilesDontExist_34", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn clean test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireFilesDontExist.java", + "line": 34, + "npe_method": "checkFile", + "deref_field": "file", + "npe_class": "RequireFilesDontExist", + "repo": "maven-enforcer", + "bug_id": "RequireFilesDontExist_34" + } +} diff --git a/Java/maven-enforcer-RequireFilesDontExist_34/npe.json b/Java/maven-enforcer-RequireFilesDontExist_34/npe.json new file mode 100644 index 000000000..076077950 --- /dev/null +++ b/Java/maven-enforcer-RequireFilesDontExist_34/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireFilesDontExist.java", + "line": 34, + "npe_method": "checkFile", + "deref_field": "file", + "npe_class": "RequireFilesDontExist" +} \ No newline at end of file diff --git a/Java/maven-enforcer-RequireFilesExist_34/Dockerfile b/Java/maven-enforcer-RequireFilesExist_34/Dockerfile new file mode 100644 index 000000000..3581e6769 --- /dev/null +++ b/Java/maven-enforcer-RequireFilesExist_34/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-enforcer + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-enforcer-RequireFilesExist_34/buggy.java b/Java/maven-enforcer-RequireFilesExist_34/buggy.java new file mode 100644 index 000000000..187972a68 --- /dev/null +++ b/Java/maven-enforcer-RequireFilesExist_34/buggy.java @@ -0,0 +1,43 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.io.File; + +/** + * The Class RequireFilesExist. + */ +public class RequireFilesExist + extends AbstractRequireFiles +{ + @Override +boolean checkFile(java.io.File file) { + // if we get here and the handle is null, treat it as a success + return /* NPEX_NULL_EXP */ + file.exists(); +} + + @Override + String getErrorMsg() + { + return "Some required files are missing:" + System.lineSeparator(); + } + +} diff --git a/Java/maven-enforcer-RequireFilesExist_34/metadata.json b/Java/maven-enforcer-RequireFilesExist_34/metadata.json new file mode 100644 index 000000000..53de3e9c5 --- /dev/null +++ b/Java/maven-enforcer-RequireFilesExist_34/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-enforcer-RequireFilesExist_34", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn clean test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireFilesExist.java", + "line": 34, + "npe_method": "checkFile", + "deref_field": "file", + "npe_class": "RequireFilesExist", + "repo": "maven-enforcer", + "bug_id": "RequireFilesExist_34" + } +} diff --git a/Java/maven-enforcer-RequireFilesExist_34/npe.json b/Java/maven-enforcer-RequireFilesExist_34/npe.json new file mode 100644 index 000000000..99099a18c --- /dev/null +++ b/Java/maven-enforcer-RequireFilesExist_34/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireFilesExist.java", + "line": 34, + "npe_method": "checkFile", + "deref_field": "file", + "npe_class": "RequireFilesExist" +} \ No newline at end of file diff --git a/Java/maven-enforcer-RequireFilesSize_99/Dockerfile b/Java/maven-enforcer-RequireFilesSize_99/Dockerfile new file mode 100644 index 000000000..3581e6769 --- /dev/null +++ b/Java/maven-enforcer-RequireFilesSize_99/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-enforcer + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-enforcer-RequireFilesSize_99/buggy.java b/Java/maven-enforcer-RequireFilesSize_99/buggy.java new file mode 100644 index 000000000..aa8badc35 --- /dev/null +++ b/Java/maven-enforcer-RequireFilesSize_99/buggy.java @@ -0,0 +1,145 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.io.File; + +import org.apache.maven.enforcer.rule.api.EnforcerRule; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; + +/** + * Rule to validate the main artifact is within certain size constraints. + * + * @author brianf + * @author Roman Stumm + */ +public class RequireFilesSize + extends AbstractRequireFiles +{ + + private static final long MAXSIZE = 10000; + + /** the max size allowed. */ + private long maxsize = MAXSIZE; + + /** the min size allowed. */ + private long minsize = 0; + + /** The error msg. */ + private String errorMsg; + + /** The log. */ + private Log log; + + @Override + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + this.log = helper.getLog(); + + // if the file is already defined, use that. Otherwise get the main artifact. + if ( getFiles().length == 0 ) + { + try + { + MavenProject project = (MavenProject) helper.evaluate( "${project}" ); + setFiles( new File[1] ); + getFiles()[0] = project.getArtifact().getFile(); + + super.execute( helper ); + } + catch ( ExpressionEvaluationException e ) + { + throw new EnforcerRuleException( "Unable to retrieve the project.", e ); + } + } + else + { + super.execute( helper ); + } + + } + + @Override + public boolean isCacheable() + { + return false; + } + + @Override + public boolean isResultValid( EnforcerRule cachedRule ) + { + return false; + } + + @Override +boolean checkFile(java.io.File file) { + { + // check the file now + if (/* NPEX_NULL_EXP */ + file.exists()) { + long length = file.length(); + if (length < minsize) { + this.errorMsg = (((file + " size (") + length) + ") too small. Min. is ") + minsize; + return false; + } else if (length > maxsize) { + this.errorMsg = (((file + " size (") + length) + ") too large. Max. is ") + maxsize; + return false; + } else { + this.log.debug(((((file + " size (") + length) + ") is OK (") + ((minsize == maxsize) || (minsize == 0) ? "max. " + maxsize : (("between " + minsize) + " and ") + maxsize)) + " byte)."); + return true; + } + } else { + this.errorMsg = file + " does not exist!"; + return false; + } + } +} + + @Override + String getErrorMsg() + { + return this.errorMsg; + } + + public long getMaxsize() + { + return maxsize; + } + + public void setMaxsize( long maxsize ) + { + this.maxsize = maxsize; + } + + public long getMinsize() + { + return minsize; + } + + public void setMinsize( long minsize ) + { + this.minsize = minsize; + } +} diff --git a/Java/maven-enforcer-RequireFilesSize_99/metadata.json b/Java/maven-enforcer-RequireFilesSize_99/metadata.json new file mode 100644 index 000000000..3cb5e19ec --- /dev/null +++ b/Java/maven-enforcer-RequireFilesSize_99/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-enforcer-RequireFilesSize_99", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn clean test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireFilesSize.java", + "line": 101, + "npe_method": "checkFile", + "deref_field": "file", + "npe_class": "RequireFilesSize", + "repo": "maven-enforcer", + "bug_id": "RequireFilesSize_99" + } +} diff --git a/Java/maven-enforcer-RequireFilesSize_99/npe.json b/Java/maven-enforcer-RequireFilesSize_99/npe.json new file mode 100644 index 000000000..097457bb5 --- /dev/null +++ b/Java/maven-enforcer-RequireFilesSize_99/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireFilesSize.java", + "line": 101, + "npe_method": "checkFile", + "deref_field": "file", + "npe_class": "RequireFilesSize" +} \ No newline at end of file diff --git a/Java/maven-enforcer-RequirePluginVersions_379/Dockerfile b/Java/maven-enforcer-RequirePluginVersions_379/Dockerfile new file mode 100644 index 000000000..3581e6769 --- /dev/null +++ b/Java/maven-enforcer-RequirePluginVersions_379/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-enforcer + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-enforcer-RequirePluginVersions_379/buggy.java b/Java/maven-enforcer-RequirePluginVersions_379/buggy.java new file mode 100644 index 000000000..af8cfa1cc --- /dev/null +++ b/Java/maven-enforcer-RequirePluginVersions_379/buggy.java @@ -0,0 +1,1275 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.maven.BuildFailureException; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.ArtifactNotFoundException; +import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.artifact.resolver.ArtifactResolver; +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.lifecycle.Lifecycle; +import org.apache.maven.lifecycle.LifecycleExecutionException; +import org.apache.maven.lifecycle.LifecycleExecutor; +import org.apache.maven.lifecycle.mapping.LifecycleMapping; +import org.apache.maven.model.BuildBase; +import org.apache.maven.model.Model; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.Profile; +import org.apache.maven.model.ReportPlugin; +import org.apache.maven.plugin.InvalidPluginException; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.PluginManager; +import org.apache.maven.plugin.PluginManagerException; +import org.apache.maven.plugin.PluginNotFoundException; +import org.apache.maven.plugin.descriptor.PluginDescriptor; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.plugin.version.PluginVersionNotFoundException; +import org.apache.maven.plugin.version.PluginVersionResolutionException; +import org.apache.maven.plugins.enforcer.utils.EnforcerRuleUtils; +import org.apache.maven.plugins.enforcer.utils.PluginWrapper; +import org.apache.maven.project.MavenProject; +import org.apache.maven.settings.Settings; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import org.codehaus.plexus.util.ReflectionUtils; +import org.codehaus.plexus.util.StringUtils; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +/** + * This rule will enforce that all plugins specified in the poms have a version declared. + * + * @author Brian Fox + */ +public class RequirePluginVersions + extends AbstractNonCacheableEnforcerRule +{ + + private EnforcerRuleHelper helper; + + /** + * Don't allow the LATEST identifier. + * + * @see {@link #setBanLatest(boolean)} + * @see {@link #isBanLatest()} + */ + private boolean banLatest = true; + + /** + * Don't allow the RELEASE identifier. + * + * @see {@link #setBanRelease(boolean)} + * @see {@link #isBanRelease()} + */ + private boolean banRelease = true; + + /** + * Don't allow snapshot plugins. + * + * @see {@link #setBanSnapshots(boolean)} + * @see {@link #isBanSnapshots()} + */ + private boolean banSnapshots = true; + + /** + * Don't allow timestamp snapshot plugins. + * + * @see {@link #setBanTimestamps(boolean)} + * @see {@link #isBanTimestamps()} + */ + private boolean banTimestamps = true; + + /** + * The comma separated list of phases that should be used to find lifecycle plugin bindings. The default value is + * "clean,deploy,site". + * + * @see {@link #setPhases(String)} + * @see {@link #getPhases()} + */ + private String phases = "clean,deploy,site"; + + /** + * Additional plugins to enforce have versions. These are plugins that may not be in the poms but are used anyway, + * like help, eclipse etc.
+ * The plugins should be specified in the form: group:artifactId. + * + * @see {@link #setAdditionalPlugins(List)} + * @see {@link #getAdditionalPlugins()} + */ + private List additionalPlugins; + + /** + * Plugins to skip for version enforcement. The plugins should be specified in the form: + * group:artifactId. NOTE: This is deprecated, use unCheckedPluginList instead. + * + * @see {@link #setUnCheckedPlugins(List)} + * @see {@link #getUnCheckedPlugins()} + */ + private List unCheckedPlugins; + + /** + * Same as unCheckedPlugins but as a comma list to better support properties. Sample form: + * group:artifactId,group2:artifactId2 + * + * @since 1.0-beta-1 + * @see {@link #setUnCheckedPlugins(List)} + * @see {@link #getUnCheckedPlugins()} + */ + private String unCheckedPluginList; + + /** The plugin manager. */ + private PluginManager pluginManager; + + /** The phase to lifecycle map. */ + private Map phaseToLifecycleMap; + + /** The lifecycles. */ + private Collection lifecycles; + + /** The factory. */ + private ArtifactFactory factory; + + /** The resolver. */ + private ArtifactResolver resolver; + + /** The local. */ + private ArtifactRepository local; + + /** The remote repositories. */ + private List remoteRepositories; + + /** The log. */ + private Log log; + + /** The session. */ + private MavenSession session; + + /** The utils. */ + private EnforcerRuleUtils utils; + + @Override + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + this.log = helper.getLog(); + this.helper = helper; + + MavenProject project; + try + { + // get the various expressions out of the helper. + + project = (MavenProject) helper.evaluate( "${project}" ); + LifecycleExecutor life; + life = helper.getComponent( LifecycleExecutor.class ); + + Object defaultLifeCycles = ReflectionUtils.getValueIncludingSuperclasses( "defaultLifeCycles", life ); + Map lifecyclesMap = (Map) ReflectionUtils.getValueIncludingSuperclasses( "lifecycles", defaultLifeCycles ); + lifecycles = lifecyclesMap.values(); + + session = (MavenSession) helper.evaluate( "${session}" ); + pluginManager = helper.getComponent( PluginManager.class ); + factory = helper.getComponent( ArtifactFactory.class ); + resolver = helper.getComponent( ArtifactResolver.class ); + local = (ArtifactRepository) helper.evaluate( "${localRepository}" ); + remoteRepositories = project.getRemoteArtifactRepositories(); + + utils = new EnforcerRuleUtils( helper ); + + // get all the plugins that are bound to the specified lifecycles + Set allPlugins = getBoundPlugins( life, project, phases ); + + // insert any additional plugins specified by the user. + allPlugins = addAdditionalPlugins( allPlugins, additionalPlugins ); + allPlugins.addAll( getProfilePlugins( project ) ); + + // pull out any we should skip + allPlugins = + removeUncheckedPlugins( combineUncheckedPlugins( unCheckedPlugins, unCheckedPluginList ), allPlugins ); + + // there's nothing to do here + if ( allPlugins.isEmpty() ) + { + log.info( "No plugin bindings found." ); + return; + } + else + { + log.debug( "All Plugins in use: " + allPlugins ); + } + + // get all the plugins that are mentioned in the pom (and parents) + List pluginWrappers = getAllPluginEntries( project ); + + for ( PluginWrapper pluginWrapper : pluginWrappers ) + { + log.debug( "pluginWrappers: " + pluginWrapper.getGroupId() + ":" + pluginWrapper.getArtifactId() + ":" + + pluginWrapper.getVersion() + " source:" + pluginWrapper.getSource() ); + } + // now look for the versions that aren't valid and add to a list. + List failures = new ArrayList(); + + for ( Plugin plugin : allPlugins ) + { + if ( !hasValidVersionSpecified( helper, plugin, pluginWrappers ) ) + { + failures.add( plugin ); + } + } + + // if anything was found, log it then append the optional message. + if ( !failures.isEmpty() ) + { + handleMessagesToTheUser( project, failures ); + } + } + catch ( ExpressionEvaluationException e ) + { + throw new EnforcerRuleException( "Unable to Evaluate an Expression:" + e.getLocalizedMessage() ); + } + catch ( ComponentLookupException e ) + { + throw new EnforcerRuleException( "Unable to lookup a component:" + e.getLocalizedMessage() ); + } + catch ( Exception e ) + { + throw new EnforcerRuleException( e.getLocalizedMessage() ); + } + } + + private void handleMessagesToTheUser( MavenProject project, List failures ) + throws EnforcerRuleException + { + StringBuilder newMsg = new StringBuilder(); + newMsg.append( "Some plugins are missing valid versions:" ); + handleBanMessages( newMsg ); + newMsg.append( "\n" ); + for ( Plugin plugin : failures ) + { + newMsg.append( plugin.getGroupId() ); + newMsg.append( ":" ); + newMsg.append( plugin.getArtifactId() ); + + try + { + newMsg.append( ". \tThe version currently in use is " ); + + Plugin currentPlugin = findCurrentPlugin( plugin, project ); + + if ( currentPlugin != null ) + { + newMsg.append( currentPlugin.getVersion() ); + } + else + { + newMsg.append( "unknown" ); + } + } + catch ( Exception e ) + { + // lots can go wrong here. Don't allow any issues trying to + // determine the issue stop me + log.debug( "Exception while determining plugin Version.", e ); + newMsg.append( ". Unable to determine the plugin version." ); + } + newMsg.append( "\n" ); + } + String message = getMessage(); + if ( StringUtils.isNotEmpty( message ) ) + { + newMsg.append( message ); + } + + throw new EnforcerRuleException( newMsg.toString() ); + } + + private void handleBanMessages( StringBuilder newMsg ) + { + if ( banLatest || banRelease || banSnapshots || banTimestamps ) + { + newMsg.append( " (" ); + if ( banLatest ) + { + newMsg.append( "LATEST " ); + } + if ( banRelease ) + { + newMsg.append( "RELEASE " ); + } + if ( banSnapshots || banTimestamps ) + { + newMsg.append( "SNAPSHOT " ); + } + newMsg.append( "are not allowed)" ); + } + } + + /** + * Remove the plugins that the user doesn't want to check. + * + * @param uncheckedPlugins + * @param plugins + * @throws MojoExecutionException + * @return The plugins which have been removed. + */ + public Set removeUncheckedPlugins( Collection uncheckedPlugins, Set plugins ) + throws MojoExecutionException + { + if ( uncheckedPlugins != null && !uncheckedPlugins.isEmpty() ) + { + for ( String pluginKey : uncheckedPlugins ) + { + Plugin plugin = parsePluginString( pluginKey, "UncheckedPlugins" ); + plugins.remove( plugin ); + } + } + return plugins; + } + + /** + * Combines the old Collection with the new comma separated list. + * + * @param uncheckedPlugins + * @param uncheckedPluginsList + * @return List of unchecked plugins. + */ + // CHECKSTYLE_OFF: LineLength +/** + * Combines the old Collection with the new comma separated list. + * + * @param uncheckedPlugins + * + * @param uncheckedPluginsList + * + * @return List of unchecked plugins. + */ +// CHECKSTYLE_OFF: LineLength +// CHECKSTYLE_ON: LineLength +public java.util.Collection combineUncheckedPlugins(java.util.Collection uncheckedPlugins, java.lang.String uncheckedPluginsList) { + // if the comma list is empty, then there's nothing to do here. + if (org.codehaus.plexus.util.StringUtils.isNotEmpty(uncheckedPluginsList)) { + { + if ((!/* NPEX_NULL_EXP */ + uncheckedPlugins.isEmpty()) && (log != null)) { + log.warn("The parameter 'unCheckedPlugins' is deprecated. Use 'unCheckedPluginList' instead"); + } + } + uncheckedPlugins.addAll(java.util.Arrays.asList(uncheckedPluginsList.split(","))); + } + return uncheckedPlugins; +} + + /** + * Add the additional plugins if they don't exist yet. + * + * @param existing the existing + * @param additional the additional + * @return the sets the + * @throws MojoExecutionException the mojo execution exception + */ + public Set addAdditionalPlugins( Set existing, List additional ) + throws MojoExecutionException + { + if ( additional != null ) + { + for ( String pluginString : additional ) + { + Plugin plugin = parsePluginString( pluginString, "AdditionalPlugins" ); + + if ( existing == null ) + { + existing = new HashSet<>(); + existing.add( plugin ); + } + else if ( !existing.contains( plugin ) ) + { + existing.add( plugin ); + } + } + } + return existing; + } + + /** + * Helper method to parse and inject a Plugin. + * + * @param pluginString + * @param field + * @throws MojoExecutionException + * @return the plugin + */ + protected Plugin parsePluginString( String pluginString, String field ) + throws MojoExecutionException + { + if ( pluginString != null ) + { + String[] pluginStrings = pluginString.split( ":" ); + if ( pluginStrings.length == 2 ) + { + Plugin plugin = new Plugin(); + plugin.setGroupId( StringUtils.strip( pluginStrings[0] ) ); + plugin.setArtifactId( StringUtils.strip( pluginStrings[1] ) ); + + return plugin; + } + else + { + throw new MojoExecutionException( "Invalid " + field + " string: " + pluginString ); + } + } + else + { + throw new MojoExecutionException( "Invalid " + field + " string: " + pluginString ); + } + + } + + /** + * Finds the plugins that are listed in active profiles. + * + * @param project the project + * @return the profile plugins + */ + public Set getProfilePlugins( MavenProject project ) + { + Set result = new HashSet<>(); + List profiles = project.getActiveProfiles(); + if ( profiles != null && !profiles.isEmpty() ) + { + for ( Profile p : profiles ) + { + BuildBase b = p.getBuild(); + if ( b != null ) + { + List plugins = b.getPlugins(); + if ( plugins != null ) + { + result.addAll( plugins ); + } + } + } + } + return result; + } + + /** + * Given a plugin, this will retrieve the matching plugin artifact from the model. + * + * @param plugin plugin to lookup + * @param project project to search + * @return matching plugin, null if not found. + */ + protected Plugin findCurrentPlugin( Plugin plugin, MavenProject project ) + { + Plugin found = null; + try + { + Model model = project.getModel(); + Map plugins = model.getBuild().getPluginsAsMap(); + found = plugins.get( plugin.getKey() ); + } + catch ( NullPointerException e ) + { + // nothing to do here + } + + if ( found == null ) + { + found = resolvePlugin( plugin, project ); + } + + return found; + } + + /** + * Resolve plugin. + * + * @param plugin the plugin + * @param project the project + * @return the plugin + */ + protected Plugin resolvePlugin( Plugin plugin, MavenProject project ) + { + + List pluginRepositories = project.getPluginArtifactRepositories(); + Artifact artifact = factory.createPluginArtifact( plugin.getGroupId(), plugin.getArtifactId(), + VersionRange.createFromVersion( "LATEST" ) ); + + try + { + this.resolver.resolve( artifact, pluginRepositories, this.local ); + plugin.setVersion( artifact.getVersion() ); + } + catch ( ArtifactResolutionException | ArtifactNotFoundException e ) + { + // What does this mean? + } + + return plugin; + } + + /** + * Gets the plugins that are bound to the defined phases. This does not find plugins bound in the pom to a phase + * later than the plugin is executing. + * + * @param life the life + * @param project the project + * @param thePhases the the phases + * @return the bound plugins + * @throws PluginNotFoundException the plugin not found exception + * @throws LifecycleExecutionException the lifecycle execution exception + * @throws IllegalAccessException the illegal access exception + */ + protected Set getBoundPlugins( LifecycleExecutor life, MavenProject project, String thePhases ) + throws PluginNotFoundException, LifecycleExecutionException, IllegalAccessException + { + + Set allPlugins = new HashSet<>(); + + // lookup the bindings for all the passed in phases + String[] lifecyclePhases = thePhases.split( "," ); + for ( int i = 0; i < lifecyclePhases.length; i++ ) + { + String lifecyclePhase = lifecyclePhases[i]; + if ( StringUtils.isNotEmpty( lifecyclePhase ) ) + { + try + { + Lifecycle lifecycle = getLifecycleForPhase( lifecyclePhase ); + log.debug( "getBoundPlugins(): " + project.getId() + " " + lifecyclePhase + " " + + lifecycle.getId() ); + allPlugins.addAll( getAllPlugins( project, lifecycle ) ); + } + catch ( BuildFailureException e ) + { + // i'm going to swallow this because the + // user may have declared a phase that + // doesn't exist for every module. + } + } + } + return allPlugins; + } + + /** + * Checks for valid version specified. Checks to see if the version is specified for the plugin. Can optionally ban + * "RELEASE" or "LATEST" even if specified. + * + * @param helper the helper + * @param source the source + * @param pluginWrappers the plugins + * @return true, if successful + */ + protected boolean hasValidVersionSpecified( EnforcerRuleHelper helper, Plugin source, + List pluginWrappers ) + { + boolean found = false; + boolean status = false; + for ( PluginWrapper plugin : pluginWrappers ) + { + // find the matching plugin entry + if ( isMatchingPlugin( source, plugin ) ) + { + found = true; + // found the entry. now see if the version is specified + String version = plugin.getVersion(); + try + { + version = (String) helper.evaluate( version ); + } + catch ( ExpressionEvaluationException e ) + { + return false; + } + + if ( isValidVersion( version ) ) + { + helper.getLog().debug( "checking for notEmpty and notIsWhitespace(): " + version ); + if ( banRelease && version.equals( "RELEASE" ) ) + { + return false; + } + + if ( banLatest && version.equals( "LATEST" ) ) + { + return false; + } + + if ( banSnapshots && isSnapshot( version ) ) + { + return false; + } + // the version was specified and not + // banned. It's ok. Keep looking through the list to make + // sure it's not using a banned version somewhere else. + + status = true; + + if ( !banRelease && !banLatest && !banSnapshots ) + { + // no need to keep looking + break; + } + } + } + } + if ( !found ) + { + helper.getLog().debug( "plugin " + source.getGroupId() + ":" + source.getArtifactId() + " not found" ); + } + return status; + } + + private boolean isValidVersion( String version ) + { + return StringUtils.isNotEmpty( version ) && !StringUtils.isWhitespace( version ); + } + + private boolean isMatchingPlugin( Plugin source, PluginWrapper plugin ) + { + return source.getArtifactId().equals( plugin.getArtifactId() ) + && source.getGroupId().equals( plugin.getGroupId() ); + } + + /** + * Checks if is snapshot. + * + * @param baseVersion the base version + * @return true, if is snapshot + */ + protected boolean isSnapshot( String baseVersion ) + { + if ( banTimestamps ) + { + return Artifact.VERSION_FILE_PATTERN.matcher( baseVersion ).matches() + || baseVersion.endsWith( Artifact.SNAPSHOT_VERSION ); + } + else + { + return baseVersion.endsWith( Artifact.SNAPSHOT_VERSION ); + } + } + + /* + * Uses borrowed lifecycle code to get a list of all plugins bound to the lifecycle. + */ + /** + * Gets the all plugins. + * + * @param project the project + * @param lifecycle the lifecycle + * @return the all plugins + * @throws PluginNotFoundException the plugin not found exception + * @throws LifecycleExecutionException the lifecycle execution exception + */ + private Set getAllPlugins( MavenProject project, Lifecycle lifecycle ) + throws PluginNotFoundException, LifecycleExecutionException + + { + log.debug( "RequirePluginVersions.getAllPlugins:" ); + + Set plugins = new HashSet<>(); + // first, bind those associated with the packaging + Map mappings = findMappingsForLifecycle( project, lifecycle ); + + for ( Map.Entry entry : mappings.entrySet() ) + { + log.debug( " lifecycleMapping = " + entry.getKey() ); + String pluginsForLifecycle = (String) entry.getValue(); + log.debug( " plugins = " + pluginsForLifecycle ); + if ( StringUtils.isNotEmpty( pluginsForLifecycle ) ) + { + String pluginList[] = pluginsForLifecycle.split( "," ); + for ( String plugin : pluginList ) + { + plugin = StringUtils.strip( plugin ); + log.debug( " plugin = " + plugin ); + String tokens[] = plugin.split( ":" ); + log.debug( " GAV = " + Arrays.asList( tokens ) ); + + Plugin p = new Plugin(); + p.setGroupId( tokens[0] ); + p.setArtifactId( tokens[1] ); + plugins.add( p ); + } + } + } + + List mojos = findOptionalMojosForLifecycle( project, lifecycle ); + for ( String value : mojos ) + { + String tokens[] = value.split( ":" ); + + Plugin plugin = new Plugin(); + plugin.setGroupId( tokens[0] ); + plugin.setArtifactId( tokens[1] ); + plugins.add( plugin ); + } + + plugins.addAll( project.getBuildPlugins() ); + + return plugins; + } + + /* + * NOTE: All the code following this point was scooped from the DefaultLifecycleExecutor. There must be a better way + * but for now it should work. + */ + /** + * Gets the phase to lifecycle map. + * + * @return the phase to lifecycle map + * @throws LifecycleExecutionException the lifecycle execution exception + */ + public Map getPhaseToLifecycleMap() + throws LifecycleExecutionException + { + if ( phaseToLifecycleMap == null ) + { + phaseToLifecycleMap = new HashMap<>(); + + for ( Lifecycle lifecycle : lifecycles ) + { + List phases = lifecycle.getPhases(); + for ( String phase : phases ) + { + log.debug( "getPhaseToLifecycleMap(): phase: " + phase ); + if ( phaseToLifecycleMap.containsKey( phase ) ) + { + Lifecycle prevLifecycle = (Lifecycle) phaseToLifecycleMap.get( phase ); + throw new LifecycleExecutionException( "Phase '" + phase + + "' is defined in more than one lifecycle: '" + lifecycle.getId() + "' and '" + + prevLifecycle.getId() + "'" ); + } + else + { + phaseToLifecycleMap.put( phase, lifecycle ); + } + } + } + } + return phaseToLifecycleMap; + } + + /** + * Gets the lifecycle for phase. + * + * @param phase the phase + * @return the lifecycle for phase + * @throws BuildFailureException the build failure exception + * @throws LifecycleExecutionException the lifecycle execution exception + */ + private Lifecycle getLifecycleForPhase( String phase ) + throws BuildFailureException, LifecycleExecutionException + { + Lifecycle lifecycle = getPhaseToLifecycleMap().get( phase ); + + if ( lifecycle == null ) + { + throw new BuildFailureException( "Unable to find lifecycle for phase '" + phase + "'" ); + } + return lifecycle; + } + + /** + * Find mappings for lifecycle. + * + * @param project the project + * @param lifecycle the lifecycle + * @return the map + * @throws LifecycleExecutionException the lifecycle execution exception + * @throws PluginNotFoundException the plugin not found exception + */ + private Map findMappingsForLifecycle( MavenProject project, Lifecycle lifecycle ) + throws LifecycleExecutionException, PluginNotFoundException + { + String packaging = project.getPackaging(); + Map mappings = null; + + LifecycleMapping m = (LifecycleMapping) findExtension( project, LifecycleMapping.ROLE, packaging, + session.getSettings(), session.getLocalRepository() ); + if ( m != null ) + { + mappings = m.getPhases( lifecycle.getId() ); + } + + Map defaultMappings = lifecycle.getDefaultPhases(); + + if ( mappings == null ) + { + try + { + m = helper.getComponent( LifecycleMapping.class, packaging ); + mappings = m.getPhases( lifecycle.getId() ); + } + catch ( ComponentLookupException e ) + { + if ( defaultMappings == null ) + { + throw new LifecycleExecutionException( "Cannot find lifecycle mapping for packaging: \'" + packaging + + "\'.", e ); + } + } + } + + if ( mappings == null ) + { + if ( defaultMappings == null ) + { + throw new LifecycleExecutionException( "Cannot find lifecycle mapping for packaging: \'" + packaging + + "\', and there is no default" ); + } + else + { + mappings = defaultMappings; + } + } + + return mappings; + } + + /** + * Find optional mojos for lifecycle. + * + * @param project the project + * @param lifecycle the lifecycle + * @return the list + * @throws LifecycleExecutionException the lifecycle execution exception + * @throws PluginNotFoundException the plugin not found exception + */ + private List findOptionalMojosForLifecycle( MavenProject project, Lifecycle lifecycle ) + throws LifecycleExecutionException, PluginNotFoundException + { + String packaging = project.getPackaging(); + List optionalMojos = null; + + LifecycleMapping m = (LifecycleMapping) findExtension( project, LifecycleMapping.ROLE, packaging, + session.getSettings(), session.getLocalRepository() ); + + if ( m != null ) + { + optionalMojos = m.getOptionalMojos( lifecycle.getId() ); + } + + if ( optionalMojos == null ) + { + try + { + m = helper.getComponent( LifecycleMapping.class, packaging ); + optionalMojos = m.getOptionalMojos( lifecycle.getId() ); + } + catch ( ComponentLookupException e ) + { + log.debug( "Error looking up lifecycle mapping to retrieve optional mojos. Lifecycle ID: " + + lifecycle.getId() + ". Error: " + e.getMessage(), e ); + } + } + + if ( optionalMojos == null ) + { + optionalMojos = Collections.emptyList(); + } + + return optionalMojos; + } + + /** + * Find extension. + * + * @param project the project + * @param role the role + * @param roleHint the role hint + * @param settings the settings + * @param localRepository the local repository + * @return the object + * @throws LifecycleExecutionException the lifecycle execution exception + * @throws PluginNotFoundException the plugin not found exception + */ + private Object findExtension( MavenProject project, String role, String roleHint, Settings settings, + ArtifactRepository localRepository ) + throws LifecycleExecutionException, PluginNotFoundException + { + Object pluginComponent = null; + + List buildPlugins = project.getBuildPlugins(); + for ( Plugin plugin : buildPlugins ) + { + if ( plugin.isExtensions() ) + { + verifyPlugin( plugin, project, settings, localRepository ); + + // TODO: if moved to the plugin manager we + // already have the descriptor from above + // and so do can lookup the container + // directly + try + { + pluginComponent = pluginManager.getPluginComponent( plugin, role, roleHint ); + + if ( pluginComponent != null ) + { + break; + } + } + catch ( ComponentLookupException e ) + { + log.debug( "Unable to find the lifecycle component in the extension", e ); + } + catch ( PluginManagerException e ) + { + throw new LifecycleExecutionException( "Error getting extensions from the plugin '" + + plugin.getKey() + "': " + e.getMessage(), e ); + } + } + } + return pluginComponent; + } + + /** + * Verify plugin. + * + * @param plugin the plugin + * @param project the project + * @param settings the settings + * @param localRepository the local repository + * @return the plugin descriptor + * @throws LifecycleExecutionException the lifecycle execution exception + * @throws PluginNotFoundException the plugin not found exception + */ + private PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings, + ArtifactRepository localRepository ) + throws LifecycleExecutionException, PluginNotFoundException + { + PluginDescriptor pluginDescriptor; + try + { + pluginDescriptor = pluginManager.verifyPlugin( plugin, project, settings, localRepository ); + } + catch ( PluginManagerException e ) + { + throw new LifecycleExecutionException( "Internal error in the plugin manager getting plugin '" + + plugin.getKey() + "': " + e.getMessage(), e ); + } + catch ( PluginVersionResolutionException | InvalidVersionSpecificationException | InvalidPluginException + | ArtifactNotFoundException | ArtifactResolutionException | PluginVersionNotFoundException e ) + { + throw new LifecycleExecutionException( e.getMessage(), e ); + } + return pluginDescriptor; + } + + /** + * Gets all plugin entries in build.plugins, build.pluginManagement.plugins, profile.build.plugins, reporting and + * profile.reporting in this project and all parents + * + * @param project the project + * @return the all plugin entries wrapped in a PluginWrapper Object + * @throws ArtifactResolutionException the artifact resolution exception + * @throws ArtifactNotFoundException the artifact not found exception + * @throws IOException Signals that an I/O exception has occurred. + * @throws XmlPullParserException the xml pull parser exception + */ + protected List getAllPluginEntries( MavenProject project ) + throws ArtifactResolutionException, ArtifactNotFoundException, IOException, XmlPullParserException + { + List models = new ArrayList<>(); + + List sortedProjects = session.getProjectDependencyGraph().getSortedProjects(); + + if ( !sortedProjects.isEmpty() && sortedProjects.get( 0 ).getParent() != null ) + { + getOriginalModelFromAllParents( models, sortedProjects ); + } + + for ( MavenProject mavenProject : sortedProjects ) + { + models.add( mavenProject.getOriginalModel() ); + } + + List plugins = new ArrayList<>(); + // now find all the plugin entries, either in + // build.plugins or build.pluginManagement.plugins, profiles.plugins and reporting + for ( Model model : models ) + { + getPlugins( plugins, model ); + getReportingPlugins( plugins, model ); + getPluginManagementPlugins( plugins, model ); + + addPluginsInProfiles( plugins, model ); + } + + return plugins; + } + + private void getOriginalModelFromAllParents( List models, List sortedProjects ) + { + MavenProject parent = sortedProjects.get( 0 ).getParent(); + do + { + models.add( parent.getOriginalModel() ); + parent = parent.getParent(); + } + while ( parent != null ); + } + + private void addPluginsInProfiles( List plugins, Model model ) + { + List profiles = model.getProfiles(); + for ( Profile profile : profiles ) + { + getProfilePlugins( plugins, model, profile ); + getProfileReportingPlugins( plugins, model, profile ); + getProfilePluginManagementPlugins( plugins, model, profile ); + } + } + + private void getProfilePluginManagementPlugins( List plugins, Model model, Profile profile ) + { + try + { + List modelPlugins = profile.getBuild().getPluginManagement().getPlugins(); + plugins.addAll( PluginWrapper.addAll( utils.resolvePlugins( modelPlugins ), model.getId() + "profile[" + + profile.getId() + "].build.pluginManagement.plugins" ) ); + } + catch ( NullPointerException e ) + { + // guess there are no plugins here. + } + } + + private void getProfileReportingPlugins( List plugins, Model model, Profile profile ) + { + try + { + List modelReportPlugins = profile.getReporting().getPlugins(); + // add the reporting plugins + plugins.addAll( PluginWrapper.addAll( utils.resolveReportPlugins( modelReportPlugins ), model.getId() + + "profile[" + profile.getId() + "].reporting.plugins" ) ); + } + catch ( NullPointerException e ) + { + // guess there are no plugins here. + } + } + + private void getProfilePlugins( List plugins, Model model, Profile profile ) + { + try + { + List modelPlugins = profile.getBuild().getPlugins(); + plugins.addAll( PluginWrapper.addAll( utils.resolvePlugins( modelPlugins ), model.getId() + + ".profiles.profile[" + profile.getId() + "].build.plugins" ) ); + } + catch ( NullPointerException e ) + { + // guess there are no plugins here. + } + } + + private void getPlugins( List plugins, Model model ) + { + try + { + List modelPlugins = model.getBuild().getPlugins(); + plugins.addAll( PluginWrapper.addAll( utils.resolvePlugins( modelPlugins ), + model.getId() + ".build.plugins" ) ); + } + catch ( NullPointerException e ) + { + // guess there are no plugins here. + } + } + + private void getPluginManagementPlugins( List plugins, Model model ) + { + try + { + List modelPlugins = model.getBuild().getPluginManagement().getPlugins(); + plugins.addAll( PluginWrapper.addAll( utils.resolvePlugins( modelPlugins ), + model.getId() + ".build.pluginManagement.plugins" ) ); + } + catch ( NullPointerException e ) + { + // guess there are no plugins here. + } + } + + private void getReportingPlugins( List plugins, Model model ) + { + try + { + List modelReportPlugins = model.getReporting().getPlugins(); + // add the reporting plugins + plugins.addAll( PluginWrapper.addAll( utils.resolveReportPlugins( modelReportPlugins ), + model.getId() + ".reporting" ) ); + } + catch ( NullPointerException e ) + { + // guess there are no plugins here. + } + } + + /** + * Checks if is ban latest. + * + * @return the banLatest + */ + protected boolean isBanLatest() + { + return this.banLatest; + } + + /** + * Sets the ban latest. + * + * @param theBanLatest the banLatest to set + */ + protected void setBanLatest( boolean theBanLatest ) + { + this.banLatest = theBanLatest; + } + + /** + * Checks if is ban release. + * + * @return the banRelease + */ + protected boolean isBanRelease() + { + return this.banRelease; + } + + /** + * Sets the ban release. + * + * @param theBanRelease the banRelease to set + */ + protected void setBanRelease( boolean theBanRelease ) + { + this.banRelease = theBanRelease; + } + + /** + * Gets the utils. + * + * @return the utils + */ + protected EnforcerRuleUtils getUtils() + { + return this.utils; + } + + /** + * Sets the utils. + * + * @param theUtils the utils to set + */ + protected void setUtils( EnforcerRuleUtils theUtils ) + { + this.utils = theUtils; + } + + /** + * Checks if is ban snapshots. + * + * @return the banSnapshots + */ + public boolean isBanSnapshots() + { + return this.banSnapshots; + } + + /** + * Sets the ban snapshots. + * + * @param theBanSnapshots the banSnapshots to set + */ + public void setBanSnapshots( boolean theBanSnapshots ) + { + this.banSnapshots = theBanSnapshots; + } + + /** + * Checks if is ban timestamps. + * + * @return the banTimestamps + */ + public boolean isBanTimestamps() + { + return this.banTimestamps; + } + + /** + * Sets the ban timestamps. + * + * @param theBanTimestamps the banTimestamps to set + */ + public void setBanTimestamps( boolean theBanTimestamps ) + { + this.banTimestamps = theBanTimestamps; + } + + public List getUnCheckedPlugins() + { + return unCheckedPlugins; + } + + public void setUnCheckedPlugins( List unCheckedPlugins ) + { + this.unCheckedPlugins = unCheckedPlugins; + } + + public final void setPhases( String phases ) + { + this.phases = phases; + } + + public final String getPhases() + { + return phases; + } + + public final void setAdditionalPlugins( List additionalPlugins ) + { + this.additionalPlugins = additionalPlugins; + } + + public final List getAdditionalPlugins() + { + return additionalPlugins; + } +} diff --git a/Java/maven-enforcer-RequirePluginVersions_379/metadata.json b/Java/maven-enforcer-RequirePluginVersions_379/metadata.json new file mode 100644 index 000000000..28dacc94a --- /dev/null +++ b/Java/maven-enforcer-RequirePluginVersions_379/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-enforcer-RequirePluginVersions_379", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn clean test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java", + "line": 387, + "npe_method": "combineUncheckedPlugins", + "deref_field": "uncheckedPlugins", + "npe_class": "RequirePluginVersions", + "repo": "maven-enforcer", + "bug_id": "RequirePluginVersions_379" + } +} diff --git a/Java/maven-enforcer-RequirePluginVersions_379/npe.json b/Java/maven-enforcer-RequirePluginVersions_379/npe.json new file mode 100644 index 000000000..e39a54720 --- /dev/null +++ b/Java/maven-enforcer-RequirePluginVersions_379/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java", + "line": 387, + "npe_method": "combineUncheckedPlugins", + "deref_field": "uncheckedPlugins", + "npe_class": "RequirePluginVersions" +} \ No newline at end of file diff --git a/Java/maven-enforcer-RequirePluginVersions_404/Dockerfile b/Java/maven-enforcer-RequirePluginVersions_404/Dockerfile new file mode 100644 index 000000000..3581e6769 --- /dev/null +++ b/Java/maven-enforcer-RequirePluginVersions_404/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-enforcer + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-enforcer-RequirePluginVersions_404/buggy.java b/Java/maven-enforcer-RequirePluginVersions_404/buggy.java new file mode 100644 index 000000000..ae1ea3c18 --- /dev/null +++ b/Java/maven-enforcer-RequirePluginVersions_404/buggy.java @@ -0,0 +1,1276 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.maven.BuildFailureException; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.ArtifactNotFoundException; +import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.artifact.resolver.ArtifactResolver; +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.lifecycle.Lifecycle; +import org.apache.maven.lifecycle.LifecycleExecutionException; +import org.apache.maven.lifecycle.LifecycleExecutor; +import org.apache.maven.lifecycle.mapping.LifecycleMapping; +import org.apache.maven.model.BuildBase; +import org.apache.maven.model.Model; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.Profile; +import org.apache.maven.model.ReportPlugin; +import org.apache.maven.plugin.InvalidPluginException; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.PluginManager; +import org.apache.maven.plugin.PluginManagerException; +import org.apache.maven.plugin.PluginNotFoundException; +import org.apache.maven.plugin.descriptor.PluginDescriptor; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.plugin.version.PluginVersionNotFoundException; +import org.apache.maven.plugin.version.PluginVersionResolutionException; +import org.apache.maven.plugins.enforcer.utils.EnforcerRuleUtils; +import org.apache.maven.plugins.enforcer.utils.PluginWrapper; +import org.apache.maven.project.MavenProject; +import org.apache.maven.settings.Settings; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import org.codehaus.plexus.util.ReflectionUtils; +import org.codehaus.plexus.util.StringUtils; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +/** + * This rule will enforce that all plugins specified in the poms have a version declared. + * + * @author Brian Fox + */ +public class RequirePluginVersions + extends AbstractNonCacheableEnforcerRule +{ + + private EnforcerRuleHelper helper; + + /** + * Don't allow the LATEST identifier. + * + * @see {@link #setBanLatest(boolean)} + * @see {@link #isBanLatest()} + */ + private boolean banLatest = true; + + /** + * Don't allow the RELEASE identifier. + * + * @see {@link #setBanRelease(boolean)} + * @see {@link #isBanRelease()} + */ + private boolean banRelease = true; + + /** + * Don't allow snapshot plugins. + * + * @see {@link #setBanSnapshots(boolean)} + * @see {@link #isBanSnapshots()} + */ + private boolean banSnapshots = true; + + /** + * Don't allow timestamp snapshot plugins. + * + * @see {@link #setBanTimestamps(boolean)} + * @see {@link #isBanTimestamps()} + */ + private boolean banTimestamps = true; + + /** + * The comma separated list of phases that should be used to find lifecycle plugin bindings. The default value is + * "clean,deploy,site". + * + * @see {@link #setPhases(String)} + * @see {@link #getPhases()} + */ + private String phases = "clean,deploy,site"; + + /** + * Additional plugins to enforce have versions. These are plugins that may not be in the poms but are used anyway, + * like help, eclipse etc.
+ * The plugins should be specified in the form: group:artifactId. + * + * @see {@link #setAdditionalPlugins(List)} + * @see {@link #getAdditionalPlugins()} + */ + private List additionalPlugins; + + /** + * Plugins to skip for version enforcement. The plugins should be specified in the form: + * group:artifactId. NOTE: This is deprecated, use unCheckedPluginList instead. + * + * @see {@link #setUnCheckedPlugins(List)} + * @see {@link #getUnCheckedPlugins()} + */ + private List unCheckedPlugins; + + /** + * Same as unCheckedPlugins but as a comma list to better support properties. Sample form: + * group:artifactId,group2:artifactId2 + * + * @since 1.0-beta-1 + * @see {@link #setUnCheckedPlugins(List)} + * @see {@link #getUnCheckedPlugins()} + */ + private String unCheckedPluginList; + + /** The plugin manager. */ + private PluginManager pluginManager; + + /** The phase to lifecycle map. */ + private Map phaseToLifecycleMap; + + /** The lifecycles. */ + private Collection lifecycles; + + /** The factory. */ + private ArtifactFactory factory; + + /** The resolver. */ + private ArtifactResolver resolver; + + /** The local. */ + private ArtifactRepository local; + + /** The remote repositories. */ + private List remoteRepositories; + + /** The log. */ + private Log log; + + /** The session. */ + private MavenSession session; + + /** The utils. */ + private EnforcerRuleUtils utils; + + @Override + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + this.log = helper.getLog(); + this.helper = helper; + + MavenProject project; + try + { + // get the various expressions out of the helper. + + project = (MavenProject) helper.evaluate( "${project}" ); + LifecycleExecutor life; + life = helper.getComponent( LifecycleExecutor.class ); + + Object defaultLifeCycles = ReflectionUtils.getValueIncludingSuperclasses( "defaultLifeCycles", life ); + Map lifecyclesMap = (Map) ReflectionUtils.getValueIncludingSuperclasses( "lifecycles", defaultLifeCycles ); + lifecycles = lifecyclesMap.values(); + + session = (MavenSession) helper.evaluate( "${session}" ); + pluginManager = helper.getComponent( PluginManager.class ); + factory = helper.getComponent( ArtifactFactory.class ); + resolver = helper.getComponent( ArtifactResolver.class ); + local = (ArtifactRepository) helper.evaluate( "${localRepository}" ); + remoteRepositories = project.getRemoteArtifactRepositories(); + + utils = new EnforcerRuleUtils( helper ); + + // get all the plugins that are bound to the specified lifecycles + Set allPlugins = getBoundPlugins( life, project, phases ); + + // insert any additional plugins specified by the user. + allPlugins = addAdditionalPlugins( allPlugins, additionalPlugins ); + allPlugins.addAll( getProfilePlugins( project ) ); + + // pull out any we should skip + allPlugins = + removeUncheckedPlugins( combineUncheckedPlugins( unCheckedPlugins, unCheckedPluginList ), allPlugins ); + + // there's nothing to do here + if ( allPlugins.isEmpty() ) + { + log.info( "No plugin bindings found." ); + return; + } + else + { + log.debug( "All Plugins in use: " + allPlugins ); + } + + // get all the plugins that are mentioned in the pom (and parents) + List pluginWrappers = getAllPluginEntries( project ); + + for ( PluginWrapper pluginWrapper : pluginWrappers ) + { + log.debug( "pluginWrappers: " + pluginWrapper.getGroupId() + ":" + pluginWrapper.getArtifactId() + ":" + + pluginWrapper.getVersion() + " source:" + pluginWrapper.getSource() ); + } + // now look for the versions that aren't valid and add to a list. + List failures = new ArrayList(); + + for ( Plugin plugin : allPlugins ) + { + if ( !hasValidVersionSpecified( helper, plugin, pluginWrappers ) ) + { + failures.add( plugin ); + } + } + + // if anything was found, log it then append the optional message. + if ( !failures.isEmpty() ) + { + handleMessagesToTheUser( project, failures ); + } + } + catch ( ExpressionEvaluationException e ) + { + throw new EnforcerRuleException( "Unable to Evaluate an Expression:" + e.getLocalizedMessage() ); + } + catch ( ComponentLookupException e ) + { + throw new EnforcerRuleException( "Unable to lookup a component:" + e.getLocalizedMessage() ); + } + catch ( Exception e ) + { + throw new EnforcerRuleException( e.getLocalizedMessage() ); + } + } + + private void handleMessagesToTheUser( MavenProject project, List failures ) + throws EnforcerRuleException + { + StringBuilder newMsg = new StringBuilder(); + newMsg.append( "Some plugins are missing valid versions:" ); + handleBanMessages( newMsg ); + newMsg.append( "\n" ); + for ( Plugin plugin : failures ) + { + newMsg.append( plugin.getGroupId() ); + newMsg.append( ":" ); + newMsg.append( plugin.getArtifactId() ); + + try + { + newMsg.append( ". \tThe version currently in use is " ); + + Plugin currentPlugin = findCurrentPlugin( plugin, project ); + + if ( currentPlugin != null ) + { + newMsg.append( currentPlugin.getVersion() ); + } + else + { + newMsg.append( "unknown" ); + } + } + catch ( Exception e ) + { + // lots can go wrong here. Don't allow any issues trying to + // determine the issue stop me + log.debug( "Exception while determining plugin Version.", e ); + newMsg.append( ". Unable to determine the plugin version." ); + } + newMsg.append( "\n" ); + } + String message = getMessage(); + if ( StringUtils.isNotEmpty( message ) ) + { + newMsg.append( message ); + } + + throw new EnforcerRuleException( newMsg.toString() ); + } + + private void handleBanMessages( StringBuilder newMsg ) + { + if ( banLatest || banRelease || banSnapshots || banTimestamps ) + { + newMsg.append( " (" ); + if ( banLatest ) + { + newMsg.append( "LATEST " ); + } + if ( banRelease ) + { + newMsg.append( "RELEASE " ); + } + if ( banSnapshots || banTimestamps ) + { + newMsg.append( "SNAPSHOT " ); + } + newMsg.append( "are not allowed)" ); + } + } + + /** + * Remove the plugins that the user doesn't want to check. + * + * @param uncheckedPlugins + * @param plugins + * @throws MojoExecutionException + * @return The plugins which have been removed. + */ + public Set removeUncheckedPlugins( Collection uncheckedPlugins, Set plugins ) + throws MojoExecutionException + { + if ( uncheckedPlugins != null && !uncheckedPlugins.isEmpty() ) + { + for ( String pluginKey : uncheckedPlugins ) + { + Plugin plugin = parsePluginString( pluginKey, "UncheckedPlugins" ); + plugins.remove( plugin ); + } + } + return plugins; + } + + /** + * Combines the old Collection with the new comma separated list. + * + * @param uncheckedPlugins + * @param uncheckedPluginsList + * @return List of unchecked plugins. + */ + // CHECKSTYLE_OFF: LineLength + public Collection combineUncheckedPlugins( Collection uncheckedPlugins, + String uncheckedPluginsList ) + // CHECKSTYLE_ON: LineLength + { + // if the comma list is empty, then there's nothing to do here. + if ( StringUtils.isNotEmpty( uncheckedPluginsList ) ) + { + // make sure there is a collection to add to. + if ( uncheckedPlugins == null ) + { + uncheckedPlugins = new HashSet(); + } + else if ( !uncheckedPlugins.isEmpty() && log != null ) + { + log.warn( "The parameter 'unCheckedPlugins' is deprecated. Use 'unCheckedPluginList' instead" ); + } + + uncheckedPlugins.addAll( Arrays.asList( uncheckedPluginsList.split( "," ) ) ); + } + return uncheckedPlugins; + } + + /** + * Add the additional plugins if they don't exist yet. + * + * @param existing the existing + * @param additional the additional + * @return the sets the + * @throws MojoExecutionException the mojo execution exception + */ +/** + * Add the additional plugins if they don't exist yet. + * + * @param existing + * the existing + * @param additional + * the additional + * @return the sets the + * @throws MojoExecutionException + * the mojo execution exception + */ +public java.util.Set addAdditionalPlugins(java.util.Set existing, java.util.List additional) throws org.apache.maven.plugin.MojoExecutionException { + { + for (java.lang.String pluginString : /* NPEX_NULL_EXP */ + additional) { + org.apache.maven.model.Plugin plugin = parsePluginString(pluginString, "AdditionalPlugins"); + if (existing == null) { + existing = new java.util.HashSet<>(); + existing.add(plugin); + } else if (!existing.contains(plugin)) { + existing.add(plugin); + } + } + } + return existing; +} + + /** + * Helper method to parse and inject a Plugin. + * + * @param pluginString + * @param field + * @throws MojoExecutionException + * @return the plugin + */ + protected Plugin parsePluginString( String pluginString, String field ) + throws MojoExecutionException + { + if ( pluginString != null ) + { + String[] pluginStrings = pluginString.split( ":" ); + if ( pluginStrings.length == 2 ) + { + Plugin plugin = new Plugin(); + plugin.setGroupId( StringUtils.strip( pluginStrings[0] ) ); + plugin.setArtifactId( StringUtils.strip( pluginStrings[1] ) ); + + return plugin; + } + else + { + throw new MojoExecutionException( "Invalid " + field + " string: " + pluginString ); + } + } + else + { + throw new MojoExecutionException( "Invalid " + field + " string: " + pluginString ); + } + + } + + /** + * Finds the plugins that are listed in active profiles. + * + * @param project the project + * @return the profile plugins + */ + public Set getProfilePlugins( MavenProject project ) + { + Set result = new HashSet<>(); + List profiles = project.getActiveProfiles(); + if ( profiles != null && !profiles.isEmpty() ) + { + for ( Profile p : profiles ) + { + BuildBase b = p.getBuild(); + if ( b != null ) + { + List plugins = b.getPlugins(); + if ( plugins != null ) + { + result.addAll( plugins ); + } + } + } + } + return result; + } + + /** + * Given a plugin, this will retrieve the matching plugin artifact from the model. + * + * @param plugin plugin to lookup + * @param project project to search + * @return matching plugin, null if not found. + */ + protected Plugin findCurrentPlugin( Plugin plugin, MavenProject project ) + { + Plugin found = null; + try + { + Model model = project.getModel(); + Map plugins = model.getBuild().getPluginsAsMap(); + found = plugins.get( plugin.getKey() ); + } + catch ( NullPointerException e ) + { + // nothing to do here + } + + if ( found == null ) + { + found = resolvePlugin( plugin, project ); + } + + return found; + } + + /** + * Resolve plugin. + * + * @param plugin the plugin + * @param project the project + * @return the plugin + */ + protected Plugin resolvePlugin( Plugin plugin, MavenProject project ) + { + + List pluginRepositories = project.getPluginArtifactRepositories(); + Artifact artifact = factory.createPluginArtifact( plugin.getGroupId(), plugin.getArtifactId(), + VersionRange.createFromVersion( "LATEST" ) ); + + try + { + this.resolver.resolve( artifact, pluginRepositories, this.local ); + plugin.setVersion( artifact.getVersion() ); + } + catch ( ArtifactResolutionException | ArtifactNotFoundException e ) + { + // What does this mean? + } + + return plugin; + } + + /** + * Gets the plugins that are bound to the defined phases. This does not find plugins bound in the pom to a phase + * later than the plugin is executing. + * + * @param life the life + * @param project the project + * @param thePhases the the phases + * @return the bound plugins + * @throws PluginNotFoundException the plugin not found exception + * @throws LifecycleExecutionException the lifecycle execution exception + * @throws IllegalAccessException the illegal access exception + */ + protected Set getBoundPlugins( LifecycleExecutor life, MavenProject project, String thePhases ) + throws PluginNotFoundException, LifecycleExecutionException, IllegalAccessException + { + + Set allPlugins = new HashSet<>(); + + // lookup the bindings for all the passed in phases + String[] lifecyclePhases = thePhases.split( "," ); + for ( int i = 0; i < lifecyclePhases.length; i++ ) + { + String lifecyclePhase = lifecyclePhases[i]; + if ( StringUtils.isNotEmpty( lifecyclePhase ) ) + { + try + { + Lifecycle lifecycle = getLifecycleForPhase( lifecyclePhase ); + log.debug( "getBoundPlugins(): " + project.getId() + " " + lifecyclePhase + " " + + lifecycle.getId() ); + allPlugins.addAll( getAllPlugins( project, lifecycle ) ); + } + catch ( BuildFailureException e ) + { + // i'm going to swallow this because the + // user may have declared a phase that + // doesn't exist for every module. + } + } + } + return allPlugins; + } + + /** + * Checks for valid version specified. Checks to see if the version is specified for the plugin. Can optionally ban + * "RELEASE" or "LATEST" even if specified. + * + * @param helper the helper + * @param source the source + * @param pluginWrappers the plugins + * @return true, if successful + */ + protected boolean hasValidVersionSpecified( EnforcerRuleHelper helper, Plugin source, + List pluginWrappers ) + { + boolean found = false; + boolean status = false; + for ( PluginWrapper plugin : pluginWrappers ) + { + // find the matching plugin entry + if ( isMatchingPlugin( source, plugin ) ) + { + found = true; + // found the entry. now see if the version is specified + String version = plugin.getVersion(); + try + { + version = (String) helper.evaluate( version ); + } + catch ( ExpressionEvaluationException e ) + { + return false; + } + + if ( isValidVersion( version ) ) + { + helper.getLog().debug( "checking for notEmpty and notIsWhitespace(): " + version ); + if ( banRelease && version.equals( "RELEASE" ) ) + { + return false; + } + + if ( banLatest && version.equals( "LATEST" ) ) + { + return false; + } + + if ( banSnapshots && isSnapshot( version ) ) + { + return false; + } + // the version was specified and not + // banned. It's ok. Keep looking through the list to make + // sure it's not using a banned version somewhere else. + + status = true; + + if ( !banRelease && !banLatest && !banSnapshots ) + { + // no need to keep looking + break; + } + } + } + } + if ( !found ) + { + helper.getLog().debug( "plugin " + source.getGroupId() + ":" + source.getArtifactId() + " not found" ); + } + return status; + } + + private boolean isValidVersion( String version ) + { + return StringUtils.isNotEmpty( version ) && !StringUtils.isWhitespace( version ); + } + + private boolean isMatchingPlugin( Plugin source, PluginWrapper plugin ) + { + return source.getArtifactId().equals( plugin.getArtifactId() ) + && source.getGroupId().equals( plugin.getGroupId() ); + } + + /** + * Checks if is snapshot. + * + * @param baseVersion the base version + * @return true, if is snapshot + */ + protected boolean isSnapshot( String baseVersion ) + { + if ( banTimestamps ) + { + return Artifact.VERSION_FILE_PATTERN.matcher( baseVersion ).matches() + || baseVersion.endsWith( Artifact.SNAPSHOT_VERSION ); + } + else + { + return baseVersion.endsWith( Artifact.SNAPSHOT_VERSION ); + } + } + + /* + * Uses borrowed lifecycle code to get a list of all plugins bound to the lifecycle. + */ + /** + * Gets the all plugins. + * + * @param project the project + * @param lifecycle the lifecycle + * @return the all plugins + * @throws PluginNotFoundException the plugin not found exception + * @throws LifecycleExecutionException the lifecycle execution exception + */ + private Set getAllPlugins( MavenProject project, Lifecycle lifecycle ) + throws PluginNotFoundException, LifecycleExecutionException + + { + log.debug( "RequirePluginVersions.getAllPlugins:" ); + + Set plugins = new HashSet<>(); + // first, bind those associated with the packaging + Map mappings = findMappingsForLifecycle( project, lifecycle ); + + for ( Map.Entry entry : mappings.entrySet() ) + { + log.debug( " lifecycleMapping = " + entry.getKey() ); + String pluginsForLifecycle = (String) entry.getValue(); + log.debug( " plugins = " + pluginsForLifecycle ); + if ( StringUtils.isNotEmpty( pluginsForLifecycle ) ) + { + String pluginList[] = pluginsForLifecycle.split( "," ); + for ( String plugin : pluginList ) + { + plugin = StringUtils.strip( plugin ); + log.debug( " plugin = " + plugin ); + String tokens[] = plugin.split( ":" ); + log.debug( " GAV = " + Arrays.asList( tokens ) ); + + Plugin p = new Plugin(); + p.setGroupId( tokens[0] ); + p.setArtifactId( tokens[1] ); + plugins.add( p ); + } + } + } + + List mojos = findOptionalMojosForLifecycle( project, lifecycle ); + for ( String value : mojos ) + { + String tokens[] = value.split( ":" ); + + Plugin plugin = new Plugin(); + plugin.setGroupId( tokens[0] ); + plugin.setArtifactId( tokens[1] ); + plugins.add( plugin ); + } + + plugins.addAll( project.getBuildPlugins() ); + + return plugins; + } + + /* + * NOTE: All the code following this point was scooped from the DefaultLifecycleExecutor. There must be a better way + * but for now it should work. + */ + /** + * Gets the phase to lifecycle map. + * + * @return the phase to lifecycle map + * @throws LifecycleExecutionException the lifecycle execution exception + */ + public Map getPhaseToLifecycleMap() + throws LifecycleExecutionException + { + if ( phaseToLifecycleMap == null ) + { + phaseToLifecycleMap = new HashMap<>(); + + for ( Lifecycle lifecycle : lifecycles ) + { + List phases = lifecycle.getPhases(); + for ( String phase : phases ) + { + log.debug( "getPhaseToLifecycleMap(): phase: " + phase ); + if ( phaseToLifecycleMap.containsKey( phase ) ) + { + Lifecycle prevLifecycle = (Lifecycle) phaseToLifecycleMap.get( phase ); + throw new LifecycleExecutionException( "Phase '" + phase + + "' is defined in more than one lifecycle: '" + lifecycle.getId() + "' and '" + + prevLifecycle.getId() + "'" ); + } + else + { + phaseToLifecycleMap.put( phase, lifecycle ); + } + } + } + } + return phaseToLifecycleMap; + } + + /** + * Gets the lifecycle for phase. + * + * @param phase the phase + * @return the lifecycle for phase + * @throws BuildFailureException the build failure exception + * @throws LifecycleExecutionException the lifecycle execution exception + */ + private Lifecycle getLifecycleForPhase( String phase ) + throws BuildFailureException, LifecycleExecutionException + { + Lifecycle lifecycle = getPhaseToLifecycleMap().get( phase ); + + if ( lifecycle == null ) + { + throw new BuildFailureException( "Unable to find lifecycle for phase '" + phase + "'" ); + } + return lifecycle; + } + + /** + * Find mappings for lifecycle. + * + * @param project the project + * @param lifecycle the lifecycle + * @return the map + * @throws LifecycleExecutionException the lifecycle execution exception + * @throws PluginNotFoundException the plugin not found exception + */ + private Map findMappingsForLifecycle( MavenProject project, Lifecycle lifecycle ) + throws LifecycleExecutionException, PluginNotFoundException + { + String packaging = project.getPackaging(); + Map mappings = null; + + LifecycleMapping m = (LifecycleMapping) findExtension( project, LifecycleMapping.ROLE, packaging, + session.getSettings(), session.getLocalRepository() ); + if ( m != null ) + { + mappings = m.getPhases( lifecycle.getId() ); + } + + Map defaultMappings = lifecycle.getDefaultPhases(); + + if ( mappings == null ) + { + try + { + m = helper.getComponent( LifecycleMapping.class, packaging ); + mappings = m.getPhases( lifecycle.getId() ); + } + catch ( ComponentLookupException e ) + { + if ( defaultMappings == null ) + { + throw new LifecycleExecutionException( "Cannot find lifecycle mapping for packaging: \'" + packaging + + "\'.", e ); + } + } + } + + if ( mappings == null ) + { + if ( defaultMappings == null ) + { + throw new LifecycleExecutionException( "Cannot find lifecycle mapping for packaging: \'" + packaging + + "\', and there is no default" ); + } + else + { + mappings = defaultMappings; + } + } + + return mappings; + } + + /** + * Find optional mojos for lifecycle. + * + * @param project the project + * @param lifecycle the lifecycle + * @return the list + * @throws LifecycleExecutionException the lifecycle execution exception + * @throws PluginNotFoundException the plugin not found exception + */ + private List findOptionalMojosForLifecycle( MavenProject project, Lifecycle lifecycle ) + throws LifecycleExecutionException, PluginNotFoundException + { + String packaging = project.getPackaging(); + List optionalMojos = null; + + LifecycleMapping m = (LifecycleMapping) findExtension( project, LifecycleMapping.ROLE, packaging, + session.getSettings(), session.getLocalRepository() ); + + if ( m != null ) + { + optionalMojos = m.getOptionalMojos( lifecycle.getId() ); + } + + if ( optionalMojos == null ) + { + try + { + m = helper.getComponent( LifecycleMapping.class, packaging ); + optionalMojos = m.getOptionalMojos( lifecycle.getId() ); + } + catch ( ComponentLookupException e ) + { + log.debug( "Error looking up lifecycle mapping to retrieve optional mojos. Lifecycle ID: " + + lifecycle.getId() + ". Error: " + e.getMessage(), e ); + } + } + + if ( optionalMojos == null ) + { + optionalMojos = Collections.emptyList(); + } + + return optionalMojos; + } + + /** + * Find extension. + * + * @param project the project + * @param role the role + * @param roleHint the role hint + * @param settings the settings + * @param localRepository the local repository + * @return the object + * @throws LifecycleExecutionException the lifecycle execution exception + * @throws PluginNotFoundException the plugin not found exception + */ + private Object findExtension( MavenProject project, String role, String roleHint, Settings settings, + ArtifactRepository localRepository ) + throws LifecycleExecutionException, PluginNotFoundException + { + Object pluginComponent = null; + + List buildPlugins = project.getBuildPlugins(); + for ( Plugin plugin : buildPlugins ) + { + if ( plugin.isExtensions() ) + { + verifyPlugin( plugin, project, settings, localRepository ); + + // TODO: if moved to the plugin manager we + // already have the descriptor from above + // and so do can lookup the container + // directly + try + { + pluginComponent = pluginManager.getPluginComponent( plugin, role, roleHint ); + + if ( pluginComponent != null ) + { + break; + } + } + catch ( ComponentLookupException e ) + { + log.debug( "Unable to find the lifecycle component in the extension", e ); + } + catch ( PluginManagerException e ) + { + throw new LifecycleExecutionException( "Error getting extensions from the plugin '" + + plugin.getKey() + "': " + e.getMessage(), e ); + } + } + } + return pluginComponent; + } + + /** + * Verify plugin. + * + * @param plugin the plugin + * @param project the project + * @param settings the settings + * @param localRepository the local repository + * @return the plugin descriptor + * @throws LifecycleExecutionException the lifecycle execution exception + * @throws PluginNotFoundException the plugin not found exception + */ + private PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings, + ArtifactRepository localRepository ) + throws LifecycleExecutionException, PluginNotFoundException + { + PluginDescriptor pluginDescriptor; + try + { + pluginDescriptor = pluginManager.verifyPlugin( plugin, project, settings, localRepository ); + } + catch ( PluginManagerException e ) + { + throw new LifecycleExecutionException( "Internal error in the plugin manager getting plugin '" + + plugin.getKey() + "': " + e.getMessage(), e ); + } + catch ( PluginVersionResolutionException | InvalidVersionSpecificationException | InvalidPluginException + | ArtifactNotFoundException | ArtifactResolutionException | PluginVersionNotFoundException e ) + { + throw new LifecycleExecutionException( e.getMessage(), e ); + } + return pluginDescriptor; + } + + /** + * Gets all plugin entries in build.plugins, build.pluginManagement.plugins, profile.build.plugins, reporting and + * profile.reporting in this project and all parents + * + * @param project the project + * @return the all plugin entries wrapped in a PluginWrapper Object + * @throws ArtifactResolutionException the artifact resolution exception + * @throws ArtifactNotFoundException the artifact not found exception + * @throws IOException Signals that an I/O exception has occurred. + * @throws XmlPullParserException the xml pull parser exception + */ + protected List getAllPluginEntries( MavenProject project ) + throws ArtifactResolutionException, ArtifactNotFoundException, IOException, XmlPullParserException + { + List models = new ArrayList<>(); + + List sortedProjects = session.getProjectDependencyGraph().getSortedProjects(); + + if ( !sortedProjects.isEmpty() && sortedProjects.get( 0 ).getParent() != null ) + { + getOriginalModelFromAllParents( models, sortedProjects ); + } + + for ( MavenProject mavenProject : sortedProjects ) + { + models.add( mavenProject.getOriginalModel() ); + } + + List plugins = new ArrayList<>(); + // now find all the plugin entries, either in + // build.plugins or build.pluginManagement.plugins, profiles.plugins and reporting + for ( Model model : models ) + { + getPlugins( plugins, model ); + getReportingPlugins( plugins, model ); + getPluginManagementPlugins( plugins, model ); + + addPluginsInProfiles( plugins, model ); + } + + return plugins; + } + + private void getOriginalModelFromAllParents( List models, List sortedProjects ) + { + MavenProject parent = sortedProjects.get( 0 ).getParent(); + do + { + models.add( parent.getOriginalModel() ); + parent = parent.getParent(); + } + while ( parent != null ); + } + + private void addPluginsInProfiles( List plugins, Model model ) + { + List profiles = model.getProfiles(); + for ( Profile profile : profiles ) + { + getProfilePlugins( plugins, model, profile ); + getProfileReportingPlugins( plugins, model, profile ); + getProfilePluginManagementPlugins( plugins, model, profile ); + } + } + + private void getProfilePluginManagementPlugins( List plugins, Model model, Profile profile ) + { + try + { + List modelPlugins = profile.getBuild().getPluginManagement().getPlugins(); + plugins.addAll( PluginWrapper.addAll( utils.resolvePlugins( modelPlugins ), model.getId() + "profile[" + + profile.getId() + "].build.pluginManagement.plugins" ) ); + } + catch ( NullPointerException e ) + { + // guess there are no plugins here. + } + } + + private void getProfileReportingPlugins( List plugins, Model model, Profile profile ) + { + try + { + List modelReportPlugins = profile.getReporting().getPlugins(); + // add the reporting plugins + plugins.addAll( PluginWrapper.addAll( utils.resolveReportPlugins( modelReportPlugins ), model.getId() + + "profile[" + profile.getId() + "].reporting.plugins" ) ); + } + catch ( NullPointerException e ) + { + // guess there are no plugins here. + } + } + + private void getProfilePlugins( List plugins, Model model, Profile profile ) + { + try + { + List modelPlugins = profile.getBuild().getPlugins(); + plugins.addAll( PluginWrapper.addAll( utils.resolvePlugins( modelPlugins ), model.getId() + + ".profiles.profile[" + profile.getId() + "].build.plugins" ) ); + } + catch ( NullPointerException e ) + { + // guess there are no plugins here. + } + } + + private void getPlugins( List plugins, Model model ) + { + try + { + List modelPlugins = model.getBuild().getPlugins(); + plugins.addAll( PluginWrapper.addAll( utils.resolvePlugins( modelPlugins ), + model.getId() + ".build.plugins" ) ); + } + catch ( NullPointerException e ) + { + // guess there are no plugins here. + } + } + + private void getPluginManagementPlugins( List plugins, Model model ) + { + try + { + List modelPlugins = model.getBuild().getPluginManagement().getPlugins(); + plugins.addAll( PluginWrapper.addAll( utils.resolvePlugins( modelPlugins ), + model.getId() + ".build.pluginManagement.plugins" ) ); + } + catch ( NullPointerException e ) + { + // guess there are no plugins here. + } + } + + private void getReportingPlugins( List plugins, Model model ) + { + try + { + List modelReportPlugins = model.getReporting().getPlugins(); + // add the reporting plugins + plugins.addAll( PluginWrapper.addAll( utils.resolveReportPlugins( modelReportPlugins ), + model.getId() + ".reporting" ) ); + } + catch ( NullPointerException e ) + { + // guess there are no plugins here. + } + } + + /** + * Checks if is ban latest. + * + * @return the banLatest + */ + protected boolean isBanLatest() + { + return this.banLatest; + } + + /** + * Sets the ban latest. + * + * @param theBanLatest the banLatest to set + */ + protected void setBanLatest( boolean theBanLatest ) + { + this.banLatest = theBanLatest; + } + + /** + * Checks if is ban release. + * + * @return the banRelease + */ + protected boolean isBanRelease() + { + return this.banRelease; + } + + /** + * Sets the ban release. + * + * @param theBanRelease the banRelease to set + */ + protected void setBanRelease( boolean theBanRelease ) + { + this.banRelease = theBanRelease; + } + + /** + * Gets the utils. + * + * @return the utils + */ + protected EnforcerRuleUtils getUtils() + { + return this.utils; + } + + /** + * Sets the utils. + * + * @param theUtils the utils to set + */ + protected void setUtils( EnforcerRuleUtils theUtils ) + { + this.utils = theUtils; + } + + /** + * Checks if is ban snapshots. + * + * @return the banSnapshots + */ + public boolean isBanSnapshots() + { + return this.banSnapshots; + } + + /** + * Sets the ban snapshots. + * + * @param theBanSnapshots the banSnapshots to set + */ + public void setBanSnapshots( boolean theBanSnapshots ) + { + this.banSnapshots = theBanSnapshots; + } + + /** + * Checks if is ban timestamps. + * + * @return the banTimestamps + */ + public boolean isBanTimestamps() + { + return this.banTimestamps; + } + + /** + * Sets the ban timestamps. + * + * @param theBanTimestamps the banTimestamps to set + */ + public void setBanTimestamps( boolean theBanTimestamps ) + { + this.banTimestamps = theBanTimestamps; + } + + public List getUnCheckedPlugins() + { + return unCheckedPlugins; + } + + public void setUnCheckedPlugins( List unCheckedPlugins ) + { + this.unCheckedPlugins = unCheckedPlugins; + } + + public final void setPhases( String phases ) + { + this.phases = phases; + } + + public final String getPhases() + { + return phases; + } + + public final void setAdditionalPlugins( List additionalPlugins ) + { + this.additionalPlugins = additionalPlugins; + } + + public final List getAdditionalPlugins() + { + return additionalPlugins; + } +} diff --git a/Java/maven-enforcer-RequirePluginVersions_404/metadata.json b/Java/maven-enforcer-RequirePluginVersions_404/metadata.json new file mode 100644 index 000000000..fd8714632 --- /dev/null +++ b/Java/maven-enforcer-RequirePluginVersions_404/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-enforcer-RequirePluginVersions_404", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn clean test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java", + "line": 415, + "npe_method": "addAdditionalPlugins", + "deref_field": "additional", + "npe_class": "RequirePluginVersions", + "repo": "maven-enforcer", + "bug_id": "RequirePluginVersions_404" + } +} diff --git a/Java/maven-enforcer-RequirePluginVersions_404/npe.json b/Java/maven-enforcer-RequirePluginVersions_404/npe.json new file mode 100644 index 000000000..ce0d78698 --- /dev/null +++ b/Java/maven-enforcer-RequirePluginVersions_404/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java", + "line": 415, + "npe_method": "addAdditionalPlugins", + "deref_field": "additional", + "npe_class": "RequirePluginVersions" +} \ No newline at end of file diff --git a/Java/maven-enforcer-RequirePluginVersions_410/Dockerfile b/Java/maven-enforcer-RequirePluginVersions_410/Dockerfile new file mode 100644 index 000000000..3581e6769 --- /dev/null +++ b/Java/maven-enforcer-RequirePluginVersions_410/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-enforcer + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-enforcer-RequirePluginVersions_410/buggy.java b/Java/maven-enforcer-RequirePluginVersions_410/buggy.java new file mode 100644 index 000000000..ea1bb758f --- /dev/null +++ b/Java/maven-enforcer-RequirePluginVersions_410/buggy.java @@ -0,0 +1,1275 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.maven.BuildFailureException; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.ArtifactNotFoundException; +import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.artifact.resolver.ArtifactResolver; +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.lifecycle.Lifecycle; +import org.apache.maven.lifecycle.LifecycleExecutionException; +import org.apache.maven.lifecycle.LifecycleExecutor; +import org.apache.maven.lifecycle.mapping.LifecycleMapping; +import org.apache.maven.model.BuildBase; +import org.apache.maven.model.Model; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.Profile; +import org.apache.maven.model.ReportPlugin; +import org.apache.maven.plugin.InvalidPluginException; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.PluginManager; +import org.apache.maven.plugin.PluginManagerException; +import org.apache.maven.plugin.PluginNotFoundException; +import org.apache.maven.plugin.descriptor.PluginDescriptor; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.plugin.version.PluginVersionNotFoundException; +import org.apache.maven.plugin.version.PluginVersionResolutionException; +import org.apache.maven.plugins.enforcer.utils.EnforcerRuleUtils; +import org.apache.maven.plugins.enforcer.utils.PluginWrapper; +import org.apache.maven.project.MavenProject; +import org.apache.maven.settings.Settings; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import org.codehaus.plexus.util.ReflectionUtils; +import org.codehaus.plexus.util.StringUtils; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +/** + * This rule will enforce that all plugins specified in the poms have a version declared. + * + * @author Brian Fox + */ +public class RequirePluginVersions + extends AbstractNonCacheableEnforcerRule +{ + + private EnforcerRuleHelper helper; + + /** + * Don't allow the LATEST identifier. + * + * @see {@link #setBanLatest(boolean)} + * @see {@link #isBanLatest()} + */ + private boolean banLatest = true; + + /** + * Don't allow the RELEASE identifier. + * + * @see {@link #setBanRelease(boolean)} + * @see {@link #isBanRelease()} + */ + private boolean banRelease = true; + + /** + * Don't allow snapshot plugins. + * + * @see {@link #setBanSnapshots(boolean)} + * @see {@link #isBanSnapshots()} + */ + private boolean banSnapshots = true; + + /** + * Don't allow timestamp snapshot plugins. + * + * @see {@link #setBanTimestamps(boolean)} + * @see {@link #isBanTimestamps()} + */ + private boolean banTimestamps = true; + + /** + * The comma separated list of phases that should be used to find lifecycle plugin bindings. The default value is + * "clean,deploy,site". + * + * @see {@link #setPhases(String)} + * @see {@link #getPhases()} + */ + private String phases = "clean,deploy,site"; + + /** + * Additional plugins to enforce have versions. These are plugins that may not be in the poms but are used anyway, + * like help, eclipse etc.
+ * The plugins should be specified in the form: group:artifactId. + * + * @see {@link #setAdditionalPlugins(List)} + * @see {@link #getAdditionalPlugins()} + */ + private List additionalPlugins; + + /** + * Plugins to skip for version enforcement. The plugins should be specified in the form: + * group:artifactId. NOTE: This is deprecated, use unCheckedPluginList instead. + * + * @see {@link #setUnCheckedPlugins(List)} + * @see {@link #getUnCheckedPlugins()} + */ + private List unCheckedPlugins; + + /** + * Same as unCheckedPlugins but as a comma list to better support properties. Sample form: + * group:artifactId,group2:artifactId2 + * + * @since 1.0-beta-1 + * @see {@link #setUnCheckedPlugins(List)} + * @see {@link #getUnCheckedPlugins()} + */ + private String unCheckedPluginList; + + /** The plugin manager. */ + private PluginManager pluginManager; + + /** The phase to lifecycle map. */ + private Map phaseToLifecycleMap; + + /** The lifecycles. */ + private Collection lifecycles; + + /** The factory. */ + private ArtifactFactory factory; + + /** The resolver. */ + private ArtifactResolver resolver; + + /** The local. */ + private ArtifactRepository local; + + /** The remote repositories. */ + private List remoteRepositories; + + /** The log. */ + private Log log; + + /** The session. */ + private MavenSession session; + + /** The utils. */ + private EnforcerRuleUtils utils; + + @Override + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + this.log = helper.getLog(); + this.helper = helper; + + MavenProject project; + try + { + // get the various expressions out of the helper. + + project = (MavenProject) helper.evaluate( "${project}" ); + LifecycleExecutor life; + life = helper.getComponent( LifecycleExecutor.class ); + + Object defaultLifeCycles = ReflectionUtils.getValueIncludingSuperclasses( "defaultLifeCycles", life ); + Map lifecyclesMap = (Map) ReflectionUtils.getValueIncludingSuperclasses( "lifecycles", defaultLifeCycles ); + lifecycles = lifecyclesMap.values(); + + session = (MavenSession) helper.evaluate( "${session}" ); + pluginManager = helper.getComponent( PluginManager.class ); + factory = helper.getComponent( ArtifactFactory.class ); + resolver = helper.getComponent( ArtifactResolver.class ); + local = (ArtifactRepository) helper.evaluate( "${localRepository}" ); + remoteRepositories = project.getRemoteArtifactRepositories(); + + utils = new EnforcerRuleUtils( helper ); + + // get all the plugins that are bound to the specified lifecycles + Set allPlugins = getBoundPlugins( life, project, phases ); + + // insert any additional plugins specified by the user. + allPlugins = addAdditionalPlugins( allPlugins, additionalPlugins ); + allPlugins.addAll( getProfilePlugins( project ) ); + + // pull out any we should skip + allPlugins = + removeUncheckedPlugins( combineUncheckedPlugins( unCheckedPlugins, unCheckedPluginList ), allPlugins ); + + // there's nothing to do here + if ( allPlugins.isEmpty() ) + { + log.info( "No plugin bindings found." ); + return; + } + else + { + log.debug( "All Plugins in use: " + allPlugins ); + } + + // get all the plugins that are mentioned in the pom (and parents) + List pluginWrappers = getAllPluginEntries( project ); + + for ( PluginWrapper pluginWrapper : pluginWrappers ) + { + log.debug( "pluginWrappers: " + pluginWrapper.getGroupId() + ":" + pluginWrapper.getArtifactId() + ":" + + pluginWrapper.getVersion() + " source:" + pluginWrapper.getSource() ); + } + // now look for the versions that aren't valid and add to a list. + List failures = new ArrayList(); + + for ( Plugin plugin : allPlugins ) + { + if ( !hasValidVersionSpecified( helper, plugin, pluginWrappers ) ) + { + failures.add( plugin ); + } + } + + // if anything was found, log it then append the optional message. + if ( !failures.isEmpty() ) + { + handleMessagesToTheUser( project, failures ); + } + } + catch ( ExpressionEvaluationException e ) + { + throw new EnforcerRuleException( "Unable to Evaluate an Expression:" + e.getLocalizedMessage() ); + } + catch ( ComponentLookupException e ) + { + throw new EnforcerRuleException( "Unable to lookup a component:" + e.getLocalizedMessage() ); + } + catch ( Exception e ) + { + throw new EnforcerRuleException( e.getLocalizedMessage() ); + } + } + + private void handleMessagesToTheUser( MavenProject project, List failures ) + throws EnforcerRuleException + { + StringBuilder newMsg = new StringBuilder(); + newMsg.append( "Some plugins are missing valid versions:" ); + handleBanMessages( newMsg ); + newMsg.append( "\n" ); + for ( Plugin plugin : failures ) + { + newMsg.append( plugin.getGroupId() ); + newMsg.append( ":" ); + newMsg.append( plugin.getArtifactId() ); + + try + { + newMsg.append( ". \tThe version currently in use is " ); + + Plugin currentPlugin = findCurrentPlugin( plugin, project ); + + if ( currentPlugin != null ) + { + newMsg.append( currentPlugin.getVersion() ); + } + else + { + newMsg.append( "unknown" ); + } + } + catch ( Exception e ) + { + // lots can go wrong here. Don't allow any issues trying to + // determine the issue stop me + log.debug( "Exception while determining plugin Version.", e ); + newMsg.append( ". Unable to determine the plugin version." ); + } + newMsg.append( "\n" ); + } + String message = getMessage(); + if ( StringUtils.isNotEmpty( message ) ) + { + newMsg.append( message ); + } + + throw new EnforcerRuleException( newMsg.toString() ); + } + + private void handleBanMessages( StringBuilder newMsg ) + { + if ( banLatest || banRelease || banSnapshots || banTimestamps ) + { + newMsg.append( " (" ); + if ( banLatest ) + { + newMsg.append( "LATEST " ); + } + if ( banRelease ) + { + newMsg.append( "RELEASE " ); + } + if ( banSnapshots || banTimestamps ) + { + newMsg.append( "SNAPSHOT " ); + } + newMsg.append( "are not allowed)" ); + } + } + + /** + * Remove the plugins that the user doesn't want to check. + * + * @param uncheckedPlugins + * @param plugins + * @throws MojoExecutionException + * @return The plugins which have been removed. + */ + public Set removeUncheckedPlugins( Collection uncheckedPlugins, Set plugins ) + throws MojoExecutionException + { + if ( uncheckedPlugins != null && !uncheckedPlugins.isEmpty() ) + { + for ( String pluginKey : uncheckedPlugins ) + { + Plugin plugin = parsePluginString( pluginKey, "UncheckedPlugins" ); + plugins.remove( plugin ); + } + } + return plugins; + } + + /** + * Combines the old Collection with the new comma separated list. + * + * @param uncheckedPlugins + * @param uncheckedPluginsList + * @return List of unchecked plugins. + */ + // CHECKSTYLE_OFF: LineLength + public Collection combineUncheckedPlugins( Collection uncheckedPlugins, + String uncheckedPluginsList ) + // CHECKSTYLE_ON: LineLength + { + // if the comma list is empty, then there's nothing to do here. + if ( StringUtils.isNotEmpty( uncheckedPluginsList ) ) + { + // make sure there is a collection to add to. + if ( uncheckedPlugins == null ) + { + uncheckedPlugins = new HashSet(); + } + else if ( !uncheckedPlugins.isEmpty() && log != null ) + { + log.warn( "The parameter 'unCheckedPlugins' is deprecated. Use 'unCheckedPluginList' instead" ); + } + + uncheckedPlugins.addAll( Arrays.asList( uncheckedPluginsList.split( "," ) ) ); + } + return uncheckedPlugins; + } + + /** + * Add the additional plugins if they don't exist yet. + * + * @param existing the existing + * @param additional the additional + * @return the sets the + * @throws MojoExecutionException the mojo execution exception + */ +/** + * Add the additional plugins if they don't exist yet. + * + * @param existing + * the existing + * @param additional + * the additional + * @return the sets the + * @throws MojoExecutionException + * the mojo execution exception + */ +public java.util.Set addAdditionalPlugins(java.util.Set existing, java.util.List additional) throws org.apache.maven.plugin.MojoExecutionException { + { + for (java.lang.String pluginString : additional) { + org.apache.maven.model.Plugin plugin = parsePluginString(pluginString, "AdditionalPlugins"); + { + if (!/* NPEX_NULL_EXP */ + existing.contains(plugin)) { + existing.add(plugin); + } + } + } + } + return existing; +} + + /** + * Helper method to parse and inject a Plugin. + * + * @param pluginString + * @param field + * @throws MojoExecutionException + * @return the plugin + */ + protected Plugin parsePluginString( String pluginString, String field ) + throws MojoExecutionException + { + if ( pluginString != null ) + { + String[] pluginStrings = pluginString.split( ":" ); + if ( pluginStrings.length == 2 ) + { + Plugin plugin = new Plugin(); + plugin.setGroupId( StringUtils.strip( pluginStrings[0] ) ); + plugin.setArtifactId( StringUtils.strip( pluginStrings[1] ) ); + + return plugin; + } + else + { + throw new MojoExecutionException( "Invalid " + field + " string: " + pluginString ); + } + } + else + { + throw new MojoExecutionException( "Invalid " + field + " string: " + pluginString ); + } + + } + + /** + * Finds the plugins that are listed in active profiles. + * + * @param project the project + * @return the profile plugins + */ + public Set getProfilePlugins( MavenProject project ) + { + Set result = new HashSet<>(); + List profiles = project.getActiveProfiles(); + if ( profiles != null && !profiles.isEmpty() ) + { + for ( Profile p : profiles ) + { + BuildBase b = p.getBuild(); + if ( b != null ) + { + List plugins = b.getPlugins(); + if ( plugins != null ) + { + result.addAll( plugins ); + } + } + } + } + return result; + } + + /** + * Given a plugin, this will retrieve the matching plugin artifact from the model. + * + * @param plugin plugin to lookup + * @param project project to search + * @return matching plugin, null if not found. + */ + protected Plugin findCurrentPlugin( Plugin plugin, MavenProject project ) + { + Plugin found = null; + try + { + Model model = project.getModel(); + Map plugins = model.getBuild().getPluginsAsMap(); + found = plugins.get( plugin.getKey() ); + } + catch ( NullPointerException e ) + { + // nothing to do here + } + + if ( found == null ) + { + found = resolvePlugin( plugin, project ); + } + + return found; + } + + /** + * Resolve plugin. + * + * @param plugin the plugin + * @param project the project + * @return the plugin + */ + protected Plugin resolvePlugin( Plugin plugin, MavenProject project ) + { + + List pluginRepositories = project.getPluginArtifactRepositories(); + Artifact artifact = factory.createPluginArtifact( plugin.getGroupId(), plugin.getArtifactId(), + VersionRange.createFromVersion( "LATEST" ) ); + + try + { + this.resolver.resolve( artifact, pluginRepositories, this.local ); + plugin.setVersion( artifact.getVersion() ); + } + catch ( ArtifactResolutionException | ArtifactNotFoundException e ) + { + // What does this mean? + } + + return plugin; + } + + /** + * Gets the plugins that are bound to the defined phases. This does not find plugins bound in the pom to a phase + * later than the plugin is executing. + * + * @param life the life + * @param project the project + * @param thePhases the the phases + * @return the bound plugins + * @throws PluginNotFoundException the plugin not found exception + * @throws LifecycleExecutionException the lifecycle execution exception + * @throws IllegalAccessException the illegal access exception + */ + protected Set getBoundPlugins( LifecycleExecutor life, MavenProject project, String thePhases ) + throws PluginNotFoundException, LifecycleExecutionException, IllegalAccessException + { + + Set allPlugins = new HashSet<>(); + + // lookup the bindings for all the passed in phases + String[] lifecyclePhases = thePhases.split( "," ); + for ( int i = 0; i < lifecyclePhases.length; i++ ) + { + String lifecyclePhase = lifecyclePhases[i]; + if ( StringUtils.isNotEmpty( lifecyclePhase ) ) + { + try + { + Lifecycle lifecycle = getLifecycleForPhase( lifecyclePhase ); + log.debug( "getBoundPlugins(): " + project.getId() + " " + lifecyclePhase + " " + + lifecycle.getId() ); + allPlugins.addAll( getAllPlugins( project, lifecycle ) ); + } + catch ( BuildFailureException e ) + { + // i'm going to swallow this because the + // user may have declared a phase that + // doesn't exist for every module. + } + } + } + return allPlugins; + } + + /** + * Checks for valid version specified. Checks to see if the version is specified for the plugin. Can optionally ban + * "RELEASE" or "LATEST" even if specified. + * + * @param helper the helper + * @param source the source + * @param pluginWrappers the plugins + * @return true, if successful + */ + protected boolean hasValidVersionSpecified( EnforcerRuleHelper helper, Plugin source, + List pluginWrappers ) + { + boolean found = false; + boolean status = false; + for ( PluginWrapper plugin : pluginWrappers ) + { + // find the matching plugin entry + if ( isMatchingPlugin( source, plugin ) ) + { + found = true; + // found the entry. now see if the version is specified + String version = plugin.getVersion(); + try + { + version = (String) helper.evaluate( version ); + } + catch ( ExpressionEvaluationException e ) + { + return false; + } + + if ( isValidVersion( version ) ) + { + helper.getLog().debug( "checking for notEmpty and notIsWhitespace(): " + version ); + if ( banRelease && version.equals( "RELEASE" ) ) + { + return false; + } + + if ( banLatest && version.equals( "LATEST" ) ) + { + return false; + } + + if ( banSnapshots && isSnapshot( version ) ) + { + return false; + } + // the version was specified and not + // banned. It's ok. Keep looking through the list to make + // sure it's not using a banned version somewhere else. + + status = true; + + if ( !banRelease && !banLatest && !banSnapshots ) + { + // no need to keep looking + break; + } + } + } + } + if ( !found ) + { + helper.getLog().debug( "plugin " + source.getGroupId() + ":" + source.getArtifactId() + " not found" ); + } + return status; + } + + private boolean isValidVersion( String version ) + { + return StringUtils.isNotEmpty( version ) && !StringUtils.isWhitespace( version ); + } + + private boolean isMatchingPlugin( Plugin source, PluginWrapper plugin ) + { + return source.getArtifactId().equals( plugin.getArtifactId() ) + && source.getGroupId().equals( plugin.getGroupId() ); + } + + /** + * Checks if is snapshot. + * + * @param baseVersion the base version + * @return true, if is snapshot + */ + protected boolean isSnapshot( String baseVersion ) + { + if ( banTimestamps ) + { + return Artifact.VERSION_FILE_PATTERN.matcher( baseVersion ).matches() + || baseVersion.endsWith( Artifact.SNAPSHOT_VERSION ); + } + else + { + return baseVersion.endsWith( Artifact.SNAPSHOT_VERSION ); + } + } + + /* + * Uses borrowed lifecycle code to get a list of all plugins bound to the lifecycle. + */ + /** + * Gets the all plugins. + * + * @param project the project + * @param lifecycle the lifecycle + * @return the all plugins + * @throws PluginNotFoundException the plugin not found exception + * @throws LifecycleExecutionException the lifecycle execution exception + */ + private Set getAllPlugins( MavenProject project, Lifecycle lifecycle ) + throws PluginNotFoundException, LifecycleExecutionException + + { + log.debug( "RequirePluginVersions.getAllPlugins:" ); + + Set plugins = new HashSet<>(); + // first, bind those associated with the packaging + Map mappings = findMappingsForLifecycle( project, lifecycle ); + + for ( Map.Entry entry : mappings.entrySet() ) + { + log.debug( " lifecycleMapping = " + entry.getKey() ); + String pluginsForLifecycle = (String) entry.getValue(); + log.debug( " plugins = " + pluginsForLifecycle ); + if ( StringUtils.isNotEmpty( pluginsForLifecycle ) ) + { + String pluginList[] = pluginsForLifecycle.split( "," ); + for ( String plugin : pluginList ) + { + plugin = StringUtils.strip( plugin ); + log.debug( " plugin = " + plugin ); + String tokens[] = plugin.split( ":" ); + log.debug( " GAV = " + Arrays.asList( tokens ) ); + + Plugin p = new Plugin(); + p.setGroupId( tokens[0] ); + p.setArtifactId( tokens[1] ); + plugins.add( p ); + } + } + } + + List mojos = findOptionalMojosForLifecycle( project, lifecycle ); + for ( String value : mojos ) + { + String tokens[] = value.split( ":" ); + + Plugin plugin = new Plugin(); + plugin.setGroupId( tokens[0] ); + plugin.setArtifactId( tokens[1] ); + plugins.add( plugin ); + } + + plugins.addAll( project.getBuildPlugins() ); + + return plugins; + } + + /* + * NOTE: All the code following this point was scooped from the DefaultLifecycleExecutor. There must be a better way + * but for now it should work. + */ + /** + * Gets the phase to lifecycle map. + * + * @return the phase to lifecycle map + * @throws LifecycleExecutionException the lifecycle execution exception + */ + public Map getPhaseToLifecycleMap() + throws LifecycleExecutionException + { + if ( phaseToLifecycleMap == null ) + { + phaseToLifecycleMap = new HashMap<>(); + + for ( Lifecycle lifecycle : lifecycles ) + { + List phases = lifecycle.getPhases(); + for ( String phase : phases ) + { + log.debug( "getPhaseToLifecycleMap(): phase: " + phase ); + if ( phaseToLifecycleMap.containsKey( phase ) ) + { + Lifecycle prevLifecycle = (Lifecycle) phaseToLifecycleMap.get( phase ); + throw new LifecycleExecutionException( "Phase '" + phase + + "' is defined in more than one lifecycle: '" + lifecycle.getId() + "' and '" + + prevLifecycle.getId() + "'" ); + } + else + { + phaseToLifecycleMap.put( phase, lifecycle ); + } + } + } + } + return phaseToLifecycleMap; + } + + /** + * Gets the lifecycle for phase. + * + * @param phase the phase + * @return the lifecycle for phase + * @throws BuildFailureException the build failure exception + * @throws LifecycleExecutionException the lifecycle execution exception + */ + private Lifecycle getLifecycleForPhase( String phase ) + throws BuildFailureException, LifecycleExecutionException + { + Lifecycle lifecycle = getPhaseToLifecycleMap().get( phase ); + + if ( lifecycle == null ) + { + throw new BuildFailureException( "Unable to find lifecycle for phase '" + phase + "'" ); + } + return lifecycle; + } + + /** + * Find mappings for lifecycle. + * + * @param project the project + * @param lifecycle the lifecycle + * @return the map + * @throws LifecycleExecutionException the lifecycle execution exception + * @throws PluginNotFoundException the plugin not found exception + */ + private Map findMappingsForLifecycle( MavenProject project, Lifecycle lifecycle ) + throws LifecycleExecutionException, PluginNotFoundException + { + String packaging = project.getPackaging(); + Map mappings = null; + + LifecycleMapping m = (LifecycleMapping) findExtension( project, LifecycleMapping.ROLE, packaging, + session.getSettings(), session.getLocalRepository() ); + if ( m != null ) + { + mappings = m.getPhases( lifecycle.getId() ); + } + + Map defaultMappings = lifecycle.getDefaultPhases(); + + if ( mappings == null ) + { + try + { + m = helper.getComponent( LifecycleMapping.class, packaging ); + mappings = m.getPhases( lifecycle.getId() ); + } + catch ( ComponentLookupException e ) + { + if ( defaultMappings == null ) + { + throw new LifecycleExecutionException( "Cannot find lifecycle mapping for packaging: \'" + packaging + + "\'.", e ); + } + } + } + + if ( mappings == null ) + { + if ( defaultMappings == null ) + { + throw new LifecycleExecutionException( "Cannot find lifecycle mapping for packaging: \'" + packaging + + "\', and there is no default" ); + } + else + { + mappings = defaultMappings; + } + } + + return mappings; + } + + /** + * Find optional mojos for lifecycle. + * + * @param project the project + * @param lifecycle the lifecycle + * @return the list + * @throws LifecycleExecutionException the lifecycle execution exception + * @throws PluginNotFoundException the plugin not found exception + */ + private List findOptionalMojosForLifecycle( MavenProject project, Lifecycle lifecycle ) + throws LifecycleExecutionException, PluginNotFoundException + { + String packaging = project.getPackaging(); + List optionalMojos = null; + + LifecycleMapping m = (LifecycleMapping) findExtension( project, LifecycleMapping.ROLE, packaging, + session.getSettings(), session.getLocalRepository() ); + + if ( m != null ) + { + optionalMojos = m.getOptionalMojos( lifecycle.getId() ); + } + + if ( optionalMojos == null ) + { + try + { + m = helper.getComponent( LifecycleMapping.class, packaging ); + optionalMojos = m.getOptionalMojos( lifecycle.getId() ); + } + catch ( ComponentLookupException e ) + { + log.debug( "Error looking up lifecycle mapping to retrieve optional mojos. Lifecycle ID: " + + lifecycle.getId() + ". Error: " + e.getMessage(), e ); + } + } + + if ( optionalMojos == null ) + { + optionalMojos = Collections.emptyList(); + } + + return optionalMojos; + } + + /** + * Find extension. + * + * @param project the project + * @param role the role + * @param roleHint the role hint + * @param settings the settings + * @param localRepository the local repository + * @return the object + * @throws LifecycleExecutionException the lifecycle execution exception + * @throws PluginNotFoundException the plugin not found exception + */ + private Object findExtension( MavenProject project, String role, String roleHint, Settings settings, + ArtifactRepository localRepository ) + throws LifecycleExecutionException, PluginNotFoundException + { + Object pluginComponent = null; + + List buildPlugins = project.getBuildPlugins(); + for ( Plugin plugin : buildPlugins ) + { + if ( plugin.isExtensions() ) + { + verifyPlugin( plugin, project, settings, localRepository ); + + // TODO: if moved to the plugin manager we + // already have the descriptor from above + // and so do can lookup the container + // directly + try + { + pluginComponent = pluginManager.getPluginComponent( plugin, role, roleHint ); + + if ( pluginComponent != null ) + { + break; + } + } + catch ( ComponentLookupException e ) + { + log.debug( "Unable to find the lifecycle component in the extension", e ); + } + catch ( PluginManagerException e ) + { + throw new LifecycleExecutionException( "Error getting extensions from the plugin '" + + plugin.getKey() + "': " + e.getMessage(), e ); + } + } + } + return pluginComponent; + } + + /** + * Verify plugin. + * + * @param plugin the plugin + * @param project the project + * @param settings the settings + * @param localRepository the local repository + * @return the plugin descriptor + * @throws LifecycleExecutionException the lifecycle execution exception + * @throws PluginNotFoundException the plugin not found exception + */ + private PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings, + ArtifactRepository localRepository ) + throws LifecycleExecutionException, PluginNotFoundException + { + PluginDescriptor pluginDescriptor; + try + { + pluginDescriptor = pluginManager.verifyPlugin( plugin, project, settings, localRepository ); + } + catch ( PluginManagerException e ) + { + throw new LifecycleExecutionException( "Internal error in the plugin manager getting plugin '" + + plugin.getKey() + "': " + e.getMessage(), e ); + } + catch ( PluginVersionResolutionException | InvalidVersionSpecificationException | InvalidPluginException + | ArtifactNotFoundException | ArtifactResolutionException | PluginVersionNotFoundException e ) + { + throw new LifecycleExecutionException( e.getMessage(), e ); + } + return pluginDescriptor; + } + + /** + * Gets all plugin entries in build.plugins, build.pluginManagement.plugins, profile.build.plugins, reporting and + * profile.reporting in this project and all parents + * + * @param project the project + * @return the all plugin entries wrapped in a PluginWrapper Object + * @throws ArtifactResolutionException the artifact resolution exception + * @throws ArtifactNotFoundException the artifact not found exception + * @throws IOException Signals that an I/O exception has occurred. + * @throws XmlPullParserException the xml pull parser exception + */ + protected List getAllPluginEntries( MavenProject project ) + throws ArtifactResolutionException, ArtifactNotFoundException, IOException, XmlPullParserException + { + List models = new ArrayList<>(); + + List sortedProjects = session.getProjectDependencyGraph().getSortedProjects(); + + if ( !sortedProjects.isEmpty() && sortedProjects.get( 0 ).getParent() != null ) + { + getOriginalModelFromAllParents( models, sortedProjects ); + } + + for ( MavenProject mavenProject : sortedProjects ) + { + models.add( mavenProject.getOriginalModel() ); + } + + List plugins = new ArrayList<>(); + // now find all the plugin entries, either in + // build.plugins or build.pluginManagement.plugins, profiles.plugins and reporting + for ( Model model : models ) + { + getPlugins( plugins, model ); + getReportingPlugins( plugins, model ); + getPluginManagementPlugins( plugins, model ); + + addPluginsInProfiles( plugins, model ); + } + + return plugins; + } + + private void getOriginalModelFromAllParents( List models, List sortedProjects ) + { + MavenProject parent = sortedProjects.get( 0 ).getParent(); + do + { + models.add( parent.getOriginalModel() ); + parent = parent.getParent(); + } + while ( parent != null ); + } + + private void addPluginsInProfiles( List plugins, Model model ) + { + List profiles = model.getProfiles(); + for ( Profile profile : profiles ) + { + getProfilePlugins( plugins, model, profile ); + getProfileReportingPlugins( plugins, model, profile ); + getProfilePluginManagementPlugins( plugins, model, profile ); + } + } + + private void getProfilePluginManagementPlugins( List plugins, Model model, Profile profile ) + { + try + { + List modelPlugins = profile.getBuild().getPluginManagement().getPlugins(); + plugins.addAll( PluginWrapper.addAll( utils.resolvePlugins( modelPlugins ), model.getId() + "profile[" + + profile.getId() + "].build.pluginManagement.plugins" ) ); + } + catch ( NullPointerException e ) + { + // guess there are no plugins here. + } + } + + private void getProfileReportingPlugins( List plugins, Model model, Profile profile ) + { + try + { + List modelReportPlugins = profile.getReporting().getPlugins(); + // add the reporting plugins + plugins.addAll( PluginWrapper.addAll( utils.resolveReportPlugins( modelReportPlugins ), model.getId() + + "profile[" + profile.getId() + "].reporting.plugins" ) ); + } + catch ( NullPointerException e ) + { + // guess there are no plugins here. + } + } + + private void getProfilePlugins( List plugins, Model model, Profile profile ) + { + try + { + List modelPlugins = profile.getBuild().getPlugins(); + plugins.addAll( PluginWrapper.addAll( utils.resolvePlugins( modelPlugins ), model.getId() + + ".profiles.profile[" + profile.getId() + "].build.plugins" ) ); + } + catch ( NullPointerException e ) + { + // guess there are no plugins here. + } + } + + private void getPlugins( List plugins, Model model ) + { + try + { + List modelPlugins = model.getBuild().getPlugins(); + plugins.addAll( PluginWrapper.addAll( utils.resolvePlugins( modelPlugins ), + model.getId() + ".build.plugins" ) ); + } + catch ( NullPointerException e ) + { + // guess there are no plugins here. + } + } + + private void getPluginManagementPlugins( List plugins, Model model ) + { + try + { + List modelPlugins = model.getBuild().getPluginManagement().getPlugins(); + plugins.addAll( PluginWrapper.addAll( utils.resolvePlugins( modelPlugins ), + model.getId() + ".build.pluginManagement.plugins" ) ); + } + catch ( NullPointerException e ) + { + // guess there are no plugins here. + } + } + + private void getReportingPlugins( List plugins, Model model ) + { + try + { + List modelReportPlugins = model.getReporting().getPlugins(); + // add the reporting plugins + plugins.addAll( PluginWrapper.addAll( utils.resolveReportPlugins( modelReportPlugins ), + model.getId() + ".reporting" ) ); + } + catch ( NullPointerException e ) + { + // guess there are no plugins here. + } + } + + /** + * Checks if is ban latest. + * + * @return the banLatest + */ + protected boolean isBanLatest() + { + return this.banLatest; + } + + /** + * Sets the ban latest. + * + * @param theBanLatest the banLatest to set + */ + protected void setBanLatest( boolean theBanLatest ) + { + this.banLatest = theBanLatest; + } + + /** + * Checks if is ban release. + * + * @return the banRelease + */ + protected boolean isBanRelease() + { + return this.banRelease; + } + + /** + * Sets the ban release. + * + * @param theBanRelease the banRelease to set + */ + protected void setBanRelease( boolean theBanRelease ) + { + this.banRelease = theBanRelease; + } + + /** + * Gets the utils. + * + * @return the utils + */ + protected EnforcerRuleUtils getUtils() + { + return this.utils; + } + + /** + * Sets the utils. + * + * @param theUtils the utils to set + */ + protected void setUtils( EnforcerRuleUtils theUtils ) + { + this.utils = theUtils; + } + + /** + * Checks if is ban snapshots. + * + * @return the banSnapshots + */ + public boolean isBanSnapshots() + { + return this.banSnapshots; + } + + /** + * Sets the ban snapshots. + * + * @param theBanSnapshots the banSnapshots to set + */ + public void setBanSnapshots( boolean theBanSnapshots ) + { + this.banSnapshots = theBanSnapshots; + } + + /** + * Checks if is ban timestamps. + * + * @return the banTimestamps + */ + public boolean isBanTimestamps() + { + return this.banTimestamps; + } + + /** + * Sets the ban timestamps. + * + * @param theBanTimestamps the banTimestamps to set + */ + public void setBanTimestamps( boolean theBanTimestamps ) + { + this.banTimestamps = theBanTimestamps; + } + + public List getUnCheckedPlugins() + { + return unCheckedPlugins; + } + + public void setUnCheckedPlugins( List unCheckedPlugins ) + { + this.unCheckedPlugins = unCheckedPlugins; + } + + public final void setPhases( String phases ) + { + this.phases = phases; + } + + public final String getPhases() + { + return phases; + } + + public final void setAdditionalPlugins( List additionalPlugins ) + { + this.additionalPlugins = additionalPlugins; + } + + public final List getAdditionalPlugins() + { + return additionalPlugins; + } +} diff --git a/Java/maven-enforcer-RequirePluginVersions_410/metadata.json b/Java/maven-enforcer-RequirePluginVersions_410/metadata.json new file mode 100644 index 000000000..69669049f --- /dev/null +++ b/Java/maven-enforcer-RequirePluginVersions_410/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-enforcer-RequirePluginVersions_410", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn clean test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java", + "line": 418, + "npe_method": "addAdditionalPlugins", + "deref_field": "existing", + "npe_class": "RequirePluginVersions", + "repo": "maven-enforcer", + "bug_id": "RequirePluginVersions_410" + } +} diff --git a/Java/maven-enforcer-RequirePluginVersions_410/npe.json b/Java/maven-enforcer-RequirePluginVersions_410/npe.json new file mode 100644 index 000000000..87455dfcc --- /dev/null +++ b/Java/maven-enforcer-RequirePluginVersions_410/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java", + "line": 418, + "npe_method": "addAdditionalPlugins", + "deref_field": "existing", + "npe_class": "RequirePluginVersions" +} \ No newline at end of file diff --git a/Java/maven-enforcer-RequirePrerequisite_101/Dockerfile b/Java/maven-enforcer-RequirePrerequisite_101/Dockerfile new file mode 100644 index 000000000..3581e6769 --- /dev/null +++ b/Java/maven-enforcer-RequirePrerequisite_101/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-enforcer + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-enforcer-RequirePrerequisite_101/buggy.java b/Java/maven-enforcer-RequirePrerequisite_101/buggy.java new file mode 100644 index 000000000..ed98e4b18 --- /dev/null +++ b/Java/maven-enforcer-RequirePrerequisite_101/buggy.java @@ -0,0 +1,109 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.util.List; + +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.model.Prerequisites; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; + +/** + * @author Robert Scholte + * @since 1.3 + */ +public class RequirePrerequisite + extends AbstractNonCacheableEnforcerRule +{ + /** + * Only the projects with one of these packagings will be enforced to have the correct prerequisite. + * + * @since 1.4 + */ + private List packagings; + + /** + * Can either be version or a range, e.g. {@code 2.2.1} or {@code [2.2.1,)} + */ + private String mavenVersion; + + /** + * Set the mavenVersion Can either be version or a range, e.g. {@code 2.2.1} or {@code [2.2.1,)} + * + * @param mavenVersion the version or {@code null} + */ + public void setMavenVersion( String mavenVersion ) + { + this.mavenVersion = mavenVersion; + } + + /** + * Only the projects with one of these packagings will be enforced to have the correct prerequisite. + * + * @since 1.4 + * @param packagings the list of packagings + */ + public void setPackagings( List packagings ) + { + this.packagings = packagings; + } + + @Override +public void execute(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper helper) throws org.apache.maven.enforcer.rule.api.EnforcerRuleException { + try { + org.apache.maven.project.MavenProject project = ((org.apache.maven.project.MavenProject) (helper.evaluate("${project}"))); + if ("pom".equals(project.getPackaging())) { + helper.getLog().debug("Packaging is pom, skipping requirePrerequisite rule"); + return; + } + if ((packagings != null) && (!packagings.contains(project.getPackaging()))) { + // CHECKSTYLE_OFF: LineLength + helper.getLog().debug(("Packaging is " + project.getPackaging()) + ", skipping requirePrerequisite rule"); + return; + // CHECKSTYLE_ON: LineLength + } + org.apache.maven.model.Prerequisites prerequisites = project.getPrerequisites(); + if (prerequisites == null) { + throw new org.apache.maven.enforcer.rule.api.EnforcerRuleException("Requires prerequisite not set"); + } + { + org.apache.maven.artifact.versioning.VersionRange requiredVersionRange = org.apache.maven.artifact.versioning.VersionRange.createFromVersionSpec(/* NPEX_NULL_EXP */ + mavenVersion); + if (!requiredVersionRange.hasRestrictions()) { + requiredVersionRange = org.apache.maven.artifact.versioning.VersionRange.createFromVersionSpec(("[" + mavenVersion) + ",)"); + } + org.apache.maven.artifact.versioning.VersionRange specifiedVersion = org.apache.maven.artifact.versioning.VersionRange.createFromVersionSpec(prerequisites.getMaven()); + org.apache.maven.artifact.versioning.VersionRange restrictedVersionRange = requiredVersionRange.restrict(specifiedVersion); + if (restrictedVersionRange.getRecommendedVersion() == null) { + throw new org.apache.maven.enforcer.rule.api.EnforcerRuleException((("The specified Maven prerequisite( " + specifiedVersion) + " ) doesn't match the required version: ") + mavenVersion); + } + } + } catch (org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException e) { + throw new org.apache.maven.enforcer.rule.api.EnforcerRuleException(e.getMessage(), e); + } catch (org.apache.maven.artifact.versioning.InvalidVersionSpecificationException e) { + throw new org.apache.maven.enforcer.rule.api.EnforcerRuleException(e.getMessage(), e); + } +} + +} diff --git a/Java/maven-enforcer-RequirePrerequisite_101/metadata.json b/Java/maven-enforcer-RequirePrerequisite_101/metadata.json new file mode 100644 index 000000000..fda5ebc84 --- /dev/null +++ b/Java/maven-enforcer-RequirePrerequisite_101/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-enforcer-RequirePrerequisite_101", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn clean test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePrerequisite.java", + "line": 92, + "npe_method": "execute", + "deref_field": "mavenVersion", + "npe_class": "RequirePrerequisite", + "repo": "maven-enforcer", + "bug_id": "RequirePrerequisite_101" + } +} diff --git a/Java/maven-enforcer-RequirePrerequisite_101/npe.json b/Java/maven-enforcer-RequirePrerequisite_101/npe.json new file mode 100644 index 000000000..3d0e0b534 --- /dev/null +++ b/Java/maven-enforcer-RequirePrerequisite_101/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePrerequisite.java", + "line": 92, + "npe_method": "execute", + "deref_field": "mavenVersion", + "npe_class": "RequirePrerequisite" +} \ No newline at end of file diff --git a/Java/maven-enforcer-RequirePrerequisite_96/Dockerfile b/Java/maven-enforcer-RequirePrerequisite_96/Dockerfile new file mode 100644 index 000000000..3581e6769 --- /dev/null +++ b/Java/maven-enforcer-RequirePrerequisite_96/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/kupl/starlab-benchmarks/java-base:maven-enforcer + +ENV TZ=Asia/Seoul + +COPY ./metadata.json . +COPY ./npe.json . +COPY ./buggy.java /tmp/buggy.java +RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ + && export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ + && export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ + && mv /tmp/buggy.java $BUGGY_PATH \ + && echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json + +RUN git init . && git add -A + +RUN $(cat metadata.json | jq -r ".buildCommand") + +RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi diff --git a/Java/maven-enforcer-RequirePrerequisite_96/buggy.java b/Java/maven-enforcer-RequirePrerequisite_96/buggy.java new file mode 100644 index 000000000..84bdf889d --- /dev/null +++ b/Java/maven-enforcer-RequirePrerequisite_96/buggy.java @@ -0,0 +1,108 @@ +package org.apache.maven.plugins.enforcer; + +/* + * 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. + */ + +import java.util.List; + +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.model.Prerequisites; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; + +/** + * @author Robert Scholte + * @since 1.3 + */ +public class RequirePrerequisite + extends AbstractNonCacheableEnforcerRule +{ + /** + * Only the projects with one of these packagings will be enforced to have the correct prerequisite. + * + * @since 1.4 + */ + private List packagings; + + /** + * Can either be version or a range, e.g. {@code 2.2.1} or {@code [2.2.1,)} + */ + private String mavenVersion; + + /** + * Set the mavenVersion Can either be version or a range, e.g. {@code 2.2.1} or {@code [2.2.1,)} + * + * @param mavenVersion the version or {@code null} + */ + public void setMavenVersion( String mavenVersion ) + { + this.mavenVersion = mavenVersion; + } + + /** + * Only the projects with one of these packagings will be enforced to have the correct prerequisite. + * + * @since 1.4 + * @param packagings the list of packagings + */ + public void setPackagings( List packagings ) + { + this.packagings = packagings; + } + + @Override +public void execute(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper helper) throws org.apache.maven.enforcer.rule.api.EnforcerRuleException { + try { + org.apache.maven.project.MavenProject project = ((org.apache.maven.project.MavenProject) (helper.evaluate("${project}"))); + if ("pom".equals(project.getPackaging())) { + helper.getLog().debug("Packaging is pom, skipping requirePrerequisite rule"); + return; + } + if ((packagings != null) && (!packagings.contains(project.getPackaging()))) { + // CHECKSTYLE_OFF: LineLength + helper.getLog().debug(("Packaging is " + project.getPackaging()) + ", skipping requirePrerequisite rule"); + return; + // CHECKSTYLE_ON: LineLength + } + org.apache.maven.model.Prerequisites prerequisites = project.getPrerequisites(); + { + if (mavenVersion != null) { + org.apache.maven.artifact.versioning.VersionRange requiredVersionRange = org.apache.maven.artifact.versioning.VersionRange.createFromVersionSpec(mavenVersion); + if (!requiredVersionRange.hasRestrictions()) { + requiredVersionRange = org.apache.maven.artifact.versioning.VersionRange.createFromVersionSpec(("[" + mavenVersion) + ",)"); + } + org.apache.maven.artifact.versioning.VersionRange specifiedVersion = org.apache.maven.artifact.versioning.VersionRange.createFromVersionSpec(/* NPEX_NULL_EXP */ + prerequisites.getMaven()); + org.apache.maven.artifact.versioning.VersionRange restrictedVersionRange = requiredVersionRange.restrict(specifiedVersion); + if (restrictedVersionRange.getRecommendedVersion() == null) { + throw new org.apache.maven.enforcer.rule.api.EnforcerRuleException((("The specified Maven prerequisite( " + specifiedVersion) + " ) doesn't match the required version: ") + mavenVersion); + } + } + } + } catch (org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException e) { + throw new org.apache.maven.enforcer.rule.api.EnforcerRuleException(e.getMessage(), e); + } catch (org.apache.maven.artifact.versioning.InvalidVersionSpecificationException e) { + throw new org.apache.maven.enforcer.rule.api.EnforcerRuleException(e.getMessage(), e); + } +} + +} diff --git a/Java/maven-enforcer-RequirePrerequisite_96/metadata.json b/Java/maven-enforcer-RequirePrerequisite_96/metadata.json new file mode 100644 index 000000000..f030b668c --- /dev/null +++ b/Java/maven-enforcer-RequirePrerequisite_96/metadata.json @@ -0,0 +1,21 @@ +{ + "language": "java", + "id": "maven-enforcer-RequirePrerequisite_96", + "buggyPath": ".", + "referencePath": null, + "buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", + "testCommand": "mvn clean test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", + "categories": [ + "safety", + "npe" + ], + "npe": { + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePrerequisite.java", + "line": 94, + "npe_method": "execute", + "deref_field": "prerequisites", + "npe_class": "RequirePrerequisite", + "repo": "maven-enforcer", + "bug_id": "RequirePrerequisite_96" + } +} diff --git a/Java/maven-enforcer-RequirePrerequisite_96/npe.json b/Java/maven-enforcer-RequirePrerequisite_96/npe.json new file mode 100644 index 000000000..1b8b2be98 --- /dev/null +++ b/Java/maven-enforcer-RequirePrerequisite_96/npe.json @@ -0,0 +1,7 @@ +{ + "filepath": "enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePrerequisite.java", + "line": 94, + "npe_method": "execute", + "deref_field": "prerequisites", + "npe_class": "RequirePrerequisite" +} \ No newline at end of file