Author: adietish
Date: 2010-09-10 12:49:22 -0400 (Fri, 10 Sep 2010)
New Revision: 24875
Modified:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/JBossComponents.java
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/ReportingEclipseEnvironment.java
Log:
[JBIDE-7035] Refactored bundle filter to generic collection filter
Modified:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/JBossComponents.java
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/JBossComponents.java 2010-09-10
16:26:43 UTC (rev 24874)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/JBossComponents.java 2010-09-10
16:49:22 UTC (rev 24875)
@@ -14,13 +14,15 @@
import java.util.Set;
import java.util.TreeSet;
+import org.jboss.tools.usage.util.BundleUtils;
+import org.jboss.tools.usage.util.CollectionFilterUtils;
import org.jboss.tools.usage.util.ICollectionEntryFilter;
import org.osgi.framework.Bundle;
/**
* @author Andre Dietisheim
*/
-public class JBossComponents implements ICollectionEntryFilter<Bundle> {
+public class JBossComponents {
public enum BundleGroup {
ARCHIVES("org.jboss.ide.eclipse.archives.core",
@@ -200,24 +202,52 @@
}
}
- private Set<String> jbossBundleGroups = new TreeSet<String>();
+ private static final String JBOSS_TOOLS_BUNDLES_PREFIX =
"org\\.jboss\\.tools.+"; //$NON-NLS-1$
- /**
- * 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;
+ private static class JBossComponentBundlesFilter implements
ICollectionEntryFilter<Bundle> {
+
+ private Collection<String> componentNames;
+
+ private JBossComponentBundlesFilter(Collection<String> componentNames) {
+ this.componentNames = componentNames;
+ }
+
+ /**
+ * 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)) {
+ componentNames.add(bundleGroup.name());
+ break;
+ }
}
+ return true;
}
- return true;
}
- public Collection<String> getBundleGroupIds() {
- return jbossBundleGroups;
+ private JBossComponents() {
+ // inhibit instantiation
}
+
+ /**
+ * Returns the jboss components that the given bundles are members of
+ *
+ * @param bundles
+ * the bundles to check
+ * @return
+ */
+ public static Collection<String> getComponentIds(Bundle[] bundles) {
+ Set<String> jbossComponentNames = new TreeSet<String>();
+ ICollectionEntryFilter<Bundle> jbossToolsFilter = new
BundleUtils.BundleSymbolicNameFilter(
+ JBOSS_TOOLS_BUNDLES_PREFIX);
+ @SuppressWarnings("unchecked")
+ ICollectionEntryFilter<Bundle> compositeFilter = new
CollectionFilterUtils.CompositeCollectionFilter<Bundle>(
+ jbossToolsFilter
+ , new JBossComponentBundlesFilter(jbossComponentNames));
+ BundleUtils.getBundles(compositeFilter, bundles);
+ return jbossComponentNames;
+ }
}
\ No newline at end of file
Modified:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/ReportingEclipseEnvironment.java
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/ReportingEclipseEnvironment.java 2010-09-10
16:26:43 UTC (rev 24874)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/reporting/ReportingEclipseEnvironment.java 2010-09-10
16:49:22 UTC (rev 24875)
@@ -10,12 +10,11 @@
******************************************************************************/
package org.jboss.tools.usage.reporting;
+import java.util.Collection;
+
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.jboss.tools.usage.googleanalytics.eclipse.AbstractEclipseEnvironment;
import org.jboss.tools.usage.internal.JBossToolsUsageActivator;
-import org.jboss.tools.usage.util.BundleUtils;
-import org.jboss.tools.usage.util.CollectionFilterUtils;
-import org.jboss.tools.usage.util.ICollectionEntryFilter;
import org.osgi.framework.Bundle;
/**
@@ -23,7 +22,6 @@
*/
public class ReportingEclipseEnvironment extends AbstractEclipseEnvironment {
- private static final String JBOSS_TOOLS_BUNDLES_PREFIX =
"org\\.jboss\\.tools.+"; //$NON-NLS-1$
private static final char BUNDLE_GROUP_DELIMITER = '-';
public ReportingEclipseEnvironment(String accountName, String hostName,
IEclipsePreferences preferences) {
@@ -32,25 +30,18 @@
@Override
public String getKeyword() {
- JBossComponents jbossBundleGroups = new JBossComponents();
- ICollectionEntryFilter<Bundle> jbossToolsFilter = new
BundleUtils.BundleSymbolicNameFilter(JBOSS_TOOLS_BUNDLES_PREFIX);
- ICollectionEntryFilter<Bundle> compositeFilter = new
CollectionFilterUtils.CompositeCollectionFilter<Bundle>(
- jbossToolsFilter
- , jbossBundleGroups);
- BundleUtils.getBundles(compositeFilter, getBundles());
-
- return bundleGroupsToKeywordString(jbossBundleGroups);
+ return bundleGroupsToKeywordString(JBossComponents.getComponentIds(getBundles()));
}
protected Bundle[] getBundles() {
return
JBossToolsUsageActivator.getDefault().getBundle().getBundleContext().getBundles();
}
- private String bundleGroupsToKeywordString(JBossComponents jbossBundleGroups) {
+ private String bundleGroupsToKeywordString(Collection<String> jbossComponentNames)
{
char delimiter = BUNDLE_GROUP_DELIMITER;
StringBuilder builder = new StringBuilder();
- for (String bundleGroupId : jbossBundleGroups.getBundleGroupIds()) {
- builder.append(bundleGroupId)
+ for (String componentName : jbossComponentNames) {
+ builder.append(componentName)
.append(delimiter);
}
return builder.toString();
Show replies by date