|
|
@ -16,6 +16,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.gradle.tasks.buildinfo;
|
|
|
|
package org.springframework.boot.gradle.tasks.buildinfo;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import java.io.ObjectInputStream;
|
|
|
|
import java.io.Serializable;
|
|
|
|
import java.io.Serializable;
|
|
|
|
import java.time.Instant;
|
|
|
|
import java.time.Instant;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashMap;
|
|
|
@ -23,6 +25,7 @@ import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
import org.gradle.api.Project;
|
|
|
|
import org.gradle.api.Project;
|
|
|
|
import org.gradle.api.provider.Property;
|
|
|
|
import org.gradle.api.provider.Property;
|
|
|
|
|
|
|
|
import org.gradle.api.provider.Provider;
|
|
|
|
import org.gradle.api.tasks.Input;
|
|
|
|
import org.gradle.api.tasks.Input;
|
|
|
|
import org.gradle.api.tasks.Optional;
|
|
|
|
import org.gradle.api.tasks.Optional;
|
|
|
|
|
|
|
|
|
|
|
@ -35,6 +38,8 @@ import org.gradle.api.tasks.Optional;
|
|
|
|
@SuppressWarnings("serial")
|
|
|
|
@SuppressWarnings("serial")
|
|
|
|
public class BuildInfoProperties implements Serializable {
|
|
|
|
public class BuildInfoProperties implements Serializable {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private transient Instant creationTime = Instant.now();
|
|
|
|
|
|
|
|
|
|
|
|
private final Property<String> group;
|
|
|
|
private final Property<String> group;
|
|
|
|
|
|
|
|
|
|
|
|
private final Property<String> artifact;
|
|
|
|
private final Property<String> artifact;
|
|
|
@ -43,22 +48,35 @@ public class BuildInfoProperties implements Serializable {
|
|
|
|
|
|
|
|
|
|
|
|
private final Property<String> name;
|
|
|
|
private final Property<String> name;
|
|
|
|
|
|
|
|
|
|
|
|
private final Property<Instant> time;
|
|
|
|
private final Property<Long> time;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean timeConfigured = false;
|
|
|
|
|
|
|
|
|
|
|
|
private Map<String, Object> additionalProperties = new HashMap<>();
|
|
|
|
private Map<String, Object> additionalProperties = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
BuildInfoProperties(Project project) {
|
|
|
|
BuildInfoProperties(Project project) {
|
|
|
|
this.time = project.getObjects().property(Instant.class);
|
|
|
|
this.time = project.getObjects().property(Long.class);
|
|
|
|
this.time.set(Instant.now());
|
|
|
|
|
|
|
|
this.group = project.getObjects().property(String.class);
|
|
|
|
this.group = project.getObjects().property(String.class);
|
|
|
|
this.group.set(project.provider(() -> project.getGroup().toString()));
|
|
|
|
this.group.set(project.provider(() -> project.getGroup().toString()));
|
|
|
|
this.artifact = project.getObjects().property(String.class);
|
|
|
|
this.artifact = project.getObjects().property(String.class);
|
|
|
|
this.version = project.getObjects().property(String.class);
|
|
|
|
this.version = project.getObjects().property(String.class);
|
|
|
|
this.version.set(project.provider(() -> project.getVersion().toString()));
|
|
|
|
this.version.set(projectVersion(project));
|
|
|
|
this.name = project.getObjects().property(String.class);
|
|
|
|
this.name = project.getObjects().property(String.class);
|
|
|
|
this.name.set(project.provider(project::getName));
|
|
|
|
this.name.set(project.provider(project::getName));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Provider<String> projectVersion(Project project) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Provider<String> externalVersionProperty = project.getProviders().gradleProperty("version")
|
|
|
|
|
|
|
|
.forUseAtConfigurationTime();
|
|
|
|
|
|
|
|
externalVersionProperty.getOrNull();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (NoSuchMethodError ex) {
|
|
|
|
|
|
|
|
// Gradle < 6.5
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return project.provider(() -> project.getVersion().toString());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Returns the value used for the {@code build.group} property. Defaults to the
|
|
|
|
* Returns the value used for the {@code build.group} property. Defaults to the
|
|
|
|
* {@link Project#getGroup() Project's group}.
|
|
|
|
* {@link Project#getGroup() Project's group}.
|
|
|
@ -142,7 +160,14 @@ public class BuildInfoProperties implements Serializable {
|
|
|
|
@Input
|
|
|
|
@Input
|
|
|
|
@Optional
|
|
|
|
@Optional
|
|
|
|
public Instant getTime() {
|
|
|
|
public Instant getTime() {
|
|
|
|
return this.time.getOrNull();
|
|
|
|
Long epochMillis = this.time.getOrNull();
|
|
|
|
|
|
|
|
if (epochMillis != null) {
|
|
|
|
|
|
|
|
return Instant.ofEpochMilli(epochMillis);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.timeConfigured) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.creationTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -150,7 +175,8 @@ public class BuildInfoProperties implements Serializable {
|
|
|
|
* @param time the build time
|
|
|
|
* @param time the build time
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void setTime(Instant time) {
|
|
|
|
public void setTime(Instant time) {
|
|
|
|
this.time.set(time);
|
|
|
|
this.timeConfigured = true;
|
|
|
|
|
|
|
|
this.time.set((time != null) ? time.toEpochMilli() : null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -173,4 +199,9 @@ public class BuildInfoProperties implements Serializable {
|
|
|
|
this.additionalProperties = additionalProperties;
|
|
|
|
this.additionalProperties = additionalProperties;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void readObject(ObjectInputStream input) throws ClassNotFoundException, IOException {
|
|
|
|
|
|
|
|
input.defaultReadObject();
|
|
|
|
|
|
|
|
this.creationTime = Instant.now();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|