Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNG-7939] Allow to exclude plugins from validation #320

Merged
merged 1 commit into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* 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.
*/
package org.apache.maven.it;

import java.io.File;
import java.util.List;

import org.apache.maven.shared.verifier.Verifier;
import org.apache.maven.shared.verifier.util.ResourceExtractor;
import org.junit.jupiter.api.Test;

/**
* This is a test set for
* <a href="https://issues.apache.org/jira/browse/MNG-7939">MNG-7939</a>.
* Allow to exclude plugins from validation
*/
class MavenITmng7939PluginsValidationExcludesTest extends AbstractMavenIntegrationTestCase {

protected MavenITmng7939PluginsValidationExcludesTest() {
super("[4.0.0-alpha-9,)");
}

@Test
void warningForPluginValidationIsPresentInProject() throws Exception {
File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-7939-plugins-validation-excludes");

Verifier verifier = newVerifier(testDir.getAbsolutePath());
verifier.setAutoclean(false);
verifier.setLogFileName("with-warning-log.txt");
verifier.deleteDirectory("target");
verifier.addCliArgument("-Dmaven.plugin.validation=verbose");
verifier.addCliArgument("validate");
verifier.execute();
verifier.verifyErrorFreeLog();

List<String> logs = verifier.loadLines(verifier.getLogFileName(), null);

verifyTextInLog(logs, "[INFO] [MAVEN-CORE-IT-LOG] localRepository");
verifyTextInLog(logs, "[WARNING] * org.apache.maven.its.plugins:maven-it-plugin-configuration:2.1-SNAPSHOT");
verifyTextInLog(
logs, "[WARNING] Plugin [INTERNAL, EXTERNAL] validation issues were detected in following plugin(s)");
verifyTextInLog(
logs, "[WARNING] * Mojo itconfiguration:localRepo (org.apache.maven.plugin.coreit.LocalRepoMojo)");
verifyTextInLog(
logs,
"[WARNING] - Parameter 'localRepository' uses deprecated parameter expression '${localRepository}'");
}

@Test
void excludePluginFromValidation() throws Exception {
File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-7939-plugins-validation-excludes");

Verifier verifier = newVerifier(testDir.getAbsolutePath());
verifier.setAutoclean(false);
verifier.setLogFileName("without-warning-log.txt");
verifier.deleteDirectory("target");
verifier.addCliArgument("-Dmaven.plugin.validation=verbose");
verifier.addCliArgument(
"-Dmaven.plugin.validation.excludes=org.apache.maven.its.plugins:maven-it-plugin-configuration:2.1-SNAPSHOT");
verifier.addCliArgument("validate");
verifier.execute();
verifier.verifyErrorFreeLog();

List<String> logs = verifier.loadLines(verifier.getLogFileName(), null);

verifyTextInLog(logs, "[INFO] [MAVEN-CORE-IT-LOG] localRepository");
verifyTextNotInLog(
logs, "[WARNING] * org.apache.maven.its.plugins:maven-it-plugin-configuration:2.1-SNAPSHOT");
verifyTextNotInLog(
logs, "[WARNING] Plugin [INTERNAL, EXTERNAL] validation issues were detected in following plugin(s)");
verifyTextNotInLog(
logs, "[WARNING] * Mojo itconfiguration:localRepo (org.apache.maven.plugin.coreit.LocalRepoMojo)");
verifyTextNotInLog(
logs,
"[WARNING] - Parameter 'localRepository' uses deprecated parameter expression '${localRepository}'");
}

private void verifyTextInLog(List<String> logs, String text) {
assertTrue("Log file not contains: " + text, logs.stream().anyMatch(l -> l.contains(text)));
}

private void verifyTextNotInLog(List<String> logs, String text) {
assertFalse("Log file contains: " + text, logs.stream().anyMatch(l -> l.contains(text)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public TestSuiteOrdering() {
* the tests are to finishing. Newer tests are also more likely to fail, so this is
* a fail fast technique as well.
*/
suite.addTestSuite(MavenITmng7939PluginsValidationExcludesTest.class);
suite.addTestSuite(MavenITmng7837ProjectElementInPomTest.class);
suite.addTestSuite(MavenITmng7804PluginExecutionOrderTest.class);
suite.addTestSuite(MavenITmng7836AlternativePomSyntaxTest.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.its.mng7939</groupId>
<artifactId>test</artifactId>
<version>1.0.0-SNAPSHOT</version>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-configuration</artifactId>
<version>2.1-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>localRepo</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.
*/
package org.apache.maven.plugin.coreit;

import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

/**
* simple Mojo using detracted localRepository, in order to test plugin verification
*/
@Mojo(name = "localRepo", defaultPhase = LifecyclePhase.VALIDATE)
public class LocalRepoMojo extends AbstractMojo {

@Parameter(defaultValue = "${localRepository}", readonly = true)
private ArtifactRepository localRepository;

public void execute() throws MojoExecutionException {
getLog().info("[MAVEN-CORE-IT-LOG] localRepository " + localRepository);
}
}