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/01/04 11:41:19 UTC
karaf git commit: [KARAF-3425] Add support of feature name/version
format in install-kars MOJO
Repository: karaf
Updated Branches:
refs/heads/karaf-3.0.x 2d3da7ebc -> 07f33e9c1
[KARAF-3425] Add support of feature name/version format in install-kars MOJO
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/07f33e9c
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/07f33e9c
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/07f33e9c
Branch: refs/heads/karaf-3.0.x
Commit: 07f33e9c1cead0af78d0ce5d4db3e13bd3f3f727
Parents: 2d3da7e
Author: Jean-Baptiste Onofré <jb...@apache.org>
Authored: Sun Jan 4 11:40:44 2015 +0100
Committer: Jean-Baptiste Onofré <jb...@apache.org>
Committed: Sun Jan 4 11:40:44 2015 +0100
----------------------------------------------------------------------
.../karaf/tooling/features/InstallKarsMojo.java | 81 +++++++++++++++-----
1 file changed, 62 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/07f33e9c/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 c9d5b7c..b75c3e9 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
@@ -157,7 +157,7 @@ public class InstallKarsMojo extends MojoSupport {
Set<String> repositories = new HashSet<String>();
Map<Feature, Boolean> features = new HashMap<Feature, Boolean>();
- // loading kar and featres repositories
+ // loading kar and features repositories
getLog().info("Loading kar and features repositories dependencies with compile or runtime scopes");
getLog().info("The startup.properties file is updated using kar and features dependency with a scope different from runtime, or defined in the <startupFeatures/> plugin configuration");
Collection<Artifact> dependencies = project.getDependencyArtifacts();
@@ -192,28 +192,24 @@ public class InstallKarsMojo extends MojoSupport {
// checking if all startup, installed, and boot features have been resolved
getLog().info("Checking features resolution");
- List<String> resolvedFeaturesNames = new ArrayList<String>();
- for (Feature feature : features.keySet()) {
- resolvedFeaturesNames.add(feature.getName());
- }
if (startupFeatures != null) {
for (String startupFeature : startupFeatures) {
- if (!resolvedFeaturesNames.contains(startupFeature)) {
- throw new MojoFailureException("Feature " + startupFeature + " is not resolved. Check that <dependencies/> provide the kar of features repository providing this feature (with compile or runtime scope)");
+ if (!resolveFeature(features.keySet(), startupFeature)) {
+ throw new MojoFailureException("Startup feature " + startupFeature + " is not resolved. Check that <dependencies/> provide the kar of features repository providing this feature (with compile or runtime scope)");
}
}
}
if (bootFeatures != null) {
for (String bootFeature : bootFeatures) {
- if (!resolvedFeaturesNames.contains(bootFeature)) {
- throw new MojoFailureException("Feature " + bootFeature + " is not resolved. Check that <dependencies/> provide the kar of features repository providing this feature (with compile or runtime scope)");
+ if (!resolveFeature(features.keySet(), bootFeature)) {
+ throw new MojoFailureException("Boot feature " + bootFeature + " is not resolved. Check that <dependencies/> provide the kar of features repository providing this feature (with compile or runtime scope)");
}
}
}
if (installedFeatures != null) {
for (String installedFeature : installedFeatures) {
- if (!resolvedFeaturesNames.contains(installedFeature)) {
- throw new MojoFailureException("Feature " + installedFeature + " is not resolved. Check that <dependencies/> provide the kar of features repository providing this feature (with compile or runtime scope)");
+ if (!resolveFeature(features.keySet(), installedFeature)) {
+ throw new MojoFailureException("Boot feature " + installedFeature + " is not resolved. Check that <dependencies/> provide the kar of features repository providing this feature (with compile or runtime scope)");
}
}
}
@@ -222,9 +218,9 @@ public class InstallKarsMojo extends MojoSupport {
getLog().info("Installing features");
for (Feature feature : features.keySet()) {
try {
- if (features.get(feature) || (startupFeatures != null && startupFeatures.contains(feature.getName()))) {
+ if (features.get(feature) || (startupFeatures != null && resolveFeature(startupFeatures, feature))) {
// the feature is a startup feature, updating startup.properties file
- getLog().info("Feature " + feature.getName() + " is defined as a startup feature");
+ getLog().info("Feature " + feature.getName() + "/" + feature.getVersion() + " is defined as a startup feature");
getLog().info("= Updating startup.properties file");
List<String> comment = Arrays.asList(new String[]{"", "# feature: " + feature.getName() + " version: " + feature.getVersion()});
for (BundleInfo bundleInfo : feature.getBundles()) {
@@ -246,9 +242,9 @@ public class InstallKarsMojo extends MojoSupport {
}
// add the feature in the system folder
resolveFeature(feature, features);
- } else if (bootFeatures != null && bootFeatures.contains(feature.getName())) {
+ } else if (bootFeatures != null && resolveFeature(bootFeatures, feature)) {
// the feature is a boot feature, updating the etc/org.apache.karaf.features.cfg file
- getLog().info("Feature " + feature.getName() + " is defined as a boot feature");
+ getLog().info("Feature " + feature.getName() + "/" + feature.getVersion() + " is defined as a boot feature");
if (featuresCfgFile.exists()) {
getLog().info("= Updating " + featuresCfgFile.getPath());
Properties featuresProperties = new Properties();
@@ -268,15 +264,15 @@ public class InstallKarsMojo extends MojoSupport {
}
// add the feature in the system folder
resolveFeature(feature, features);
- } else if (installedFeatures != null && installedFeatures.contains(feature.getName())) {
- getLog().info("Feature " + feature.getName() + " is defined as a installed feature");
+ } else if (installedFeatures != null && resolveFeature(installedFeatures, feature)) {
+ getLog().info("Feature " + feature.getName() + "/" + feature.getVersion() + " is defined as a installed feature");
// add the feature in the system folder
resolveFeature(feature, features);
} else {
- getLog().debug("Feature " + feature.getName() + " is not installed");
+ getLog().debug("Feature " + feature.getName() + "/" + feature.getVersion() + " is not installed");
}
} catch (Exception e) {
- throw new MojoFailureException("Can not install " + feature.getName() + " feature", e);
+ throw new MojoFailureException("Can not install " + feature.getName() + "/" + feature.getVersion() + " feature", e);
}
}
@@ -307,6 +303,53 @@ public class InstallKarsMojo extends MojoSupport {
}
}
+ private boolean resolveFeature(Set<Feature> features, String featureToCheck) {
+ String name = featureToCheck;
+ // the format can be name/version
+ String[] split = name.split("/");
+ if (split.length == 2) {
+ // the feature used name/version format
+ name = split[0];
+ String version = split[1];
+ boolean found = false;
+ for (Feature feature : features) {
+ if (feature.getName().equals(name) && feature.getVersion().equals(version)) {
+ found = true;
+ break;
+ }
+ }
+ return found;
+ } else {
+ // the feature is just name
+ boolean found = false;
+ for (Feature feature : features) {
+ if (feature.getName().equals(name)) {
+ found = true;
+ break;
+ }
+ }
+ return found;
+ }
+ }
+
+ private boolean resolveFeature(List<String> features, Feature feature) {
+ for (String f : features) {
+ String[] split = f.split("/");
+ if (split.length == 2) {
+ String name = split[0];
+ String version = split[1];
+ if (feature.getName().equals(name) && feature.getVersion().equals(version)) {
+ return true;
+ }
+ } else {
+ if (feature.getName().equals(f)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
private void resolveRepository(String repository, Set<String> repositories, Map<Feature, Boolean> features, boolean updateFeaturesCfgFile, boolean updateStartupProperties) throws Exception {
// check if the repository has not been processed
if (repositories.contains(repository)) {