Skip to content

Commit 3a7fb27

Browse files
Support packaging OSGi bundles in "all" content package file and local installation (#10)
Also generate "all" content packgage for environment if configured explicitly, even if it is configure to cloudManager.target=node.
1 parent 3b9188a commit 3a7fb27

22 files changed

Lines changed: 621 additions & 190 deletions

changes.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
<action type="add" dev="sseifert">
2828
conga-aem-maven-plugin: Add new parameter packageTypeValidation which controls how to handle packages with invalid or without package types.
2929
</action>
30+
<action type="add" dev="sseifert">
31+
conga-aem-maven-plugin: Support to include OSGi bundles referenced in CONGA definitions to be directly included in "all" content package, or deployed to a local AEM instance.
32+
</action>
33+
<action type="update" dev="sseifert">
34+
conga-aem-maven-plugin: Generate "all" content packgage for environment if configured explicitly, even if it is configure to cloudManager.target=node.
35+
</action>
3036
<action type="update" dev="sseifert">
3137
Content Package Validator: Update to filevault-package-maven-plugin 1.3.0.
3238
</action>

tooling/conga-aem-maven-plugin/src/main/java/io/wcm/devops/conga/plugins/aem/maven/AbstractCloudManagerMojo.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ protected List<File> getEnvironmentDir() throws MojoExecutionException {
9393
return directories;
9494
}
9595

96+
/**
97+
* Checks if the given environment was configured explicitly in plugin configuration.
98+
* @param environment Environment name
99+
* @return true if configured explicitly
100+
*/
101+
protected boolean isEnvironmentConfiguredExplicitely(String environment) {
102+
Set<String> selectedEnvironments = toSet(this.environments);
103+
return selectedEnvironments.contains(environment);
104+
}
105+
96106
/**
97107
* Get matching node directories from environment.
98108
* @param environmentDir Environment directory

tooling/conga-aem-maven-plugin/src/main/java/io/wcm/devops/conga/plugins/aem/maven/AbstractContentPackageMojo.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
*/
4141
abstract class AbstractContentPackageMojo extends AbstractMojo {
4242

43+
private static final String CONSOLE_URL = "/system/console";
44+
4345
/**
4446
* <p>
4547
* The URL of the HTTP service API of the CRX package manager.
@@ -245,4 +247,16 @@ private String buildBundleStatusUrl() throws MojoExecutionException {
245247
return baseUrl + "/system/console/bundles/.json";
246248
}
247249

250+
protected String buildConsoleUrl() {
251+
return VendorInstallerFactory.getBaseUrl(this.serviceURL) + CONSOLE_URL;
252+
}
253+
254+
protected String getConsoleUser() {
255+
return this.consoleUserId;
256+
}
257+
258+
protected String getConsolePassword() {
259+
return this.consolePassword;
260+
}
261+
248262
}

tooling/conga-aem-maven-plugin/src/main/java/io/wcm/devops/conga/plugins/aem/maven/CloudManagerAllPackageMojo.java

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import org.apache.maven.project.MavenProjectHelper;
3737

3838
import io.wcm.devops.conga.plugins.aem.maven.allpackage.AllPackageBuilder;
39-
import io.wcm.devops.conga.plugins.aem.maven.model.ContentPackageFile;
39+
import io.wcm.devops.conga.plugins.aem.maven.model.InstallableFile;
4040
import io.wcm.devops.conga.plugins.aem.maven.model.ModelParser;
4141

4242
/**
@@ -180,12 +180,12 @@ public void execute() throws MojoExecutionException, MojoFailureException {
180180
* Build an "all" package for each environment and node.
181181
*/
182182
private void buildAllPackagesPerEnvironmentNode() throws MojoExecutionException, MojoFailureException {
183-
visitEnvironmentsNodes((environmentDir, nodeDir, cloudManagerTarget, contentPackages) -> {
183+
visitEnvironmentsNodes((environmentDir, nodeDir, cloudManagerTarget, files) -> {
184184
String packageName = environmentDir.getName() + "." + nodeDir.getName() + "." + this.name;
185185
AllPackageBuilder builder = createBuilder(packageName);
186186

187187
try {
188-
builder.add(contentPackages, cloudManagerTarget);
188+
builder.add(files, cloudManagerTarget);
189189
}
190190
catch (IllegalArgumentException ex) {
191191
throw new MojoFailureException(ex.getMessage(), ex);
@@ -202,9 +202,9 @@ private void buildSingleAllPackage() throws MojoExecutionException, MojoFailureE
202202
String packageName = this.name;
203203
AllPackageBuilder builder = createBuilder(packageName);
204204

205-
visitEnvironmentsNodes((environmentDir, nodeDir, cloudManagerTarget, contentPackages) -> {
205+
visitEnvironmentsNodes((environmentDir, nodeDir, cloudManagerTarget, files) -> {
206206
try {
207-
builder.add(contentPackages, cloudManagerTarget);
207+
builder.add(files, cloudManagerTarget);
208208
}
209209
catch (IllegalArgumentException ex) {
210210
throw new MojoFailureException(ex.getMessage(), ex);
@@ -249,23 +249,37 @@ private void buildAllPackage(AllPackageBuilder builder) throws MojoExecutionExce
249249
}
250250

251251
private void visitEnvironmentsNodes(EnvironmentNodeVisitor visitor) throws MojoExecutionException, MojoFailureException {
252-
ModelParser modelParser = new ModelParser();
253252
List<File> environmentDirs = getEnvironmentDir();
254253
for (File environmentDir : environmentDirs) {
255254
List<File> nodeDirs = getNodeDirs(environmentDir);
256255
for (File nodeDir : nodeDirs) {
257-
Set<String> cloudManagerTarget = modelParser.getCloudManagerTarget(nodeDir);
258-
if (!cloudManagerTarget.contains(CLOUDMANAGER_TARGET_NONE)) {
259-
List<? extends ContentPackageFile> contentPackages = modelParser.getContentPackagesForNode(nodeDir);
260-
visitor.visit(environmentDir, nodeDir, cloudManagerTarget, contentPackages);
256+
ModelParser modelParser = new ModelParser(nodeDir);
257+
Set<String> cloudManagerTarget = modelParser.getCloudManagerTarget();
258+
259+
boolean validNodeForAllPackage = false;
260+
if (cloudManagerTarget.contains(CLOUDMANAGER_TARGET_NONE)) {
261+
if (isEnvironmentConfiguredExplicitely(environmentDir.getName())) {
262+
// cloud manager target is set to "none" - but environment is configured explicitly, so include it
263+
validNodeForAllPackage = true;
264+
cloudManagerTarget.remove(CLOUDMANAGER_TARGET_NONE);
265+
}
266+
}
267+
else {
268+
// cloud manager target is not set to "none" - include node
269+
validNodeForAllPackage = true;
270+
}
271+
272+
if (validNodeForAllPackage) {
273+
List<InstallableFile> files = modelParser.getInstallableFilesForNode();
274+
visitor.visit(environmentDir, nodeDir, cloudManagerTarget, files);
261275
}
262276
}
263277
}
264278
}
265279

266280
interface EnvironmentNodeVisitor {
267281
void visit(File environmentDir, File nodeDir, Set<String> cloudManagerTarget,
268-
List<? extends ContentPackageFile> contentPackages) throws MojoExecutionException, MojoFailureException;
282+
List<InstallableFile> files) throws MojoExecutionException, MojoFailureException;
269283
}
270284

271285
}

tooling/conga-aem-maven-plugin/src/main/java/io/wcm/devops/conga/plugins/aem/maven/CloudManagerDispatcherConfigMojo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ public void execute() throws MojoExecutionException, MojoFailureException {
6969
List<File> environmentDirs = getEnvironmentDir();
7070
for (File environmentDir : environmentDirs) {
7171
List<File> nodeDirs = getNodeDirs(environmentDir);
72-
ModelParser modelParser = new ModelParser();
7372
for (File nodeDir : nodeDirs) {
74-
if (modelParser.hasRole(nodeDir, ROLE_AEM_DISPATCHER_CLOUD)) {
73+
ModelParser modelParser = new ModelParser(nodeDir);
74+
if (modelParser.hasRole(ROLE_AEM_DISPATCHER_CLOUD)) {
7575
buildDispatcherConfig(environmentDir, nodeDir);
7676
dispatcherNodeCount++;
7777
}

tooling/conga-aem-maven-plugin/src/main/java/io/wcm/devops/conga/plugins/aem/maven/InstallPackagesMojo.java

Lines changed: 103 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,34 @@
2323

2424
import java.io.File;
2525
import java.util.List;
26-
import java.util.stream.Collectors;
2726

27+
import org.apache.maven.execution.MavenSession;
28+
import org.apache.maven.model.Plugin;
29+
import org.apache.maven.plugin.BuildPluginManager;
30+
import org.apache.maven.plugin.MavenPluginManager;
31+
import org.apache.maven.plugin.MojoExecution;
2832
import org.apache.maven.plugin.MojoExecutionException;
2933
import org.apache.maven.plugin.MojoFailureException;
34+
import org.apache.maven.plugin.descriptor.MojoDescriptor;
35+
import org.apache.maven.plugin.descriptor.PluginDescriptor;
36+
import org.apache.maven.plugins.annotations.Component;
3037
import org.apache.maven.plugins.annotations.Mojo;
3138
import org.apache.maven.plugins.annotations.Parameter;
39+
import org.apache.maven.project.MavenProject;
40+
import org.codehaus.plexus.configuration.PlexusConfiguration;
41+
import org.codehaus.plexus.configuration.PlexusConfigurationException;
42+
import org.codehaus.plexus.util.xml.Xpp3Dom;
3243

44+
import io.wcm.devops.conga.plugins.aem.maven.model.BundleFile;
45+
import io.wcm.devops.conga.plugins.aem.maven.model.InstallableFile;
3346
import io.wcm.devops.conga.plugins.aem.maven.model.ModelContentPackageFile;
3447
import io.wcm.devops.conga.plugins.aem.maven.model.ModelParser;
3548
import io.wcm.tooling.commons.packmgr.install.PackageFile;
3649
import io.wcm.tooling.commons.packmgr.install.PackageInstaller;
3750

3851
/**
39-
* Installs all AEM content packages to AEM which are referenced in a model.yaml generated by CONGA for a node.
52+
* Installs all AEM content packages and OSGi bundles to AEM which are referenced in a model.yaml
53+
* generated by CONGA for a node.
4054
*/
4155
@Mojo(name = "package-install", threadSafe = true, requiresProject = false)
4256
public final class InstallPackagesMojo extends AbstractContentPackageMojo {
@@ -82,6 +96,21 @@ public final class InstallPackagesMojo extends AbstractContentPackageMojo {
8296
@Parameter(property = "vault.replicatePackage")
8397
private boolean replicate;
8498

99+
/**
100+
* Version of Sling plugin
101+
*/
102+
@Parameter(property = "sling.plugin.version", required = true, defaultValue = "2.4.2")
103+
private String slingPluginVersion;
104+
105+
@Parameter(defaultValue = "${project}", readonly = true)
106+
private MavenProject project;
107+
@Parameter(defaultValue = "${session}", readonly = true)
108+
private MavenSession session;
109+
@Component(role = MavenPluginManager.class)
110+
private MavenPluginManager pluginManager;
111+
@Component(role = BuildPluginManager.class)
112+
private BuildPluginManager buildPluginManager;
113+
85114
@Override
86115
public void execute() throws MojoExecutionException, MojoFailureException {
87116
if (isSkip()) {
@@ -95,10 +124,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {
95124
getLog().info("Get AEM content packages from " + getCanonicalPath(nodeDirectory));
96125

97126
// collect files to install
98-
ModelParser modelParser = new ModelParser();
99-
List<PackageFile> items = modelParser.getContentPackagesForNode(nodeDirectory).stream()
100-
.map(this::toPackageFile)
101-
.collect(Collectors.toList());
127+
ModelParser modelParser = new ModelParser(nodeDirectory);
128+
List<InstallableFile> items = modelParser.getInstallableFilesForNode();
102129

103130
// ensure any file exist
104131
if (items.isEmpty()) {
@@ -109,33 +136,52 @@ public void execute() throws MojoExecutionException, MojoFailureException {
109136
// install files
110137
PackageInstaller installer = new PackageInstaller(getPackageManagerProperties());
111138
installer.setReplicate(this.replicate);
112-
installer.installFiles(items);
139+
140+
for (InstallableFile item : items) {
141+
if (item instanceof ModelContentPackageFile) {
142+
PackageFile packageFile = toPackageFile((ModelContentPackageFile)item);
143+
installer.installFile(packageFile);
144+
}
145+
else if (item instanceof BundleFile) {
146+
BundleFile bundleFile = (BundleFile)item;
147+
if (bundleFile.getInstall() == null || bundleFile.getInstall()) {
148+
installBundleViaSlingPlugin(bundleFile.getFile());
149+
}
150+
}
151+
else {
152+
getLog().warn("Unsupported file: " + getCanonicalPath(item.getFile()));
153+
}
154+
}
113155
}
114156

115157
private PackageFile toPackageFile(ModelContentPackageFile item) {
116158
PackageFile output = new PackageFile();
117159

118160
output.setFile(item.getFile());
119-
if (item.getInstall() != null) {
120-
output.setInstall(item.getInstall());
161+
Boolean installParam = item.getInstall();
162+
if (installParam != null) {
163+
output.setInstall(installParam);
121164
}
122165
else {
123166
output.setInstall(this.install);
124167
}
125-
if (item.getForce() != null) {
126-
output.setForce(item.getForce());
168+
Boolean forcePAram = item.getForce();
169+
if (forcePAram != null) {
170+
output.setForce(forcePAram);
127171
}
128172
else {
129173
output.setForce(this.force);
130174
}
131-
if (item.getRecursive() != null) {
132-
output.setRecursive(item.getRecursive());
175+
Boolean recursiveParam = item.getRecursive();
176+
if (recursiveParam != null) {
177+
output.setRecursive(recursiveParam);
133178
}
134179
else {
135180
output.setRecursive(this.recursive);
136181
}
137-
if (item.getDelayAfterInstallSec() != null) {
138-
output.setDelayAfterInstallSec(item.getDelayAfterInstallSec());
182+
Integer delayAfterInstallSecParam = item.getDelayAfterInstallSec();
183+
if (delayAfterInstallSecParam != null) {
184+
output.setDelayAfterInstallSec(delayAfterInstallSecParam);
139185
}
140186
else if (this.delayAfterInstallSec != null) {
141187
output.setDelayAfterInstallSec(this.delayAfterInstallSec);
@@ -148,4 +194,46 @@ else if (this.delayAfterInstallSec != null) {
148194
return output;
149195
}
150196

197+
/**
198+
* Executes the sling-maven-plugin directly from the current project to install OSGi bundles.
199+
*/
200+
private void installBundleViaSlingPlugin(File file) throws MojoExecutionException {
201+
Plugin plugin = new Plugin();
202+
plugin.setGroupId("org.apache.sling");
203+
plugin.setArtifactId("sling-maven-plugin");
204+
plugin.setVersion(this.slingPluginVersion);
205+
206+
try {
207+
PluginDescriptor pluginDescriptor = pluginManager.getPluginDescriptor(plugin,
208+
project.getRemotePluginRepositories(), session.getRepositorySession());
209+
MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo("install-file");
210+
MojoExecution mojoExecution = new MojoExecution(pluginDescriptor.getMojo("install-file"));
211+
212+
Xpp3Dom config = convertConfiguration(mojoDescriptor.getMojoConfiguration());
213+
config.getChild("slingUrl").setValue(buildConsoleUrl());
214+
config.getChild("user").setValue(this.getConsoleUser());
215+
config.getChild("password").setValue(this.getConsolePassword());
216+
config.getChild("mountByFS").setValue("false");
217+
config.getChild("bundleFileName").setValue(file.getAbsolutePath());
218+
mojoExecution.setConfiguration(config);
219+
220+
buildPluginManager.executeMojo(session, mojoExecution);
221+
}
222+
catch (Exception ex) {
223+
throw new MojoExecutionException("Faild to execute plugin: " + plugin, ex);
224+
}
225+
}
226+
227+
private Xpp3Dom convertConfiguration(PlexusConfiguration plexusConfig) throws PlexusConfigurationException {
228+
Xpp3Dom config = new Xpp3Dom(plexusConfig.getName());
229+
config.setValue(plexusConfig.getValue());
230+
for (String attribute : plexusConfig.getAttributeNames()) {
231+
config.setAttribute(attribute, plexusConfig.getAttribute(attribute));
232+
}
233+
for (PlexusConfiguration child : plexusConfig.getChildren()) {
234+
config.addChild(convertConfiguration(child));
235+
}
236+
return config;
237+
}
238+
151239
}

0 commit comments

Comments
 (0)