Skip to content

Commit

Permalink
Merge branch 'release/6.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
gruberrolandvaltech committed May 19, 2022
2 parents cf91c5a + 2ea36b0 commit 325528d
Show file tree
Hide file tree
Showing 20 changed files with 118 additions and 30 deletions.
3 changes: 3 additions & 0 deletions HISTORY
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2022-05-19 6.0.1
- Fixed race condition on AEM Cloud startup hook (184)

2022-04-22 6.0.0
- Added startup hook for automatic script execution on AEM Cloud (171)
- AecuService: added executeWithInstallHookHistory() method (172)
Expand Down
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<version>6.0.0</version>
<version>6.0.1</version>
</parent>

<artifactId>aecu.api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public FilterByProperty(@Nonnull String name, Object value) {
public boolean filter(@Nonnull Resource resource, StringBuilder output) {
ValueMap properties = resource.getValueMap();
Object attrValue = properties.get(name);
return (value == null) && (attrValue == null) || ((value != null) && value.equals(attrValue));
return ((value == null) && (attrValue == null)) || ((value != null) && value.equals(attrValue));
}
}

2 changes: 1 addition & 1 deletion complete-cloud/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<version>6.0.0</version>
<version>6.0.1</version>
</parent>

<artifactId>aecu.complete.cloud</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion complete/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<version>6.0.0</version>
<version>6.0.1</version>
</parent>

<artifactId>aecu.complete</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<version>6.0.0</version>
<version>6.0.1</version>
</parent>

<artifactId>aecu.core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public String doAction(@Nonnull Resource resource) throws PersistenceException {
}

String warning = (oldValues.length != newValues.length)
? "WARNING: old values and new values length mismatch (old: " + Arrays.toString(oldValues) + " , new: "
+ Arrays.toString(newValues) + ")" + " -> the smaller length will be considered\n"
? ("WARNING: old values and new values length mismatch (old: " + Arrays.toString(oldValues) + " , new: "
+ Arrays.toString(newValues) + ")" + " -> the smaller length will be considered\n")
: "";

