-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathStickyAPI.java
More file actions
125 lines (108 loc) · 3.4 KB
/
StickyAPI.java
File metadata and controls
125 lines (108 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* 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 lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;
import java.io.InputStream;
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;
/**
* <h1>StickyAPI</h1> Utility methods, classes and potentially
* code-dupe-annihilating code for DDD plugins.
*
* @author DumbDogDiner (dumbdogdiner.com)
*/
public class StickyAPI {
private StickyAPI() {
}
@Getter
public static Logger logger = Logger.getLogger("StickyAPI");
@Getter
@Setter
private static @NotNull ExecutorService pool = Executors.newCachedThreadPool();
/**
* Provides a wrapper for {@link java.lang.Class#getResourceAsStream(String)} (String)}
* @param resourceName The resource to get
* @return an {@link InputStream} to that resource
*/
public static InputStream getResourceAsStream(@NotNull String resourceName){
return StickyAPI.class.getResourceAsStream(resourceName);
}
// Build Info Start
/**
* Get the current version of API.
*
* @since TBA
* @return {@link String} version
*/
@SuppressWarnings("JavaDoc")
@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
*/
@SuppressWarnings("JavaDoc")
@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
*/
@SuppressWarnings("JavaDoc")
@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 {
return formatter.parse(timestamp);
} 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
*/
@SuppressWarnings("ConstantConditions")
public static Boolean getIsDirty() {
return Boolean.parseBoolean(isDirty);
}
}