[jbosstools-commits] JBoss Tools SVN: r24253 - in trunk/usage: plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util and 1 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Wed Aug 18 05:21:54 EDT 2010


Author: adietish
Date: 2010-08-18 05:21:54 -0400 (Wed, 18 Aug 2010)
New Revision: 24253

Modified:
   trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/internal/EclipseEnvironment.java
   trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/internal/JBossBundleGroups.java
   trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/BundleUtils.java
   trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/EclipseEnvironmenTest.java
Log:
[JBIDE-6376] test for bundle reporting added


Modified: trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/internal/EclipseEnvironment.java
===================================================================
--- trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/internal/EclipseEnvironment.java	2010-08-18 08:12:50 UTC (rev 24252)
+++ trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/internal/EclipseEnvironment.java	2010-08-18 09:21:54 UTC (rev 24253)
@@ -33,6 +33,10 @@
  */
 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;
@@ -211,17 +215,21 @@
 	@Override
 	public String getKeyword() {
 		JBossBundleGroups jbossBundleGroups = new JBossBundleGroups();
-		IBundleEntryFilter jbossToolsFilter = new BundleUtils.BundleSymbolicNameFilter("org\\.jboss\\.tools.+");
+		IBundleEntryFilter jbossToolsFilter = new BundleUtils.BundleSymbolicNameFilter(JBOSS_TOOLS_BUNDLES_PREFIX);
 		IBundleEntryFilter compositeFilter = new BundleUtils.CompositeFilter(
 				jbossToolsFilter
 				, jbossBundleGroups );
-		BundleUtils.getBundles(compositeFilter, JBossToolsUsageActivator.getDefault().getBundle().getBundleContext());
+		BundleUtils.getBundles(compositeFilter, getBundles());
 		
 		return bundleGroupsToKeywordString(jbossBundleGroups);
 	}
