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 2014/09/25 21:33:44 UTC
git commit: Add features conditional support in install-kar goal
Repository: karaf
Updated Branches:
refs/heads/master 058ab718a -> 5cba362d6
Add features conditional support in install-kar goal
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/5cba362d
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/5cba362d
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/5cba362d
Branch: refs/heads/master
Commit: 5cba362d683e807ceb56698f1da716398a6eab3f
Parents: 058ab71
Author: Jean-Baptiste Onofré <jb...@apache.org>
Authored: Thu Sep 25 21:33:07 2014 +0200
Committer: Jean-Baptiste Onofré <jb...@apache.org>
Committed: Thu Sep 25 21:33:07 2014 +0200
----------------------------------------------------------------------
.../karaf/tooling/features/InstallKarsMojo.java | 174 ++++++++++++-------
1 file changed, 107 insertions(+), 67 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/5cba362d/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java
----------------------------------------------------------------------
diff --git a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java
index c724321..6e78565 100644
--- a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java
+++ b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java
@@ -384,86 +384,99 @@ public class InstallKarsMojo extends MojoSupport {
// installing feature bundles
getLog().info("= Installing bundles from " + feature.getName() + " feature");
for (Bundle bundle : feature.getBundle()) {
- if (!ignoreDependencyFlag && bundle.isDependency()) {
- getLog().warn("== Bundle " + bundle.getLocation() + " is defined as dependency, so it's not installed");
- } else {
- getLog().info("== Installing bundle " + bundle.getLocation());
- String bundleLocation = bundle.getLocation();
- // cleanup prefixes
- if (bundleLocation.startsWith("wrap:")) {
- bundleLocation = bundleLocation.substring("wrap:".length());
- int index = bundleLocation.indexOf("$");
- if (index != -1) {
- bundleLocation = bundleLocation.substring(0, index);
+ installBundle(bundle);
+ }
+
+ // installing feature config files
+ getLog().info("= Installing configuration files from " + feature.getName() + " feature");
+ for (ConfigFile configFile : feature.getConfigfile()) {
+ installConfigFile(configFile);
+ }
+
+ // installing condition features
+ for (Conditional conditional : feature.getConditional()) {
+ boolean found = true;
+ for (String condition : conditional.getCondition()) {
+ if (!condition.startsWith("req:")) {
+ if (!installedFeatures.contains(condition) && !bootFeatures.contains(condition)) {
+ found = false;
+ break;
}
}
- if (bundleLocation.startsWith("blueprint:")) {
- bundleLocation = bundleLocation.substring("blueprint:".length());
- }
- if (bundleLocation.startsWith("webbundle:")) {
- bundleLocation = bundleLocation.substring("webbundle:".length());
- }
- if (bundleLocation.startsWith("war:")) {
- bundleLocation = bundleLocation.substring("war:".length());
- }
- File bundleFile;
- if (bundleLocation.startsWith("mvn:")) {
- if (bundleLocation.endsWith("/")) {
- // for bad formed URL (like in Camel for mustache-compiler), we remove the trailing /
- bundleLocation = bundleLocation.substring(0, bundleLocation.length() - 1);
- }
- if (bundleLocation.startsWith("mvn:http")) {
- // cleanup the URL containing the repository location directly in the URL
- int index = bundleLocation.indexOf("!");
- if (index != -1) {
- bundleLocation = bundleLocation.substring(index + 1);
- bundleLocation = "mvn:" + bundleLocation;
+ }
+ if (found) {
+ getLog().info("= Installing conditional " + conditional.getCondition().toString());
+ getLog().debug("== Conditional features ...");
+ for (Dependency dependency : conditional.getFeature()) {
+ for (Feature f : features.keySet()) {
+ if (f.getName().equals(dependency.getName())) {
+ resolveFeature(f, features);
}
}
- bundleFile = dependencyHelper.resolveById(bundleLocation, getLog());
- bundleLocation = dependencyHelper.pathFromMaven(bundleLocation);
- } else {
- bundleFile = new File(new URI(bundleLocation));
}
- File bundleSystemFile = new File(system.resolve(bundleLocation));
- copy(bundleFile, bundleSystemFile);
- // add metadata for snapshot
- if (bundleLocation.startsWith("mvn")) {
- Artifact bundleArtifact = dependencyHelper.mvnToArtifact(bundleLocation);
- if (bundleArtifact.isSnapshot()) {
- File metadataTarget = new File(bundleSystemFile.getParentFile(), "maven-metadata-local.xml");
- try {
- MavenUtil.generateMavenMetadata(bundleArtifact, metadataTarget);
- } catch (Exception e) {
- getLog().warn("Could not create maven-metadata-local.xml", e);
- getLog().warn("It means that this SNAPSHOT could be overwritten by an older one present on remote repositories");
- }
- }
+ getLog().debug("== Conditional bundles");
+ for (Bundle bundle : conditional.getBundle()) {
+ installBundle(bundle);
+ }
+ getLog().debug("== Conditional configuration files");
+ for (ConfigFile configFile : conditional.getConfigfile()) {
+ installConfigFile(configFile);
}
}
}
+ }
- // installing feature config files
- getLog().info("= Installing configuration files from " + feature.getName() + " feature");
- for (ConfigFile configFile : feature.getConfigfile()) {
- getLog().warn("== Installing configuration file " + configFile.getLocation());
- String configFileLocation = configFile.getLocation();
- File configFileFile;
- if (configFileLocation.startsWith("mvn:")) {
- configFileFile = dependencyHelper.resolveById(configFileLocation, getLog());
- configFileLocation = dependencyHelper.pathFromMaven(configFileLocation);
+ private void installBundle(Bundle bundle) throws Exception {
+ if (!ignoreDependencyFlag && bundle.isDependency()) {
+ getLog().warn("== Bundle " + bundle.getLocation() + " is defined as dependency, so it's not installed");
+ } else {
+ getLog().info("== Installing bundle " + bundle.getLocation());
+ String bundleLocation = bundle.getLocation();
+ // cleanup prefixes
+ if (bundleLocation.startsWith("wrap:")) {
+ bundleLocation = bundleLocation.substring("wrap:".length());
+ int index = bundleLocation.indexOf("$");
+ if (index != -1) {
+ bundleLocation = bundleLocation.substring(0, index);
+ }
+ }
+ if (bundleLocation.startsWith("blueprint:")) {
+ bundleLocation = bundleLocation.substring("blueprint:".length());
+ }
+ if (bundleLocation.startsWith("webbundle:")) {
+ bundleLocation = bundleLocation.substring("webbundle:".length());
+ }
+ if (bundleLocation.startsWith("war:")) {
+ bundleLocation = bundleLocation.substring("war:".length());
+ }
+ File bundleFile;
+ if (bundleLocation.startsWith("mvn:")) {
+ if (bundleLocation.endsWith("/")) {
+ // for bad formed URL (like in Camel for mustache-compiler), we remove the trailing /
+ bundleLocation = bundleLocation.substring(0, bundleLocation.length() - 1);
+ }
+ if (bundleLocation.startsWith("mvn:http")) {
+ // cleanup the URL containing the repository location directly in the URL
+ int index = bundleLocation.indexOf("!");
+ if (index != -1) {
+ bundleLocation = bundleLocation.substring(index + 1);
+ bundleLocation = "mvn:" + bundleLocation;
+ }
+ }
+ bundleFile = dependencyHelper.resolveById(bundleLocation, getLog());
+ bundleLocation = dependencyHelper.pathFromMaven(bundleLocation);
} else {
- configFileFile = new File(new URI(configFileLocation));
+ bundleFile = new File(new URI(bundleLocation));
}
- File configFileSystemFile = new File(system.resolve(configFileLocation));
- copy(configFileFile, configFileSystemFile);
+ File bundleSystemFile = new File(system.resolve(bundleLocation));
+ copy(bundleFile, bundleSystemFile);
// add metadata for snapshot
- if (configFileLocation.startsWith("mvn")) {
- Artifact configFileArtifact = dependencyHelper.mvnToArtifact(configFileLocation);
- if (configFileArtifact.isSnapshot()) {
- File metadataTarget = new File(configFileSystemFile.getParentFile(), "maven-metadata-local.xml");
+ if (bundleLocation.startsWith("mvn")) {
+ Artifact bundleArtifact = dependencyHelper.mvnToArtifact(bundleLocation);
+ if (bundleArtifact.isSnapshot()) {
+ File metadataTarget = new File(bundleSystemFile.getParentFile(), "maven-metadata-local.xml");
try {
- MavenUtil.generateMavenMetadata(configFileArtifact, metadataTarget);
+ MavenUtil.generateMavenMetadata(bundleArtifact, metadataTarget);
} catch (Exception e) {
getLog().warn("Could not create maven-metadata-local.xml", e);
getLog().warn("It means that this SNAPSHOT could be overwritten by an older one present on remote repositories");
@@ -473,4 +486,31 @@ public class InstallKarsMojo extends MojoSupport {
}
}
+ private void installConfigFile(ConfigFile configFile) throws Exception {
+ getLog().warn("== Installing configuration file " + configFile.getLocation());
+ String configFileLocation = configFile.getLocation();
+ File configFileFile;
+ if (configFileLocation.startsWith("mvn:")) {
+ configFileFile = dependencyHelper.resolveById(configFileLocation, getLog());
+ configFileLocation = dependencyHelper.pathFromMaven(configFileLocation);
+ } else {
+ configFileFile = new File(new URI(configFileLocation));
+ }
+ File configFileSystemFile = new File(system.resolve(configFileLocation));
+ copy(configFileFile, configFileSystemFile);
+ // add metadata for snapshot
+ if (configFileLocation.startsWith("mvn")) {
+ Artifact configFileArtifact = dependencyHelper.mvnToArtifact(configFileLocation);
+ if (configFileArtifact.isSnapshot()) {
+ File metadataTarget = new File(configFileSystemFile.getParentFile(), "maven-metadata-local.xml");
+ try {
+ MavenUtil.generateMavenMetadata(configFileArtifact, metadataTarget);
+ } catch (Exception e) {
+ getLog().warn("Could not create maven-metadata-local.xml", e);
+ getLog().warn("It means that this SNAPSHOT could be overwritten by an older one present on remote repositories");
+ }
+ }
+ }
+ }
+
}