Author: adietish
Date: 2010-08-18 12:42:12 -0400 (Wed, 18 Aug 2010)
New Revision: 24264
Added:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/AbstractGoogleAnalyticsParameters.java
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/EclipseEnvironment.java
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/GoogleAnalyticsUrlStrategy.java
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/HttpGetMethod.java
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/JBossBundleGroups.java
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/JBossToolsUsageActivator.java
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/Messages.java
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/PluginLogger.java
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/UsageReport.java
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/UsageReportDispatcher.java
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/UsageReportEnablementDialog.java
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/UsageReportPreferences.java
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/messages.properties
Log:
[JBIDE-6376] package internal renamed to reporting
Added:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/AbstractGoogleAnalyticsParameters.java
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/AbstractGoogleAnalyticsParameters.java
(rev 0)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/AbstractGoogleAnalyticsParameters.java 2010-08-18
16:42:12 UTC (rev 24264)
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.usage.reporting;
+
+import org.jboss.tools.usage.googleanalytics.IGoogleAnalyticsParameters;
+
+/**
+ * @author Andre Dietisheim
+ */
+public abstract class AbstractGoogleAnalyticsParameters implements
IGoogleAnalyticsParameters {
+
+ private String accountName;
+ private String referral;
+ private String hostName;
+
+ public AbstractGoogleAnalyticsParameters(String accountName, String hostName, String
referral) {
+ this.accountName = accountName;
+ this.hostName = hostName;
+ this.referral = referral;
+ }
+
+ public String getAccountName() {
+ return accountName;
+ }
+
+ public String getHostname() {
+ return hostName;
+ }
+
+ public String getReferral() {
+ return referral;
+ }
+}
Added:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/EclipseEnvironment.java
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/EclipseEnvironment.java
(rev 0)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/EclipseEnvironment.java 2010-08-18
16:42:12 UTC (rev 24264)
@@ -0,0 +1,241 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.usage.reporting;
+
+import java.text.MessageFormat;
+import java.util.Random;
+
+import org.eclipse.core.runtime.IProduct;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.PlatformUI;
+import org.jboss.tools.usage.googleanalytics.IGoogleAnalyticsParameters;
+import org.jboss.tools.usage.preferences.IUsageReportPreferenceConstants;
+import org.jboss.tools.usage.util.BundleUtils;
+import org.jboss.tools.usage.util.PreferencesUtils;
+import org.jboss.tools.usage.util.StatusUtils;
+import org.jboss.tools.usage.util.BundleUtils.IBundleEntryFilter;
+import org.osgi.framework.Bundle;
+import org.osgi.service.prefs.BackingStoreException;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class EclipseEnvironment extends AbstractGoogleAnalyticsParameters implements
IGoogleAnalyticsParameters {
+
+ private static final char BUNDLE_GROUP_DELIMITER = '-';
+
+ private static final String JBOSS_TOOLS_BUNDLES_PREFIX =
"org\\.jboss\\.tools.+";
+
+ private static final String ECLIPSE_RUNTIME_BULDEID =
"org.eclipse.core.runtime";
+
+ private String screenResolution;
+
+ private String screenColorDepth;
+
+ private Random random;
+
+ public EclipseEnvironment(String accountName, String hostName, String referral) {
+ super(accountName, hostName, referral);
+ this.random = new Random();
+ initScreenSettings();
+ }
+
+ public String getBrowserLanguage() {
+ String nl = getNL();
+ if (nl == null) {
+ return "";
+ }
+
+ int indexOf = nl.indexOf(JAVA_LOCALE_DELIMITER); //$NON-NLS-1$
+ if (indexOf <= 0) {
+ return nl;
+ }
+
+ StringBuilder builder = new StringBuilder();
+ builder.append(nl.substring(0, indexOf));
+ builder.append(BROWSER_LOCALE_DELIMITER);
+ builder.append(nl.substring(indexOf + 1));
+ return builder.toString();
+ }
+
+ protected String getNL() {
+ return Platform.getNL(); //$NON-NLS-1$
+ }
+
+ protected void initScreenSettings() {
+ final Display display = getDisplay();
+ display.syncExec(new Runnable() {
+
+ public void run() {
+ screenColorDepth = display.getDepth() + SCREENCOLORDEPTH_POSTFIX;
+
+ Rectangle bounds = display.getBounds();
+ screenResolution = bounds.width + SCREERESOLUTION_DELIMITER + bounds.height;
+ }
+ });
+ }
+
+ public String getScreenResolution() {
+ return screenResolution;
+ }
+
+ public String getScreenColorDepth() {
+ return screenColorDepth;
+ }
+
+ protected Display getDisplay() {
+ if (PlatformUI.isWorkbenchRunning()) {
+ return PlatformUI.getWorkbench().getDisplay();
+ }
+
+ Display display = Display.getCurrent();
+ if (display == null) {
+ display = Display.getDefault();
+ }
+ return display;
+ }
+
+ public String getUserAgent() {
+
+ String productId = getApplicationName();
+ String productVersion = getApplicationVersion();
+ String browserLanguage = getBrowserLanguage();
+
+ /**
+ * Google API for android: this.userAgent = String.format(
+ * "GoogleAnalytics/%s (Linux; U; Android %s; %s-%s; %s; Build/%s)" ,
+ * new Object[] { "1.0" , Build.VERSION.RELEASE ,
+ * (localLocale.getLanguage() != null) ?
+ * localLocale.getLanguage().toLowerCase() : "en" ,
+ * (localLocale.getCountry() != null) ?
+ * localLocale.getCountry().toLowerCase() : "" , Build.MODEL, Build.ID
+ * });
+ */
+
+ return MessageFormat.format(
+ getUserAgentPattern(getOS())
+ , productId
+ , productVersion
+ , browserLanguage
+ );
+ }
+
+ private String getUserAgentPattern(String os) {
+ String userAgentPattern = "";
+ /*
+ * TODO: implement architecture (i686, x86_64 etc.), Windows version, MacOS version
etc.
+ */
+ if (Platform.OS_LINUX.equals(os)) {
+ return "{0}/{1} (X11; U; Linux i686; {2})";
+ } else if (Platform.OS_MACOSX.equals(os)) {
+ return "{0}/{1} (Macintosh; U; Intel Mac OS X 10.5; {2})";
+ } else if (Platform.OS_WIN32.equals(os)) {
+ return "{0}/{1} (Windows; U; Windows NT 6.1; {2})";
+ }
+ return userAgentPattern;
+ }
+
+ protected String getOS() {
+ return Platform.getOS();
+ }
+
+ protected String getApplicationName() {
+ return getApplicationBundle().getSymbolicName();
+ }
+
+ protected String getApplicationVersion() {
+ String fullVersion = getApplicationBundle().getVersion().toString();
+ int productVersionStart = fullVersion.lastIndexOf(VERSION_DELIMITER);
+ if (productVersionStart > 0) {
+ return fullVersion.substring(0, productVersionStart);
+ } else {
+ return fullVersion;
+ }
+ }
+
+ /**
+ * Returns the bundle that launched the application that this class runs in.
+ *
+ * @return the defining bundle
+ */
+ private Bundle getApplicationBundle() {
+ IProduct product = Platform.getProduct();
+ if (product != null) {
+ return product.getDefiningBundle();
+ } else {
+ return Platform.getBundle(ECLIPSE_RUNTIME_BULDEID);
+ }
+ }
+
+ public String getUserId() {
+ if
(PreferencesUtils.getStore().contains(IUsageReportPreferenceConstants.ECLIPSE_INSTANCE_ID))
{
+ return
PreferencesUtils.getStore().getString(IUsageReportPreferenceConstants.ECLIPSE_INSTANCE_ID);
+ } else {
+ String userId = createIdentifier();
+ PreferencesUtils.getStore().putValue(IUsageReportPreferenceConstants.ECLIPSE_INSTANCE_ID,
userId);
+ return userId;
+ }
+// IEclipsePreferences preferences = Preferences.getConfigurationPreferences();
+// String userId = createIdentifier();
+// try {
+// if (!preferences.nodeExists(IUsageReportPreferenceConstants.ECLIPSE_INSTANCE_ID)) {
+// preferences.put(IUsageReportPreferenceConstants.ECLIPSE_INSTANCE_ID, userId);
+// preferences.flush();
+// } else {
+// userId = preferences.get(IUsageReportPreferenceConstants.ECLIPSE_INSTANCE_ID,
userId);
+// }
+// } catch (BackingStoreException e) {
+// StatusUtils.getErrorStatus(JBossToolsUsageActivator.PLUGIN_ID, "Could not
retrieve {0} from preferences.",
+// e, IUsageReportPreferenceConstants.ECLIPSE_INSTANCE_ID);
+// }
+// return userId;
+ }
+
+ /**
+ * Creates an unique identifier.
+ *
+ * @return the identifier
+ */
+ private String createIdentifier() {
+ StringBuilder builder = new StringBuilder();
+ builder.append(Math.abs(random.nextLong()));
+ builder.append(System.currentTimeMillis());
+ return builder.toString();
+ }
+
+ public String getKeyword() {
+ JBossBundleGroups jbossBundleGroups = new JBossBundleGroups();
+ IBundleEntryFilter jbossToolsFilter = new
BundleUtils.BundleSymbolicNameFilter(JBOSS_TOOLS_BUNDLES_PREFIX);
+ IBundleEntryFilter compositeFilter = new BundleUtils.CompositeFilter(
+ jbossToolsFilter
+ , jbossBundleGroups );
+ BundleUtils.getBundles(compositeFilter, getBundles());
+
+ return bundleGroupsToKeywordString(jbossBundleGroups);
+ }
+
+ protected Bundle[] getBundles() {
+ return
JBossToolsUsageActivator.getDefault().getBundle().getBundleContext().getBundles();
+ }
+
+ private String bundleGroupsToKeywordString(JBossBundleGroups jbossBundleGroups) {
+ char delimiter = BUNDLE_GROUP_DELIMITER;
+ StringBuilder builder = new StringBuilder();
+ for (String bundleGroupId : jbossBundleGroups.getBundleGroupIds()) {
+ builder.append(bundleGroupId)
+ .append(delimiter);
+ }
+ return builder.toString();
+ }
+}
Added:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/GoogleAnalyticsUrlStrategy.java
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/GoogleAnalyticsUrlStrategy.java
(rev 0)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/GoogleAnalyticsUrlStrategy.java 2010-08-18
16:42:12 UTC (rev 24264)
@@ -0,0 +1,248 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.usage.reporting;
+
+import java.io.UnsupportedEncodingException;
+
+import org.jboss.tools.usage.googleanalytics.FocusPoint;
+import org.jboss.tools.usage.googleanalytics.IGoogleAnalyticsParameters;
+import org.jboss.tools.usage.googleanalytics.IURLBuildingStrategy;
+import org.jboss.tools.usage.util.EncodingUtils;
+
+/**
+ * Class that builds an URL that passes given parameters to google analytics
+ *
+ * @author Andre Dietisheim
+ */
+public class GoogleAnalyticsUrlStrategy implements IURLBuildingStrategy {
+
+ private static final String TRACKING_URL =
"http://www.google-analytics.com/__utm.gif";
+
+ private static final int VISITS = -1;
+
+ private IGoogleAnalyticsParameters googleParameters;
+
+ public GoogleAnalyticsUrlStrategy(IGoogleAnalyticsParameters googleAnalyticsParameters)
{
+ this.googleParameters = googleAnalyticsParameters;
+ }
+
+ public String build(FocusPoint focusPoint) throws UnsupportedEncodingException {
+ /*
+ * Google Analytics for Android:
+ *
+ String str = "";
+ if (paramEvent.action != null)
+ str = paramEvent.action;
+ if (!(str.startsWith("/")))
+ str = "/" + str;
+ str = encode(str);
+ Locale localLocale = Locale.getDefault();
+ StringBuilder localStringBuilder = new StringBuilder();
+ localStringBuilder.append("/__utm.gif");
+ localStringBuilder.append("?utmwv=4.3");
+ localStringBuilder.append("&utmn=").append(paramEvent.randomVal);
+ localStringBuilder.append("&utmcs=UTF-8");
+ localStringBuilder.append(String.format("&utmsr=%dx%d", new Object[] {
+ Integer.valueOf(paramEvent.screenWidth)
+ , Integer.valueOf(paramEvent.screenHeight) }));
+ localStringBuilder.append(String.format("&utmul=%s-%s", new Object[] {
+ localLocale.getLanguage()
+ , localLocale.getCountry() }));
+ localStringBuilder.append("&utmp=").append(str);
+ localStringBuilder.append("&utmac=").append(paramEvent.accountId);
+ localStringBuilder.append("&utmcc=").append(
+ getEscapedCookieString(paramEvent, paramString));
+ return localStringBuilder.toString();
+
+ *
+ * getEscapedCookieString:
+ *
+ StringBuilder localStringBuilder = new StringBuilder();
+ localStringBuilder.append("__utma=");
+ localStringBuilder.append("999").append(".");
+ localStringBuilder.append(paramEvent.userId).append(".");
+ localStringBuilder.append(paramEvent.timestampFirst).append(".");
+ localStringBuilder.append(paramEvent.timestampPrevious).append(".");
+ localStringBuilder.append(paramEvent.timestampCurrent).append(".");
+ localStringBuilder.append(paramEvent.visits);
+ if (paramString != null)
+ {
+ localStringBuilder.append("+__utmz=");
+ localStringBuilder.append("999").append(".");
+ localStringBuilder.append(paramEvent.timestampFirst).append(".");
+ localStringBuilder.append("1.1.");
+ localStringBuilder.append(paramString);
+ }
+ return encode(localStringBuilder.toString());
+
+ */
+
+ /*
+ * our working tracking code
+ *
+
http://www.google-analytics.com/__utm.gif?utmwv=4.7.2
+ &utmn=338321265
+ &utmhn=jboss.org
+ &utmcs=UTF-8
+ &utmsr=1920x1080
+ &utmsc=24-bit
+ &utmul=en-us
+ &utmje=1
+ &utmfl=10.1%20r53
+ &utmdt=-%20JBoss%20Community
+ &utmhid=1087431432
+ &utmr=0
+ &utmp=%2Ftools%2Fusage.html
+ &utmac=UA-17645367-1
+ &utmcc=__utma%3D156030500.1285760711.1281430767.1281430767.1281430767.1%3B%2B__utmz%3D156030500.1281430767.1.1.utmcsr%3D(direct)%7Cutmccn%3D(direct)%7Cutmcmd%3D(none)%3B
+ &gaq=1
+ *
+ */
+
+ StringBuilder builder = new StringBuilder(TRACKING_URL)
+ .append(IGoogleAnalyticsParameters.URL_PARAM_DELIMITER);
+ appendParameter(IGoogleAnalyticsParameters.PARAM_TRACKING_CODE_VERSION,
+ IGoogleAnalyticsParameters.VALUE_TRACKING_CODE_VERSION, builder);
+ appendParameter(IGoogleAnalyticsParameters.PARAM_UNIQUE_TRACKING_NUMBER,
getRandomNumber(), builder);
+ appendParameter(IGoogleAnalyticsParameters.PARAM_HOST_NAME,
googleParameters.getHostname(), builder);
+ appendParameter(IGoogleAnalyticsParameters.PARAM_LANGUAGE_ENCODING,
+ IGoogleAnalyticsParameters.VALUE_ENCODING_UTF8, builder);
+ appendParameter(IGoogleAnalyticsParameters.PARAM_SCREEN_RESOLUTION,
googleParameters.getScreenResolution(),
+ builder);
+ appendParameter(IGoogleAnalyticsParameters.PARAM_SCREEN_COLOR_DEPTH,
googleParameters.getScreenColorDepth(),
+ builder);
+ appendParameter(IGoogleAnalyticsParameters.PARAM_BROWSER_LANGUAGE,
googleParameters.getBrowserLanguage(),
+ builder);
+ appendParameter(IGoogleAnalyticsParameters.PARAM_PAGE_TITLE,
focusPoint.getContentTitle(), builder);
+ appendParameter(IGoogleAnalyticsParameters.PARAM_HID, getRandomNumber(), builder);
+ appendParameter(IGoogleAnalyticsParameters.PARAM_REFERRAL,
googleParameters.getReferral(), builder);
+ appendParameter(IGoogleAnalyticsParameters.PARAM_PAGE_REQUEST,
focusPoint.getContentURI(), builder);
+
+ appendParameter(IGoogleAnalyticsParameters.PARAM_ACCOUNT_NAME,
googleParameters.getAccountName(), builder);
+ appendParameter(IGoogleAnalyticsParameters.PARAM_COOKIES, getCookies(focusPoint),
builder);
+ appendParameter(IGoogleAnalyticsParameters.PARAM_GAQ, "1", false, builder);
+
+ return builder.toString();
+ }
+
+ private String getCookies(FocusPoint focusPoint) {
+ long timeStamp = System.currentTimeMillis();
+ StringBuilder builder = new StringBuilder();
+ builder.append(IGoogleAnalyticsParameters.PARAM_COOKIES_FIRST_VISIT)
+ .append(IGoogleAnalyticsParameters.EQUALS_SIGN)
+ .append("999.")
+ .append(googleParameters.getUserId()).append(IGoogleAnalyticsParameters.DOT)
+ .append(timeStamp).append(IGoogleAnalyticsParameters.DOT)
+ .append(timeStamp).append(IGoogleAnalyticsParameters.DOT)
+ .append(timeStamp).append(IGoogleAnalyticsParameters.DOT)
+ .append(VISITS)
+ .append(IGoogleAnalyticsParameters.SEMICOLON)
+ .append(IGoogleAnalyticsParameters.PLUS_SIGN)
+ .append(IGoogleAnalyticsParameters.PARAM_COOKIES_REFERRAL_TYPE)
+ .append(IGoogleAnalyticsParameters.EQUALS_SIGN)
+ .append("999.")
+ .append(timeStamp).append(IGoogleAnalyticsParameters.DOT)
+ .append("1.1.")
+ .append(IGoogleAnalyticsParameters.PARAM_COOKIES_UTMCSR).append(IGoogleAnalyticsParameters.EQUALS_SIGN)
+ .append("(direct)").append(IGoogleAnalyticsParameters.PIPE)
+ .append(IGoogleAnalyticsParameters.PARAM_COOKIES_UTMCCN).append(IGoogleAnalyticsParameters.EQUALS_SIGN)
+ .append("(direct)").append(IGoogleAnalyticsParameters.PIPE)
+ .append(IGoogleAnalyticsParameters.PARAM_COOKIES_UTMCMD).append(IGoogleAnalyticsParameters.EQUALS_SIGN)
+ .append("(none)");
+ appendCookieKeyword(builder);
+ builder.append(IGoogleAnalyticsParameters.SEMICOLON);
+
+ return EncodingUtils.checkedEncodeUtf8(builder.toString());
+
+ // builder.append(IGoogleAnalyticsParameters.PARAM_COOKIE_VALUES)
+ // .append(IGoogleAnalyticsParameters.EQUALS_SIGN)
+ // .append("__utma%3D")
+ // .append(getRandomNumber())
+ // .append(".")
+ // .append(getRandomNumber())
+ // .append(".")
+ // .append(now)
+ // .append(".")
+ // .append(now)
+ // .append(".")
+ // .append(now)
+ // .append(".2%3B%2B)")
+ //
+ // // .append("__utmb%3D")
+ // // .append(getRandomNumber())
+ // // .append("%3B%2B__utmc%3D")
+ // // .append(getRandomNumber())
+ // // .append("%3B%2B")
+ //
+ // .append("__utmz%3D")
+ // .append(getRandomNumber())
+ // .append(".")
+ // .append(now)
+ // .append(IGoogleAnalyticsParameters.AMPERSAND);
+
+ // .append("utmcsr%3D(direct)%7C")
+ // .append("utmccn%3D(direct)%7C")
+ // .append("utmcmd%3D(none)%3B");
+
+ }
+
+ /**
+ * Appends the keyword to the cookies.
+ *
+ * @param builder the builder to append to
+ */
+ private void appendCookieKeyword(StringBuilder builder) {
+ String keyword = googleParameters.getKeyword();
+ if (keyword != null && keyword.length() > 0) {
+ builder.append(IGoogleAnalyticsParameters.PIPE)
+ .append(IGoogleAnalyticsParameters.PARAM_COOKIES_KEYWORD)
+ .append(IGoogleAnalyticsParameters.EQUALS_SIGN)
+ .append(keyword);
+ }
+ }
+
+ private String getRandomNumber() {
+ return Integer.toString((int) (Math.random() * 0x7fffffff));
+ }
+
+ private void appendParameter(String name, String value, StringBuilder builder) {
+ appendParameter(name, value, true, builder);
+ }
+
+ private void appendParameter(String name, String value, boolean appendAmpersand,
StringBuilder builder) {
+ builder.append(name)
+ .append(IGoogleAnalyticsParameters.EQUALS_SIGN)
+ .append(value);
+ if (appendAmpersand) {
+ builder.append(IGoogleAnalyticsParameters.AMPERSAND);
+ }
+ }
+
+ // private String getIpAddress() throws SocketException {
+ // Enumeration<NetworkInterface> e1 =
+ // (Enumeration<NetworkInterface>)NetworkInterface.getNetworkInterfaces();
+ // while(e1.hasMoreElements()) {
+ // NetworkInterface ni = e1.nextElement();
+ //
+ // System.out.print(ni.getName());
+ // System.out.print(" : [");
+ // Enumeration<InetAddress> e2 = ni.getInetAddresses();
+ // while(e2.hasMoreElements()) {
+ // InetAddress ia = e2.nextElement();
+ // System.out.print(ia);
+ // if( e2.hasMoreElements()) {
+ // System.out.print(",");
+ // }
+ // }
+ // System.out.println("]");
+ // }
+ // }
+}
Added:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/HttpGetMethod.java
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/HttpGetMethod.java
(rev 0)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/HttpGetMethod.java 2010-08-18
16:42:12 UTC (rev 24264)
@@ -0,0 +1,102 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.usage.reporting;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.text.MessageFormat;
+
+import org.jboss.tools.usage.googleanalytics.ILoggingAdapter;
+
+/**
+ * Class that executes a HTTP Get request to the given url.
+ *
+ * @author Andre Dietisheim
+ */
+public class HttpGetMethod {
+
+ private static final String USER_AGENT = "User-Agent";
+
+ private static final String GET_METHOD_NAME = "GET";
+
+ private static final String SUCCESS_MESSAGE = "Http Get to url {0}
successfull!";
+
+ private static final String ERROR_MESSAGE = "Http Get to {0} failed, response code
was {1}";
+
+ private ILoggingAdapter loggingAdapter = null;
+
+// private CookieHandler cookieHandler;
+
+ private String userAgent;
+
+ public HttpGetMethod(String userAgent, ILoggingAdapter loggingAdapter) {
+ this.userAgent = userAgent;
+ this.loggingAdapter = loggingAdapter;
+// this.cookieHandler = new CookieHandler();
+// this.cookieHandler = CookieHandler.getDefault();
+// cookieHandler.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
+ }
+
+ public void request(String urlString) {
+
+// CookieHandler currentCookieHandler = setCookieHandler(cookieHandler);
+ try {
+ HttpURLConnection urlConnection = createURLConnection(urlString, userAgent);
+ urlConnection.connect();
+ int responseCode = getResponseCode(urlConnection);
+ if (responseCode != HttpURLConnection.HTTP_OK) {
+ loggingAdapter.logMessage(MessageFormat.format(ERROR_MESSAGE, urlString,
responseCode));
+ } else {
+ loggingAdapter.logError(MessageFormat.format(SUCCESS_MESSAGE, urlString));
+ }
+ } catch (Exception e) {
+ loggingAdapter.logError(e.getMessage());
+ } finally {
+// setCookieHandler(currentCookieHandler);
+ }
+ }
+
+ /**
+ * Returns the return code from the given {@link HttpURLConnection}.
+ * Provided to be called by test cases so that they can retrieve the return code.
+ *
+ * @param urlConnection to get the response code from
+ * @return the return code the HttpUrlConnection received
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
+ protected int getResponseCode(HttpURLConnection urlConnection) throws IOException {
+ return urlConnection.getResponseCode();
+ }
+
+// private CookieHandler setCookieHandler(CookieHandler cookieHandler) {
+// CookieHandler currentCookieHandler = CookieHandler.getDefault();
+// CookieHandler.setDefault(cookieHandler);
+// return currentCookieHandler;
+// }
+
+ /**
+ * Creates a new url connection.
+ *
+ * @param urlString the url string
+ * @param userAgent the user agent
+ * @return the http url connection
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
+ protected HttpURLConnection createURLConnection(String urlString, String userAgent)
throws IOException {
+ URL url = new URL(urlString);
+ HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
+ urlConnection.setInstanceFollowRedirects(true);
+ urlConnection.setRequestMethod(GET_METHOD_NAME);
+ urlConnection.setRequestProperty(USER_AGENT, userAgent);
+ return urlConnection;
+ }
+}
Added:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/JBossBundleGroups.java
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/JBossBundleGroups.java
(rev 0)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/JBossBundleGroups.java 2010-08-18
16:42:12 UTC (rev 24264)
@@ -0,0 +1,223 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.usage.reporting;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.tools.usage.util.BundleUtils.IBundleEntryFilter;
+import org.osgi.framework.Bundle;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class JBossBundleGroups implements IBundleEntryFilter {
+
+ public enum BundleGroup {
+ ARCHIVES("org.jboss.ide.eclipse.archives.core",
+ "org.jboss.ide.eclipse.archives.jdt.integration",
+ "org.jboss.ide.eclipse.archives.ui"
+ )
+ , AS("org.jboss.ide.eclipse.archives.webtools",
+ "org.jboss.ide.eclipse.as.classpath.core",
+ "org.jboss.ide.eclipse.as.classpath.ui",
+ "org.jboss.ide.eclipse.as.core",
+ "org.jboss.ide.eclipse.as.doc.user",
+ "org.jboss.ide.eclipse.as.ssh",
+ "org.jboss.ide.eclipse.as.ui",
+ "org.jboss.ide.eclipse.as.ui.mbeans",
+ "org.jboss.ide.eclipse.as.wtp.core",
+ "org.jboss.ide.eclipse.as.wtp.ui")
+ , BIRT("org.jboss.tools.birt.core",
+ "org.jboss.tools.birt.oda",
+ "org.jboss.tools.birt.oda.ui")
+ , BPEL("org.eclipse.bpel.apache.ode.deploy.model",
+ "org.eclipse.bpel.apache.ode.deploy.ui",
+ "org.eclipse.bpel.common.model",
+ "org.eclipse.bpel.common.ui",
+ "org.eclipse.bpel.model",
+ "org.eclipse.bpel.ui",
+ "org.eclipse.bpel.validator",
+ "org.eclipse.bpel.wsil.model",
+ "org.eclipse.bpel.xpath10",
+ "org.jboss.tools.bpel.cheatsheet",
+ "org.jboss.tools.bpel.runtimes")
+ , CDI("org.jboss.tools.cdi.core",
+ "org.jboss.tools.cdi.text.ext",
+ "org.jboss.tools.cdi.ui",
+ "org.jboss.tools.cdi.xml",
+ "org.jboss.tools.cdi.xml.ui")
+ , DELTACLOUD("org.jboss.tools.deltacloud.core",
+ "org.jboss.tools.deltacloud.ui")
+ , DROOLS("org.drools.eclipse",
+ "org.drools.eclipse.task",
+ "org.eclipse.webdav",
+ "org.guvnor.tools",
+ "org.jboss.tools.flow.ruleflow")
+ , ESB("org.jboss.tools.esb.core",
+ "org.jboss.tools.esb.project.core",
+ "org.jboss.tools.esb.project.ui",
+ "org.jboss.tools.esb.ui",
+ "org.jboss.tools.esb.validator")
+ , FLOW("org.jboss.tools.flow.common")
+ , FREEMARKER("org.jboss.ide.eclipse.freemarker")
+ , GWT("org.jboss.tools.gwt.core",
+ "org.jboss.tools.gwt.ui")
+ , HIBERNATETOOLS("org.hibernate.eclipse",
+ "org.hibernate.eclipse.console",
+ "org.hibernate.eclipse.help",
+ "org.hibernate.eclipse.jdt.apt.ui",
+ "org.hibernate.eclipse.jdt.ui",
+ "org.hibernate.eclipse.mapper",
+ "org.jboss.tools.hibernate.jpt.core",
+ "org.jboss.tools.hibernate.jpt.ui",
+ "org.jboss.tools.hibernate.ui",
+ "org.jboss.tools.hibernate.xml",
+ "org.jboss.tools.hibernate.xml.ui")
+ , JBPM("org.jboss.tools.flow.jpdl4",
+ "org.jboss.tools.flow.jpdl4.multipage",
+ "org.jboss.tools.jbpm.common",
+ "org.jboss.tools.jbpm.convert",
+ "org.jbpm.gd.jpdl")
+ , JMX("org.jboss.tools.jmx.core",
+ "org.jboss.tools.jmx.ui")
+ , JSF("org.jboss.tools.jsf",
+ "org.jboss.tools.jsf.doc.user",
+ "org.jboss.tools.jsf.text.ext",
+ "org.jboss.tools.jsf.text.ext.facelets",
+ "org.jboss.tools.jsf.text.ext.richfaces",
+ "org.jboss.tools.jsf.ui",
+ "org.jboss.tools.jsf.verification",
+ "org.jboss.tools.jsf.vpe.ajax4jsf",
+ "org.jboss.tools.jsf.vpe.facelets",
+ "org.jboss.tools.jsf.vpe.jbpm",
+ "org.jboss.tools.jsf.vpe.jsf",
+ "org.jboss.tools.jsf.vpe.jstl",
+ "org.jboss.tools.jsf.vpe.myfaces",
+ "org.jboss.tools.jsf.vpe.richfaces",
+ "org.jboss.tools.jsf.vpe.seam")
+ , JST("org.jboss.tools.jst.css",
+ "org.jboss.tools.jst.firstrun",
+ "org.jboss.tools.jst.jsp",
+ "org.jboss.tools.jst.text.ext",
+ "org.jboss.tools.jst.web",
+ "org.jboss.tools.jst.web.kb",
+ "org.jboss.tools.jst.web.tiles",
+ "org.jboss.tools.jst.web.tiles.ui",
+ "org.jboss.tools.jst.web.ui",
+ "org.jboss.tools.jst.web.verification")
+ , LABS("org.jboss.tools.labs.pde.sourceprovider")
+ , MAVEN("org.jboss.tools.maven.cdi",
+ "org.jboss.tools.maven.core",
+ "org.jboss.tools.maven.hibernate",
+ "org.jboss.tools.maven.jsf",
+ "org.jboss.tools.maven.portlet",
+ "org.jboss.tools.maven.seam",
+ "org.jboss.tools.maven.ui")
+ , MODESHAPE("org.jboss.tools.modeshape.rest")
+ , PORTLET("org.jboss.tools.portlet.core",
+ "org.jboss.tools.portlet.ui")
+ , PROFILER("org.jboss.tools.profiler.ui")
+ , RUNTIME("org.jboss.tools.runtime")
+ , SEAM("org.jboss.tools.seam.core",
+ "org.jboss.tools.seam.doc.user",
+ "org.jboss.tools.seam.pages.xml",
+ "org.jboss.tools.seam.text.ext",
+ "org.jboss.tools.seam.ui",
+ "org.jboss.tools.seam.ui.pages",
+ "org.jboss.tools.seam.xml",
+ "org.jboss.tools.seam.xml.ui")
+ , SMOOKS("org.jboss.tools.smooks.core",
+ "org.jboss.tools.smooks.runtime",
+ "org.jboss.tools.smooks.templating",
+ "org.jboss.tools.smooks.ui")
+ , STRUTS("org.jboss.tools.struts",
+ "org.jboss.tools.struts.text.ext",
+ "org.jboss.tools.struts.ui",
+ "org.jboss.tools.struts.validator.ui",
+ "org.jboss.tools.struts.verification",
+ "org.jboss.tools.struts.vpe.struts")
+ , TPTP("org.jboss.tools.eclipse.as.tptp")
+ , VPE("org.jboss.tools.vpe",
+ "org.jboss.tools.vpe.docbook",
+ "org.jboss.tools.vpe.html",
+ "org.jboss.tools.vpe.jsp",
+ "org.jboss.tools.vpe.resref",
+ "org.jboss.tools.vpe.spring",
+ "org.jboss.tools.vpe.ui.palette",
+ "org.jboss.tools.vpe.xulrunner",
+ "org.jboss.tools.xulrunner",
+ "org.jboss.tools.xulrunner.initializer")
+ , WORKINGSET("org.jboss.tools.workingset.core",
+ "org.jboss.tools.workingset.ui")
+ , WS("rg.jboss.tools.ws.core",
+ "org.jboss.tools.ws.creation.core",
+ "org.jboss.tools.ws.creation.ui",
+ "org.jboss.tools.ws.ui")
+ , XULRUNNER("org.mozilla.xpcom",
+ "org.mozilla.xulrunner.carbon.macosx",
+ "org.mozilla.xulrunner.cocoa.macosx",
+ "org.mozilla.xulrunner.gtk.linux.x86",
+ "org.mozilla.xulrunner.gtk.linux.x86_64",
+ "org.mozilla.xulrunner.win32.win32.x86");
+
+ private String[] bundleNames;
+
+ BundleGroup(String... bundleNames) {
+ this.bundleNames = bundleNames;
+ }
+
+ /**
+ * Returns <tt>true</tt> if the given bundle name is a member of this
+ * bundle group.
+ *
+ * @param bundleName
+ * the bundle name to check whether it's a member of this
+ * group of bundles.
+ * @return <tt>true</tt>, if the given bundle
+ */
+ public boolean isMember(String bundleName) {
+ boolean isMember = false;
+ for (String name : bundleNames) {
+ if (name.equals(bundleName)) {
+ return true;
+ }
+ }
+ return isMember;
+ }
+
+ public void addGroupIdTo(Collection<String> bundleGroupIds) {
+ bundleGroupIds.add(name());
+ }
+ }
+
+ private Set<String> jbossBundleGroups = new HashSet<String>();
+
+ /**
+ * Collects the bundle groups the bundles it gets belong
+ * to. Always returns <tt>true</tt> (does match) while collecting
+ */
+ public boolean matches(Bundle bundle) {
+ String bundleName = bundle.getSymbolicName();
+ for (BundleGroup bundleGroup : BundleGroup.values()) {
+ if (bundleGroup.isMember(bundleName)) {
+ jbossBundleGroups.add(bundleGroup.name());
+ break;
+ }
+ }
+ return true;
+ }
+
+ public Collection<String> getBundleGroupIds() {
+ return jbossBundleGroups;
+ }
+}
\ No newline at end of file
Added:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/JBossToolsUsageActivator.java
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/JBossToolsUsageActivator.java
(rev 0)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/JBossToolsUsageActivator.java 2010-08-18
16:42:12 UTC (rev 24264)
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.usage.reporting;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class JBossToolsUsageActivator extends AbstractUIPlugin {
+
+ public static final String PLUGIN_ID = "org.jboss.tools.usage"; //$NON-NLS-1$
+
+ private static JBossToolsUsageActivator plugin;
+
+ public JBossToolsUsageActivator() {
+ plugin = this;
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ public static JBossToolsUsageActivator getDefault() {
+ return plugin;
+ }
+
+ public static ImageDescriptor getImageDescriptor(String path) {
+ return imageDescriptorFromPlugin(PLUGIN_ID, path);
+ }
+
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ }
+}
Added:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/Messages.java
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/Messages.java
(rev 0)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/Messages.java 2010-08-18
16:42:12 UTC (rev 24264)
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.usage.reporting;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME =
"org.jboss.tools.usage.reporting.messages"; //$NON-NLS-1$
+ public static String UsageReport_Checkbox_Text;
+ public static String UsageReport_DialogMessage;
+ public static String UsageReport_DialogTitle;
+
+ public static String UsageReport_Error_SavePreferences;
+ public static String UsageReport_GoogleAnalyticsAccount;
+ public static String UsageReport_HostName;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
Added:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/PluginLogger.java
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/PluginLogger.java
(rev 0)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/PluginLogger.java 2010-08-18
16:42:12 UTC (rev 24264)
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.usage.reporting;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.core.runtime.Status;
+import org.jboss.tools.usage.googleanalytics.ILoggingAdapter;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class PluginLogger implements ILoggingAdapter {
+
+ private Plugin plugin;
+
+ public PluginLogger(Plugin plugin) {
+ this.plugin = plugin;
+ }
+
+ public void logError(String message) {
+ log(IStatus.ERROR, message);
+ }
+
+ public void logMessage(String message) {
+ log(IStatus.INFO, message);
+ }
+
+ private void log(int severity, String message) {
+ if (plugin != null) {
+ IStatus status = new Status(severity, plugin.getBundle().getSymbolicName(), message);
+ plugin.getLog().log(status);
+ }
+ }
+}
Added:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/UsageReport.java
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/UsageReport.java
(rev 0)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/UsageReport.java 2010-08-18
16:42:12 UTC (rev 24264)
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.usage.reporting;
+
+import org.jboss.tools.usage.ITracker;
+import org.jboss.tools.usage.googleanalytics.FocusPoint;
+import org.jboss.tools.usage.googleanalytics.IGoogleAnalyticsParameters;
+import org.jboss.tools.usage.googleanalytics.ILoggingAdapter;
+import org.jboss.tools.usage.googleanalytics.IURLBuildingStrategy;
+import org.jboss.tools.usage.googleanalytics.Tracker;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class UsageReport {
+
+ private static final String GANALYTICS_ACCOUNTNAME =
Messages.UsageReport_GoogleAnalyticsAccount;
+
+ private static final String HOST_NAME = Messages.UsageReport_HostName;
+
+ private FocusPoint focusPoint = new FocusPoint("jboss.org").setChild(new
FocusPoint("tools") //$NON-NLS-1$ //$NON-NLS-2$
+ .setChild(new FocusPoint("usage").setChild(new
FocusPoint("action") //$NON-NLS-1$ //$NON-NLS-2$
+ .setChild(new FocusPoint("wsstartup"))))); //$NON-NLS-1$
+
+ public void report() {
+ if (UsageReportPreferences.isEnabled()) {
+ report(getAnalyticsTracker());
+ }
+ }
+
+ private void report(ITracker tracker) {
+ tracker.trackAsynchronously(focusPoint);
+ }
+
+ private ITracker getAnalyticsTracker() {
+ IGoogleAnalyticsParameters eclipseSettings = new EclipseEnvironment(
+ GANALYTICS_ACCOUNTNAME
+ , HOST_NAME
+ , IGoogleAnalyticsParameters.VALUE_NO_REFERRAL);
+ ILoggingAdapter loggingAdapter = new
PluginLogger(JBossToolsUsageActivator.getDefault());
+ IURLBuildingStrategy urlStrategy = new GoogleAnalyticsUrlStrategy(eclipseSettings);
+ return new Tracker(urlStrategy, eclipseSettings.getUserAgent(), loggingAdapter);
+ }
+}
Added:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/UsageReportDispatcher.java
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/UsageReportDispatcher.java
(rev 0)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/UsageReportDispatcher.java 2010-08-18
16:42:12 UTC (rev 24264)
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.usage.reporting;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IStartup;
+import org.eclipse.ui.PlatformUI;
+import org.jboss.tools.usage.reporting.Messages;
+import org.jboss.tools.usage.util.StatusUtils;
+import org.osgi.service.prefs.BackingStoreException;
+
+/**
+ * @author Andre Dieitsheim
+ */
+public class UsageReportDispatcher implements IStartup {
+
+ public void earlyStartup() {
+ Display.getDefault().asyncExec(new Runnable() {
+
+ public void run() {
+ UsageReportEnablementDialog dialog = new
UsageReportEnablementDialog(Messages.UsageReport_DialogTitle,
+ Messages.UsageReport_DialogMessage,
+ Messages.UsageReport_Checkbox_Text,
+ true,
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow());
+ if (UsageReportPreferences.isAskUser()) {
+ if (dialog.open() == Window.OK) {
+ UsageReportPreferences.setEnabled(dialog.isReportEnabled());
+ UsageReportPreferences.setAskUser(false);
+ flushPreferences();
+ }
+ }
+
+ if (UsageReportPreferences.isEnabled()) {
+ new UsageReport().report();
+ }
+ }
+
+ private void flushPreferences() {
+ try {
+ UsageReportPreferences.flush();
+ } catch (BackingStoreException e) {
+ IStatus status = StatusUtils.getErrorStatus(JBossToolsUsageActivator.PLUGIN_ID,
+ Messages.UsageReport_Error_SavePreferences, e);
+ JBossToolsUsageActivator.getDefault().getLog().log(status);
+ }
+ }
+ });
+ }
+}
Added:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/UsageReportEnablementDialog.java
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/UsageReportEnablementDialog.java
(rev 0)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/UsageReportEnablementDialog.java 2010-08-18
16:42:12 UTC (rev 24264)
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.usage.reporting;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.window.IShellProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class UsageReportEnablementDialog extends Dialog {
+
+ private Button checkBox;
+ private String title;
+ private String message;
+ private boolean reportEnabled;
+ private String checkBoxLabel;
+
+ public UsageReportEnablementDialog(String title, String message, String checkBoxLabel,
+ boolean reportEnabled, IShellProvider parentShell) {
+ super(parentShell);
+ this.title = title;
+ this.message = message;
+ this.checkBoxLabel = checkBoxLabel;
+ this.reportEnabled = reportEnabled;
+ }
+
+ protected void buttonPressed(int buttonId) {
+ if (buttonId == IDialogConstants.OK_ID) {
+ this.reportEnabled = checkBox.getSelection();
+ }
+ else if (buttonId == IDialogConstants.CANCEL_ID) {
+ this.reportEnabled = false;
+ }
+ super.buttonPressed(buttonId);
+ }
+
+ protected void configureShell(Shell shell) {
+ super.configureShell(shell);
+ if (title != null) {
+ shell.setText(title);
+ }
+ }
+
+ protected void createButtonsForButtonBar(Composite parent) {
+ createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
+ createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL,
false);
+ checkBox.setFocus();
+ checkBox.setSelection(reportEnabled);
+ }
+
+ protected Control createDialogArea(Composite parent) {
+ Composite composite = (Composite) super.createDialogArea(parent);
+ if (message != null) {
+ Label label = new Label(composite, SWT.WRAP);
+ label.setFont(parent.getFont());
+ label.setText(message);
+ GridDataFactory.fillDefaults()
+ .align(SWT.FILL, SWT.CENTER).grab(true, false)
+ .hint(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH, SWT.DEFAULT)
+ .applyTo(label);
+ }
+ checkBox = new Button(composite, SWT.CHECK);
+ checkBox.setText(checkBoxLabel);
+ GridDataFactory.fillDefaults().grab(true, false).align(SWT.LEFT,
SWT.CENTER).applyTo(checkBox);
+ applyDialogFont(composite);
+ return composite;
+ }
+
+ public boolean isReportEnabled() {
+ return reportEnabled;
+ }
+}
Added:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/UsageReportPreferences.java
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/UsageReportPreferences.java
(rev 0)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/UsageReportPreferences.java 2010-08-18
16:42:12 UTC (rev 24264)
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.usage.reporting;
+
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.jboss.tools.usage.preferences.IUsageReportPreferenceConstants;
+import org.jboss.tools.usage.util.PreferencesUtils;
+import org.jboss.tools.usage.util.StatusUtils;
+import org.osgi.service.prefs.BackingStoreException;
+
+public class UsageReportPreferences {
+
+ public static void setEnabled(boolean enabled) {
+ PreferencesUtils.getStore().putValue(
+ IUsageReportPreferenceConstants.USAGEREPORT_ENABLED_ID, String.valueOf(enabled));
+ }
+
+ public static boolean isEnabled() {
+ return PreferencesUtils.getPreferences().getBoolean(
+ IUsageReportPreferenceConstants.USAGEREPORT_ENABLED_ID,
+ IUsageReportPreferenceConstants.USAGEREPORT_ENABLED_DEFAULTVALUE);
+ }
+
+ public static void flush() throws BackingStoreException {
+ PreferencesUtils.getPreferences().flush();
+ }
+
+ public static IPreferenceStore createPreferenceStore() {
+ return PreferencesUtils.getStore();
+ }
+
+ public static boolean isAskUser() {
+ IEclipsePreferences preferences = PreferencesUtils.getPreferences();
+ return preferences.getBoolean(IUsageReportPreferenceConstants.ASK_USER_USAGEREPORT_ID,
true);
+ }
+
+ public static void setAskUser(boolean askUser) {
+ try {
+ IEclipsePreferences preferences = PreferencesUtils.getPreferences();
+ preferences.putBoolean(IUsageReportPreferenceConstants.ASK_USER_USAGEREPORT_ID,
askUser);
+ preferences.flush();
+ } catch (BackingStoreException e) {
+ JBossToolsUsageActivator.getDefault().getLog().log(
+ StatusUtils.getErrorStatus(JBossToolsUsageActivator.PLUGIN_ID,
+ Messages.UsageReport_Error_SavePreferences, e,
+ IUsageReportPreferenceConstants.ASK_USER_USAGEREPORT_ID));
+ }
+ }
+}
Added:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/messages.properties
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/messages.properties
(rev 0)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/messages.properties 2010-08-18
16:42:12 UTC (rev 24264)
@@ -0,0 +1,6 @@
+UsageReport_Checkbox_Text=Report usage anonymously to Red Hat Inc.
+UsageReport_DialogMessage=Please allow Red Hat Inc. to report this installation
anynomously for statistical matters.
+UsageReport_DialogTitle=Report usage
+UsageReport_Error_SavePreferences=Could not save preferences {0}
+UsageReport_GoogleAnalyticsAccount=UA-17645367-1
+UsageReport_HostName=jboss.org