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

Fix mismatching Parameter initial field values #418

Merged
merged 1 commit into from
Jul 2, 2024
Merged

Fix mismatching Parameter initial field values #418

merged 1 commit into from
Jul 2, 2024

Conversation

Marcono1234
Copy link
Contributor

@Marcono1234 Marcono1234 commented Jun 30, 2024

If I understand it correctly, if a Mojo parameter has a @Parameter#defaultValue, that value overwrites the initial value of the field (if any).

This pull request therefore fixes two cases where the initial field value did not match the @Parameter#defaultValue, which could have lead to confusion.

  • For AbstractFromDependenciesMojo#failOnMissingClassifierArtifact it seems this issue was accidentally introduced by 1592cdc#diff-b352be9b15d48a15ddf79e115c28c4cc776b7ec2662f553e189a978261d34881R100; the Javadoc had previously default-value="true", which was matching the field value true, and was accidentally changed to false.
    Though I am not going to adjust the default value to be true again since it has been false now for multiple years apparently.

    The test classes TestUnpackDependenciesMojo and TestCopyDependenciesMojo had to be adjusted because they were apparently not creating the Mojo instances they way Maven would normally do and therefore were relying on the field values instead of the defaultValue. For example when using the following pom.xml and running mvn package, you will see that the Dependency Plugin does not report an error for a missing classifier by default:

    pom.xml (click to expand)
    <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>com.mycompany.app</groupId>
      <artifactId>my-app</artifactId>
      <version>1.0-SNAPSHOT</version>
      
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>4.12</version>
        </dependency>
      </dependencies>
    
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>3.7.1</version>
            <executions>
              <execution>
                <id>copy-dependencies</id>
                <phase>package</phase>
                <goals>
                  <goal>copy-dependencies</goal>
                </goals>
                <configuration>
                  <classifier>does-not-exist</classifier>
                  <outputDirectory>${project.build.directory}/dependencies</outputDirectory>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </project>
  • For CopyDependenciesMojo#copyPom it looks like it always had this mismatch since it was added by 32a29e6


Following this checklist to help us incorporate your
contribution quickly and easily:

  • Make sure there is a JIRA issue filed
    for the change (usually before you start working on it). Trivial changes like typos do not
    require a JIRA issue. Your pull request should address just this issue, without
    pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [MDEP-XXX] - Fixes bug in ApproximateQuantiles,
    where you replace MDEP-XXX with the appropriate JIRA issue. Best practice
    is to use the JIRA issue title in the pull request title and in the first line of the
    commit message.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean verify to make sure basic checks pass. A more thorough check will
    be performed on your pull request automatically.
  • You have run the integration tests successfully (mvn -Prun-its clean verify).

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

Field values should match `defaultValue` of `Parameter` annotation.
Had to adjust the unit tests because they were apparently manually
constructing the Mojos and therefore not using the `Parameter#defaultValue`.

Also removes the parameters from `TestUnpackDependenciesMojo#dotestArtifactExceptions`
because they were apparently unused since commit 809bfe1.
dotestArtifactExceptions(true, false);
}

public void dotestArtifactExceptions(boolean are, boolean anfe) throws Exception {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the parameters from this test method because it looks like they were unused since 809bfe1, so testArtifactNotFound and testArtifactResolutionException were effectively equivalent.

@slawekjaranowski slawekjaranowski merged commit c729702 into apache:master Jul 2, 2024
20 checks passed
@Marcono1234 Marcono1234 deleted the wrong-field-default-value branch July 7, 2024 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants