Set this to {@code 'true'} to inject git properties into all reactor projects, not just the current one.
@@ -91,27 +87,27 @@ public class GitCommitIdMojo extends AbstractMojo {
*
*/
@Parameter(defaultValue = "false")
- private boolean injectAllReactorProjects;
+ boolean injectAllReactorProjects;
/**
* Set this to {@code 'true'} to print more info while scanning for paths.
* It will make git-commit-id "eat its own dog food" :-)
*/
@Parameter(defaultValue = "false")
- private boolean verbose;
+ boolean verbose;
/**
* Set this to {@code 'false'} to execute plugin in 'pom' packaged projects.
*/
@Parameter(defaultValue = "true")
- private boolean skipPoms;
+ boolean skipPoms;
/**
* Set this to {@code 'true'} to generate {@code 'git.properties'} file.
* By default plugin only adds properties to maven project properties.
*/
@Parameter(defaultValue = "false")
- private boolean generateGitPropertiesFile;
+ boolean generateGitPropertiesFile;
/**
*
The location of {@code 'git.properties'} file. Set {@code 'generateGitPropertiesFile'} to {@code 'true'}
@@ -120,20 +116,20 @@ public class GitCommitIdMojo extends AbstractMojo {
*
The path here is relative to your project src directory.
*/
@Parameter(defaultValue = "${project.build.outputDirectory}/git.properties")
- private String generateGitPropertiesFilename;
+ String generateGitPropertiesFilename;
/**
* The root directory of the repository we want to check.
*/
@Parameter(defaultValue = "${project.basedir}/.git")
- private File dotGitDirectory;
+ File dotGitDirectory;
/**
* Configuration for the {@code 'git-describe'} command.
* You can modify the dirty marker, abbrev length and other options here.
*/
@Parameter
- private GitDescribeConfig gitDescribe;
+ GitDescribeConfig gitDescribe;
/**
*
Minimum length of {@code 'git.commit.id.abbrev'} property.
@@ -149,19 +145,19 @@ public class GitCommitIdMojo extends AbstractMojo {
*
*/
@Parameter(defaultValue = "7")
- private int abbrevLength;
+ int abbrevLength;
/**
* The format to save properties in: {@code 'properties'} or {@code 'json'}.
*/
@Parameter(defaultValue = "properties")
- private String format;
+ String format;
/**
* The prefix to expose the properties on. For example {@code 'git'} would allow you to access {@code ${git.branch}}.
*/
@Parameter(defaultValue = "git")
- private String prefix;
+ String prefix;
// prefix with dot appended if needed
private String prefixDot = "";
@@ -169,7 +165,7 @@ public class GitCommitIdMojo extends AbstractMojo {
* The date format to be used for any dates exported by this plugin. It should be a valid {@link SimpleDateFormat} string.
*/
@Parameter(defaultValue = "yyyy-MM-dd'T'HH:mm:ssZ")
- private String dateFormat;
+ String dateFormat;
/**
*
The timezone used in the date format of dates exported by this plugin.
@@ -179,13 +175,13 @@ public class GitCommitIdMojo extends AbstractMojo {
* Please review https://docs.oracle.com/javase/7/docs/api/java/util/TimeZone.html for more information on this issue.
*/
@Parameter
- private String dateFormatTimeZone;
+ String dateFormatTimeZone;
/**
* Set this to {@code 'false'} to continue the build on missing {@code '.git'} directory.
*/
@Parameter(defaultValue = "true")
- private boolean failOnNoGitDirectory;
+ boolean failOnNoGitDirectory;
/**
*
Set this to {@code 'false'} to continue the build even if unable to get enough data for a complete run.
@@ -198,7 +194,7 @@ public class GitCommitIdMojo extends AbstractMojo {
* for a rationale behind this flag.
*/
@Parameter(defaultValue = "true")
- private boolean failOnUnableToExtractRepoInfo;
+ boolean failOnUnableToExtractRepoInfo;
/**
* Set this to {@code 'true'} to use native Git executable to fetch information about the repository.
@@ -207,14 +203,14 @@ public class GitCommitIdMojo extends AbstractMojo {
* @since 2.1.9
*/
@Parameter(defaultValue = "false")
- private boolean useNativeGit;
+ boolean useNativeGit;
/**
* Set this to {@code 'true'} to skip plugin execution.
* @since 2.1.8
*/
@Parameter(defaultValue = "false")
- private boolean skip;
+ boolean skip;
/**
@@ -238,7 +234,7 @@ public class GitCommitIdMojo extends AbstractMojo {
* @since 2.1.12
*/
@Parameter(defaultValue = "false")
- private boolean runOnlyOnce;
+ boolean runOnlyOnce;
/**
*
List of properties to exclude from the resulting file.
@@ -252,7 +248,7 @@ public class GitCommitIdMojo extends AbstractMojo {
* @since 2.1.9
*/
@Parameter
- private List excludeProperties;
+ List excludeProperties;
/**
*
List of properties to include into the resulting file. Only properties specified here will be included.
@@ -265,7 +261,7 @@ public class GitCommitIdMojo extends AbstractMojo {
* @since 2.1.14
*/
@Parameter
- private List includeOnlyProperties;
+ List includeOnlyProperties;
/**
*
The mode of {@code 'git.commit.id'} property generation.
@@ -288,7 +284,7 @@ public class GitCommitIdMojo extends AbstractMojo {
* @since 2.2.0
*/
@Parameter(defaultValue = "flat")
- private String commitIdGenerationMode;
+ String commitIdGenerationMode;
private CommitIdGenerationMode commitIdGenerationModeEnum;
/**
@@ -300,7 +296,7 @@ public class GitCommitIdMojo extends AbstractMojo {
* @since 2.2.3
*/
@Parameter
- @VisibleForTesting List replacementProperties;
+ List replacementProperties;
/**
* Allow to tell the plugin what commit should be used as reference to generate the properties from.
@@ -316,9 +312,17 @@ public class GitCommitIdMojo extends AbstractMojo {
* @since 2.2.4
*/
@Parameter(defaultValue = "HEAD")
- private String evaluateOnCommit;
+ String evaluateOnCommit;
protected static final Pattern allowedCharactersForEvaluateOnCommit = Pattern.compile("[a-zA-Z0-9\\_\\-\\^\\/\\.]+");
+ /**
+ * Allow to specify a timeout (in milliseconds) for fetching information with the native Git executable.
+ * Note that {@code useNativeGit} needs to be set to {@code 'true'} to use native Git executable.
+ * @since 3.0.0
+ */
+ @Parameter(defaultValue = "30000")
+ long nativeGitTimeoutInMs;
+
/**
* The properties we store our data in and then expose them.
*/
@@ -329,13 +333,14 @@ public class GitCommitIdMojo extends AbstractMojo {
*/
private Charset sourceCharset = StandardCharsets.UTF_8;
- @NotNull
+ @Nonnull
private final LoggerBridge log = new MavenLoggerBridge(this, false);
- @NotNull
+ @Nonnull
private PropertiesFilterer propertiesFilterer = new PropertiesFilterer(log);
- @NotNull @VisibleForTesting PropertiesReplacer propertiesReplacer = new PropertiesReplacer(log);
+ @Nonnull
+ PropertiesReplacer propertiesReplacer = new PropertiesReplacer(log);
@Override
public void execute() throws MojoExecutionException {
@@ -404,7 +409,6 @@ public void execute() throws MojoExecutionException {
loadGitData(properties);
loadBuildData(properties);
- loadShortDescribe(properties);
propertiesReplacer.performReplacement(properties, replacementProperties);
propertiesFilterer.filter(properties, includeOnlyProperties, this.prefixDot);
propertiesFilterer.filterNot(properties, excludeProperties, this.prefixDot);
@@ -472,7 +476,7 @@ private void appendPropertiesToReactorProjects() {
*
* @return the File representation of the .git directory
*/
- @VisibleForTesting File lookupGitDirectory() throws GitCommitIdExecutionException {
+ private File lookupGitDirectory() throws GitCommitIdExecutionException {
return new GitDirLocator(project, reactorProjects).lookupGitDirectory(dotGitDirectory);
}
@@ -483,28 +487,7 @@ private void logProperties() {
}
}
- void loadShortDescribe(@NotNull Properties properties) {
- //removes git hash part from describe
- String commitDescribe = properties.getProperty(prefixDot + GitCommitPropertyConstant.COMMIT_DESCRIBE);
-
- if (commitDescribe != null) {
- int startPos = commitDescribe.indexOf("-g");
- if (startPos > 0) {
- String commitShortDescribe;
- int endPos = commitDescribe.indexOf('-', startPos + 1);
- if (endPos < 0) {
- commitShortDescribe = commitDescribe.substring(0, startPos);
- } else {
- commitShortDescribe = commitDescribe.substring(0, startPos) + commitDescribe.substring(endPos);
- }
- put(properties, GitCommitPropertyConstant.COMMIT_SHORT_DESCRIBE, commitShortDescribe);
- } else {
- put(properties, GitCommitPropertyConstant.COMMIT_SHORT_DESCRIBE, commitDescribe);
- }
- }
- }
-
- void loadGitData(@NotNull Properties properties) throws GitCommitIdExecutionException {
+ private void loadGitData(@Nonnull Properties properties) throws GitCommitIdExecutionException {
if (useNativeGit) {
loadGitDataWithNativeGit(properties);
} else {
@@ -512,12 +495,12 @@ void loadGitData(@NotNull Properties properties) throws GitCommitIdExecutionExce
}
}
- void loadGitDataWithNativeGit(@NotNull Properties properties) throws GitCommitIdExecutionException {
+ private void loadGitDataWithNativeGit(@Nonnull Properties properties) throws GitCommitIdExecutionException {
try {
final File basedir = project.getBasedir().getCanonicalFile();
GitDataProvider nativeGitProvider = NativeGitProvider
- .on(basedir, log)
+ .on(basedir, nativeGitTimeoutInMs, log)
.setPrefixDot(prefixDot)
.setAbbrevLength(abbrevLength)
.setDateFormat(dateFormat)
@@ -531,7 +514,7 @@ void loadGitDataWithNativeGit(@NotNull Properties properties) throws GitCommitId
}
}
- void loadGitDataWithJGit(@NotNull Properties properties) throws GitCommitIdExecutionException {
+ private void loadGitDataWithJGit(@Nonnull Properties properties) throws GitCommitIdExecutionException {
GitDataProvider jGitProvider = JGitProvider
.on(dotGitDirectory, log)
.setPrefixDot(prefixDot)
@@ -544,7 +527,7 @@ void loadGitDataWithJGit(@NotNull Properties properties) throws GitCommitIdExecu
jGitProvider.loadGitData(evaluateOnCommit, properties);
}
- void maybeGeneratePropertiesFile(@NotNull Properties localProperties, File base, String propertiesFilename) throws GitCommitIdExecutionException {
+ private void maybeGeneratePropertiesFile(@Nonnull Properties localProperties, File base, String propertiesFilename) throws GitCommitIdExecutionException {
try {
final File gitPropsFile = craftPropertiesOutputFile(base, propertiesFilename);
final boolean isJsonFormat = "json".equalsIgnoreCase(format);
@@ -582,33 +565,22 @@ void maybeGeneratePropertiesFile(@NotNull Properties localProperties, File base,
if (shouldGenerate) {
Files.createParentDirs(gitPropsFile);
- Writer outputWriter = null;
- OutputStream outputStream = null;
- boolean threw = true;
-
- try {
- outputStream = new FileOutputStream(gitPropsFile);
+ try (OutputStream outputStream = new FileOutputStream(gitPropsFile)) {
SortedProperties sortedLocalProperties = new SortedProperties();
sortedLocalProperties.putAll(localProperties);
if (isJsonFormat) {
- outputWriter = new OutputStreamWriter(outputStream, sourceCharset);
- log.info("Writing json file to [{}] (for module {})...", gitPropsFile.getAbsolutePath(), project.getName());
- ObjectMapper mapper = new ObjectMapper();
- mapper.writerWithDefaultPrettyPrinter().writeValue(outputWriter, sortedLocalProperties);
+ try (Writer outputWriter = new OutputStreamWriter(outputStream, sourceCharset)) {
+ log.info("Writing json file to [{}] (for module {})...", gitPropsFile.getAbsolutePath(), project.getName());
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.writerWithDefaultPrettyPrinter().writeValue(outputWriter, sortedLocalProperties);
+ }
} else {
log.info("Writing properties file to [{}] (for module {})...", gitPropsFile.getAbsolutePath(), project.getName());
// using outputStream directly instead of outputWriter this way the UTF-8 characters appears in unicode escaped form
sortedLocalProperties.store(outputStream, "Generated by Git-Commit-Id-Plugin");
}
- threw = false;
} catch (final IOException ex) {
throw new RuntimeException("Cannot create custom git properties file: " + gitPropsFile, ex);
- } finally {
- if (outputWriter == null) {
- Closeables.close(outputStream, threw);
- } else {
- Closeables.close(outputWriter, threw);
- }
}
} else {
log.info("Properties file [{}] is up-to-date (for module {})...", gitPropsFile.getAbsolutePath(), project.getName());
@@ -618,7 +590,7 @@ void maybeGeneratePropertiesFile(@NotNull Properties localProperties, File base,
}
}
- @VisibleForTesting File craftPropertiesOutputFile(File base, String propertiesFilename) {
+ File craftPropertiesOutputFile(File base, String propertiesFilename) {
File returnPath = new File(base, propertiesFilename);
File currentPropertiesFilepath = new File(propertiesFilename);
@@ -630,43 +602,24 @@ void maybeGeneratePropertiesFile(@NotNull Properties localProperties, File base,
}
- boolean isPomProject(@NotNull MavenProject project) {
+ private boolean isPomProject(@Nonnull MavenProject project) {
return project.getPackaging().equalsIgnoreCase("pom");
}
- private void put(@NotNull Properties properties, String key, String value) {
- String keyWithPrefix = prefixDot + key;
- log.info(keyWithPrefix + " " + value);
- PropertyManager.putWithoutPrefix(properties, keyWithPrefix, value);
- }
-
private boolean directoryExists(@Nullable File fileLocation) {
return fileLocation != null && fileLocation.exists() && fileLocation.isDirectory();
}
- @SuppressWarnings("resource")
- private Properties readJsonProperties(@NotNull File jsonFile) throws CannotReadFileException {
+ private Properties readJsonProperties(@Nonnull File jsonFile) throws CannotReadFileException {
final HashMap propertiesMap;
- Closeable closeable = null;
-
- try {
- boolean threw = true;
- try {
- final FileInputStream fis = new FileInputStream(jsonFile);
- closeable = fis;
-
- final InputStreamReader reader = new InputStreamReader(fis, sourceCharset);
- closeable = reader;
-
+ try (final FileInputStream fis = new FileInputStream(jsonFile)) {
+ try (final InputStreamReader reader = new InputStreamReader(fis, sourceCharset)) {
final ObjectMapper mapper = new ObjectMapper();
final TypeReference> mapTypeRef =
new TypeReference>() {};
propertiesMap = mapper.readValue(reader, mapTypeRef);
- threw = false;
- } finally {
- Closeables.close(closeable, threw);
}
} catch (final Exception ex) {
throw new CannotReadFileException(ex);
@@ -681,27 +634,12 @@ private Properties readJsonProperties(@NotNull File jsonFile) throws CannotReadF
return retVal;
}
- @SuppressWarnings("resource")
- private Properties readProperties(@NotNull File propertiesFile) throws CannotReadFileException {
- Closeable closeable = null;
-
- try {
- boolean threw = true;
- try {
- final FileInputStream fis = new FileInputStream(propertiesFile);
- closeable = fis;
-
- final InputStreamReader reader = new InputStreamReader(fis, sourceCharset);
- closeable = reader;
-
+ private Properties readProperties(@Nonnull File propertiesFile) throws CannotReadFileException {
+ try (final FileInputStream fis = new FileInputStream(propertiesFile)) {
+ try (final InputStreamReader reader = new InputStreamReader(fis, sourceCharset)) {
final Properties retVal = new Properties();
-
retVal.load(reader);
- threw = false;
-
return retVal;
- } finally {
- Closeables.close(closeable, threw);
}
} catch (final Exception ex) {
throw new CannotReadFileException(ex);
@@ -715,94 +653,4 @@ static class CannotReadFileException extends Exception {
super(cause);
}
}
-
- // SETTERS FOR TESTS ----------------------------------------------------
-
- @VisibleForTesting void setFormat(String format) {
- this.format = format;
- }
-
- @VisibleForTesting void setVerbose(boolean verbose) {
- this.verbose = verbose;
- }
-
- @VisibleForTesting void setProject(MavenProject project) {
- this.project = project;
- }
-
- @VisibleForTesting void setDotGitDirectory(File dotGitDirectory) {
- this.dotGitDirectory = dotGitDirectory;
- }
-
- @VisibleForTesting void setPrefix(String prefix) {
- this.prefix = prefix;
- }
-
- @VisibleForTesting void setDateFormat(String dateFormat) {
- this.dateFormat = dateFormat;
- }
-
- @VisibleForTesting Properties getProperties() {
- return properties;
- }
-
- @VisibleForTesting void setGitDescribe(GitDescribeConfig gitDescribe) {
- this.gitDescribe = gitDescribe;
- }
-
- @VisibleForTesting void setAbbrevLength(int abbrevLength) {
- this.abbrevLength = abbrevLength;
- }
-
- @VisibleForTesting void setExcludeProperties(List excludeProperties) {
- this.excludeProperties = excludeProperties;
- }
-
- @VisibleForTesting void setIncludeOnlyProperties(List includeOnlyProperties) {
- this.includeOnlyProperties = includeOnlyProperties;
- }
-
- @VisibleForTesting void setUseNativeGit(boolean useNativeGit) {
- this.useNativeGit = useNativeGit;
- }
-
- @VisibleForTesting void setCommitIdGenerationMode(String commitIdGenerationMode) {
- this.commitIdGenerationMode = commitIdGenerationMode;
- }
-
- @VisibleForTesting void setSkip(boolean skip) {
- this.skip = skip;
- }
-
- @VisibleForTesting void setSkipPoms(boolean skipPoms) {
- this.skipPoms = skipPoms;
- }
-
- @VisibleForTesting void setGenerateGitPropertiesFile(boolean generateGitPropertiesFile) {
- this.generateGitPropertiesFile = generateGitPropertiesFile;
- }
-
- @VisibleForTesting void setGenerateGitPropertiesFilename(String generateGitPropertiesFilename) {
- this.generateGitPropertiesFilename = generateGitPropertiesFilename;
- }
-
- @VisibleForTesting void setDateFormatTimeZone(String dateFormatTimeZone) {
- this.dateFormatTimeZone = dateFormatTimeZone;
- }
-
- @VisibleForTesting void setFailOnNoGitDirectory(boolean failOnNoGitDirectory) {
- this.failOnNoGitDirectory = failOnNoGitDirectory;
- }
-
- @VisibleForTesting void setFailOnUnableToExtractRepoInfo(boolean failOnUnableToExtractRepoInfo) {
- this.failOnUnableToExtractRepoInfo = failOnUnableToExtractRepoInfo;
- }
-
- @VisibleForTesting String getEvaluateOnCommit() {
- return evaluateOnCommit;
- }
-
- @VisibleForTesting void setEvaluateOnCommit(String evaluateOnCommit) {
- this.evaluateOnCommit = evaluateOnCommit;
- }
}
diff --git a/src/main/java/pl/project13/maven/git/GitDataProvider.java b/src/main/java/pl/project13/maven/git/GitDataProvider.java
index bdae0eba..2b676d63 100644
--- a/src/main/java/pl/project13/maven/git/GitDataProvider.java
+++ b/src/main/java/pl/project13/maven/git/GitDataProvider.java
@@ -18,12 +18,12 @@
package pl.project13.maven.git;
import org.apache.http.client.utils.URIBuilder;
-import org.jetbrains.annotations.NotNull;
import pl.project13.maven.git.build.BuildServerDataProvider;
import pl.project13.maven.git.build.UnknownBuildServerData;
import pl.project13.maven.git.log.LoggerBridge;
import pl.project13.maven.git.util.PropertyManager;
+import javax.annotation.Nonnull;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;
@@ -36,7 +36,7 @@
public abstract class GitDataProvider implements GitProvider {
- @NotNull
+ @Nonnull
protected final LoggerBridge log;
protected String prefixDot;
@@ -53,7 +53,7 @@ public abstract class GitDataProvider implements GitProvider {
protected String evaluateOnCommit;
- public GitDataProvider(@NotNull LoggerBridge log) {
+ public GitDataProvider(@Nonnull LoggerBridge log) {
this.log = log;
}
@@ -87,7 +87,7 @@ public GitDataProvider setDateFormatTimeZone(String dateFormatTimeZone) {
return this;
}
- public void loadGitData(@NotNull String evaluateOnCommit, @NotNull Properties properties) throws GitCommitIdExecutionException {
+ public void loadGitData(@Nonnull String evaluateOnCommit, @Nonnull Properties properties) throws GitCommitIdExecutionException {
this.evaluateOnCommit = evaluateOnCommit;
init();
// git.user.name
@@ -103,6 +103,7 @@ public void loadGitData(@NotNull String evaluateOnCommit, @NotNull Properties pr
put(properties, GitCommitPropertyConstant.BRANCH, determineBranchName(System.getenv()));
// git.commit.id.describe
maybePutGitDescribe(properties);
+ loadShortDescribe(properties);
// git.commit.id
switch (commitIdGenerationMode) {
case FULL: {
@@ -146,7 +147,7 @@ public void loadGitData(@NotNull String evaluateOnCommit, @NotNull Properties pr
}
}
- private void maybePutGitDescribe(@NotNull Properties properties) throws GitCommitIdExecutionException {
+ private void maybePutGitDescribe(@Nonnull Properties properties) throws GitCommitIdExecutionException {
boolean isGitDescribeOptOutByDefault = (gitDescribe == null);
boolean isGitDescribeOptOutByConfiguration = (gitDescribe != null && !gitDescribe.isSkip());
@@ -155,6 +156,27 @@ private void maybePutGitDescribe(@NotNull Properties properties) throws GitCommi
}
}
+ protected void loadShortDescribe(@Nonnull Properties properties) {
+ //removes git hash part from describe
+ String commitDescribe = properties.getProperty(prefixDot + GitCommitPropertyConstant.COMMIT_DESCRIBE);
+
+ if (commitDescribe != null) {
+ int startPos = commitDescribe.indexOf("-g");
+ if (startPos > 0) {
+ String commitShortDescribe;
+ int endPos = commitDescribe.indexOf('-', startPos + 1);
+ if (endPos < 0) {
+ commitShortDescribe = commitDescribe.substring(0, startPos);
+ } else {
+ commitShortDescribe = commitDescribe.substring(0, startPos) + commitDescribe.substring(endPos);
+ }
+ put(properties, GitCommitPropertyConstant.COMMIT_SHORT_DESCRIBE, commitShortDescribe);
+ } else {
+ put(properties, GitCommitPropertyConstant.COMMIT_SHORT_DESCRIBE, commitDescribe);
+ }
+ }
+ }
+
void validateAbbrevLength(int abbrevLength) throws GitCommitIdExecutionException {
if (abbrevLength < 2 || abbrevLength > 40) {
throw new GitCommitIdExecutionException(String.format("Abbreviated commit id length must be between 2 and 40, inclusive! Was [%s]. ", abbrevLength) +
@@ -169,7 +191,7 @@ void validateAbbrevLength(int abbrevLength) throws GitCommitIdExecutionException
* @param env environment settings
* @return results of getBranchName() or, if in Jenkins/Hudson, value of GIT_BRANCH
*/
- protected String determineBranchName(@NotNull Map env) throws GitCommitIdExecutionException {
+ protected String determineBranchName(@Nonnull Map env) throws GitCommitIdExecutionException {
BuildServerDataProvider buildServerDataProvider = BuildServerDataProvider.getBuildServerProvider(env,log);
if (!(buildServerDataProvider instanceof UnknownBuildServerData)) {
String branchName = buildServerDataProvider.getBuildBranch();
@@ -191,7 +213,7 @@ protected SimpleDateFormat getSimpleDateFormatWithTimeZone() {
return smf;
}
- protected void put(@NotNull Properties properties, String key, String value) {
+ protected void put(@Nonnull Properties properties, String key, String value) {
String keyWithPrefix = prefixDot + key;
log.info("{} {}", keyWithPrefix, value);
PropertyManager.putWithoutPrefix(properties, keyWithPrefix, value);
diff --git a/src/main/java/pl/project13/maven/git/GitDirLocator.java b/src/main/java/pl/project13/maven/git/GitDirLocator.java
index e1a4077b..834386f6 100644
--- a/src/main/java/pl/project13/maven/git/GitDirLocator.java
+++ b/src/main/java/pl/project13/maven/git/GitDirLocator.java
@@ -19,9 +19,9 @@
import org.apache.maven.project.MavenProject;
import org.eclipse.jgit.lib.Constants;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import java.io.*;
import java.util.List;
@@ -39,7 +39,7 @@ public GitDirLocator(MavenProject mavenProject, List reactorProjec
}
@Nullable
- public File lookupGitDirectory(@NotNull File manuallyConfiguredDir) {
+ public File lookupGitDirectory(@Nonnull File manuallyConfiguredDir) {
if (manuallyConfiguredDir.exists()) {
// If manuallyConfiguredDir is a directory then we can use it as the git path.
@@ -98,42 +98,30 @@ private File findProjectGitDirectory() {
*
* @return File object with path loaded or null
*/
- private File processGitDirFile(@NotNull File file) {
- try {
- BufferedReader reader = null;
-
- try {
- reader = new BufferedReader(new FileReader(file));
-
- // There should be just one line in the file, e.g.
- // "gitdir: /usr/local/src/parentproject/.git/modules/submodule"
- String line = reader.readLine();
- if (line == null) {
- return null;
- }
- // Separate the key and the value in the string.
- String[] parts = line.split(": ");
-
- // If we don't have 2 parts or if the key is not gitdir then give up.
- if (parts.length != 2 || !parts[0].equals("gitdir")) {
- return null;
- }
+ private File processGitDirFile(@Nonnull File file) {
+ try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
+ // There should be just one line in the file, e.g.
+ // "gitdir: /usr/local/src/parentproject/.git/modules/submodule"
+ String line = reader.readLine();
+ if (line == null) {
+ return null;
+ }
+ // Separate the key and the value in the string.
+ String[] parts = line.split(": ");
- // All seems ok so return the "gitdir" value read from the file.
- File gitDir = new File(parts[1]);
- if (gitDir.isAbsolute()) {
- // gitdir value is an absolute path. Return as-is
- return gitDir;
- } else {
- // gitdir value is relative.
- return new File(file.getParentFile(), parts[1]);
- }
- } catch (FileNotFoundException e) {
+ // If we don't have 2 parts or if the key is not gitdir then give up.
+ if (parts.length != 2 || !parts[0].equals("gitdir")) {
return null;
- } finally {
- if (reader != null) {
- reader.close();
- }
+ }
+
+ // All seems ok so return the "gitdir" value read from the file.
+ File gitDir = new File(parts[1]);
+ if (gitDir.isAbsolute()) {
+ // gitdir value is an absolute path. Return as-is
+ return gitDir;
+ } else {
+ // gitdir value is relative.
+ return new File(file.getParentFile(), parts[1]);
}
} catch (IOException e) {
return null;
diff --git a/src/main/java/pl/project13/maven/git/GitProvider.java b/src/main/java/pl/project13/maven/git/GitProvider.java
index cc4b875c..918d1b8b 100644
--- a/src/main/java/pl/project13/maven/git/GitProvider.java
+++ b/src/main/java/pl/project13/maven/git/GitProvider.java
@@ -1,44 +1,44 @@
package pl.project13.maven.git;
public interface GitProvider {
- public void init() throws GitCommitIdExecutionException;
+ void init() throws GitCommitIdExecutionException;
- public String getBuildAuthorName() throws GitCommitIdExecutionException;
+ String getBuildAuthorName() throws GitCommitIdExecutionException;
- public String getBuildAuthorEmail() throws GitCommitIdExecutionException;
+ String getBuildAuthorEmail() throws GitCommitIdExecutionException;
- public void prepareGitToExtractMoreDetailedRepoInformation() throws GitCommitIdExecutionException;
+ void prepareGitToExtractMoreDetailedRepoInformation() throws GitCommitIdExecutionException;
- public String getBranchName() throws GitCommitIdExecutionException;
+ String getBranchName() throws GitCommitIdExecutionException;
- public String getGitDescribe() throws GitCommitIdExecutionException;
+ String getGitDescribe() throws GitCommitIdExecutionException;
- public String getCommitId() throws GitCommitIdExecutionException;
+ String getCommitId() throws GitCommitIdExecutionException;
- public String getAbbrevCommitId() throws GitCommitIdExecutionException;
+ String getAbbrevCommitId() throws GitCommitIdExecutionException;
- public boolean isDirty() throws GitCommitIdExecutionException;
+ boolean isDirty() throws GitCommitIdExecutionException;
- public String getCommitAuthorName() throws GitCommitIdExecutionException;
+ String getCommitAuthorName() throws GitCommitIdExecutionException;
- public String getCommitAuthorEmail() throws GitCommitIdExecutionException;
+ String getCommitAuthorEmail() throws GitCommitIdExecutionException;
- public String getCommitMessageFull() throws GitCommitIdExecutionException;
+ String getCommitMessageFull() throws GitCommitIdExecutionException;
- public String getCommitMessageShort() throws GitCommitIdExecutionException;
+ String getCommitMessageShort() throws GitCommitIdExecutionException;
- public String getCommitTime() throws GitCommitIdExecutionException;
+ String getCommitTime() throws GitCommitIdExecutionException;
- public String getRemoteOriginUrl() throws GitCommitIdExecutionException;
+ String getRemoteOriginUrl() throws GitCommitIdExecutionException;
- public String getTags() throws GitCommitIdExecutionException;
+ String getTags() throws GitCommitIdExecutionException;
- public String getClosestTagName() throws GitCommitIdExecutionException;
+ String getClosestTagName() throws GitCommitIdExecutionException;
- public String getClosestTagCommitCount() throws GitCommitIdExecutionException;
+ String getClosestTagCommitCount() throws GitCommitIdExecutionException;
- public String getTotalCommitCount() throws GitCommitIdExecutionException;
+ String getTotalCommitCount() throws GitCommitIdExecutionException;
- public void finalCleanUp() throws GitCommitIdExecutionException;
+ void finalCleanUp() throws GitCommitIdExecutionException;
}
diff --git a/src/main/java/pl/project13/maven/git/GitRepositoryState.java b/src/main/java/pl/project13/maven/git/GitRepositoryState.java
index c00b70dd..3f0a1351 100644
--- a/src/main/java/pl/project13/maven/git/GitRepositoryState.java
+++ b/src/main/java/pl/project13/maven/git/GitRepositoryState.java
@@ -17,9 +17,7 @@
package pl.project13.maven.git;
-import com.google.common.base.Joiner;
-import org.jetbrains.annotations.NotNull;
-
+import javax.annotation.Nonnull;
import java.util.Set;
/**
@@ -173,14 +171,14 @@ public String toJson() {
appendProperty(sb, "buildUserName", buildUserName);
appendProperty(sb, "buildUserEmail", buildUserEmail);
- appendProperty(sb, "tags", Joiner.on(",").join(tags));
+ appendProperty(sb, "tags", String.join(",", tags));
appendProperty(sb, "mavenProjectVersion", mavenProjectVersion);
return sb.append("}").toString();
}
- private void appendProperty(@NotNull StringBuilder sb, String label, String value) {
+ private void appendProperty(@Nonnull StringBuilder sb, String label, String value) {
sb.append(String.format("\"%s\": \"%s\",", label, value));
}
diff --git a/src/main/java/pl/project13/maven/git/JGitProvider.java b/src/main/java/pl/project13/maven/git/JGitProvider.java
index 7dc05383..0e9e5624 100644
--- a/src/main/java/pl/project13/maven/git/JGitProvider.java
+++ b/src/main/java/pl/project13/maven/git/JGitProvider.java
@@ -18,8 +18,6 @@
package pl.project13.maven.git;
import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Joiner;
-import com.google.common.base.MoreObjects;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.AbbreviatedObjectId;
@@ -31,7 +29,6 @@
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.revwalk.RevWalkUtils;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
-import org.jetbrains.annotations.NotNull;
import pl.project13.jgit.DescribeCommand;
import pl.project13.jgit.DescribeResult;
@@ -43,8 +40,12 @@
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
+import java.util.Optional;
+
import org.eclipse.jgit.storage.file.WindowCacheConfig;
+import javax.annotation.Nonnull;
+
public class JGitProvider extends GitDataProvider {
private File dotGitDirectory;
@@ -54,12 +55,12 @@ public class JGitProvider extends GitDataProvider {
private RevCommit evalCommit;
private JGitCommon jGitCommon;
- @NotNull
- public static JGitProvider on(@NotNull File dotGitDirectory, @NotNull LoggerBridge log) {
+ @Nonnull
+ public static JGitProvider on(@Nonnull File dotGitDirectory, @Nonnull LoggerBridge log) {
return new JGitProvider(dotGitDirectory, log);
}
- JGitProvider(@NotNull File dotGitDirectory, @NotNull LoggerBridge log) {
+ JGitProvider(@Nonnull File dotGitDirectory, @Nonnull LoggerBridge log) {
super(log);
this.dotGitDirectory = dotGitDirectory;
this.jGitCommon = new JGitCommon(log);
@@ -74,13 +75,13 @@ public void init() throws GitCommitIdExecutionException {
@Override
public String getBuildAuthorName() throws GitCommitIdExecutionException {
String userName = git.getConfig().getString("user", null, "name");
- return MoreObjects.firstNonNull(userName, "");
+ return Optional.ofNullable(userName).orElse("");
}
@Override
public String getBuildAuthorEmail() throws GitCommitIdExecutionException {
String userEmail = git.getConfig().getString("user", null, "email");
- return MoreObjects.firstNonNull(userEmail, "");
+ return Optional.ofNullable(userEmail).orElse("");
}
@Override
@@ -94,7 +95,7 @@ public void prepareGitToExtractMoreDetailedRepoInformation() throws GitCommitIdE
throw new GitCommitIdExecutionException("Could not get " + evaluateOnCommit + " Ref, are you sure you have set the dotGitDirectory property of this plugin to a valid path?");
}
revWalk = new RevWalk(git);
- ObjectId headObjectId = null;
+ ObjectId headObjectId;
if (evaluateOnCommitReference != null) {
headObjectId = evaluateOnCommitReference.getObjectId();
} else {
@@ -184,7 +185,7 @@ public String getTags() throws GitCommitIdExecutionException {
Repository repo = getGitRepository();
ObjectId headId = evalCommit.toObjectId();
Collection tags = jGitCommon.getTags(repo, headId);
- return Joiner.on(",").join(tags);
+ return String.join(",", tags);
} catch (GitAPIException e) {
log.error("Unable to extract tags from commit: {} ({})", evalCommit.getName(), e.getClass().getName());
return "";
@@ -240,7 +241,7 @@ public void finalCleanUp() {
}
}
- @VisibleForTesting String getGitDescribe(@NotNull Repository repository) throws GitCommitIdExecutionException {
+ @VisibleForTesting String getGitDescribe(@Nonnull Repository repository) throws GitCommitIdExecutionException {
try {
DescribeResult describeResult = DescribeCommand
.on(evaluateOnCommit, repository, log)
@@ -264,7 +265,7 @@ private String getAbbrevCommitId(ObjectReader objectReader, RevCommit headCommit
}
}
- @NotNull
+ @Nonnull
private Repository getGitRepository() throws GitCommitIdExecutionException {
Repository repository;
diff --git a/src/main/java/pl/project13/maven/git/NativeGitProvider.java b/src/main/java/pl/project13/maven/git/NativeGitProvider.java
index 439133a4..875f2241 100644
--- a/src/main/java/pl/project13/maven/git/NativeGitProvider.java
+++ b/src/main/java/pl/project13/maven/git/NativeGitProvider.java
@@ -19,13 +19,13 @@
import static java.lang.String.format;
-import com.google.common.base.Throwables;
-
-import org.jetbrains.annotations.NotNull;
import pl.project13.maven.git.log.LoggerBridge;
+import javax.annotation.Nonnull;
import java.io.*;
+import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
+import java.util.concurrent.TimeUnit;
public class NativeGitProvider extends GitDataProvider {
@@ -34,16 +34,19 @@ public class NativeGitProvider extends GitDataProvider {
final File dotGitDirectory;
+ final long nativeGitTimeoutInMs;
+
final File canonical;
- @NotNull
- public static NativeGitProvider on(@NotNull File dotGitDirectory, @NotNull LoggerBridge log) {
- return new NativeGitProvider(dotGitDirectory, log);
+ @Nonnull
+ public static NativeGitProvider on(@Nonnull File dotGitDirectory, long nativeGitTimeoutInMs, @Nonnull LoggerBridge log) {
+ return new NativeGitProvider(dotGitDirectory, nativeGitTimeoutInMs, log);
}
- NativeGitProvider(@NotNull File dotGitDirectory, @NotNull LoggerBridge log) {
+ NativeGitProvider(@Nonnull File dotGitDirectory, long nativeGitTimeoutInMs, @Nonnull LoggerBridge log) {
super(log);
this.dotGitDirectory = dotGitDirectory;
+ this.nativeGitTimeoutInMs = nativeGitTimeoutInMs;
try {
this.canonical = dotGitDirectory.getCanonicalFile();
} catch (IOException ex) {
@@ -59,24 +62,24 @@ public void init() throws GitCommitIdExecutionException {
@Override
public String getBuildAuthorName() throws GitCommitIdExecutionException {
try {
- return runGitCommand(canonical, "config --get user.name");
+ return runGitCommand(canonical, nativeGitTimeoutInMs, "config --get user.name");
} catch (NativeCommandException e) {
if (e.getExitCode() == 1) { // No config file found
return "";
}
- throw Throwables.propagate(e);
+ throw new RuntimeException(e);
}
}
@Override
public String getBuildAuthorEmail() throws GitCommitIdExecutionException {
try {
- return runGitCommand(canonical, "config --get user.email");
+ return runGitCommand(canonical, nativeGitTimeoutInMs, "config --get user.email");
} catch (NativeCommandException e) {
if (e.getExitCode() == 1) { // No config file found
return "";
}
- throw Throwables.propagate(e);
+ throw new RuntimeException(e);
}
}
@@ -92,7 +95,7 @@ public String getBranchName() throws GitCommitIdExecutionException {
private String getBranch(File canonical) throws GitCommitIdExecutionException {
String branch;
try {
- branch = runGitCommand(canonical, "symbolic-ref " + evaluateOnCommit);
+ branch = runGitCommand(canonical, nativeGitTimeoutInMs, "symbolic-ref " + evaluateOnCommit);
if (branch != null) {
branch = branch.replace("refs/heads/", "");
}
@@ -105,10 +108,10 @@ private String getBranch(File canonical) throws GitCommitIdExecutionException {
if (noSymbolicRef || noSuchRef) {
branch = getCommitId();
} else {
- throw Throwables.propagate(e);
+ throw new RuntimeException(e);
}
} else {
- throw Throwables.propagate(e);
+ throw new RuntimeException(e);
}
}
return branch;
@@ -117,7 +120,7 @@ private String getBranch(File canonical) throws GitCommitIdExecutionException {
@Override
public String getGitDescribe() throws GitCommitIdExecutionException {
final String argumentsForGitDescribe = getArgumentsForGitDescribe(gitDescribe);
- return runQuietGitCommand(canonical, "describe" + argumentsForGitDescribe);
+ return runQuietGitCommand(canonical, nativeGitTimeoutInMs, "describe" + argumentsForGitDescribe);
}
private String getArgumentsForGitDescribe(GitDescribeConfig describeConfig) {
@@ -170,10 +173,10 @@ public String getCommitId() throws GitCommitIdExecutionException {
// in case evaluateOnCommit is not a reference rev-list will just return the argument given
// and thus it's always safe(r) to unwrap it
// however when evaluateOnCommit is not set we don't want to waste calls to the native binary
- String actualCommitId = runQuietGitCommand(canonical, "rev-list -n 1 " + evaluateOnCommit);
- return runQuietGitCommand(canonical, "rev-parse " + actualCommitId);
+ String actualCommitId = runQuietGitCommand(canonical, nativeGitTimeoutInMs, "rev-list -n 1 " + evaluateOnCommit);
+ return runQuietGitCommand(canonical, nativeGitTimeoutInMs, "rev-parse " + actualCommitId);
} else {
- return runQuietGitCommand(canonical, "rev-parse HEAD");
+ return runQuietGitCommand(canonical, nativeGitTimeoutInMs, "rev-parse HEAD");
}
}
@@ -193,45 +196,45 @@ public String getAbbrevCommitId() throws GitCommitIdExecutionException {
@Override
public boolean isDirty() throws GitCommitIdExecutionException {
- return !tryCheckEmptyRunGitCommand(canonical, "status -s");
+ return !tryCheckEmptyRunGitCommand(canonical, nativeGitTimeoutInMs, "status -s");
}
@Override
public String getCommitAuthorName() throws GitCommitIdExecutionException {
- return runQuietGitCommand(canonical, "log -1 --pretty=format:%an " + evaluateOnCommit);
+ return runQuietGitCommand(canonical, nativeGitTimeoutInMs, "log -1 --pretty=format:%an " + evaluateOnCommit);
}
@Override
public String getCommitAuthorEmail() throws GitCommitIdExecutionException {
- return runQuietGitCommand(canonical, "log -1 --pretty=format:%ae " + evaluateOnCommit);
+ return runQuietGitCommand(canonical, nativeGitTimeoutInMs, "log -1 --pretty=format:%ae " + evaluateOnCommit);
}
@Override
public String getCommitMessageFull() throws GitCommitIdExecutionException {
- return runQuietGitCommand(canonical, "log -1 --pretty=format:%B " + evaluateOnCommit);
+ return runQuietGitCommand(canonical, nativeGitTimeoutInMs, "log -1 --pretty=format:%B " + evaluateOnCommit);
}
@Override
public String getCommitMessageShort() throws GitCommitIdExecutionException {
- return runQuietGitCommand(canonical, "log -1 --pretty=format:%s " + evaluateOnCommit);
+ return runQuietGitCommand(canonical, nativeGitTimeoutInMs, "log -1 --pretty=format:%s " + evaluateOnCommit);
}
@Override
public String getCommitTime() throws GitCommitIdExecutionException {
- String value = runQuietGitCommand(canonical, "log -1 --pretty=format:%ct " + evaluateOnCommit);
+ String value = runQuietGitCommand(canonical, nativeGitTimeoutInMs, "log -1 --pretty=format:%ct " + evaluateOnCommit);
SimpleDateFormat smf = getSimpleDateFormatWithTimeZone();
return smf.format(Long.parseLong(value) * 1000L);
}
@Override
public String getTags() throws GitCommitIdExecutionException {
- final String result = runQuietGitCommand(canonical, "tag --contains " + evaluateOnCommit);
+ final String result = runQuietGitCommand(canonical, nativeGitTimeoutInMs, "tag --contains " + evaluateOnCommit);
return result.replace('\n', ',');
}
@Override
public String getRemoteOriginUrl() throws GitCommitIdExecutionException {
- return getOriginRemote(canonical);
+ return getOriginRemote(canonical, nativeGitTimeoutInMs);
}
@Override
@@ -249,7 +252,7 @@ public String getClosestTagName() throws GitCommitIdExecutionException {
argumentsForGitDescribe.append(" --match=").append(matchOption);
}
}
- return runGitCommand(canonical, argumentsForGitDescribe.toString());
+ return runGitCommand(canonical, nativeGitTimeoutInMs, argumentsForGitDescribe.toString());
} catch (NativeCommandException ignore) {
// could not find any tags to describe
}
@@ -260,23 +263,23 @@ public String getClosestTagName() throws GitCommitIdExecutionException {
public String getClosestTagCommitCount() throws GitCommitIdExecutionException {
String closestTagName = getClosestTagName();
if (closestTagName != null && !closestTagName.trim().isEmpty()) {
- return runQuietGitCommand(canonical, "rev-list " + closestTagName + ".." + evaluateOnCommit + " --count");
+ return runQuietGitCommand(canonical, nativeGitTimeoutInMs, "rev-list " + closestTagName + ".." + evaluateOnCommit + " --count");
}
return "";
}
@Override
public String getTotalCommitCount() throws GitCommitIdExecutionException {
- return runQuietGitCommand(canonical, "rev-list " + evaluateOnCommit + " --count");
+ return runQuietGitCommand(canonical, nativeGitTimeoutInMs, "rev-list " + evaluateOnCommit + " --count");
}
@Override
public void finalCleanUp() throws GitCommitIdExecutionException {
}
- private String getOriginRemote(File directory) throws GitCommitIdExecutionException {
+ private String getOriginRemote(File directory, long nativeGitTimeoutInMs) throws GitCommitIdExecutionException {
try {
- String remoteUrl = runGitCommand(directory, "ls-remote --get-url");
+ String remoteUrl = runGitCommand(directory, nativeGitTimeoutInMs, "ls-remote --get-url");
return stripCredentialsFromOriginUrl(remoteUrl);
} catch (NativeCommandException ignore) {
@@ -292,13 +295,13 @@ private String getOriginRemote(File directory) throws GitCommitIdExecutionExcept
* Return true if the result is empty.
*
**/
- private boolean tryCheckEmptyRunGitCommand(File directory, String gitCommand) {
+ private boolean tryCheckEmptyRunGitCommand(File directory, long nativeGitTimeoutInMs, String gitCommand) {
try {
String env = System.getenv("GIT_PATH");
String exec = (env == null) ? "git" : env;
String command = String.format("%s %s", exec, gitCommand);
- return getRunner().runEmpty(directory, command);
+ return getRunner().runEmpty(directory, nativeGitTimeoutInMs, command);
} catch (IOException ex) {
// Error means "non-empty"
return false;
@@ -306,29 +309,29 @@ private boolean tryCheckEmptyRunGitCommand(File directory, String gitCommand) {
}
}
- private String runQuietGitCommand(File directory, String gitCommand) {
+ private String runQuietGitCommand(File directory, long nativeGitTimeoutInMs, String gitCommand) {
final String env = System.getenv("GIT_PATH");
final String exec = (env == null) ? "git" : env;
final String command = String.format("%s %s", exec, gitCommand);
try {
- return getRunner().run(directory, command.trim()).trim();
+ return getRunner().run(directory, nativeGitTimeoutInMs, command.trim()).trim();
} catch (IOException e) {
- throw Throwables.propagate(e);
+ throw new RuntimeException(e);
}
}
- private String runGitCommand(File directory, String gitCommand) throws NativeCommandException {
+ private String runGitCommand(File directory, long nativeGitTimeoutInMs, String gitCommand) throws NativeCommandException {
final String env = System.getenv("GIT_PATH");
final String exec = (env == null) ? "git" : env;
final String command = String.format("%s %s", exec, gitCommand);
try {
- return getRunner().run(directory, command.trim()).trim();
+ return getRunner().run(directory, nativeGitTimeoutInMs, command.trim()).trim();
} catch (NativeCommandException e) {
throw e;
} catch (IOException e) {
- throw Throwables.propagate(e);
+ throw new RuntimeException(e);
}
}
@@ -341,10 +344,10 @@ private ProcessRunner getRunner() {
public interface ProcessRunner {
/** Run a command and return the entire output as a String - naive, we know. */
- String run(File directory, String command) throws IOException;
+ String run(File directory, long nativeGitTimeoutInMs, String command) throws IOException;
/** Run a command and return false if it contains at least one output line*/
- boolean runEmpty(File directory, String command) throws IOException;
+ boolean runEmpty(File directory, long nativeGitTimeoutInMs, String command) throws IOException;
}
public static class NativeCommandException extends IOException {
@@ -395,7 +398,7 @@ public String getMessage() {
protected static class JavaProcessRunner implements ProcessRunner {
@Override
- public String run(File directory, String command) throws IOException {
+ public String run(File directory, long nativeGitTimeoutInMs, String command) throws IOException {
String output = "";
try {
ProcessBuilder builder = new ProcessBuilder(command.split("\\s"));
@@ -403,7 +406,7 @@ public String run(File directory, String command) throws IOException {
final InputStream is = proc.getInputStream();
final InputStream err = proc.getErrorStream();
- final BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+ final BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
final StringBuilder commandResult = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
@@ -411,12 +414,12 @@ public String run(File directory, String command) throws IOException {
}
final StringBuilder errMsg = readStderr(err);
- proc.waitFor();
+ proc.waitFor(nativeGitTimeoutInMs, TimeUnit.MILLISECONDS);
if (proc.exitValue() != 0) {
throw new NativeCommandException(proc.exitValue(), command, directory, output, errMsg.toString());
}
output = commandResult.toString();
- } catch (InterruptedException ex) {
+ } catch (final InterruptedException ex) {
throw new IOException(ex);
}
return output;
@@ -433,7 +436,7 @@ private StringBuilder readStderr(InputStream err) throws IOException {
}
@Override
- public boolean runEmpty(File directory, String command) throws IOException {
+ public boolean runEmpty(File directory, long nativeGitTimeoutInMs, String command) throws IOException {
boolean empty = true;
try {
@@ -451,12 +454,12 @@ public boolean runEmpty(File directory, String command) throws IOException {
}
final StringBuilder errMsg = readStderr(err);
- proc.waitFor();
+ proc.waitFor(nativeGitTimeoutInMs, TimeUnit.MILLISECONDS);
if (proc.exitValue() != 0) {
throw new NativeCommandException(proc.exitValue(), command, directory, "", errMsg.toString());
}
- } catch (InterruptedException ex) {
+ } catch (final InterruptedException ex) {
throw new IOException(ex);
}
return empty; // was non-empty
diff --git a/src/main/java/pl/project13/maven/git/PropertiesFilterer.java b/src/main/java/pl/project13/maven/git/PropertiesFilterer.java
index fa3ab792..f421c99c 100644
--- a/src/main/java/pl/project13/maven/git/PropertiesFilterer.java
+++ b/src/main/java/pl/project13/maven/git/PropertiesFilterer.java
@@ -20,15 +20,10 @@
import java.util.List;
import java.util.Properties;
-import org.jetbrains.annotations.Nullable;
-
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
-import com.google.common.base.Predicates;
-import com.google.common.collect.Lists;
-
import pl.project13.maven.git.log.LoggerBridge;
+import javax.annotation.Nullable;
+
public class PropertiesFilterer {
private LoggerBridge log;
@@ -42,25 +37,16 @@ public void filterNot(Properties properties, @Nullable List exclusions,
return;
}
- List> excludePredicates = Lists.transform(exclusions,
- new Function>() {
- @Override
- public Predicate apply(String exclude) {
- return Predicates.containsPattern(exclude);
- }
- });
-
- Predicate shouldExclude = Predicates.alwaysFalse();
- for (Predicate predicate : excludePredicates) {
- shouldExclude = Predicates.or(shouldExclude, predicate);
- }
-
- for (String key : properties.stringPropertyNames()) {
- if (isOurProperty(key, prefixDot) && shouldExclude.apply(key)) {
- log.debug("shouldExclude.apply({}) = {}", key, shouldExclude.apply(key));
- properties.remove(key);
- }
- }
+ properties.stringPropertyNames()
+ .stream()
+ .filter(key -> isOurProperty(key, prefixDot))
+ .forEach(key -> {
+ if (exclusions.stream()
+ .anyMatch(key::matches)) {
+ log.debug("shouldExclude.apply({})", key);
+ properties.remove(key);
+ }
+ });
}
public void filter(Properties properties, @Nullable List inclusions, String prefixDot) {
@@ -68,25 +54,16 @@ public void filter(Properties properties, @Nullable List inclusions, Str
return;
}
- List> includePredicates = Lists.transform(inclusions,
- new Function>() {
- @Override
- public Predicate apply(String exclude) {
- return Predicates.containsPattern(exclude);
- }
- });
-
- Predicate shouldInclude = Predicates.alwaysFalse();
- for (Predicate predicate : includePredicates) {
- shouldInclude = Predicates.or(shouldInclude, predicate);
- }
-
- for (String key : properties.stringPropertyNames()) {
- if (isOurProperty(key, prefixDot) && !shouldInclude.apply(key)) {
- log.debug("!shouldInclude.apply({}) = {}", key, shouldInclude.apply(key));
- properties.remove(key);
- }
- }
+ properties.stringPropertyNames()
+ .stream()
+ .filter(key -> isOurProperty(key, prefixDot))
+ .forEach(key -> {
+ if (inclusions.stream()
+ .noneMatch(key::matches)) {
+ log.debug("!shouldInclude.apply({})", key);
+ properties.remove(key);
+ }
+ });
}
private boolean isOurProperty(String key, String prefixDot) {
diff --git a/src/main/java/pl/project13/maven/git/build/BambooBuildServerData.java b/src/main/java/pl/project13/maven/git/build/BambooBuildServerData.java
index 122ef88c..f60f4ad2 100644
--- a/src/main/java/pl/project13/maven/git/build/BambooBuildServerData.java
+++ b/src/main/java/pl/project13/maven/git/build/BambooBuildServerData.java
@@ -1,15 +1,15 @@
package pl.project13.maven.git.build;
-import org.jetbrains.annotations.NotNull;
import pl.project13.maven.git.GitCommitPropertyConstant;
import pl.project13.maven.git.log.LoggerBridge;
+import javax.annotation.Nonnull;
import java.util.Map;
import java.util.Properties;
public class BambooBuildServerData extends BuildServerDataProvider {
- BambooBuildServerData(LoggerBridge log, @NotNull Map env) {
+ BambooBuildServerData(LoggerBridge log, @Nonnull Map env) {
super(log, env);
}
@@ -18,7 +18,7 @@ public static boolean isActiveServer(Map env) {
}
@Override
- void loadBuildNumber(@NotNull Properties properties) {
+ void loadBuildNumber(@Nonnull Properties properties) {
String buildNumber = env.get("BAMBOO_BUILDNUMBER");
put(properties, GitCommitPropertyConstant.BUILD_NUMBER, buildNumber == null ? "" : buildNumber);
diff --git a/src/main/java/pl/project13/maven/git/build/BuildServerDataProvider.java b/src/main/java/pl/project13/maven/git/build/BuildServerDataProvider.java
index 81e8810d..86b17991 100644
--- a/src/main/java/pl/project13/maven/git/build/BuildServerDataProvider.java
+++ b/src/main/java/pl/project13/maven/git/build/BuildServerDataProvider.java
@@ -1,11 +1,11 @@
package pl.project13.maven.git.build;
import org.apache.maven.project.MavenProject;
-import org.jetbrains.annotations.NotNull;
import pl.project13.maven.git.GitCommitPropertyConstant;
import pl.project13.maven.git.log.LoggerBridge;
import pl.project13.maven.git.util.PropertyManager;
+import javax.annotation.Nonnull;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
@@ -23,27 +23,27 @@ public abstract class BuildServerDataProvider {
private String prefixDot = "";
private MavenProject project = null;
- BuildServerDataProvider(@NotNull LoggerBridge log, @NotNull Map env) {
+ BuildServerDataProvider(@Nonnull LoggerBridge log, @Nonnull Map env) {
this.log = log;
this.env = env;
}
- public BuildServerDataProvider setDateFormat(@NotNull String dateFormat) {
+ public BuildServerDataProvider setDateFormat(@Nonnull String dateFormat) {
this.dateFormat = dateFormat;
return this;
}
- public BuildServerDataProvider setDateFormatTimeZone(@NotNull String dateFormatTimeZone) {
+ public BuildServerDataProvider setDateFormatTimeZone(@Nonnull String dateFormatTimeZone) {
this.dateFormatTimeZone = dateFormatTimeZone;
return this;
}
- public BuildServerDataProvider setProject(@NotNull MavenProject project) {
+ public BuildServerDataProvider setProject(@Nonnull MavenProject project) {
this.project = project;
return this;
}
- public BuildServerDataProvider setPrefixDot(@NotNull String prefixDot) {
+ public BuildServerDataProvider setPrefixDot(@Nonnull String prefixDot) {
this.prefixDot = prefixDot;
return this;
}
@@ -55,7 +55,7 @@ public BuildServerDataProvider setPrefixDot(@NotNull String prefixDot) {
* @param log logging provider which will be used to log events
* @return the corresponding {@link BuildServerDataProvider} for your environment or {@link UnknownBuildServerData}
*/
- public static BuildServerDataProvider getBuildServerProvider(@NotNull Map env, @NotNull LoggerBridge log) {
+ public static BuildServerDataProvider getBuildServerProvider(@Nonnull Map env, @Nonnull LoggerBridge log) {
if (BambooBuildServerData.isActiveServer(env)) {
return new BambooBuildServerData(log, env);
}
@@ -74,7 +74,7 @@ public static BuildServerDataProvider getBuildServerProvider(@NotNull Map env) {
+ GitlabBuildServerData(LoggerBridge log, @Nonnull Map env) {
super(log,env);
}
@@ -21,7 +21,7 @@ public static boolean isActiveServer(Map env) {
}
@Override
- void loadBuildNumber(@NotNull Properties properties) {
+ void loadBuildNumber(@Nonnull Properties properties) {
// GITLAB CI
// CI_PIPELINE_ID will be present if in a Gitlab CI environment (Gitlab >8.10 & Gitlab CI >0.5) and contains a server wide unique ID for a pipeline run
String uniqueBuildNumber = env.get("CI_PIPELINE_ID");
diff --git a/src/main/java/pl/project13/maven/git/build/HudsonJenkinsBuildServerData.java b/src/main/java/pl/project13/maven/git/build/HudsonJenkinsBuildServerData.java
index d42a6da4..5d577e87 100644
--- a/src/main/java/pl/project13/maven/git/build/HudsonJenkinsBuildServerData.java
+++ b/src/main/java/pl/project13/maven/git/build/HudsonJenkinsBuildServerData.java
@@ -1,9 +1,9 @@
package pl.project13.maven.git.build;
-import org.jetbrains.annotations.NotNull;
import pl.project13.maven.git.GitCommitPropertyConstant;
import pl.project13.maven.git.log.LoggerBridge;
+import javax.annotation.Nonnull;
import java.util.Map;
import java.util.Properties;
@@ -11,20 +11,20 @@
public class HudsonJenkinsBuildServerData extends BuildServerDataProvider {
- HudsonJenkinsBuildServerData(@NotNull LoggerBridge log, @NotNull Map env) {
+ HudsonJenkinsBuildServerData(@Nonnull LoggerBridge log, @Nonnull Map env) {
super(log, env);
}
/**
* @see JenkinsSetEnvironmentVariables
*/
- public static boolean isActiveServer(@NotNull Map env) {
+ public static boolean isActiveServer(@Nonnull Map env) {
return env.containsKey("JENKINS_URL") || env.containsKey("JENKINS_HOME") ||
env.containsKey("HUDSON_URL") || env.containsKey("HUDSON_HOME");
}
@Override
- void loadBuildNumber(@NotNull Properties properties) {
+ void loadBuildNumber(@Nonnull Properties properties) {
String buildNumber = env.get("BUILD_NUMBER");
put(properties, GitCommitPropertyConstant.BUILD_NUMBER, buildNumber == null ? "" : buildNumber);
diff --git a/src/main/java/pl/project13/maven/git/build/TeamCityBuildServerData.java b/src/main/java/pl/project13/maven/git/build/TeamCityBuildServerData.java
index a358c097..187f7382 100644
--- a/src/main/java/pl/project13/maven/git/build/TeamCityBuildServerData.java
+++ b/src/main/java/pl/project13/maven/git/build/TeamCityBuildServerData.java
@@ -1,9 +1,9 @@
package pl.project13.maven.git.build;
-import org.jetbrains.annotations.NotNull;
import pl.project13.maven.git.GitCommitPropertyConstant;
import pl.project13.maven.git.log.LoggerBridge;
+import javax.annotation.Nonnull;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Map;
@@ -13,7 +13,7 @@ public class TeamCityBuildServerData extends BuildServerDataProvider {
private final Properties teamcitySystemProperties = new Properties();
- TeamCityBuildServerData(@NotNull LoggerBridge log, @NotNull Map env) {
+ TeamCityBuildServerData(@Nonnull LoggerBridge log, @Nonnull Map env) {
super(log, env);
if (isActiveServer(env)) {
//https://confluence.jetbrains.com/display/TCD18/Predefined+Build+Parameters
@@ -28,12 +28,12 @@ public class TeamCityBuildServerData extends BuildServerDataProvider {
/**
* @see TeamCity
*/
- public static boolean isActiveServer(@NotNull Map env) {
+ public static boolean isActiveServer(@Nonnull Map env) {
return env.containsKey("TEAMCITY_VERSION");
}
@Override
- void loadBuildNumber(@NotNull Properties properties) {
+ void loadBuildNumber(@Nonnull Properties properties) {
String buildNumber = env.get("BUILD_NUMBER");
String buildNumberUnique = teamcitySystemProperties.getProperty("teamcity.build.id");
diff --git a/src/main/java/pl/project13/maven/git/build/TravisBuildServerData.java b/src/main/java/pl/project13/maven/git/build/TravisBuildServerData.java
index a36b1f29..f2f9d74e 100644
--- a/src/main/java/pl/project13/maven/git/build/TravisBuildServerData.java
+++ b/src/main/java/pl/project13/maven/git/build/TravisBuildServerData.java
@@ -1,27 +1,27 @@
package pl.project13.maven.git.build;
-import org.jetbrains.annotations.NotNull;
import pl.project13.maven.git.GitCommitPropertyConstant;
import pl.project13.maven.git.log.LoggerBridge;
+import javax.annotation.Nonnull;
import java.util.Map;
import java.util.Properties;
public class TravisBuildServerData extends BuildServerDataProvider {
- TravisBuildServerData(LoggerBridge log, @NotNull Map env) {
+ TravisBuildServerData(LoggerBridge log, @Nonnull Map env) {
super(log, env);
}
/**
* @see Travis
*/
- public static boolean isActiveServer(@NotNull Map env) {
+ public static boolean isActiveServer(@Nonnull Map env) {
return env.containsKey("TRAVIS");
}
@Override
- void loadBuildNumber(@NotNull Properties properties) {
+ void loadBuildNumber(@Nonnull Properties properties) {
String buildNumber = env.get("TRAVIS_BUILD_NUMBER");
String uniqueBuildNumber = env.get("TRAVIS_BUILD_ID");
diff --git a/src/main/java/pl/project13/maven/git/build/UnknownBuildServerData.java b/src/main/java/pl/project13/maven/git/build/UnknownBuildServerData.java
index ec8da4ac..2523a0d7 100644
--- a/src/main/java/pl/project13/maven/git/build/UnknownBuildServerData.java
+++ b/src/main/java/pl/project13/maven/git/build/UnknownBuildServerData.java
@@ -1,18 +1,18 @@
package pl.project13.maven.git.build;
-import org.jetbrains.annotations.NotNull;
import pl.project13.maven.git.log.LoggerBridge;
+import javax.annotation.Nonnull;
import java.util.Map;
import java.util.Properties;
public class UnknownBuildServerData extends BuildServerDataProvider {
- public UnknownBuildServerData(@NotNull LoggerBridge log, @NotNull Map env) {
+ public UnknownBuildServerData(@Nonnull LoggerBridge log, @Nonnull Map env) {
super(log, env);
}
@Override
- void loadBuildNumber(@NotNull Properties properties) {
+ void loadBuildNumber(@Nonnull Properties properties) {
}
@Override
diff --git a/src/main/java/pl/project13/maven/git/log/MessageFormatter.java b/src/main/java/pl/project13/maven/git/log/MessageFormatter.java
index 2149f38e..4cef47b6 100644
--- a/src/main/java/pl/project13/maven/git/log/MessageFormatter.java
+++ b/src/main/java/pl/project13/maven/git/log/MessageFormatter.java
@@ -138,7 +138,7 @@ public final class MessageFormatter {
* The argument to be substituted in place of the formatting anchor
* @return The formatted message
*/
- public static final FormattingTuple format(String messagePattern, Object arg) {
+ public static FormattingTuple format(String messagePattern, Object arg) {
return arrayFormat(messagePattern, new Object[] { arg });
}
@@ -165,11 +165,11 @@ public static final FormattingTuple format(String messagePattern, Object arg) {
* anchor
* @return The formatted message
*/
- public static final FormattingTuple format(final String messagePattern, Object arg1, Object arg2) {
+ public static FormattingTuple format(final String messagePattern, Object arg1, Object arg2) {
return arrayFormat(messagePattern, new Object[] { arg1, arg2 });
}
- static final Throwable getThrowableCandidate(Object[] argArray) {
+ static Throwable getThrowableCandidate(Object[] argArray) {
if (argArray == null || argArray.length == 0) {
return null;
}
@@ -193,7 +193,7 @@ static final Throwable getThrowableCandidate(Object[] argArray) {
* anchors
* @return The formatted message
*/
- public static final FormattingTuple arrayFormat(final String messagePattern, final Object[] argArray) {
+ public static FormattingTuple arrayFormat(final String messagePattern, final Object[] argArray) {
Throwable throwableCandidate = getThrowableCandidate(argArray);
@@ -236,13 +236,13 @@ public static final FormattingTuple arrayFormat(final String messagePattern, fin
// itself escaped: "abc x:\\{}"
// we have to consume one backward slash
sbuf.append(messagePattern, i, j - 1);
- deeplyAppendParameter(sbuf, argArray[L], new HashMap