Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
container:
image: jcxldn/openjdk-alpine:${{matrix.version}}-jdk
steps:
- name: Install git
run: apk add --no-cache git
- uses: actions/checkout@v2
- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand All @@ -32,6 +34,8 @@ jobs:
container:
image: jcxldn/openjdk-alpine:11-jdk
steps:
- name: Install git
run: apk add --no-cache git
- uses: actions/checkout@v2
- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand All @@ -42,8 +46,27 @@ jobs:
container:
image: jcxldn/openjdk-alpine:11-jdk
steps:
- name: Install git
run: apk add --no-cache git
- uses: actions/checkout@v2
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build javadocs
run: ./gradlew javadoc
- name: Save javadocs
uses: actions/upload-artifact@v2
with:
name: javadocs
path: build/docs/ # upload entire directory
- name: Save failed javadocs build output
if: ${{ failure() }}
uses: actions/upload-artifact@v2
with:
name: failed-javadocs-build-output
path: build/ # upload entire directory
- name: Save failed javadocs build options
if: ${{ failure() }}
uses: actions/upload-artifact@v2
with:
name: failed-javadocs-options-file
path: build/tmp/javadoc/javadoc.options
2 changes: 2 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
container:
image: jcxldn/openjdk-alpine:11-jdk
steps:
- name: Install git
run: apk add --no-cache git
- uses: actions/checkout@v2
- name: Echo branch name
run: echo ${GITHUB_REF##*/}
Expand Down
34 changes: 34 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ plugins {
id 'jacoco'
id "io.freefair.lombok" version "5.3.0"
id "com.github.hierynomus.license" version "0.15.0"
// Nemerosa Versioning Plugin for the build info
id "net.nemerosa.versioning" version "2.8.2"
}

jacoco {
Expand Down Expand Up @@ -95,6 +97,38 @@ compileTestJava.options.encoding = "UTF-8"
javadoc.options.encoding = "UTF-8"


// Build Info
// Set the timestamp format
def dataBuildTimestamp = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"

// Import the filter
import org.apache.tools.ant.filters.ReplaceTokens

// Define the map containing the tokens we want to replace
def tokensMap = [
BUILDINFO_VERSION: project.version,
BUILDINFO_DATEFORMAT: dataBuildTimestamp,
BUILDINFO_TIMESTAMP: new java.text.SimpleDateFormat(dataBuildTimestamp).format(new Date()),
BUILDINFO_COMMIT: versioning.info.commit,
BUILDINFO_BRANCH: versioning.info.branch,
BUILDINFO_ISDIRTY: versioning.info.dirty.toString()
]

// Create task to replace the tokens with their actual values
// NOTE: At the moment this replaces tokens *globally* (format eg. @BUILDINFO_COMMIT@ in source code)
task processSourceTokens(type: Sync) {
from sourceSets.main.java
into 'build/processed/src/main/java'
filter(ReplaceTokens, tokens: tokensMap)

// Pretty print the build info
println("\n----- StickyAPI Build Info -----\n")
tokensMap.each { println "${String.format("%1\$-" + 10 + "s", it.key.replace("BUILDINFO_", "").toLowerCase())}\t${it.value}" }
}
// Use the filter task as the input for compileJava
compileJava.source = processSourceTokens.outputs


tasks.publish.dependsOn build, sources


Expand Down
83 changes: 82 additions & 1 deletion src/main/java/com/dumbdogdiner/stickyapi/StickyAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
*/
package com.dumbdogdiner.stickyapi;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.logging.Logger;
Expand All @@ -16,7 +19,6 @@
* code-dupe-annihilating code for DDD plugins.
*
* @author DumbDogDiner (dumbdogdiner.com)
* @version 2.0.0
*/
public class StickyAPI {
@Getter
Expand All @@ -25,4 +27,83 @@ public class StickyAPI {
@Getter
@Setter
private static ExecutorService pool = Executors.newCachedThreadPool();

// Build Info Start

/**
* Get the current version of API.
*
* @since TBA
* @return {@link String} version
*
*/
@Getter
private static final String version = "@BUILDINFO_VERSION";

// Getter not required
private static final String dateFormat = "@BUILDINFO_DATEFORMAT@";

// Custom Getter (see below)
private static final String timestamp = "@BUILDINFO_TIMESTAMP@";

/**
* Get a string with the latest commit (id) at API's build-time.
*
* @since TBA
* @return {@link String} commit id
*/
@Getter
private static final String commit = "@BUILDINFO_COMMIT@";

/**
* Get a string with the current branch at API's build-time.
*
* @since TBA
* @return {@link String} branch name
*/
@Getter
private static final String branch = "@BUILDINFO_BRANCH@";

// Custom Getter (see below)
private static final String isDirty = "@BUILDINFO_ISDIRTY@";


/**
* Get a Date object showing the current time at API's build-time.
*
* @since TBA
* @return {@link Date} date
*/
public static Date getTimestamp() {
SimpleDateFormat formatter = new SimpleDateFormat(dateFormat);
try {
Date date = formatter.parse(timestamp);
return date;
} catch (ParseException e) {
e.printStackTrace();
return null;
}
}

/**
* Get a string with the latest commit sha at API's build-time.
*
* @since TBA
* @return {@link String} sha
*/
public static String getSha() {
return commit.substring(0, 7);
}

/**
* Get a boolean showing if the working tree was dirty at API's build-time.
* <p>
* If the working directory was dirty, this will return true, meaning there were modified tracked files and staged changes at build-time.
*
* @since TBA
* @return {@link Boolean} isDirty
*/
public static Boolean getIsDirty() {
return Boolean.parseBoolean(isDirty);
}
}
55 changes: 55 additions & 0 deletions src/test/java/com/dumbdogdiner/stickyapi/StickyAPITest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2020-2021 DumbDogDiner <dumbdogdiner.com>. All rights reserved.
* Licensed under the MIT license, see LICENSE for more information...
*/
package com.dumbdogdiner.stickyapi;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.junit.jupiter.api.Test;

public class StickyAPITest {

@Test
public void testGetVersion() {
String version = StickyAPI.getVersion();

assertNotNull(version);
assertFalse(version.length() == 0);
}

@Test
public void testGetTimestamp() {
assertNotNull(StickyAPI.getTimestamp());
}

@Test
public void testGetCommit() {
assertEquals(40, StickyAPI.getCommit().length());
}

@Test
public void testGetSha() {
String sha = StickyAPI.getSha();

assertEquals(7, sha.length());
assertEquals(StickyAPI.getCommit().substring(0, 7), sha);
}

@Test
public void testGetBranch() {
String branch = StickyAPI.getBranch();

assertNotNull(branch);
assertTrue(branch.length() != 0);
}

@Test
// This test is kinda useless?
public void testGetIsDirty() {
assertTrue(StickyAPI.getIsDirty() instanceof Boolean);
}
}