Skip to content

Commit b3da4a4

Browse files
author
TheSnoozer
authored
Merge pull request #331 from TheSnoozer/feature/214
#214 Introduce checkstyle to deploy a common code style
2 parents c670e24 + b8a6c24 commit b3da4a4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2129
-1522
lines changed

.checkstyle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false">
4+
<local-check-config name="git-commit-id-plugin" location="src/test/resources/checks/google_checks_checkstyle_8.2.xml" type="project" description="">
5+
<additional-data name="protect-config-file" value="false"/>
6+
</local-check-config>
7+
<fileset name="all" enabled="true" check-config-name="git-commit-id-plugin" local="true">
8+
<file-match-pattern match-pattern="." include-pattern="true"/>
9+
</fileset>
10+
</fileset-config>

.travis.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
language: java
22
sudo: false
33
dist: trusty
4+
5+
stages:
6+
- checkstyle
7+
- test
8+
- Integration Test
9+
410
jdk:
511
- oraclejdk9
612
- oraclejdk8
@@ -21,6 +27,14 @@ matrix:
2127
env: CUSTOM_MVN_VERION="3.3.9"
2228
- jdk: oraclejdk9
2329
env: CUSTOM_MVN_VERION="3.5.0"
30+
- stage: checkstyle
31+
jdk: oraclejdk9
32+
script: mvn clean verify -Pcheckstyle -Dcheckstyle.version=8.2 -Dmaven.test.skip=true -B
33+
env: CHECKSTYLE=8.2
34+
- stage: checkstyle
35+
jdk: openjdk7
36+
script: mvn clean verify -Pcheckstyle -Dmaven.test.skip=true -B
37+
env: CHECKSTYLE=6.11.2
2438

2539
install:
2640
- if [[ -n "${CUSTOM_MVN_VERION}" ]]; then

README.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ In order to understand the ideology and intention here are some pretty usefull i
4141
With the current version of the validation the user can decide if the build should fail if *at least one* of the defined criterias do not match with the desired values.
4242

4343
For flexibility and due to the fact that this validation has a different scope than the maven-git-commit-id-plugin this validation needs to be configured as additional execution inside the configuration of the pom.xml.
44-
Once configured, the validation is executed during the verification-phase. However since the validation is done in a seperate execution the phase can easily be changed by adding the desired phase to the execution configuration.
44+
Once configured, the validation is executed during the verification-phase. However since the validation is done in a separate execution the phase can easily be changed by adding the desired phase to the execution configuration.
4545

4646
Usage Example:
4747

@@ -72,7 +72,7 @@ Usage Example:
7272

7373
Required Configuration:
7474
If you plan to use this feature you'll want to know that the validation will be executed inside an additional mojo.
75-
Inside you pom you thus may want to add an additional execution tag that triggers the execution of the validation plugin.
75+
Inside your pom you thus may want to add an additional execution tag that triggers the execution of the validation plugin.
7676
You can also change the default phase of each execution by adding a `phase` definition.
7777

