Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,37 @@ public boolean isApplicable(ProjectContext projectContext) {
@Override
public Section build(ProjectContext projectContext) {
List<MatchingMethod> matchingMethods = finder.findMatches(projectContext);



return ChangeSection.RelevantChangeSection.builder()
.title("`CommonsMultipartResolver` support has been removed")
.paragraph("Support for Spring Framework’s `CommonsMultipartResolver` has been removed following its removal in Spring Framework 6")
.relevanceSection()
.paragraph("The scan found bean declarations of type `CommonsMultipartResolver`")
.paragraph("The scan found bean declarations of type `CommonsMultipartResolver`.")
.todoSection()
.todoList(
TodoList.builder()
.todo(
TodoList.Todo.builder()
.text("Remove beans of type `CommonsMultipartResolver` and rely on Spring Boot auto-configuration")
.build()
)
.paragraph("Remove beans of type `CommonsMultipartResolver` and rely on Spring Boot auto-configuration")
.todoList(this.buildTodoList(matchingMethods))
.build();
}

private TodoList buildTodoList(List<MatchingMethod> matchingMethods) {
TodoList.TodoListBuilder todoListBuilder = TodoList.builder();
matchingMethods.forEach(m -> {
todoListBuilder.todo(
TodoList.Todo.builder()
.text(String.format("Remove from class `%s`", m.getType().getFullyQualifiedName()))
.build()
);
});
return todoListBuilder.build();
}

private TodoList createTodo(String s) {
return TodoList.builder()
.todo(
TodoList.Todo.builder()
.text(String.format("Remove from class `%s`", s))
.build()
)
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<#import "todo.ftl" as todo>
<#import "relevance.ftl" as relevance>
<#import "paragraph.ftl" as p/>
<#--<#macro section sections>-->
<#if sections?has_content>
<#list sections as changeSection>
=== ${changeSection.title}
<@p.paragraph changeSection.paragraphs/>
<#if changeSection.relevanceSection?has_content>
<@relevance.relevance changeSection.relevanceSection/>
</#if>
<#if changeSection.todoSection?has_content>
<@todo.todos changeSection.todoSection/>
</#if>
</#list>
<#else>
No Changes found.
</#if>
<#--</#macro>-->
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,5 @@ apply boot-2.4-2.5-upgrade-report

== Relevant Changes

<#if changeSections?has_content>
<#list changeSections as changeSection>
=== ${changeSection.title}
<@p.paragraph changeSection.paragraphs/>
<#if changeSection.relevanceSection?has_content>
<@relevance.relevance changeSection.relevanceSection/>
</#if>
<#if changeSection.todoSection?has_content>
<@todo.todos changeSection.todoSection/>
</#if>


</#list>
<#else>
No Changes found.
</#if>
<#-- Bad practice? How to import another rendered template? -->
<#include "section.ftl"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* 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.checks;

import org.junit.jupiter.api.Test;
import org.springframework.sbm.boot.asciidoctor.Section;
import org.springframework.sbm.boot.common.finder.MatchingMethod;
import org.springframework.sbm.engine.context.ProjectContext;
import org.springframework.sbm.java.api.Type;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.matches;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

class CommonsMultipartResolverSectionBuilderTest {

@Test
void test_renameMe() {
CommonsMultipartResolverBeanFinder finder = mock(CommonsMultipartResolverBeanFinder.class);

Type type = mock(Type.class);
Type type2 = mock(Type.class);

ProjectContext context = mock(ProjectContext.class);
CommonsMultipartResolverSectionBuilder sut = new CommonsMultipartResolverSectionBuilder(finder);
List<MatchingMethod> matches = List.of(
new MatchingMethod(null, type, null),
new MatchingMethod(null, type2, null)
);

when(finder.findMatches(context)).thenReturn(matches);
when(type.getFullyQualifiedName()).thenReturn("com.foo.bar.SomeClass");
when(type2.getFullyQualifiedName()).thenReturn("com.foo.baz.AnotherClass");

Section section = sut.build(context);

String rendered = SectionRendererTestUtil.render(section);
assertThat(rendered).isEqualTo(
"""
=== `CommonsMultipartResolver` support has been removed
Support for Spring Framework’s `CommonsMultipartResolver` has been removed following its removal in Spring Framework 6

==== Relevance

The scan found bean declarations of type `CommonsMultipartResolver`.

==== Todo

Remove beans of type `CommonsMultipartResolver` and rely on Spring Boot auto-configuration


* [ ] Remove from class `com.foo.bar.SomeClass`
* [ ] Remove from class `com.foo.baz.AnotherClass`
"""
);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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.checks;

import freemarker.cache.FileTemplateLoader;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.Version;
import org.springframework.sbm.boot.asciidoctor.Section;

import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SectionRendererTestUtil {
public static String render(Section section) {
Version version = new Version("2.3.0");
Configuration configuration = new Configuration(version);
try {
configuration.setTemplateLoader(new FileTemplateLoader(new File("./src/main/resources/templates")));
Map<String, Object> params = new HashMap<>();
params.put("sections", List.of(section));
// params.put("className", className);

StringWriter writer = new StringWriter();
try {
Template template = configuration.getTemplate("section.ftl");
template.process(params, writer);
String output = writer.toString();
return output;
} catch (Exception e) {
throw new RuntimeException(e);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}