Restructure the code to enforce separation of plugin logic and tasks
parent
5f27ecc6d9
commit
8d55801c4d
@ -1,174 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2017 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
|
||||
*
|
||||
* http://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.springframework.boot.gradle.bundling;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
import org.gradle.api.artifacts.ModuleDependency;
|
||||
import org.gradle.api.artifacts.PublishArtifact;
|
||||
import org.gradle.api.artifacts.maven.MavenResolver;
|
||||
import org.gradle.api.attributes.Usage;
|
||||
import org.gradle.api.file.FileCollection;
|
||||
import org.gradle.api.internal.artifacts.publish.ArchivePublishArtifact;
|
||||
import org.gradle.api.internal.attributes.Usages;
|
||||
import org.gradle.api.internal.component.SoftwareComponentInternal;
|
||||
import org.gradle.api.internal.component.UsageContext;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.gradle.api.plugins.JavaPluginConvention;
|
||||
import org.gradle.api.plugins.WarPlugin;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
import org.gradle.api.tasks.Upload;
|
||||
|
||||
import org.springframework.boot.gradle.MainClassResolver;
|
||||
import org.springframework.boot.gradle.PluginFeatures;
|
||||
|
||||
/**
|
||||
* {@link PluginFeatures} for the bundling of an application.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class BundlingPluginFeatures implements PluginFeatures {
|
||||
|
||||
private SinglePublishedArtifact singlePublishedArtifact;
|
||||
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
this.singlePublishedArtifact = new SinglePublishedArtifact(
|
||||
project.getConfigurations().create("bootArchives").getArtifacts());
|
||||
project.getPlugins().withType(JavaPlugin.class,
|
||||
(javaPlugin) -> configureBootJarTask(project));
|
||||
project.getPlugins().withType(WarPlugin.class,
|
||||
(warPlugin) -> configureBootWarTask(project));
|
||||
project.afterEvaluate(this::configureBootArchivesUpload);
|
||||
}
|
||||
|
||||
private void configureBootWarTask(Project project) {
|
||||
BootWar bootWar = project.getTasks().create("bootWar", BootWar.class);
|
||||
bootWar.providedClasspath(providedRuntimeConfiguration(project));
|
||||
ArchivePublishArtifact artifact = new ArchivePublishArtifact(bootWar);
|
||||
this.singlePublishedArtifact.addCandidate(artifact);
|
||||
project.getComponents().add(new BootSoftwareComponent(artifact, "bootWeb"));
|
||||
bootWar.conventionMapping("mainClass",
|
||||
mainClassConvention(project, bootWar::getClasspath));
|
||||
}
|
||||
|
||||
private void configureBootJarTask(Project project) {
|
||||
BootJar bootJar = project.getTasks().create("bootJar", BootJar.class);
|
||||
bootJar.classpath((Callable<FileCollection>) () -> {
|
||||
JavaPluginConvention convention = project.getConvention()
|
||||
.getPlugin(JavaPluginConvention.class);
|
||||
SourceSet mainSourceSet = convention.getSourceSets()
|
||||
.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
|
||||
return mainSourceSet.getRuntimeClasspath();
|
||||
});
|
||||
ArchivePublishArtifact artifact = new ArchivePublishArtifact(bootJar);
|
||||
this.singlePublishedArtifact.addCandidate(artifact);
|
||||
project.getComponents().add(new BootSoftwareComponent(artifact, "bootJava"));
|
||||
bootJar.conventionMapping("mainClass",
|
||||
mainClassConvention(project, bootJar::getClasspath));
|
||||
}
|
||||
|
||||
private Callable<Object> mainClassConvention(Project project,
|
||||
Supplier<FileCollection> classpathSupplier) {
|
||||
return () -> {
|
||||
if (project.hasProperty("mainClassName")) {
|
||||
return project.property("mainClassName");
|
||||
}
|
||||
return new MainClassResolver(classpathSupplier.get()).resolveMainClass();
|
||||
};
|
||||
}
|
||||
|
||||
private void configureBootArchivesUpload(Project project) {
|
||||
Upload upload = project.getTasks().withType(Upload.class)
|
||||
.findByName("uploadBootArchives");
|
||||
if (upload == null) {
|
||||
return;
|
||||
}
|
||||
clearConfigurationMappings(upload);
|
||||
}
|
||||
|
||||
private void clearConfigurationMappings(Upload upload) {
|
||||
upload.getRepositories().withType(MavenResolver.class, (resolver) -> {
|
||||
resolver.getPom().getScopeMappings().getMappings().clear();
|
||||
});
|
||||
}
|
||||
|
||||
private Configuration providedRuntimeConfiguration(Project project) {
|
||||
return project.getConfigurations()
|
||||
.getByName(WarPlugin.PROVIDED_RUNTIME_CONFIGURATION_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link SofwareComponent} for a Spring Boot fat jar or war.
|
||||
*/
|
||||
private static final class BootSoftwareComponent
|
||||
implements SoftwareComponentInternal {
|
||||
|
||||
private final PublishArtifact artifact;
|
||||
|
||||
private final String name;
|
||||
|
||||
private BootSoftwareComponent(PublishArtifact artifact, String name) {
|
||||
this.artifact = artifact;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UsageContext> getUsages() {
|
||||
return Collections.singleton(new BootUsageContext(this.artifact));
|
||||
}
|
||||
|
||||
private static final class BootUsageContext implements UsageContext {
|
||||
|
||||
private static final Usage USAGE = Usages.usage("master");
|
||||
|
||||
private final PublishArtifact artifact;
|
||||
|
||||
private BootUsageContext(PublishArtifact artifact) {
|
||||
this.artifact = artifact;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Usage getUsage() {
|
||||
return USAGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PublishArtifact> getArtifacts() {
|
||||
return Collections.singleton(this.artifact);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ModuleDependency> getDependencies() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2012-2017 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
|
||||
*
|
||||
* http://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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Spring Boot Gradle DSL.
|
||||
*/
|
||||
package org.springframework.boot.gradle.dsl;
|
@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright 2012-2017 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
|
||||
*
|
||||
* http://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.springframework.boot.gradle.plugin;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import org.gradle.api.Action;
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.file.FileCollection;
|
||||
import org.gradle.api.internal.artifacts.publish.ArchivePublishArtifact;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.gradle.api.plugins.JavaPluginConvention;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
import org.gradle.api.tasks.compile.JavaCompile;
|
||||
|
||||
import org.springframework.boot.gradle.tasks.bundling.BootJar;
|
||||
import org.springframework.boot.gradle.tasks.run.BootRun;
|
||||
|
||||
/**
|
||||
* {@link Action} that is executed in response to the {@link JavaPlugin} being applied.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
final class JavaPluginAction implements PluginApplicationAction {
|
||||
|
||||
private final SinglePublishedArtifact singlePublishedArtifact;
|
||||
|
||||
JavaPluginAction(SinglePublishedArtifact singlePublishedArtifact) {
|
||||
this.singlePublishedArtifact = singlePublishedArtifact;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Plugin<? extends Project>> getPluginClass() {
|
||||
return JavaPlugin.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Project project) {
|
||||
BootJar bootJar = configureBootJarTask(project);
|
||||
configureArtifactPublication(project, bootJar);
|
||||
configureBootRunTask(project);
|
||||
configureUtf8Encoding(project);
|
||||
}
|
||||
|
||||
private BootJar configureBootJarTask(Project project) {
|
||||
BootJar bootJar = project.getTasks().create(SpringBootPlugin.BOOT_JAR_TASK_NAME,
|
||||
BootJar.class);
|
||||
bootJar.classpath((Callable<FileCollection>) () -> {
|
||||
JavaPluginConvention convention = project.getConvention()
|
||||
.getPlugin(JavaPluginConvention.class);
|
||||
SourceSet mainSourceSet = convention.getSourceSets()
|
||||
.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
|
||||
return mainSourceSet.getRuntimeClasspath();
|
||||
});
|
||||
bootJar.conventionMapping("mainClass",
|
||||
new MainClassConvention(project, bootJar::getClasspath));
|
||||
return bootJar;
|
||||
}
|
||||
|
||||
private void configureArtifactPublication(Project project, BootJar bootJar) {
|
||||
ArchivePublishArtifact artifact = new ArchivePublishArtifact(bootJar);
|
||||
this.singlePublishedArtifact.addCandidate(artifact);
|
||||
project.getComponents().add(new SpringBootSoftwareComponent(artifact,
|
||||
SpringBootPlugin.BOOT_JAVA_SOFTWARE_COMPONENT_NAME));
|
||||
}
|
||||
|
||||
private void configureBootRunTask(Project project) {
|
||||
JavaPluginConvention javaConvention = project.getConvention()
|
||||
.getPlugin(JavaPluginConvention.class);
|
||||
BootRun run = project.getTasks().create("bootRun", BootRun.class);
|
||||
run.setDescription("Run the project with support for "
|
||||
+ "auto-detecting main class and reloading static resources");
|
||||
run.setGroup("application");
|
||||
run.classpath(javaConvention.getSourceSets()
|
||||
.findByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath());
|
||||
run.getConventionMapping().map("jvmArgs", () -> {
|
||||
if (project.hasProperty("applicationDefaultJvmArgs")) {
|
||||
return project.property("applicationDefaultJvmArgs");
|
||||
}
|
||||
return Collections.emptyList();
|
||||
});
|
||||
run.conventionMapping("main",
|
||||
new MainClassConvention(project, run::getClasspath));
|
||||
}
|
||||
|
||||
private void configureUtf8Encoding(Project project) {
|
||||
project.getTasks().withType(JavaCompile.class,
|
||||
compile -> compile.doFirst(task -> {
|
||||
if (compile.getOptions().getEncoding() == null) {
|
||||
compile.getOptions().setEncoding("UTF-8");
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2012-2017 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
|
||||
*
|
||||
* http://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.springframework.boot.gradle.plugin;
|
||||
|
||||
import org.gradle.api.Action;
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.maven.MavenResolver;
|
||||
import org.gradle.api.plugins.MavenPlugin;
|
||||
import org.gradle.api.tasks.Upload;
|
||||
|
||||
/**
|
||||
* {@link Action} that is executed in response to the {@link MavenPlugin} being applied.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
final class MavenPluginAction implements PluginApplicationAction {
|
||||
|
||||
private final String uploadTaskName;
|
||||
|
||||
MavenPluginAction(String uploadTaskName) {
|
||||
this.uploadTaskName = uploadTaskName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Plugin<? extends Project>> getPluginClass() {
|
||||
return MavenPlugin.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Project project) {
|
||||
project.getTasks().withType(Upload.class, upload -> {
|
||||
if (this.uploadTaskName.equals(upload.getName())) {
|
||||
project.afterEvaluate(evaluated -> clearConfigurationMappings(upload));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void clearConfigurationMappings(Upload upload) {
|
||||
upload.getRepositories().withType(MavenResolver.class,
|
||||
resolver -> resolver.getPom().getScopeMappings().getMappings().clear());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright 2012-2017 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
|
||||
*
|
||||
* http://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.springframework.boot.gradle.plugin;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gradle.api.artifacts.ModuleDependency;
|
||||
import org.gradle.api.artifacts.PublishArtifact;
|
||||
import org.gradle.api.attributes.Usage;
|
||||
import org.gradle.api.internal.attributes.Usages;
|
||||
import org.gradle.api.internal.component.SoftwareComponentInternal;
|
||||
import org.gradle.api.internal.component.UsageContext;
|
||||
|
||||
/**
|
||||
* {@link org.gradle.api.component.SoftwareComponent} for a Spring Boot fat jar or war.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
final class SpringBootSoftwareComponent implements SoftwareComponentInternal {
|
||||
|
||||
private final PublishArtifact artifact;
|
||||
|
||||
private final String name;
|
||||
|
||||
SpringBootSoftwareComponent(PublishArtifact artifact, String name) {
|
||||
this.artifact = artifact;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UsageContext> getUsages() {
|
||||
return Collections.singleton(new BootUsageContext(this.artifact));
|
||||
}
|
||||
|
||||
private static final class BootUsageContext implements UsageContext {
|
||||
|
||||
private static final Usage USAGE = Usages.usage("master");
|
||||
|
||||
private final PublishArtifact artifact;
|
||||
|
||||
private BootUsageContext(PublishArtifact artifact) {
|
||||
this.artifact = artifact;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Usage getUsage() {
|
||||
return USAGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PublishArtifact> getArtifacts() {
|
||||
return Collections.singleton(this.artifact);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ModuleDependency> getDependencies() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2012-2017 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
|
||||
*
|
||||
* http://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.springframework.boot.gradle.plugin;
|
||||
|
||||
import org.gradle.api.Action;
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
import org.gradle.api.internal.artifacts.publish.ArchivePublishArtifact;
|
||||
import org.gradle.api.plugins.WarPlugin;
|
||||
|
||||
import org.springframework.boot.gradle.tasks.bundling.BootWar;
|
||||
|
||||
/**
|
||||
* {@link Action} that is executed in response to the {@link WarPlugin} being applied.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
class WarPluginAction implements PluginApplicationAction {
|
||||
|
||||
private final SinglePublishedArtifact singlePublishedArtifact;
|
||||
|
||||
WarPluginAction(SinglePublishedArtifact singlePublishedArtifact) {
|
||||
this.singlePublishedArtifact = singlePublishedArtifact;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Plugin<? extends Project>> getPluginClass() {
|
||||
return WarPlugin.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Project project) {
|
||||
BootWar bootWar = project.getTasks().create(SpringBootPlugin.BOOT_WAR_TASK_NAME,
|
||||
BootWar.class);
|
||||
bootWar.providedClasspath(providedRuntimeConfiguration(project));
|
||||
ArchivePublishArtifact artifact = new ArchivePublishArtifact(bootWar);
|
||||
this.singlePublishedArtifact.addCandidate(artifact);
|
||||
project.getComponents().add(new SpringBootSoftwareComponent(artifact,
|
||||
SpringBootPlugin.BOOT_WEB_SOFTWARE_COMPONENT_NAME));
|
||||
bootWar.conventionMapping("mainClass",
|
||||
new MainClassConvention(project, bootWar::getClasspath));
|
||||
}
|
||||
|
||||
private Configuration providedRuntimeConfiguration(Project project) {
|
||||
return project.getConfigurations()
|
||||
.getByName(WarPlugin.PROVIDED_RUNTIME_CONFIGURATION_NAME);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2012-2017 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
|
||||
*
|
||||
* http://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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Central classes for the Spring Boot Gradle plugin.
|
||||
*/
|
||||
package org.springframework.boot.gradle.plugin;
|
@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2017 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
|
||||
*
|
||||
* http://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.springframework.boot.gradle.run;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.gradle.api.plugins.JavaPluginConvention;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
|
||||
import org.springframework.boot.gradle.MainClassResolver;
|
||||
import org.springframework.boot.gradle.PluginFeatures;
|
||||
|
||||
/**
|
||||
* {@link PluginFeatures} to add run support.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class RunPluginFeatures implements PluginFeatures {
|
||||
|
||||
private static final String RUN_APP_TASK_NAME = "bootRun";
|
||||
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
project.getPlugins().withType(JavaPlugin.class, (javaPlugin) -> {
|
||||
addBootRunTask(project);
|
||||
});
|
||||
}
|
||||
|
||||
private void addBootRunTask(Project project) {
|
||||
JavaPluginConvention javaConvention = project.getConvention()
|
||||
.getPlugin(JavaPluginConvention.class);
|
||||
BootRun run = project.getTasks().create(RUN_APP_TASK_NAME, BootRun.class);
|
||||
run.setDescription("Run the project with support for "
|
||||
+ "auto-detecting main class and reloading static resources");
|
||||
run.setGroup("application");
|
||||
run.classpath(javaConvention.getSourceSets()
|
||||
.findByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath());
|
||||
run.getConventionMapping().map("jvmArgs", ((Callable<Object>) () -> {
|
||||
if (project.hasProperty("applicationDefaultJvmArgs")) {
|
||||
return project.property("applicationDefaultJvmArgs");
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}));
|
||||
run.conventionMapping("main", () -> {
|
||||
if (project.hasProperty("mainClassName")) {
|
||||
return project.property("mainClassName");
|
||||
}
|
||||
return new MainClassResolver(run.getClasspath()).resolveMainClass();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2015 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
|
||||
*
|
||||
* http://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.springframework.boot.gradle.run;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.plugins.JavaPluginConvention;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
|
||||
/**
|
||||
* Utilities for working with {@link SourceSet}s.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
final class SourceSets {
|
||||
|
||||
private SourceSets() {
|
||||
}
|
||||
|
||||
public static SourceSet findMainSourceSet(Project project) {
|
||||
for (SourceSet sourceSet : getJavaSourceSets(project)) {
|
||||
if (SourceSet.MAIN_SOURCE_SET_NAME.equals(sourceSet.getName())) {
|
||||
return sourceSet;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Iterable<SourceSet> getJavaSourceSets(Project project) {
|
||||
JavaPluginConvention plugin = project.getConvention()
|
||||
.getPlugin(JavaPluginConvention.class);
|
||||
if (plugin == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return plugin.getSourceSets();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2012-2017 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
|
||||
*
|
||||
* http://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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Classes related to Gradle's application features.
|
||||
*/
|
||||
package org.springframework.boot.gradle.tasks.application;
|
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2012-2017 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
|
||||
*
|
||||
* http://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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Support for producing build info for consumption by Spring Boot's actuator.
|
||||
*/
|
||||
package org.springframework.boot.gradle.tasks.buildinfo;
|
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2012-2017 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
|
||||
*
|
||||
* http://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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Support for creating executable jars and wars.
|
||||
*/
|
||||
package org.springframework.boot.gradle.tasks.bundling;
|
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2012-2017 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
|
||||
*
|
||||
* http://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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Support for running Spring Boot applications.
|
||||
*/
|
||||
package org.springframework.boot.gradle.tasks.run;
|
7
spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/dependencymanagement/DependencyManagementIntegrationTests.java → spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/DependencyManagementPluginActionIntegrationTests.java
7
spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/dependencymanagement/DependencyManagementIntegrationTests.java → spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/DependencyManagementPluginActionIntegrationTests.java
Loading…
Reference in New Issue