Skip to content

Commit

Permalink
mojohaus#517: optionally support copyright values that only contain i…
Browse files Browse the repository at this point in the history
…nception year rather than year range
  • Loading branch information
d-ryan-ashcraft committed Oct 18, 2023
1 parent f59f6ec commit f6d693a
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/it/inception-year-only-copyright-format/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Integration test for issue #517

## description

Verify that the copyright statement format can be restricted to use inception year only
23 changes: 23 additions & 0 deletions src/it/inception-year-only-copyright-format/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
###
# #%L
# License Maven Plugin
# %%
# Copyright (C) 2008 - 2020 CodeLutin, Codehaus, Tony Chemit
# %%
# 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=clean package
invoker.failureBehavior=fail-fast
117 changes: 117 additions & 0 deletions src/it/inception-year-only-copyright-format/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<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.codehaus.mojo.license.test</groupId>
<artifactId>test-inception-year-only-copyright-format</artifactId>
<version>1.0</version>
<name>License Test :: inception-year-only-copyright-format</name>
<packaging>jar</packaging>

<organization>
<name>org.example</name>
</organization>

<inceptionYear>2023</inceptionYear>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>

<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>@maven-compiler-plugin.version@</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>

<plugins>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>@build-helper-maven-plugin.version@</version>
<executions>
<execution>
<id>add-generated-source-directory</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>@maven-resources-plugin.version@</version>

<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>

<outputDirectory>${project.build.directory}/generated-sources</outputDirectory>

<resources>
<resource>
<directory>src/main/original/java</directory>
<filtering>false</filtering>
<include>**/*.java</include>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>

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

<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>update-file-header</goal>
</goals>
<configuration>

<encoding>UTF-8</encoding>
<roots>
<root>${project.build.directory}/generated-sources</root>
</roots>

<ignoreLastDate>true</ignoreLastDate>

<licenseName>lgpl_v3</licenseName>

</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
29 changes: 29 additions & 0 deletions src/it/inception-year-only-copyright-format/postbuild.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* #%L
* License Maven Plugin
* %%
* Copyright (C) 2008 - 2020 CodeLutin, Codehaus, Tony Chemit
* %%
* 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, 'target/generated-sources/org/example/test/SampleFile.java');
assert file.exists();
content = file.text;

assert content.contains('Copyright (C) 2023 org.example');

return true;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.example.test;
import java.io.File;


public class SampleFile {
public static void main(String[] args) {
File file = new File(args[0]);
System.out.println(file.getAbsolutePath());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@Deprecated
package org.example.test;
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ public abstract class AbstractLicenseNameMojo extends AbstractLicenseMojo {
@Parameter
protected Map<String, String> extraTemplateParameters;

/**
* Ignore the last date for copyright year range.
*
* @since 2.3.0
*/
@Parameter(property = "license.ignoreLastDate", defaultValue = "false")
protected boolean ignoreLastDate;

// ----------------------------------------------------------------------
// Private Fields
// ----------------------------------------------------------------------
Expand Down Expand Up @@ -276,7 +284,9 @@ protected String processLicenseContext(String licenseContent) throws IOException
}

Copyright getCopyright(String copyrightStringFormat, String holder) {
return Copyright.newCopyright(copyrightStringFormat, inceptionYear, holder);
return (ignoreLastDate)
? Copyright.newCopyright(copyrightStringFormat, inceptionYear, null, holder)
: Copyright.newCopyright(copyrightStringFormat, inceptionYear, holder);
}

/**
Expand Down

0 comments on commit f6d693a

Please sign in to comment.