Skip to content

Commit 82f428d

Browse files
committed
Add config builder
1 parent 1e4cdfc commit 82f428d

52 files changed

Lines changed: 1888 additions & 358 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,11 @@ include:
5050
Techsenger Alpha is a framework designed to work with module layers. The framework resides in the boot layer and handles
5151
all the work of managing the other layers. To facilitate this, the concept of a component is introduced.
5252

53-
A component is a logical part of the system that can be dynamically added or removed. Each component is deployed in
54-
a separate module layer and has a clearly defined lifecycle. The configuration of a component is specified via an XML
55-
file (with plans to add a ConfigBuilder), which describes the component's modules (groupId, artifactId, version),
56-
module directives (opens, reads, exports, etc.), repositories from which modules can be loaded, and other information.
57-
For flexibility, the XML configuration supports properties, the `if` and `choose-when` constructs and EL
58-
(Expression Language).
53+
A component is a logical part of the system that can be dynamically added or removed. Each component is deployed in a
54+
separate module layer and has a clearly defined lifecycle. The configuration of a component is specified via a `Builder`
55+
or an XML, which describes the component's modules (groupId, artifactId, version), module directives
56+
(opens, reads, exports, etc.), repositories from which modules can be loaded, and other related information.
57+
For flexibility, the XML configuration supports properties, if and choose-when constructs, and EL (Expression Language).
5958

6059
All loaded modules are stored in the framework's internal repository, which is by default a Maven repository.
6160

