Skip to content

Commit

Permalink
Merge branch 'release/3.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
gruberrolandvaltech committed Apr 21, 2020
2 parents 6f11fea + d18c628 commit 643f9fd
Show file tree
Hide file tree
Showing 14 changed files with 136 additions and 17 deletions.
3 changes: 3 additions & 0 deletions HISTORY
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2020-04-21 3.1.1
- JMX: added executeWithHistory()

2020-02-19 3.1.0
- Allow node creation
- JDK 11 support
Expand Down
9 changes: 9 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,15 @@ AECU provides JMX methods for executing scripts and reading the history. You can

This will execute the given script or folder. If a folder is specified then all files (incl. any subfolders) are executed. AECU will respect run modes during execution.

Parameters:
* Path: file or folder to execute

## ExecuteWithHistory

Use this e.g. when you copied over content from production to development and need to rerun install hook scripts.

This will execute the given script or folder. If a folder is specified then all files (incl. any subfolders) are executed. AECU will respect run modes and install hook history during execution. This means that scripts that were already executed by install hook are ignored. After execution the install hook history will be updated.

Parameters:
* Path: file or folder to execute

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>3.1.0</version>
<version>3.1.1</version>
</parent>

<artifactId>aecu.api</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion bundle/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>3.1.0</version>
<version>3.1.1</version>
</parent>

<artifactId>aecu.bundle</artifactId>
Expand Down
20 changes: 19 additions & 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>3.1.0</version>
<version>3.1.1</version>
</parent>

