https://github.com/pixee/simple-gradle-codemod-tutorial
An example codemodder codemod
https://github.com/pixee/simple-gradle-codemod-tutorial
codemod codemods java
Last synced: 5 months ago
JSON representation
An example codemodder codemod
- Host: GitHub
- URL: https://github.com/pixee/simple-gradle-codemod-tutorial
- Owner: pixee
- License: mit
- Created: 2023-12-08T18:18:03.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2026-01-16T16:14:58.000Z (5 months ago)
- Last Synced: 2026-01-17T05:15:18.952Z (5 months ago)
- Topics: codemod, codemods, java
- Language: Java
- Homepage: https://codemodder.io/
- Size: 217 KB
- Stars: 10
- Watchers: 5
- Forks: 6
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Sample Codemod
This page holds an example Codemodder codemod, built with Gradle, as discussed in the [codemodder.io tutorial](http://codemodder.io/languages/java/fork_sample).
The newer methods in `java.nio.file.Files` replaced the need for some of community-loved APIs in `org.apache.commons.io.FileUtils`. and this project demonstrates creating a codemod to move `org.apache.commons.io.FileUtils#readLines()` to `java.nio.file.Files.readAllLines()`. The codemod should make changes like this:
```diff
- import org.apache.commons.io.FileUtils; // remove the import if possible
+ import java.nio.file.Files;
...
- List lines = FilesUtils.readLines(file);
+ List lines = Files.readAllLines(file.toPath());
```
# Setup
1. Install JDK 17 for building this project. We recommend [Eclipse Adoptium](https://adoptium.net/)
1. Install [Semgrep](https://semgrep.dev/) CLI. See
[here](https://semgrep.dev/docs/getting-started/#installing-and-running-semgrep-locally)
for instructions. It can usually be done via `pip`:
```shell
pip install semgrep
```
If your Python library paths contain your home directory as a root folder (i.e.
due to the use of the `$HOME` environment variable), you may need to manually
set up your `PYTHONPATH` for tests:
```shell
PYTHONPATH=$HOME/ ./gradlew check
```
You can check your python paths with:
```shell
python -m site
```
# Testing
```bash
$ ./gradlew check
```
# Building
```bash
$ ./gradlew distZip
```
# Running
After building, you can run the distribution packaged in the `distZip` task.
```bash
$ cd app/build/distributions/
$ unzip app.zip
# do it without making the actual code changes on disk
$ app/bin/app --dry-run /my-project
# do it and make the actual code changes
$ app/bin/app /my-project
```