-
Notifications
You must be signed in to change notification settings - Fork 92
Static analysis spotbugs #458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: SpotBugs | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- master | ||
paths: | ||
- 'powertools-core/**' | ||
- 'powertools-logging/**' | ||
- 'powertools-sqs/**' | ||
- 'powertools-tracing/**' | ||
- 'powertools-validation/**' | ||
- 'powertools-parameters/**' | ||
- 'powertools-metrics/**' | ||
- 'pom.xml' | ||
- '.github/workflows/**' | ||
jobs: | ||
codecheck: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Setup java JDK 1.8 | ||
uses: actions/setup-java@v2 | ||
with: | ||
distribution: 'zulu' | ||
java-version: 8 | ||
- name: Build with Maven for spotbugs check to gather reports | ||
run: mvn -Pbuild-with-spotbugs -B install --file pom.xml -DskipTests -Dmaven.javadoc.skip=true -Dspotbugs.failOnError=false | ||
- uses: jwgmeligmeyling/spotbugs-github-action@master | ||
with: | ||
path: '**/spotbugsXml.xml' | ||
# Can be simplified post this issue is fixed https://github.com/jwgmeligmeyling/spotbugs-github-action/issues/9 | ||
- name: Build with Maven for spotbugs check to mark build as fail if voilations found | ||
run: mvn -Pbuild-with-spotbugs -B install --file pom.xml -DskipTests -Dmaven.javadoc.skip=true -Dspotbugs.failOnError=true |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,8 +85,13 @@ public SpecVersion.VersionFlag getSchemaVersion() { | |
* @param <T> Must extends {@link BaseFunction} | ||
*/ | ||
public <T extends BaseFunction> void addFunction(T function) { | ||
configuration.functionRegistry().extend(function); | ||
jmesPath = new JacksonRuntime(configuration, getObjectMapper()); | ||
FunctionRegistry functionRegistryWithExtendedFunctions = configuration.functionRegistry().extend(function); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a neat finding and was actually a bug There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
RuntimeConfiguration updatedConfig = new RuntimeConfiguration.Builder() | ||
.withFunctionRegistry(functionRegistryWithExtendedFunctions) | ||
.build(); | ||
|
||
jmesPath = new JacksonRuntime(updatedConfig, getObjectMapper()); | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,13 @@ | |
*/ | ||
package software.amazon.lambda.powertools.validation; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.stream.Collectors; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.node.JsonNodeType; | ||
|
@@ -21,12 +28,6 @@ | |
import io.burt.jmespath.Expression; | ||
import software.amazon.lambda.powertools.validation.internal.ValidationAspect; | ||
|
||
import java.io.InputStream; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Validation utility, used to manually validate Json against Json Schema | ||
*/ | ||
|
@@ -229,31 +230,37 @@ public static JsonSchema getJsonSchema(String schema) { | |
public static JsonSchema getJsonSchema(String schema, boolean validateSchema) { | ||
JsonSchema jsonSchema = schemas.get(schema); | ||
|
||
if (jsonSchema == null) { | ||
if (schema.startsWith(CLASSPATH)) { | ||
String filePath = schema.substring(CLASSPATH.length()); | ||
InputStream schemaStream = ValidationAspect.class.getResourceAsStream(filePath); | ||
if (jsonSchema != null) { | ||
return jsonSchema; | ||
} | ||
|
||
if (schema.startsWith(CLASSPATH)) { | ||
String filePath = schema.substring(CLASSPATH.length()); | ||
try (InputStream schemaStream = ValidationAspect.class.getResourceAsStream(filePath)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
if (schemaStream == null) { | ||
throw new IllegalArgumentException("'" + schema + "' is invalid, verify '" + filePath + "' is in your classpath"); | ||
} | ||
|
||
jsonSchema = ValidationConfig.get().getFactory().getSchema(schemaStream); | ||
} else { | ||
jsonSchema = ValidationConfig.get().getFactory().getSchema(schema); | ||
} catch (IOException e) { | ||
throw new IllegalArgumentException("'" + schema + "' is invalid, verify '" + filePath + "' is in your classpath"); | ||
} | ||
} else { | ||
jsonSchema = ValidationConfig.get().getFactory().getSchema(schema); | ||
} | ||
|
||
if (validateSchema) { | ||
String version = ValidationConfig.get().getSchemaVersion().toString(); | ||
try { | ||
validate(jsonSchema.getSchemaNode(), | ||
getJsonSchema("classpath:/schemas/meta_schema_" + version)); | ||
} catch (ValidationException ve) { | ||
throw new IllegalArgumentException("The schema " + schema + " is not valid, it does not respect the specification " + version, ve); | ||
} | ||
if (validateSchema) { | ||
String version = ValidationConfig.get().getSchemaVersion().toString(); | ||
try { | ||
validate(jsonSchema.getSchemaNode(), | ||
getJsonSchema("classpath:/schemas/meta_schema_" + version)); | ||
} catch (ValidationException ve) { | ||
throw new IllegalArgumentException("The schema " + schema + " is not valid, it does not respect the specification " + version, ve); | ||
} | ||
|
||
schemas.put(schema, jsonSchema); | ||
} | ||
|
||
schemas.put(schema, jsonSchema); | ||
|
||
return jsonSchema; | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.