diff options
author | Pascal Rapicault | 2016-04-27 11:03:48 +0000 |
---|---|---|
committer | Pascal Rapicault | 2016-04-27 19:01:59 +0000 |
commit | b97ef3f4f4fc248edcabf714c36ad7980529f399 (patch) | |
tree | a531dbf3dd4d5609907bd06ce975691876458a49 | |
parent | 8e84db691394e6ecf6fd8ddacbdb5bca6df551d3 (diff) | |
download | eclipse.platform.runtime-Y20160428-1430.tar.gz eclipse.platform.runtime-Y20160428-1430.tar.xz eclipse.platform.runtime-Y20160428-1430.zip |
Bug 490112 - Add unique id to p2 user agent informationY20160428-1430Y20160428-1000I20160504-0035I20160503-2000I20160502-2000I20160501-2000I20160430-2000I20160429-2300I20160429-2000I20160428-0800I20160427-2000
Change-Id: Ib3bcbe28218cb33116e44d30590024c966fa2731
Signed-off-by: Pascal Rapicault <pascal@rapicorp.com>
-rw-r--r-- | bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/InternalPlatform.java | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/InternalPlatform.java b/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/InternalPlatform.java index a5cbb50b2..728f4eb63 100644 --- a/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/InternalPlatform.java +++ b/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/InternalPlatform.java @@ -84,7 +84,9 @@ public final class InternalPlatform { public static final String PROP_PRODUCT = "eclipse.product"; //$NON-NLS-1$ public static final String PROP_WS = "osgi.ws"; //$NON-NLS-1$ public static final String PROP_ACTIVATE_PLUGINS = "eclipse.activateRuntimePlugins"; //$NON-NLS-1$ + public static final String PROP_UUID = "eclipse.uuid"; //$NON-NLS-1$ + private static final String UUID_PATH = "/.eclipse/eclipse.uuid"; //$NON-NLS-1$ private static final InternalPlatform singleton = new InternalPlatform(); private static final String[] WS_LIST = {Platform.WS_CARBON, Platform.WS_COCOA, Platform.WS_GTK, Platform.WS_MOTIF, Platform.WS_PHOTON, Platform.WS_WIN32, Platform.WS_WPF}; @@ -718,6 +720,54 @@ public final class InternalPlatform { // activate Jobs plugin by creating a class from it: org.eclipse.core.runtime.jobs.Job.getJobManager(); } + loadMachineUUID(); + } + + private void loadMachineUUID() { + EnvironmentInfo environment = environmentTracker.getService(); + if (environment != null) { + if (environment.getProperty(PROP_UUID) != null) + return; + } + String uuid = loadExistingUUID(); + if (uuid == null) { + uuid = UUID.randomUUID().toString(); + saveUUID(uuid); + } + if (environment != null) { + environment.setProperty(PROP_UUID, uuid); + } else { + System.setProperty(PROP_UUID, uuid); + } + } + + private void saveUUID(String uuid) { + File eclipseUUIDFile = new File(System.getProperty("user.home") + UUID_PATH); //$NON-NLS-1$ + if (!eclipseUUIDFile.getParentFile().exists()) { + if (!eclipseUUIDFile.getParentFile().mkdirs()) + return; + } + try (OutputStream os = new BufferedOutputStream(new FileOutputStream(eclipseUUIDFile))){ + Properties prop = new Properties(); + prop.setProperty(PROP_UUID, uuid); + prop.setProperty("version", "1"); //$NON-NLS-1$//$NON-NLS-2$ + prop.store(os, ""); //$NON-NLS-1$ + } catch (IOException e) { + return; + } + } + + private String loadExistingUUID() { + File eclipseUUIDFile = new File(System.getProperty("user.home") + UUID_PATH); //$NON-NLS-1$ + if (!eclipseUUIDFile.exists()) + return null; + try(InputStream in = new BufferedInputStream(new FileInputStream(eclipseUUIDFile))) { + Properties prop = new Properties(); + prop.load(in); + return (String) prop.get(PROP_UUID); + } catch (IOException e) { + return null; + } } /** |