2525import java .io .InputStreamReader ;
2626import java .io .OutputStreamWriter ;
2727import java .io .Writer ;
28- import java .net .InetAddress ;
29- import java .net .UnknownHostException ;
3028import java .nio .charset .Charset ;
3129import java .nio .charset .StandardCharsets ;
3230import java .text .SimpleDateFormat ;
33- import java .util .Date ;
3431import java .util .HashMap ;
3532import java .util .List ;
3633import java .util .Map ;
3734import java .util .Properties ;
38- import java .util .TimeZone ;
3935import java .util .regex .Pattern ;
4036
4137import org .apache .maven .execution .MavenSession ;
5551import com .google .common .io .Files ;
5652import java .io .OutputStream ;
5753
54+ import pl .project13 .maven .git .build .BuildServerDataProvider ;
5855import pl .project13 .maven .git .log .LoggerBridge ;
5956import pl .project13 .maven .git .log .MavenLoggerBridge ;
6057import pl .project13 .maven .git .util .PropertyManager ;
@@ -308,12 +305,12 @@ public class GitCommitIdMojo extends AbstractMojo {
308305 /**
309306 * Allow to tell the plugin what commit should be used as reference to generate the properties from.
310307 * By default this property is simply set to <p>HEAD</p> which should reference to the latest commit in your repository.
311- *
308+ *
312309 * In general this property can be set to something generic like <p>HEAD^1</p> or point to a branch or tag-name.
313310 * To support any kind or use-case this configuration can also be set to an entire commit-hash or it's abbreviated version.
314- *
311+ *
315312 * A use-case for this feature can be found in https://github.com/ktoso/maven-git-commit-id-plugin/issues/338.
316- *
313+ *
317314 * Please note that for security purposes not all references might be allowed as configuration.
318315 * If you have a specific use-case that is currently not white listed feel free to file an issue.
319316 * @since 2.2.4
@@ -406,8 +403,7 @@ public void execute() throws MojoExecutionException {
406403 prefixDot = trimmedPrefix .equals ("" ) ? "" : trimmedPrefix + "." ;
407404
408405 loadGitData (properties );
409- loadBuildVersionAndTimeData (properties );
410- loadBuildHostData (properties );
406+ loadBuildData (properties );
411407 loadShortDescribe (properties );
412408 propertiesReplacer .performReplacement (properties , replacementProperties );
413409 propertiesFilterer .filter (properties , includeOnlyProperties , this .prefixDot );
@@ -430,6 +426,17 @@ public void execute() throws MojoExecutionException {
430426 }
431427 }
432428
429+ private void loadBuildData (Properties properties ) {
430+ BuildServerDataProvider buildServerDataProvider = BuildServerDataProvider .getBuildServerProvider (System .getenv (),log );
431+ buildServerDataProvider
432+ .setDateFormat (dateFormat )
433+ .setDateFormatTimeZone (dateFormatTimeZone )
434+ .setProject (project )
435+ .setPrefixDot (prefixDot );
436+
437+ buildServerDataProvider .loadBuildData (properties );
438+ }
439+
433440 private void publishPropertiesInto (MavenProject target ) {
434441 target .getProperties ().putAll (properties );
435442 }
@@ -476,26 +483,6 @@ private void logProperties() {
476483 }
477484 }
478485
479- void loadBuildVersionAndTimeData (@ NotNull Properties properties ) {
480- Date buildDate = new Date ();
481- SimpleDateFormat smf = new SimpleDateFormat (dateFormat );
482- if (dateFormatTimeZone != null ) {
483- smf .setTimeZone (TimeZone .getTimeZone (dateFormatTimeZone ));
484- }
485- put (properties , GitCommitPropertyConstant .BUILD_TIME , smf .format (buildDate ));
486- put (properties , GitCommitPropertyConstant .BUILD_VERSION , project .getVersion ());
487- }
488-
489- void loadBuildHostData (@ NotNull Properties properties ) {
490- String buildHost = null ;
491- try {
492- buildHost = InetAddress .getLocalHost ().getHostName ();
493- } catch (UnknownHostException e ) {
494- log .info ("Unable to get build host, skipping property {}. Error message: {}" , GitCommitPropertyConstant .BUILD_HOST , e .getMessage ());
495- }
496- put (properties , GitCommitPropertyConstant .BUILD_HOST , buildHost );
497- }
498-
499486 void loadShortDescribe (@ NotNull Properties properties ) {
500487 //removes git hash part from describe
501488 String commitDescribe = properties .getProperty (prefixDot + GitCommitPropertyConstant .COMMIT_DESCRIBE );
0 commit comments