Skip to content

Commit 5d58827

Browse files
committed
Add some documentation
1 parent 9d0e92e commit 5d58827

File tree

3 files changed

+75
-2
lines changed

3 files changed

+75
-2
lines changed

docs/reference/concepts.adoc

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ With the `ProjectContext` in place SBM checks all ``Condition``s of recipes and
107107
The resulting list of applicable recipes is then shown to the user to select and apply recipes against the scanned application.
108108

109109
==== Apply Recipe
110-
The user applies a recipe of the list of applicable recipes.
110+
The user applies a recipe from the list of applicable recipes.
111111

112112
===== Applying Recipe Actions
113113
SBM provides the `ProjectContext` to the list of applicable ``Action``s and each `Action` modifies the AST through the
114114
`ProjectContext` API. These modifications are only represented in memory.
115115

116116
===== Verify Application In Sync
117-
After applying all ``Action``s of the `Recipe` he changes need to be written back to filesystem.
117+
After applying all ``Action``s of the `Recipe` the changes need to be written back to filesystem.
118118
When `sbm.gitSupportEnabled` is `true` SBM verifies that nothing changed in the scanned project while the recipe was applied.
119119
If the git hash changed or non-indexed resources are found the changes are rolled back, the project must be synced,
120120
re-scanned and the recipe needs to be re-applied.

docs/reference/getting-started.adoc

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
NOTE: *`M2_HOME` env must be set* to run integration tests! +
1313
*Docker must be installed* to run (some) integration tests!
14+
To build SBM ignoring integration tests you can run `mvn clean install -DskipITs`
1415

1516
[source,shell]
1617
....

docs/reference/howto.adoc

+72
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,82 @@ A recipe can be defined as Spring bean using @Bean annotated method, see link:{r
9292
NOTE: Remember to provide a description to all Actions to display the description to the user when the Action is applied.
9393

9494
=== Create a Condition
95+
Every `Action` and every `Recipe` must have a `Condition` which defines if the `Recipe` or `Action` is applicable.
96+
Therefore the `Condition` interface must be implemented which defines a `evaluate(ProjectContext)` method which must return true if the Recipe or Action is applicable and false otherwise.
97+
A condition should only read from the `ProjectContext` and never modify the AST.
98+
99+
[source, java]
100+
....
101+
public class MyCondition implements Condition {
102+
@Override
103+
public boolean evaluate(ProjectContext context) {
104+
// analyze ProjectContext to evaluate condition
105+
}
106+
}
107+
....
108+
109+
=== Single and Multi module projects
110+
Projects can come as single module or multi-module project.
111+
Working with single module projects is significantly easier because only one `BuildFile` exists.
112+
With multi-module projects the application modules play a central role and there must be means to
113+
select a module.
114+
115+
==== Application Modules
116+
A common multi-module project has a root modules which consists of one or more child modules which again can consist of multiple child modules and so on.
117+
118+
* The root module
119+
* The application module(s), bundle all modules of an application and define the composition of deployable artifact buulding a runnable application, e.g. a war module
120+
* The component module(s), define reusable components which are not deployable in isolation
121+
122+
[source, java]
123+
....
124+
public void apply(ProjectContext context) {
125+
// Retrieve ApplicationModules
126+
// TODO: Maybe ProjectModules ?
127+
Modules modules = context.getModules();
128+
129+
// TODO: is this sufficient --> must all child modules share same groupId?
130+
Module module = modules.getModule("module-artifact-id");
131+
132+
boolean isMultiModule = modules.isMultiModuleProject();
133+
Module root = modules.getRootModule(); // type="pom" or type="ear"
134+
modules.getApplicationModules(); // type="war", containing "main" method
135+
modules.getComponentModules(); // type="jar" without main method
136+
137+
List<Module> parentModules = module.getParentModules();
138+
List<Module> subModules = module.getSubModules();
139+
}
140+
....
141+
95142

96143
=== BuildFile and Dependencies
144+
The buildfiles of the scanned project are represented by `BuildFile`.
145+
The `BuildFile` API offers methods to read and modify the buildfile.
146+
``BuildFile``s can be retrieved through the `ProjectContext`.
147+
148+
[source, java]
149+
....
150+
// Retrieve the root build file
151+
BuildFile rootBuildFile = projectContext.getBuildFile();
152+
153+
....
154+
97155

98156
==== Adding a Dependency
157+
[source, java]
158+
....
159+
public void apply(ProjectContext context) {
160+
// ...get buildFile for module
161+
BuildFile buildFile = context...
162+
Dependency dependency = Dependency.builder()
163+
.groupId("...")
164+
.artifactId("...")
165+
.version("...")
166+
.scope("test")
167+
.build();
168+
buildFile.addDependency(dependency);
169+
}
170+
....
99171

100172
==== Removing a Dependency
101173

0 commit comments

Comments
 (0)