Skip to content

Commit 8aec1c0

Browse files
committed
Fixing tests and made default params for describe config really work
The config problem has roots in maven, see http://jira.codehaus.org/browse/MNG-5725 and #134
1 parent fde80a3 commit 8aec1c0

File tree

9 files changed

+241
-168
lines changed

9 files changed

+241
-168
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public DescribeCommand always(boolean always) {
161161
*/
162162
@NotNull
163163
public DescribeCommand forceLongFormat(@Nullable Boolean forceLongFormat) {
164-
if (forceLongFormat != null) {
164+
if (forceLongFormat != null && forceLongFormat) {
165165
this.forceLongFormat = forceLongFormat;
166166
log("--long =", forceLongFormat);
167167
}
@@ -217,7 +217,7 @@ public DescribeCommand abbrev(@Nullable Integer n) {
217217
*/
218218
@NotNull
219219
public DescribeCommand tags(@Nullable Boolean includeLightweightTagsInSearch) {
220-
if (includeLightweightTagsInSearch != null) {
220+
if (includeLightweightTagsInSearch != null && includeLightweightTagsInSearch) {
221221
tagsFlag = includeLightweightTagsInSearch;
222222
log("--tags =", includeLightweightTagsInSearch);
223223
}
@@ -275,8 +275,10 @@ public DescribeCommand dirty(@Nullable String dirtyMarker) {
275275
*/
276276
@NotNull
277277
public DescribeCommand match(@Nullable String pattern) {
278-
matchOption = Optional.fromNullable(pattern);
279-
log("--match =", matchOption.or(""));
278+
if (!"*".equals(pattern)) {
279+
matchOption = Optional.fromNullable(pattern);
280+
log("--match =", matchOption.or(""));
281+
}
280282
return this;
281283
}
282284

src/main/java/pl/project13/maven/git/GitCommitIdMojo.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ public void execute() throws MojoExecutionException {
300300
dotGitDirectory = lookupGitDirectory();
301301
throwWhenRequiredDirectoryNotFound(dotGitDirectory, failOnNoGitDirectory, ".git directory could not be found! Please specify a valid [dotGitDirectory] in your pom.xml");
302302

303+
if (gitDescribe == null) {
304+
gitDescribe = new GitDescribeConfig();
305+
}
306+
303307
if (dotGitDirectory != null) {
304308
log("dotGitDirectory", dotGitDirectory.getAbsolutePath());
305309
} else {
@@ -460,10 +464,10 @@ void loadGitData(@NotNull Properties properties) throws IOException, MojoExecuti
460464
}
461465

462466
void loadGitDataWithNativeGit(@NotNull Properties properties) throws IOException, MojoExecutionException {
463-
File basedir = project.getBasedir().getCanonicalFile();
464-
NativeGitProvider nativeGitProvider = NativeGitProvider
465-
.on(basedir)
466-
.withLoggerBridge(loggerBridge)
467+
final File basedir = project.getBasedir().getCanonicalFile();
468+
469+
GitDataProvider nativeGitProvider = NativeGitProvider
470+
.on(basedir, loggerBridge)
467471
.setVerbose(verbose)
468472
.setPrefixDot(prefixDot)
469473
.setAbbrevLength(abbrevLength)
@@ -474,9 +478,8 @@ void loadGitDataWithNativeGit(@NotNull Properties properties) throws IOException
474478
}
475479

476480
void loadGitDataWithJGit(@NotNull Properties properties) throws IOException, MojoExecutionException {
477-
JGitProvider jGitProvider = JGitProvider
478-
.on(dotGitDirectory)
479-
.withLoggerBridge(loggerBridge)
481+
GitDataProvider jGitProvider = JGitProvider
482+
.on(dotGitDirectory, loggerBridge)
480483
.setVerbose(verbose)
481484
.setPrefixDot(prefixDot)
482485
.setAbbrevLength(abbrevLength)

src/main/java/pl/project13/maven/git/GitDataProvider.java

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
import static com.google.common.base.Strings.isNullOrEmpty;
1313

1414
/**
15-
*
16-
* @author <a href="mailto:konrad.malawski@java.pl">Konrad 'ktoso' Malawski</a>
17-
*/
15+
* @author <a href="mailto:konrad.malawski@java.pl">Konrad 'ktoso' Malawski</a>
16+
*/
1817
public abstract class GitDataProvider {
18+
1919
@NotNull
2020
protected LoggerBridge loggerBridge;
2121

@@ -27,7 +27,31 @@ public abstract class GitDataProvider {
2727

2828
protected String dateFormat;
2929

30-
protected GitDescribeConfig gitDescribe;
30+
protected GitDescribeConfig gitDescribe = new GitDescribeConfig();
31+
32+
public GitDataProvider(@NotNull LoggerBridge loggerBridge) {
33+
this.loggerBridge = loggerBridge;
34+
}
35+
36+
public GitDataProvider setGitDescribe(GitDescribeConfig gitDescribe) {
37+
this.gitDescribe = gitDescribe;
38+
return this;
39+
}
40+
41+
public GitDataProvider setPrefixDot(String prefixDot) {
42+
this.prefixDot = prefixDot;
43+
return this;
44+
}
45+
46+
public GitDataProvider setAbbrevLength(int abbrevLength) {
47+
this.abbrevLength = abbrevLength;
48+
return this;
49+
}
50+
51+
public GitDataProvider setDateFormat(String dateFormat) {
52+
this.dateFormat = dateFormat;
53+
return this;
54+
}
3155

3256
protected abstract void init() throws MojoExecutionException;
3357
protected abstract String getBuildAuthorName();
@@ -148,9 +172,7 @@ protected String determineBranchNameOnBuildServer(Map<String, String> env) throw
148172
}
149173

150174
void log(String... parts) {
151-
if (loggerBridge != null) {
152-
loggerBridge.log((Object[]) parts);
153-
}
175+
loggerBridge.log((Object[]) parts);
154176
}
155177

156178
protected void put(@NotNull Properties properties, String key, String value) {

src/main/java/pl/project13/maven/git/GitDescribeConfig.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class GitDescribeConfig {
3232
*
3333
* @parameter default-value=false
3434
*/
35-
private boolean skip;
35+
private boolean skip = false;
3636

3737
/**
3838
* <pre>--always</pre>
@@ -42,18 +42,18 @@ public class GitDescribeConfig {
4242
*
4343
* @parameter default-value=true
4444
*/
45-
private boolean always;
45+
private boolean always = true;
4646

4747
/**
4848
* <pre>--dirty[=mark]</pre>
4949
* Describe the working tree. It means describe HEAD and appends mark (<pre>-dirty</pre> by default) if the
5050
* working tree is dirty.
5151
*
52-
* <b>-devel</b> by default, following git's behaviour.
52+
* <b>empty</b> by default, following git's behaviour.
5353
*
54-
* @parameter default-value="devel"
54+
* @parameter default-value=""
5555
*/
56-
private String dirty;
56+
private String dirty = "";
5757

5858
/**
5959
*<pre>--match glob-pattern</pre>
@@ -63,7 +63,7 @@ public class GitDescribeConfig {
6363
*
6464
* @parameter default-value="*"
6565
*/
66-
private String match;
66+
private String match = "*";
6767

6868
/**
6969
* <pre>--abbrev=N</pre>
@@ -103,7 +103,7 @@ public class GitDescribeConfig {
103103
*
104104
* @parameter default-value=7
105105
*/
106-
private int abbrev;
106+
private int abbrev = 7;
107107

108108
/**
109109
* <pre>--tags</pre>
@@ -136,7 +136,7 @@ public class GitDescribeConfig {
136136
*
137137
* @parameter default-value=false
138138
*/
139-
private boolean tags;
139+
private boolean tags = false;
140140

141141
/**
142142
* <pre>--long</pre>
@@ -151,7 +151,7 @@ public class GitDescribeConfig {
151151
*
152152
* @parameter default-value=false
153153
*/
154-
private boolean forceLongFormat;
154+
private boolean forceLongFormat = false;
155155

156156
public GitDescribeConfig() {
157157
}

src/main/java/pl/project13/maven/git/JGitProvider.java

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
import com.google.common.base.Joiner;
66
import com.google.common.base.Predicate;
77
import com.google.common.collect.Collections2;
8-
import com.google.common.collect.Lists;
98
import org.apache.maven.plugin.MojoExecutionException;
109
import org.eclipse.jgit.api.Git;
11-
import org.eclipse.jgit.api.ListTagCommand;
1210
import org.eclipse.jgit.api.errors.GitAPIException;
13-
import org.eclipse.jgit.lib.*;
11+
import org.eclipse.jgit.lib.AbbreviatedObjectId;
12+
import org.eclipse.jgit.lib.Constants;
13+
import org.eclipse.jgit.lib.ObjectId;
14+
import org.eclipse.jgit.lib.ObjectReader;
15+
import org.eclipse.jgit.lib.Ref;
16+
import org.eclipse.jgit.lib.Repository;
1417
import org.eclipse.jgit.revwalk.RevCommit;
1518
import org.eclipse.jgit.revwalk.RevWalk;
1619
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
@@ -22,7 +25,9 @@
2225
import java.io.File;
2326
import java.io.IOException;
2427
import java.text.SimpleDateFormat;
25-
import java.util.*;
28+
import java.util.Collection;
29+
import java.util.Date;
30+
import java.util.List;
2631

2732
/**
2833
* @author <a href="mailto:konrad.malawski@java.pl">Konrad 'ktoso' Malawski</a>
@@ -36,47 +41,22 @@ public class JGitProvider extends GitDataProvider {
3641
private RevCommit headCommit;
3742

3843
@NotNull
39-
public static JGitProvider on(@NotNull File dotGitDirectory) {
40-
return new JGitProvider(dotGitDirectory);
44+
public static JGitProvider on(@NotNull File dotGitDirectory, @NotNull LoggerBridge loggerBridge) {
45+
return new JGitProvider(dotGitDirectory, loggerBridge);
4146
}
4247

43-
JGitProvider(@NotNull File dotGitDirectory) {
48+
JGitProvider(@NotNull File dotGitDirectory, @NotNull LoggerBridge loggerBridge) {
49+
super(loggerBridge);
4450
this.dotGitDirectory = dotGitDirectory;
4551
}
4652

47-
@NotNull
48-
public JGitProvider withLoggerBridge(LoggerBridge bridge) {
49-
super.loggerBridge = bridge;
50-
return this;
51-
}
52-
5353
@NotNull
5454
public JGitProvider setVerbose(boolean verbose) {
5555
super.verbose = verbose;
5656
super.loggerBridge.setVerbose(verbose);
5757
return this;
5858
}
5959

60-
public JGitProvider setPrefixDot(String prefixDot) {
61-
super.prefixDot = prefixDot;
62-
return this;
63-
}
64-
65-
public JGitProvider setAbbrevLength(int abbrevLength) {
66-
super.abbrevLength = abbrevLength;
67-
return this;
68-
}
69-
70-
public JGitProvider setDateFormat(String dateFormat) {
71-
super.dateFormat = dateFormat;
72-
return this;
73-
}
74-
75-
public JGitProvider setGitDescribe(GitDescribeConfig gitDescribe) {
76-
super.gitDescribe = gitDescribe;
77-
return this;
78-
}
79-
8060
@Override
8161
protected void init() throws MojoExecutionException {
8262
git = getGitRepository();

0 commit comments

Comments
 (0)