Skip to content

Commit

Permalink
Add indication that the JVM version was downgraded
Browse files Browse the repository at this point in the history
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
snicoll committed Dec 27, 2019
1 parent 599d8c4 commit a12d02e
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 0 deletions.
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);
}

}
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"));
}
});
}

}
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;
1 change: 1 addition & 0 deletions start-site/src/main/resources/META-INF/spring.factories
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ io.spring.start.site.extension.dependency.springcloud.SpringCloudProjectGenerati
io.spring.start.site.extension.dependency.springdata.SpringDataProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.springintegration.SpringIntegrationProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.springrestdocs.SpringRestDocsProjectGenerationConfiguration,\
io.spring.start.site.extension.description.DescriptionProjectGenerationConfiguration,\
io.spring.start.site.extension.code.kotin.KotlinProjectGenerationConfiguration
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"));
}

}

0 comments on commit a12d02e

Please sign in to comment.