Upgrade to spring-javaformat 0.0.11
This commit is contained in:
@@ -271,8 +271,7 @@ public class SpringBootPluginExtension {
|
||||
return this.embeddedLaunchScriptProperties;
|
||||
}
|
||||
|
||||
public void setEmbeddedLaunchScriptProperties(
|
||||
Map<String, String> embeddedLaunchScriptProperties) {
|
||||
public void setEmbeddedLaunchScriptProperties(Map<String, String> embeddedLaunchScriptProperties) {
|
||||
this.embeddedLaunchScriptProperties = embeddedLaunchScriptProperties;
|
||||
}
|
||||
|
||||
@@ -281,10 +280,8 @@ public class SpringBootPluginExtension {
|
||||
}
|
||||
|
||||
public void buildInfo(Closure<?> taskConfigurer) {
|
||||
BuildInfo bootBuildInfo = this.project.getTasks().create("bootBuildInfo",
|
||||
BuildInfo.class);
|
||||
this.project.getTasks().getByName(JavaPlugin.CLASSES_TASK_NAME)
|
||||
.dependsOn(bootBuildInfo);
|
||||
BuildInfo bootBuildInfo = this.project.getTasks().create("bootBuildInfo", BuildInfo.class);
|
||||
this.project.getTasks().getByName(JavaPlugin.CLASSES_TASK_NAME).dependsOn(bootBuildInfo);
|
||||
if (taskConfigurer != null) {
|
||||
taskConfigurer.setDelegate(bootBuildInfo);
|
||||
taskConfigurer.call();
|
||||
|
||||
@@ -61,8 +61,7 @@ public class AgentTasksEnhancer implements Action<Project> {
|
||||
|
||||
private void setup(Project project) {
|
||||
project.getLogger().info("Configuring agent");
|
||||
SpringBootPluginExtension extension = project.getExtensions()
|
||||
.getByType(SpringBootPluginExtension.class);
|
||||
SpringBootPluginExtension extension = project.getExtensions().getByType(SpringBootPluginExtension.class);
|
||||
this.noverify = extension.getNoverify();
|
||||
this.agent = getAgent(project, extension);
|
||||
if (this.agent == null) {
|
||||
@@ -116,8 +115,7 @@ public class AgentTasksEnhancer implements Action<Project> {
|
||||
if (this.noverify != null && this.noverify) {
|
||||
exec.jvmArgs("-noverify");
|
||||
}
|
||||
Iterable<?> defaultJvmArgs = exec.getConventionMapping()
|
||||
.getConventionValue(null, "jvmArgs", false);
|
||||
Iterable<?> defaultJvmArgs = exec.getConventionMapping().getConventionValue(null, "jvmArgs", false);
|
||||
if (defaultJvmArgs != null) {
|
||||
exec.jvmArgs(defaultJvmArgs);
|
||||
}
|
||||
|
||||
@@ -46,15 +46,14 @@ import org.springframework.boot.loader.tools.BuildPropertiesWriter.ProjectDetail
|
||||
public class BuildInfo extends DefaultTask {
|
||||
|
||||
@OutputFile
|
||||
private File outputFile = getProject().file(new File(getProject().getBuildDir(),
|
||||
"resources/main/META-INF/build-info.properties"));
|
||||
private File outputFile = getProject()
|
||||
.file(new File(getProject().getBuildDir(), "resources/main/META-INF/build-info.properties"));
|
||||
|
||||
@Input
|
||||
private String projectGroup = getProject().getGroup().toString();
|
||||
|
||||
@Input
|
||||
private String projectArtifact = ((Jar) getProject().getTasks()
|
||||
.getByName(JavaPlugin.JAR_TASK_NAME)).getBaseName();
|
||||
private String projectArtifact = ((Jar) getProject().getTasks().getByName(JavaPlugin.JAR_TASK_NAME)).getBaseName();
|
||||
|
||||
@Input
|
||||
private String projectVersion = getProject().getVersion().toString();
|
||||
@@ -69,9 +68,8 @@ public class BuildInfo extends DefaultTask {
|
||||
public void generateBuildProperties() {
|
||||
try {
|
||||
new BuildPropertiesWriter(this.outputFile)
|
||||
.writeBuildProperties(new ProjectDetails(this.projectGroup,
|
||||
this.projectArtifact, this.projectVersion, this.projectName,
|
||||
coerceToStringValues(this.additionalProperties)));
|
||||
.writeBuildProperties(new ProjectDetails(this.projectGroup, this.projectArtifact,
|
||||
this.projectVersion, this.projectName, coerceToStringValues(this.additionalProperties)));
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new TaskExecutionException(this, ex);
|
||||
|
||||
@@ -33,8 +33,8 @@ import org.springframework.boot.gradle.PluginFeatures;
|
||||
*/
|
||||
public class DependencyManagementPluginFeatures implements PluginFeatures {
|
||||
|
||||
private static final String SPRING_BOOT_VERSION = DependencyManagementPluginFeatures.class
|
||||
.getPackage().getImplementationVersion();
|
||||
private static final String SPRING_BOOT_VERSION = DependencyManagementPluginFeatures.class.getPackage()
|
||||
.getImplementationVersion();
|
||||
|
||||
private static final String SPRING_BOOT_BOM = "org.springframework.boot:spring-boot-starter-parent:"
|
||||
+ SPRING_BOOT_VERSION;
|
||||
|
||||
@@ -30,13 +30,11 @@ import org.slf4j.LoggerFactory;
|
||||
@Deprecated
|
||||
public class DeprecatedSpringBootPlugin extends SpringBootPlugin {
|
||||
|
||||
private static final Logger logger = LoggerFactory
|
||||
.getLogger(DeprecatedSpringBootPlugin.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(DeprecatedSpringBootPlugin.class);
|
||||
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
logger.warn("The plugin id 'spring-boot' is deprecated. Please use "
|
||||
+ "'org.springframework.boot' instead.");
|
||||
logger.warn("The plugin id 'spring-boot' is deprecated. Please use " + "'org.springframework.boot' instead.");
|
||||
super.apply(project);
|
||||
}
|
||||
|
||||
|
||||
@@ -40,8 +40,7 @@ public class SpringBootPlugin implements Plugin<Project> {
|
||||
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
project.getExtensions().create("springBoot", SpringBootPluginExtension.class,
|
||||
project);
|
||||
project.getExtensions().create("springBoot", SpringBootPluginExtension.class, project);
|
||||
project.getPlugins().apply(JavaPlugin.class);
|
||||
new AgentPluginFeatures().apply(project);
|
||||
new RepackagePluginFeatures().apply(project);
|
||||
|
||||
@@ -63,8 +63,7 @@ class ProjectLibraries implements Libraries {
|
||||
* @param extension the extension
|
||||
* @param excludeDevTools whether Spring Boot Devtools should be excluded
|
||||
*/
|
||||
ProjectLibraries(Project project, SpringBootPluginExtension extension,
|
||||
boolean excludeDevTools) {
|
||||
ProjectLibraries(Project project, SpringBootPluginExtension extension, boolean excludeDevTools) {
|
||||
this.project = project;
|
||||
this.extension = extension;
|
||||
this.excludeDevtools = excludeDevTools;
|
||||
@@ -73,8 +72,7 @@ class ProjectLibraries implements Libraries {
|
||||
|
||||
private static TargetConfigurationResolver createTargetConfigurationResolver() {
|
||||
try {
|
||||
return new Gradle3TargetConfigurationResolver(
|
||||
ProjectDependency.class.getMethod("getTargetConfiguration"));
|
||||
return new Gradle3TargetConfigurationResolver(ProjectDependency.class.getMethod("getTargetConfiguration"));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return new Gradle2TargetConfigurationResolver();
|
||||
@@ -95,15 +93,13 @@ class ProjectLibraries implements Libraries {
|
||||
|
||||
@Override
|
||||
public void doWithLibraries(LibraryCallback callback) throws IOException {
|
||||
Set<GradleLibrary> custom = getLibraries(this.customConfigurationName,
|
||||
LibraryScope.CUSTOM);
|
||||
Set<GradleLibrary> custom = getLibraries(this.customConfigurationName, LibraryScope.CUSTOM);
|
||||
if (custom != null) {
|
||||
libraries(custom, callback);
|
||||
}
|
||||
else {
|
||||
Set<GradleLibrary> runtime = getLibraries("runtime", LibraryScope.RUNTIME);
|
||||
Set<GradleLibrary> provided = getLibraries(this.providedConfigurationName,
|
||||
LibraryScope.PROVIDED);
|
||||
Set<GradleLibrary> provided = getLibraries(this.providedConfigurationName, LibraryScope.PROVIDED);
|
||||
if (provided != null) {
|
||||
runtime = minus(runtime, provided);
|
||||
}
|
||||
@@ -112,47 +108,39 @@ class ProjectLibraries implements Libraries {
|
||||
}
|
||||
}
|
||||
|
||||
private Set<GradleLibrary> getLibraries(String configurationName,
|
||||
LibraryScope scope) {
|
||||
private Set<GradleLibrary> getLibraries(String configurationName, LibraryScope scope) {
|
||||
Configuration configuration = (configurationName != null)
|
||||
? this.project.getConfigurations().findByName(configurationName) : null;
|
||||
if (configuration == null) {
|
||||
return null;
|
||||
}
|
||||
Set<GradleLibrary> libraries = new LinkedHashSet<GradleLibrary>();
|
||||
for (ResolvedArtifact artifact : configuration.getResolvedConfiguration()
|
||||
.getResolvedArtifacts()) {
|
||||
for (ResolvedArtifact artifact : configuration.getResolvedConfiguration().getResolvedArtifacts()) {
|
||||
libraries.add(new ResolvedArtifactLibrary(artifact, scope));
|
||||
}
|
||||
libraries.addAll(getLibrariesForFileDependencies(configuration, scope));
|
||||
return libraries;
|
||||
}
|
||||
|
||||
private Set<GradleLibrary> getLibrariesForFileDependencies(
|
||||
Configuration configuration, LibraryScope scope) {
|
||||
private Set<GradleLibrary> getLibrariesForFileDependencies(Configuration configuration, LibraryScope scope) {
|
||||
Set<GradleLibrary> libraries = new LinkedHashSet<GradleLibrary>();
|
||||
for (Dependency dependency : configuration.getIncoming().getDependencies()) {
|
||||
if (dependency instanceof FileCollectionDependency) {
|
||||
FileCollectionDependency fileDependency = (FileCollectionDependency) dependency;
|
||||
for (File file : fileDependency.resolve()) {
|
||||
libraries.add(
|
||||
new GradleLibrary(fileDependency.getGroup(), file, scope));
|
||||
libraries.add(new GradleLibrary(fileDependency.getGroup(), file, scope));
|
||||
}
|
||||
}
|
||||
else if (dependency instanceof ProjectDependency) {
|
||||
ProjectDependency projectDependency = (ProjectDependency) dependency;
|
||||
libraries
|
||||
.addAll(getLibrariesForFileDependencies(
|
||||
this.targetConfigurationResolver
|
||||
.resolveTargetConfiguration(projectDependency),
|
||||
scope));
|
||||
libraries.addAll(getLibrariesForFileDependencies(
|
||||
this.targetConfigurationResolver.resolveTargetConfiguration(projectDependency), scope));
|
||||
}
|
||||
}
|
||||
return libraries;
|
||||
}
|
||||
|
||||
private Set<GradleLibrary> minus(Set<GradleLibrary> source,
|
||||
Set<GradleLibrary> toRemove) {
|
||||
private Set<GradleLibrary> minus(Set<GradleLibrary> source, Set<GradleLibrary> toRemove) {
|
||||
if (source == null || toRemove == null) {
|
||||
return source;
|
||||
}
|
||||
@@ -169,8 +157,7 @@ class ProjectLibraries implements Libraries {
|
||||
return result;
|
||||
}
|
||||
|
||||
private void libraries(Set<GradleLibrary> libraries, LibraryCallback callback)
|
||||
throws IOException {
|
||||
private void libraries(Set<GradleLibrary> libraries, LibraryCallback callback) throws IOException {
|
||||
if (libraries != null) {
|
||||
Set<String> duplicates = getDuplicates(libraries);
|
||||
for (GradleLibrary library : libraries) {
|
||||
@@ -261,8 +248,7 @@ class ProjectLibraries implements Libraries {
|
||||
private final ResolvedArtifact artifact;
|
||||
|
||||
ResolvedArtifactLibrary(ResolvedArtifact artifact, LibraryScope scope) {
|
||||
super(artifact.getModuleVersion().getId().getGroup(), artifact.getFile(),
|
||||
scope);
|
||||
super(artifact.getModuleVersion().getId().getGroup(), artifact.getFile(), scope);
|
||||
this.artifact = artifact;
|
||||
}
|
||||
|
||||
@@ -270,8 +256,7 @@ class ProjectLibraries implements Libraries {
|
||||
public boolean isUnpackRequired() {
|
||||
if (ProjectLibraries.this.extension.getRequiresUnpack() != null) {
|
||||
ModuleVersionIdentifier id = this.artifact.getModuleVersion().getId();
|
||||
return ProjectLibraries.this.extension.getRequiresUnpack()
|
||||
.contains(id.getGroup() + ":" + id.getName());
|
||||
return ProjectLibraries.this.extension.getRequiresUnpack().contains(id.getGroup() + ":" + id.getName());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -291,12 +276,10 @@ class ProjectLibraries implements Libraries {
|
||||
/**
|
||||
* {@link TargetConfigurationResolver} for Gradle 2.x.
|
||||
*/
|
||||
private static final class Gradle2TargetConfigurationResolver
|
||||
implements TargetConfigurationResolver {
|
||||
private static final class Gradle2TargetConfigurationResolver implements TargetConfigurationResolver {
|
||||
|
||||
@Override
|
||||
public Configuration resolveTargetConfiguration(
|
||||
ProjectDependency projectDependency) {
|
||||
public Configuration resolveTargetConfiguration(ProjectDependency projectDependency) {
|
||||
return projectDependency.getProjectConfiguration();
|
||||
}
|
||||
|
||||
@@ -305,8 +288,7 @@ class ProjectLibraries implements Libraries {
|
||||
/**
|
||||
* {@link TargetConfigurationResolver} for Gradle 3.x.
|
||||
*/
|
||||
private static final class Gradle3TargetConfigurationResolver
|
||||
implements TargetConfigurationResolver {
|
||||
private static final class Gradle3TargetConfigurationResolver implements TargetConfigurationResolver {
|
||||
|
||||
private final Method getTargetConfiguration;
|
||||
|
||||
@@ -315,14 +297,11 @@ class ProjectLibraries implements Libraries {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Configuration resolveTargetConfiguration(
|
||||
ProjectDependency projectDependency) {
|
||||
public Configuration resolveTargetConfiguration(ProjectDependency projectDependency) {
|
||||
try {
|
||||
String configurationName = (String) this.getTargetConfiguration
|
||||
.invoke(projectDependency);
|
||||
String configurationName = (String) this.getTargetConfiguration.invoke(projectDependency);
|
||||
return projectDependency.getDependencyProject().getConfigurations()
|
||||
.getByName((configurationName != null) ? configurationName
|
||||
: Dependency.DEFAULT_CONFIGURATION);
|
||||
.getByName((configurationName != null) ? configurationName : Dependency.DEFAULT_CONFIGURATION);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new RuntimeException("Failed to get target configuration", ex);
|
||||
|
||||
@@ -58,20 +58,16 @@ public class RepackagePluginFeatures implements PluginFeatures {
|
||||
}
|
||||
|
||||
private void addRepackageTask(Project project) {
|
||||
RepackageTask task = project.getTasks().create(REPACKAGE_TASK_NAME,
|
||||
RepackageTask.class);
|
||||
RepackageTask task = project.getTasks().create(REPACKAGE_TASK_NAME, RepackageTask.class);
|
||||
task.setDescription("Repackage existing JAR and WAR "
|
||||
+ "archives so that they can be executed from the command "
|
||||
+ "line using 'java -jar'");
|
||||
+ "archives so that they can be executed from the command " + "line using 'java -jar'");
|
||||
task.setGroup(BasePlugin.BUILD_GROUP);
|
||||
Configuration runtimeConfiguration = project.getConfigurations()
|
||||
.getByName(JavaPlugin.RUNTIME_CONFIGURATION_NAME);
|
||||
TaskDependency runtimeProjectDependencyJarTasks = runtimeConfiguration
|
||||
.getTaskDependencyFromProjectDependency(true, JavaPlugin.JAR_TASK_NAME);
|
||||
task.dependsOn(
|
||||
project.getConfigurations().getByName(Dependency.ARCHIVES_CONFIGURATION)
|
||||
.getAllArtifacts().getBuildDependencies(),
|
||||
runtimeProjectDependencyJarTasks);
|
||||
task.dependsOn(project.getConfigurations().getByName(Dependency.ARCHIVES_CONFIGURATION).getAllArtifacts()
|
||||
.getBuildDependencies(), runtimeProjectDependencyJarTasks);
|
||||
registerOutput(project, task);
|
||||
ensureTaskRunsOnAssembly(project, task);
|
||||
ensureMainClassHasBeenFound(project, task);
|
||||
@@ -81,8 +77,7 @@ public class RepackagePluginFeatures implements PluginFeatures {
|
||||
project.afterEvaluate(new Action<Project>() {
|
||||
@Override
|
||||
public void execute(Project project) {
|
||||
project.getTasks().withType(Jar.class,
|
||||
new RegisterInputsOutputsAction(task));
|
||||
project.getTasks().withType(Jar.class, new RegisterInputsOutputsAction(task));
|
||||
Object withJar = task.getWithJarTask();
|
||||
if (withJar != null) {
|
||||
task.dependsOn(withJar);
|
||||
@@ -104,8 +99,7 @@ public class RepackagePluginFeatures implements PluginFeatures {
|
||||
* @param project the source project
|
||||
*/
|
||||
private void registerRepackageTaskProperty(Project project) {
|
||||
project.getExtensions().getExtraProperties().set("BootRepackage",
|
||||
RepackageTask.class);
|
||||
project.getExtensions().getExtraProperties().set("BootRepackage", RepackageTask.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,12 +134,11 @@ public class RepackagePluginFeatures implements PluginFeatures {
|
||||
|
||||
private void setupInputOutputs(Jar jarTask, String classifier) {
|
||||
Logger logger = this.project.getLogger();
|
||||
logger.debug("Using classifier: " + classifier + " for task "
|
||||
+ this.task.getName());
|
||||
logger.debug("Using classifier: " + classifier + " for task " + this.task.getName());
|
||||
File inputFile = jarTask.getArchivePath();
|
||||
String outputName = inputFile.getName();
|
||||
outputName = StringUtils.stripFilenameExtension(outputName) + "-" + classifier
|
||||
+ "." + StringUtils.getFilenameExtension(outputName);
|
||||
outputName = StringUtils.stripFilenameExtension(outputName) + "-" + classifier + "."
|
||||
+ StringUtils.getFilenameExtension(outputName);
|
||||
File outputFile = new File(inputFile.getParentFile(), outputName);
|
||||
this.task.getInputs().file(jarTask);
|
||||
addLibraryDependencies(this.task);
|
||||
|
||||
@@ -126,27 +126,23 @@ public class RepackageTask extends DefaultTask {
|
||||
return this.embeddedLaunchScriptProperties;
|
||||
}
|
||||
|
||||
public void setEmbeddedLaunchScriptProperties(
|
||||
Map<String, String> embeddedLaunchScriptProperties) {
|
||||
public void setEmbeddedLaunchScriptProperties(Map<String, String> embeddedLaunchScriptProperties) {
|
||||
this.embeddedLaunchScriptProperties = embeddedLaunchScriptProperties;
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
public void repackage() {
|
||||
Project project = getProject();
|
||||
SpringBootPluginExtension extension = project.getExtensions()
|
||||
.getByType(SpringBootPluginExtension.class);
|
||||
SpringBootPluginExtension extension = project.getExtensions().getByType(SpringBootPluginExtension.class);
|
||||
ProjectLibraries libraries = getLibraries();
|
||||
project.getTasks().withType(Jar.class, new RepackageAction(extension, libraries));
|
||||
}
|
||||
|
||||
public ProjectLibraries getLibraries() {
|
||||
Project project = getProject();
|
||||
SpringBootPluginExtension extension = project.getExtensions()
|
||||
.getByType(SpringBootPluginExtension.class);
|
||||
SpringBootPluginExtension extension = project.getExtensions().getByType(SpringBootPluginExtension.class);
|
||||
ProjectLibraries libraries = new ProjectLibraries(project, extension,
|
||||
(this.excludeDevtools != null) ? this.excludeDevtools
|
||||
: extension.isExcludeDevtools());
|
||||
(this.excludeDevtools != null) ? this.excludeDevtools : extension.isExcludeDevtools());
|
||||
if (extension.getProvidedConfiguration() != null) {
|
||||
libraries.setProvidedConfigurationName(extension.getProvidedConfiguration());
|
||||
}
|
||||
@@ -181,8 +177,7 @@ public class RepackageTask extends DefaultTask {
|
||||
}
|
||||
Object withJarTask = RepackageTask.this.withJarTask;
|
||||
if (!isTaskMatch(jarTask, withJarTask)) {
|
||||
getLogger().info(
|
||||
"Jar task not repackaged (didn't match withJarTask): " + jarTask);
|
||||
getLogger().info("Jar task not repackaged (didn't match withJarTask): " + jarTask);
|
||||
return;
|
||||
}
|
||||
File file = jarTask.getArchivePath();
|
||||
@@ -195,11 +190,10 @@ public class RepackageTask extends DefaultTask {
|
||||
if (withJarTask == null) {
|
||||
if ("".equals(task.getClassifier())) {
|
||||
Set<Object> tasksWithCustomRepackaging = new HashSet<Object>();
|
||||
for (RepackageTask repackageTask : RepackageTask.this.getProject()
|
||||
.getTasks().withType(RepackageTask.class)) {
|
||||
for (RepackageTask repackageTask : RepackageTask.this.getProject().getTasks()
|
||||
.withType(RepackageTask.class)) {
|
||||
if (repackageTask.getWithJarTask() != null) {
|
||||
tasksWithCustomRepackaging
|
||||
.add(repackageTask.getWithJarTask());
|
||||
tasksWithCustomRepackaging.add(repackageTask.getWithJarTask());
|
||||
}
|
||||
}
|
||||
return !tasksWithCustomRepackaging.contains(task);
|
||||
@@ -216,16 +210,13 @@ public class RepackageTask extends DefaultTask {
|
||||
copy(file, outputFile);
|
||||
file = outputFile;
|
||||
}
|
||||
Repackager repackager = new Repackager(file,
|
||||
this.extension.getLayoutFactory());
|
||||
repackager.addMainClassTimeoutWarningListener(
|
||||
new LoggingMainClassTimeoutWarningListener());
|
||||
Repackager repackager = new Repackager(file, this.extension.getLayoutFactory());
|
||||
repackager.addMainClassTimeoutWarningListener(new LoggingMainClassTimeoutWarningListener());
|
||||
setMainClass(repackager);
|
||||
Layout layout = this.extension.convertLayout();
|
||||
if (layout != null) {
|
||||
if (layout instanceof Layouts.Module) {
|
||||
getLogger().warn("Module layout is deprecated. Please use a custom"
|
||||
+ " LayoutFactory instead.");
|
||||
getLogger().warn("Module layout is deprecated. Please use a custom" + " LayoutFactory instead.");
|
||||
}
|
||||
repackager.setLayout(layout);
|
||||
}
|
||||
@@ -259,8 +250,7 @@ public class RepackageTask extends DefaultTask {
|
||||
else {
|
||||
Task runTask = getProject().getTasks().findByName("run");
|
||||
if (runTask != null && runTask.hasProperty("main")) {
|
||||
mainClassName = (String) getProject().getTasks().getByName("run")
|
||||
.property("main");
|
||||
mainClassName = (String) getProject().getTasks().getByName("run").property("main");
|
||||
}
|
||||
}
|
||||
if (mainClassName != null) {
|
||||
@@ -276,8 +266,8 @@ public class RepackageTask extends DefaultTask {
|
||||
if (getProject().hasProperty("mainClassName")) {
|
||||
return (String) getProject().property("mainClassName");
|
||||
}
|
||||
ExtraPropertiesExtension extraProperties = (ExtraPropertiesExtension) getProject()
|
||||
.getExtensions().getByName("ext");
|
||||
ExtraPropertiesExtension extraProperties = (ExtraPropertiesExtension) getProject().getExtensions()
|
||||
.getByName("ext");
|
||||
if (extraProperties.has("mainClassName")) {
|
||||
return (String) extraProperties.get("mainClassName");
|
||||
}
|
||||
@@ -286,8 +276,7 @@ public class RepackageTask extends DefaultTask {
|
||||
|
||||
private LaunchScript getLaunchScript() throws IOException {
|
||||
if (isExecutable() || getEmbeddedLaunchScript() != null) {
|
||||
return new DefaultLaunchScript(getEmbeddedLaunchScript(),
|
||||
getEmbeddedLaunchScriptProperties());
|
||||
return new DefaultLaunchScript(getEmbeddedLaunchScript(), getEmbeddedLaunchScriptProperties());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -298,8 +287,7 @@ public class RepackageTask extends DefaultTask {
|
||||
}
|
||||
|
||||
private File getEmbeddedLaunchScript() {
|
||||
return (RepackageTask.this.embeddedLaunchScript != null)
|
||||
? RepackageTask.this.embeddedLaunchScript
|
||||
return (RepackageTask.this.embeddedLaunchScript != null) ? RepackageTask.this.embeddedLaunchScript
|
||||
: this.extension.getEmbeddedLaunchScript();
|
||||
}
|
||||
|
||||
@@ -314,13 +302,12 @@ public class RepackageTask extends DefaultTask {
|
||||
/**
|
||||
* {@link Repackager} that also logs when searching takes too long.
|
||||
*/
|
||||
private class LoggingMainClassTimeoutWarningListener
|
||||
implements MainClassTimeoutWarningListener {
|
||||
private class LoggingMainClassTimeoutWarningListener implements MainClassTimeoutWarningListener {
|
||||
|
||||
@Override
|
||||
public void handleTimeoutWarning(long duration, String mainMethod) {
|
||||
getLogger().warn("Searching for the main-class is taking "
|
||||
+ "some time, consider using setting " + "'springBoot.mainClass'");
|
||||
getLogger().warn("Searching for the main-class is taking " + "some time, consider using setting "
|
||||
+ "'springBoot.mainClass'");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -65,8 +65,7 @@ public class BootRunTask extends JavaExec {
|
||||
private void addResourcesIfNecessary() {
|
||||
if (this.addResources) {
|
||||
SourceSet mainSourceSet = SourceSets.findMainSourceSet(getProject());
|
||||
final File outputDir = (mainSourceSet != null)
|
||||
? mainSourceSet.getOutput().getResourcesDir() : null;
|
||||
final File outputDir = (mainSourceSet != null) ? mainSourceSet.getOutput().getResourcesDir() : null;
|
||||
final Set<File> resources = new LinkedHashSet<File>();
|
||||
if (mainSourceSet != null) {
|
||||
resources.addAll(mainSourceSet.getResources().getSrcDirs());
|
||||
|
||||
@@ -60,15 +60,14 @@ public class FindMainClassTask extends DefaultTask {
|
||||
@TaskAction
|
||||
public void setMainClassNameProperty() {
|
||||
Project project = getProject();
|
||||
if (!project.hasProperty("mainClassName")
|
||||
|| project.property("mainClassName") == null) {
|
||||
if (!project.hasProperty("mainClassName") || project.property("mainClassName") == null) {
|
||||
String mainClass = findMainClass();
|
||||
if (project.hasProperty("mainClassName")) {
|
||||
project.setProperty("mainClassName", mainClass);
|
||||
}
|
||||
else {
|
||||
ExtraPropertiesExtension extraProperties = (ExtraPropertiesExtension) project
|
||||
.getExtensions().getByName("ext");
|
||||
ExtraPropertiesExtension extraProperties = (ExtraPropertiesExtension) project.getExtensions()
|
||||
.getByName("ext");
|
||||
extraProperties.set("mainClassName", mainClass);
|
||||
}
|
||||
}
|
||||
@@ -80,14 +79,13 @@ public class FindMainClassTask extends DefaultTask {
|
||||
String mainClass = null;
|
||||
|
||||
// Try the SpringBoot extension setting
|
||||
SpringBootPluginExtension bootExtension = project.getExtensions()
|
||||
.getByType(SpringBootPluginExtension.class);
|
||||
SpringBootPluginExtension bootExtension = project.getExtensions().getByType(SpringBootPluginExtension.class);
|
||||
if (bootExtension.getMainClass() != null) {
|
||||
mainClass = bootExtension.getMainClass();
|
||||
}
|
||||
|
||||
ApplicationPluginConvention application = (ApplicationPluginConvention) project
|
||||
.getConvention().getPlugins().get("application");
|
||||
ApplicationPluginConvention application = (ApplicationPluginConvention) project.getConvention().getPlugins()
|
||||
.get("application");
|
||||
|
||||
if (mainClass == null && application != null) {
|
||||
// Try the Application extension setting
|
||||
@@ -109,12 +107,10 @@ public class FindMainClassTask extends DefaultTask {
|
||||
if (mainClass == null) {
|
||||
// Search
|
||||
if (this.mainClassSourceSetOutput != null) {
|
||||
Collection<File> classesDirs = getClassesDirs(
|
||||
this.mainClassSourceSetOutput);
|
||||
Collection<File> classesDirs = getClassesDirs(this.mainClassSourceSetOutput);
|
||||
getProject().getLogger().debug("Looking for main in: " + classesDirs);
|
||||
try {
|
||||
mainClass = MainClassFinder.findSingleMainClass(classesDirs,
|
||||
SPRING_BOOT_APPLICATION_CLASS_NAME);
|
||||
mainClass = MainClassFinder.findSingleMainClass(classesDirs, SPRING_BOOT_APPLICATION_CLASS_NAME);
|
||||
getProject().getLogger().info("Computed main class: " + mainClass);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
@@ -139,13 +135,11 @@ public class FindMainClassTask extends DefaultTask {
|
||||
}
|
||||
|
||||
private Collection<File> getClassesDirs(SourceSetOutput sourceSetOutput) {
|
||||
Method getClassesDirs = ReflectionUtils.findMethod(SourceSetOutput.class,
|
||||
"getClassesDirs");
|
||||
Method getClassesDirs = ReflectionUtils.findMethod(SourceSetOutput.class, "getClassesDirs");
|
||||
if (getClassesDirs == null) {
|
||||
return Arrays.asList(sourceSetOutput.getClassesDir());
|
||||
}
|
||||
FileCollection classesDirs = (FileCollection) ReflectionUtils
|
||||
.invokeMethod(getClassesDirs, sourceSetOutput);
|
||||
FileCollection classesDirs = (FileCollection) ReflectionUtils.invokeMethod(getClassesDirs, sourceSetOutput);
|
||||
return classesDirs.getFiles();
|
||||
}
|
||||
|
||||
|
||||
@@ -47,8 +47,8 @@ public class RunPluginFeatures implements PluginFeatures {
|
||||
}
|
||||
|
||||
private void mainClassNameFinder(Project project) {
|
||||
FindMainClassTask findMainClassTask = project.getTasks()
|
||||
.create(FIND_MAIN_CLASS_TASK_NAME, FindMainClassTask.class);
|
||||
FindMainClassTask findMainClassTask = project.getTasks().create(FIND_MAIN_CLASS_TASK_NAME,
|
||||
FindMainClassTask.class);
|
||||
SourceSet mainSourceSet = SourceSets.findMainSourceSet(project);
|
||||
if (mainSourceSet != null) {
|
||||
findMainClassTask.setMainClassSourceSetOutput(mainSourceSet.getOutput());
|
||||
@@ -64,24 +64,21 @@ public class RunPluginFeatures implements PluginFeatures {
|
||||
}
|
||||
|
||||
private void addBootRunTask(final Project project) {
|
||||
final JavaPluginConvention javaConvention = project.getConvention()
|
||||
.getPlugin(JavaPluginConvention.class);
|
||||
final JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
|
||||
|
||||
BootRunTask run = project.getTasks().create(RUN_APP_TASK_NAME, BootRunTask.class);
|
||||
run.setDescription("Run the project with support for "
|
||||
+ "auto-detecting main class and reloading static resources");
|
||||
run.setDescription(
|
||||
"Run the project with support for " + "auto-detecting main class and reloading static resources");
|
||||
run.setGroup("application");
|
||||
run.setClasspath(
|
||||
javaConvention.getSourceSets().findByName("main").getRuntimeClasspath());
|
||||
run.setClasspath(javaConvention.getSourceSets().findByName("main").getRuntimeClasspath());
|
||||
run.getConventionMapping().map("main", new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
if (project.hasProperty("mainClassName")
|
||||
&& project.property("mainClassName") != null) {
|
||||
if (project.hasProperty("mainClassName") && project.property("mainClassName") != null) {
|
||||
return project.property("mainClassName");
|
||||
}
|
||||
ExtraPropertiesExtension extraPropertiesExtension = (ExtraPropertiesExtension) project
|
||||
.getExtensions().getByName("ext");
|
||||
ExtraPropertiesExtension extraPropertiesExtension = (ExtraPropertiesExtension) project.getExtensions()
|
||||
.getByName("ext");
|
||||
if (extraPropertiesExtension.has("mainClassName")
|
||||
&& extraPropertiesExtension.get("mainClassName") != null) {
|
||||
return extraPropertiesExtension.get("mainClassName");
|
||||
|
||||
@@ -43,8 +43,7 @@ final class SourceSets {
|
||||
}
|
||||
|
||||
private static Iterable<SourceSet> getJavaSourceSets(Project project) {
|
||||
JavaPluginConvention plugin = project.getConvention()
|
||||
.getPlugin(JavaPluginConvention.class);
|
||||
JavaPluginConvention plugin = project.getConvention().getPlugin(JavaPluginConvention.class);
|
||||
if (plugin == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user