Skip to content

Commit

Permalink
Initial commit with simple ApplyCodemod recipe (#1)
Browse files Browse the repository at this point in the history
* Initial commit

* Add generic `ApplyCodemod` recipe

* Add a few Next.JS codemods

* Polish test

* Disable test in CI

* Run codemod from `node_modules`

* Polish build

* Copy `node_modules` to temp folder

* Use Node plugin to populate `node_modules`

* Fix build

* Fix bug when extracting node_modules from jar

* Avoid `Files.createTempDirectory()`

* Fix build

* Fix build
  • Loading branch information
knutwannheden authored Dec 7, 2023
1 parent 98d3cda commit f5ede63
Show file tree
Hide file tree
Showing 18 changed files with 6,058 additions and 292 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ build/
.gradle/
.idea/
out/

node_modules/
1 change: 0 additions & 1 deletion .java-version

This file was deleted.

104 changes: 82 additions & 22 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,37 +1,97 @@
import com.github.gradle.node.npm.task.NpmInstallTask

plugins {
id("org.openrewrite.build.recipe-library") version "latest.release"
id("com.github.node-gradle.node") version "latest.release"
}

// Set as appropriate for your organization
group = "com.yourorg"
description = "Rewrite recipes."
group = "org.openrewrite.recipe"
description = "Migrate JavaScript projects using codemods"

// The bom version can also be set to a specific version or latest.release.
val latest = "latest.integration"
val rewriteVersion = rewriteRecipe.rewriteVersion.get()
dependencies {
implementation(platform("org.openrewrite:rewrite-bom:${latest}"))
implementation(platform("org.openrewrite:rewrite-bom:$rewriteVersion"))

implementation("org.openrewrite:rewrite-java")
runtimeOnly("org.openrewrite:rewrite-java-17")
// Need to have a slf4j binding to see any output enabled from the parser.
runtimeOnly("ch.qos.logback:logback-classic:1.2.+")
implementation("org.openrewrite:rewrite-core")

testRuntimeOnly("com.google.guava:guava:latest.release")
testImplementation("org.openrewrite:rewrite-test")
}

configure<PublishingExtension> {
publications {
named("nebula", MavenPublication::class.java) {
suppressPomMetadataWarningsFor("runtimeElements")
}
}
license {
exclude("**/package.json")
exclude("**/package-lock.json")
}

node {
nodeProjectDir.set(file("build/resources/main/codemods"))
}

tasks.named("npmInstall") {
dependsOn(tasks.named("processResources"))
}

tasks.named("classes") {
dependsOn(tasks.named("npmInstall"))
}

// We don't care about publishing javadocs anywhere, so don't waste time building them
tasks.withType<Javadoc>().configureEach {
enabled = false
}

tasks.named<Jar>("sourcesJar") {
enabled = false
}

tasks.named<Jar>("javadocJar") {
enabled = false
}

val emptySourceJar = tasks.create<Jar>("emptySourceJar") {
file("README.md")
archiveClassifier.set("sources")
}

val emptyJavadocJar = tasks.create<Jar>("emptyJavadocJar") {
file("README.md")
archiveClassifier.set("javadoc")
}

publishing {
repositories {
maven {
name = "moderne"
url = uri("https://us-west1-maven.pkg.dev/moderne-dev/moderne-recipe")
}
}
publications.named<MavenPublication>("nebula") {
artifactId = project.name
description = project.description

artifacts.clear() // remove the regular JAR
// Empty JARs are OK: https://central.sonatype.org/publish/requirements/#supply-javadoc-and-sources
artifact(tasks.named("jar"))
artifact(emptySourceJar)
artifact(emptyJavadocJar)

pom {
name.set(project.name)
description.set(project.description)
url.set("https://moderne.io")
licenses {
license {
name.set("Creative Commons Attribution-NonCommercial 4.0")
url.set("https://creativecommons.org/licenses/by-nc-nd/4.0/deed.en")
}
}
developers {
developer {
name.set("Team Moderne")
email.set("[email protected]")
organization.set("Moderne, Inc.")
organizationUrl.set("https://moderne.io")
}
}
scm {
connection.set("scm:git:git://github.com/moderneinc/rewrite-codemods.git")
developerConnection.set("scm:git:ssh://github.com:moderneinc/rewrite-codemods.git")
url.set("https://github.com/moderneinc/rewrite-codemods/tree/main")
}
}
}
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 3 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
25 changes: 17 additions & 8 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,13 +80,11 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -133,22 +131,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -193,6 +198,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand Down
1 change: 1 addition & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rootProject.name = "rewrite-recipe-starter"
rootProject.name = "rewrite-codemods"
92 changes: 0 additions & 92 deletions src/main/java/com/yourorg/NoGuavaListsNewArrayList.java

This file was deleted.

Loading

0 comments on commit f5ede63

Please sign in to comment.