diff options
author | Ed Merks | 2014-08-20 06:45:05 +0000 |
---|---|---|
committer | Ed Merks | 2014-08-20 06:45:05 +0000 |
commit | d4e97a7562d39fdee9bb4a6a92292a813cd5fb85 (patch) | |
tree | 37d695e21af03ea30cc87f5420cc417e9f8f810d /plugins/org.eclipse.oomph.setup/src | |
parent | 08d3994e590cdf92dc7b23edbe3431460d69e425 (diff) | |
download | org.eclipse.oomph-d4e97a7562d39fdee9bb4a6a92292a813cd5fb85.tar.gz org.eclipse.oomph-d4e97a7562d39fdee9bb4a6a92292a813cd5fb85.tar.xz org.eclipse.oomph-d4e97a7562d39fdee9bb4a6a92292a813cd5fb85.zip |
[441188] Provide more flexible control over where a variable is saved
https://bugs.eclipse.org/bugs/show_bug.cgi?id=441188
Diffstat (limited to 'plugins/org.eclipse.oomph.setup/src')
3 files changed, 115 insertions, 5 deletions
diff --git a/plugins/org.eclipse.oomph.setup/src/org/eclipse/oomph/setup/AnnotationConstants.java b/plugins/org.eclipse.oomph.setup/src/org/eclipse/oomph/setup/AnnotationConstants.java index c3c530c4d..a5ef09105 100644 --- a/plugins/org.eclipse.oomph.setup/src/org/eclipse/oomph/setup/AnnotationConstants.java +++ b/plugins/org.eclipse.oomph.setup/src/org/eclipse/oomph/setup/AnnotationConstants.java @@ -25,6 +25,8 @@ public final class AnnotationConstants public static final String ANNOTATION_FEATURE_SUBSTITUTION = "http://www.eclipse.org/oomph/setup/FeatureSubstitution"; + public static final String ANNOTATION_PASSWORD_VERIFICATION = "http://www.eclipse.org/oomph/setup/PasswordVerification"; + public static final String KEY_INHERIT = "inherit"; public static final String KEY_TARGET = "target"; diff --git a/plugins/org.eclipse.oomph.setup/src/org/eclipse/oomph/setup/SetupTaskContext.java b/plugins/org.eclipse.oomph.setup/src/org/eclipse/oomph/setup/SetupTaskContext.java index 70074e808..9f882ca02 100644 --- a/plugins/org.eclipse.oomph.setup/src/org/eclipse/oomph/setup/SetupTaskContext.java +++ b/plugins/org.eclipse.oomph.setup/src/org/eclipse/oomph/setup/SetupTaskContext.java @@ -13,7 +13,6 @@ package org.eclipse.oomph.setup; import org.eclipse.oomph.internal.setup.SetupPrompter; import org.eclipse.oomph.setup.log.ProgressLog; import org.eclipse.oomph.setup.util.OS; -import org.eclipse.oomph.setup.util.StringExpander; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.URIConverter; @@ -24,7 +23,7 @@ import java.util.Set; /** * @author Eike Stepper */ -public interface SetupTaskContext extends ProgressLog, StringExpander +public interface SetupTaskContext extends ProgressLog { public SetupPrompter getPrompter(); diff --git a/plugins/org.eclipse.oomph.setup/src/org/eclipse/oomph/setup/util/StringExpander.java b/plugins/org.eclipse.oomph.setup/src/org/eclipse/oomph/setup/util/StringExpander.java index c0141a7e1..4a1da6e1e 100644 --- a/plugins/org.eclipse.oomph.setup/src/org/eclipse/oomph/setup/util/StringExpander.java +++ b/plugins/org.eclipse.oomph.setup/src/org/eclipse/oomph/setup/util/StringExpander.java @@ -10,12 +10,121 @@ */ package org.eclipse.oomph.setup.util; +import java.io.File; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + /** * @author Eike Stepper */ -public interface StringExpander +public abstract class StringExpander { - public String expandString(String string); + public static final Pattern STRING_EXPANSION_PATTERN = Pattern.compile("\\$(\\{([^${}|/]+)(\\|([^{}/]+))?([^{}]*)}|\\$)"); + + private static boolean NEEDS_PATH_SEPARATOR_CONVERSION = File.separatorChar == '\\'; + + protected static String resolve(StringExpander stringExpander, String key) + { + return stringExpander.resolve(key); + } + + protected static boolean isUnexpanded(StringExpander stringExpander, String key) + { + return stringExpander.isUnexpanded(key); + } + + protected static String filter(StringExpander stringExpander, String value, String filterName) + { + return stringExpander.filter(value, filterName); + } + + protected abstract String resolve(String key); + + protected abstract boolean isUnexpanded(String key); + + protected abstract String filter(String value, String filterName); + + public String expandString(String string) + { + return expandString(string, null); + } + + public String expandString(String string, Set<String> keys) + { + if (string == null) + { + return null; + } + + StringBuilder result = new StringBuilder(); + int previous = 0; + boolean unresolved = false; + for (Matcher matcher = StringExpander.STRING_EXPANSION_PATTERN.matcher(string); matcher.find();) + { + result.append(string.substring(previous, matcher.start())); + String key = matcher.group(1); + if ("$".equals(key)) + { + result.append('$'); + } + else + { + key = matcher.group(2); + String suffix = matcher.group(5); + if (NEEDS_PATH_SEPARATOR_CONVERSION) + { + suffix = suffix.replace('/', File.separatorChar); + } + + boolean isUnexpanded = isUnexpanded(key); + String value = isUnexpanded ? null : resolve(key); + if (value == null) + { + if (keys != null) + { + unresolved = true; + + if (!isUnexpanded) + { + keys.add(key); + } + } + else if (!unresolved) + { + result.append(matcher.group()); + } + } + + if (value != null) + { + String filters = matcher.group(4); + if (filters != null) + { + for (String filterName : filters.split("\\|")) + { + value = filter(value, filterName); + } + } + + if (!unresolved) + { + result.append(value); + result.append(suffix); + } + } + } + + previous = matcher.end(); + } + + if (unresolved) + { + return null; + } + + result.append(string.substring(previous)); + return result.toString(); + } - public String expandString(String string, boolean secure); } |