Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

Contains resources used during the build of other Hawkular projects:

* Configuration for Checkstyle in `src/main/resources/hawkular-checkstyle` directory

Also contains IDE configuration files. Import these in your IDE so your IDE can
format files according to Hawkular style rules.

* ide-configs/eclipse - Eclipse preferences for code style. The names of the files
* The configuration for Checkstyle in `src/main/resources/hawkular-checkstyle` directory.
* `org.hawkular.build.checkstyle.xml.XmlIndentCheck` - an extension for Checkstyle to enforce indentation in XML files.
* A license header template to be used by com.mycila:license-maven-plugin in
`src/main/resources/hawkular-license/jboss-apache-2-template.txt`.
* `org.hawkular.build.license.CopyrightRangeProvider` - an extension of license-maven-plugin to set copyright years
range based on git history.
* IDE configuration files - import these in your IDE so your IDE can format files according to Hawkular style rules.
** `ide-configs/eclipse` - Eclipse preferences for code style. The names of the files
in here indicates where you should import these files.
e.g, hawkular-eclipse-preferences-java-codestyle-cleanup.xml
should be imported in Preferences > Java > Code Style > Cleanup.
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,8 @@
* @param ${param} the ${bare_field_name} to set
*/</template><template autoinsert="true" context="constructorcomment_context" deleted="false" description="Comment for created constructors" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name="constructorcomment">/**
* ${tags}
*/</template><template autoinsert="false" context="filecomment_context" deleted="false" description="Comment for created Java files" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.filecomment" name="filecomment"/><template autoinsert="false" context="typecomment_context" deleted="false" description="Comment for created types" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.typecomment" name="typecomment">/**
* ${tags}
*
* @author ${user}
*/</template><template autoinsert="true" context="fieldcomment_context" deleted="false" description="Comment for fields" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name="fieldcomment">/**
*
*/</template><template autoinsert="true" context="methodcomment_context" deleted="false" description="Comment for non-overriding methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name="methodcomment">/**
* ${tags}
*/</template><template autoinsert="true" context="overridecomment_context" deleted="false" description="Comment for overriding methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name="overridecomment">/* (non-Javadoc)
* ${see_to_overridden}
*/</template><template autoinsert="true" context="delegatecomment_context" deleted="false" description="Comment for delegate methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name="delegatecomment">/**
* ${tags}
* ${see_to_target}
*/</template><template autoinsert="false" context="newtype_context" deleted="false" description="Newly created files" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.newtype" name="newtype">/*
* Copyright 2014 - ${year} Red Hat, Inc. and/or its affiliates
*/</template><template autoinsert="false" context="filecomment_context" deleted="false" description="Comment for created Java files" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.filecomment" name="filecomment">/*
* Copyright 2014-${year} 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");
Expand All @@ -32,8 +19,17 @@
* 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.
*/
${filecomment}
*/</template><template autoinsert="false" context="typecomment_context" deleted="false" description="Comment for created types" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.typecomment" name="typecomment">/**
* @author ${user}
* ${tags}
*/</template><template autoinsert="false" context="fieldcomment_context" deleted="false" description="Comment for fields" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name="fieldcomment">/** */</template><template autoinsert="true" context="methodcomment_context" deleted="false" description="Comment for non-overriding methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name="methodcomment">/**
* ${tags}
*/</template><template autoinsert="true" context="overridecomment_context" deleted="false" description="Comment for overriding methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name="overridecomment">/* (non-Javadoc)
* ${see_to_overridden}
*/</template><template autoinsert="true" context="delegatecomment_context" deleted="false" description="Comment for delegate methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name="delegatecomment">/**
* ${tags}
* ${see_to_target}
*/</template><template autoinsert="false" context="newtype_context" deleted="false" description="Newly created files" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.newtype" name="newtype">${filecomment}
${package_declaration}

${typecomment}
Expand Down
38 changes: 29 additions & 9 deletions pom.xml
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>
Expand Down Expand Up @@ -79,21 +81,39 @@
</distributionManagement>

<properties>
<checkstyle.version>6.1.1</checkstyle.version>
<maven.compiler.source>1.6</maven.compiler.source>
Copy link
Member

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?

Copy link
Contributor Author

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?

<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>
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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. com.puppycrawl.tools.checkstyle version between here and the hawkular ur-parent.
You are right that there is no re-use in this particular place but for the named reasons, I'd keep it like this.

Copy link
Contributor

Choose a reason for hiding this comment

The 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

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>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* 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.checkstyle.xml;

import java.io.File;
Expand Down
148 changes: 148 additions & 0 deletions src/main/java/org/hawkular/build/license/CopyrightRangeProvider.java
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;
}

}
Loading