+
+	protected Bundle[] getBundles() {
+		return JBossToolsUsageActivator.getDefault().getBundle().getBundleContext().getBundles();
+	}
 	
 	private String bundleGroupsToKeywordString(JBossBundleGroups jbossBundleGroups) {
-		char delimiter = '-';
+		char delimiter = BUNDLE_GROUP_DELIMITER;
 		StringBuilder builder = new StringBuilder();
 		for (String bundleGroupId : jbossBundleGroups.getBundleGroupIds()) {
 			builder.append(bundleGroupId)

Modified: trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/internal/JBossBundleGroups.java
===================================================================
--- trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/internal/JBossBundleGroups.java	2010-08-18 08:12:50 UTC (rev 24252)
+++ trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/internal/JBossBundleGroups.java	2010-08-18 09:21:54 UTC (rev 24253)
@@ -22,7 +22,7 @@
  */
 public class JBossBundleGroups implements IBundleEntryFilter {
 
-	enum BundleGroup {
+	public enum BundleGroup {
 		ARCHIVES("org.jboss.ide.eclipse.archives.core",
 				"org.jboss.ide.eclipse.archives.jdt.integration",
 				"org.jboss.ide.eclipse.archives.ui"

Modified: trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/BundleUtils.java
===================================================================
--- trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/BundleUtils.java	2010-08-18 08:12:50 UTC (rev 24252)
+++ trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/BundleUtils.java	2010-08-18 09:21:54 UTC (rev 24253)
@@ -16,7 +16,6 @@
 
 import org.eclipse.core.runtime.Assert;
 import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
 
 
 /**
@@ -26,16 +25,14 @@
 
 	/**
 	 * Returns the bundles among the available ones that match the given filter.
-	 * 
-	 * @param filter
-	 *            the filter to match the available bundles against
-	 * @param bundleContext
-	 *            the bundle context
+	 *
+	 * @param filter the filter to match the available bundles against
+	 * @param bundles the bundles
 	 * @return the bundles that match the given filter
 	 */
-	public static List<Bundle> getBundles(IBundleEntryFilter filter, BundleContext bundleContext) {
+	public static List<Bundle> getBundles(IBundleEntryFilter filter, Bundle[] bundles) {
 		List<Bundle> bundleList = new ArrayList<Bundle>();
-		for (Bundle bundle : bundleContext.getBundles()) {
+		for (Bundle bundle : bundles) {
 			if (filter.matches(bundle)) {
 				bundleList.add(bundle);
 			}
@@ -45,15 +42,13 @@
 
 	/**
 	 * Returns the bundles that have a symbolic name that match the given regex.
-	 * 
-	 * @param bundleSymbolicNameRegex
-	 *            the symbolic name regex to match.
-	 * @param bundleContext
-	 *            the bundle context
+	 *
+	 * @param bundleSymbolicNameRegex the symbolic name regex to match.
+	 * @param bundles the bundles
 	 * @return the bundles
 	 */
-	public static List<Bundle> getBundles(String bundleSymbolicNameRegex, BundleContext bundleContext) {
-		return getBundles(new BundleSymbolicNameFilter(bundleSymbolicNameRegex), bundleContext);
+	public static List<Bundle> getBundles(String bundleSymbolicNameRegex, Bundle[] bundles) {
+		return getBundles(new BundleSymbolicNameFilter(bundleSymbolicNameRegex), bundles);
 	}
 
 	/**

Modified: trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/EclipseEnvironmenTest.java
===================================================================
--- trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/EclipseEnvironmenTest.java	2010-08-18 08:12:50 UTC (rev 24252)
+++ trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/EclipseEnvironmenTest.java	2010-08-18 09:21:54 UTC (rev 24253)
@@ -13,13 +13,24 @@
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
-import java.io.UnsupportedEncodingException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import org.eclipse.core.runtime.Platform;
 import org.jboss.tools.usage.internal.EclipseEnvironment;
+import org.jboss.tools.usage.internal.JBossBundleGroups;
 import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.Version;
 
 /**
  * @author Andre Dietisheim
@@ -32,7 +43,7 @@
 	private static final String LOCALE_US = "en_US";
 
 	@Test
-	public void testMacOs() throws UnsupportedEncodingException {
+	public void testMacOs() {
 		EclipseEnvironment eclipseEnvironment = new EclipseEnvironmentFake(GANALYTICS_ACCOUNTNAME, HOSTNAME, REFERRAL,
 				Platform.OS_MACOSX, LOCALE_US);
 		String userAgent = eclipseEnvironment.getUserAgent();
@@ -42,7 +53,7 @@
 	}
 
 	@Test
-	public void testLinux() throws UnsupportedEncodingException {
+	public void testLinux() {
 		EclipseEnvironment eclipseEnvironment = new EclipseEnvironmentFake(GANALYTICS_ACCOUNTNAME, HOSTNAME, REFERRAL,
 				Platform.OS_LINUX, LOCALE_US);
 		String userAgent = eclipseEnvironment.getUserAgent();
@@ -52,7 +63,7 @@
 	}
 
 	@Test
-	public void testWindows() throws UnsupportedEncodingException {
+	public void testWindows() {
 		EclipseEnvironment eclipseEnvironment = new EclipseEnvironmentFake(GANALYTICS_ACCOUNTNAME, HOSTNAME, REFERRAL,
 				Platform.OS_WIN32, LOCALE_US);
 		String userAgent = eclipseEnvironment.getUserAgent();
@@ -61,6 +72,31 @@
 		assertLanguage("en-US", userAgent);
 	}
 
+	@Test
+	public void testKeyword() {
+		EclipseEnvironment eclipseEnvironment = new EclipseEnvironmentFake(GANALYTICS_ACCOUNTNAME, HOSTNAME, REFERRAL,
+				Platform.OS_WIN32, LOCALE_US) {
+			@Override
+			protected Bundle[] getBundles() {
+				return new Bundle[] {
+						new BundleSymbolicNameFake("org.jboss.tools.seam.ui"),
+						new BundleSymbolicNameFake("org.jboss.tools.seam.core"),
+						new BundleSymbolicNameFake("org.jboss.tools.gwt.ui"),
+						new BundleSymbolicNameFake("org.jboss.tools.gwt.core"),
+						new BundleSymbolicNameFake("org.jboss.tools.smooks.core"),
+						new BundleSymbolicNameFake("org.eclipse.core.runtime"),
+				};
+			}
+		};
+		String keyword = eclipseEnvironment.getKeyword();
+
+		Matcher matcher = Pattern.compile("(([A-Z]+)-){3}").matcher(keyword);
+		assertTrue(matcher.matches());
+		assertTrue(keyword.indexOf(JBossBundleGroups.BundleGroup.GWT.name()) >= 0);
+		assertTrue(keyword.indexOf(JBossBundleGroups.BundleGroup.SEAM.name()) >= 0);
+		assertTrue(keyword.indexOf(JBossBundleGroups.BundleGroup.SMOOKS.name()) >= 0);
+	}
+	
 	private void assertApplicationNameAndVersion(String applicationName, String applicationVersion, String userAgent) {
 		Matcher matcher = Pattern.compile("([a-zA-Z\\.]+)/([0-9\\.]+).+").matcher(userAgent);
 		assertTrue(matcher.matches());
@@ -83,4 +119,146 @@
 		assertEquals(1, matcher.groupCount());
 		assertEquals(language, matcher.group(1));
 	}
+	
+	private class BundleSymbolicNameFake implements Bundle {
+
+		private String symbolicName;
+
+		public BundleSymbolicNameFake(String symbolicName) {
+			this.symbolicName = symbolicName;
+		}
+
+		@Override
+		public Enumeration findEntries(String path, String filePattern, boolean recurse) {
+			throw new UnsupportedOperationException();
+		}
+
+		@Override
+		public BundleContext getBundleContext() {
+			throw new UnsupportedOperationException();
+		}
+
+		@Override
+		public long getBundleId() {
+			throw new UnsupportedOperationException();
+		}
+
+		@Override
+		public URL getEntry(String path) {
+			throw new UnsupportedOperationException();
+		}
+
+		@Override
+		public Enumeration getEntryPaths(String path) {
+			throw new UnsupportedOperationException();
+		}
+
+		@Override
+		public Dictionary getHeaders() {
+			throw new UnsupportedOperationException();
+		}
+
+		@Override
+		public Dictionary getHeaders(String locale) {
+			throw new UnsupportedOperationException();
+		}
+
+		@Override
+		public long getLastModified() {
+			throw new UnsupportedOperationException();
+		}
+
+		@Override
+		public String getLocation() {
+			throw new UnsupportedOperationException();
+		}
+
+		@Override
+		public ServiceReference[] getRegisteredServices() {
+			throw new UnsupportedOperationException();
+		}
+
+		@Override
+		public URL getResource(String name) {
+			throw new UnsupportedOperationException();
+		}
+
+		@Override
+		public Enumeration getResources(String name) throws IOException {
+			throw new UnsupportedOperationException();
+		}
+
+		@Override
+		public ServiceReference[] getServicesInUse() {
+			throw new UnsupportedOperationException();
+		}
+
+		@Override
+		public Map getSignerCertificates(int signersType) {
+			throw new UnsupportedOperationException();
+		}
+
+		@Override
+		public int getState() {
+			throw new UnsupportedOperationException();
+		}
+
+		@Override
+		public String getSymbolicName() {
+			return this.symbolicName;
+		}
+
+		@Override
+		public Version getVersion() {
+			throw new UnsupportedOperationException();
+
+		}
+
+		@Override
+		public boolean hasPermission(Object permission) {
+			throw new UnsupportedOperationException();
+
+		}
+
+		@Override
+		public Class loadClass(String name) throws ClassNotFoundException {
+			throw new UnsupportedOperationException();
+		}
+
+		@Override
+		public void start() throws BundleException {
+			throw new UnsupportedOperationException();
+
+		}
+
+		@Override
+		public void start(int options) throws BundleException {
+			throw new UnsupportedOperationException();
+		}
+
+		@Override
+		public void stop() throws BundleException {
+			throw new UnsupportedOperationException();
+		}
+
+		@Override
+		public void stop(int options) throws BundleException {
+			throw new UnsupportedOperationException();
+		}
+
+		@Override
+		public void uninstall() throws BundleException {
+			throw new UnsupportedOperationException();
+		}
+
+		@Override
+		public void update() throws BundleException {
+			throw new UnsupportedOperationException();
+		}
+
+		@Override
+		public void update(InputStream input) throws BundleException {
+			throw new UnsupportedOperationException();
+		}
+	}
 }



More information about the jbosstools-commits mailing list