7878
```xml
@@ -191,7 +191,7 @@ It's really simple to setup this plugin; below is a sample pom that you may base
191191
<plugin>
192192
<groupId>pl.project13.maven</groupId>
193193
<artifactId>git-commit-id-plugin</artifactId>
194-
<version>2.2.1</version>
194+
<version>2.2.3</version>
195195
<executions>
196196
<execution>
197197
<id>get-the-git-infos</id>
@@ -362,7 +362,7 @@ It's really simple to setup this plugin; below is a sample pom that you may base
362362
The token can be seen as the needle and the value as the text to be written over any found tokens. If using regular expressions the value can reference grouped regex matches by using $1, $2, etc.
363363
364364
Since 2.2.4 the plugin allows to define a even more sophisticated ruleset and allows to set an `propertyOutputSuffix` within each replacement property. If this option is empty the original property will be overwritten (default behaviour in 2.2.3). however when this configuration is set to `something` and a user wants to modify the `git.branch` property the plugin will keep `git.branch` as the original one (w/o modifications) but also will be creating a new `git.branch.something` property with the requested replacement.
365-
Furthermore with 2.2.4 the plugin allows to perform certain types of string manipulation either before or after the evaluation of the replacement. With this feature a user can currently easily manipulate the case (e.g. lower case VS upper case) of the input/output property. This behaviour can be achieved by defining a list of `transformationRules` for the property where those rules should take effect. Each `transformationRule` consist of two required fields `apply` and `action`. The `apply`-tag controls when the rule should be applied and can be set to `BEFORE` to have the rule being applied before or it can be set to `AFTER` to have the rule being applied after the replacement. The `action`-tag determines the string conversion rule that should be applied. Currenlty supported is `LOWER_CASE` and `UPPER_CASE`. Potential candidates in the feature are `CAPITALIZATION` and `INVERT_CASE``(open a ticket if you need them...).
365+
Furthermore with 2.2.4 the plugin allows to perform certain types of string manipulation either before or after the evaluation of the replacement. With this feature a user can currently easily manipulate the case (e.g. lower case VS upper case) of the input/output property. This behaviour can be achieved by defining a list of `transformationRules` for the property where those rules should take effect. Each `transformationRule` consist of two required fields `apply` and `action`. The `apply`-tag controls when the rule should be applied and can be set to `BEFORE` to have the rule being applied before or it can be set to `AFTER` to have the rule being applied after the replacement. The `action`-tag determines the string conversion rule that should be applied. Currently supported is `LOWER_CASE` and `UPPER_CASE`. Potential candidates in the feature are `CAPITALIZATION` and `INVERT_CASE``(open a ticket if you need them...).
366366
367367
Please note that the replacement will *only be applied to properties that are being generated by the plugin*.
368368
If you want to replace properties that are being generated by other plugins you may want to use the maven-replacer-plugin or any other alternative.
@@ -766,7 +766,7 @@ git.build.time=${git.build.time}
766766
Yet another way to use the plugin
767767
=================================
768768

769-
Rather than reading properties files at runtime or injecting with spring, you can filter a Java source file directly and place it into src/main/java with an ignore, or into generated sources directory within the target directory. This has some minor advantages and disadvantages, but is useful for avoiding runtime injection or lookup from properties files that might get lost during repackaging later if used within a library.
769+
Rather than reading properties files at runtime or injecting with spring, you can filter a Java source file directly and place it into `src/main/java` with an ignore, or into generated sources directory within the target directory. This has some minor advantages and disadvantages, but is useful for avoiding runtime injection or lookup from properties files that might get lost during repackaging later if used within a library.
770770

771771
Git describe - short intro to an awesome command
772772
==================================================
@@ -939,6 +939,22 @@ Example:
939939
If you are using the maven build with [Maven's Plugin Prefix Resolution](https://maven.apache.org/guides/introduction/introduction-to-plugin-prefix-mapping.html) (e.g. `mvn somePrefix:goal`) please note that this currently seems to be [not supported by maven](https://issues.apache.org/jira/browse/MNG-6260).
940940
Instead of using the Plugin Prefix Resolution add an execution tag that calls the desired goal of the plugin within a normal maven life cycle (e.g. `mvn clean package`).
941941

942+
How to contribute to the project
943+
-------------------------------
944+
In general pull requests and support for open issues is always welcome!
945+
If you open a pull request or want to help out in any way please keep in mind that we currently use `checkstyle` to ensure that the project somehow maintains a uniform code base. Fortunately the most common IDEs support the integration of `checkstyle` via plugins. On top of more or less native integration into modern development tools the `checkstyle` rules are currently also being verified by using the [maven-checkstyle-plugin](https://maven.apache.org/plugins/maven-checkstyle-plugin/) during the build. it should be worth to highlight that you are not required to install `checkstyle` inside your IDE. If you feel more comfortable running the checks via maven this would to the trick!
946+
The checkstyle rules for this project are currently residing in `src/test/resources/checks` and for some IDEs those rules need to be imported manually (unfortunately there is no better solution available for this yet). The current rule set is pretty much the same as the `google_checks.xml` with certain checks disabled (e.g. line length). If you choose to integrate `checkstyle` inside your IDE feel free to checkout some high level requirements to get started with checkstyle within your IDE:
947+
* eclipse -- for eclipse / STS you would need to install the `checkstyle plug-in` via `Help -> Eclipse Marketplace -> Search` after restarting eclipse it should pick-up the rules automatically. If this does not work out of the box checkout the [official integration guide](http://checkstyle.sourceforge.net/eclipse.html) or use google to trace down your error message.
948+
* IntelliJ IDEA -- for IntelliJ you would need to install the `CheckStyle-IDEA` via `File -> Settings -> Plugins -> Search`. After restarting IntelliJ you would need to import the `checkstyle` rules manually via `File -> Settings -> Checkstyle`. As checkstyle version you may choose `6.11.2` or `8.2` and then click on the plus-sign on the right. As description you may choose `maven-git-commit-id-plugin` and as local checkstyle file you may choose one of the checkstyle rule residing in `src/test/resources/checks`. Please note that the rule-file depend on the version you have selected in the previous step and thus it is essential to ensure that the version numbers match up. As next-step you unfortunately will be prompted to enter the **full directory** of the `checkstyle-suppressions.xml`-File. If this does not work out of the box checkout the [official integration guide](http://checkstyle.sourceforge.net/idea.html) or use google to trace down your error message.
949+
* Netbeans -- feel free to open a ticket and share your installation guide :-) You can also check out the [official integration guide](http://checkstyle.sourceforge.net/netbeans.html) or use google to get any addtional help.
950+
* Maven -- if you want to run `checkstyle` via maven you simply can execute `mvn clean verify -Pcheckstyle -Dmaven.test.skip=true -B`. If you are using java9 you may want to run `mvn clean verify -Pcheckstyle -Dcheckstyle.version=8.2 -Dmaven.test.skip=true -B` that uses a more recent checkstyle version.
951+
952+
**Note**:
953+
If you run into
954+
```
955+
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check (validate) on project git-commit-id-plugin: Execution validate of goal org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check failed: Plugin org.apache.maven.plugins:maven-checkstyle-plugin:2.17 or one of its dependencies could not be resolved: Could not find artifact com.sun:tools:jar:1.7.0 at specified path /usr/lib/jvm/java-9-oracle/../lib/tools.jar -> [Help 1]
956+
```
957+
you may want to check that your ``JAVA_HOME``-Path is set correctly and that your are running `mvn clean verify -Pcheckstyle -Dcheckstyle.version=8.2 -Dmaven.test.skip=true -B`.
942958

943959
Maintainers
944960
===========
@@ -953,7 +969,7 @@ I'd like to give a big thanks to some of these folks, for their suggestions and
953969
* @fredcooke - for consistent feedback and suggestions,
954970
* @MrOnion - for a small yet fast bugfix,
955971
* @cardil and @TheSnoozer - for helping with getting the native git support shipped,
956-
* all the other contributors (as of writing 25) which can be on the [contributors tab](https://github.com/ktoso/maven-git-commit-id-plugin/graphs/contributors) - thanks guys,
972+
* all the other contributors (as of writing 50) which can be on the [contributors tab](https://github.com/ktoso/maven-git-commit-id-plugin/graphs/contributors) - thanks guys,
957973
* ... many others - thank you for your contributions,
958974
* ... you! - for using the plugin :-)
959975

pom.xml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,5 +419,59 @@
419419
</plugins>
420420
</build>
421421
</profile>
422+
<profile>
423+
<id>checkstyle</id>
424+
<properties>
425+
<maven-checkstyle-plugin.version>2.17</maven-checkstyle-plugin.version>
426+
<!-- if you update the checkstyle version make sure you update the google_checks.xml inside the repository -->
427+
<checkstyle.version>6.11.2</checkstyle.version>
428+
</properties>
429+
<build>
430+
<pluginManagement>
431+
<plugins>
432+
<plugin>
433+
<groupId>org.apache.maven.plugins</groupId>
434+
<artifactId>maven-checkstyle-plugin</artifactId>
435+
<version>${maven-checkstyle-plugin.version}</version>
436+
<dependencies>
437+
<dependency>
438+
<groupId>com.puppycrawl.tools</groupId>
439+
<artifactId>checkstyle</artifactId>
440+
<version>${checkstyle.version}</version>
441+
</dependency>
442+
</dependencies>
443+
</plugin>
444+
</plugins>
445+
</pluginManagement>
446+
<plugins>
447+
<plugin>
448+
<groupId>org.apache.maven.plugins</groupId>
449+
<artifactId>maven-checkstyle-plugin</artifactId>
450+
<version>${maven-checkstyle-plugin.version}</version>
451+
<executions>
452+
<execution>
453+
<id>validate</id>
454+
<phase>verify</phase>
455+
<goals>
456+
<goal>check</goal>
457+
</goals>
458+
<configuration>
459+
<configLocation>${basedir}/src/test/resources/checks/google_checks_checkstyle_${checkstyle.version}.xml</configLocation>
460+
<suppressionsLocation>${basedir}/src/test/resources/checks/checkstyle-suppressions.xml</suppressionsLocation>
461+
<propertyExpansion>samedir=${basedir}/src/test/resources/checks</propertyExpansion>
462+
<includeTestSourceDirectory>true</includeTestSourceDirectory>
463+
<encoding>${project.reporting.outputEncoding}</encoding>
464+
<consoleOutput>true</consoleOutput>
465+
<violationSeverity>warning</violationSeverity>
466+
<failsOnError>true</failsOnError>
467+
<failOnViolation>true</failOnViolation>
468+
<linkXRef>false</linkXRef>
469+
</configuration>
470+
</execution>
471+
</executions>
472+
</plugin>
473+
</plugins>
474+
</build>
475+
</profile>
422476
</profiles>
423477
</project>

src/main/java/pl/project13/jgit/DescribeCommand.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ public class DescribeCommand extends GitCommand<DescribeResult> {
4747
private LoggerBridge log;
4848
private JGitCommon jGitCommon;
4949

50-
// TODO not yet implemented options:
51-
// private boolean containsFlag = false;
52-
// private boolean allFlag = false;
53-
// private boolean tagsFlag = false;
54-
// private Optional<Integer> candidatesOption = Optional.of(10);
55-
// private boolean exactMatchFlag = false;
50+
// TODO not yet implemented options:
51+
// private boolean containsFlag = false;
52+
// private boolean allFlag = false;
53+
// private boolean tagsFlag = false;
54+
// private Optional<Integer> candidatesOption = Optional.of(10);
55+
// private boolean exactMatchFlag = false;
5656

5757
private Optional<String> matchOption = Optional.absent();
5858

@@ -275,7 +275,7 @@ public DescribeResult call() throws GitAPIException {
275275
List<RevCommit> commits;
276276
try {
277277
commits = jGitCommon.findCommitsUntilSomeTag(repo, headCommit, tagObjectIdToName);
278-
} catch(Exception e) {
278+
} catch (Exception e) {
279279
if (alwaysFlag) {
280280
// Show uniquely abbreviated commit object as fallback
281281
commits = Collections.emptyList();
@@ -360,12 +360,12 @@ RevCommit findHeadObjectId(@NotNull Repository repo) throws RuntimeException {
360360

361361
// git commit id -> its tag (or tags)
362362
private Map<ObjectId, List<String>> findTagObjectIds(@NotNull Repository repo, boolean tagsFlag) {
363-
String matchPattern = createMatchPattern();
364-
Map<ObjectId, List<DatedRevTag>> commitIdsToTags = jGitCommon.getCommitIdsToTags(repo, tagsFlag, matchPattern);
365-
Map<ObjectId, List<String>> commitIdsToTagNames = jGitCommon.transformRevTagsMapToDateSortedTagNames(commitIdsToTags);
363+
String matchPattern = createMatchPattern();
364+
Map<ObjectId, List<DatedRevTag>> commitIdsToTags = jGitCommon.getCommitIdsToTags(repo, tagsFlag, matchPattern);
365+
Map<ObjectId, List<String>> commitIdsToTagNames = jGitCommon.transformRevTagsMapToDateSortedTagNames(commitIdsToTags);
366366
log.info("Created map: [{}]", commitIdsToTagNames);
367367

368-
return commitIdsToTagNames;
368+
return commitIdsToTagNames;
369369
}
370370

371371
private String createMatchPattern() {

src/main/java/pl/project13/jgit/DescribeResult.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,16 @@
2020
import com.google.common.base.Joiner;
2121
import com.google.common.base.Optional;
2222
import com.google.common.base.Preconditions;
23-
import org.eclipse.jgit.lib.AbbreviatedObjectId;
24-
import org.eclipse.jgit.lib.ObjectId;
25-
import org.eclipse.jgit.lib.ObjectReader;
26-
import org.jetbrains.annotations.NotNull;
27-
import org.jetbrains.annotations.Nullable;
28-
2923
import java.io.IOException;
3024
import java.util.ArrayList;
3125
import java.util.Arrays;
3226
import java.util.Collections;
3327
import java.util.List;
28+
import org.eclipse.jgit.lib.AbbreviatedObjectId;
29+
import org.eclipse.jgit.lib.ObjectId;
30+
import org.eclipse.jgit.lib.ObjectReader;
31+
import org.jetbrains.annotations.NotNull;
32+
import org.jetbrains.annotations.Nullable;
3433

3534
/**
3635
* Represents the result of a <code>git describe</code> command.

0 commit comments

Comments
 (0)