-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add codemodder framework and replace 1 codemod #24
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
77dce55
wip but getting there
nahsra 84f32b9
i think all common files are exported to common package and can start…
nahsra cf34774
add semgrep
nahsra af366db
tests pass, now pretty clean interface for repository injections
nahsra 2ebe359
made name better
nahsra 197bd85
made name better
nahsra 1735091
first codemod replaced
nahsra d2d0176
pre pr cleanup
nahsra d5740b3
now rule management is built in
nahsra aed1dbc
run on semgrep container
nahsra 26c4830
without graal
nahsra bbb1edc
try different way of adding semgrep
nahsra 4dc300b
add semgrep to release job
nahsra fb856d5
pr feedback addressed
nahsra 7390cb4
fixed bug
nahsra 51c5fc4
updated future entrypoint to be documented at least
nahsra aa13a24
pr feedback
nahsra ecf7bfa
all feedback addressed
nahsra dddcb2a
did the flatmap thing
nahsra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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,37 @@ | ||
@Suppress("DSL_SCOPE_VIOLATION") // https://github.com/gradle/gradle/issues/22797 | ||
plugins { | ||
id("io.openpixee.codetl.base") | ||
id("io.openpixee.codetl.java-library") | ||
id("io.openpixee.codetl.maven-publish") | ||
alias(libs.plugins.fileversioning) | ||
} | ||
|
||
java { | ||
toolchain { | ||
languageVersion.set(JavaLanguageVersion.of(11)) | ||
} | ||
} | ||
|
||
publishing { | ||
publications { | ||
register<MavenPublication>("maven") { | ||
from(components["java"]) | ||
artifactId = "codemodder-common" | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compileOnly(libs.jetbrains.annotations) | ||
implementation(libs.guice) | ||
implementation(libs.contrast.sarif) | ||
implementation(libs.java.security.toolkit) | ||
implementation(libs.slf4j.api) | ||
|
||
testImplementation(testlibs.bundles.junit.jupiter) | ||
testImplementation(testlibs.bundles.hamcrest) | ||
testImplementation(testlibs.assertj) | ||
testImplementation(testlibs.jgit) | ||
testImplementation(testlibs.mockito) | ||
testRuntimeOnly(testlibs.junit.jupiter.engine) | ||
} |
2 changes: 1 addition & 1 deletion
2
...n/java/io/openpixee/java/ChangedFile.java → .../main/java/io/codemodder/ChangedFile.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package io.openpixee.java; | ||
package io.codemodder; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
2 changes: 1 addition & 1 deletion
2
...io/openpixee/java/DefaultRuleSetting.java → ...ava/io/codemodder/DefaultRuleSetting.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package io.openpixee.java; | ||
package io.codemodder; | ||
|
||
import java.util.Objects; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...java/io/openpixee/java/DependencyGAV.java → ...ain/java/io/codemodder/DependencyGAV.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package io.openpixee.java; | ||
package io.codemodder; | ||
|
||
import java.util.Objects; | ||
|
||
|
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
2 changes: 1 addition & 1 deletion
2
...a/io/openpixee/java/IncludesExcludes.java → .../java/io/codemodder/IncludesExcludes.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
2 changes: 1 addition & 1 deletion
2
.../openpixee/java/LineIncludesExcludes.java → ...a/io/codemodder/LineIncludesExcludes.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package io.openpixee.java; | ||
package io.codemodder; | ||
|
||
import java.util.Collections; | ||
import java.util.Objects; | ||
|
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
2 changes: 1 addition & 1 deletion
2
...n/java/io/openpixee/java/RuleContext.java → .../main/java/io/codemodder/RuleContext.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package io.openpixee.java; | ||
package io.codemodder; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
2 changes: 1 addition & 1 deletion
2
...rc/main/java/io/openpixee/java/Weave.java → ...on/src/main/java/io/codemodder/Weave.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package io.openpixee.java; | ||
package io.codemodder; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
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,34 @@ | ||
@Suppress("DSL_SCOPE_VIOLATION") // https://github.com/gradle/gradle/issues/22797 | ||
plugins { | ||
id("io.openpixee.codetl.base") | ||
id("io.openpixee.codetl.java-library") | ||
nahsra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
id("io.openpixee.codetl.maven-publish") | ||
alias(libs.plugins.fileversioning) | ||
} | ||
|
||
java { | ||
toolchain { | ||
languageVersion.set(JavaLanguageVersion.of(11)) | ||
} | ||
} | ||
|
||
publishing { | ||
publications { | ||
register<MavenPublication>("maven") { | ||
from(components["java"]) | ||
artifactId = "codemodder-default-codemods" | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation(project(":languages:codemodder-framework-java")) | ||
implementation(project(":languages:codemodder-semgrep-provider")) | ||
|
||
testImplementation(testlibs.bundles.junit.jupiter) | ||
testImplementation(testlibs.bundles.hamcrest) | ||
testImplementation(testlibs.assertj) | ||
testImplementation(testlibs.mockito) | ||
|
||
testRuntimeOnly(testlibs.junit.jupiter.engine) | ||
} |
16 changes: 16 additions & 0 deletions
16
...ges/codemodder-default-codemods/src/main/java/io/codemodder/codemods/DefaultCodemods.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,16 @@ | ||
package io.codemodder.codemods; | ||
|
||
import io.codemodder.Changer; | ||
import java.util.List; | ||
|
||
/** | ||
* Give an ability for users to list all the codemods so they don't have to reference them | ||
* individually. | ||
*/ | ||
public final class DefaultCodemods { | ||
|
||
/** Get a list of all the codemods in our default set. */ | ||
public static List<Class<? extends Changer>> asList() { | ||
return List.of(SecureRandomCodemod.class); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
languages/codemodder-default-codemods/src/main/java/io/codemodder/codemods/Runner.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 io.codemodder.codemods; | ||
|
||
import static io.codemodder.CodemodInvoker.run; | ||
|
||
/** Invokes the codemod from a command line. */ | ||
public final class Runner { | ||
|
||
public static void main(final String[] args) { | ||
run(args, SecureRandomCodemod.class); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...codemodder-default-codemods/src/main/java/io/codemodder/codemods/SecureRandomCodemod.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,36 @@ | ||
package io.codemodder.codemods; | ||
|
||
import com.contrastsecurity.sarif.Region; | ||
import com.github.javaparser.ast.visitor.ModifierVisitor; | ||
import io.codemodder.ChangeConstructorTypeVisitor; | ||
import io.codemodder.Codemod; | ||
import io.codemodder.CodemodInvocationContext; | ||
import io.codemodder.FileWeavingContext; | ||
import io.codemodder.ReviewGuidance; | ||
import io.codemodder.RuleSarif; | ||
import io.codemodder.providers.sarif.semgrep.SemgrepJavaParserChanger; | ||
import io.codemodder.providers.sarif.semgrep.SemgrepScan; | ||
import java.util.List; | ||
import javax.inject.Inject; | ||
|
||
/** Turns {@link java.util.Random} into {@link java.security.SecureRandom}. */ | ||
@Codemod( | ||
id = "pixee:java/secure-random", | ||
author = "[email protected]", | ||
reviewGuidance = ReviewGuidance.MERGE_WITHOUT_REVIEW) | ||
public final class SecureRandomCodemod extends SemgrepJavaParserChanger { | ||
|
||
@Inject | ||
public SecureRandomCodemod( | ||
@SemgrepScan(pathToYaml = "/secure-random.yaml", ruleId = "secure-random") | ||
nahsra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
final RuleSarif sarif) { | ||
super(sarif); | ||
} | ||
|
||
@Override | ||
public ModifierVisitor<FileWeavingContext> createVisitor( | ||
final CodemodInvocationContext context, final List<Region> regions) { | ||
return new ChangeConstructorTypeVisitor( | ||
regions, "java.security.SecureRandom", context.codemodId()); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
languages/codemodder-default-codemods/src/main/resources/secure-random.yaml
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,7 @@ | ||
rules: | ||
- id: secure-random | ||
pattern: new Random() | ||
message: Insecure PRNG | ||
languages: | ||
- java | ||
severity: WARNING |
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,46 @@ | ||
@Suppress("DSL_SCOPE_VIOLATION") // https://github.com/gradle/gradle/issues/22797 | ||
plugins { | ||
id("io.openpixee.codetl.base") | ||
id("io.openpixee.codetl.java-library") | ||
id("io.openpixee.codetl.maven-publish") | ||
alias(libs.plugins.fileversioning) | ||
} | ||
|
||
java { | ||
toolchain { | ||
languageVersion.set(JavaLanguageVersion.of(11)) | ||
} | ||
} | ||
|
||
publishing { | ||
publications { | ||
register<MavenPublication>("maven") { | ||
from(components["java"]) | ||
artifactId = "codemodder-framework-java" | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compileOnly(libs.jetbrains.annotations) | ||
|
||
api("io.github.pixee:codetf-java:0.0.2") // TODO bring codetf-java into the monorepo | ||
|
||
api(libs.guice) | ||
api(libs.contrast.sarif) | ||
api(libs.javaparser.core) | ||
api(libs.javaparser.symbolsolver.core) | ||
api(libs.javaparser.symbolsolver.logic) | ||
api(libs.javaparser.symbolsolver.model) | ||
implementation(libs.logback.classic) | ||
implementation(libs.maven.model) | ||
api(libs.slf4j.api) | ||
api(project(":languages:codemodder-common")) | ||
|
||
testImplementation(testlibs.bundles.junit.jupiter) | ||
testImplementation(testlibs.bundles.hamcrest) | ||
testImplementation(testlibs.assertj) | ||
testImplementation(testlibs.mockito) | ||
|
||
testRuntimeOnly(testlibs.junit.jupiter.engine) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took out this tight coupling to JavaParser as this class is intended to be used generally.