diff --git a/src/it/add-third-party-skip-second-execution/invoker.properties b/src/it/add-third-party-skip-second-execution/invoker.properties new file mode 100644 index 000000000..20dd58c7a --- /dev/null +++ b/src/it/add-third-party-skip-second-execution/invoker.properties @@ -0,0 +1,23 @@ +### +# #%L +# License Maven Plugin +# %% +# Copyright (C) 2023 MojoHaus and Contributors +# %% +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Lesser Public License for more details. +# +# You should have received a copy of the GNU General Lesser Public +# License along with this program. If not, see +# . +# #L% +### +invoker.goals.1=clean license:add-third-party +invoker.goals.2=license:add-third-party diff --git a/src/it/add-third-party-skip-second-execution/pom.xml b/src/it/add-third-party-skip-second-execution/pom.xml new file mode 100644 index 000000000..c92b5ddb7 --- /dev/null +++ b/src/it/add-third-party-skip-second-execution/pom.xml @@ -0,0 +1,55 @@ + + + + + + 4.0.0 + + org.codehaus.mojo.license.test + add-third-party-skip-second-execution + 1.0.0 + + License Test :: add-third-party-skip-second-execution + https://github.com/mojohaus/license-maven-plugin/issues/498 + + + UTF-8 + true + true + + + + + + + org.codehaus.mojo + license-maven-plugin + @project.version@ + + + + + + diff --git a/src/it/add-third-party-skip-second-execution/postbuild.groovy b/src/it/add-third-party-skip-second-execution/postbuild.groovy new file mode 100644 index 000000000..395f02827 --- /dev/null +++ b/src/it/add-third-party-skip-second-execution/postbuild.groovy @@ -0,0 +1,29 @@ +/* + * #%L + * License Maven Plugin + * %% + * Copyright (C) 2023 MojoHaus and Contributors + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * . + * #L% + */ + +file = new File(basedir, 'build.log'); +assert file.exists(); +content = file.text; +assert 1 == content.count('[INFO] Writing third-party file to'); +assert 1 == content.count('[INFO] Writing bundled third-party file to'); +assert 1 == content.count('[INFO] All files are up to date, skip goal execution.'); +assert 2 == content.count('[INFO] BUILD SUCCESS'); diff --git a/src/it/aggregate-add-third-party-second-execution/child1/pom.xml b/src/it/aggregate-add-third-party-second-execution/child1/pom.xml new file mode 100644 index 000000000..e3693a3ff --- /dev/null +++ b/src/it/aggregate-add-third-party-second-execution/child1/pom.xml @@ -0,0 +1,40 @@ + + + + + + 4.0.0 + + + org.codehaus.mojo.license.test + aggregate-add-third-party-second-execution + 1.0.0 + + + child1 + + + + diff --git a/src/it/aggregate-add-third-party-second-execution/invoker.properties b/src/it/aggregate-add-third-party-second-execution/invoker.properties new file mode 100644 index 000000000..9d7487510 --- /dev/null +++ b/src/it/aggregate-add-third-party-second-execution/invoker.properties @@ -0,0 +1,23 @@ +### +# #%L +# License Maven Plugin +# %% +# Copyright (C) 2023 MojoHaus and Contributors +# %% +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Lesser Public License for more details. +# +# You should have received a copy of the GNU General Lesser Public +# License along with this program. If not, see +# . +# #L% +### +invoker.goals.1=clean license:aggregate-add-third-party +invoker.goals.2=license:aggregate-add-third-party diff --git a/src/it/aggregate-add-third-party-second-execution/pom.xml b/src/it/aggregate-add-third-party-second-execution/pom.xml new file mode 100644 index 000000000..34039eae7 --- /dev/null +++ b/src/it/aggregate-add-third-party-second-execution/pom.xml @@ -0,0 +1,64 @@ + + + + + + 4.0.0 + + org.codehaus.mojo.license.test + aggregate-add-third-party-second-execution + 1.0.0 + + + child1 + + + License Test :: aggregate-add-third-party-second-execution + https://github.com/mojohaus/license-maven-plugin/issues/498 + + pom + + + UTF-8 + true + true + + + + + + + + org.codehaus.mojo + license-maven-plugin + @project.version@ + + + + + + + + diff --git a/src/it/aggregate-add-third-party-second-execution/postbuild.groovy b/src/it/aggregate-add-third-party-second-execution/postbuild.groovy new file mode 100644 index 000000000..2245daad4 --- /dev/null +++ b/src/it/aggregate-add-third-party-second-execution/postbuild.groovy @@ -0,0 +1,29 @@ +/* + * #%L + * License Maven Plugin + * %% + * Copyright (C) 2023 MojoHaus and Contributors + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * . + * #L% + */ + +file = new File(basedir, 'build.log'); +assert file.exists(); +content = file.text; +assert 1 == content.count('[INFO] Writing third-party file to'); +assert 1 == content.count('[INFO] Writing bundled third-party file'); +assert 1 == content.count('[INFO] All files are up to date, skip goal execution.'); +assert 2 == content.count('[INFO] BUILD SUCCESS'); diff --git a/src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java b/src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java index f1fb67e07..4fbadf2c6 100644 --- a/src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java @@ -716,20 +716,20 @@ protected void init() thirdPartyFile = new File( outputDirectory, thirdPartyFilename ); - long buildTimestamp = getBuildTimestamp(); + File projectFile = project.getFile() != null ? project.getFile() : new File(""); - LOG.debug( "Build start at: {}", buildTimestamp ); - LOG.debug( "third-party file: {}", thirdPartyFile.lastModified() ); + LOG.debug( "project file: {} last modified: {}", projectFile, projectFile.lastModified() ); + LOG.debug( "third-party file: {} last modified: {}", thirdPartyFile, thirdPartyFile.lastModified() ); - doGenerate = force || !thirdPartyFile.exists() || buildTimestamp > thirdPartyFile.lastModified(); + doGenerate = force || !thirdPartyFile.exists() || projectFile.lastModified() > thirdPartyFile.lastModified(); if ( generateBundle ) { File bundleFile = FileUtil.getFile( outputDirectory, bundleThirdPartyPath ); - LOG.debug( "bundle third-party file: {}", bundleFile.lastModified() ); - doGenerateBundle = force || !bundleFile.exists() || buildTimestamp > bundleFile.lastModified(); + LOG.debug( "bundle third-party file: {} last modified: {}", bundleFile, bundleFile.lastModified() ); + doGenerateBundle = force || !bundleFile.exists() || projectFile.lastModified() > bundleFile.lastModified(); } else { @@ -738,6 +738,10 @@ protected void init() doGenerateBundle = false; } + if ( shouldSkip() ) { + return; + } + projectDependencies = loadDependencies(); licenseMap = getHelper().createLicenseMap( projectDependencies ); diff --git a/src/main/java/org/codehaus/mojo/license/AbstractLicenseMojo.java b/src/main/java/org/codehaus/mojo/license/AbstractLicenseMojo.java index 3b12e49c3..a837d618e 100644 --- a/src/main/java/org/codehaus/mojo/license/AbstractLicenseMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AbstractLicenseMojo.java @@ -186,14 +186,9 @@ public final void execute() } // check if mojo can be skipped - - canContinue = checkSkip(); - if ( !canContinue ) + if ( shouldSkip() ) { - if ( isVerbose() ) - { - LOG.info( "Goal will not be executed." ); - } + LOG.info( "All files are up to date, skip goal execution." ); return; } @@ -279,14 +274,6 @@ public final MavenSession getSession() return session; } - /** - * @return the build timestamp (used to have a unique timestamp all over a build). - */ - public final long getBuildTimestamp() - { - return session.getStartTime().getTime(); - } - // ---------------------------------------------------------------------- // Protected Methods // ---------------------------------------------------------------------- @@ -327,12 +314,12 @@ protected boolean checkPackaging() /** * Checks if the mojo execution should be skipped. * - * @return {@code false} if the mojo should not be executed. + * @return {@code true} if the mojo should not be executed. */ - protected boolean checkSkip() + protected boolean shouldSkip() { // by default, never skip goal - return true; + return false; } /** diff --git a/src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java b/src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java index 40272c07d..bb177f716 100644 --- a/src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java @@ -155,15 +155,9 @@ protected boolean checkPackaging() * {@inheritDoc} */ @Override - protected boolean checkSkip() + protected boolean shouldSkip() { - if ( !doGenerate && !doGenerateBundle && !doGenerateMissing ) - { - - LOG.info( "All files are up to date, skip goal execution." ); - return false; - } - return true; + return !doGenerate && !doGenerateBundle && !doGenerateMissing; } /** diff --git a/src/main/java/org/codehaus/mojo/license/AggregatorAddThirdPartyMojo.java b/src/main/java/org/codehaus/mojo/license/AggregatorAddThirdPartyMojo.java index 2c5745e0c..7579ad065 100644 --- a/src/main/java/org/codehaus/mojo/license/AggregatorAddThirdPartyMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AggregatorAddThirdPartyMojo.java @@ -130,15 +130,9 @@ protected boolean checkPackaging() * {@inheritDoc} */ @Override - protected boolean checkSkip() + protected boolean shouldSkip() { - if ( !doGenerate && !doGenerateBundle ) - { - - LOG.info( "All files are up to date, skip goal execution." ); - return false; - } - return super.checkSkip(); + return !doGenerate && !doGenerateBundle; } @Override