Repository: jclouds Updated Branches: refs/heads/master bae4377dc -> 2e942072d
[JCLOUDS-392] Remove dependency from Maps2. Make jclouds-core packages optionally imported from jclouds-scriptbuilder. Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/2e942072 Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/2e942072 Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/2e942072 Branch: refs/heads/master Commit: 2e942072d7f321a1b18f7d39fd824b02c9eb9938 Parents: bae4377 Author: Ioannis Canellos <[email protected]> Authored: Mon Dec 2 13:35:14 2013 +0200 Committer: Ignasi Barrera <[email protected]> Committed: Tue May 27 10:20:52 2014 +0200 ---------------------------------------------------------------------- scriptbuilder/pom.xml | 16 +++++++++++-- .../org/jclouds/scriptbuilder/util/Utils.java | 24 ++++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jclouds/blob/2e942072/scriptbuilder/pom.xml ---------------------------------------------------------------------- diff --git a/scriptbuilder/pom.xml b/scriptbuilder/pom.xml index b4e7084..02f747f 100644 --- a/scriptbuilder/pom.xml +++ b/scriptbuilder/pom.xml @@ -34,8 +34,20 @@ <jclouds.test.listener /> <jclouds.osgi.activator>org.jclouds.scriptbuilder.functionloader.osgi.Activator</jclouds.osgi.activator> - <jclouds.osgi.export>org.jclouds.scriptbuilder*;version="${project.version}"</jclouds.osgi.export> - <jclouds.osgi.import>org.jclouds*;version="${project.version}",*</jclouds.osgi.import> + <jclouds.osgi.export>org.jclouds.scriptbuilder*;version="${project.version}";-noimport:=true</jclouds.osgi.export> + <!-- + The following classes are only needed when using chef or other compute stuff: + i) org.jclouds.javax.annotation.Nullable + ii) org.jclouds.domain.Credentials + iii) java.inject.Inject + --> + <jclouds.osgi.import> + javax.inject*;resolution:=optional, + org.jclouds.domain*;version="${project.version}";resolution:=optional, + org.jclouds.javax.annotation*;version="${project.version}";resolution:=optional, + org.jclouds*;version="${project.version}", + * + </jclouds.osgi.import> </properties> <dependencies> http://git-wip-us.apache.org/repos/asf/jclouds/blob/2e942072/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/util/Utils.java ---------------------------------------------------------------------- diff --git a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/util/Utils.java b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/util/Utils.java index 4c20dff..bbada91 100644 --- a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/util/Utils.java +++ b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/util/Utils.java @@ -24,7 +24,6 @@ import java.util.regex.Pattern; import org.jclouds.scriptbuilder.domain.OsFamily; import org.jclouds.scriptbuilder.domain.ShellToken; import org.jclouds.scriptbuilder.functionloader.CurrentFunctionLoader; -import org.jclouds.util.Maps2; import com.google.common.base.CaseFormat; import com.google.common.base.Function; @@ -32,6 +31,8 @@ import com.google.common.base.Joiner; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; +import static com.google.common.base.Preconditions.checkNotNull; + /** * Utilities used to build init scripts. * @@ -112,7 +113,7 @@ public class Utils { * @see VariableNameForOsFamily */ public static String writeVariableExporters(Map<String, String> exports, final OsFamily family) { - exports = Maps2.transformKeys(exports, new VariableNameForOsFamily(family)); + exports = transformKeys(exports, new VariableNameForOsFamily(family)); return replaceTokens(writeVariableExporters(exports), ShellToken.tokenValueMap(family)); } @@ -207,4 +208,23 @@ public class Utils { public static String writeComment(String comment, OsFamily family) { return String.format("%s%s%s", ShellToken.REM.to(family), comment, ShellToken.LF.to(family)); } + + /** + * change the keys but keep the values in-tact. + * + * @param <K1> input key type + * @param <K2> output key type + * @param <V> value type + * @param in input map to transform + * @param fn how to transform the values + * @return immutableMap with the new keys. + */ + public static <K1, K2, V> Map<K2, V> transformKeys(Map<K1, V> in, Function<K1, K2> fn) { + checkNotNull(in, "input map"); + checkNotNull(fn, "function"); + ImmutableMap.Builder<K2, V> returnVal = ImmutableMap.builder(); + for (Entry<K1, V> entry : in.entrySet()) + returnVal.put(fn.apply(entry.getKey()), entry.getValue()); + return returnVal.build(); + } }