@@ -277,21 +276,48 @@ configuration. During deactivation, they are called in reverse order (the last a
277276

278277
#### Configuration <a name="usage-component-config"></a>
279278

280-
At the moment, the configuration is set using an XML file. In the future, `ConfigBuilder` is planned to be added.
279+
The configuration can be set using a `Builder` or an XML.
280+
281+
```java
282+
var config = ComponentConfig.builder()
283+
.title("The Best Foo")
284+
.name("foo")
285+
.version(Version.of("1.0.0"))
286+
.metadata("License", "Apache 2")
287+
.repositories(
288+
r -> r.name("local").url("file://...."),
289+
r -> r.name("central").url("https://repo1.maven.org/maven2/")
290+
)
291+
.parents(
292+
p -> p.name(...).version(...).versionMatch(VersionMatch.MAJOR)
293+
)
294+
.modules(
295+
m -> m.groupId(...).artifactId(....).version(...).classifier(fxClsfr).active(...)
296+
.directives(
297+
d -> d.type(...).pkg(...).layer(...).module(...)
298+
)
299+
)
300+
.build();
301+
```
281302

282-
A configuration template with all supported tags:
303+
A XML configuration template with all supported tags:
283304

284-
```
305+
```xml
285306
<?xml version="1.0" encoding="UTF-8" ?>
286307
<Configuration title="The Best Foo" name="foo" version="1.0.0" type="notBar">
287308
<Metadata>
288309
<Entry key="License" value="Apache 2"/>
289310
</Metadata>
290311

291312
<Repositories>
313+
<Repository name="local" url="file://...."/>
292314
<Repository name="central" url="https://repo1.maven.org/maven2/"/>
293315
</Repositories>
294316

317+
<Parents>
318+
<Parent name="... " version="..." versionMatch="major/minor/patch"/>
319+
</Parents>
320+
295321
<Choose>
296322
<When test="${info['os.family'] == 'linux'}">
297323
<Property name="modVersion" value="2.0.0"/>

alpha-assembly/alpha-assembly-maven-plugin/src/main/resources/com/techsenger/alpha/assembly/maven/plugin/cli-config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
2-
<Configuration title="Alpha CLI" name="alpha-cli" version="${project.version}" type="base">
2+
<Configuration title="Alpha CLI" name="alpha-cli" version="${project.version}">
33
<Repositories>
44
<Repository name="local" url="file://${settings.localRepository}"/>
55
<Repository name="central" url="${maven.central.url}"/>

alpha-assembly/alpha-assembly-maven-plugin/src/main/resources/com/techsenger/alpha/assembly/maven/plugin/gui-config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
2-
<Configuration title="Alpha GUI" name="alpha-gui" version="${project.version}" type="base">
2+
<Configuration title="Alpha GUI" name="alpha-gui" version="${project.version}">
33
<Repositories>
44
<Repository name="local" url="file://${settings.localRepository}"/>
55
<Repository name="central" url="${maven.central.url}"/>

alpha-assembly/alpha-assembly-maven-plugin/src/main/resources/com/techsenger/alpha/assembly/maven/plugin/registry.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
22
<!-- AUTO-GENERATED FILE — DO NOT EDIT -->
33
<Registry>
4-
<InstallResult successful="true"/>
54
<AddedComponents>
65
<Component name="alpha-repo" version="${project.version}"/>
76
<Component name="alpha-server" version="${project.version}"/>

alpha-assembly/alpha-assembly-maven-plugin/src/main/resources/com/techsenger/alpha/assembly/maven/plugin/repo-config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
2-
<Configuration title="Alpha Repo" name="alpha-repo" version="${project.version}" type="base">
2+
<Configuration title="Alpha Repo" name="alpha-repo" version="${project.version}">
33
<Repositories>
44
<Repository name="local" url="file://${settings.localRepository}"/>
55
<Repository name="central" url="${maven.central.url}"/>

alpha-assembly/alpha-assembly-maven-plugin/src/main/resources/com/techsenger/alpha/assembly/maven/plugin/server-config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
2-
<Configuration title="Alpha Server HTTP" name="alpha-server" version="${project.version}" type="base">
2+
<Configuration title="Alpha Server HTTP" name="alpha-server" version="${project.version}">
33
<Repositories>
44
<Repository name="local" url="file://${settings.localRepository}"/>
55
<Repository name="central" url="${maven.central.url}"/>

alpha-core/src/main/java/com/techsenger/alpha/core/api/ComponentManager.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ Path buildComponent(String name, Version version, Path directoryPath, String ext
7979
*/
8080
ComponentConfig addComponent(String xmlConfig) throws ComponentException;
8181

82+
83+
/**
84+
* Adds a component with the specified configuration and writes its XML to disk.
85+
*
86+
* @param config
87+
* @throws ComponentException
88+
* @return the xml config of the component
89+
*/
90+
String addComponent(ComponentConfig config) throws ComponentException;
91+
8292
/**
8393
* Resolves a component by providing all its modules presence in repo.
8494
*
@@ -291,6 +301,16 @@ ComponentConfig unresolveComponent(String name, Version version, MessagePrinter
291301
*/
292302
ComponentConfig installComponent(String xmlConfig, MessagePrinter printer) throws ComponentException;
293303

304+
/**
305+
* Installs a component (adds and resolves it).
306+
*
307+
* @param config the config of the component
308+
* @param printer
309+
* @throws ComponentException
310+
* @return the xml config of the component
311+
*/
312+
String installComponent(ComponentConfig config, MessagePrinter printer) throws ComponentException;
313+
294314
/**
295315
* Starts a component (deploys and activates it).
296316
*

alpha-core/src/main/java/com/techsenger/alpha/core/api/DefaultPathResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public Path resolveModule(ModuleArtifact artifact) {
202202
+ File.separator
203203
+ artifact.getVersion()
204204
+ File.separator
205-
+ artifact.getFileName();
205+
+ ModuleArtifact.resolveFileName(artifact);
206206
var resolvedPath = this.pathManager.getRepositoryDirectory().resolve(modulePath);
207207
logger.trace("Module {} has path {}", artifact.getArtifactId(), resolvedPath);
208208
return resolvedPath;

alpha-core/src/main/java/com/techsenger/alpha/core/api/component/Component.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package com.techsenger.alpha.core.api.component;
1818

1919
import com.techsenger.alpha.core.api.Constants;
20-
import com.techsenger.alpha.core.api.module.ModuleDescriptor;
20+
import com.techsenger.alpha.core.api.module.ModuleConfig;
2121
import com.techsenger.alpha.core.api.module.ResolvedModuleDirective;
2222
import com.techsenger.toolkit.core.Pair;
2323
import com.techsenger.toolkit.core.version.Version;
@@ -41,7 +41,7 @@ static Pair<String, Version> resolveNameAndVersion(String nameAndVersion) {
4141
return new Pair<>(nameAndVersion.trim(), null);
4242
} else {
4343
String name = nameAndVersion.substring(0, index).trim();
44-
Version version = Version.parse(nameAndVersion.substring(index + 1).trim());
44+
Version version = Version.of(nameAndVersion.substring(index + 1).trim());
4545
return new Pair<>(name, version);
4646
}
4747
}
@@ -73,12 +73,11 @@ static Pair<String, Version> resolveNameAndVersion(String nameAndVersion) {
7373
ModuleLayer getLayer();
7474

7575
/**
76-
* Returns module by descriptor.
76+
* Returns module by config.
7777
*
78-
* @param descriptor
79-
* @return
78+
* @param config
8079
*/
81-
Module getModule(ModuleDescriptor descriptor);
80+
Module getModule(ModuleConfig config);
8281

8382
/**
8483
* Returns resolved modules directives. It is important to clarify that these will only be the directives

alpha-core/src/main/java/com/techsenger/alpha/core/api/component/ComponentConfig.java

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,48 +17,52 @@
1717
package com.techsenger.alpha.core.api.component;
1818

1919
import com.techsenger.alpha.core.api.LayerOwner;
20-
import com.techsenger.alpha.core.api.module.ModuleDescriptor;
21-
import com.techsenger.alpha.core.api.module.ModuleType;
20+
import com.techsenger.alpha.core.api.module.ModuleConfig;
2221
import java.util.List;
2322
import java.util.Map;
2423

2524
/**
25+
* Provides configuration for a component.
2626
*
2727
* @author Pavel Castornii
2828
*/
2929
public interface ComponentConfig extends ComponentConfigDto, LayerOwner {
3030

31+
static ComponentConfigBuilder builder() {
32+
return new ComponentConfigBuilder();
33+
}
34+
3135
/**
32-
* Returns map where key is the attribute name, and value is the attribute value. It is possible to add any
33-
* metadata, for example, author, developer, license etc.
36+
* Returns an unmodifiable map of metadata where the key is the attribute name and the value is the
37+
* attribute value. Arbitrary metadata can be provided, for example: author, developer, license, etc.
3438
*
35-
* @return
39+
* @return the metadata map
3640
*/
3741
Map<String, String> getMetadata();
3842

3943
/**
40-
* Returns the repos from which modules will be resolved.
44+
* Returns an unmodifiable list of repositories from which modules will be resolved.
4145
*
42-
* <p>Repositories will be used in the order they are specified. This means that the module will first be searched
43-
* for in the first repository, then in the second, and so on. It is important to note that, by default, the central
44-
* repository is not used. Therefore, if the central repository needs to be used, it must be explicitly added.
46+
* <p>Repositories are used in the order they are specified. A module is searched for in the first
47+
* repository, then in the next, and so on. By default, the central repository is not used and must
48+
* be explicitly added if required.
4549
*
46-
* @return
50+
* @return the list of repository configurations
4751
*/
48-
List<RepositoryDescriptor> getRepositories();
52+
List<RepositoryConfig> getRepositories();
4953

5054
/**
51-
* Returns module descriptors.
55+
* Returns an unmodifiable list of parent component configurations to which this component can be
56+
* added as a child. An empty list indicates that this component can be added to any component.
5257
*
53-
* @return
58+
* @return the list of parent configurations
5459
*/
55-
List<ModuleDescriptor> getModules();
60+
List<ParentConfig> getParents();
5661

5762
/**
58-
* Returns true if this component contains modules with type {@link ModuleType#WAR}, otherwise returns false.
59-
* The check is performed only once, and the result is stored.
63+
* Returns an unmodifiable list of module configurations.
6064
*
61-
* @return
65+
* @return the list of module configurations
6266
*/
63-
boolean containsWarModules();
67+
List<ModuleConfig> getModules();
6468
}

0 commit comments

Comments
 (0)