<artifactId>aecu.core</artifactId>
Expand Down Expand Up @@ -79,6 +79,24 @@
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
*/
public class AecuTrackerListener implements ProgressTrackerListener {

public static final String ALWAYS_SUFFIX = "always.groovy";

private static final Set<String> ACTIONS = new HashSet<>(Arrays.asList("A", "M", "U"));

private static final String ACTION_DELETE = "D";
Expand Down Expand Up @@ -89,7 +91,7 @@ public void onMessage(Mode mode, String action, String path) {
return;
}

if (StringUtils.endsWith(path, "always.groovy")) {
if (StringUtils.endsWith(path, ALWAYS_SUFFIX)) {
logMessage(String.format("Adding %s due to having 'always' in name.", path));
paths.add(path);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ public class HookExecutionHistory {
*/
public HookExecutionHistory(Session session, String groovyScriptPath) throws AecuException {
try {
hookHistory = JcrUtils.getOrCreateByPath(HISTORY_BASE_PATH + groovyScriptPath, false, JcrConstants.NT_UNSTRUCTURED,
JcrConstants.NT_UNSTRUCTURED, session, true);
String fullPath = HISTORY_BASE_PATH + groovyScriptPath;
hookHistory = JcrUtils.getOrCreateByPath(fullPath, false, JcrConstants.NT_UNSTRUCTURED, JcrConstants.NT_UNSTRUCTURED,
session, true);
} catch (RepositoryException e) {
throw new AecuException("Error getting or creating node at " + HISTORY_BASE_PATH + groovyScriptPath, e);
}
Expand Down
15 changes: 13 additions & 2 deletions core/src/main/java/de/valtech/aecu/core/jmx/AecuServiceMBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,26 @@ public interface AecuServiceMBean {
List<String> getFiles(@Name("Path") @Description("File or folder") String path) throws AecuException;

/**
* Executes the script at the given position.
* Executes the script(s) at the given position.
*
* @param path path of script
* @param path path of script/folder
* @return execution result
* @throws AecuException error during execution
*/
@Description("Executes a single file or all files of a folder structure")
String execute(@Name("Path") @Description("Path to file/folder that should be executed") String path) throws AecuException;

/**
* Executes the script(s) at the given position and taking install hook history into account.
*
* @param path path of script/folder
* @return execution result
* @throws AecuException error during execution
*/
@Description("Executes a single file or all files of a folder structure. Additionally, the install hook history will be checked if scripts need to be run. History will also be updated for executed scripts.")
String executeWithHistory(@Name("Path") @Description("Path to file/folder that should be executed") String path)
throws AecuException;

/**
* Returns history entries.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@

import java.util.List;

import javax.jcr.Session;
import javax.management.NotCompliantMBeanException;

import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.ResourceResolver;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

Expand All @@ -31,13 +34,19 @@
import de.valtech.aecu.api.service.AecuService;
import de.valtech.aecu.api.service.ExecutionResult;
import de.valtech.aecu.api.service.HistoryEntry;
import de.valtech.aecu.core.installhook.AecuTrackerListener;
import de.valtech.aecu.core.installhook.HookExecutionHistory;
import de.valtech.aecu.core.serviceuser.ServiceResourceResolverService;

@Component(service = {AecuServiceMBean.class}, immediate = true,
property = {"jmx.objectname=de.valtech:type=AECU", "pattern=/.*"})
public class AecuServiceMBeanImpl extends AnnotatedStandardMBean implements AecuServiceMBean {

@Reference
AecuService aecuService;
private AecuService aecuService;

@Reference
private ServiceResourceResolverService serviceResourceResolver;

/**
* Constructor
Expand Down Expand Up @@ -74,6 +83,33 @@ public String execute(String path) throws AecuException {
return result.toString();
}

@Override
public String executeWithHistory(String path) throws AecuException {
HistoryEntry history = aecuService.createHistoryEntry();
List<String> files = aecuService.getFiles(path);
StringBuilder result = new StringBuilder("Found " + files.size() + " files to execute\n\n");
try (ResourceResolver resolver = serviceResourceResolver.getAdminResourceResolver()) {
Session session = resolver.adaptTo(Session.class);
for (String file : files) {
result.append(file + "\n");
HookExecutionHistory executionHistory = new HookExecutionHistory(session, file);
if (!file.endsWith(AecuTrackerListener.ALWAYS_SUFFIX) && executionHistory.hasBeenExecutedBefore()) {
result.append("Skipped due to history\n\n");
continue;
}
ExecutionResult singleResult = aecuService.execute(file);
executionHistory.setExecuted();
aecuService.storeExecutionInHistory(history, singleResult);
result.append(singleResult.toString());
result.append("\n\n");
}
} catch (LoginException e) {
throw new AecuException(e.getMessage(), e);
}
aecuService.finishHistoryEntry(history);
return result.toString();
}

@Override
public String getHistory(int start, int count) throws AecuException {
List<HistoryEntry> entries = aecuService.getHistory(start, count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
import java.util.Arrays;
import java.util.List;

import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;

import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.ResourceResolver;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -39,6 +45,7 @@
import de.valtech.aecu.api.service.AecuService;
import de.valtech.aecu.api.service.ExecutionResult;
import de.valtech.aecu.api.service.HistoryEntry;
import de.valtech.aecu.core.serviceuser.ServiceResourceResolverService;

/**
* Tests AecuServiceMBeanImpl
Expand All @@ -48,20 +55,37 @@
@RunWith(MockitoJUnitRunner.class)
public class AecuServiceMBeanImplTest {

private static final String FILE1 = "file1";
private static final String FILE1 = "/path/file1";

private static final String PATH = "path";
private static final String PATH = "/path";

@Mock
private AecuService service;

@Mock
private ServiceResourceResolverService serviceResourceResolverService;

@Mock
private ResourceResolver resolver;

@Mock
private Session session;

@Mock
private Node node;

@InjectMocks
private AecuServiceMBeanImpl bean;

@Before
public void setup() throws AecuException {
public void setup() throws AecuException, LoginException, RepositoryException {
when(service.getVersion()).thenReturn("1");
when(service.getFiles(PATH)).thenReturn(Arrays.asList(FILE1));
when(serviceResourceResolverService.getAdminResourceResolver()).thenReturn(resolver);
when(resolver.adaptTo(Session.class)).thenReturn(session);
when(node.getSession()).thenReturn(session);
when(session.nodeExists("/var/aecu-installhook" + FILE1)).thenReturn(Boolean.TRUE);
when(session.getNode("/var/aecu-installhook" + FILE1)).thenReturn(node);
}

@Test
Expand Down Expand Up @@ -93,6 +117,21 @@ public void execute() throws AecuException {
verify(service, times(1)).finishHistoryEntry(Mockito.any());
}

@Test
public void executeWithHistory() throws AecuException, LoginException {
ExecutionResult result = mock(ExecutionResult.class);
when(service.execute(FILE1)).thenReturn(result);

String out = bean.executeWithHistory(PATH);

verify(serviceResourceResolverService, times(1)).getAdminResourceResolver();
verify(service, times(1)).getFiles(PATH);
verify(service, times(1)).createHistoryEntry();
verify(service, times(1)).execute(FILE1);
verify(service, times(1)).execute(FILE1);
verify(service, times(1)).finishHistoryEntry(Mockito.any());
}

@Test
public void getHistory() throws AecuException {
HistoryEntry entry = mock(HistoryEntry.class);
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>3.1.0</version>
<version>3.1.1</version>
</parent>

<artifactId>aecu.examples</artifactId>
Expand Down
2 changes: 1 addition & 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>3.1.0</version>
<version>3.1.1</version>
<name>AECU</name>
<description>AEM Easy Content Upgrade</description>
<url>https://github.com/valtech/aem-easy-content-upgrade</url>
Expand Down
4 changes: 2 additions & 2 deletions 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=3.0.2-SNAPSHOT
sonar.projectVersion=3.1.1-SNAPSHOT

# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8
Expand All @@ -15,4 +15,4 @@ sonar.links.issue=https://github.com/valtech/aem-easy-content-upgrade/issues
sonar.sources=core/src/main
sonar.tests=core/src/test
sonar.java.binaries=core/target/classes
sonar.jacoco.reportPaths=core/target/jacoco.exec
sonar.coverage.jacoco.xmlReportPaths=core/target/site/jacoco/jacoco.xml
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>3.1.0</version>
<version>3.1.1</version>
</parent>

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

0 comments on commit 643f9fd

Please sign in to comment.