Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jkschneider authored Aug 8, 2023
0 parents commit b0cf1b4
Show file tree
Hide file tree
Showing 20 changed files with 931 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
commit-message:
prefix: "chore(ci)"
55 changes: 55 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
name: ci

on:
push:
branches:
- main
tags-ignore:
- "*"
pull_request:
branches:
- main

env:
GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError"'
GRADLE_SWITCHES: "-s --console=plain --info --stacktrace"

jobs:
build:
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest"]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: set-up-jdk
uses: actions/[email protected]
with:
distribution: zulu
java-version: 17
cache: gradle
- name: build
run: ./gradlew ${GRADLE_SWITCHES} build test

publish-snapshots:
needs: [build]
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: set-up-jdk
uses: actions/[email protected]
with:
distribution: zulu
java-version: 17
cache: gradle
- name: publish-snapshots
if: github.event_name == 'push'
timeout-minutes: 30
run: ./gradlew ${GRADLE_SWITCHES} snapshot
11 changes: 11 additions & 0 deletions .github/workflows/gradle-wrapper-validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: "Validate Gradle Wrapper"
on: [push, pull_request]

jobs:
validation:
name: "Validation"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: gradle/wrapper-validation-action@v1
36 changes: 36 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
name: publish

on:
push:
tags:
- v[0-9]+.[0-9]+.[0-9]+
- v[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+

env:
GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError"'
GRADLE_SWITCHES: "-s --console=plain --info --stacktrace"

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: set-up-jdk
uses: actions/[email protected]
with:
distribution: zulu
java-version: 17
cache: gradle

- name: publish-candidate
if: contains(github.ref, '-rc.')
timeout-minutes: 30
run: ./gradlew ${GRADLE_SWITCHES} -Preleasing -Prelease.disableGitChecks=true -Prelease.useLastTag=true candidate publish

- name: publish-release
if: (!contains(github.ref, '-rc.'))
timeout-minutes: 30
run: ./gradlew ${GRADLE_SWITCHES} -Preleasing -Prelease.disableGitChecks=true -Prelease.useLastTag=true final publish
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
build/
.gradle/
.idea/
out/
1 change: 1 addition & 0 deletions .java-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
11
104 changes: 104 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
## Rewrite recipe starter

This repository serves as a template for building your own recipe JARs and publishing them to a repository where they can be applied on [app.moderne.io](https://app.moderne.io) against all of the public OSS code that is included there.

We've provided a sample recipe (NoGuavaListsNewArray) and a sample test class. Both of these exist as placeholders, and they should be replaced by whatever recipe you are interested in writing.

To begin, fork this repository and customize it by:

1. Changing the root project name in `settings.gradle.kts`.
2. Changing the `group` in `build.gradle.kts`.
3. Changing the package structure from `com.yourorg` to whatever you want.

## Detailed Guide

There is a [comprehensive getting started guide](https://docs.openrewrite.org/getting-started/recipe-development-environment)
available in the OpenRewrite docs that provides more details than the below README.

## Local Publishing for Testing

Before you publish your recipe module to an artifact repository, you may want to try it out locally.
To do this on the command line, run `./gradlew publishToMavenLocal` (or equivalently `./gradlew pTML`).
This will publish to your local maven repository, typically under `~/.m2/repository`.

Replace the groupId, artifactId, recipe name, and version in the below snippets with the ones that correspond to your recipe.

In a Maven project's pom.xml, make your recipe module a plugin dependency:
```xml
<project>
<build>
<plugins>
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>5.2.4</version>
<configuration>
<activeRecipes>
<recipe>com.yourorg.NoGuavaListsNewArrayList</recipe>
</activeRecipes>
</configuration>
<dependencies>
<dependency>
<groupId>com.yourorg</groupId>
<artifactId>rewrite-recipe-starter</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
```

Unlike Maven, Gradle must be explicitly configured to resolve dependencies from maven local.
The root project of your gradle build, make your recipe module a dependency of the `rewrite` configuration:

```groovy
plugins {
id("java")
id("org.openrewrite.rewrite") version("6.1.8")
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
rewrite("com.yourorg:rewrite-recipe-starter:0.1.0-SNAPSHOT")
}
rewrite {
activeRecipe("com.yourorg.NoGuavaListsNewArrayList")
}
```

Now you can run `mvn rewrite:run` or `gradlew rewriteRun` to run your recipe.

## Publishing to Artifact Repositories

This project is configured to publish to Moderne's open artifact repository (via the `publishing` task at the bottom of
the `build.gradle.kts` file). If you want to publish elsewhere, you'll want to update that task.
[app.moderne.io](https://app.moderne.io) can draw recipes from the provided repository, as well as from [Maven Central](https://search.maven.org).

Note:
Running the publish task _will not_ update [app.moderne.io](https://app.moderne.io), as only Moderne employees can
add new recipes. If you want to add your recipe to [app.moderne.io](https://app.moderne.io), please ask the
team in [Slack](https://join.slack.com/t/rewriteoss/shared_invite/zt-nj42n3ea-b~62rIHzb3Vo0E1APKCXEA) or in [Discord](https://discord.gg/xk3ZKrhWAb).

These other docs might also be useful for you depending on where you want to publish the recipe:

* Sonatype's instructions for [publishing to Maven Central](https://maven.apache.org/repository/guide-central-repository-upload.html)
* Gradle's instructions on the [Gradle Publishing Plugin](https://docs.gradle.org/current/userguide/publishing\_maven.html).

### From Github Actions

The `.github` directory contains a Github action that will push a snapshot on every successful build.

Run the release action to publish a release version of a recipe.

### From the command line

To build a snapshot, run `./gradlew snapshot publish` to build a snapshot and publish it to Moderne's open artifact repository for inclusion at [app.moderne.io](https://app.moderne.io).

To build a release, run `./gradlew final publish` to tag a release and publish it to Moderne's open artifact repository for inclusion at [app.moderne.io](https://app.moderne.io).
109 changes: 109 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import nebula.plugin.contacts.Contact
import nebula.plugin.contacts.ContactsExtension

plugins {
`java-library`

id("nebula.release") version "16.0.0"

id("nebula.maven-manifest") version "18.4.0"
id("nebula.maven-nebula-publish") version "18.4.0"
id("nebula.maven-resolved-dependencies") version "18.4.0"

id("nebula.contacts") version "6.0.0"
id("nebula.info") version "11.3.3"

id("nebula.javadoc-jar") version "18.4.0"
id("nebula.source-jar") version "18.4.0"
}

apply(plugin = "nebula.publish-verification")

configure<nebula.plugin.release.git.base.ReleasePluginExtension> {
defaultVersionStrategy = nebula.plugin.release.NetflixOssStrategies.SNAPSHOT(project)
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}

// Set as appropriate for your organization
group = "com.yourorg"
description = "Rewrite recipes."

repositories {
mavenLocal()
// Needed to pick up snapshot versions of rewrite
maven {
url = uri("https://oss.sonatype.org/content/repositories/snapshots/")
}
mavenCentral()
}

configurations.all {
resolutionStrategy {
cacheChangingModulesFor(0, TimeUnit.SECONDS)
cacheDynamicVersionsFor(0, TimeUnit.SECONDS)
}
}

// The bom version can also be set to a specific version or latest.release.
val rewriteBomVersion = "latest.integration"

dependencies {
compileOnly("org.projectlombok:lombok:latest.release")
compileOnly("com.google.code.findbugs:jsr305:latest.release")
annotationProcessor("org.projectlombok:lombok:latest.release")
implementation(platform("org.openrewrite.recipe:rewrite-recipe-bom:${rewriteBomVersion}"))

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.+")

testImplementation("org.junit.jupiter:junit-jupiter-api:latest.release")
testImplementation("org.junit.jupiter:junit-jupiter-params:latest.release")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:latest.release")
testRuntimeOnly("com.google.guava:guava:latest.release")

testImplementation("org.openrewrite:rewrite-test")
testImplementation("org.assertj:assertj-core:latest.release")
}

tasks.named<Test>("test") {
useJUnitPlatform()
jvmArgs = listOf("-XX:+UnlockDiagnosticVMOptions", "-XX:+ShowHiddenFrames")
}

tasks.withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
options.compilerArgs.add("-parameters")
}
tasks.named<JavaCompile>("compileJava") {
options.release.set(8)
}

configure<ContactsExtension> {
val j = Contact("[email protected]")
j.moniker("Team Moderne")
people["[email protected]"] = j
}

configure<PublishingExtension> {
publications {
named("nebula", MavenPublication::class.java) {
suppressPomMetadataWarningsFor("runtimeElements")
}
}
}

publishing {
repositories {
maven {
name = "moderne"
url = uri("https://us-west1-maven.pkg.dev/moderne-dev/moderne-recipe")
}
}
}
13 changes: 13 additions & 0 deletions gradle/licenseHeader.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2021 the original author or authors.
<p>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
<p>
https://www.apache.org/licenses/LICENSE-2.0
<p>
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit b0cf1b4

Please sign in to comment.