-
Notifications
You must be signed in to change notification settings - Fork 13
Add license header template for com.mycila:license-maven-plugin #1
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
Changes from all commits
5e53ecf
e9d06fe
0d66654
a3755ba
e825d5a
8fa5552
35c28b3
a6212ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
JBoss, Home of Professional Open Source | ||
Copyright 2012, Red Hat, Inc. and/or its affiliates, and individual | ||
contributors by the @authors tag. See the copyright.txt in the | ||
distribution for a full listing of individual contributors. | ||
|
||
Copyright 2014-2015 Red Hat, Inc. and/or its affiliates | ||
and other contributors as indicated by the @author tags. | ||
|
||
Licensed 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 | ||
|
||
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> | ||
|
@@ -79,21 +81,39 @@ | |
</distributionManagement> | ||
|
||
<properties> | ||
<checkstyle.version>6.1.1</checkstyle.version> | ||
<maven.compiler.source>1.6</maven.compiler.source> | ||
<maven.compiler.target>1.6</maven.compiler.target> | ||
|
||
<version.com.puppycrawl.tools.checkstyle>6.1.1</version.com.puppycrawl.tools.checkstyle> | ||
<version.com.mycila.license-maven-plugin>2.7</version.com.mycila.license-maven-plugin> | ||
<version.org.eclipse.jgit>3.6.1.201501031845-r</version.org.eclipse.jgit> | ||
<version.junit>4.12</version.junit> | ||
</properties> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor comment AFAIC, I don't see the value in extracting all versions to properties (I do see value when the version number is used twice or more) Is this a rule for POM writing we're supposed to obey or only your own practice? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because that's how it is done - not only usually but also in the Hawkular family. It is practical to do things in uniform ways so that one can find them quickly in a well defined location. Moreover, doing it the same way in the whole family of hawkular projects will make it easier to keep the same versions on multiple place. As far as I can see now, it will be inevitable to copy e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If it's been agreed then ok. |
||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.puppycrawl.tools</groupId> | ||
<artifactId>checkstyle</artifactId> | ||
<version>${checkstyle.version}</version> | ||
<version>${version.com.puppycrawl.tools.checkstyle}</version> | ||
</dependency> | ||
|
||
<!-- license header checking deps --> | ||
<dependency> | ||
<groupId>com.mycila</groupId> | ||
<artifactId>license-maven-plugin</artifactId> | ||
<version>${version.com.mycila.license-maven-plugin}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jgit</groupId> | ||
<artifactId>org.eclipse.jgit</artifactId> | ||
<version>${version.org.eclipse.jgit}</version> | ||
</dependency> | ||
|
||
<!-- test scope stuff --> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.11</version> | ||
<version>${version.junit}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
/* | ||
* Copyright 2014-2015 Red Hat, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed 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.hawkular.build.license; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
import java.util.TimeZone; | ||
|
||
import org.eclipse.jgit.api.errors.GitAPIException; | ||
import org.eclipse.jgit.api.errors.NoHeadException; | ||
import org.hawkular.build.license.GitLookup.DateSource; | ||
|
||
import com.mycila.maven.plugin.license.AbstractLicenseMojo; | ||
import com.mycila.maven.plugin.license.PropertiesProvider; | ||
import com.mycila.maven.plugin.license.document.Document; | ||
|
||
/** | ||
* An implementation of {@link PropertiesProvider} that adds {@value #COPYRIGHT_LAST_YEAR_KEY} and | ||
* {@value #COPYRIGHT_YEARS_KEY} values - see | ||
* {@link #getAdditionalProperties(AbstractLicenseMojo, Properties, Document)}. | ||
* | ||
* @author <a href="mailto:ppalaga@redhat.com">Peter Palaga</a> | ||
*/ | ||
public class CopyrightRangeProvider implements PropertiesProvider { | ||
|
||
public static final String COPYRIGHT_LAST_YEAR_KEY = "license.copyrightLastYear"; | ||
public static final String COPYRIGHT_LAST_YEAR_MAX_COMMITS_LOOKUP_KEY = "license.git.copyrightLastYearMaxCommitsLookup"; | ||
public static final String COPYRIGHT_LAST_YEAR_SOURCE_KEY = "license.git.copyrightLastYearSource"; | ||
public static final String COPYRIGHT_LAST_YEAR_TIME_ZONE_KEY = "license.git.copyrightLastYearTimeZone"; | ||
public static final String COPYRIGHT_YEARS_KEY = "license.copyrightYears"; | ||
public static final String INCEPTION_YEAR_KEY = "project.inceptionYear"; | ||
|
||
private volatile GitLookup gitLookup; | ||
|
||
public CopyrightRangeProvider() { | ||
super(); | ||
} | ||
|
||
/** | ||
* Returns an unmodifiable map containing two entries {@value #COPYRIGHT_LAST_YEAR_KEY} and | ||
* {@value #COPYRIGHT_YEARS_KEY} whose values are set based on inspecting git history. | ||
* <ul> | ||
* <li>{@value #COPYRIGHT_LAST_YEAR_KEY} key stores the year from the commiter date of the last git commit that has | ||
* modified the supplied {@code document}. | ||
* <li>{@value #COPYRIGHT_YEARS_KEY} key stores the range from {@value #INCEPTION_YEAR_KEY} value to | ||
* {@value #COPYRIGHT_LAST_YEAR_KEY} value. If both values a equal, only the {@value #INCEPTION_YEAR_KEY} value is | ||
* returned; otherwise, the two values are combined using dash, so that the result is e.g. {@code "2000 - 2010"}. | ||
* </ul> | ||
* The {@value #INCEPTION_YEAR_KEY} value is read from the supplied properties and it must available. Otherwise a | ||
* {@link RuntimeException} is thrown. | ||
* | ||
*/ | ||
public Map<String, String> getAdditionalProperties(AbstractLicenseMojo mojo, Properties properties, | ||
Document document) { | ||
String inceptionYear = properties.getProperty(INCEPTION_YEAR_KEY); | ||
if (inceptionYear == null) { | ||
throw new RuntimeException("'project.inceptionYear' must have a value for file " | ||
+ document.getFile().getAbsolutePath()); | ||
} | ||
try { | ||
Map<String, String> result = new HashMap<String, String>(3); | ||
String copyrightEnd = getGitLookup(document.getFile(), properties).getYearOfLastChange(document.getFile()); | ||
result.put(COPYRIGHT_LAST_YEAR_KEY, copyrightEnd); | ||
final String copyrightYears; | ||
if (inceptionYear.equals(copyrightEnd)) { | ||
copyrightYears = inceptionYear; | ||
} else { | ||
copyrightYears = inceptionYear + "-" + copyrightEnd; | ||
} | ||
result.put(COPYRIGHT_YEARS_KEY, copyrightYears); | ||
return Collections.unmodifiableMap(result); | ||
} catch (NoHeadException e) { | ||
throw new RuntimeException("Could not compute the year of the last git commit for file " | ||
+ document.getFile().getAbsolutePath(), e); | ||
} catch (GitAPIException e) { | ||
throw new RuntimeException("Could not compute the year of the last git commit for file " | ||
+ document.getFile().getAbsolutePath(), e); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Could not compute the year of the last git commit for file " | ||
+ document.getFile().getAbsolutePath(), e); | ||
} | ||
} | ||
|
||
/** | ||
* Lazily initializes #gitLookup assuming that all subsequent calls to this method will be related to the same | ||
* git repository. | ||
* | ||
* @param file | ||
* @return | ||
* @throws IOException | ||
*/ | ||
private GitLookup getGitLookup(File file, Properties props) throws IOException { | ||
if (gitLookup == null) { | ||
synchronized (this) { | ||
if (gitLookup == null) { | ||
String dateSourceString = props.getProperty(COPYRIGHT_LAST_YEAR_SOURCE_KEY, | ||
DateSource.AUTHOR.name()); | ||
DateSource dateSource = DateSource.valueOf(dateSourceString.toUpperCase(Locale.US)); | ||
String checkCommitsCountString = props.getProperty(COPYRIGHT_LAST_YEAR_MAX_COMMITS_LOOKUP_KEY); | ||
int checkCommitsCount = GitLookup.DEFAULT_COMMITS_COUNT; | ||
if (checkCommitsCountString != null) { | ||
checkCommitsCountString = checkCommitsCountString.trim(); | ||
checkCommitsCount = Integer.parseInt(checkCommitsCountString); | ||
} | ||
final TimeZone timeZone; | ||
String tzString = props.getProperty(COPYRIGHT_LAST_YEAR_TIME_ZONE_KEY); | ||
switch (dateSource) { | ||
case COMMITER: | ||
timeZone = tzString == null ? GitLookup.DEFAULT_ZONE : TimeZone.getTimeZone(tzString); | ||
break; | ||
case AUTHOR: | ||
if (tzString != null) { | ||
throw new RuntimeException(COPYRIGHT_LAST_YEAR_TIME_ZONE_KEY + " must not be set with " | ||
+ COPYRIGHT_LAST_YEAR_SOURCE_KEY + " = " + DateSource.AUTHOR.name() | ||
+ " because git author name already contrains time zone information."); | ||
} | ||
timeZone = null; | ||
break; | ||
default: | ||
throw new IllegalStateException("Unexpected " + DateSource.class.getName() + " " + dateSource); | ||
} | ||
gitLookup = new GitLookup(file, dateSource, timeZone, checkCommitsCount); | ||
} | ||
} | ||
} | ||
return gitLookup; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What for ist that? As we allow Java 8 for Hawkular in general, do we need to restrict to 6 here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's just for having it easier to contribute some parts of the code to upstream. Is that an acceptable reason?