-
Notifications
You must be signed in to change notification settings - Fork 908
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add indication that the JVM version was downgraded
This commit adds a warning when it detects that the JVM version was downgraded. While not providing the exact reason, it provides a link to the supported Java versions. See gh-250
- Loading branch information
Showing
5 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
...io/spring/start/site/extension/description/DescriptionProjectGenerationConfiguration.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,40 @@ | ||
/* | ||
* Copyright 2012-2019 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.description; | ||
|
||
import io.spring.initializr.generator.project.ProjectDescription; | ||
import io.spring.initializr.generator.project.ProjectDescriptionDiff; | ||
import io.spring.initializr.generator.project.ProjectGenerationConfiguration; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
|
||
/** | ||
* {@link ProjectGenerationConfiguration} for customizations relevant to the | ||
* {@link ProjectDescription}. | ||
* | ||
* @author Stephane Nicoll | ||
*/ | ||
@ProjectGenerationConfiguration | ||
public class DescriptionProjectGenerationConfiguration { | ||
|
||
@Bean | ||
public InvalidJvmVersionHelpDocumentCustomizer invalidJvmVersionHelpDocumentCustomizer(ProjectDescriptionDiff diff, | ||
ProjectDescription description) { | ||
return new InvalidJvmVersionHelpDocumentCustomizer(diff, description); | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
...a/io/spring/start/site/extension/description/InvalidJvmVersionHelpDocumentCustomizer.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,56 @@ | ||
/* | ||
* Copyright 2012-2019 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.description; | ||
|
||
import java.util.Objects; | ||
|
||
import io.spring.initializr.generator.project.ProjectDescription; | ||
import io.spring.initializr.generator.project.ProjectDescriptionDiff; | ||
import io.spring.initializr.generator.spring.documentation.HelpDocument; | ||
import io.spring.initializr.generator.spring.documentation.HelpDocumentCustomizer; | ||
|
||
/** | ||
* A {@link HelpDocumentCustomizer} that adds a warning when the JVM level was changed. | ||
* | ||
* @author Stephane Nicoll | ||
*/ | ||
public class InvalidJvmVersionHelpDocumentCustomizer implements HelpDocumentCustomizer { | ||
|
||
private final ProjectDescriptionDiff diff; | ||
|
||
private final ProjectDescription description; | ||
|
||
public InvalidJvmVersionHelpDocumentCustomizer(ProjectDescriptionDiff diff, ProjectDescription description) { | ||
this.diff = diff; | ||
this.description = description; | ||
} | ||
|
||
@Override | ||
public void customize(HelpDocument document) { | ||
this.diff.ifLanguageChanged(this.description, (original, current) -> { | ||
String originalJvmVersion = original.jvmVersion(); | ||
String currentJvmVersion = current.jvmVersion(); | ||
if (!Objects.equals(originalJvmVersion, currentJvmVersion)) { | ||
document.getWarnings().addItem(String.format( | ||
"The JVM level was changed from '%s' to '%s', review the [JDK Version Range](%s) on the wiki for more details.", | ||
originalJvmVersion, currentJvmVersion, | ||
"https://github.com/spring-projects/spring-framework/wiki/Spring-Framework-Versions#jdk-version-range")); | ||
} | ||
}); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
start-site/src/main/java/io/spring/start/site/extension/description/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-2019 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 project description. | ||
*/ | ||
package io.spring.start.site.extension.description; |
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
51 changes: 51 additions & 0 deletions
51
...spring/start/site/extension/description/InvalidJvmVersionHelpDocumentCustomizerTests.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,51 @@ | ||
/* | ||
* Copyright 2012-2019 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.description; | ||
|
||
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 InvalidJvmVersionHelpDocumentCustomizer}. | ||
* | ||
* @author Stephane Nicoll | ||
*/ | ||
class InvalidJvmVersionHelpDocumentCustomizerTests extends AbstractExtensionTests { | ||
|
||
@Test | ||
void warningAddedWithSpringBoot21AndJava13() { | ||
assertHelpDocument("2.1.0.RELEASE", "13").lines().containsSubsequence("# Read Me First", | ||
"* The JVM level was changed from '13' to '11', review the [JDK Version Range](https://github.com/spring-projects/spring-framework/wiki/Spring-Framework-Versions#jdk-version-range) on the wiki for more details."); | ||
} | ||
|
||
@Test | ||
void warningNotAddedWithCompatibleVersion() { | ||
assertHelpDocument("2.1.0.RELEASE", "11").doesNotContain("# Read Me First"); | ||
} | ||
|
||
private TextAssert assertHelpDocument(String platformVersion, String jvmVersion) { | ||
ProjectRequest request = createProjectRequest("web"); | ||
request.setBootVersion(platformVersion); | ||
request.setJavaVersion(jvmVersion); | ||
ProjectStructure project = generateProject(request); | ||
return new TextAssert(project.getProjectDirectory().resolve("HELP.md")); | ||
} | ||
|
||
} |