[jbosstools-commits] JBoss Tools SVN: r24290 - trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Thu Aug 19 06:54:07 EDT 2010


Author: adietish
Date: 2010-08-19 06:54:06 -0400 (Thu, 19 Aug 2010)
New Revision: 24290

Added:
   trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/FocusPoint.java
   trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/HttpGetMethod.java
   trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/ILoggingAdapter.java
   trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/IURLBuildingStrategy.java
   trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/PluginLogger.java
   trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/Tracker.java
   trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/UsageMessages.java
   trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/internal/
   trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/messages.properties
Removed:
   trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/JBossToolsUsageActivator.java
Modified:
   trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/ITracker.java
Log:
[JBIDE-6376] packages refactored, strings externalized

Copied: trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/FocusPoint.java (from rev 24263, trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/googleanalytics/FocusPoint.java)
===================================================================
--- trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/FocusPoint.java	                        (rev 0)
+++ trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/FocusPoint.java	2010-08-19 10:54:06 UTC (rev 24290)
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * 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;
+
+import org.jboss.tools.usage.util.EncodingUtils;
+
+/**
+ * Focus point of the application. It can represent data points like application
+ * load, application module load, user actions, error events etc.
+ */
+public class FocusPoint {
+
+	private String name;
+	private FocusPoint childFocusPoint;
+	public static final String URI_SEPARATOR = "/";
+	public static final String TITLE_SEPARATOR = "-";
+
+	public FocusPoint(String name) {
+		this.name = name;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public FocusPoint setChild(FocusPoint childFocusPoint) {
+		this.childFocusPoint = childFocusPoint;
+		return this;
+	}
+
+	public FocusPoint getChild() {
+		return childFocusPoint;
+	}
+
+	public String getContentURI() {
+		StringBuilder builder = new StringBuilder();
+		appendContentURI(builder, this);
+		return EncodingUtils.checkedEncodeUtf8(builder.toString());
+	}
+
+	private void appendContentURI(StringBuilder builder, FocusPoint focusPoint) {
+		FocusPoint parentFocuPoint = focusPoint.getChild();
+		builder.append(URI_SEPARATOR);
+		builder.append(focusPoint.getName());
+		if (parentFocuPoint != null) {
+			appendContentURI(builder, parentFocuPoint);
+		}
+	}
+
+	public String getContentTitle() {
+		StringBuilder builder = new StringBuilder();
+		appendContentTitle(builder, this);
+		return EncodingUtils.checkedEncodeUtf8(builder.toString());
+	}
+
+	private void appendContentTitle(StringBuilder builder, FocusPoint focusPoint) {
+		FocusPoint childFocusPoint = focusPoint.getChild();
+		builder.append(focusPoint.getName());
+		if (childFocusPoint != null) {
+			builder.append(TITLE_SEPARATOR);
+			appendContentTitle(builder, childFocusPoint);
+		}
+	}
+}


Property changes on: trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/FocusPoint.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Copied: trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/HttpGetMethod.java (from rev 24289, trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/googleanalytics/HttpGetMethod.java)
===================================================================
--- trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/HttpGetMethod.java	                        (rev 0)
+++ trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/HttpGetMethod.java	2010-08-19 10:54:06 UTC (rev 24290)
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * 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;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.text.MessageFormat;
+
+
+/**
+ * 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"; //$NON-NLS-1$
+
+	private static final String GET_METHOD_NAME = "GET"; //$NON-NLS-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(UsageMessages.HttpGetMethod_Error_Http, urlString, responseCode));
+			} else {
+				loggingAdapter.logError(MessageFormat.format(UsageMessages.HttpGetMethod_Success, urlString));
+			}
+		} catch (Exception e) {
+			loggingAdapter.logMessage(MessageFormat.format(UsageMessages.HttpGetMethod_Error_Io, urlString, e.toString()));
+		} 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;
+	}
+}

Copied: trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/ILoggingAdapter.java (from rev 24263, trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/googleanalytics/ILoggingAdapter.java)
===================================================================
--- trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/ILoggingAdapter.java	                        (rev 0)
+++ trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/ILoggingAdapter.java	2010-08-19 10:54:06 UTC (rev 24290)
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * @author Andre Dietisheim
+ */
+public interface ILoggingAdapter {
+
+  public void logError(String errorMessage);
+
+  public void logMessage(String message);
+
+}


Property changes on: trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/ILoggingAdapter.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/ITracker.java
===================================================================
--- trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/ITracker.java	2010-08-19 09:53:32 UTC (rev 24289)
+++ trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/ITracker.java	2010-08-19 10:54:06 UTC (rev 24290)
@@ -2,7 +2,6 @@
 
 import java.io.UnsupportedEncodingException;
 
-import org.jboss.tools.usage.googleanalytics.FocusPoint;
 
 /**
  * @author Andre Dietisheim

Copied: trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/IURLBuildingStrategy.java (from rev 24263, trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/googleanalytics/IURLBuildingStrategy.java)
===================================================================
--- trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/IURLBuildingStrategy.java	                        (rev 0)
+++ trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/IURLBuildingStrategy.java	2010-08-19 10:54:06 UTC (rev 24290)
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * 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;
+
+import java.io.UnsupportedEncodingException;
+
+
+/**
+ * Interface for the URL building strategy
+ * 
+ * @author Andre Dietisheim
+ * 
+ */
+public interface IURLBuildingStrategy {
+
+	public String build(FocusPoint focusPoint) throws UnsupportedEncodingException;
+
+}


Property changes on: trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/IURLBuildingStrategy.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Deleted: trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/JBossToolsUsageActivator.java
===================================================================
--- trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/JBossToolsUsageActivator.java	2010-08-19 09:53:32 UTC (rev 24289)
+++ trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/JBossToolsUsageActivator.java	2010-08-19 10:54:06 UTC (rev 24290)
@@ -1,47 +0,0 @@
-/*******************************************************************************
- * 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;
-
-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);
-	}
-}

Copied: trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/PluginLogger.java (from rev 24289, trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/googleanalytics/PluginLogger.java)
===================================================================
--- trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/PluginLogger.java	                        (rev 0)
+++ trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/PluginLogger.java	2010-08-19 10:54:06 UTC (rev 24290)
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * 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;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.core.runtime.Status;
+
+/**
+ * @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);
+		}
+	}
+}

Copied: trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/Tracker.java (from rev 24289, trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/googleanalytics/Tracker.java)
===================================================================
--- trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/Tracker.java	                        (rev 0)
+++ trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/Tracker.java	2010-08-19 10:54:06 UTC (rev 24290)
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * 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;
+
+import java.text.MessageFormat;
+
+/**
+ * Reports (tracks) usage
+ * 
+ * @author Andre Dietisheim
+ * @see based on <a
+ *      href="http://jgoogleAnalytics.googlecode.com">http://jgoogleAnalytics.googlecode.com</a>
+ */
+public class Tracker implements ITracker {
+
+	private IURLBuildingStrategy urlBuildingStrategy = null;
+	private HttpGetMethod httpRequest;
+	private ILoggingAdapter loggingAdapter;
+
+	public Tracker(IURLBuildingStrategy urlBuildingStrategy, String userAgent, ILoggingAdapter loggingAdapter) {
+		this.httpRequest = new HttpGetMethod(userAgent, loggingAdapter);
+		this.loggingAdapter = loggingAdapter;
+		this.urlBuildingStrategy = urlBuildingStrategy;
+	}
+
+	public void trackSynchronously(FocusPoint focusPoint) {
+		loggingAdapter.logMessage(MessageFormat.format(UsageMessages.Tracker_Synchronous, focusPoint.getContentTitle()));
+		try {
+			httpRequest.request(urlBuildingStrategy.build(focusPoint));
+		} catch (Exception e) {
+			loggingAdapter.logMessage(MessageFormat.format(UsageMessages.Tracker_Error, e.getMessage()));
+		}
+	}
+
+	public void trackAsynchronously(FocusPoint focusPoint) {
+		loggingAdapter.logMessage(MessageFormat.format(UsageMessages.Tracker_Asynchronous, focusPoint.getContentTitle()));
+		new TrackingThread(focusPoint).start();
+	}
+
+	private class TrackingThread extends Thread {
+		private FocusPoint focusPoint;
+
+		public TrackingThread(FocusPoint focusPoint) {
+			this.focusPoint = focusPoint;
+			this.setPriority(Thread.MIN_PRIORITY);
+		}
+
+		public void run() {
+			try {
+				httpRequest.request(urlBuildingStrategy.build(focusPoint));
+			} catch (Exception e) {
+				loggingAdapter.logMessage(MessageFormat.format(UsageMessages.Tracker_Error, e.getMessage()));
+			}
+		}
+	}
+}


Property changes on: trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/Tracker.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/UsageMessages.java
===================================================================
--- trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/UsageMessages.java	                        (rev 0)
+++ trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/UsageMessages.java	2010-08-19 10:54:06 UTC (rev 24290)
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * 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;
+
+import org.eclipse.osgi.util.NLS;
+
+public class UsageMessages extends NLS {
+	private static final String BUNDLE_NAME = "org.jboss.tools.usage.messages"; //$NON-NLS-1$
+	public static String Tracker_Synchronous;
+	public static String Tracker_Asynchronous;
+	public static String Tracker_Error;
+
+	public static String HttpGetMethod_Error_Http;
+	public static String HttpGetMethod_Error_Io;
+	public static String HttpGetMethod_Success;
+
+	static {
+		// initialize resource bundle
+		NLS.initializeMessages(BUNDLE_NAME, UsageMessages.class);
+	}
+
+	private UsageMessages() {
+	}
+}


Property changes on: trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/UsageMessages.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/messages.properties
===================================================================
--- trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/messages.properties	                        (rev 0)
+++ trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/messages.properties	2010-08-19 10:54:06 UTC (rev 24290)
@@ -0,0 +1,7 @@
+HttpGetMethod_Error_Http=HTTP GET to \"{0}\" failed, response code received \"{1}\"
+HttpGetMethod_Error_Io=HTTP GET to \"{0}\" failed, exception occured: \"{1}\"
+HttpGetMethod_Success=HTTP GET to url \"{0}\" successfull\!
+
+Tracker_Asynchronous=Tracking asynchronously focusPoint \"{0}\"
+Tracker_Error=Tracking failed, exception thrown: \"{0}\"
+Tracker_Synchronous=Tracking synchronously focusPoint \"{0}\"


Property changes on: trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/messages.properties
___________________________________________________________________
Name: svn:mime-type
   + text/plain



More information about the jbosstools-commits mailing list