Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SpringBoot devtools feature #187

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public enum Phase {
ANNOTATION_PROCESSING,
COMPILATION,
CONSOLE,
DEVELOPMENT_ONLY,
RUNTIME,
OPENREWRITE,
BUILD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class Scope {
public static final Scope COMPILE = new Scope(Source.MAIN, Arrays.asList(Phase.COMPILATION, Phase.RUNTIME));
public static final Scope COMPILE_ONLY = new Scope(Source.MAIN, Collections.singletonList(Phase.COMPILATION));
public static final Scope CONSOLE = new Scope(Source.MAIN, Collections.singletonList(Phase.CONSOLE));
public static final Scope DEVELOPMENT_ONLY = new Scope(Source.MAIN, Collections.singletonList(Phase.DEVELOPMENT_ONLY));
public static final Scope RUNTIME = new Scope(Source.MAIN, Collections.singletonList(Phase.RUNTIME));
public static final Scope TEST = new Scope(Source.TEST, Arrays.asList(Phase.COMPILATION, Phase.RUNTIME));
public static final Scope TEST_ANNOTATION_PROCESSOR = new Scope(Source.TEST, Collections.singletonList(Phase.ANNOTATION_PROCESSING));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public enum GradleConfiguration implements Ordered {
IMPLEMENTATION("implementation", 4),
COMPILE_ONLY("compileOnly", 5),
CONSOLE("console", 6),
DEVELOPMENT_ONLY("developmentOnly", 2),
RUNTIME_ONLY("runtimeOnly", 7),
TEST_ANNOTATION_PROCESSOR("testAnnotationProcessor", 8),
TEST_KAPT("kaptTest", 9),
Expand Down Expand Up @@ -85,6 +86,9 @@ public static Optional<GradleConfiguration> of(@NonNull Scope scope,
}
return Optional.of(GradleConfiguration.RUNTIME_ONLY);
}
if (scope.getPhases().contains(Phase.DEVELOPMENT_ONLY)) {
return Optional.of(GradleConfiguration.DEVELOPMENT_ONLY);
}
if (scope.getPhases().contains(Phase.COMPILATION)) {
return Optional.of(GradleConfiguration.COMPILE_ONLY);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2017-2020 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 org.grails.forge.feature.reloading;

import jakarta.inject.Singleton;
import org.grails.forge.application.generator.GeneratorContext;
import org.grails.forge.build.dependencies.Dependency;
import org.grails.forge.build.dependencies.Scope;


@Singleton
public class SpringBootDevTools implements ReloadingFeature {
@Override
public String getName() {
return "spring-boot-devtools";
}

@Override
public String getTitle() {
return "SpringBoot Developer Tools";
}

@Override
public String getDescription() {
return "Spring Boot Devtools is a powerful tool that enhances development productivity by providing features like automatic application restarts on code changes, live reloading of static resources, and remote debugging support. It enables developers to rapidly iterate and test changes during the development process, making it a valuable asset for Spring Boot projects.";
}

@Override
public void apply(GeneratorContext generatorContext) {
generatorContext.addDependency(Dependency.builder().groupId("org.springframework.boot")
.artifactId("spring-boot-devtools")
.scope(Scope.DEVELOPMENT_ONLY)
.build());
}

@Override
public boolean isVisible() {
return true;
}

@Override
public String getDocumentation() {
return "https://docs.spring.io/spring-boot/docs/2.7.12/reference/htmlsingle/#using.devtools";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.grails.forge.feature.reloading;

import jakarta.inject.Singleton;
import org.grails.forge.application.ApplicationType;
import org.grails.forge.application.generator.GeneratorContext;
import org.grails.forge.feature.Feature;
import org.grails.forge.feature.FeatureContext;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.grails.forge.feature.reloading

import org.grails.forge.ApplicationContextSpec
import org.grails.forge.application.ApplicationType
import org.grails.forge.feature.Features
import org.grails.forge.fixture.CommandOutputFixture

class SpringBootDevToolsSpec extends ApplicationContextSpec implements CommandOutputFixture {

void "test spring-boot-devtools feature"() {

when:
final Features features = getFeatures(["spring-boot-devtools"])

then:
features.contains("spring-boot-devtools")

}

void "test spring-boot-devtools dependency is present for #applicationType application type"() {

when:
def output = generate(applicationType, ["spring-boot-devtools"])
def build = output["build.gradle"]

then:
build.contains("developmentOnly(\"org.springframework.boot:spring-boot-devtools\"")

where:
applicationType << [ApplicationType.WEB, ApplicationType.REST_API]
}

void "test there can be only one of Reloading feature"() {
when:
getFeatures(beanContext.getBeansOfType(ReloadingFeature.class)*.name)

then:
def ex = thrown(IllegalArgumentException)
ex.message.contains("There can only be one of the following features selected")
}
}