diff --git a/src/main/java/com/canonical/devpackspring/rewrite/AddRockcraftGradleRecipe.java b/src/main/java/com/canonical/devpackspring/rewrite/AddRockcraftGradleRecipe.java deleted file mode 100644 index 18d6d39..0000000 --- a/src/main/java/com/canonical/devpackspring/rewrite/AddRockcraftGradleRecipe.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2025 the original author or authors. - * - * 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 - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * 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 com.canonical.devpackspring.rewrite; - -import com.canonical.devpackspring.rewrite.visitors.GroovyAddPluginVisitor; -import com.canonical.devpackspring.rewrite.visitors.KotlinAddPluginVisitor; -import org.openrewrite.ExecutionContext; -import org.openrewrite.NlsRewrite; -import org.openrewrite.Recipe; -import org.openrewrite.TreeVisitor; - -public class AddRockcraftGradleRecipe extends Recipe { - - private final String PLUGIN_ID = "io.github.rockcrafters.rockcraft"; - - private final String PLUGIN_VERSION = "1.0.0"; - - private final TreeVisitor visitor; - - public AddRockcraftGradleRecipe(boolean kotlin) { - if (kotlin) { - visitor = new KotlinAddPluginVisitor(PLUGIN_ID, PLUGIN_VERSION); - } - else { - visitor = new GroovyAddPluginVisitor(PLUGIN_ID, PLUGIN_VERSION); - } - } - - @Override - public @NlsRewrite.DisplayName String getDisplayName() { - return "Add rockcraft support"; - } - - @Override - public @NlsRewrite.Description String getDescription() { - return "Add rockcraft plugin support to the project"; - } - - @Override - public TreeVisitor getVisitor() { - return visitor; - } - -} diff --git a/src/main/java/com/canonical/devpackspring/rewrite/AddRockcraftMavenRecipe.java b/src/main/java/com/canonical/devpackspring/rewrite/AddRockcraftMavenRecipe.java deleted file mode 100644 index 49f292c..0000000 --- a/src/main/java/com/canonical/devpackspring/rewrite/AddRockcraftMavenRecipe.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2025 the original author or authors. - * - * 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 - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * 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 com.canonical.devpackspring.rewrite; - -import org.openrewrite.NlsRewrite; -import org.openrewrite.Recipe; -import org.openrewrite.RecipeList; -import org.openrewrite.maven.AddPlugin; - -public class AddRockcraftMavenRecipe extends Recipe { - - @Override - public @NlsRewrite.DisplayName String getDisplayName() { - return "Add rockcraft maven plugin"; - } - - @Override - public @NlsRewrite.Description String getDescription() { - return "Adds rockcraft maven plugin"; - } - - @Override - public void buildRecipeList(RecipeList recipes) { - super.buildRecipeList(recipes); - // CHECKSTYLE.OFF: SpringLeadingWhitespace - maven executions snippets format - recipes.recipe(new AddPlugin("io.github.rockcrafters", "rockcraft-maven-plugin", "1.0.0", null, null, """ - - - - - create-rock - - build-rock - - push-rock - - - - """, null)); - // CHECKSTYLE.ON: SpringLeadingWhitespace - } - -} diff --git a/src/main/java/com/canonical/devpackspring/rewrite/EnableRockcraftRefactoring.java b/src/main/java/com/canonical/devpackspring/rewrite/EnableRockcraftRefactoring.java deleted file mode 100644 index 523fe71..0000000 --- a/src/main/java/com/canonical/devpackspring/rewrite/EnableRockcraftRefactoring.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2025 the original author or authors. - * - * 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 - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * 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 com.canonical.devpackspring.rewrite; - -import java.io.IOException; -import java.nio.file.Path; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.function.Consumer; - -import org.openrewrite.InMemoryExecutionContext; -import org.openrewrite.Parser; -import org.openrewrite.SourceFile; -import org.openrewrite.gradle.GradleParser; -import org.openrewrite.groovy.GroovyParser; -import org.openrewrite.kotlin.KotlinParser; -import org.openrewrite.maven.MavenParser; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class EnableRockcraftRefactoring { - - private static final Logger logger = LoggerFactory.getLogger(EnableRockcraftRefactoring.class); - - public EnableRockcraftRefactoring() { - } - - public boolean execute(Path baseDir) throws IOException { - InMemoryExecutionContext context = new InMemoryExecutionContext(new Consumer() { - @Override - public void accept(Throwable throwable) { - logger.error(throwable.getMessage(), throwable); - } - }); - - List files = parseGradle(baseDir, context); - if (!files.isEmpty()) { - boolean kotlinDsl = files.stream() - .filter(x -> x.getSourcePath().toString().equals("build.gradle")) - .findAny() - .isEmpty(); - return RecipeUtil.applyRecipe(baseDir, new AddRockcraftGradleRecipe(kotlinDsl), files, context); - } - files = parseMaven(baseDir, context); - return RecipeUtil.applyRecipe(baseDir, new AddRockcraftMavenRecipe(), files, context); - } - - private static List parseMaven(Path baseDir, InMemoryExecutionContext context) { - Parser p = MavenParser.builder().build(); - List files = Arrays.stream(baseDir.toFile().listFiles(file -> "pom.xml".equals(file.getName()))) - .map(x -> x.toPath()) - .toList(); - - return p.parse(files, baseDir, context).toList(); - } - - private static List parseGradle(Path baseDir, InMemoryExecutionContext context) { - Parser.Builder builder = GradleParser.builder() - .groovyParser(GroovyParser.builder().logCompilationWarningsAndErrors(true)) - .kotlinParser(KotlinParser.builder().logCompilationWarningsAndErrors(true)); - - Parser p = builder.build(); - final HashSet gradleNames = new HashSet<>(Arrays.asList("build.gradle", "build.gradle.kts", - "settings.gradle", "settings.gradle.kts", "init.gradle", "init.gradle.kts")); - List files = Arrays.stream(baseDir.toFile().listFiles(file -> gradleNames.contains(file.getName()))) - .map(x -> x.toPath()) - .toList(); - - return p.parse(files, baseDir, context).toList(); - } - -}