Skip to content

Commit be80679

Browse files
committed
initial commit
1 parent a35132c commit be80679

21 files changed

+610
-1
lines changed

.github/dependabot.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "maven" # See documentation for possible values
9+
directory: "/" # Location of package manifests
10+
schedule:
11+
interval: "daily"

.github/workflows/maven.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
3+
4+
name: Java CI with Maven
5+
6+
on: [ push, pull_request ]
7+
8+
jobs:
9+
build:
10+
name: Build for JDK ${{ matrix.java }}
11+
if: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.full_name != 'zrdj/java-properties' }}
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
java: [ 11, 17, 21 ]
16+
steps:
17+
- uses: actions/checkout@v2
18+
- uses: actions/cache@v1
19+
with:
20+
path: ~/.m2/repository
21+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
22+
restore-keys: |
23+
${{ runner.os }}-maven-
24+
- name: Set up JDK ${{ matrix.java }}
25+
uses: actions/setup-java@v2
26+
with:
27+
java-version: ${{ matrix.java }}
28+
distribution: 'temurin'
29+
cache: maven
30+
- name: Build with Maven
31+
run: mvn -B -U compile test --file pom.xml
32+
env:
33+
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}

.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
!**/src/main/**/target/
4+
!**/src/test/**/target/
5+
6+
### IntelliJ IDEA ###
7+
.idea/**
8+
*.iws
9+
*.iml
10+
*.ipr
11+
12+
### Eclipse ###
13+
.apt_generated
14+
.classpath
15+
.factorypath
16+
.project
17+
.settings
18+
.springBeans
19+
.sts4-cache
20+
21+
### NetBeans ###
22+
/nbproject/private/
23+
/nbbuild/
24+
/dist/
25+
/nbdist/
26+
/.nb-gradle/
27+
build/
28+
!**/src/main/**/build/
29+
!**/src/test/**/build/
30+
31+
### VS Code ###
32+
.vscode/
33+
34+
### Mac OS ###
35+
.DS_Store

