From fba69ae5d8cd617424e324c62b14225decf0315e Mon Sep 17 00:00:00 2001 From: Jonatan Kronqvist Date: Tue, 12 Aug 2014 13:52:09 +0300 Subject: Allow for multiple license keys in a single license file #14408 License files can now contain multiple keys to support different versions of a product. The keys are identified by the major version number followed by an equals sign and the key for that version, e.g. 1 = foo-bar-baz 2 = baz-foo-bar The license file can also contain a "default" license key, which is used for all versions except for the explicitly defined ones, e.g. foo-bar-baz 3 = baz-bar-foo 4 = bar-baz-baz Change-Id: Id07d22e9fdc44189c4298b634006cf0df128bfd9 --- .../src/com/vaadin/tools/CvalChecker.java | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'client-compiler/src') diff --git a/client-compiler/src/com/vaadin/tools/CvalChecker.java b/client-compiler/src/com/vaadin/tools/CvalChecker.java index 2de7e10faa..e426c5c4e6 100644 --- a/client-compiler/src/com/vaadin/tools/CvalChecker.java +++ b/client-compiler/src/com/vaadin/tools/CvalChecker.java @@ -26,6 +26,7 @@ import java.net.URLConnection; import java.text.MessageFormat; import java.util.Arrays; import java.util.Date; +import java.util.List; import java.util.Locale; import java.util.ResourceBundle; import java.util.prefs.Preferences; @@ -465,7 +466,8 @@ public final class CvalChecker { if (url != null) { try { - key = IOUtils.toString(url.openStream()); + key = readKeyFromFile(url, + computeMajorVersion(productVersion)); if (key != null && !(key = key.trim()).isEmpty()) { return key; } @@ -480,6 +482,22 @@ public final class CvalChecker { productTitle, null, null); } + String readKeyFromFile(URL url, int majorVersion) throws IOException { + String majorVersionStr = String.valueOf(majorVersion); + List lines = IOUtils.readLines(url.openStream()); + String defaultKey = null; + for (String line : lines) { + String[] parts = line.split("\\s*=\\s*"); + if (parts.length < 2) { + defaultKey = parts[0].trim(); + } + if (parts[0].equals(majorVersionStr)) { + return parts[1].trim(); + } + } + return defaultKey; + } + static String getErrorMessage(String key, Object... pars) { Locale loc = Locale.getDefault(); ResourceBundle res = ResourceBundle.getBundle( -- cgit v1.2.3