Skip to content

Commit 03cc93b

Browse files
committed
WIP: Add MultiModuleAwareAction for actions dealing with multi-module projects
1 parent 710c225 commit 03cc93b

File tree

11 files changed

+173
-5
lines changed

11 files changed

+173
-5
lines changed

components/sbm-core/src/main/java/org/springframework/sbm/build/migration/actions/AddDependencies.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.springframework.sbm.build.migration.actions;
1717

18-
import org.springframework.sbm.build.api.BuildFile;
1918
import org.springframework.sbm.build.api.Dependency;
2019
import org.springframework.sbm.engine.recipe.AbstractAction;
2120
import org.springframework.sbm.engine.context.ProjectContext;
@@ -39,7 +38,7 @@ public class AddDependencies extends AbstractAction {
3938

4039
@Override
4140
public void apply(ProjectContext context) {
42-
BuildFile buildFile = context.getBuildFile();
43-
buildFile.addDependencies(dependencies);
41+
dependencies.forEach(d -> context.getBuildFile().addDependency(d));
4442
}
43+
4544
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2021 - 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.sbm.build.migration.actions;
18+
19+
import org.springframework.sbm.build.api.ApplicationModules;
20+
import org.springframework.sbm.build.api.Dependency;
21+
import org.springframework.sbm.engine.context.ProjectContext;
22+
23+
public interface AddDependenciesMultiModuleHandler {
24+
void handle(ProjectContext context, Dependency d);
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2021 - 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.sbm.build.migration.actions;
18+
19+
import org.springframework.sbm.build.api.Dependency;
20+
import org.springframework.sbm.engine.context.ProjectContext;
21+
22+
public class AddDependenciesToApplicationModules implements AddDependenciesMultiModuleHandler {
23+
@Override
24+
public void handle(ProjectContext context, Dependency d) {
25+
if(!context.getApplicationModules().isSingleModuleApplication()) {
26+
context.getApplicationModules().getTopmostApplicationModules().forEach(m -> m.getBuildFile().addDependency(d));
27+
}
28+
}
29+
}

components/sbm-core/src/main/java/org/springframework/sbm/build/migration/actions/AddMavenPlugin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
import org.springframework.sbm.engine.context.ProjectContext;
2121
import lombok.Getter;
2222
import lombok.Setter;
23+
import org.springframework.sbm.engine.recipe.MultiModuleAwareAction;
2324

2425
import javax.validation.Valid;
2526

2627
@Getter
27-
public class AddMavenPlugin extends AbstractAction {
28+
public class AddMavenPlugin extends MultiModuleAwareAction {
2829

2930
@Setter
3031
@Valid
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2021 - 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.sbm.build.migration.actions;
18+
19+
public class AddMavenPluginToApplicationModules implements AddMavenPluginToMultiModuleHandler {
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2021 - 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.sbm.build.migration.actions;
18+
19+
public interface AddMavenPluginToMultiModuleHandler {
20+
}

components/sbm-core/src/main/java/org/springframework/sbm/engine/recipe/AbstractAction.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import lombok.experimental.SuperBuilder;
2424
import org.springframework.beans.factory.annotation.Autowired;
2525
import org.springframework.context.ApplicationEventPublisher;
26+
import org.springframework.sbm.engine.context.ProjectContext;
2627

2728
import javax.validation.constraints.NotBlank;
2829

@@ -52,6 +53,11 @@ public String getDetailedDescription() {
5253
return conditionDescription + getDescription();
5354
}
5455

56+
@Override
57+
public void applyInternal(ProjectContext context) {
58+
apply(context);
59+
}
60+
5561
@Override
5662
public boolean isAutomated() {
5763
return !this.getClass().isAssignableFrom(DisplayDescription.class);

components/sbm-core/src/main/java/org/springframework/sbm/engine/recipe/Action.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ default void applyWithStatusEvent(ProjectContext context) {
3434
eventPublisher.publishEvent(new ActionStartedEvent(getDescription()));
3535
}
3636
try {
37-
apply(context);
37+
applyInternal(context);
3838
} catch(Exception e) {
3939
throw new ActionFailedException("'"+this.getDescription()+"' failed: " + e.getMessage(), e);
4040
}
@@ -43,6 +43,8 @@ default void applyWithStatusEvent(ProjectContext context) {
4343
}
4444
}
4545

46+
void applyInternal(ProjectContext context);
47+
4648
ApplicationEventPublisher getEventPublisher();
4749

4850
boolean isAutomated();
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2021 - 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.sbm.engine.recipe;
18+
19+
import lombok.Setter;
20+
import org.springframework.beans.factory.annotation.Autowired;
21+
import org.springframework.sbm.build.api.ApplicationModule;
22+
import org.springframework.sbm.build.migration.actions.AddDependenciesToApplicationModules;
23+
import org.springframework.sbm.engine.context.ProjectContext;
24+
25+
public abstract class MultiModuleAwareAction extends AbstractAction {
26+
27+
@Autowired
28+
@Setter
29+
private MultiModuleHandler multiModuleHandler;
30+
31+
@Override
32+
public void applyInternal(ProjectContext context) {
33+
if (context.getApplicationModules().isSingleModuleApplication()) {
34+
apply(context);
35+
} else {
36+
multiModuleHandler.handle(context);
37+
}
38+
}
39+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2021 - 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.sbm.engine.recipe;
18+
19+
import org.springframework.sbm.engine.context.ProjectContext;
20+
21+
public interface MultiModuleHandler {
22+
void handle(ProjectContext context);
23+
}

components/sbm-support-boot/src/main/resources/recipes/initialize-spring-boot-migration.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
artifactId: spring-boot-starter-test
5454
version: 2.6.3
5555
scope: test
56+
multiModuleHandler:
57+
type: org.springframework.sbm.build.migration.actions.AddDependenciesToApplicationModules
5658
description: Add spring dependencies 'spring-boot-starter' and 'spring-boot-starter-test'.
5759
detailedDescription: |-
5860
This code snippet is going to be added to the <dependencies> section in pom.xml
@@ -92,6 +94,8 @@
9294
plugin:
9395
groupId: org.springframework.boot
9496
artifactId: spring-boot-maven-plugin
97+
multiModuleHandler:
98+
type: org.springframework.sbm.build.migration.actions.AddMavenPluginToApplicationModules
9599
description: Add Spring Boot Maven plugin.
96100
detailedDescription: |
97101

0 commit comments

Comments
 (0)