Skip to content

Add removal of Image Banner to report #499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2021 - 2022 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 org.springframework.sbm.boot.upgrade_27_30.report.helper;

import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSection;
import org.springframework.sbm.engine.context.ProjectContext;
import org.springframework.sbm.project.resource.RewriteSourceFileHolder;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class BannerSupportHelper implements SpringBootUpgradeReportSection.Helper<List<String>> {

private List<Path> foundBanners;

@Override
public String getDescription() {
return "";
}

@Override
public boolean evaluate(ProjectContext context) {
foundBanners = context
.getProjectResources()
.stream()
.map(RewriteSourceFileHolder::getAbsolutePath)
.filter(absolutePath -> absolutePath.toString()
.matches(".*banner.(jpg|gif|png)$")
)
.collect(Collectors.toList());
return !foundBanners.isEmpty();
}

@Override
public Map<String, List<String>> getData(ProjectContext context) {

return Map.of("files", foundBanners.stream().map(Path::toString).collect(Collectors.toList()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@
import lombok.RequiredArgsConstructor;
import org.springframework.sbm.boot.properties.api.SpringBootApplicationProperties;
import org.springframework.sbm.boot.properties.search.SpringBootApplicationPropertiesResourceListFilter;
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportAction;
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSection;
import org.springframework.sbm.build.migration.conditions.NoDependencyExistMatchingRegex;
import org.springframework.sbm.engine.context.ProjectContext;
import org.springframework.sbm.engine.recipe.Condition;

import java.nio.file.Path;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
description: Create a report for Spring Boot Upgrade from 2.7.x to 3.0.x
condition:
type: org.springframework.sbm.boot.common.conditions.IsSpringBootProject
versionPattern: "2\\.4\\..*|2\\.5\\..*"
versionPattern: "2\\.7\\..*"

actions:

Expand All @@ -18,7 +18,7 @@
= Spring Boot 3 Upgrade Report
<#if contributors?has_content>
<#list contributors as contributor>
${contributor.name}<#sep>, </#sep>
${contributor.name}<#sep>,</#sep>
</#list>
</#if>
:source-highlighter: highlight.js
Expand Down Expand Up @@ -113,7 +113,24 @@
contributors:
- "Fabian Krüger[@fabapp2]"

- title: Banner support
helper: org.springframework.sbm.boot.upgrade_27_30.report.helper.BannerSupportHelper
change: |-
Support for image-based application banners has been removed. banner.gif, banner.jpg, and banner.png
files are now ignored and should be replaced with a text-based banner.txt file.
affected: |-
The scan found banner image files here:

<#list files as file>
* ${file}
</#list>
remediation: |-
remove image banners and replace it with text-banner with banner.txt file
gitHubIssue: 150
recipe: boot-2.7-3.0-upgrade-report
contributors:
- "Sandeep Nagaraj[@sanagaraj-pivotal]"
footer: |-
We want to say thank you to all Contributors:

Generated by Spring Boot Migrator (experimental)
Generated by Spring Boot Migrator (experimental)
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ void changesToDataPropertiesSection_renders() {
==== Remediation
Either add `spring-data` dependency, rename the property or remove it in case it's not required anymore.

""", Map.of("PATH", Path
.of(".").toAbsolutePath().resolve(TestProjectContext.getDefaultProjectRoot()).toString()));
""",
Map.of("PATH", Path.of(".").toAbsolutePath().resolve(TestProjectContext.getDefaultProjectRoot()).toString()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void renderReport() throws IOException {
"""
[[index]]
= Spring Boot 3 Upgrade Report
Sandeep Nagaraj,
Fabian Krüger
:source-highlighter: highlight.js
:highlightjs-languages: java
Expand Down Expand Up @@ -76,7 +77,7 @@ void renderReport() throws IOException {
| Revision | Scanned project not under Git
| Coordinate | `com.example:dummy-root:0.1.0-SNAPSHOT`
| Boot version | `2.7.3`
| Changes | 2
| Changes | 3
|===

The application was scanned and matched against the changes listed in the
Expand Down Expand Up @@ -132,6 +133,7 @@ void renderReport() throws IOException {

Generated by Spring Boot Migrator (experimental)
""";

SpringBootUpgradeReportTestSupport.generatedReport()
.fromProjectContext(context)
.shouldRenderAs(expectedOutput, Map.of("PATH", Path.of(".").toAbsolutePath().resolve(TestProjectContext.getDefaultProjectRoot()).toString()));
Expand All @@ -141,4 +143,4 @@ Generated by Spring Boot Migrator (experimental)
Files.writeString(Path.of(".").toAbsolutePath().resolve("report.html"), context.getProjectResources().get(3).print(), StandardOpenOption.TRUNCATE_EXISTING);
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2021 - 2022 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 org.springframework.sbm.boot.upgrade_27_30.report.helper;

import org.junit.jupiter.api.Test;
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportTestSupport;
import org.springframework.sbm.engine.context.ProjectContext;
import org.springframework.sbm.project.resource.TestProjectContext;

import java.nio.file.Path;
import java.util.Map;

public class BannerSupportHelperTest {

@Test
public void rendersBannerSupportInformation() {
ProjectContext context = TestProjectContext.buildProjectContext()
.addProjectResource("src/main/resources/banner.gif", "gif-banner")
.addProjectResource("src/main/resources/banner.jpg", "jpg-banner")
.addProjectResource("src/main/com/test/banner.java","class banner {}")
.build();

SpringBootUpgradeReportTestSupport
.generatedSection("Banner support")
.fromProjectContext(context)
.shouldRenderAs(
"""
=== Banner support
Issue: https://github.com/spring-projects-experimental/spring-boot-migrator/issues/150[#150], Contributors: https://github.com/sanagaraj-pivotal[@sanagaraj-pivotal^, role="ext-link"]

==== What Changed
Support for image-based application banners has been removed. banner.gif, banner.jpg, and banner.png\s
files are now ignored and should be replaced with a text-based banner.txt file.

==== Why is the application affected
The scan found banner image files here:

* <PATH>/src/main/resources/banner.gif
* <PATH>/src/main/resources/banner.jpg

==== Remediation
remove image banners and replace it with text-banner with banner.txt file

""",
Map.of("PATH", Path.of(".").toAbsolutePath().resolve(TestProjectContext.getDefaultProjectRoot()).toString()));
}
}