Author: jjohnstn
Date: 2010-10-08 19:00:27 -0400 (Fri, 08 Oct 2010)
New Revision: 25659
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AllInstanceFilter.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/IInstanceFilter.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/InstanceFilter.java
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AllFieldMatcher.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloud.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudManager.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/FieldMatcher.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/IImageFilter.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/ImageFilter.java
Log:
2010-10-08 Jeff Johnston <jjohnstn(a)redhat.com>
* src/org/jboss/tools/deltacloud/core/AllInstanceFilter.java: New file.
* src/org/jboss/tools/deltacloud/core/IInstanceFilter.java: New file.
* src/org/jboss/tools/deltacloud/core/InstanceFilter.java: New file.
* src/org/jboss/tools/deltacloud/core/AllFieldMatcher.java (toString): Switch back
to non-regex, just a wildcard.
* src/org/jboss/tools/deltacloud/core/DeltaCloud.java (DeltaCloud): Add instance
filter rules to constructor.
(getInstanceFilter): New method.
(createInstanceFilter): Ditto.
* src/org/jboss/tools/deltacloud/core/DeltaCloudManager.java (loadClouds): Add instance
filter support.
(saveClouds): Ditto.
* src/org/jboss/tools/deltacloud/core/FieldMatcher.java (FieldMatcher): Use the input
string to form a regex where all non-alphanumeric characters are escaped and wildcards
are expanded to a reluctant any character matcher.
(transform): New method to transform the input rule into a regex.
* src/org/jboss/tools/deltacloud/core/IImageFilter.java: Fix ALL_STRING.
* src/org/jboss/tools/deltacloud/core/ImageFilter.java (setRules): Fix checking for
AllFieldMatchers.
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog 2010-10-08 22:39:22
UTC (rev 25658)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog 2010-10-08 23:00:27
UTC (rev 25659)
@@ -1,3 +1,25 @@
+2010-10-08 Jeff Johnston <jjohnstn(a)redhat.com>
+
+ * src/org/jboss/tools/deltacloud/core/AllInstanceFilter.java: New file.
+ * src/org/jboss/tools/deltacloud/core/IInstanceFilter.java: New file.
+ * src/org/jboss/tools/deltacloud/core/InstanceFilter.java: New file.
+ * src/org/jboss/tools/deltacloud/core/AllFieldMatcher.java (toString): Switch back
+ to non-regex, just a wildcard.
+ * src/org/jboss/tools/deltacloud/core/DeltaCloud.java (DeltaCloud): Add instance
+ filter rules to constructor.
+ (getInstanceFilter): New method.
+ (createInstanceFilter): Ditto.
+ * src/org/jboss/tools/deltacloud/core/DeltaCloudManager.java (loadClouds): Add instance
+ filter support.
+ (saveClouds): Ditto.
+ * src/org/jboss/tools/deltacloud/core/FieldMatcher.java (FieldMatcher): Use the input
+ string to form a regex where all non-alphanumeric characters are escaped and wildcards
+ are expanded to a reluctant any character matcher.
+ (transform): New method to transform the input rule into a regex.
+ * src/org/jboss/tools/deltacloud/core/IImageFilter.java: Fix ALL_STRING.
+ * src/org/jboss/tools/deltacloud/core/ImageFilter.java (setRules): Fix checking for
+ AllFieldMatchers.
+
2010-10-07 Jeff Johnston <jjohnstn(a)redhat.com>
[JBIDE-7181]
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AllFieldMatcher.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AllFieldMatcher.java 2010-10-08
22:39:22 UTC (rev 25658)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AllFieldMatcher.java 2010-10-08
23:00:27 UTC (rev 25659)
@@ -9,7 +9,7 @@
@Override
public String toString() {
- return ".*"; //$NON-NLS-1$
+ return "*"; //$NON-NLS-1$
}
}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AllInstanceFilter.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AllInstanceFilter.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AllInstanceFilter.java 2010-10-08
23:00:27 UTC (rev 25659)
@@ -0,0 +1,57 @@
+package org.jboss.tools.deltacloud.core;
+
+public class AllInstanceFilter implements IInstanceFilter {
+
+ private IFieldMatcher matcher = new AllFieldMatcher();
+
+ @Override
+ public boolean isVisible(DeltaCloudInstance instance) {
+ return true;
+ }
+
+ @Override
+ public void setRules(String ruleString) {
+ // ignore, never set the rules for this filter
+ }
+
+ @Override
+ public String toString() {
+ return ALL_STRING;
+ }
+
+ @Override
+ public IFieldMatcher getNameRule() {
+ return matcher; //$NON-NLS-1$
+ }
+
+ @Override
+ public IFieldMatcher getIdRule() {
+ return matcher; //$NON-NLS-1$
+ }
+
+ @Override
+ public IFieldMatcher getImageIdRule() {
+ return matcher;
+ }
+
+ @Override
+ public IFieldMatcher getKeyNameRule() {
+ return matcher;
+ }
+
+ @Override
+ public IFieldMatcher getOwnerIdRule() {
+ return matcher;
+ }
+
+ @Override
+ public IFieldMatcher getProfileRule() {
+ return matcher;
+ }
+
+ @Override
+ public IFieldMatcher getRealmRule() {
+ return matcher;
+ }
+
+}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloud.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloud.java 2010-10-08
22:39:22 UTC (rev 25658)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloud.java 2010-10-08
23:00:27 UTC (rev 25659)
@@ -43,6 +43,7 @@
private ArrayList<DeltaCloudInstance> instances;
private ArrayList<DeltaCloudImage> images;
private IImageFilter imageFilter;
+ private IInstanceFilter instanceFilter;
private Map<String, Job> actionJobs;
private Object imageLock = new Object();
private Object instanceLock = new Object();
@@ -52,16 +53,17 @@
ListenerList imageListeners = new ListenerList();
public DeltaCloud(String name, String url, String username, String passwd) throws
MalformedURLException {
- this(name, url, username, passwd, null, false, IImageFilter.ALL_STRING);
+ this(name, url, username, passwd, null, false, IImageFilter.ALL_STRING,
IInstanceFilter.ALL_STRING);
}
public DeltaCloud(String name, String url, String username, String passwd,
String type, boolean persistent) throws MalformedURLException {
- this(name, url, username, passwd, null, persistent, IImageFilter.ALL_STRING);
+ this(name, url, username, passwd, null, persistent, IImageFilter.ALL_STRING,
IInstanceFilter.ALL_STRING);
}
public DeltaCloud(String name, String url, String username, String passwd,
- String type, boolean persistent, String imageFilterRules) throws MalformedURLException
{
+ String type, boolean persistent,
+ String imageFilterRules, String instanceFilterRules) throws MalformedURLException {
this.client = new DeltaCloudClient(new URL(url + "/api"), username, passwd);
//$NON-NLS-1$
this.url = url;
this.name = name;
@@ -73,6 +75,12 @@
} catch (PatternSyntaxException e) {
imageFilter.setRules(IImageFilter.ALL_STRING);
}
+ instanceFilter = new InstanceFilter();
+ try {
+ instanceFilter.setRules(instanceFilterRules);
+ } catch (PatternSyntaxException e) {
+ instanceFilter.setRules(IInstanceFilter.ALL_STRING);
+ }
if (persistent) {
ISecurePreferences root = SecurePreferencesFactory.getDefault();
String key = DeltaCloud.getPreferencesKey(url, username);
@@ -123,6 +131,24 @@
return type;
}
+ public IInstanceFilter getInstanceFilter() {
+ return instanceFilter;
+ }
+
+ public void createInstanceFilter(String ruleString) {
+ String rules = getInstanceFilter().toString();
+ if (IInstanceFilter.ALL_STRING.equals(ruleString))
+ instanceFilter = new AllInstanceFilter();
+ else {
+ instanceFilter = new InstanceFilter();
+ instanceFilter.setRules(ruleString);
+ }
+ if (!rules.equals(ruleString)) {
+ save();
+ notifyInstanceListListeners(getCurrInstances());
+ }
+ }
+
public IImageFilter getImageFilter() {
return imageFilter;
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudManager.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudManager.java 2010-10-08
22:39:22 UTC (rev 25658)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudManager.java 2010-10-08
23:00:27 UTC (rev 25659)
@@ -63,6 +63,7 @@
Node usernameNode = attrs.getNamedItem("username"); // $NON-NLS-1$
Node typeNode = attrs.getNamedItem("type"); // $NON-NLS-1$
Node imageFilterNode = attrs.getNamedItem("imagefilter"); //$NON-NLS-1$
+ Node instanceFilterNode = attrs.getNamedItem("instancefilter");
//$NON-NLS-1$
String name = nameNode.getNodeValue();
String url = urlNode.getNodeValue();
String username = usernameNode.getNodeValue();
@@ -73,13 +74,18 @@
imageFilterRules = imageFilterNode.getNodeValue();
else
imageFilterRules = IImageFilter.ALL_STRING;
+ String instanceFilterRules = null;
+ if (instanceFilterNode != null)
+ instanceFilterRules = instanceFilterNode.getNodeValue();
+ else
+ instanceFilterRules = IInstanceFilter.ALL_STRING;
ISecurePreferences root = SecurePreferencesFactory.getDefault();
ISecurePreferences node = root.node(key);
String password;
try {
password = node.get("password", null); //$NON-NLS-1$
DeltaCloud cloud = new DeltaCloud(name, url, username, password, type,
- false, imageFilterRules);
+ false, imageFilterRules, instanceFilterRules);
cloud.loadChildren();
clouds.add(cloud);
} catch (Exception e1) {
@@ -112,7 +118,8 @@
+ d.getURL() +
"\" username=\"" + d.getUsername() +
"\" type=\"" + d.getType() +
- "\" imagefilter=\"" + d.getImageFilter() +
"\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
+ "\" imagefilter=\"" + d.getImageFilter() +
+ "\" instancefilter=\"" + d.getInstanceFilter() +
"\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
}
p.println("</clouds>"); //$NON-NLS-1$
p.close();
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/FieldMatcher.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/FieldMatcher.java 2010-10-08
22:39:22 UTC (rev 25658)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/FieldMatcher.java 2010-10-08
23:00:27 UTC (rev 25659)
@@ -11,8 +11,25 @@
public FieldMatcher(String rule) throws PatternSyntaxException {
this.rule = rule;
- pattern = Pattern.compile(rule);
+ String regexRule = transform(rule);
+ pattern = Pattern.compile(regexRule);
}
+
+ private String transform(String rule) {
+ StringBuffer buffer = new StringBuffer();
+ for (int i = 0; i < rule.length(); ++i) {
+ char ch = rule.charAt(i);
+ if (Character.isLetterOrDigit(ch))
+ buffer.append(ch);
+ else if (ch == '*') {
+ buffer.append(".*?");
+ } else {
+ buffer.append('\\');
+ buffer.append(ch);
+ }
+ }
+ return buffer.toString();
+ }
@Override
public boolean matches(String input) {
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/IImageFilter.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/IImageFilter.java 2010-10-08
22:39:22 UTC (rev 25658)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/IImageFilter.java 2010-10-08
23:00:27 UTC (rev 25659)
@@ -2,7 +2,7 @@
public interface IImageFilter {
- public final static String ALL_STRING = ".*;.*;.*;.*"; //$NON-NLS-1$
+ public final static String ALL_STRING = "*;*;*;*"; //$NON-NLS-1$
public boolean isVisible(DeltaCloudImage image);
public void setRules(String ruleString);
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/IInstanceFilter.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/IInstanceFilter.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/IInstanceFilter.java 2010-10-08
23:00:27 UTC (rev 25659)
@@ -0,0 +1,16 @@
+package org.jboss.tools.deltacloud.core;
+
+public interface IInstanceFilter {
+
+ public final static String ALL_STRING = "*;*;*;*;*;*;*"; //$NON-NLS-1$
+
+ public boolean isVisible(DeltaCloudInstance instance);
+ public void setRules(String ruleString);
+ public IFieldMatcher getNameRule();
+ public IFieldMatcher getIdRule();
+ public IFieldMatcher getImageIdRule();
+ public IFieldMatcher getOwnerIdRule();
+ public IFieldMatcher getKeyNameRule();
+ public IFieldMatcher getRealmRule();
+ public IFieldMatcher getProfileRule();
+}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/ImageFilter.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/ImageFilter.java 2010-10-08
22:39:22 UTC (rev 25658)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/ImageFilter.java 2010-10-08
23:00:27 UTC (rev 25659)
@@ -20,22 +20,22 @@
@Override
public void setRules(String ruleString) throws PatternSyntaxException {
String[] tokens = ruleString.split(";");
- if (tokens[0].equals(".*")) { //$NON-NLS-1$
+ if (tokens[0].equals("*")) { //$NON-NLS-1$
nameRule = new AllFieldMatcher();
} else {
nameRule = new FieldMatcher(tokens[0]);
}
- if (tokens[1].equals(".*")) { //$NON-NLS-1$
+ if (tokens[1].equals("*")) { //$NON-NLS-1$
idRule = new AllFieldMatcher();
} else {
idRule = new FieldMatcher(tokens[1]);
}
- if (tokens[2].equals(".*")) { //$NON-NLS-1$
+ if (tokens[2].equals("*")) { //$NON-NLS-1$
archRule = new AllFieldMatcher();
} else {
archRule = new FieldMatcher(tokens[2]);
}
- if (tokens[3].equals(".*")) { //$NON-NLS-1$
+ if (tokens[3].equals("*")) { //$NON-NLS-1$
descRule = new AllFieldMatcher();
} else {
descRule = new FieldMatcher(tokens[3]);
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/InstanceFilter.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/InstanceFilter.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/InstanceFilter.java 2010-10-08
23:00:27 UTC (rev 25659)
@@ -0,0 +1,112 @@
+package org.jboss.tools.deltacloud.core;
+
+import java.util.regex.PatternSyntaxException;
+
+public class InstanceFilter implements IInstanceFilter {
+
+ private IFieldMatcher nameRule;
+ private IFieldMatcher idRule;
+ private IFieldMatcher imageIdRule;
+ private IFieldMatcher realmRule;
+ private IFieldMatcher profileRule;
+ private IFieldMatcher ownerIdRule;
+ private IFieldMatcher keyNameRule;
+
+ @Override
+ public boolean isVisible(DeltaCloudInstance instance) {
+ return nameRule.matches(instance.getName()) &&
+ idRule.matches(instance.getId()) &&
+ imageIdRule.matches(instance.getImageId()) &&
+ ownerIdRule.matches(instance.getOwnerId()) &&
+ keyNameRule.matches(instance.getKey()) &&
+ realmRule.matches(instance.getRealmId()) &&
+ profileRule.matches(instance.getProfileId());
+ }
+
+ @Override
+ public void setRules(String ruleString) throws PatternSyntaxException {
+ String[] tokens = ruleString.split(";");
+ if (tokens[0].equals("*")) { //$NON-NLS-1$
+ nameRule = new AllFieldMatcher();
+ } else {
+ nameRule = new FieldMatcher(tokens[0]);
+ }
+ if (tokens[1].equals("*")) { //$NON-NLS-1$
+ idRule = new AllFieldMatcher();
+ } else {
+ idRule = new FieldMatcher(tokens[1]);
+ }
+ if (tokens[2].equals("*")) { //$NON-NLS-1$
+ imageIdRule = new AllFieldMatcher();
+ } else {
+ imageIdRule = new FieldMatcher(tokens[2]);
+ }
+ if (tokens[3].equals("*")) { //$NON-NLS-1$
+ ownerIdRule = new AllFieldMatcher();
+ } else {
+ ownerIdRule = new FieldMatcher(tokens[3]);
+ }
+ if (tokens[4].equals("*")) { //$NON-NLS-1$
+ keyNameRule = new AllFieldMatcher();
+ } else {
+ keyNameRule = new FieldMatcher(tokens[4]);
+ }
+ if (tokens[5].equals("*")) { //$NON-NLS-1$
+ realmRule = new AllFieldMatcher();
+ } else {
+ realmRule = new FieldMatcher(tokens[5]);
+ }
+ if (tokens[6].equals("*")) { //$NON-NLS-1$
+ profileRule = new AllFieldMatcher();
+ } else {
+ profileRule = new FieldMatcher(tokens[6]);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return nameRule + ";" //$NON-NLS-1$
+ + idRule + ";" //$NON-NLS-1$
+ + imageIdRule + ";" //$NON-NLS-1$
+ + ownerIdRule + ";" //$NON-NLS-1$
+ + keyNameRule + ";" //$NON-NLS-1$
+ + realmRule + ";" //$NON-NLS-1$
+ + profileRule; //$NON-NLS-1$
+ }
+
+ @Override
+ public IFieldMatcher getNameRule() {
+ return nameRule;
+ }
+
+ @Override
+ public IFieldMatcher getIdRule() {
+ return idRule;
+ }
+
+
+ @Override
+ public IFieldMatcher getImageIdRule() {
+ return imageIdRule;
+ }
+
+ @Override
+ public IFieldMatcher getKeyNameRule() {
+ return keyNameRule;
+ }
+
+ @Override
+ public IFieldMatcher getOwnerIdRule() {
+ return ownerIdRule;
+ }
+
+ @Override
+ public IFieldMatcher getProfileRule() {
+ return profileRule;
+ }
+
+ @Override
+ public IFieldMatcher getRealmRule() {
+ return realmRule;
+ }
+}