Skip to content

#329 compilable Boot Integration output #333

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 17 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from 16 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 @@ -45,8 +45,8 @@ void migrateSimpleApplication() {

applyRecipe("boot-2.7-3.0-dependency-version-update");

buildProject();
verifyParentPomVersion();
verifyMicrometerPackageUpdate();
verifyYamlConfigurationUpdate();
verifyPropertyConfigurationUpdate();
verifyConstructorBindingRemoval();
Expand All @@ -55,6 +55,10 @@ void migrateSimpleApplication() {
verifyEhCacheVersionIsUpgraded();
}

private void buildProject() {
executeMavenGoals(getTestDir(), "clean", "verify");
}

private void verifyEhCacheVersionIsUpgraded() {
String pomContent = loadFile(Path.of("pom.xml"));

Expand Down Expand Up @@ -143,19 +147,6 @@ private void verifyConstructorBindingRemoval() {
"\n");
}

private void verifyMicrometerPackageUpdate() {
String micrometerClass = loadFile(Path.of("src/main/java/org/springboot/example/upgrade/MicrometerConfig.java"));
assertThat(micrometerClass).isEqualTo(
"package org.springboot.example.upgrade;\n" +
"\n" +
"import io.micrometer.binder.MeterBinder;\n" +
"\n" +
"public class MicroMeterConfig {\n" +
"\n" +
" private MeterBinder k;\n" +
"}\n");
}

private void verifyYamlConfigurationUpdate() {
String micrometerClass = loadFile(Path.of("src/main/resources/application.yaml"));
assertThat(micrometerClass).isEqualTo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
Expand Down Expand Up @@ -85,7 +81,12 @@
</snapshots>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>spring-milestone</id>
<url>https://repo.spring.io/milestone</url>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,8 @@ public interface BuildFile extends ProjectResource {

void addRepository(RepositoryDefinition repository);

void addPluginRepository(RepositoryDefinition repository);

List<RepositoryDefinition> getRepositories();
List<RepositoryDefinition> getPluginRepositories();
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* 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.build.migration.actions;

import lombok.Setter;
import org.springframework.sbm.build.api.RepositoryDefinition;
import org.springframework.sbm.engine.context.ProjectContext;
import org.springframework.sbm.engine.recipe.AbstractAction;

/**
* Adds Repository to pom.xml
*/
@Setter
public abstract class AddGenericRepositoryAction extends AbstractAction {

private String id;
private String url;
private String name;
private String layout;
private Boolean snapshotsEnabled;
private String snapshotsChecksumPolicy;
private String snapShotsUpdatePolicy;
private Boolean releasesEnabled;
private String releasesChecksumPolicy;
private String releasesUpdatePolicy;

protected abstract void addRepository(ProjectContext context, RepositoryDefinition repositoryDefinition);

@Override
public void apply(ProjectContext context) {
RepositoryDefinition.RepositoryDefinitionBuilder builder = RepositoryDefinition.builder();

builder.id(id)
.name(name)
.url(url);

if (snapshotsEnabled != null) {
builder.snapshotsEnabled(snapshotsEnabled);
}
if (snapShotsUpdatePolicy != null) {
builder.snapShotsUpdatePolicy(snapShotsUpdatePolicy);
}
if (snapshotsChecksumPolicy != null) {
builder.snapshotsChecksumPolicy(snapshotsChecksumPolicy);
}

if (releasesEnabled != null) {
builder.releasesEnabled(releasesEnabled);
}
if (releasesUpdatePolicy != null) {
builder.releasesUpdatePolicy(releasesUpdatePolicy);
}
if (releasesChecksumPolicy != null) {
builder.releasesChecksumPolicy(releasesChecksumPolicy);
}
if (layout != null) {
builder.layout(layout);
}

RepositoryDefinition repository = builder.build();
addRepository(context, repository);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.build.migration.actions;

import lombok.Setter;
import org.springframework.sbm.build.api.RepositoryDefinition;
import org.springframework.sbm.engine.context.ProjectContext;
import org.springframework.sbm.engine.recipe.AbstractAction;

@Setter
public class AddPluginRepositoryAction extends AddGenericRepositoryAction {

@Override
protected void addRepository(ProjectContext context, RepositoryDefinition repositoryDefinition) {
context.getApplicationModules().getRootModule().getBuildFile().addPluginRepository(repositoryDefinition);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,52 +24,9 @@
* Adds Repository to pom.xml
*/
@Setter
public class AddRepositoryAction extends AbstractAction {

private String id;
private String url;
private String name;
private String layout;
private Boolean snapshotsEnabled;
private String snapshotsChecksumPolicy;
private String snapShotsUpdatePolicy;
private Boolean releasesEnabled;
private String releasesChecksumPolicy;
private String releasesUpdatePolicy;


public class AddRepositoryAction extends AddGenericRepositoryAction {
@Override
public void apply(ProjectContext context) {
RepositoryDefinition.RepositoryDefinitionBuilder builder = RepositoryDefinition.builder();

builder.id(id)
.name(name)
.url(url);

if (snapshotsEnabled != null) {
builder.snapshotsEnabled(snapshotsEnabled);
}
if (snapShotsUpdatePolicy != null) {
builder.snapShotsUpdatePolicy(snapShotsUpdatePolicy);
}
if (snapshotsChecksumPolicy != null) {
builder.snapshotsChecksumPolicy(snapshotsChecksumPolicy);
}

if (releasesEnabled != null) {
builder.releasesEnabled(releasesEnabled);
}
if (releasesUpdatePolicy != null) {
builder.releasesUpdatePolicy(releasesUpdatePolicy);
}
if (releasesChecksumPolicy != null) {
builder.releasesChecksumPolicy(releasesChecksumPolicy);
}
if (layout != null) {
builder.layout(layout);
}

RepositoryDefinition repository = builder.build();
context.getApplicationModules().getRootModule().getBuildFile().addRepository(repository);
protected void addRepository(ProjectContext context, RepositoryDefinition repositoryDefinition) {
context.getApplicationModules().getRootModule().getBuildFile().addRepository(repositoryDefinition);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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.build.migration.conditions;

import lombok.Setter;
import org.springframework.sbm.build.api.RepositoryDefinition;
import org.springframework.sbm.engine.context.ProjectContext;
import org.springframework.sbm.engine.recipe.Condition;

@Setter
public class NoPluginRepositoryExistsCondition implements Condition {
private String url;

@Override
public String getDescription() {
return "Check that no Plugin Repository definition with same id or url exists";
}

@Override
public boolean evaluate(ProjectContext context) {
// if name is set and repo

return !context.getBuildFile()
.getPluginRepositories().stream()
.anyMatch(this::urlsAreEqual);
}

private boolean urlsAreEqual(RepositoryDefinition r) {
return r.getUrl() != null && r.getUrl().equals(url);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,8 @@

@Setter
public class NoRepositoryExistsCondition implements Condition {

private String id;
private String url;

private Boolean snapshotsEnabled = true;

private Boolean releasesEnabled = true;

@Override
public String getDescription() {
return "Check that no Repository definition with same id or url exists";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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.build.migration.actions;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.sbm.engine.context.ProjectContext;
import org.springframework.sbm.project.resource.TestProjectContext;

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

public class AddPluginRepositoryActionTest {

String pomWithoutRepositories =
"""
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>some.group.id</groupId>
<artifactId>with-artifact</artifactId>
<packaging>jar</packaging>
<version>100.23.01-SNAPSHOT</version>
</project>
""";

@Test
void shouldAddPluginRepositoryWhenThereIsNoPluginRepository() {

ProjectContext context = TestProjectContext.buildProjectContext()
.withMavenRootBuildFileSource(pomWithoutRepositories)
.build();

AddPluginRepositoryAction sut = new AddPluginRepositoryAction();
sut.setId("repo-id");
sut.setName("thename");
sut.setUrl("https://some.url");
sut.apply(context);

assertThat(context.getBuildFile().print()).isEqualTo(
"""
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>some.group.id</groupId>
<artifactId>with-artifact</artifactId>
<packaging>jar</packaging>
<version>100.23.01-SNAPSHOT</version>
<pluginRepositories>
<pluginRepository>
<id>repo-id</id>
<name>thename</name>
<url>https://some.url</url>
</pluginRepository>
</pluginRepositories>
</project>
"""
);
}
}
Loading