-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
245 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
starter-cli/src/main/java/io/micronaut/starter/cli/command/AddFeatureCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright 2017-2022 original 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 io.micronaut.starter.cli.command; | ||
|
||
import io.micronaut.context.annotation.Prototype; | ||
import io.micronaut.core.annotation.ReflectiveAccess; | ||
import io.micronaut.starter.feature.AvailableFeatures; | ||
import io.micronaut.starter.openrewrite.OpenRewriteAvailableFeatures; | ||
import io.micronaut.starter.openrewrite.OpenRewriteFeature; | ||
import picocli.CommandLine; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.Callable; | ||
|
||
@CommandLine.Command(name = AddFeatureCommand.NAME, description = "Modifies an existing application by adding features (dependencies, configuration, etc.)") | ||
@Prototype | ||
public class AddFeatureCommand extends BaseCommand implements Callable<Integer> { | ||
|
||
public static final String NAME = "add-feature"; | ||
|
||
@CommandLine.Option(names = {"-f", "--features"}, paramLabel = "FEATURE", split = ",", | ||
description = "The features to apply. Possible values: ${COMPLETION-CANDIDATES}", | ||
completionCandidates = OpenRewriteAvailableFeatures.class) | ||
@ReflectiveAccess | ||
protected List<String> features = new ArrayList<>(); | ||
|
||
protected final AvailableFeatures availableFeatures; | ||
|
||
public AddFeatureCommand(OpenRewriteAvailableFeatures availableFeatures) { | ||
this.availableFeatures = availableFeatures; | ||
} | ||
|
||
@Override | ||
public Integer call() throws Exception { | ||
List<String> recipeNames = new ArrayList<>(); | ||
for (String feature : features) { | ||
recipeNames.add(availableFeatures.findFeature(feature) | ||
.filter(OpenRewriteFeature.class::isInstance) | ||
.map(f -> ((OpenRewriteFeature) f).getRecipeName()) | ||
.orElseThrow(() -> new CommandLine.ParameterException(spec.commandLine(), "Feature [" + feature + "] is not supported by the " + NAME + " command"))); | ||
} | ||
return 0; | ||
} | ||
|
||
void applyOpenRewriteRecipes(List<String> recipeNames) { | ||
//TODO apply OpenRewrite Recipes | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
starter-cli/src/test/groovy/io/micronaut/starter/cli/command/AddFeatureCommandSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.micronaut.starter.cli.command | ||
|
||
import io.micronaut.configuration.picocli.PicocliRunner | ||
import io.micronaut.context.ApplicationContext | ||
import io.micronaut.context.env.Environment | ||
import spock.lang.AutoCleanup | ||
import spock.lang.Shared | ||
import spock.lang.Specification | ||
|
||
class AddFeatureCommandSpec extends Specification { | ||
|
||
@Shared | ||
@AutoCleanup | ||
ApplicationContext ctx = ApplicationContext.run(Environment.CLI) | ||
|
||
void "test arm is not an OpenRewriteFeature"() { | ||
given: | ||
ByteArrayOutputStream baos = new ByteArrayOutputStream() | ||
System.setErr(new PrintStream(baos)) | ||
|
||
when: | ||
PicocliRunner.run(AddFeatureCommand, ctx, "--features", "arm") | ||
|
||
then: | ||
noExceptionThrown() | ||
baos.toString().contains("Feature [arm] is not supported by the add-feature command") | ||
} | ||
|
||
void "apply mockito OpenRewriteFeature"() { | ||
given: | ||
ByteArrayOutputStream baos = new ByteArrayOutputStream() | ||
System.setErr(new PrintStream(baos)) | ||
|
||
when: | ||
PicocliRunner.run(AddFeatureCommand, ctx, "--features", "mockito") | ||
|
||
then: | ||
noExceptionThrown() | ||
!baos.toString().contains("Feature [mockitoG] is not supported by the add-feature command") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...ter-core/src/main/java/io/micronaut/starter/openrewrite/OpenRewriteAvailableFeatures.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright 2017-2022 original 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 io.micronaut.starter.openrewrite; | ||
|
||
import io.micronaut.starter.feature.BaseAvailableFeatures; | ||
import io.micronaut.starter.feature.Feature; | ||
import jakarta.inject.Singleton; | ||
import java.util.List; | ||
|
||
@Singleton | ||
public class OpenRewriteAvailableFeatures extends BaseAvailableFeatures { | ||
|
||
public OpenRewriteAvailableFeatures(List<Feature> features) { | ||
super(features.stream() | ||
.filter(OpenRewriteFeature.class::isInstance) | ||
.toList()); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
starter-core/src/main/java/io/micronaut/starter/openrewrite/OpenRewriteFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2017-2022 original 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 io.micronaut.starter.openrewrite; | ||
|
||
import io.micronaut.core.annotation.NonNull; | ||
import io.micronaut.starter.feature.Feature; | ||
|
||
/** | ||
* A feature backed by an OpenRewrite recipe. | ||
* @author Sergio del Amo | ||
*/ | ||
public interface OpenRewriteFeature extends Feature { | ||
|
||
@NonNull | ||
String getRecipeName(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 2 additions & 5 deletions
7
starter-openrewrite-recipes/src/main/resources/META-INF/rewrite/rewrite.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,10 @@ | ||
--- | ||
type: specs.openrewrite.org/v1beta/recipe | ||
name: micronaut.starter.feature.mockito.AddDependencyMockito | ||
name: micronaut.starter.feature.Mockito | ||
displayName: Add Mockito dependency in the test configuration | ||
recipeList: | ||
- org.openrewrite.gradle.AddDependency: | ||
- org.openrewrite.java.dependencies.AddDependency: | ||
groupId: org.mockito | ||
artifactId: mockito-core | ||
configuration: testImplementation | ||
- org.openrewrite.maven.AddDependency: | ||
groupId: org.mockito | ||
artifactId: mockito-core | ||
scope: test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters