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 @@ -49,6 +49,7 @@ RecipeInfo[] scan(@RequestParam("projectPath") String projectPath) {
@PostMapping("/apply")
void apply(@RequestParam("projectPath") String projectPath, @RequestParam("recipe") String recipe) {
// FIXME: ProjectContext must be cached and used here
// FIXME: Apply should not do implicit scan.
ProjectContext projectContext = scanCommand.execute(projectPath);
applyCommand.execute(projectContext, recipe);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@
import java.nio.file.Path;
import java.util.Map;

import org.junit.jupiter.api.*;
import org.springframework.sbm.service.dto.RecipeInfo;
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
Expand All @@ -46,18 +45,18 @@ public class RestApiTest {

@TempDir
File tempFolder;


@BeforeEach
void setup() throws IOException {
FileUtils.cleanDirectory(tempFolder);
}

@Test
public void scanNoParameters() throws Exception {
ResponseEntity<?> recipes = this.restTemplate.postForEntity("http://localhost:" + port + "/scan", null, Object.class);
assertThat(recipes.getStatusCode().isError()).isTrue();
}

@BeforeEach
void setup() throws IOException {
FileUtils.cleanDirectory(tempFolder);
}


@Test
public void scanProject() throws Exception {
File testProject = ProjectUtils.initTestProject(tempFolder, "bootify-jaxrs");
Expand All @@ -68,6 +67,7 @@ public void scanProject() throws Exception {
}

@Test
@Disabled("Fails somtimes in CI 'RestApiTest.applyRecipe:76 ? ResourceAccess I/O error on POST request for \"htt...' and will be replaced by Websocket API")
public void applyRecipe() throws Exception {
File testProject = ProjectUtils.initTestProject(tempFolder, "bootify-jaxrs");
Path bootAppMainClass = testProject.toPath().resolve("src/main/java/com/example/jee/app/SpringBootApp.java");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ protected static RunningNetworkedContainer startDockerContainer(NetworkedContain
.withNetwork(network)
.withNetworkMode("host")
.withNetworkAliases(networkedContainer.networkAlias)
.withStartupTimeout(Duration.of(60, ChronoUnit.SECONDS))
.withStartupTimeout(Duration.of(180, ChronoUnit.SECONDS))
.withEnv(envMap);
genericContainer.start();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

@Disabled("Temporary disabled before CI will be fixed with docker in docker issue: #351")
public class BootifyAnnotatedServletsIntegrationTest extends IntegrationTestBaseClass {
public class MigrateAnnotatedServletsIntegrationTest extends IntegrationTestBaseClass {


@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

public class BootifyJpaApplicationIntegrationTest extends IntegrationTestBaseClass {
public class MigrateJpaApplicationIntegrationTest extends IntegrationTestBaseClass {

@Override
protected String getTestSubDir() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

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

public class BootifySimpleJeeAppIntegrationTest extends IntegrationTestBaseClass {

@Disabled("Temporary disabled before CI will be fixed with docker in docker issue: #351")
public class MigrateSimpleJeeAppIntegrationTest extends IntegrationTestBaseClass {

@Override
protected String getTestSubDir() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

@TestMethodOrder(MethodOrderer.MethodName.class)
@Disabled("Temporary disabled before CI will be fixed with docker in docker issue: #351")
public class BootifySimpleMuleAppIntegrationTest extends IntegrationTestBaseClass {
public class MigrateSimpleMuleAppIntegrationTest extends IntegrationTestBaseClass {

private static final String FIRST_QUEUE_NAME = "sbm-integration-queue-one";
private static final String SECOND_QUEUE_NAME = "sbm-integration-queue-two";
Expand Down
3 changes: 0 additions & 3 deletions ci/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,7 @@ jobs:
trigger: true
- task: compile
privileged: true
# caches:
# - path: .m2/
image: ci-image
params:
file: git-repo/ci/tasks/maven-build.yml
# - in_parallel:
# fail_fast: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,13 @@ private RecipeTestSupport() {
ValidatorConfiguration.class,
YamlObjectMapperConfiguration.class,
ResourceHelperDummy.class,
ActionDeserializerRegistry.class,
MultiModuleAwareActionDeserializer.class,
DefaultActionDeserializer.class,
RewriteJavaSearchActionDeserializer.class,
RewriteRecipeLoader.class,
SbmRecipeLoader.class,
BasePackageCalculator.class,
ActionDeserializerRegistry.class
BasePackageCalculator.class
};


Expand All @@ -82,7 +85,6 @@ public static void testRecipe(Path recipeFile, Consumer<Recipes> consumer, Class
SpringBeanProvider.run(context -> {
context.start();
ActionDeserializerRegistry deserializerRegistry = context.getBean(ActionDeserializerRegistry.class);
deserializerRegistry.register(AbstractAction.class, new DefaultActionDeserializer());
ObjectMapper objectMapper = context.getBean("yamlObjectMapper", ObjectMapper.class);

deserializerRegistry.register(OpenRewriteJavaSearchAction.class, new RewriteJavaSearchActionDeserializer(objectMapper, context.getBeanFactory()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,26 +120,8 @@ public ResourceSet getTestResourceSet() {
return new ResourceSet(projectResourceSet, projectRootDir, modulePath, testResourceSet);
}

public List<ApplicationModule> getModules() {
Optional<MavenResolutionResult> mavenResolution = MavenBuildFileUtil.findMavenResolution(((OpenRewriteMavenBuildFile) buildFile).getSourceFile());
List<MavenResolutionResult> modulesMarker = mavenResolution.get().getModules();
if ( ! modulesMarker.isEmpty()) {
return modulesMarker
.stream()
.map(m -> new ApplicationModule(
m.getPom().getGav().toString(),
this.buildFile,
projectRootDir,
modulePath,
projectResourceSet,
javaRefactoringFactory,
basePackageCalculator,
javaParser
))
.collect(Collectors.toList());
} else {
return new ArrayList<>();
}
public List<String> getDeclaredModules() {
return buildFile.getDeclaredModules();
}

public <T> T search(ProjectResourceFinder<T> finder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,17 @@ public List<ApplicationModule> list() {
return stream().collect(Collectors.toUnmodifiableList());
}

public ApplicationModule getModule(Path name) {
public ApplicationModule getModule(Path modulePath) {
return modules.stream()
.filter(m -> m.getModulePath().equals(name))
.filter(m -> m.getModulePath().equals(modulePath))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Could not find module with name '" + name + "'"));
.orElseThrow(() -> new IllegalArgumentException("Could not find module with modulePath '" + modulePath + "'"));
}

public ApplicationModule getModule(String name) {
return getModule(Path.of(name));
public Optional<ApplicationModule> findModule(String coordinate) {
return modules.stream()
.filter(m -> m.getBuildFile().getCoordinates().equals(coordinate))
.findFirst();
}

public List<ApplicationModule> getModules(ApplicationModule module) {
Expand All @@ -85,6 +87,11 @@ private List<ApplicationModule> filterModulesContainingMavens(List<MavenResoluti
.collect(Collectors.toList());
}

/**
* Returns the list of application modules.
*
* An application module is a module that no other module depends on and which has a parent with packaging of type pom.
*/
public List<ApplicationModule> getTopmostApplicationModules() {
List<ApplicationModule> topmostModules = new ArrayList<>();
modules.forEach(module -> {
Expand All @@ -107,6 +114,21 @@ public List<ApplicationModule> getTopmostApplicationModules() {
return topmostModules;
}

/**
* Returns the list of component modules.
*
* A component module is a module that another module depends on and that thus will be part of another application module.
*/
public List<ApplicationModule> getComponentModules() {
return modules.stream()
.filter(this::isDependencyOfAnotherModule)
.collect(Collectors.toList());
}

private boolean isDependencyOfAnotherModule(ApplicationModule applicationModule) {
return ! noOtherPomDependsOn(applicationModule.getBuildFile());
}

private boolean isPackagingOfPom(ParentDeclaration parentPomDeclaration) {
Optional<ApplicationModule> applicationModule = this.modules.stream()
.filter(module -> module.getBuildFile().getCoordinates().equals(parentPomDeclaration.getCoordinates()))
Expand All @@ -125,7 +147,7 @@ private boolean isDeclaredInProject(ParentDeclaration parentPomDeclaration) {

private boolean noOtherPomDependsOn(BuildFile buildFile) {
return !this.modules.stream()
.anyMatch(module -> module.getBuildFile().getDeclaredDependencies().stream().anyMatch(d -> d.getCoordinates().equals(buildFile.getCoordinates())));
.anyMatch(module -> module.getBuildFile().getRequestedDependencies().stream().anyMatch(d -> d.getCoordinates().equals(buildFile.getCoordinates())));
}

public boolean isSingleModuleApplication() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,20 @@

public interface BuildFile extends ProjectResource {

/**
* Returns the dependencies as declared in build file.
*
* E.g. a dependency that has no version set will have a version of null.
*/
List<Dependency> getDeclaredDependencies(Scope... scopes);

/**
* Returns the declared dependencies with resolved attributes.
*
* E.g. a dependency that has no version set will have its version resolved.
*/
List<Dependency> getRequestedDependencies();

/**
* Returns any available dependency (declared or transitive) with given scope.
*/
Expand Down Expand Up @@ -135,8 +147,8 @@ public interface BuildFile extends ProjectResource {
Optional<ParentDeclaration> getParentPomDeclaration();

Optional<String> getName();
// TODO: add same method to ApplicationModules to add excludes to all relevant dependencies in all BuildFiles

// TODO: add same method to ApplicationModules to add excludes to all relevant dependencies in all BuildFiles
/**
* Adds an exclusion for each of the dependencies in {@code excludedDependencies} to all declared dependencies in this {@code BuildFile} which transitively depend on it.
*/
Expand All @@ -147,5 +159,8 @@ public interface BuildFile extends ProjectResource {
void addPluginRepository(RepositoryDefinition repository);

List<RepositoryDefinition> getRepositories();

List<RepositoryDefinition> getPluginRepositories();

List<String> getDeclaredModules();
}
Loading