Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Switched ping mechanism to generate ids client-side.

  • Loading branch information...
commit d5834942708068700b8b651e064fcc84fb5b93ba 1 parent 0da8a6c
Kevin Lindsey authored
View
11 .project
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>ide_core</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ </buildSpec>
+ <natures>
+ </natures>
+</projectDescription>
View
532 plugins/com.aptana.ide.core.ui/src/com/aptana/ide/core/ui/ping/PingStartup.java
@@ -49,18 +49,18 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.UUID;
import java.util.zip.GZIPOutputStream;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Preferences;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.preferences.IPreferencesService;
import org.eclipse.ui.IStartup;
import com.aptana.ide.core.AptanaCorePlugin;
-import com.aptana.ide.core.Base64;
import com.aptana.ide.core.DateUtils;
import com.aptana.ide.core.IdeLog;
import com.aptana.ide.core.PluginUtils;
@@ -71,7 +71,6 @@
import com.aptana.ide.core.db.FeatureTracker;
import com.aptana.ide.core.db.LogEventTypes;
import com.aptana.ide.core.ui.CoreUIPlugin;
-import com.aptana.ide.core.ui.CoreUIUtils;
import com.aptana.ide.core.ui.WorkbenchHelper;
import com.aptana.ide.core.ui.preferences.ApplicationPreferences;
import com.aptana.ide.core.ui.preferences.IPreferenceConstants;
@@ -81,78 +80,126 @@
public class PingStartup implements IStartup
{
-
private static final String FEATURE_IU_SUFFIX = ".feature.group"; //$NON-NLS-1$
- private static final String INSTALL_URL = "http://check.aptana.com/install.php"; //$NON-NLS-1$
- private static final String UPDATE_URL = "https://check.aptana.com/update2.php"; //$NON-NLS-1$
+ private static final String INSTALL_URL = "http://ping.aptana.com/welcome.php"; //$NON-NLS-1$
+ private static final String UPDATE_URL = "https://ping.aptana.com/ping.php"; //$NON-NLS-1$
private static final int READ_TIMEOUT = 15 * 60 * 1000; // 15 seconds in millis
private static final long TWENTY_FOUR_HOURS = 24 * 60 * 60 * 1000; // 24 hours in milliseconds
private static boolean ranOnce = false;
/**
- * @see org.eclipse.ui.IStartup#earlyStartup()
+ * addFeatureList
+ *
+ * @return
*/
- public void earlyStartup()
+ private static void addFeatureList()
{
- if (Platform.inDevelopmentMode()) {
- return;
+ Set<FeatureInfo> featureList = new HashSet<FeatureInfo>();
+ List<IPlugin> installed = FeatureUtil.getInstalledFeatures();
+
+ for (IPlugin iu : installed)
+ {
+ // NOTE: Prior to P2, features could be enabled or not. P2 no longer has this
+ // concept, so we hard-code that the feature is enabled to keep the format
+ // consistent with pre-P2 pings.
+ featureList.add(new FeatureInfo(stripFeatureNameToBaseID(iu.getId()), iu.getVersion(), true));
}
- Job job = new Job("Sending Ping...") //$NON-NLS-1$
+
+ FeatureInfo[] features = featureList.toArray(new FeatureInfo[featureList.size()]);
+
+ if (featuresMatch(features) == false)
{
- @Override
- protected IStatus run(IProgressMonitor monitor)
+ FeatureTracker tracker = FeatureTracker.getInstance();
+
+ // clear old list of features
+ tracker.clearFeatures();
+
+ // emit feature list and add to feature tracker
+ EventLogger logger = EventLogger.getInstance();
+
+ for (FeatureInfo feature : featureList)
{
- updateAnonymousId();
- if (!ranOnce)
- {
- ranOnce = true;
- }
- schedule(TWENTY_FOUR_HOURS);
- return Status.OK_STATUS;
+ logger.logEvent(LogEventTypes.FEATURE, feature.toString());
+ tracker.addFeature(feature);
}
- };
- job.setSystem(true);
- job.setPriority(Job.BUILD);
- job.schedule();
+ }
}
/**
- * updateAnonymousId Updates the IDE ID if it hasn't been set. This ID is used just to track updates, no personal
- * information is shared or retained.
+ * addKeyPair
+ *
+ * @param keyValues
+ * @param key
+ * @param value
*/
- private static void updateAnonymousId()
+ private static void addKeyPair(List<String> keyValues, String key, String value)
{
- URL url = null;
- boolean needId = false;
- String previousId = null;
+ if (value == null)
+ {
+ value = StringUtils.EMPTY;
+ }
- boolean success = false;
+ keyValues.add(StringUtils.urlEncodeKeyValuePair(key, value));
+ }
- // load application preferences
- ApplicationPreferences preferences = ApplicationPreferences.getInstance();
- preferences.loadPreferences();
+ /**
+ * featuresMatch
+ *
+ * @param currentFeatures
+ * @return
+ */
+ private static boolean featuresMatch(FeatureInfo[] currentFeatures)
+ {
+ FeatureInfo[] savedFeatures = FeatureTracker.getInstance().getFeatures();
+ boolean result = (currentFeatures.length == savedFeatures.length);
- // get application run and id values
- boolean hasRun = preferences.getBoolean(IPreferenceConstants.P_IDE_HAS_RUN);
- String applicationId = preferences.getString(IPreferenceConstants.P_IDE_ID);
+ if (result)
+ {
+ // sort both lists
+ Arrays.sort(savedFeatures);
+ Arrays.sort(currentFeatures);
+
+ // now compare for any diffs
+ for (int i = 0; i < savedFeatures.length; i++)
+ {
+ if (savedFeatures[i].equals(currentFeatures[i]) == false)
+ {
+ result = false;
+ break;
+ }
+ }
+ }
- // get workspace id value
- Preferences p = CoreUIPlugin.getDefault().getPluginPreferences();
- String workspaceId = p.getString(IPreferenceConstants.P_IDE_ID);
+ return result;
+ }
+
+ /**
+ * getApplicationId
+ *
+ * @return
+ */
+ private static String getApplicationId(ApplicationPreferences preferences)
+ {
+ String applicationId = preferences.getString(IPreferenceConstants.P_IDE_ID);
+ String workspaceId = getWorkspaceId();
+ String previousId = null;
- // tag id as "none" if it wasn't defined
if (applicationId == null || applicationId.length() == 0)
{
if (workspaceId == null || workspaceId.length() == 0)
{
- applicationId = "none"; //$NON-NLS-1$
-
// Look for id from previous release's location
Map<String, String> previousPreferences = preferences.loadPreviousPreferences();
previousId = previousPreferences.get(IPreferenceConstants.P_IDE_ID);
- needId = true;
+ // Use the id from previous release or generate a UUID
+ applicationId = (previousId != null) ? previousId : UUID.randomUUID().toString();
+
+ // save results in preferences
+ preferences.setString(IPreferenceConstants.P_IDE_ID, applicationId);
+ preferences.setBoolean(IPreferenceConstants.P_IDE_HAS_RUN, true);
+ preferences.savePreferences();
}
else
{
@@ -168,58 +215,61 @@ private static void updateAnonymousId()
// merge ids if they do not match
if (workspaceId != null && workspaceId.length() > 0 && workspaceId.equals(applicationId) == false)
{
- // id from prefs wins right now
+ // id from workspace wins right now
applicationId = workspaceId;
}
}
+
+ return applicationId;
+ }
- String queryString = null;
+ /**
+ * getUserAgent
+ *
+ * @return
+ */
+ private static String getUserAgent()
+ {
+ return "Aptana/1.5"; //$NON-NLS-1$
+ }
- try
+ /**
+ * getWorkspaceId
+ *
+ * @return
+ */
+ private static String getWorkspaceId()
+ {
+ IPreferencesService preferencesService = Platform.getPreferencesService();
+ String result = StringUtils.EMPTY;
+
+ if (preferencesService != null)
{
- List<String> keyValues = new ArrayList<String>();
-
- addKeyPair(keyValues, "id", applicationId); //$NON-NLS-1$
- addKeyPair(keyValues, "v", PluginUtils.getPluginVersion(AptanaCorePlugin.getDefault())); //$NON-NLS-1$
- addKeyPair(keyValues, "p", System.getProperty("eclipse.product")); //$NON-NLS-1$ //$NON-NLS-2$
- addKeyPair(keyValues, "ev", System.getProperty("osgi.framework.version")); //$NON-NLS-1$ //$NON-NLS-2$
- addKeyPair(keyValues, "osa", System.getProperty("os.arch")); //$NON-NLS-1$ //$NON-NLS-2$
- addKeyPair(keyValues, "osn", System.getProperty("os.name")); //$NON-NLS-1$ //$NON-NLS-2$
- addKeyPair(keyValues, "osv", System.getProperty("os.version")); //$NON-NLS-1$ //$NON-NLS-2$
- addKeyPair(keyValues, "pre", getPreviewString()); //$NON-NLS-1$
- addKeyPair(keyValues, "pro", CoreUIUtils.getEncryptedProValue()); //$NON-NLS-1$
-
- // add current date/time before extracting events
- EventLogger.getInstance().logEvent(LogEventTypes.DATE_TIME);
-
- // add studio key
- EventLogger.getInstance().logEvent(LogEventTypes.STUDIO_KEY, MACAddress.getMACAddress());
-
- // add plugins
- addFeatureList();
-
- // add custom key/value pairs
- EventInfo[] events = EventLogger.getInstance().getEvents();
-
- for (EventInfo event : events)
- {
- // ignore preview events
- if (event.getEventType().equals(LogEventTypes.PREVIEW) == false)
- {
- // make sure to specify the key as an array in case we have
- // more than one value of the same event type
- String key = event.getEventType() + "[]"; //$NON-NLS-1$
-
- // combine datetime stamp and value
- String value = Long.toString(event.getDateTime()) + ":" + event.getMessage(); //$NON-NLS-1$
+ result = preferencesService.getString(
+ CoreUIPlugin.getPluginId(),
+ IPreferenceConstants.P_IDE_ID,
+ StringUtils.EMPTY,
+ null
+ );
+ }
- addKeyPair(keyValues, key, value);
- }
- }
+ return result;
+ }
- // create POST string
- queryString = StringUtils.join("&", keyValues.toArray(new String[keyValues.size()])); //$NON-NLS-1$
+ /**
+ * sendUpdate
+ *
+ * @param preferences
+ * @param queryString
+ * @return
+ */
+ private static boolean sendUpdate(ApplicationPreferences preferences, String queryString)
+ {
+ URL url = null;
+ boolean result = false;
+ try
+ {
// gzip POST string
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream gos = new GZIPOutputStream(baos);
@@ -262,36 +312,24 @@ private static void updateAnonymousId()
output.close();
input.close();
- String newId = sb.toString();
-
- // only save the new id if we need one and if it is valid
- if (needId == true && newId.matches("^[0-9]+$")) //$NON-NLS-1$
- {
- if (previousId != null)
- {
- // Use the id from previous release
- newId = previousId;
- }
- preferences.setString(IPreferenceConstants.P_IDE_ID, newId);
- preferences.setBoolean(IPreferenceConstants.P_IDE_HAS_RUN, true);
- preferences.savePreferences();
- }
-
- success = true;
+ String resultText = sb.toString();
+ System.out.println(resultText);
+
+ result = true;
}
catch (UnknownHostException e)
{
// happens when user is offline or can't resolve aptana.com
- return;
}
catch (MalformedURLException e)
{
- IdeLog.logError(CoreUIPlugin.getDefault(), StringUtils
- .format(Messages.SchedulerStartup_UrlIsMalformed, url), e);
+ IdeLog.logError(CoreUIPlugin.getDefault(), StringUtils.format(Messages.SchedulerStartup_UrlIsMalformed, url), e);
}
catch (IOException e)
{
- if (needId && hasRun == false)
+ boolean hasRun = preferences.getBoolean(IPreferenceConstants.P_IDE_HAS_RUN);
+
+ if (hasRun == false)
{
WorkbenchHelper.launchBrowser(INSTALL_URL + "?" + queryString); //$NON-NLS-1$
preferences.setBoolean(IPreferenceConstants.P_IDE_HAS_RUN, true);
@@ -302,105 +340,10 @@ private static void updateAnonymousId()
{
IdeLog.logError(CoreUIPlugin.getDefault(), Messages.SchedulerStartup_UnableToContactUpdateServer, e);
}
-
- if (success)
- {
- // clear event log
- EventLogger.getInstance().clearEvents();
- }
- else
- {
- // remove anything older than 28 days.
- long fourWeeksAgo = DateUtils.addDayInterval(System.currentTimeMillis(), -28);
-
- EventLogger.getInstance().clearEvents(fourWeeksAgo);
- }
- }
-
- /**
- * addKeyPair
- *
- * @param keyValues
- * @param key
- * @param value
- */
- private static void addKeyPair(List<String> keyValues, String key, String value)
- {
- if (value == null)
- {
- value = StringUtils.EMPTY;
- }
-
- keyValues.add(StringUtils.urlEncodeKeyValuePair(key, value));
- }
-
- /**
- * addFeatureList
- *
- * @return
- */
- private static void addFeatureList()
- {
- Set<FeatureInfo> featureList = new HashSet<FeatureInfo>();
- List<IPlugin> installed = FeatureUtil.getInstalledFeatures();
- for (IPlugin iu : installed)
- {
- // NOTE: Prior to P2, features could be enabled or not. P2 no longer has this
- // concept, so we hard-code that the feature is enabled to keep the format
- // consistent with pre-P2 pings.
- featureList.add(new FeatureInfo(stripFeatureNameToBaseID(iu.getId()), iu.getVersion(), true));
- }
-
- FeatureInfo[] features = featureList.toArray(new FeatureInfo[featureList.size()]);
- if (featuresMatch(features) == false)
- {
- FeatureTracker tracker = FeatureTracker.getInstance();
-
- // clear old list of features
- tracker.clearFeatures();
-
- // emit feature list and add to feature tracker
- EventLogger logger = EventLogger.getInstance();
-
- for (FeatureInfo feature : featureList)
- {
- logger.logEvent(LogEventTypes.FEATURE, feature.toString());
- tracker.addFeature(feature);
- }
- }
- }
-
- /**
- * featuresMatch
- *
- * @param currentFeatures
- * @return
- */
- private static boolean featuresMatch(FeatureInfo[] currentFeatures)
- {
- FeatureInfo[] savedFeatures = FeatureTracker.getInstance().getFeatures();
- boolean result = (currentFeatures.length == savedFeatures.length);
-
- if (result)
- {
- // sort both lists
- Arrays.sort(savedFeatures);
- Arrays.sort(currentFeatures);
-
- // now compare for any diffs
- for (int i = 0; i < savedFeatures.length; i++)
- {
- if (savedFeatures[i].equals(currentFeatures[i]) == false)
- {
- result = false;
- break;
- }
- }
- }
-
+
return result;
}
-
+
/**
* stripFeatureNameToBaseID
*
@@ -416,128 +359,97 @@ private static String stripFeatureNameToBaseID(String name)
return name.substring(0, name.length() - FEATURE_IU_SUFFIX.length());
}
-
+
/**
- * getPreviewString
- *
- * @return
+ * updateAnonymousId Updates the IDE ID if it hasn't been set. This ID is used just to track updates, no personal
+ * information is shared or retained.
*/
- private static String getPreviewString()
+ private static void updateAnonymousId()
{
- EventInfo[] events = EventLogger.getInstance().getEvents(LogEventTypes.PREVIEW);
- String result = "-"; //$NON-NLS-1$
+ String queryString = null;
+ List<String> keyValues = new ArrayList<String>();
+
+ // load application preferences
+ ApplicationPreferences preferences = ApplicationPreferences.getInstance();
+ preferences.loadPreferences();
- if (events.length > 0)
+ // build key/value pairs
+ addKeyPair(keyValues, "id", getApplicationId(preferences)); //$NON-NLS-1$
+ addKeyPair(keyValues, "version", PluginUtils.getPluginVersion(AptanaCorePlugin.getDefault())); //$NON-NLS-1$
+ addKeyPair(keyValues, "product", System.getProperty("eclipse.product")); //$NON-NLS-1$ //$NON-NLS-2$
+ addKeyPair(keyValues, "eclipse_version", System.getProperty("osgi.framework.version")); //$NON-NLS-1$ //$NON-NLS-2$
+ addKeyPair(keyValues, "os_architecture", System.getProperty("os.arch")); //$NON-NLS-1$ //$NON-NLS-2$
+ addKeyPair(keyValues, "os_name", System.getProperty("os.name")); //$NON-NLS-1$ //$NON-NLS-2$
+ addKeyPair(keyValues, "os_version", System.getProperty("os.version")); //$NON-NLS-1$ //$NON-NLS-2$
+ addKeyPair(keyValues, LogEventTypes.STUDIO_KEY, MACAddress.getMACAddress());
+
+ // add date/time stamp
+ EventLogger.getInstance().logEvent(LogEventTypes.DATE_TIME);
+
+ // add plugins
+ addFeatureList();
+
+ // add any custom key/value pairs
+ EventInfo[] events = EventLogger.getInstance().getEvents();
+
+ for (EventInfo event : events)
{
- ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
- DataOutputStream output = new DataOutputStream(byteStream);
-
- // determine width of each interval
- int minuteInterval = 10;
-
- // round current time up to next interval
- long stopTime = DateUtils.roundDownToMinuteInterval(System.currentTimeMillis(), minuteInterval);
- stopTime = DateUtils.addMinuteInterval(stopTime, minuteInterval);
-
- // round first time down to previous interval
- long nextTime = events[0].getDateTime();
- nextTime = DateUtils.roundDownToMinuteInterval(nextTime, minuteInterval);
-
- // init byte
- int currentByte = 0;
- int shiftCount = 0;
- int eventIndex = 0;
-
- try
+ // ignore preview events
+ if (event.getEventType().equals(LogEventTypes.PREVIEW) == false)
{
- // write time for first interval
- output.writeLong(nextTime);
+ // make sure to specify the key as an array in case we have
+ // more than one value of the same event type
+ String key = event.getEventType() + "[]"; //$NON-NLS-1$
- // write number of minutes between intervals
- output.writeInt(minuteInterval);
+ // combine datetime stamp and value
+ String value = Long.toString(event.getDateTime()) + ":" + event.getMessage(); //$NON-NLS-1$
- // advance to next interval to process all events up to that interval
- nextTime = DateUtils.addMinuteInterval(nextTime, minuteInterval);
-
- do
- {
- boolean match = false;
-
- while (eventIndex < events.length)
- {
- if (events[eventIndex].getDateTime() >= nextTime)
- {
- // process this bit
- break;
- }
- else
- {
- // set this bit
- match = true;
-
- // go to next event
- eventIndex++;
- }
- }
-
- // write bit
- if (match)
- {
- currentByte = (currentByte << 1) | 1;
- }
- else
- {
- currentByte = currentByte << 1;
- }
-
- shiftCount++;
-
- // emit if that was the 8th bit
- if (shiftCount == 8)
- {
- output.writeByte(currentByte);
-
- // reset
- currentByte = 0;
- shiftCount = 0;
- }
-
- // advance to next interval
- nextTime = DateUtils.addMinuteInterval(nextTime, minuteInterval);
- }
- while (nextTime <= stopTime);
-
- // fill the rest of the byte with zero and emit
- if (shiftCount > 0)
- {
- currentByte = (currentByte << (8 - shiftCount));
- output.writeByte(currentByte);
- }
-
- // we're done
- output.close();
+ addKeyPair(keyValues, key, value);
+ }
+ }
- // grab bytes
- byte[] data = byteStream.toByteArray();
+ // create POST query string
+ queryString = StringUtils.join("&", keyValues.toArray(new String[keyValues.size()])); //$NON-NLS-1$
+ System.out.println(queryString);
- // compress as base64
- result = Base64.encodeBytes(data, Base64.DONT_BREAK_LINES);
- }
- catch (IOException e)
- {
- }
+ // send ping and clear log events based on the result
+ if (sendUpdate(preferences, queryString))
+ {
+ EventLogger.getInstance().clearEvents();
}
+ else
+ {
+ // remove anything older than 28 days.
+ long fourWeeksAgo = DateUtils.addDayInterval(System.currentTimeMillis(), -28);
- return result;
+ EventLogger.getInstance().clearEvents(fourWeeksAgo);
+ }
}
/**
- * getUserAgent
- *
- * @return
+ * @see org.eclipse.ui.IStartup#earlyStartup()
*/
- private static String getUserAgent()
+ public void earlyStartup()
{
- return "Aptana/1.5"; //$NON-NLS-1$
+ if (Platform.inDevelopmentMode()) {
+ return;
+ }
+ Job job = new Job("Sending Ping...") //$NON-NLS-1$
+ {
+ @Override
+ protected IStatus run(IProgressMonitor monitor)
+ {
+ updateAnonymousId();
+ if (!ranOnce)
+ {
+ ranOnce = true;
+ }
+ schedule(TWENTY_FOUR_HOURS);
+ return Status.OK_STATUS;
+ }
+ };
+ job.setSystem(true);
+ job.setPriority(Job.BUILD);
+ job.schedule();
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.