1 package org
.argeo
.cms
.runtime
;
3 import java
.nio
.file
.Path
;
4 import java
.nio
.file
.Paths
;
5 import java
.util
.Dictionary
;
6 import java
.util
.concurrent
.CompletableFuture
;
8 import org
.argeo
.api
.acr
.ContentRepository
;
9 import org
.argeo
.api
.acr
.spi
.ProvidedRepository
;
10 import org
.argeo
.api
.cms
.CmsContext
;
11 import org
.argeo
.api
.cms
.CmsDeployment
;
12 import org
.argeo
.api
.cms
.CmsState
;
13 import org
.argeo
.api
.uuid
.UuidFactory
;
14 import org
.argeo
.cms
.acr
.CmsUuidFactory
;
15 import org
.argeo
.cms
.internal
.osgi
.DeployConfig
;
16 import org
.argeo
.cms
.internal
.runtime
.CmsContextImpl
;
17 import org
.argeo
.cms
.internal
.runtime
.CmsDeploymentImpl
;
18 import org
.argeo
.cms
.internal
.runtime
.CmsStateImpl
;
19 import org
.argeo
.cms
.internal
.runtime
.CmsUserAdmin
;
20 import org
.argeo
.cms
.internal
.runtime
.DeployedContentRepository
;
21 import org
.argeo
.osgi
.transaction
.SimpleTransactionManager
;
22 import org
.argeo
.osgi
.transaction
.WorkControl
;
23 import org
.argeo
.osgi
.transaction
.WorkTransaction
;
24 import org
.argeo
.util
.register
.Component
;
25 import org
.argeo
.util
.register
.SimpleRegister
;
26 import org
.osgi
.service
.useradmin
.UserAdmin
;
29 * A CMS assembly which is programatically defined, as an alternative to OSGi
30 * deployment. Useful for testing or AOT compilation.
32 public class StaticCms
{
33 private static SimpleRegister register
= new SimpleRegister();
35 private CompletableFuture
<Void
> stopped
= new CompletableFuture
<Void
>();
39 CmsUuidFactory uuidFactory
= new CmsUuidFactory();
40 Component
<CmsUuidFactory
> uuidFactoryC
= new Component
.Builder
<>(uuidFactory
) //
41 .addType(UuidFactory
.class) //
45 CmsStateImpl cmsState
= new CmsStateImpl();
46 Component
<CmsStateImpl
> cmsStateC
= new Component
.Builder
<>(cmsState
) //
47 .addType(CmsState
.class) //
48 .addActivation(cmsState
::start
) //
49 .addDeactivation(cmsState
::stop
) //
50 .addDependency(uuidFactoryC
.getType(UuidFactory
.class), cmsState
::setUuidFactory
, null) //
53 // Deployment Configuration
54 DeployConfig deployConfig
= new DeployConfig();
55 Component
<DeployConfig
> deployConfigC
= new Component
.Builder
<>(deployConfig
) //
56 .addType(DeployConfig
.class) //
57 .addActivation(deployConfig
::start
) //
58 .addDeactivation(deployConfig
::stop
) //
62 CmsDeploymentImpl cmsDeployment
= new CmsDeploymentImpl();
63 Component
<CmsDeploymentImpl
> cmsDeploymentC
= new Component
.Builder
<>(cmsDeployment
) //
64 .addType(CmsDeployment
.class) //
65 .addActivation(cmsDeployment
::start
) //
66 .addDeactivation(cmsDeployment
::stop
) //
67 .addDependency(cmsStateC
.getType(CmsState
.class), cmsDeployment
::setCmsState
, null) //
68 .addDependency(deployConfigC
.getType(DeployConfig
.class), cmsDeployment
::setDeployConfig
, null) //
71 // Transaction manager
72 SimpleTransactionManager transactionManager
= new SimpleTransactionManager();
73 Component
<SimpleTransactionManager
> transactionManagerC
= new Component
.Builder
<>(transactionManager
) //
74 .addType(WorkControl
.class) //
75 .addType(WorkTransaction
.class) //
79 CmsUserAdmin userAdmin
= new CmsUserAdmin();
81 Component
<CmsUserAdmin
> userAdminC
= new Component
.Builder
<>(userAdmin
) //
82 .addType(UserAdmin
.class) //
83 .addDependency(transactionManagerC
.getType(WorkControl
.class), userAdmin
::setTransactionManager
, null) //
84 .addDependency(transactionManagerC
.getType(WorkTransaction
.class), userAdmin
::setUserTransaction
, null) //
85 .addDependency(deployConfigC
.getType(DeployConfig
.class), (d
) -> {
86 for (Dictionary
<String
, Object
> userDirectoryConfig
: d
.getUserDirectoryConfigs())
87 userAdmin
.enableUserDirectory(userDirectoryConfig
);
92 DeployedContentRepository contentRepository
= new DeployedContentRepository();
93 Component
<DeployedContentRepository
> contentRepositoryC
= new Component
.Builder
<>(contentRepository
) //
94 .addType(ProvidedRepository
.class) //
95 .addType(ContentRepository
.class) //
96 .addActivation(contentRepository
::start
) //
97 .addDeactivation(contentRepository
::stop
) //
98 .addDependency(cmsStateC
.getType(CmsState
.class), contentRepository
::setCmsState
, null) //
99 .addDependency(uuidFactoryC
.getType(UuidFactory
.class), contentRepository
::setUuidFactory
, null) //
103 CmsContextImpl cmsContext
= new CmsContextImpl();
104 Component
<CmsContextImpl
> cmsContextC
= new Component
.Builder
<>(cmsContext
) //
105 .addType(CmsContext
.class) //
106 .addActivation(cmsContext
::start
) //
107 .addDeactivation(cmsContext
::stop
) //
108 .addDependency(cmsStateC
.getType(CmsState
.class), cmsContext
::setCmsState
, null) //
109 .addDependency(cmsDeploymentC
.getType(CmsDeployment
.class), cmsContext
::setCmsDeployment
, null) //
110 .addDependency(userAdminC
.getType(UserAdmin
.class), cmsContext
::setUserAdmin
, null) //
111 .addDependency(uuidFactoryC
.getType(UuidFactory
.class), cmsContext
::setUuidFactory
, null) //
112 .addDependency(contentRepositoryC
.getType(ProvidedRepository
.class), cmsContext
::setContentRepository
,
115 assert cmsContextC
.get() == cmsContext
;
121 if (register
.isActive()) {
122 register
.deactivate();
125 stopped
.complete(null);
128 public void waitForStop() {
132 public static void main(String
[] args
) {
133 if (args
.length
== 0) {
134 System
.err
.println("Usage: <data path>");
137 Path instancePath
= Paths
.get(args
[0]);
138 System
.setProperty("osgi.instance.area", instancePath
.toUri().toString());
140 StaticCms staticCms
= new StaticCms();
141 Runtime
.getRuntime().addShutdownHook(new Thread(() -> staticCms
.stop(), "Static CMS Shutdown"));
143 staticCms
.waitForStop();