org.springframework.boot.info.GitProperties Java Examples

The following examples show how to use org.springframework.boot.info.GitProperties. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PrefixedKeyGenerator.java    From jhipster with Apache License 2.0 6 votes vote down vote up
private String generatePrefix(GitProperties gitProperties, BuildProperties buildProperties) {

        String shortCommitId = null;
        if (Objects.nonNull(gitProperties)) {
            shortCommitId = gitProperties.getShortCommitId();
        }

        Instant time = null;
        String version = null;
        if (Objects.nonNull(buildProperties)) {
            time = buildProperties.getTime();
            version = buildProperties.getVersion();
        }
        Object p = ObjectUtils.firstNonNull(shortCommitId, time, version, RandomStringUtils.randomAlphanumeric(12));

        if (p instanceof Instant) {
            return DateTimeFormatter.ISO_INSTANT.format((Instant) p);
        }
        return p.toString();
    }
 
Example #2
Source File: VersionInfo.java    From edison-microservice with Apache License 2.0 6 votes vote down vote up
private VersionInfo(final VersionInfoProperties versionInfoProperties, final GitProperties gitProperties) {
    if (gitProperties != null) {
        this.commitId = gitProperties.getCommitId();
        this.commitIdAbbrev = gitProperties.getShortCommitId();
        this.branch = gitProperties.getBranch();
        this.commitTime = gitProperties.get(COMMIT_TIME);
        this.userName = gitProperties.get(USER_NAME);
        this.userEmail = gitProperties.get(USER_EMAIL);
        this.messageShort = gitProperties.get(MESSAGE_SHORT);
        this.messageFull = gitProperties.get(MESSAGE_FULL);

    } else {
        this.commitId = versionInfoProperties.getCommitId();
        this.commitIdAbbrev= versionInfoProperties.getCommitIdAbbrev();
        this.commitTime = versionInfoProperties.getCommitTime();
        this.userName = versionInfoProperties.getUserName();
        this.userEmail = versionInfoProperties.getUserEmail();
        this.messageShort = versionInfoProperties.getMessageShort();
        this.messageFull = versionInfoProperties.getMessageFull();
        this.branch = versionInfoProperties.getBranch();
    }
    this.version = Objects.toString(versionInfoProperties.getVersion(), this.commitId);
    this.url = versionInfoProperties.getUrlTemplate().replace("{commit}", commitId).replace("{version}", version);
}
 
Example #3
Source File: SystemInfoService.java    From fredbet with Creative Commons Attribution Share Alike 4.0 International 6 votes vote down vote up
private void addStaticProperties() {
    add("Build Time", buildProperties.getTime());
    add("Build Version", buildProperties.getVersion());
    add("Java Version", buildProperties.get("java.source"));

    if (gitProperties.isPresent()) {
        GitProperties gitProps = gitProperties.get();
        add("Commit ID", gitProps.getCommitId());
        add("Branch", gitProps.getBranch());
        add("Commit Message", gitProps.get("commit.message.full"));
        add("Commit Time", gitProps.getCommitTime());
    }

    addSpringProfiles();
    addEnvProperty("JDBC Driver Class","spring.datasource.hikari.driver-class-name");
    addEnvProperty("JDBC-URL","spring.datasource.hikari.jdbc-url");
    addEnvProperty("Image Location","fredbet.image-location");
    addEnvProperty("Image Size","fredbet.image-size");
    addEnvProperty("Thumbnail Size","fredbet.thumbnail-size");
    addEnvProperty("AWS S3 Bucket Name","fredbet.aws-s3bucket-name");
    addEnvProperty("AWS Region","fredbet.aws-region");
}
 
Example #4
Source File: LauncherInfoProperties.java    From spring-cloud-formula with Apache License 2.0 5 votes vote down vote up
public GitProperties getGit() {
    Properties e = entries.entrySet()
            .stream()
            .filter(entry -> entry.toString().startsWith("git"))
            .collect(Collectors.toMap(
                    entry -> entry.getKey().toString().replace("git", ""),
                    Map.Entry::getValue, (v1, v2) -> {
                        throw new RuntimeException();
                    },
                    Properties::new));
    return new GitProperties(e);
}
 
Example #5
Source File: SystemInfoService.java    From fredbet with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
@Autowired
public SystemInfoService(BuildProperties buildProperties, Environment environment, Optional<GitProperties> gitProperties) {
    this.buildProperties = buildProperties;
    this.environment = environment;
    this.gitProperties = gitProperties;
    addStaticProperties();
}
 
Example #6
Source File: VersionInfoTest.java    From edison-microservice with Apache License 2.0 4 votes vote down vote up
private GitProperties gitProperties(final String commitId) {
    return new GitProperties(new Properties() {{
        put("commit.id", commitId);
    }});
}
 
Example #7
Source File: PrefixedKeyGeneratorTest.java    From jhipster with Apache License 2.0 3 votes vote down vote up
@Test
public void generatePrefixFromShortCommitId() {

    Properties gitProperties = new Properties();
    gitProperties.put("commit.id.abbrev", "1234");

    PrefixedKeyGenerator prefixedKeyGenerator = new PrefixedKeyGenerator(new GitProperties(gitProperties), null);

    assertThat(prefixedKeyGenerator.getPrefix()).isEqualTo("1234");
}
 
Example #8
Source File: PrefixedKeyGeneratorTest.java    From jhipster with Apache License 2.0 3 votes vote down vote up
@Test
public void generatePrefixFromCommitId() {

    Properties gitProperties = new Properties();
    gitProperties.put("commit.id", "1234567");

    PrefixedKeyGenerator prefixedKeyGenerator = new PrefixedKeyGenerator(new GitProperties(gitProperties), null);

    assertThat(prefixedKeyGenerator.getPrefix()).isEqualTo("1234567");
}
 
Example #9
Source File: PrefixedKeyGenerator.java    From jhipster with Apache License 2.0 2 votes vote down vote up
public PrefixedKeyGenerator(GitProperties gitProperties, BuildProperties buildProperties) {

        this.prefix = generatePrefix(gitProperties, buildProperties);
    }
 
Example #10
Source File: VersionInfo.java    From edison-microservice with Apache License 2.0 2 votes vote down vote up
/**
 * Creates VersionInfo from Spring Boot {@link GitProperties}. Missing Information ({@link #version} and
 * {@link #url})is filled from VersionInfoProperties.
 *
 * @param versionInfoProperties Edison VersionInfoProperties used for version and url
 * @param gitProperties Spring Boot GitProperties for all the other properties.
 * @return VersionInfo
 */
public static VersionInfo versionInfo(final VersionInfoProperties versionInfoProperties,
                                      final GitProperties gitProperties) {
    return new VersionInfo(versionInfoProperties, gitProperties);
}