Skip to content

Commit 044ee3e

Browse files
committed
Add demo starter
1 parent ffff249 commit 044ee3e

10 files changed

Lines changed: 279 additions & 23 deletions

File tree

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,17 @@ both the client and server instances of the framework use this file.
160160

161161
#### Boot <a name="usage-framework-boot"></a>
162162

163-
The framework is booted as follows. If the framework detects a `BootService` provider, this service is executed.
164-
Otherwise, a command script is executed.
163+
The boot layer must always contain a minimal set of modules: the two framework modules, the Expression Language modules,
164+
and the logging modules. In addition, the boot layer must contain a module that launches and initializes the framework
165+
— in a distribution this is the main application module, and in integration tests this is the test module itself.
166+
167+
There are two ways to populate the boot layer with the required modules. If the JVM is launched via `.sh`/`.bat`
168+
scripts, the module path is configured by the scripts automatically. The `assemble-distro` goal of the Assembly Maven
169+
Plugin handles this by generating the scripts with the correct module path.
170+
171+
If the JVM is launched via Maven plugins (`exec-maven-plugin`, `maven-failsafe-plugin`, etc.), Maven takes care of
172+
adding the required modules to the boot layer, which makes it convenient both for running the application and for
173+
setting up the integration test environment.
165174

166175
### Component <a name="usage-component"></a>
167176

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<Module groupId="org.apache.commons" artifactId="commons-lang3" version="${commons.lang.version}"/>
1616
<Module groupId="com.techsenger.toolkit" artifactId="toolkit-ascii" version="${toolkit.version}"/>
1717
<Module groupId="com.techsenger.toolkit" artifactId="toolkit-http" version="${toolkit.version}"/>
18+
<Module groupId="com.beust" artifactId="jcommander" version="${jcommander.version}"/>
1819
<Module groupId="com.google.code.gson" artifactId="gson" version="${gson.version}">
1920
<!--
2021
Gson requires reflective access to java.time classes for serialization/deserialization.

alpha-assembly/alpha-assembly-maven-plugin/src/main/resources/com/techsenger/alpha/assembly/maven/plugin/framework-modules.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ org.apache.logging.log4j:log4j-api:${log4j.version}
66
org.apache.logging.log4j:log4j-jcl:${log4j.version}
77
org.apache.logging.log4j:log4j-slf4j2-impl:${log4j.version}
88
org.fusesource.jansi:jansi:${jansi.version}
9-
com.beust:jcommander:${jcommander.version}
109
jakarta.el:jakarta.el-api:${el.version}
1110
org.glassfish.expressly:expressly:${el.version}
1211
com.techsenger.toolkit:toolkit-core:${toolkit.version}
13-
com.techsenger.toolkit:toolkit-http:${toolkit.version}
1412
com.techsenger.alpha:alpha-core:${project.version}
1513

alpha-demo/alpha-demo-cli/pom.xml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,62 +24,46 @@
2424
<dependency>
2525
<groupId>org.slf4j</groupId>
2626
<artifactId>slf4j-api</artifactId>
27-
<version>2.0.9</version>
2827
</dependency>
2928
<dependency>
3029
<groupId>org.apache.logging.log4j</groupId>
3130
<artifactId>log4j-core</artifactId>
32-
<version>2.21.1</version>
3331
</dependency>
3432
<dependency>
3533
<groupId>org.apache.logging.log4j</groupId>
3634
<artifactId>log4j-jul</artifactId>
37-
<version>2.21.1</version>
3835
</dependency>
3936
<dependency>
4037
<groupId>org.apache.logging.log4j</groupId>
4138
<artifactId>log4j-api</artifactId>
42-
<version>2.21.1</version>
4339
</dependency>
4440
<dependency>
4541
<groupId>org.apache.logging.log4j</groupId>
4642
<artifactId>log4j-jcl</artifactId>
47-
<version>2.21.1</version>
4843
</dependency>
4944
<dependency>
5045
<groupId>org.apache.logging.log4j</groupId>
5146
<artifactId>log4j-slf4j2-impl</artifactId>
52-
<version>2.21.1</version>
5347
</dependency>
5448
<dependency>
5549
<groupId>com.techsenger.alpha</groupId>
5650
<artifactId>alpha-core</artifactId>
57-
<version>1.0.0-SNAPSHOT</version>
5851
</dependency>
5952
<dependency>
6053
<groupId>com.techsenger.toolkit</groupId>
6154
<artifactId>toolkit-core</artifactId>
62-
<version>1.0.0</version>
6355
</dependency>
6456
<dependency>
6557
<groupId>org.fusesource.jansi</groupId>
6658
<artifactId>jansi</artifactId>
67-
<version>2.4.1</version>
68-
</dependency>
69-
<dependency>
70-
<groupId>com.beust</groupId>
71-
<artifactId>jcommander</artifactId>
72-
<version>1.78</version>
7359
</dependency>
7460
<dependency>
7561
<groupId>jakarta.el</groupId>
7662
<artifactId>jakarta.el-api</artifactId>
77-
<version>${el.version}</version>
7863
</dependency>
7964
<dependency>
8065
<groupId>org.glassfish.expressly</groupId>
8166
<artifactId>expressly</artifactId>
82-
<version>${el.version}</version>
8367
</dependency>
8468
</dependencies>
8569

