-
Notifications
You must be signed in to change notification settings - Fork 912
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add spring.application.name to application.properties
Closes gh-1427
- Loading branch information
1 parent
d408fb9
commit d3e96c1
Showing
5 changed files
with
153 additions
and
1 deletion.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
.../start/site/extension/properties/ApplicationPropertiesProjectGenerationConfiguration.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,39 @@ | ||
/* | ||
* Copyright 2012-2024 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 io.spring.start.site.extension.properties; | ||
|
||
import io.spring.initializr.generator.project.ProjectDescription; | ||
import io.spring.initializr.generator.project.ProjectGenerationConfiguration; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
|
||
/** | ||
* {@link ProjectGenerationConfiguration} for customizations relevant to the application | ||
* properties. | ||
* | ||
* @author Moritz Halbritter | ||
*/ | ||
@ProjectGenerationConfiguration | ||
class ApplicationPropertiesProjectGenerationConfiguration { | ||
|
||
@Bean | ||
DefaultApplicationPropertiesCustomizer defaultApplicationPropertiesContributorCustomizer( | ||
ProjectDescription projectDescription) { | ||
return new DefaultApplicationPropertiesCustomizer(projectDescription); | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
...ava/io/spring/start/site/extension/properties/DefaultApplicationPropertiesCustomizer.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,46 @@ | ||
/* | ||
* Copyright 2012-2024 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 io.spring.start.site.extension.properties; | ||
|
||
import io.spring.initializr.generator.project.ProjectDescription; | ||
import io.spring.initializr.generator.spring.properties.ApplicationProperties; | ||
import io.spring.initializr.generator.spring.properties.ApplicationPropertiesCustomizer; | ||
|
||
import org.springframework.util.StringUtils; | ||
|
||
/** | ||
* {@link ApplicationPropertiesCustomizer} to add default application properties. | ||
* | ||
* @author Moritz Halbritter | ||
*/ | ||
class DefaultApplicationPropertiesCustomizer implements ApplicationPropertiesCustomizer { | ||
|
||
private final ProjectDescription projectDescription; | ||
|
||
DefaultApplicationPropertiesCustomizer(ProjectDescription projectDescription) { | ||
this.projectDescription = projectDescription; | ||
} | ||
|
||
@Override | ||
public void customize(ApplicationProperties properties) { | ||
String name = this.projectDescription.getName(); | ||
if (StringUtils.hasLength(name)) { | ||
properties.add("spring.application.name", name); | ||
} | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
start-site/src/main/java/io/spring/start/site/extension/properties/package-info.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,20 @@ | ||
/* | ||
* Copyright 2012-2024 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. | ||
*/ | ||
|
||
/** | ||
* Extensions for customization of the application properties. | ||
*/ | ||
package io.spring.start.site.extension.properties; |
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
46 changes: 46 additions & 0 deletions
46
...o/spring/start/site/extension/properties/DefaultApplicationPropertiesCustomizerTests.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,46 @@ | ||
/* | ||
* Copyright 2012-2024 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 io.spring.start.site.extension.properties; | ||
|
||
import io.spring.initializr.generator.test.io.TextAssert; | ||
import io.spring.initializr.generator.test.project.ProjectStructure; | ||
import io.spring.initializr.web.project.ProjectRequest; | ||
import io.spring.start.site.extension.AbstractExtensionTests; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Tests for {@link DefaultApplicationPropertiesCustomizer}. | ||
* | ||
* @author Moritz Halbritter | ||
*/ | ||
class DefaultApplicationPropertiesCustomizerTests extends AbstractExtensionTests { | ||
|
||
@Test | ||
void shouldAddSpringApplicationName() { | ||
ProjectRequest request = createProjectRequest("web"); | ||
request.setBootVersion("3.1.0"); | ||
request.setJavaVersion("21"); | ||
request.setName("test"); | ||
assertApplicationProperties(request).lines().contains("spring.application.name=test"); | ||
} | ||
|
||
private TextAssert assertApplicationProperties(ProjectRequest request) { | ||
ProjectStructure project = generateProject(request); | ||
return new TextAssert(project.getProjectDirectory().resolve("src/main/resources/application.properties")); | ||
} | ||
|
||
} |