README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,30 @@
1+
[![License](https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000)]()
2+
[![](https://jitpack.io/v/ZrdJ/javachord.svg)](https://jitpack.io/#ZrdJ/java-properties)
3+
![GitHub Workflow Status (branch)](https://github.com/zrdj/java-properties/actions/workflows/maven.yml/badge.svg)
4+
15
# java-properties
2-
Configuration properties for the JVM
6+
7+
## Maven
8+
9+
Add the Jitpack repository to your build file
10+
11+
```xml
12+
13+
<repositories>
14+
<repository>
15+
<id>jitpack.io</id>
16+
<url>https://jitpack.io</url>
17+
</repository>
18+
</repositories>
19+
```
20+
21+
Release artifact
22+
23+
```xml
24+
25+
<dependency>
26+
<groupId>com.github.zrdj</groupId>
27+
<artifactId>java-properties</artifactId>
28+
<version>0.1.0</version>
29+
</dependency>
30+
```

pom.xml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="http://maven.apache.org/POM/4.0.0"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.github.zrdj</groupId>
8+
<artifactId>java-properties</artifactId>
9+
<version>0.1.0</version>
10+
11+
<properties>
12+
<maven.compiler.source>11</maven.compiler.source>
13+
<maven.compiler.target>11</maven.compiler.target>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
<slf4j.version>1.7.36</slf4j.version>
16+
</properties>
17+
18+
<build>
19+
<plugins>
20+
<plugin>
21+
<groupId>org.apache.maven.plugins</groupId>
22+
<artifactId>maven-compiler-plugin</artifactId>
23+
<version>3.12.1</version>
24+
<configuration>
25+
<source>${maven.compiler.source}</source>
26+
<target>${maven.compiler.target}</target>
27+
</configuration>
28+
</plugin>
29+
<!-- Sources -->
30+
<plugin>
31+
<groupId>org.apache.maven.plugins</groupId>
32+
<artifactId>maven-source-plugin</artifactId>
33+
<version>3.3.0</version>
34+
<executions>
35+
<execution>
36+
<id>attach-sources</id>
37+
<goals>
38+
<goal>jar-no-fork</goal>
39+
</goals>
40+
</execution>
41+
</executions>
42+
</plugin>
43+
44+
<!-- Javadoc -->
45+
<plugin>
46+
<groupId>org.apache.maven.plugins</groupId>
47+
<artifactId>maven-javadoc-plugin</artifactId>
48+
<version>3.6.3</version>
49+
<executions>
50+
<execution>
51+
<id>attach-javadocs</id>
52+
<goals>
53+
<goal>jar</goal>
54+
</goals>
55+
</execution>
56+
</executions>
57+
</plugin>
58+
59+
</plugins>
60+
</build>
61+
62+
<dependencies>
63+
<dependency>
64+
<groupId>org.slf4j</groupId>
65+
<artifactId>slf4j-api</artifactId>
66+
<version>${slf4j.version}</version>
67+
</dependency>
68+
69+
</dependencies>
70+
71+
72+
</project>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.github.zrdj.java.properties;
2+
3+
4+
import com.github.zrdj.java.properties.error.MissingApplicationPropertyException;
5+
6+
public interface ApplicationProperty {
7+
8+
final class Immutable implements ApplicationProperty {
9+
10+
private final String _key;
11+
12+
public Immutable(final String key) {
13+
_key = key;
14+
}
15+
16+
@Override
17+
public String key() {
18+
return _key;
19+
}
20+
}
21+
22+
default MissingApplicationPropertyException exception() {
23+
return new MissingApplicationPropertyException(this);
24+
}
25+
26+
String key();
27+
28+
default boolean isSecret() {
29+
return false;
30+
}
31+
32+
default ApplicationPropertyValue value(String value) {
33+
return isSecret() ? new ApplicationPropertyValue.ImmutableSecured(value) : new ApplicationPropertyValue.Immutable(value);
34+
}
35+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.github.zrdj.java.properties;
2+
3+
import java.util.Optional;
4+
import java.util.function.Function;
5+
6+
7+
public interface ApplicationPropertyStore {
8+
9+
default ApplicationPropertyStore decorate(final Function<ApplicationPropertyStore, ApplicationPropertyStore> factory) {
10+
return factory.apply(this);
11+
}
12+
13+
Optional<ApplicationPropertyValue> get(final ApplicationProperty property);
14+
15+
default ApplicationPropertyStore or(final ApplicationPropertyStore other) {
16+
return name -> this.get(name).or(() -> other.get(name));
17+
}
18+
19+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.github.zrdj.java.properties;
2+
3+
import java.math.BigDecimal;
4+
import java.util.Optional;
5+
import java.util.function.Supplier;
6+
7+
8+
public interface ApplicationPropertyValue {
9+
10+
final class Immutable implements ApplicationPropertyValue {
11+
12+
private final String _value;
13+
14+
public Immutable(final String value) {
15+
_value = value;
16+
}
17+
18+
@Override
19+
public String asString() {
20+
return _value;
21+
}
22+
}
23+
24+
final class ImmutableSecured implements ApplicationPropertyValue {
25+
26+
private final String _value;
27+
28+
public ImmutableSecured(final String value) {
29+
_value = value;
30+
}
31+
32+
@Override
33+
public String asStringProtected() {
34+
final int oneThird = (int) (_value.length() * (20.0f / 100.0f));
35+
return _value.substring(0, oneThird) + "*******";
36+
}
37+
38+
@Override
39+
public String asString() {
40+
return _value;
41+
}
42+
}
43+
44+
default Optional<BigDecimal> asBigDecimal() {
45+
return emptyWhenFailing(() -> Optional.of(new BigDecimal(asString())));
46+
}
47+
48+
default Optional<Double> asDouble() {
49+
return emptyWhenFailing(() -> Optional.of(Double.parseDouble(asString())));
50+
}
51+
52+
default Optional<Integer> asInteger() {
53+
return emptyWhenFailing(() -> Optional.of(Integer.parseInt(asString())));
54+
}
55+
56+
default Optional<Long> asLong() {
57+
return emptyWhenFailing(() -> Optional.of(Long.parseLong(asString())));
58+
}
59+
60+
String asString();
61+
62+
default String asStringProtected() {
63+
return asString();
64+
}
65+
66+
private <T> Optional<T> emptyWhenFailing(Supplier<Optional<T>> runnable) {
67+
try {
68+
return runnable.get();
69+
} catch (Exception e) {
70+
return Optional.empty();
71+
}
72+
}
73+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.github.zrdj.java.properties.error;
2+
3+
4+
import com.github.zrdj.java.properties.ApplicationProperty;
5+
6+
public class MissingApplicationPropertyException extends RuntimeException {
7+
8+
private static final long serialVersionUID = -3092078564412729408L;
9+
10+
public MissingApplicationPropertyException(final ApplicationProperty property) {
11+
super("Missing application property " + property.key() + ". Did you forget to define it?");
12+
}
13+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.github.zrdj.java.properties.naming;
2+
3+
4+
import com.github.zrdj.java.properties.ApplicationProperty;
5+
6+
public class ChangeDashToDotProperty extends ChangeDelimiterProperty {
7+
8+
public ChangeDashToDotProperty(final ApplicationProperty property) {
9+
super(property, "-", "\\.");
10+
}
11+
}

0 commit comments

Comments
 (0)