Skip to content

Commit

Permalink
Add checkstyle and formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
carlphilipp committed Apr 24, 2020
1 parent 0053498 commit d6f17ad
Show file tree
Hide file tree
Showing 22 changed files with 1,222 additions and 827 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Carl-Philipp Harmant
Copyright (c) 2020 Slalom LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
21 changes: 21 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@ import org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
import org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED
import org.gradle.api.tasks.testing.logging.TestLogEvent.PASSED
import org.gradle.api.tasks.testing.logging.TestLogEvent.SKIPPED
import java.util.Calendar.YEAR

buildscript {
repositories {
mavenCentral()
}
}

repositories {
mavenCentral()
}

plugins {
`maven-publish`
checkstyle
id("com.github.sherter.google-java-format") version "0.8"
id("com.dorongold.task-tree") version "1.5"
}

subprojects {
Expand All @@ -19,6 +27,7 @@ subprojects {

apply(plugin = "java-library")
apply(plugin = "maven-publish")
apply(plugin = "com.github.sherter.google-java-format")
apply(plugin = "checkstyle")

repositories {
Expand Down Expand Up @@ -67,6 +76,11 @@ subprojects {
}
}

// TODO: make that typed if possible
tasks.named("checkstyleMain") {
dependsOn("googleJavaFormat")
}

tasks.withType<JavaCompile> {
sourceCompatibility = Version.java
targetCompatibility = Version.java
Expand All @@ -80,4 +94,11 @@ subprojects {
exceptionFormat = FULL
}
}
}

checkstyle {
version = 8.29
isIgnoreFailures = false
maxErrors = 0
maxWarnings = 0
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
/**
* MIT License
*
* <p>Copyright (c) 2020 Slalom LLC
*
* <p>Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* <p>The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.slalom.logging.compliance.common;

public interface MaskService {
String maskMessage(String message);
}
String maskMessage(String message);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
/**
* MIT License
*
* <p>Copyright (c) 2020 Slalom LLC
*
* <p>Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* <p>The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.slalom.logging.compliance.common;

import org.slf4j.Marker;
import org.slf4j.MarkerFactory;

public class MaskType {
public static String JSON_MARKER_NAME = "JSON-COMPLIANCE";
public static String LOMBOK_MARKER_NAME = "LOMBOK-COMPLIANCE";
public static Marker JSON = MarkerFactory.getMarker(JSON_MARKER_NAME);
public static Marker LOMBOK = MarkerFactory.getMarker(LOMBOK_MARKER_NAME);
public static String JSON_MARKER_NAME = "JSON-COMPLIANCE";
public static String LOMBOK_MARKER_NAME = "LOMBOK-COMPLIANCE";
public static Marker JSON = MarkerFactory.getMarker(JSON_MARKER_NAME);
public static Marker LOMBOK = MarkerFactory.getMarker(LOMBOK_MARKER_NAME);
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,52 @@
/**
* MIT License
*
* <p>Copyright (c) 2020 Slalom LLC
*
* <p>Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* <p>The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.slalom.logging.compliance.common.impl;

import com.slalom.logging.compliance.common.MaskService;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

abstract class AbstractService implements MaskService {

protected static final String DEFAULT_MASK = "***********";
protected static final String DEFAULT_MASK = "***********";

protected final String fieldRegex;
protected final String fieldRegex;

protected AbstractService(final List<String> fields) {
fieldRegex = String.join("|", fields);
}
protected AbstractService(final List<String> fields) {
fieldRegex = String.join("|", fields);
}

protected String maskMessage(final String message, final Pattern pattern, final String replacementRegex) {
try {
final StringBuffer buffer = new StringBuffer();
final Matcher matcher = pattern.matcher(message);
while (matcher.find()) {
matcher.appendReplacement(buffer, replacementRegex);
}
matcher.appendTail(buffer);
return buffer.toString();
} catch (Exception e) {
return message;
}
protected String maskMessage(
final String message, final Pattern pattern, final String replacementRegex) {
try {
final StringBuffer buffer = new StringBuffer();
final Matcher matcher = pattern.matcher(message);
while (matcher.find()) {
matcher.appendReplacement(buffer, replacementRegex);
}
matcher.appendTail(buffer);
return buffer.toString();
} catch (Exception e) {
return message;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@
/**
* MIT License
*
* <p>Copyright (c) 2020 Slalom LLC
*
* <p>Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* <p>The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.slalom.logging.compliance.common.impl;

import java.util.List;
import java.util.regex.Pattern;

public class JsonMaskService extends AbstractService {

private static final String JSON_REPLACEMENT_REGEX = "\"$1\":$2\"" + DEFAULT_MASK + "\"";
private static final String JSON_PATTERN = "\"(%s)\":([ ]*)\"([^\"]+)\"";
private static final String JSON_REPLACEMENT_REGEX = "\"$1\":$2\"" + DEFAULT_MASK + "\"";
private static final String JSON_PATTERN = "\"(%s)\":([ ]*)\"([^\"]+)\"";

private final Pattern pattern;
private final Pattern pattern;

public JsonMaskService(final List<String> fields) {
super(fields);
this.pattern = Pattern.compile(String.format(JSON_PATTERN, fieldRegex));
}
public JsonMaskService(final List<String> fields) {
super(fields);
this.pattern = Pattern.compile(String.format(JSON_PATTERN, fieldRegex));
}

@Override
public String maskMessage(String message) {
return maskMessage(message, pattern, JSON_REPLACEMENT_REGEX);
}
@Override
public String maskMessage(String message) {
return maskMessage(message, pattern, JSON_REPLACEMENT_REGEX);
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@
/**
* MIT License
*
* <p>Copyright (c) 2020 Slalom LLC
*
* <p>Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* <p>The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.slalom.logging.compliance.common.impl;

import java.util.List;
import java.util.regex.Pattern;

public class LombokMaskService extends AbstractService {

private static final String LOMBOK_REPLACEMENT_REGEX = "$1=" + DEFAULT_MASK + "$3";
private static final String LOMBOK_PATTERN = "(%s)=([^\"]+?(, |\\)))";
private static final String LOMBOK_REPLACEMENT_REGEX = "$1=" + DEFAULT_MASK + "$3";
private static final String LOMBOK_PATTERN = "(%s)=([^\"]+?(, |\\)))";

private final Pattern pattern;
private final Pattern pattern;

public LombokMaskService(List<String> fields) {
super(fields);
this.pattern = Pattern.compile(String.format(LOMBOK_PATTERN, fieldRegex));
}
public LombokMaskService(List<String> fields) {
super(fields);
this.pattern = Pattern.compile(String.format(LOMBOK_PATTERN, fieldRegex));
}

@Override
public String maskMessage(String message) {
return maskMessage(message, pattern, LOMBOK_REPLACEMENT_REGEX);
}
}
@Override
public String maskMessage(String message) {
return maskMessage(message, pattern, LOMBOK_REPLACEMENT_REGEX);
}
}
Loading

0 comments on commit d6f17ad

Please sign in to comment.