You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2015/11/24 20:50:46 UTC
[03/10] karaf git commit: KARAF-3982: wire this up to the Builder and
the mojo.
KARAF-3982: wire this up to the Builder and the mojo.
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/2b170904
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/2b170904
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/2b170904
Branch: refs/heads/master
Commit: 2b1709045d79ea0d24e3cc4bd5d4b762b460872a
Parents: 04840c8
Author: Benson Margulies <be...@basistech.com>
Authored: Wed Sep 9 10:35:21 2015 -0400
Committer: Benson Margulies <be...@basistech.com>
Committed: Wed Sep 9 10:35:21 2015 -0400
----------------------------------------------------------------------
profile/pom.xml | 6 ++
.../apache/karaf/profile/assembly/Builder.java | 25 +++++++
tooling/karaf-maven-plugin/pom.xml | 8 +-
.../src/it/test-assembly-prop-edits/pom.xml | 78 ++++++++++++++++++++
.../org/apache/karaf/tooling/AssemblyMojo.java | 46 ++++++++++++
tooling/utils/pom.xml | 11 +++
6 files changed, 171 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/2b170904/profile/pom.xml
----------------------------------------------------------------------
diff --git a/profile/pom.xml b/profile/pom.xml
index 2045cb3..fc3c2a5 100644
--- a/profile/pom.xml
+++ b/profile/pom.xml
@@ -71,6 +71,12 @@
</dependency>
<dependency>
+ <groupId>org.apache.karaf.tooling</groupId>
+ <artifactId>org.apache.karaf.tools.utils</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.karaf.shell</groupId>
<artifactId>org.apache.karaf.shell.core</artifactId>
<optional>true</optional>
http://git-wip-us.apache.org/repos/asf/karaf/blob/2b170904/profile/src/main/java/org/apache/karaf/profile/assembly/Builder.java
----------------------------------------------------------------------
diff --git a/profile/src/main/java/org/apache/karaf/profile/assembly/Builder.java b/profile/src/main/java/org/apache/karaf/profile/assembly/Builder.java
index dd0e623..b644ac3 100644
--- a/profile/src/main/java/org/apache/karaf/profile/assembly/Builder.java
+++ b/profile/src/main/java/org/apache/karaf/profile/assembly/Builder.java
@@ -75,6 +75,9 @@ import org.apache.karaf.kar.internal.Kar;
import org.apache.karaf.profile.Profile;
import org.apache.karaf.profile.ProfileBuilder;
import org.apache.karaf.profile.impl.Profiles;
+import org.apache.karaf.tools.utils.KarafPropertiesEditor;
+import org.apache.karaf.tools.utils.model.KarafPropertyEdit;
+import org.apache.karaf.tools.utils.model.KarafPropertyEdits;
import org.apache.karaf.util.config.PropertiesLoader;
import org.apache.karaf.util.maven.Parser;
import org.ops4j.pax.url.mvn.MavenResolver;
@@ -154,6 +157,7 @@ public class Builder {
private Path etcDirectory;
private Path systemDirectory;
private Map<String, Profile> allProfiles;
+ private KarafPropertyEdits propertyEdits;
public static Builder newInstance() {
return new Builder();
@@ -336,6 +340,16 @@ public class Builder {
return this;
}
+ /**
+ * Specify a set of edits to apply when moving etc files.
+ * @param propertyEdits the edits.
+ * @return this.
+ */
+ public Builder propertyEdits(KarafPropertyEdits propertyEdits) {
+ this.propertyEdits = propertyEdits;
+ return this;
+ }
+
public List<String> getBlacklistedProfiles() {
return blacklistedProfiles;
}
@@ -486,6 +500,8 @@ public class Builder {
}
}, false, false, true);
+ Map<String, List<KarafPropertyEdit>> editsByFile = new HashMap<>();
+
//
// Write config and system properties
//
@@ -522,6 +538,15 @@ public class Builder {
Files.write(configFile, config.getValue());
}
+ // 'improve' configuration files.
+ if (propertyEdits != null) {
+ KarafPropertiesEditor editor = new KarafPropertiesEditor();
+ editor.setInputEtc(etcDirectory.toFile())
+ .setOutputEtc(etcDirectory.toFile())
+ .setEdits(propertyEdits);
+ editor.run();
+ }
+
//
// Handle overrides
//
http://git-wip-us.apache.org/repos/asf/karaf/blob/2b170904/tooling/karaf-maven-plugin/pom.xml
----------------------------------------------------------------------
diff --git a/tooling/karaf-maven-plugin/pom.xml b/tooling/karaf-maven-plugin/pom.xml
index 9aa63d4..67998e4 100644
--- a/tooling/karaf-maven-plugin/pom.xml
+++ b/tooling/karaf-maven-plugin/pom.xml
@@ -92,13 +92,15 @@
<groupId>org.apache.karaf</groupId>
<artifactId>org.apache.karaf.util</artifactId>
</dependency>
-
-
+ <dependency>
+ <groupId>org.apache.karaf.tooling</groupId>
+ <artifactId>org.apache.karaf.tools.utils</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
</dependency>
-
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-filtering</artifactId>
http://git-wip-us.apache.org/repos/asf/karaf/blob/2b170904/tooling/karaf-maven-plugin/src/it/test-assembly-prop-edits/pom.xml
----------------------------------------------------------------------
diff --git a/tooling/karaf-maven-plugin/src/it/test-assembly-prop-edits/pom.xml b/tooling/karaf-maven-plugin/src/it/test-assembly-prop-edits/pom.xml
new file mode 100644
index 0000000..886ef11
--- /dev/null
+++ b/tooling/karaf-maven-plugin/src/it/test-assembly-prop-edits/pom.xml
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>test</groupId>
+ <artifactId>test-assembl-prop-edits</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>karaf-assembly</packaging>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.karaf.features</groupId>
+ <artifactId>framework</artifactId>
+ <version>@pom.version@</version>
+ <type>kar</type>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.karaf.features</groupId>
+ <artifactId>standard</artifactId>
+ <version>@pom.version@</version>
+ <classifier>features</classifier>
+ <type>xml</type>
+ <scope>runtime</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.karaf.tooling</groupId>
+ <artifactId>karaf-maven-plugin</artifactId>
+ <version>@pom.version@</version>
+ <extensions>true</extensions>
+ <configuration>
+ <finalName>${project.artifactId}</finalName>
+ <bootFeatures>
+ <feature>bundle</feature>
+ <feature>config</feature>
+ <feature>diagnostic</feature>
+ <feature>feature</feature>
+ <feature>jaas</feature>
+ <feature>shell</feature>
+ <feature>log</feature>
+ <feature>management</feature>
+ <feature>package</feature>
+ <feature>shell-compat</feature>
+ <feature>ssh</feature>
+ <feature>system</feature>
+ <feature>wrap</feature>
+ </bootFeatures>
+ <archiveZip>false</archiveZip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
http://git-wip-us.apache.org/repos/asf/karaf/blob/2b170904/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/AssemblyMojo.java
----------------------------------------------------------------------
diff --git a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/AssemblyMojo.java b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/AssemblyMojo.java
index 44ebcbe..c0653c5 100644
--- a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/AssemblyMojo.java
+++ b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/AssemblyMojo.java
@@ -22,6 +22,9 @@ import org.apache.karaf.profile.assembly.Builder;
import org.apache.karaf.tooling.utils.IoUtils;
import org.apache.karaf.tooling.utils.MavenUtil;
import org.apache.karaf.tooling.utils.MojoSupport;
+import org.apache.karaf.tools.utils.KarafPropertiesEditor;
+import org.apache.karaf.tools.utils.model.KarafPropertyEdits;
+import org.apache.karaf.tools.utils.model.io.stax.KarafPropertyInstructionsModelStaxReader;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
@@ -31,6 +34,8 @@ import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.attribute.PosixFilePermissions;
import java.util.ArrayList;
@@ -173,6 +178,35 @@ public class AssemblyMojo extends MojoSupport {
@Parameter(defaultValue = "1.7")
protected String javase;
+ /**
+ * Specify an XML file that instructs this goal to apply edits to
+ * one or more standard Karaf property files. This allows you to
+ * customize these files without making copies in your resources
+ * directories. Here's a simple example:
+ * <pre>
+ * {@literal
+ <property-edits xmlns="http://karaf.apache.org/tools/property-edits/1.0.0">
+ <edits>
+ <edit>
+ <file>config.properties</file>
+ <operation>put</operation>
+ <key>karaf.framework</key>
+ <value>equinox</value>
+ </edit>
+ <edit>
+ <file>config.properties</file>
+ <operation>extend</operation>
+ <key>org.osgi.framework.system.capabilities</key>
+ <value>my-magic-capability</value>
+ </edit>
+ </edits>
+ </property-edits>
+ </pre>
+ }
+ */
+ @Parameter(defaultValue = "${project.basedir}/src/main/karaf/assembly-property-edits.xml")
+ protected String propertyFileEdits;
+
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
try {
@@ -226,6 +260,18 @@ public class AssemblyMojo extends MojoSupport {
builder.blacklistProfiles(blacklistedProfiles);
builder.blacklistPolicy(blacklistPolicy);
+ if (propertyFileEdits != null) {
+ File file = new File(propertyFileEdits);
+ if (file.exists()) {
+ KarafPropertyEdits edits;
+ try (InputStream editsStream = new FileInputStream(propertyFileEdits)) {
+ KarafPropertyInstructionsModelStaxReader kipmsr = new KarafPropertyInstructionsModelStaxReader();
+ edits = kipmsr.read(editsStream, true);
+ }
+ builder.propertyEdits(edits);
+ }
+ }
+
// creating system directory
getLog().info("Creating work directory");
builder.homeDirectory(workDirectory.toPath());
http://git-wip-us.apache.org/repos/asf/karaf/blob/2b170904/tooling/utils/pom.xml
----------------------------------------------------------------------
diff --git a/tooling/utils/pom.xml b/tooling/utils/pom.xml
index ece56ce..7688e25 100644
--- a/tooling/utils/pom.xml
+++ b/tooling/utils/pom.xml
@@ -69,6 +69,17 @@
<version>1.0.0</version>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.karaf.tools.utils
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>