File tree 21 files changed +108
-97
lines changed
main/java/pt/com/hugodias/gradle/gitversioner
test/java/pt/com/hugodias/gradle/gitversioner 21 files changed +108
-97
lines changed Original file line number Diff line number Diff line change 1
1
plugins {
2
2
id ' java-gradle-plugin'
3
3
id " com.diffplug.spotless" version " 6.11.0"
4
- // id ' pt.com.hugo-dias.git-versioner' version ' 1.0.0'
4
+ id " pt.com.hugo-dias.git-versioner" version " 1.0.1 "
5
5
id ' maven-publish'
6
6
id " com.gradle.plugin-publish" version " 1.0.0"
7
7
id " pl.droidsonroids.jacoco.testkit" version " 1.0.7"
@@ -10,7 +10,6 @@ plugins {
10
10
}
11
11
12
12
group ' pt.com.hugo-dias.gradle.gitversioner'
13
- version ' 1.0.1'
14
13
15
14
repositories {
16
15
mavenCentral()
@@ -90,3 +89,11 @@ sonarqube {
90
89
// property "sonar.cpd.exclusions", "src/test/**/*"
91
90
}
92
91
}
92
+
93
+ versioner {
94
+ startFrom {
95
+ major = 1
96
+ minor = 0
97
+ patch = 1
98
+ }
99
+ }
Original file line number Diff line number Diff line change 2
2
package pt .com .hugodias .gradle .gitversioner ;
3
3
4
4
import java .io .File ;
5
- import org .gradle .api .Action ;
6
5
import org .gradle .api .Plugin ;
7
6
import org .gradle .api .Project ;
8
7
import org .gradle .api .tasks .TaskProvider ;
@@ -40,18 +39,15 @@ public void apply(Project project) {
40
39
});
41
40
42
41
project .afterEvaluate (
43
- new Action <Project >() {
44
- @ Override
45
- public void execute (Project project ) {
46
- if (extension .getCalculatedVersion () == null ) {
47
- VersionerConfig config = VersionerConfig .fromExtension (extension );
48
- String version = versioner .version (config ).print (config .getPattern ());
49
- project .setVersion (version );
50
- }
51
-
52
- printVersionTask .get ().getVersion ().set (project .getVersion ().toString ());
53
- tagVersionTask .get ().getVersion ().set (project .getVersion ().toString ());
42
+ innerProject -> {
43
+ if (extension .getCalculatedVersion () == null ) {
44
+ VersionerConfig config = VersionerConfig .fromExtension (extension );
45
+ String version = versioner .version (config ).print (config .getPattern ());
46
+ innerProject .setVersion (version );
54
47
}
48
+
49
+ printVersionTask .get ().getVersion ().set (innerProject .getVersion ().toString ());
50
+ tagVersionTask .get ().getVersion ().set (innerProject .getVersion ().toString ());
55
51
});
56
52
}
57
53
}
Original file line number Diff line number Diff line change 3
3
4
4
import org .gradle .api .provider .Property ;
5
5
6
- public abstract class Match {
7
- public abstract Property <String > getMajor ();
6
+ public interface Match {
7
+ Property <String > getMajor ();
8
8
9
- public abstract Property <String > getMinor ();
9
+ Property <String > getMinor ();
10
10
11
- public abstract Property <String > getPatch ();
11
+ Property <String > getPatch ();
12
12
}
Original file line number Diff line number Diff line change 3
3
4
4
import org .gradle .api .provider .Property ;
5
5
6
- public abstract class Pattern {
7
- public abstract Property <String > getPattern ();
6
+ public interface Pattern {
7
+ Property <String > getPattern ();
8
8
}
Original file line number Diff line number Diff line change 3
3
4
4
import org .gradle .api .provider .Property ;
5
5
6
- public abstract class StartFrom {
7
- public abstract Property <Integer > getMajor ();
6
+ public interface StartFrom {
7
+ Property <Integer > getMajor ();
8
8
9
- public abstract Property <Integer > getMinor ();
9
+ Property <Integer > getMinor ();
10
10
11
- public abstract Property <Integer > getPatch ();
11
+ Property <Integer > getPatch ();
12
12
}
Original file line number Diff line number Diff line change 3
3
4
4
import org .gradle .api .provider .Property ;
5
5
6
- public abstract class Tag {
7
- public abstract Property <String > getPrefix ();
6
+ public interface Tag {
7
+ Property <String > getPrefix ();
8
8
9
- public abstract Property <Boolean > getUseCommitMessage ();
9
+ Property <Boolean > getUseCommitMessage ();
10
10
}
Original file line number Diff line number Diff line change 3
3
4
4
import org .gradle .api .tasks .Nested ;
5
5
6
- public abstract class Authentication {
6
+ public interface Authentication {
7
7
@ Nested
8
- public abstract Ssh getSsh ();
8
+ Ssh getSsh ();
9
9
10
10
@ Nested
11
- public abstract Https getHttps ();
11
+ Https getHttps ();
12
12
}
Original file line number Diff line number Diff line change 3
3
4
4
import org .gradle .api .tasks .Nested ;
5
5
6
- public abstract class Git {
6
+ public interface Git {
7
7
@ Nested
8
- public abstract Authentication getAuthentication ();
8
+ Authentication getAuthentication ();
9
9
}
Original file line number Diff line number Diff line change 3
3
4
4
import org .gradle .api .provider .Property ;
5
5
6
- public abstract class Https {
7
- public abstract Property <String > getUsername ();
6
+ public interface Https {
7
+ Property <String > getUsername ();
8
8
9
- public abstract Property <String > getPassword ();
9
+ Property <String > getPassword ();
10
10
11
- public abstract Property <String > getToken ();
11
+ Property <String > getToken ();
12
12
}
Original file line number Diff line number Diff line change 3
3
4
4
import org .gradle .api .provider .Property ;
5
5
6
- public abstract class Ssh {
7
- public abstract Property <Boolean > getStrictSsl ();
6
+ public interface Ssh {
7
+ Property <Boolean > getStrictSsl ();
8
8
}
Original file line number Diff line number Diff line change
1
+ /* (C) 2022 Hugo Dias */
2
+ package pt .com .hugodias .gradle .gitversioner .core .exception ;
3
+
4
+ public class TaggingException extends RuntimeException {
5
+ public TaggingException (Throwable cause ) {
6
+ super (cause );
7
+ }
8
+ }
Original file line number Diff line number Diff line change
1
+ /* (C) 2022 Hugo Dias */
2
+ package pt .com .hugodias .gradle .gitversioner .core .exception ;
3
+
4
+ public class VersionerException extends RuntimeException {
5
+ public VersionerException (Throwable cause ) {
6
+ super (cause );
7
+ }
8
+ }
Original file line number Diff line number Diff line change 11
11
import org .eclipse .jgit .api .errors .GitAPIException ;
12
12
import org .eclipse .jgit .transport .CredentialsProvider ;
13
13
import org .eclipse .jgit .transport .UsernamePasswordCredentialsProvider ;
14
+ import pt .com .hugodias .gradle .gitversioner .core .exception .TaggingException ;
14
15
15
16
@ Data
16
17
@ Builder
@@ -30,7 +31,7 @@ public void tag(String version) {
30
31
tagCommand .call ();
31
32
git .push ().add (prefixedVersion ).setCredentialsProvider (credentialsProvider ).call ();
32
33
} catch (IOException | GitAPIException e ) {
33
- throw new RuntimeException (e );
34
+ throw new TaggingException (e );
34
35
}
35
36
}
36
37
Original file line number Diff line number Diff line change 10
10
import lombok .val ;
11
11
import org .eclipse .jgit .api .Git ;
12
12
import org .eclipse .jgit .api .errors .GitAPIException ;
13
- import org . eclipse . jgit . api . errors . NoHeadException ;
13
+ import pt . com . hugodias . gradle . gitversioner . core . exception . VersionerException ;
14
14
15
15
@ Data
16
16
@ Builder
17
17
public class Versioner {
18
18
private File gitFolder ;
19
19
20
20
public Version version (VersionerConfig config ) {
21
- try {
21
+ try ( Git git = Git . open ( gitFolder )) {
22
22
var major = config .getStartFromMajor ();
23
23
var minor = config .getStartFromMinor ();
24
24
var patch = config .getStartFromPatch ();
25
25
var commit = 0 ;
26
26
27
- val git = Git .open (gitFolder );
28
27
val branch = git .getRepository ().getBranch ();
29
28
val hash = git .getRepository ().findRef ("HEAD" ).getObjectId ().getName ();
30
29
@@ -56,12 +55,8 @@ public Version version(VersionerConfig config) {
56
55
.branch (branch )
57
56
.hash (hash )
58
57
.build ();
59
- } catch (IOException e ) {
60
- throw new RuntimeException (e );
61
- } catch (NoHeadException e ) {
62
- throw new RuntimeException (e );
63
- } catch (GitAPIException e ) {
64
- throw new RuntimeException (e );
58
+ } catch (IOException | GitAPIException e ) {
59
+ throw new VersionerException (e );
65
60
}
66
61
}
67
62
Original file line number Diff line number Diff line change 13
13
import pt .com .hugodias .gradle .gitversioner .util .Project ;
14
14
15
15
@ FunctionalTest
16
- public class GitVersionerTest {
16
+ class GitVersionerTest {
17
17
18
18
private File directory ;
19
19
private Project project ;
20
20
private Gradle gradle ;
21
21
22
22
@ BeforeEach
23
- public void setUp () {
23
+ void setUp () {
24
24
directory = new File ("build/tmp/functionalTest/GitVersionerTest/" );
25
25
directory .mkdirs ();
26
26
project = Project .builder ().directory (directory ).build ();
27
27
gradle = Gradle .builder ().directory (directory ).build ();
28
28
}
29
29
30
30
@ AfterEach
31
- public void tearDown () throws IOException {
31
+ void tearDown () throws IOException {
32
32
FileUtils .deleteDirectory (directory );
33
33
}
34
34
35
35
@ DisplayName ("Version is available after forcing version resolution in Groovy" )
36
36
@ Test
37
- public void testVersionIsAvailableAfterForcingVersionGroovy ()
38
- throws IOException , GitAPIException {
37
+ void testVersionIsAvailableAfterForcingVersionGroovy () throws IOException , GitAPIException {
39
38
project .withSettingsFile ().withGit ().withGroovyGradleFile ("configured" );
40
39
addCommits ();
41
40
@@ -46,8 +45,7 @@ public void testVersionIsAvailableAfterForcingVersionGroovy()
46
45
47
46
@ DisplayName ("Version is available after forcing version resolution in Kotlin" )
48
47
@ Test
49
- public void testVersionIsAvailableAfterForcingVersionKotlin ()
50
- throws IOException , GitAPIException {
48
+ void testVersionIsAvailableAfterForcingVersionKotlin () throws IOException , GitAPIException {
51
49
project .withSettingsFile ().withGit ().withKotlinGradleFile ("configured" );
52
50
addCommits ();
53
51
Original file line number Diff line number Diff line change 8
8
import org .gradle .testfixtures .ProjectBuilder ;
9
9
import org .junit .jupiter .api .Test ;
10
10
11
- public class VersionerPluginTest {
11
+ class VersionerPluginTest {
12
12
13
13
@ Test
14
- public void greetingTest () {
14
+ void greetingTest () {
15
15
Project project = ProjectBuilder .builder ().build ();
16
16
project .getPluginManager ().apply ("pt.com.hugo-dias.git-versioner" );
17
17
You can’t perform that action at this time.
0 commit comments