for (int i = 0; i < oldValues.length && i < newValues.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public AecuInstallHook() {

@Override
public void execute(InstallContext installContext) throws PackageException {
LOG.info("Executing in phase {}", installContext.getPhase());
LOG.info("Executing in phase {} for package {}", installContext.getPhase(), installContext.getPackage().getId());
ServiceReference<AecuService> aecuServiceReference = osgiServiceProvider.getServiceReference(AecuService.class);
AecuService aecuService = osgiServiceProvider.getService(aecuServiceReference);

Expand All @@ -92,7 +92,6 @@ public void execute(InstallContext installContext) throws PackageException {
installContext.getOptions().setListener(listener);
break;
case INSTALLED:

Archive archive = installContext.getPackage().getArchive();
List<String> allValidScriptCandidatesInArchive = findCandidates("", archive.getJcrRoot(), aecuService);
List<String> scriptsForInstallation =
Expand All @@ -118,6 +117,9 @@ public void execute(InstallContext installContext) throws PackageException {

private List<String> getScriptsForExecution(List<String> allValidScriptCandidatesInArchive, InstallContext installContext) {
List<String> scriptsForExecution = new ArrayList<>();
if (listener == null) {
return scriptsForExecution;
}
List<String> modifiedOrAddedScriptPaths = listener.getModifiedOrAddedPaths();
for (String groovyScriptPath : allValidScriptCandidatesInArchive) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ public AecuTrackerListener(ProgressTrackerListener originalListener, AecuService
this.originalListener = originalListener;
this.aecuService = aecuService;
this.paths = new HashSet<>();
logMessage("Starting install hook...");
if (originalListener == null) {
logMessage("No progress tracker listener given.");
} else {
logMessage("Starting install hook...");
}
}

/**
Expand All @@ -83,7 +87,9 @@ public List<String> getModifiedOrAddedPaths() {

@Override
public void onMessage(Mode mode, String action, String path) {
originalListener.onMessage(mode, action, path);
if (originalListener != null) {
originalListener.onMessage(mode, action, path);
}

if (StringUtils.length(action) != VALID_ACTION_LENGTH) {
// skip actions like 'Collecting import information... ', 'Package imported.' etc.
Expand Down Expand Up @@ -132,14 +138,21 @@ private boolean isValid(String path) {

@Override
public void onError(Mode mode, String action, Exception e) {
originalListener.onError(mode, action, e);
if (originalListener != null) {
originalListener.onError(mode, action, e);
}
}

public void logMessage(String message) {
onMessage(Mode.TEXT, LOG_PREFIX + message, "");
LOG.info(message);
if (originalListener != null) {
originalListener.onMessage(Mode.TEXT, LOG_PREFIX + message, "");
}
}

public void logError(String message, Exception e) {
LOG.error(message, e);
onError(Mode.TEXT, LOG_PREFIX + message, e);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,28 @@
*/
package de.valtech.aecu.core.service;

import java.util.Collection;

import javax.jcr.Session;

import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.ResourceResolver;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.runtime.ServiceComponentRuntime;
import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
import org.osgi.service.component.runtime.dto.ComponentDescriptionDTO;
import org.osgi.service.component.runtime.dto.SatisfiedReferenceDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.icfolson.aem.groovy.console.api.BindingExtensionProvider;

import de.valtech.aecu.api.service.AecuException;
import de.valtech.aecu.api.service.AecuService;
import de.valtech.aecu.core.groovy.console.bindings.provider.AecuBindingExtensionProvider;
import de.valtech.aecu.core.groovy.console.bindings.provider.AecuStarImportExtensionProvider;
import de.valtech.aecu.core.serviceuser.ServiceResourceResolverService;
import de.valtech.aecu.core.util.runtime.RuntimeHelper;

Expand All @@ -41,29 +49,80 @@
@Component(service = AecuCloudStartupService.class, immediate = true, name = "AECU cloud startup hook")
public class AecuCloudStartupService {

private static final String STAR_IMPORT_EXTENSION_PROVIDER = "StarImportExtensionProvider";
private static final String BINDING_EXTENSION_PROVIDER = "BindingExtensionProvider";
private static final String DEFAULT_EXTENSION_SERVICE =
"com.icfolson.aem.groovy.console.extension.impl.DefaultExtensionService";

private static final Logger LOGGER = LoggerFactory.getLogger(AecuCloudStartupService.class);

private static final int WAIT_PERIOD = 10;
private static final int WAIT_INTERVALS = 30;

@Reference
private AecuService aecuService;
@Reference
private ServiceResourceResolverService resourceResolverService;

// dependencies to avoid scripts are executed before Groovy extension is loaded
@Reference
private AecuBindingExtensionProvider dependency1;
@Reference
private AecuStarImportExtensionProvider dependency2;
private ServiceComponentRuntime serviceComponentRuntime;

@Activate
public void activate() {
public void activate() throws InterruptedException {
ResourceResolver resourceResolver = getResourceResolver();
Session session = resourceResolver.adaptTo(Session.class);
boolean isCompositeNodeStore = RuntimeHelper.isCompositeNodeStore(session);
if (isCompositeNodeStore) {
if (!waitForServices()) {
LOGGER.error("Groovy extension services seem to be not bound");
throw new IllegalStateException("Groovy extension services seem to be not bound");
}
Thread.sleep(1000L * WAIT_PERIOD);
startAecuMigration();
}
}

/**
* Waits till Groovy Console took up our services.
*
* @return services are ok
* @throws InterruptedException sleep failed
*/
protected boolean waitForServices() throws InterruptedException {
for (int i = 0; i < WAIT_INTERVALS; i++) {
if (servicesAreOk()) {
return true;
}
Thread.sleep(1000L * WAIT_PERIOD);
LOGGER.debug("Services not yet injected, waiting");
}
return false;
}

/**
* Checks if our services are already injected.
*/
private boolean servicesAreOk() {
Bundle bundle = FrameworkUtil.getBundle(BindingExtensionProvider.class);
ComponentDescriptionDTO componentDescription =
serviceComponentRuntime.getComponentDescriptionDTO(bundle, DEFAULT_EXTENSION_SERVICE);
if ((componentDescription == null) || !serviceComponentRuntime.isComponentEnabled(componentDescription)) {
return false;
}
Collection<ComponentConfigurationDTO> componentConfigurations =
serviceComponentRuntime.getComponentConfigurationDTOs(componentDescription);
int satisfied = 0;
for (ComponentConfigurationDTO componentConfiguration : componentConfigurations) {
for (SatisfiedReferenceDTO satisfiedReference : componentConfiguration.satisfiedReferences) {
if ((BINDING_EXTENSION_PROVIDER.equals(satisfiedReference.name)
|| STAR_IMPORT_EXTENSION_PROVIDER.equals(satisfiedReference.name))
&& (satisfiedReference.boundServices.length >= 2)) {
satisfied++;
}
}
}
return satisfied == 2;
}

/**
* Starts the AECU migration
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package de.valtech.aecu.core.service;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;
Expand Down Expand Up @@ -68,6 +69,7 @@ public void setUp() throws Exception {
when(resolverService.getAdminResourceResolver()).thenReturn(resolver);
when(resolver.adaptTo(Session.class)).thenReturn(session);
doReturn(true).when(session).hasPermission(anyString(), anyString());
doReturn(true).when(startupService).waitForServices();
}

@Test
Expand All @@ -79,6 +81,14 @@ public void testMigration_compositeNodeStore() throws Exception {
verify(aecuService, times(1)).executeWithInstallHookHistory(AecuService.AECU_APPS_PATH_PREFIX);
}

@Test
public void testMigration_compositeNodeStoreButServicesNotOk() throws Exception {
doReturn(false).when(session).hasCapability(anyString(), any(), any());
doReturn(false).when(startupService).waitForServices();

assertThrows(IllegalStateException.class, () -> startupService.activate());
}

@Test
public void testMigration_noCompositeNodeStore() throws Exception {
doReturn(true).when(session).hasCapability(anyString(), any(), any());
Expand Down
2 changes: 1 addition & 1 deletion examples-cloud/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<version>6.0.0</version>
<version>6.0.1</version>
</parent>

<artifactId>aecu.examples-cloud</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<version>6.0.0</version>
<version>6.0.1</version>
</parent>

<artifactId>aecu.examples</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion oak.index/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<version>6.0.0</version>
<version>6.0.1</version>
</parent>

<artifactId>aecu.oak.index</artifactId>
Expand Down
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<packaging>pom</packaging>
<version>6.0.0</version>
<version>6.0.1</version>
<name>AECU</name>
<description>AEM Easy Content Upgrade</description>
<url>https://github.com/valtech/aem-easy-content-upgrade</url>
Expand Down Expand Up @@ -694,6 +694,7 @@
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
sonar.projectKey=aecu
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=AEM Easy Content Upgrade
sonar.projectVersion=5.3.0-SNAPSHOT
sonar.projectVersion=6.0.1-SNAPSHOT

# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8
Expand Down
2 changes: 1 addition & 1 deletion ui.apps.groovyconsole/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<version>6.0.0</version>
<version>6.0.1</version>
</parent>

<artifactId>aecu.ui.apps.groovyconsole</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion ui.apps.structure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<version>6.0.0</version>
<version>6.0.1</version>
</parent>

<artifactId>aecu.ui.apps.structure</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion ui.apps/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<version>6.0.0</version>
<version>6.0.1</version>
</parent>

<artifactId>aecu.ui.apps</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion ui.content/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<version>6.0.0</version>
<version>6.0.1</version>
</parent>

<artifactId>aecu.ui.content</artifactId>
Expand Down

0 comments on commit 325528d

Please sign in to comment.