Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
#9: remove log interface, remove UpgradeActionInfo (as per PR review).
Browse files Browse the repository at this point in the history
  • Loading branch information
otarsko committed Oct 25, 2017
1 parent 2ae46e2 commit 9b79f13
Show file tree
Hide file tree
Showing 21 changed files with 142 additions and 181 deletions.
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@
<url>https://github.com/Netcentric/vault-upgrade-hook/issues</url>
</issueManagement>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>2.8.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<defaultGoal>clean install</defaultGoal>
<pluginManagement>
Expand Down
2 changes: 0 additions & 2 deletions vault-upgrade-hook/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,6 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>2.8.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,17 @@
import org.apache.jackrabbit.vault.packaging.InstallContext;
import org.apache.jackrabbit.vault.packaging.InstallContext.Phase;

import biz.netcentric.vlt.upgrade.handler.UpgradeActionInfo;
import biz.netcentric.vlt.upgrade.handler.UpgradeHandler;
import biz.netcentric.vlt.upgrade.handler.UpgradeType;
import biz.netcentric.vlt.upgrade.util.PackageInstallLogger;
import biz.netcentric.vlt.upgrade.util.PackageInstallLoggerImpl;

/**
* This class represents the wrapper to execute {@link UpgradeAction}s. It loads
* and holds the configuration.
*/
public class UpgradeInfo {

private static final PackageInstallLogger LOG = PackageInstallLoggerImpl.create(UpgradeInfo.class);
private static final PackageInstallLogger LOG = PackageInstallLogger.create(UpgradeInfo.class);

/**
* This property configures the handler to execute this {@link UpgradeInfo}s
Expand Down Expand Up @@ -78,15 +76,14 @@ public UpgradeInfo(InstallContext ctx, UpgradeStatus status, Node node) throws R
installationMode = InstallationMode.valueOf(JcrUtils.getStringProperty(node, PN_INSTALLATION_MODE, DEFAULT_INSTALLATION_MODE).toUpperCase());
defaultPhase = Phase.valueOf(JcrUtils.getStringProperty(node, PN_DEFAULT_PHASE, DEFAULT_PHASE).toUpperCase());
handler = UpgradeType.create(ctx, JcrUtils.getStringProperty(node, PN_HANDLER, DEFAULT_HANDLER));
loadActions(ctx);
LOG.debug(ctx, "UpgradeInfo loaded [{}]", this);
}

private void loadActions(InstallContext ctx) throws RepositoryException {
public void loadActions(InstallContext ctx) throws RepositoryException {
for (Phase availablePhase : Phase.values()) {
actions.put(availablePhase, new ArrayList<UpgradeAction>());
}
for (UpgradeAction action : handler.create(ctx, new UpgradeActionInfo(node, defaultPhase))) {
for (UpgradeAction action : handler.create(ctx, this)) {
actions.get(action.getPhase()).add(action);
}
for (Phase availablePhase : Phase.values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import biz.netcentric.vlt.upgrade.UpgradeInfo.InstallationMode;
import biz.netcentric.vlt.upgrade.util.PackageInstallLogger;
import biz.netcentric.vlt.upgrade.util.PackageInstallLoggerImpl;

/**
* This class is the main entry point for the <b>vault-upgrade-hook</b>
Expand All @@ -39,7 +38,7 @@
*/
public class UpgradeProcessor implements InstallHook {

private static final PackageInstallLogger LOG = PackageInstallLoggerImpl.create(UpgradeProcessor.class);
private static final PackageInstallLogger LOG = PackageInstallLogger.create(UpgradeProcessor.class);

/**
* Absolute path where information of the {@link UpgradeInfo} execution are
Expand Down Expand Up @@ -160,6 +159,7 @@ protected void loadInfos(final InstallContext ctx) throws RepositoryException {
while (nodes.hasNext()) {
Node child = nodes.nextNode();
final UpgradeInfo info = new UpgradeInfo(ctx, status, child);
info.loadActions(ctx);
LOG.debug(ctx, "info [{}]", info);
infos.add(info);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@
import org.apache.jackrabbit.vault.packaging.Version;

import biz.netcentric.vlt.upgrade.util.PackageInstallLogger;
import biz.netcentric.vlt.upgrade.util.PackageInstallLoggerImpl;

/**
* This class represents a previous upgrade execution and has methods to compare
* the current execution with the former.
*/
public class UpgradeStatus {

private static final PackageInstallLogger LOG = PackageInstallLoggerImpl.create(UpgradeStatus.class);
private static final PackageInstallLogger LOG = PackageInstallLogger.create(UpgradeStatus.class);

public static final String PN_UPGRADE_TIME = "time";
public static final String PN_VERSION = "version";
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ public interface UpgradeHandler {
* @return
* @throws RepositoryException
*/
Iterable<UpgradeAction> create(InstallContext ctx, UpgradeActionInfo info) throws RepositoryException;
Iterable<UpgradeAction> create(InstallContext ctx, UpgradeInfo info) throws RepositoryException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@
import biz.netcentric.vlt.upgrade.UpgradeAction;
import biz.netcentric.vlt.upgrade.UpgradeInfo;
import biz.netcentric.vlt.upgrade.handler.OsgiUtil;
import biz.netcentric.vlt.upgrade.handler.UpgradeActionInfo;
import biz.netcentric.vlt.upgrade.handler.UpgradeHandler;
import biz.netcentric.vlt.upgrade.util.PackageInstallLogger;
import biz.netcentric.vlt.upgrade.util.PackageInstallLoggerImpl;

/**
* This handler creates {@link GroovyScript} instances which are executed via
Expand All @@ -35,23 +33,23 @@
*/
public class GroovyConsoleHandler implements UpgradeHandler {

static PackageInstallLogger LOG = PackageInstallLoggerImpl.create(GroovyConsoleHandler.class);
static PackageInstallLogger log = PackageInstallLogger.create(GroovyConsoleHandler.class);

OsgiUtil osgi = new OsgiUtil();

@Override
public boolean isAvailable(InstallContext ctx) {
boolean available = osgi.hasService(GroovyConsoleService.class);
if (!available) {
LOG.warn(ctx, "Could not load GroovyConsoleService.");
log.warn(ctx, "Could not load GroovyConsoleService.");
}
return available;

}


@Override
public List<UpgradeAction> create(InstallContext ctx, UpgradeActionInfo info) throws RepositoryException {
public List<UpgradeAction> create(InstallContext ctx, UpgradeInfo info) throws RepositoryException {
List<UpgradeAction> scripts = new ArrayList<>();

NodeIterator nodes = info.getNode().getNodes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@
import biz.netcentric.vlt.upgrade.handler.OsgiUtil.ServiceWrapper;
import biz.netcentric.vlt.upgrade.handler.SlingUtils;
import biz.netcentric.vlt.upgrade.util.PackageInstallLogger;
import biz.netcentric.vlt.upgrade.util.PackageInstallLoggerImpl;

public class GroovyScript extends UpgradeAction {

private static final PackageInstallLogger LOG = PackageInstallLoggerImpl.create(GroovyScript.class);
private static final PackageInstallLogger LOG = PackageInstallLogger.create(GroovyScript.class);

SlingUtils sling = new SlingUtils();
private final Node script;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@

import biz.netcentric.vlt.upgrade.UpgradeAction;
import biz.netcentric.vlt.upgrade.util.PackageInstallLogger;
import biz.netcentric.vlt.upgrade.util.PackageInstallLoggerImpl;

public class Script extends UpgradeAction {

private static final PackageInstallLogger LOG = PackageInstallLoggerImpl.create(Script.class);
private static final PackageInstallLogger LOG = PackageInstallLogger.create(Script.class);

private final SlingScript delegate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
import org.apache.sling.api.scripting.SlingScript;

import biz.netcentric.vlt.upgrade.UpgradeAction;
import biz.netcentric.vlt.upgrade.UpgradeInfo;
import biz.netcentric.vlt.upgrade.handler.SlingUtils;
import biz.netcentric.vlt.upgrade.handler.UpgradeActionInfo;
import biz.netcentric.vlt.upgrade.handler.UpgradeHandler;
import biz.netcentric.vlt.upgrade.util.PackageInstallLogger;
import biz.netcentric.vlt.upgrade.util.PackageInstallLoggerImpl;

public class ScriptHandler implements UpgradeHandler {

private static final PackageInstallLogger LOG = PackageInstallLoggerImpl.create(ScriptHandler.class);
private static final PackageInstallLogger LOG = PackageInstallLogger.create(ScriptHandler.class);

SlingUtils sling = new SlingUtils();

Expand All @@ -29,7 +28,7 @@ public boolean isAvailable(final InstallContext ctx) {
}

@Override
public Iterable<UpgradeAction> create(final InstallContext ctx, final UpgradeActionInfo info) throws RepositoryException {
public Iterable<UpgradeAction> create(final InstallContext ctx, final UpgradeInfo info) throws RepositoryException {
final List<UpgradeAction> scripts = new ArrayList<>();

final Resource root = sling.getResourceResolver(ctx.getSession()).getResource(info.getNode().getPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
import biz.netcentric.vlt.upgrade.handler.OsgiUtil;
import biz.netcentric.vlt.upgrade.handler.OsgiUtil.ServiceWrapper;
import biz.netcentric.vlt.upgrade.util.PackageInstallLogger;
import biz.netcentric.vlt.upgrade.util.PackageInstallLoggerImpl;

public class SlingPipe extends UpgradeAction {

private static final PackageInstallLogger LOG = PackageInstallLoggerImpl.create(SlingPipe.class);
private static final PackageInstallLogger LOG = PackageInstallLogger.create(SlingPipe.class);

OsgiUtil osgi = new OsgiUtil();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@
import org.apache.sling.pipes.Plumber;

import biz.netcentric.vlt.upgrade.UpgradeAction;
import biz.netcentric.vlt.upgrade.UpgradeInfo;
import biz.netcentric.vlt.upgrade.handler.SlingUtils;
import biz.netcentric.vlt.upgrade.handler.UpgradeActionInfo;
import biz.netcentric.vlt.upgrade.handler.UpgradeHandler;
import biz.netcentric.vlt.upgrade.util.PackageInstallLogger;
import biz.netcentric.vlt.upgrade.util.PackageInstallLoggerImpl;

public class SlingPipesHandler implements UpgradeHandler {

private static final PackageInstallLogger LOG = PackageInstallLoggerImpl.create(SlingPipesHandler.class);
private static final PackageInstallLogger LOG = PackageInstallLogger.create(SlingPipesHandler.class);

SlingUtils sling = new SlingUtils();

Expand All @@ -40,7 +39,7 @@ public boolean isAvailable(InstallContext ctx) {
}

@Override
public Iterable<UpgradeAction> create(InstallContext ctx, UpgradeActionInfo info) throws RepositoryException {
public Iterable<UpgradeAction> create(InstallContext ctx, UpgradeInfo info) throws RepositoryException {
Collection<UpgradeAction> pipes = new ArrayList<>();
for (Resource child : sling.getResourceResolver(info.getNode().getSession())
.getResource(info.getNode().getPath()).getChildren()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@
import org.apache.jackrabbit.vault.packaging.InstallContext;

import biz.netcentric.vlt.upgrade.UpgradeAction;
import biz.netcentric.vlt.upgrade.handler.UpgradeActionInfo;
import biz.netcentric.vlt.upgrade.UpgradeInfo;
import biz.netcentric.vlt.upgrade.handler.UpgradeHandler;
import biz.netcentric.vlt.upgrade.util.PackageInstallLogger;
import biz.netcentric.vlt.upgrade.util.PackageInstallLoggerImpl;

public class UserPreferencesHandler implements UpgradeHandler {

private static final String PN_USER_IDS = "handler.userIds";
private static final String NAME_SUFFIX_USER_PREFERENCES = "user.preferences";
private static final PackageInstallLogger LOG = PackageInstallLoggerImpl.create(UserPreferencesHandler.class);
private static final PackageInstallLogger LOG = PackageInstallLogger.create(UserPreferencesHandler.class);

@Override
public boolean isAvailable(InstallContext ctx) {
Expand All @@ -32,7 +31,7 @@ public boolean isAvailable(InstallContext ctx) {
}

@Override
public Iterable<UpgradeAction> create(InstallContext ctx, UpgradeActionInfo info) throws RepositoryException {
public Iterable<UpgradeAction> create(InstallContext ctx, UpgradeInfo info) throws RepositoryException {
List<UpgradeAction> actions = new ArrayList<>();

// extract user id from upgrade info node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@

import biz.netcentric.vlt.upgrade.UpgradeAction;
import biz.netcentric.vlt.upgrade.util.PackageInstallLogger;
import biz.netcentric.vlt.upgrade.util.PackageInstallLoggerImpl;

public class UserPreferencesUpgradeAction extends UpgradeAction {

private static final PackageInstallLogger LOG = PackageInstallLoggerImpl.create(UserPreferencesUpgradeAction.class);
private static final PackageInstallLogger LOG = PackageInstallLogger.create(UserPreferencesUpgradeAction.class);

private final Node xmlFileNode;
private final String userId;
Expand Down
Loading

0 comments on commit 9b79f13

Please sign in to comment.