Skip to content

Commit

Permalink
Relocate ReplaceLibrariesWithApiPlugin
Browse files Browse the repository at this point in the history
Rewrite test in java. Issue #4
  • Loading branch information
sghill committed Jun 29, 2023
1 parent 281d2cc commit baa4b77
Show file tree
Hide file tree
Showing 5 changed files with 248 additions and 245 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.sghill.jenkins.rewrite;
package org.openrewrite.jenkins;

import lombok.EqualsAndHashCode;
import lombok.Value;
import net.sghill.jenkins.rewrite.AddDependency;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/META-INF/rewrite/rewrite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ recipeList:
artifactId: symbol-annotation
---
type: specs.openrewrite.org/v1beta/recipe
name: net.sghill.jenkins.rewrite.CommonsLang3ToApiPlugin
name: org.openrewrite.jenkins.CommonsLang3ToApiPlugin
recipeList:
- net.sghill.jenkins.rewrite.ReplaceLibrariesWithApiPlugin:
- org.openrewrite.jenkins.ReplaceLibrariesWithApiPlugin:
pluginGroupId: io.jenkins.plugins
pluginArtifactId: commons-lang3-api
pluginVersion: 3.12.0.0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
/*
* 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 org.openrewrite.jenkins;

import org.junit.jupiter.api.Test;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;

import java.util.Set;

import static org.openrewrite.maven.Assertions.pomXml;

class ReplaceLibrariesWithApiPluginTest implements RewriteTest {
@Override
public void defaults(RecipeSpec spec) {
spec.recipe(new ReplaceLibrariesWithApiPlugin(
"io.jenkins.plugins",
"commons-text-api",
"1.9-5.v7ea_44fe6061c",
Set.of(new ReplaceLibrariesWithApiPlugin.Library("org.apache.commons", "commons-text"))
));
}

@Test
void shouldWorkFromYamlDefinition() {
rewriteRun(spec -> spec.recipeFromResource(
"/replace-libraries-with-api-plugin.yml",
"org.openrewrite.jenkins.CommonsLang3ToApiPlugin"
), pomXml(
"""
<project>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.40</version>
<relativePath />
</parent>
<properties>
<jenkins.version>2.289.1</jenkins.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.9</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
</project>
""".stripIndent(),
"""
<project>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.40</version>
<relativePath />
</parent>
<properties>
<jenkins.version>2.289.1</jenkins.version>
</properties>
<dependencies>
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>commons-text-api</artifactId>
<version>1.9-5.v7ea_44fe6061c</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
</project>
""".stripIndent()
));
}

@Test
void shouldReplaceDirectDependencyWithApiPlugin() {
rewriteRun(pomXml(
"""
<project>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.40</version>
<relativePath />
</parent>
<properties>
<jenkins.version>2.289.1</jenkins.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.9</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
</project>
""".stripIndent(),
"""
<project>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.40</version>
<relativePath />
</parent>
<properties>
<jenkins.version>2.289.1</jenkins.version>
</properties>
<dependencies>
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>commons-text-api</artifactId>
<version>1.9-5.v7ea_44fe6061c</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
</project>
""".stripIndent()
));
}

@Test
void shouldExcludeTransitivesFromBundledLibrary() {
rewriteRun(pomXml(
"""
<project>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.40</version>
<relativePath />
</parent>
<properties>
<jenkins.version>2.289.1</jenkins.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.turbine</groupId>
<artifactId>turbine</artifactId>
<version>5.1</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
</project>
""".stripIndent(),
"""
<project>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.40</version>
<relativePath />
</parent>
<properties>
<jenkins.version>2.289.1</jenkins.version>
</properties>
<dependencies>
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>commons-text-api</artifactId>
<version>1.9-5.v7ea_44fe6061c</version>
</dependency>
<dependency>
<groupId>org.apache.turbine</groupId>
<artifactId>turbine</artifactId>
<version>5.1</version>
<exclusions>
<exclusion>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
</project>
""".stripIndent()
));
}
}
Loading

0 comments on commit baa4b77

Please sign in to comment.