Skip to content

Commit

Permalink
Fix #498 add-third-party should not override third-party file with th…
Browse files Browse the repository at this point in the history
…e same content
  • Loading branch information
slawekjaranowski committed Jul 1, 2023
1 parent c29552b commit 1c8fab2
Show file tree
Hide file tree
Showing 11 changed files with 282 additions and 40 deletions.
23 changes: 23 additions & 0 deletions src/it/add-third-party-skip-second-execution/invoker.properties
Original file line number Diff line number Diff line change
@@ -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
# <http://www.gnu.org/licenses/lgpl-3.0.html>.
# #L%
###
invoker.goals.1=clean license:add-third-party
invoker.goals.2=license:add-third-party
55 changes: 55 additions & 0 deletions src/it/add-third-party-skip-second-execution/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
#%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
<http://www.gnu.org/licenses/lgpl-3.0.html>.
#L%
-->

<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 https://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>org.codehaus.mojo.license.test</groupId>
<artifactId>add-third-party-skip-second-execution</artifactId>
<version>1.0.0</version>

<name>License Test :: add-third-party-skip-second-execution</name>
<url>https://github.com/mojohaus/license-maven-plugin/issues/498</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<license.generateBundle>true</license.generateBundle>
<license.verbose>true</license.verbose>
</properties>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>@project.version@</version>
</plugin>
</plugins>
</pluginManagement>
</build>

</project>
29 changes: 29 additions & 0 deletions src/it/add-third-party-skip-second-execution/postbuild.groovy
Original file line number Diff line number Diff line change
@@ -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
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #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');
40 changes: 40 additions & 0 deletions src/it/aggregate-add-third-party-second-execution/child1/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
#%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
<http://www.gnu.org/licenses/lgpl-3.0.html>.
#L%
-->

<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 https://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.codehaus.mojo.license.test</groupId>
<artifactId>aggregate-add-third-party-second-execution</artifactId>
<version>1.0.0</version>
</parent>

<artifactId>child1</artifactId>

</project>


Original file line number Diff line number Diff line change
@@ -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
# <http://www.gnu.org/licenses/lgpl-3.0.html>.
# #L%
###
invoker.goals.1=clean license:aggregate-add-third-party
invoker.goals.2=license:aggregate-add-third-party
64 changes: 64 additions & 0 deletions src/it/aggregate-add-third-party-second-execution/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
#%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
<http://www.gnu.org/licenses/lgpl-3.0.html>.
#L%
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>org.codehaus.mojo.license.test</groupId>
<artifactId>aggregate-add-third-party-second-execution</artifactId>
<version>1.0.0</version>

<modules>
<module>child1</module>
</modules>

<name>License Test :: aggregate-add-third-party-second-execution</name>
<url>https://github.com/mojohaus/license-maven-plugin/issues/498</url>

<packaging>pom</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<license.generateBundle>true</license.generateBundle>
<license.verbose>true</license.verbose>
</properties>

<build>

<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>@project.version@</version>
</plugin>
</plugins>
</pluginManagement>
</build>

</project>


29 changes: 29 additions & 0 deletions src/it/aggregate-add-third-party-second-execution/postbuild.groovy
Original file line number Diff line number Diff line change
@@ -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
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #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');
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -738,6 +738,10 @@ protected void init()
doGenerateBundle = false;
}

if ( shouldSkip() ) {
return;
}

projectDependencies = loadDependencies();

licenseMap = getHelper().createLicenseMap( projectDependencies );
Expand Down
23 changes: 5 additions & 18 deletions src/main/java/org/codehaus/mojo/license/AbstractLicenseMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
// ----------------------------------------------------------------------
Expand Down Expand Up @@ -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;
}

/**
Expand Down
10 changes: 2 additions & 8 deletions src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1c8fab2

Please sign in to comment.