-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a35132c
commit be80679
Showing
21 changed files
with
610 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# To get started with Dependabot version updates, you'll need to specify which | ||
# package ecosystems to update and where the package manifests are located. | ||
# Please see the documentation for all configuration options: | ||
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates | ||
|
||
version: 2 | ||
updates: | ||
- package-ecosystem: "maven" # See documentation for possible values | ||
directory: "/" # Location of package manifests | ||
schedule: | ||
interval: "daily" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven | ||
|
||
name: Java CI with Maven | ||
|
||
on: [ push, pull_request ] | ||
|
||
jobs: | ||
build: | ||
name: Build for JDK ${{ matrix.java }} | ||
if: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.full_name != 'zrdj/java-properties' }} | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
java: [ 11, 17, 21 ] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/cache@v1 | ||
with: | ||
path: ~/.m2/repository | ||
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | ||
restore-keys: | | ||
${{ runner.os }}-maven- | ||
- name: Set up JDK ${{ matrix.java }} | ||
uses: actions/setup-java@v2 | ||
with: | ||
java-version: ${{ matrix.java }} | ||
distribution: 'temurin' | ||
cache: maven | ||
- name: Build with Maven | ||
run: mvn -B -U compile test --file pom.xml | ||
env: | ||
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea/** | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### Eclipse ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### Mac OS ### | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,30 @@ | ||
[![License](https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000)]() | ||
[![](https://jitpack.io/v/ZrdJ/javachord.svg)](https://jitpack.io/#ZrdJ/java-properties) | ||
![GitHub Workflow Status (branch)](https://github.com/zrdj/java-properties/actions/workflows/maven.yml/badge.svg) | ||
|
||
# java-properties | ||
Configuration properties for the JVM | ||
|
||
## Maven | ||
|
||
Add the Jitpack repository to your build file | ||
|
||
```xml | ||
|
||
<repositories> | ||
<repository> | ||
<id>jitpack.io</id> | ||
<url>https://jitpack.io</url> | ||
</repository> | ||
</repositories> | ||
``` | ||
|
||
Release artifact | ||
|
||
```xml | ||
|
||
<dependency> | ||
<groupId>com.github.zrdj</groupId> | ||
<artifactId>java-properties</artifactId> | ||
<version>0.1.0</version> | ||
</dependency> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.github.zrdj</groupId> | ||
<artifactId>java-properties</artifactId> | ||
<version>0.1.0</version> | ||
|
||
<properties> | ||
<maven.compiler.source>11</maven.compiler.source> | ||
<maven.compiler.target>11</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<slf4j.version>1.7.36</slf4j.version> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.12.1</version> | ||
<configuration> | ||
<source>${maven.compiler.source}</source> | ||
<target>${maven.compiler.target}</target> | ||
</configuration> | ||
</plugin> | ||
<!-- Sources --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-source-plugin</artifactId> | ||
<version>3.3.0</version> | ||
<executions> | ||
<execution> | ||
<id>attach-sources</id> | ||
<goals> | ||
<goal>jar-no-fork</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<!-- Javadoc --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-javadoc-plugin</artifactId> | ||
<version>3.6.3</version> | ||
<executions> | ||
<execution> | ||
<id>attach-javadocs</id> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>${slf4j.version}</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
|
||
</project> |
35 changes: 35 additions & 0 deletions
35
src/main/java/com/github/zrdj/java/properties/ApplicationProperty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.github.zrdj.java.properties; | ||
|
||
|
||
import com.github.zrdj.java.properties.error.MissingApplicationPropertyException; | ||
|
||
public interface ApplicationProperty { | ||
|
||
final class Immutable implements ApplicationProperty { | ||
|
||
private final String _key; | ||
|
||
public Immutable(final String key) { | ||
_key = key; | ||
} | ||
|
||
@Override | ||
public String key() { | ||
return _key; | ||
} | ||
} | ||
|
||
default MissingApplicationPropertyException exception() { | ||
return new MissingApplicationPropertyException(this); | ||
} | ||
|
||
String key(); | ||
|
||
default boolean isSecret() { | ||
return false; | ||
} | ||
|
||
default ApplicationPropertyValue value(String value) { | ||
return isSecret() ? new ApplicationPropertyValue.ImmutableSecured(value) : new ApplicationPropertyValue.Immutable(value); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/github/zrdj/java/properties/ApplicationPropertyStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.github.zrdj.java.properties; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Function; | ||
|
||
|
||
public interface ApplicationPropertyStore { | ||
|
||
default ApplicationPropertyStore decorate(final Function<ApplicationPropertyStore, ApplicationPropertyStore> factory) { | ||
return factory.apply(this); | ||
} | ||
|
||
Optional<ApplicationPropertyValue> get(final ApplicationProperty property); | ||
|
||
default ApplicationPropertyStore or(final ApplicationPropertyStore other) { | ||
return name -> this.get(name).or(() -> other.get(name)); | ||
} | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
src/main/java/com/github/zrdj/java/properties/ApplicationPropertyValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.github.zrdj.java.properties; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.Optional; | ||
import java.util.function.Supplier; | ||
|
||
|
||
public interface ApplicationPropertyValue { | ||
|
||
final class Immutable implements ApplicationPropertyValue { | ||
|
||
private final String _value; | ||
|
||
public Immutable(final String value) { | ||
_value = value; | ||
} | ||
|
||
@Override | ||
public String asString() { | ||
return _value; | ||
} | ||
} | ||
|
||
final class ImmutableSecured implements ApplicationPropertyValue { | ||
|
||
private final String _value; | ||
|
||
public ImmutableSecured(final String value) { | ||
_value = value; | ||
} | ||
|
||
@Override | ||
public String asStringProtected() { | ||
final int oneThird = (int) (_value.length() * (20.0f / 100.0f)); | ||
return _value.substring(0, oneThird) + "*******"; | ||
} | ||
|
||
@Override | ||
public String asString() { | ||
return _value; | ||
} | ||
} | ||
|
||
default Optional<BigDecimal> asBigDecimal() { | ||
return emptyWhenFailing(() -> Optional.of(new BigDecimal(asString()))); | ||
} | ||
|
||
default Optional<Double> asDouble() { | ||
return emptyWhenFailing(() -> Optional.of(Double.parseDouble(asString()))); | ||
} | ||
|
||
default Optional<Integer> asInteger() { | ||
return emptyWhenFailing(() -> Optional.of(Integer.parseInt(asString()))); | ||
} | ||
|
||
default Optional<Long> asLong() { | ||
return emptyWhenFailing(() -> Optional.of(Long.parseLong(asString()))); | ||
} | ||
|
||
String asString(); | ||
|
||
default String asStringProtected() { | ||
return asString(); | ||
} | ||
|
||
private <T> Optional<T> emptyWhenFailing(Supplier<Optional<T>> runnable) { | ||
try { | ||
return runnable.get(); | ||
} catch (Exception e) { | ||
return Optional.empty(); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/github/zrdj/java/properties/error/MissingApplicationPropertyException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.github.zrdj.java.properties.error; | ||
|
||
|
||
import com.github.zrdj.java.properties.ApplicationProperty; | ||
|
||
public class MissingApplicationPropertyException extends RuntimeException { | ||
|
||
private static final long serialVersionUID = -3092078564412729408L; | ||
|
||
public MissingApplicationPropertyException(final ApplicationProperty property) { | ||
super("Missing application property " + property.key() + ". Did you forget to define it?"); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/github/zrdj/java/properties/naming/ChangeDashToDotProperty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.github.zrdj.java.properties.naming; | ||
|
||
|
||
import com.github.zrdj.java.properties.ApplicationProperty; | ||
|
||
public class ChangeDashToDotProperty extends ChangeDelimiterProperty { | ||
|
||
public ChangeDashToDotProperty(final ApplicationProperty property) { | ||
super(property, "-", "\\."); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/github/zrdj/java/properties/naming/ChangeDashToUnderscoreProperty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.github.zrdj.java.properties.naming; | ||
|
||
|
||
import com.github.zrdj.java.properties.ApplicationProperty; | ||
|
||
public class ChangeDashToUnderscoreProperty extends ChangeDelimiterProperty { | ||
|
||
public ChangeDashToUnderscoreProperty(final ApplicationProperty property) { | ||
super(property, "-", "_"); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/github/zrdj/java/properties/naming/ChangeDelimiterProperty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.github.zrdj.java.properties.naming; | ||
|
||
|
||
import com.github.zrdj.java.properties.ApplicationProperty; | ||
|
||
public class ChangeDelimiterProperty implements ApplicationProperty { | ||
|
||
private final ApplicationProperty _property; | ||
private final String _originalDelimiter; | ||
private final String _newDelimiter; | ||
|
||
public ChangeDelimiterProperty(final ApplicationProperty property, final String originalDelimiter, final String newDelimiter) { | ||
_property = property; | ||
_originalDelimiter = originalDelimiter; | ||
_newDelimiter = newDelimiter; | ||
} | ||
|
||
@Override | ||
public String key() { | ||
return _property.key().replaceAll(_originalDelimiter, _newDelimiter); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/github/zrdj/java/properties/naming/ChangeDotToDashProperty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.github.zrdj.java.properties.naming; | ||
|
||
|
||
import com.github.zrdj.java.properties.ApplicationProperty; | ||
|
||
public class ChangeDotToDashProperty extends ChangeDelimiterProperty { | ||
|
||
public ChangeDotToDashProperty(final ApplicationProperty property) { | ||
super(property, "\\.", "-"); | ||
} | ||
} |
Oops, something went wrong.