-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement AbstractInstallCommandTask
- Loading branch information
eschleb
committed
Dec 13, 2024
1 parent
5320a4d
commit 17db109
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
...k/src/main/java/com/merkle/oss/magnolia/setup/task/common/AbstractInstallCommandTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.merkle.oss.magnolia.setup.task.common; | ||
|
||
import info.magnolia.commands.MgnlCommand; | ||
import info.magnolia.jcr.nodebuilder.NodeOperation; | ||
import info.magnolia.jcr.nodebuilder.task.ErrorHandling; | ||
import info.magnolia.jcr.util.NodeTypes; | ||
import info.magnolia.module.InstallContext; | ||
import info.magnolia.repository.RepositoryConstants; | ||
|
||
import java.lang.invoke.MethodHandles; | ||
import java.text.MessageFormat; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.merkle.oss.magnolia.powernode.NodeOperationFactory; | ||
import com.merkle.oss.magnolia.setup.task.nodebuilder.AbstractPathNodeBuilderTask; | ||
|
||
/** | ||
* Base class for command install tasks. | ||
*/ | ||
public abstract class AbstractInstallCommandTask extends AbstractPathNodeBuilderTask { | ||
private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); | ||
|
||
public static final String MODULE_PATH = "modules/{0}"; | ||
|
||
private final NodeOperationFactory ops; | ||
private final String catalog; | ||
private final String name; | ||
private final Class<? extends MgnlCommand> clazz; | ||
|
||
protected AbstractInstallCommandTask( | ||
final NodeOperationFactory nodeOperationFactory, | ||
final String catalog, | ||
final String name, | ||
final Class<? extends MgnlCommand> clazz | ||
) { | ||
super("Install command " + name, "Install command " + name + " in catalog " + catalog, ErrorHandling.strict, RepositoryConstants.CONFIG); | ||
this.ops = nodeOperationFactory; | ||
this.catalog = catalog; | ||
this.name = name; | ||
this.clazz = clazz; | ||
} | ||
|
||
@Override | ||
protected NodeOperation[] getNodeOperations(final InstallContext ctx) { | ||
final String moduleName = ctx.getCurrentModuleDefinition().getName(); | ||
final String modulePath = MessageFormat.format(MODULE_PATH, moduleName); | ||
LOG.info("installing command '{}' for module {}", name, modulePath); | ||
return new NodeOperation[]{ | ||
ops.getOrAddNode(modulePath, NodeTypes.Content.NAME).then( | ||
ops.getOrAddNode("commands", NodeTypes.Content.NAME).then( | ||
ops.getOrAddNode(catalog, NodeTypes.Content.NAME).then( | ||
ops.getOrAddContentNode(name).then( | ||
ops.setClassProperty(clazz) | ||
) | ||
) | ||
) | ||
) | ||
}; | ||
} | ||
} |