Skip to content

3.0.0-M3 Support for Apache Solr Removed #371

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

Merged
merged 9 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
@@ -0,0 +1,60 @@
/*
* 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.springframework.sbm.java.api.JavaSourceAndType;
import org.springframework.sbm.java.api.Type;
import org.springframework.sbm.java.impl.OpenRewriteJavaSource;
import org.springframework.sbm.java.impl.OpenRewriteType;
import org.springframework.sbm.project.resource.ProjectResourceSet;
import org.springframework.sbm.project.resource.filter.ProjectResourceFinder;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@Component
public class ApacheSolrRepositoryBeanFinder implements ProjectResourceFinder<List<JavaSourceAndType>> {
private static final String SOLR_REPOSITORY_CLASS = "org.springframework.data.solr.repository.SolrCrudRepository";

@Override
public List<JavaSourceAndType> apply(ProjectResourceSet projectResourceSet) {
return projectResourceSet.stream()
.filter(OpenRewriteJavaSource.class::isInstance)
.map(OpenRewriteJavaSource.class::cast)
.filter(js -> js.getTypes().stream().anyMatch(this::isSolrRepository))
.map(js -> {
Optional<OpenRewriteType> type = js.getTypes().stream()
.filter(this::isSolrRepository)
.findFirst();
if(type.isPresent()) {
return new JavaSourceAndType(js, type.get());
} else {
return null;
}
})
.collect(Collectors.toList());
}

private boolean isSolrRepository(OpenRewriteType t) {
return t.getExtends()
.map(Type::getFullyQualifiedName)
.filter(SOLR_REPOSITORY_CLASS::equals)
.isPresent();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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 lombok.RequiredArgsConstructor;
import org.springframework.sbm.boot.asciidoctor.ChangeSection;
import org.springframework.sbm.boot.asciidoctor.Section;
import org.springframework.sbm.boot.asciidoctor.TodoList;
import org.springframework.sbm.boot.upgrade_27_30.Sbu30_UpgradeSectionBuilder;
import org.springframework.sbm.engine.context.ProjectContext;
import org.springframework.sbm.java.api.JavaSourceAndType;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@RequiredArgsConstructor
public class ApacheSolrRepositorySectionBuilder implements Sbu30_UpgradeSectionBuilder {

private final ApacheSolrRepositoryBeanFinder finder;

@Override
public boolean isApplicable(ProjectContext projectContext) {
return ! projectContext.search(finder).isEmpty();
}

@Override
public Section build(ProjectContext projectContext) {
List<JavaSourceAndType> solrRepositories = projectContext.search(finder);

return ChangeSection.RelevantChangeSection.builder()
.title("`Spring Data ApacheSolr` support has been removed")
.paragraph("Support for `Spring Data ApacheSolr` has been removed in Spring Framework 6")
.relevanceSection()
.paragraph("The scan found bean declarations of type `SolrCrudRepository`.")
.todoSection()
.paragraph("Remove repositories of type `SolrCrudRepository`")
.todoList(this.buildTodoList(solrRepositories))
.build();
}

private TodoList buildTodoList(List<JavaSourceAndType> solrRepositories) {
TodoList.TodoListBuilder todoListBuilder = TodoList.builder();
solrRepositories.forEach(m -> {
todoListBuilder.todo(
TodoList.Todo.builder()
.text(String.format("Remove from class `%s`", m.getType().getFullyQualifiedName()))
.build()
);
});
return todoListBuilder.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.springframework.sbm.boot.upgrade_27_30.checks;


import org.intellij.lang.annotations.Language;
import org.junit.jupiter.api.Test;
import org.springframework.sbm.engine.context.ProjectContext;
import org.springframework.sbm.java.api.JavaSourceAndType;
import org.springframework.sbm.java.api.Type;
import org.springframework.sbm.project.resource.TestProjectContext;

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

import static org.assertj.core.api.Assertions.assertThat;

public class ApacheSolrRepositoryBeanFinderTest {

@Language("java")
private static String SOLR_REPO =
"""
package foo.bar;
import org.springframework.data.solr.repository.SolrCrudRepository;
public class ProductRepository extends SolrCrudRepository<Product, String> {}
""";

@Test
public void givenModuleWithSolrRepository_find_expectNonEmptyList(){
ProjectContext projectContext = TestProjectContext.buildProjectContext()
.withJavaSources(SOLR_REPO)
.build();

ApacheSolrRepositoryBeanFinder solrRepositoryBeanFinder = new ApacheSolrRepositoryBeanFinder();
List<JavaSourceAndType> solrRepositories = projectContext.search(solrRepositoryBeanFinder);
assertThat(solrRepositories).isNotEmpty();
Type type = solrRepositories.get(0).getType();
assertThat(type.getFullyQualifiedName()).isEqualTo("foo.bar.ProductRepository");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* 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.engine.context.ProjectContext;
import org.springframework.sbm.java.api.JavaSource;
import org.springframework.sbm.java.api.JavaSourceAndType;
import org.springframework.sbm.java.api.Type;

import java.util.List;

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

class ApacheSolrRepositorySectionBuilderTest {

@Test
void givenAContextWithSolrRepository_applySectionBuilder_validateReport() {
ApacheSolrRepositoryBeanFinder finder = mock(ApacheSolrRepositoryBeanFinder.class);

Type type = mock(Type.class);
Type type1 = mock(Type.class);
JavaSource javaSource = mock(JavaSource.class);
JavaSource javaSource1 = mock(JavaSource.class);
JavaSourceAndType javaSourceAndType = new JavaSourceAndType(javaSource,type);
JavaSourceAndType javaSourceAndType1 = new JavaSourceAndType(javaSource1,type1);

ProjectContext context = mock(ProjectContext.class);
ApacheSolrRepositorySectionBuilder sut = new ApacheSolrRepositorySectionBuilder(finder);
List<JavaSourceAndType> matches = List.of(
javaSourceAndType,
javaSourceAndType1
);

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

Section section = sut.build(context);

String rendered = SectionRendererTestUtil.render(section);
assertThat(rendered).isEqualTo(
"""
=== `Spring Data ApacheSolr` support has been removed
Support for `Spring Data ApacheSolr` has been removed in Spring Framework 6

==== Relevance

The scan found bean declarations of type `SolrCrudRepository`.

==== Todo

Remove repositories of type `SolrCrudRepository`


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

}