Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHannes Wellmann2021-07-02 11:13:03 -0400
committerLars Vogel2021-07-26 11:19:42 -0400
commitdf70526aa12fc77cc4ab6fc48b8e15b522214fea (patch)
tree26c67f65702919f8cf36b5b8eda9c43b22a8f3b1
parent9dc76f1c04663b202422bd3e27e853c47579a130 (diff)
downloadrt.equinox.p2-df70526aa12fc77cc4ab6fc48b8e15b522214fea.tar.gz
rt.equinox.p2-df70526aa12fc77cc4ab6fc48b8e15b522214fea.tar.xz
rt.equinox.p2-df70526aa12fc77cc4ab6fc48b8e15b522214fea.zip
Bug 574622: Persist remembered accepted licenses in SimpleLicenseManagerY20210727-0800I20210728-1800I20210727-1800I20210726-1800
Additionally simplify assembling of list of accepted license digests, replace StringTokenizer by a corresponding split Pattern and make the fields private final. Change-Id: Icd7d6c28dd9e89ac93cd40c20c67602fbf59e8d7 Signed-off-by: Hannes Wellmann <wellmann.hannes1@gmx.net> Reviewed-on: https://git.eclipse.org/r/c/equinox/rt.equinox.p2/+/182707 Tested-by: Equinox Bot <equinox-bot@eclipse.org> Reviewed-by: Lars Vogel <Lars.Vogel@vogella.com>
-rw-r--r--bundles/org.eclipse.equinox.p2.ui.sdk/META-INF/MANIFEST.MF2
-rw-r--r--bundles/org.eclipse.equinox.p2.ui.sdk/pom.xml2
-rw-r--r--bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/SimpleLicenseManager.java33
3 files changed, 20 insertions, 17 deletions
diff --git a/bundles/org.eclipse.equinox.p2.ui.sdk/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.ui.sdk/META-INF/MANIFEST.MF
index d1e640c63..6929404c6 100644
--- a/bundles/org.eclipse.equinox.p2.ui.sdk/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.ui.sdk/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %bundleName
Bundle-SymbolicName: org.eclipse.equinox.p2.ui.sdk;singleton:=true
-Bundle-Version: 1.2.0.qualifier
+Bundle-Version: 1.2.1.qualifier
Bundle-Activator: org.eclipse.equinox.internal.p2.ui.sdk.ProvSDKUIActivator
Bundle-Vendor: %providerName
Bundle-Localization: plugin
diff --git a/bundles/org.eclipse.equinox.p2.ui.sdk/pom.xml b/bundles/org.eclipse.equinox.p2.ui.sdk/pom.xml
index 40235a0ca..1022d171b 100644
--- a/bundles/org.eclipse.equinox.p2.ui.sdk/pom.xml
+++ b/bundles/org.eclipse.equinox.p2.ui.sdk/pom.xml
@@ -9,6 +9,6 @@
</parent>
<groupId>org.eclipse.equinox</groupId>
<artifactId>org.eclipse.equinox.p2.ui.sdk</artifactId>
- <version>1.2.0-SNAPSHOT</version>
+ <version>1.2.1-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/SimpleLicenseManager.java b/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/SimpleLicenseManager.java
index 160fdf055..b5972a964 100644
--- a/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/SimpleLicenseManager.java
+++ b/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/SimpleLicenseManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2017 IBM Corporation and others.
+ * Copyright (c) 2007, 2021 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -11,17 +11,21 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Genuitec, LLC - added license support
+ * Hannes Wellmann - Bug 574622: Persist remembered accepted licenses
*******************************************************************************/
package org.eclipse.equinox.internal.p2.ui.sdk;
import java.util.HashSet;
-import java.util.StringTokenizer;
+import java.util.Set;
+import java.util.regex.Pattern;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.equinox.internal.p2.ui.sdk.prefs.PreferenceConstants;
import org.eclipse.equinox.p2.core.IAgentLocation;
import org.eclipse.equinox.p2.engine.IProfileRegistry;
import org.eclipse.equinox.p2.engine.ProfileScope;
import org.eclipse.equinox.p2.metadata.ILicense;
import org.eclipse.equinox.p2.ui.LicenseManager;
+import org.osgi.service.prefs.BackingStoreException;
import org.osgi.service.prefs.Preferences;
/**
@@ -32,8 +36,8 @@ import org.osgi.service.prefs.Preferences;
* @since 3.6
*/
public class SimpleLicenseManager extends LicenseManager {
- java.util.Set<String> accepted = new HashSet<>();
- String profileId;
+ private final Set<String> accepted = new HashSet<>();
+ private final String profileId;
public SimpleLicenseManager(String profileId) {
super();
@@ -75,26 +79,25 @@ public class SimpleLicenseManager extends LicenseManager {
return new ProfileScope(location, profileId).getNode(ProvSDKUIActivator.PLUGIN_ID);
}
+ private static final Pattern DIGESTS_DELIMITER = Pattern.compile(","); //$NON-NLS-1$
+
private void initializeFromPreferences() {
Preferences pref = getPreferences();
if (pref != null) {
String digestList = pref.get(PreferenceConstants.PREF_LICENSE_DIGESTS, ""); //$NON-NLS-1$
- StringTokenizer tokenizer = new StringTokenizer(digestList, ","); //$NON-NLS-1$
- while (tokenizer.hasMoreTokens()) {
- accepted.add(tokenizer.nextToken().trim());
- }
+ DIGESTS_DELIMITER.splitAsStream(digestList).filter(s -> !s.isBlank()).map(String::strip)
+ .forEach(accepted::add);
}
}
private void updatePreferences() {
Preferences pref = getPreferences();
- StringBuilder result = new StringBuilder();
- Object[] indexedList = accepted.toArray();
- for (int i = 0; i < indexedList.length; i++) {
- if (i != 0)
- result.append(","); //$NON-NLS-1$
- result.append((String) indexedList[i]);
+ String acceptedLicenseDigests = String.join(",", accepted); //$NON-NLS-1$
+ pref.put(PreferenceConstants.PREF_LICENSE_DIGESTS, acceptedLicenseDigests);
+ try {
+ pref.flush();
+ } catch (BackingStoreException e) {
+ Platform.getLog(SimpleLicenseManager.class).error("Persisting remembered licenses failed", e); //$NON-NLS-1$
}
- pref.put(PreferenceConstants.PREF_LICENSE_DIGESTS, result.toString());
}
}

Back to the top