18
18
*/
19
19
package de .valtech .aecu .startuphook ;
20
20
21
+ import de .valtech .aecu .api .service .AecuException ;
22
+ import de .valtech .aecu .api .service .AecuService ;
23
+ import de .valtech .aecu .api .service .HistoryEntry ;
24
+ import de .valtech .aecu .api .service .HistoryEntry .STATE ;
25
+ import java .util .Arrays ;
21
26
import java .util .Collection ;
22
27
import java .util .Date ;
23
28
import java .util .List ;
24
-
25
29
import javax .jcr .Session ;
26
-
27
30
import org .apache .sling .api .resource .LoginException ;
28
31
import org .apache .sling .api .resource .ResourceResolver ;
29
32
import org .osgi .framework .Bundle ;
30
- import org .osgi .framework .FrameworkUtil ;
33
+ import org .osgi .framework .BundleContext ;
31
34
import org .osgi .service .component .annotations .Activate ;
32
35
import org .osgi .service .component .annotations .Component ;
33
36
import org .osgi .service .component .annotations .Reference ;
38
41
import org .slf4j .Logger ;
39
42
import org .slf4j .LoggerFactory ;
40
43
41
- import be .orbinson .aem .groovy .console .api .BindingExtensionProvider ;
42
-
43
- import de .valtech .aecu .api .service .AecuException ;
44
- import de .valtech .aecu .api .service .AecuService ;
45
- import de .valtech .aecu .api .service .HistoryEntry ;
46
- import de .valtech .aecu .api .service .HistoryEntry .STATE ;
47
-
48
44
/**
49
45
* Service that executes the AECU migration if the node store type is composite (AEM Cloud).
50
46
*/
51
47
@ Component (service = AecuCloudStartupService .class , immediate = true , name = "AECU cloud startup hook" )
52
48
public class AecuCloudStartupService {
53
49
50
+ private static final String GROOVY_CONSOLE_BUNDLE_SYMBOLIC_NAME = "aem-groovy-console-bundle" ;
54
51
private static final String STAR_IMPORT_EXTENSION_PROVIDER = "StarImportExtensionProvider" ;
55
52
private static final String BINDING_EXTENSION_PROVIDER = "BindingExtensionProvider" ;
56
53
private static final String DEFAULT_EXTENSION_SERVICE =
@@ -70,8 +67,11 @@ public class AecuCloudStartupService {
70
67
@ Reference
71
68
private ServiceComponentRuntime serviceComponentRuntime ;
72
69
70
+ private BundleContext bundleContext ;
71
+
73
72
@ Activate
74
- public void activate () {
73
+ public void activate (final BundleContext bundleContext ) {
74
+ this .bundleContext = bundleContext ;
75
75
Runnable runnable = this ::checkAndRunMigration ;
76
76
Thread thread = new Thread (runnable );
77
77
thread .start ();
@@ -101,7 +101,7 @@ protected void checkAndRunMigration() {
101
101
/**
102
102
* Checks if an AECU migration is already in progress. If AECU history tells migration is in
103
103
* progress then wait max. for MIGRATION_TIMEOUT.
104
- *
104
+ *
105
105
* @return migration in progress
106
106
*/
107
107
protected boolean isMigrationInProgress () {
@@ -121,7 +121,7 @@ protected boolean isMigrationInProgress() {
121
121
122
122
/**
123
123
* Waits till Groovy Console took up our services.
124
- *
124
+ *
125
125
* @return services are ok
126
126
* @throws InterruptedException sleep failed
127
127
*/
@@ -140,7 +140,12 @@ protected boolean waitForServices() throws InterruptedException {
140
140
* Checks if our services are already injected.
141
141
*/
142
142
private boolean servicesAreOk () {
143
- Bundle bundle = FrameworkUtil .getBundle (BindingExtensionProvider .class );
143
+ Bundle bundle = Arrays .stream (bundleContext .getBundles ())
144
+ .filter (b -> GROOVY_CONSOLE_BUNDLE_SYMBOLIC_NAME .equals (b .getSymbolicName ()))
145
+ .findFirst ().orElse (null );
146
+ if (bundle == null ) {
147
+ return false ;
148
+ }
144
149
ComponentDescriptionDTO componentDescription =
145
150
serviceComponentRuntime .getComponentDescriptionDTO (bundle , DEFAULT_EXTENSION_SERVICE );
146
151
if ((componentDescription == null ) || !serviceComponentRuntime .isComponentEnabled (componentDescription )) {
@@ -176,7 +181,7 @@ void startAecuMigration() {
176
181
177
182
/**
178
183
* Returns the resource resolver to be used
179
- *
184
+ *
180
185
* @return the resource resolver
181
186
*/
182
187
private ResourceResolver getResourceResolver () {
0 commit comments