alpha-demo/alpha-demo-cli/src/main/java/module-info.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@
2121
requires org.apache.logging.log4j;
2222
requires org.apache.logging.log4j.jcl;
2323
requires org.apache.logging.log4j.slf4j2.impl;
24-
requires com.techsenger.alpha.core;
25-
requires com.techsenger.toolkit.core;
2624
requires org.fusesource.jansi;
27-
requires jcommander;
2825
requires jakarta.el;
2926
requires org.glassfish.expressly;
27+
requires com.techsenger.alpha.core;
28+
requires com.techsenger.toolkit.core;
3029
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>com.techsenger.alpha.demo</groupId>
6+
<artifactId>alpha-demo</artifactId>
7+
<version>1.0.0-SNAPSHOT</version>
8+
</parent>
9+
10+
<groupId>com.techsenger.alpha.demo</groupId>
11+
<artifactId>alpha-demo-starter</artifactId>
12+
<packaging>jar</packaging>
13+
<name>Alpha - Demo Starter</name>
14+
<description>Starter demo application demonstrating the basic usage of the framework</description>
15+
16+
<properties>
17+
<install.plugin.phase>package</install.plugin.phase>
18+
<dependency.plugin.skip>false</dependency.plugin.skip>
19+
<demo.main.module>com.techsenger.alpha.demo.cli</demo.main.module>
20+
<demo.main.dependency>com.techsenger.alpha.demo:alpha-demo-cli</demo.main.dependency>
21+
</properties>
22+
23+
<dependencies>
24+
<dependency>
25+
<groupId>org.slf4j</groupId>
26+
<artifactId>slf4j-api</artifactId>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.apache.logging.log4j</groupId>
30+
<artifactId>log4j-core</artifactId>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.apache.logging.log4j</groupId>
34+
<artifactId>log4j-jul</artifactId>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.apache.logging.log4j</groupId>
38+
<artifactId>log4j-api</artifactId>
39+
</dependency>
40+
<dependency>
41+
<groupId>org.apache.logging.log4j</groupId>
42+
<artifactId>log4j-jcl</artifactId>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.apache.logging.log4j</groupId>
46+
<artifactId>log4j-slf4j2-impl</artifactId>
47+
</dependency>
48+
<dependency>
49+
<groupId>com.techsenger.alpha</groupId>
50+
<artifactId>alpha-core</artifactId>
51+
</dependency>
52+
<dependency>
53+
<groupId>com.techsenger.toolkit</groupId>
54+
<artifactId>toolkit-core</artifactId>
55+
</dependency>
56+
<dependency>
57+
<groupId>org.fusesource.jansi</groupId>
58+
<artifactId>jansi</artifactId>
59+
</dependency>
60+
<dependency>
61+
<groupId>com.beust</groupId>
62+
<artifactId>jcommander</artifactId>
63+
</dependency>
64+
<dependency>
65+
<groupId>jakarta.el</groupId>
66+
<artifactId>jakarta.el-api</artifactId>
67+
</dependency>
68+
<dependency>
69+
<groupId>org.glassfish.expressly</groupId>
70+
<artifactId>expressly</artifactId>
71+
</dependency>
72+
</dependencies>
73+
74+
<build>
75+
<plugins>
76+
<plugin>
77+
<groupId>com.techsenger.alpha.assembly</groupId>
78+
<artifactId>alpha-assembly-maven-plugin</artifactId>
79+
<version>${project.version}</version>
80+
<executions>
81+
<execution>
82+
<phase>verify</phase>
83+
<goals>
84+
<goal>assemble-distro</goal>
85+
</goals>
86+
<configuration>
87+
<path>${project.build.directory}/framework</path>
88+
<mainClass>com.techsenger.alpha.demo.starter/com.techsenger.alpha.demo.starter.StarterDemo</mainClass>
89+
<modules>
90+
<module>
91+
<groupId>com.techsenger.alpha.demo</groupId>
92+
<artifactId>alpha-demo-starter</artifactId>
93+
<version>${project.version}</version>
94+
<onModulePath>true</onModulePath>
95+
</module>
96+
</modules>
97+
</configuration>
98+
</execution>
99+
</executions>
100+
</plugin>
101+
<plugin>
102+
<groupId>org.codehaus.mojo</groupId>
103+
<artifactId>exec-maven-plugin</artifactId>
104+
<configuration>
105+
<executable>java</executable>
106+
<arguments>
107+
<argument>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=localhost:7700</argument>
108+
<argument>-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager</argument>
109+
<argument>-Dorg.jboss.logging.provider=log4j</argument>
110+
<argument>-Dcom.techsenger.alpha.core.root.path=${project.build.directory}/framework</argument>
111+
<argument>--module-path</argument>
112+
<modulepath/> <!-- placeholder that automatically resolves and injects the module path -->
113+
<argument>--module</argument>
114+
<argument>com.techsenger.alpha.demo.starter/com.techsenger.alpha.demo.starter.StarterDemo</argument>
115+
</arguments>
116+
</configuration>
117+
</plugin>
118+
</plugins>
119+
</build>
120+
121+
</project>
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Copyright 2018-2025 Pavel Castornii.
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+
* http://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 com.techsenger.alpha.demo.starter;
18+
19+
import com.techsenger.alpha.core.api.ComponentManager;
20+
import com.techsenger.alpha.core.api.FrameworkFactory;
21+
import com.techsenger.alpha.core.api.FrameworkSettings;
22+
import com.techsenger.alpha.core.api.SystemProperties;
23+
import com.techsenger.alpha.core.api.message.MessagePrinter;
24+
import com.techsenger.toolkit.core.version.Version;
25+
import java.nio.file.Paths;
26+
27+
/**
28+
* A simple starter that demonstrates basic operations with components.
29+
*
30+
* <p>Two ways to run this demo:
31+
* <ol>
32+
* <li>Compile and run scripts in {@code target/framework/bin} folder</li>
33+
* <li>Run: {@code mvn clean install exec:exec}</li>
34+
* </ol>
35+
* @author Pavel Castornii
36+
*/
37+
public final class StarterDemo {
38+
39+
private static final String CUSTOM_COMPONENT =
40+
"""
41+
<Configuration title="Custom Component" name="custom-component" version="1.0.0" type="base">
42+
<Repositories>
43+
<Repository name="central" url="https://repo1.maven.org/maven2/"/>
44+
</Repositories>
45+
46+
<Modules>
47+
<Module groupId="com.google.code.gson" artifactId="gson" version="2.10"/>
48+
</Modules>
49+
</Configuration>
50+
""";
51+
52+
private static final class MessagePrinterImpl implements MessagePrinter {
53+
54+
@Override
55+
public void printlnMessage(String message) {
56+
System.out.println(message);
57+
}
58+
59+
@Override
60+
public void printlnError(String error) {
61+
System.err.println(error);
62+
}
63+
64+
@Override
65+
public int getWidth() {
66+
throw new UnsupportedOperationException("Not supported yet.");
67+
}
68+
69+
}
70+
71+
public static void main(String[] args) throws Exception {
72+
var frameworkPath = Paths.get(System.getProperty(SystemProperties.ROOT_PATH));
73+
var settings = FrameworkSettings.builder().repoChecksumEnabled(false).build();
74+
var framework = FrameworkFactory.create(settings, frameworkPath);
75+
var messagePrinter = new MessagePrinterImpl();
76+
var componentManager = framework.getComponentManager();
77+
78+
System.out.println("Starting repo (it is already resolved)");
79+
componentManager.startComponent("alpha-repo", framework.getVersion());
80+
listComponents(componentManager);
81+
82+
System.out.println("\nInstalling and starting custom component");
83+
componentManager.installComponent(CUSTOM_COMPONENT, messagePrinter);
84+
componentManager.startComponent("custom-component", Version.parse("1.0.0"));
85+
listComponents(componentManager);
86+
87+
framework.shutdown();
88+
}
89+
90+
private static void listComponents(ComponentManager manager) {
91+
System.out.println("Current components:");
92+
manager.getComponents()
93+
.forEach(c -> System.out.println(" " + c.getDescriptor().getConfig().getFullName()));
94+
}
95+
96+
private StarterDemo() {
97+
// empty
98+
}
99+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2018-2025 Pavel Castornii.
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+
* http://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+
module com.techsenger.alpha.demo.starter {
18+
requires org.slf4j;
19+
requires org.apache.logging.log4j.core;
20+
requires org.apache.logging.log4j.jul;
21+
requires org.apache.logging.log4j;
22+
requires org.apache.logging.log4j.jcl;
23+
requires org.apache.logging.log4j.slf4j2.impl;
24+
requires org.fusesource.jansi;
25+
requires jakarta.el;
26+
requires org.glassfish.expressly;
27+
requires com.techsenger.alpha.core;
28+
requires com.techsenger.toolkit.core;
29+
}
30+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Configuration status="error">
3+
<Appenders>
4+
<Console name="Console" target="SYSTEM_OUT" >
5+
<PatternLayout pattern="%highlight{%-5level}{FATAL=red blink, ERROR=red bold, WARN=yellow bold, INFO=magenta, DEBUG=green, TRACE=blue} %logger{36} - %msg%n"/>
6+
</Console>
7+
</Appenders>
8+
9+
<Loggers>
10+
<Root level="info">
11+
<AppenderRef ref="Console"/>
12+
</Root>
13+
</Loggers>
14+
</Configuration>

alpha-demo/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<module>alpha-demo-net</module>
3333
<module>alpha-demo-tools</module>
3434
<module>alpha-demo-web</module>-->
35+
<module>alpha-demo-starter</module>
3536
</modules>
3637

3738
<dependencyManagement>

0 commit comments

Comments
 (0)