Skip to content

Commit

Permalink
Adopt org.openrewrite.build.recipe-library plugin
Browse files Browse the repository at this point in the history
- Apply license header to all files
- Remove unnecessary gradle plugins
- Specify type arguments in Java-8-compatible source

Issue #4
  • Loading branch information
sghill committed Jun 28, 2023
1 parent 5fa7714 commit f0c3dc8
Show file tree
Hide file tree
Showing 28 changed files with 401 additions and 39 deletions.
23 changes: 1 addition & 22 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,8 @@ import nebula.plugin.release.git.base.ReleasePluginExtension
import java.net.URI

plugins {
`java-library`
signing

id("org.openrewrite.build.recipe-library") version "latest.release"
alias(kt.plugins.jvm)

alias(nn.plugins.contacts)
alias(nn.plugins.javadoc.jar)
alias(nn.plugins.info)
alias(nn.plugins.maven.manifest)
alias(nn.plugins.maven.publish)
alias(nn.plugins.maven.resolved.dependencies)
alias(nn.plugins.publish.verification)
alias(nn.plugins.release)
alias(nn.plugins.source.jar)

id("org.openrewrite.rewrite").version("6.0.0")
}

configure<ReleasePluginExtension> {
Expand Down Expand Up @@ -71,9 +57,6 @@ dependencies {
testRuntimeOnly("com.github.spotbugs:spotbugs-annotations:4.7.0")
testRuntimeOnly("com.google.code.findbugs:jsr305:3.0.2")
testRuntimeOnly("org.slf4j:slf4j-simple:1.7.36")

rewrite(platform("org.openrewrite.recipe:rewrite-recipe-bom:2.0.0"))
rewrite("org.openrewrite:rewrite-java:8.0.0")
}

tasks.test {
Expand Down Expand Up @@ -154,7 +137,3 @@ signing {
tasks.withType<Sign>() {
onlyIf { gradle.taskGraph.hasTask(":publish") }
}

rewrite {
activeRecipe("org.openrewrite.java.upgrade.MigrateToRewrite8sghill")
}
11 changes: 0 additions & 11 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,5 @@ dependencyResolutionManagement {
val kotlin = version("kotlin", "1.8.21")
plugin("jvm", "org.jetbrains.kotlin.jvm").versionRef(kotlin)
}
create("nn") {
plugin("contacts", "com.netflix.nebula.contacts").version("7.0.1")
plugin("info", "com.netflix.nebula.info").version("12.1.4")
plugin("javadoc-jar", "com.netflix.nebula.javadoc-jar").version("20.3.0")
plugin("maven-manifest", "com.netflix.nebula.maven-manifest").version("20.3.0")
plugin("maven-publish", "com.netflix.nebula.maven-publish").version("20.3.0")
plugin("maven-resolved-dependencies", "com.netflix.nebula.maven-resolved-dependencies").version("20.3.0")
plugin("publish-verification", "com.netflix.nebula.publish-verification").version("20.3.0")
plugin("release", "com.netflix.nebula.release").version("17.2.2")
plugin("source-jar", "com.netflix.nebula.source-jar").version("20.3.0")
}
}
}
15 changes: 15 additions & 0 deletions src/main/java/net/sghill/jenkins/rewrite/AddDependency.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2023 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.
*/
package net.sghill.jenkins.rewrite;

import lombok.EqualsAndHashCode;
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/net/sghill/jenkins/rewrite/AddPluginsBom.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2023 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.
*/
package net.sghill.jenkins.rewrite;

import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -57,7 +72,7 @@ public Scanned getInitialValue(ExecutionContext ctx) {
@Override
public TreeVisitor<?, ExecutionContext> getScanner(Scanned acc) {
BomLookup lookup = new BomLookup();
return Preconditions.check(acc.hasDependencyInBom, new MavenIsoVisitor<>() {
return Preconditions.check(acc.hasDependencyInBom, new MavenIsoVisitor<ExecutionContext>() {
@Override
public Xml.Document visitDocument(Xml.Document document, ExecutionContext executionContext) {
if (acc.hasDependencyInBom) {
Expand All @@ -82,7 +97,7 @@ public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext executionContext) {

@Override
public TreeVisitor<?, ExecutionContext> getVisitor(Scanned acc) {
return Preconditions.check(acc.hasDependencyInBom, new MavenVisitor<>() {
return Preconditions.check(acc.hasDependencyInBom, new MavenVisitor<ExecutionContext>() {
@Override
public Xml visitDocument(Xml.Document document, ExecutionContext executionContext) {
Xml maven = super.visitDocument(document, executionContext);
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/net/sghill/jenkins/rewrite/ApiPluginIndex.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2023 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.
*/
package net.sghill.jenkins.rewrite;

import com.google.inject.Guice;
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/net/sghill/jenkins/rewrite/BomLookup.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2023 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.
*/
package net.sghill.jenkins.rewrite;

import lombok.Getter;
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/net/sghill/jenkins/rewrite/ChangeJenkinsVersion.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2023 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.
*/
package net.sghill.jenkins.rewrite;

import lombok.EqualsAndHashCode;
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/net/sghill/jenkins/rewrite/CreateIndexJelly.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2023 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.
*/
package net.sghill.jenkins.rewrite;

import org.openrewrite.ExecutionContext;
Expand Down Expand Up @@ -49,7 +64,7 @@ public Scanned getInitialValue(ExecutionContext ctx) {

@Override
public TreeVisitor<?, ExecutionContext> getScanner(Scanned acc) {
return Preconditions.check(!acc.isJenkinsPlugin, new TreeVisitor<>() {
return Preconditions.check(!acc.isJenkinsPlugin, new TreeVisitor<Tree, ExecutionContext>() {
@Override
public @Nullable Tree visit(@Nullable Tree tree, ExecutionContext executionContext) {
SourceFile sourceFile = (SourceFile) Objects.requireNonNull(tree);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2023 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.
*/
package net.sghill.jenkins.rewrite;

import lombok.EqualsAndHashCode;
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/net/sghill/jenkins/rewrite/IsJenkinsPlugin.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2023 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.
*/
package net.sghill.jenkins.rewrite;

import lombok.EqualsAndHashCode;
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/net/sghill/jenkins/rewrite/Jenkins.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2023 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.
*/
package net.sghill.jenkins.rewrite;

import org.openrewrite.SourceFile;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2023 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.
*/
package net.sghill.jenkins.rewrite;

import lombok.extern.slf4j.Slf4j;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2023 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.
*/
package net.sghill.jenkins.rewrite;

import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -52,20 +67,20 @@ public String getDescription() {
public TreeVisitor<?, ExecutionContext> getVisitor() {
VersionComparator versionComparator = Semver.validate(minimumVersion, null).getValue();
assert versionComparator != null;
return Preconditions.check(new MavenVisitor<>() {
return Preconditions.check(new MavenVisitor<ExecutionContext>() {
@Override
public Xml visitDocument(Xml.Document document, ExecutionContext executionContext) {
String value = getResolutionResult().getPom().getProperties().get(key);
if (value == null) {
return document;
}
Optional<String> upgrade = versionComparator.upgrade(value, Collections.singleton(minimumVersion));
if (upgrade.isEmpty()) {
if (!upgrade.isPresent()) {
return document;
}
return SearchResult.found(document);
}
}, new MavenVisitor<>() {
}, new MavenVisitor<ExecutionContext>() {
@Override
public Xml visitTag(Tag tag, ExecutionContext ctx) {
Xml.Tag t = (Tag) super.visitTag(tag, ctx);
Expand Down
16 changes: 16 additions & 0 deletions src/main/resources/META-INF/rewrite/rewrite.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
#
# Copyright 2023 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.
#

---
type: specs.openrewrite.org/v1beta/recipe
name: net.sghill.jenkins.rewrite.UpgradeHtmlUnit_3_3_0
Expand Down
17 changes: 17 additions & 0 deletions src/main/resources/jenkins-bom.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
<!--
Copyright 2023 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.
-->
<project>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
Expand Down
15 changes: 15 additions & 0 deletions src/test/kotlin/net/sghill/jenkins/rewrite/ApiPluginIndexTest.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2023 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.
*/
package net.sghill.jenkins.rewrite;

import org.junit.jupiter.api.Test;
Expand Down
15 changes: 15 additions & 0 deletions src/test/kotlin/net/sghill/jenkins/rewrite/BomLookupTest.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2023 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.
*/
package net.sghill.jenkins.rewrite;

import org.junit.jupiter.api.Test;
Expand Down
Loading

0 comments on commit f0c3dc8

Please sign in to comment.