Author: rob.stryker(a)jboss.com
Date: 2008-02-27 18:17:16 -0500 (Wed, 27 Feb 2008)
New Revision: 6613
Added:
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/IVariableManager.java
Modified:
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/ant/AntVariables.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/xpl/StringSubstitutionEngineClone.java
Log:
moving towards variable referencing
Modified:
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/ant/AntVariables.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/ant/AntVariables.java 2008-02-27
21:15:41 UTC (rev 6612)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/ant/AntVariables.java 2008-02-27
23:17:16 UTC (rev 6613)
@@ -9,9 +9,10 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.jboss.ide.eclipse.archives.core.model.IRuntimeVariables;
+import org.jboss.ide.eclipse.archives.core.model.IVariableManager;
import org.jboss.ide.eclipse.archives.core.xpl.StringSubstitutionEngineClone;
-public class AntVariables implements IRuntimeVariables {
+public class AntVariables implements IRuntimeVariables, IVariableManager {
private Task currentTask;
public void setCurrentTask(Task task) { currentTask = task; }
public Task getCurrentTask() { return currentTask; }
@@ -45,7 +46,15 @@
public String performStringSubstitution(String expression,
boolean reportUndefinedVariables) throws CoreException {
- return new StringSubstitutionEngineClone().performStringSubstitution(expression,
reportUndefinedVariables);
+ return new StringSubstitutionEngineClone().performStringSubstitution(expression,
reportUndefinedVariables, this);
}
+ public boolean containsVariable(String variable) {
+ return false;
+ }
+
+ public String getVariableValue(String variable, String arg) {
+ return null;
+ }
+
}
Added:
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/IVariableManager.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/IVariableManager.java
(rev 0)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/IVariableManager.java 2008-02-27
23:17:16 UTC (rev 6613)
@@ -0,0 +1,31 @@
+/**
+ * JBoss, a Division of Red Hat
+ * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+* This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.archives.core.model;
+
+/**
+ * @author rob.stryker <rob.stryker(a)redhat.com>
+ *
+ */
+public interface IVariableManager {
+ public boolean containsVariable(String variable);
+ public String getVariableValue(String variable, String arg);
+}
Modified:
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/xpl/StringSubstitutionEngineClone.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/xpl/StringSubstitutionEngineClone.java 2008-02-27
21:15:41 UTC (rev 6612)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/xpl/StringSubstitutionEngineClone.java 2008-02-27
23:17:16 UTC (rev 6613)
@@ -15,10 +15,13 @@
import java.util.Iterator;
import java.util.List;
import java.util.Stack;
+
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.jboss.ide.eclipse.archives.core.ArchivesCore;
+import org.jboss.ide.eclipse.archives.core.ArchivesCorePlugin;
+import org.jboss.ide.eclipse.archives.core.model.IVariableManager;
/**
* Performs string substitution for context and value variables.
@@ -77,11 +80,11 @@
* @exception CoreException if unable to resolve a referenced variable or if a cycle
exists
* in referenced variables
*/
- public String performStringSubstitution(String expression, boolean
reportUndefinedVariables ) throws CoreException {
- substitute(expression, reportUndefinedVariables );
+ public String performStringSubstitution(String expression, boolean
reportUndefinedVariables, IVariableManager manager ) throws CoreException {
+ substitute(expression, reportUndefinedVariables,manager );
List resolvedVariableSets = new ArrayList();
while (fSubs) {
- HashSet resolved = substitute(fResult.toString(), reportUndefinedVariables );
+ HashSet resolved = substitute(fResult.toString(),
reportUndefinedVariables,manager);
for(int i=resolvedVariableSets.size()-1; i>=0; i--) {
@@ -118,8 +121,8 @@
* @exception CoreException if a referenced variable does not exist or if a cycle
exists
* in referenced variables
*/
- public void validateStringVariables(String expression ) throws CoreException {
- performStringSubstitution(expression, true );
+ public void validateStringVariables(String expression, IVariableManager manager ) throws
CoreException {
+ performStringSubstitution(expression, true, manager );
}
/**
@@ -130,7 +133,7 @@
* @param reportUndefinedVariables whether to report undefined variables as an error
* @exception CoreException if unable to resolve a variable
*/
- private HashSet substitute(String expression, boolean reportUndefinedVariables) throws
CoreException {
+ private HashSet substitute(String expression, boolean reportUndefinedVariables,
IVariableManager manager) throws CoreException {
fResult = new StringBuffer(expression.length());
fStack = new Stack();
fSubs = false;
@@ -186,7 +189,7 @@
resolvedVariables.add(substring);
pos = end + 1;
- String value= resolve(tos, reportUndefinedVariables);
+ String value= resolve(tos, reportUndefinedVariables, manager);
if (value == null) {
value = ""; //$NON-NLS-1$
}
@@ -228,54 +231,34 @@
* @param var
* @param reportUndefinedVariables whether to report undefined variables as
* an error
+ * @param manager Someone to call back to for the variable's values
* @return variable value, possibly <code>null</code>
* @exception CoreException if unable to resolve a value
*/
- private String resolve(VariableReference var, boolean reportUndefinedVariables) throws
CoreException {
-// String text = var.getText();
-// int pos = text.indexOf(VARIABLE_ARG);
-// String name = null;
-// String arg = null;
-// if (pos > 0) {
-// name = text.substring(0, pos);
-// pos++;
-// if (pos < text.length()) {
-// arg = text.substring(pos);
-// }
-// } else {
-// name = text;
-// }
-// IValueVariable valueVariable = manager.getValueVariable(name);
-// if (valueVariable == null) {
-// IDynamicVariable dynamicVariable = manager.getDynamicVariable(name);
-// if (dynamicVariable == null) {
-// // no variables with the given name
-// if (reportUndefinedVariables) {
-// throw new CoreException(new Status(IStatus.ERROR,
VariablesPlugin.getUniqueIdentifier(), VariablesPlugin.INTERNAL_ERROR,
NLS.bind(VariablesMessages.StringSubstitutionEngine_3, new String[]{name}), null));
-// }
-// // leave as is
-// return getOriginalVarText(var);
-// }
-//
-// if (resolveVariables) {
-// fSubs = true;
-// return dynamicVariable.getValue(arg);
-// }
-// //leave as is
-// return getOriginalVarText(var);
-// }
-//
-// if (arg == null) {
-// if (resolveVariables) {
-// fSubs = true;
-// return valueVariable.getValue();
-// }
-// //leave as is
-// return getOriginalVarText(var);
-// }
-// // error - an argument specified for a value variable
-// throw new CoreException(new Status(IStatus.ERROR,
VariablesPlugin.getUniqueIdentifier(), VariablesPlugin.INTERNAL_ERROR,
NLS.bind(VariablesMessages.StringSubstitutionEngine_4, new
String[]{valueVariable.getName()}), null));
- return "tobecompleted";
+ private String resolve(VariableReference var, boolean reportUndefinedVariables,
IVariableManager manager) throws CoreException {
+ String text = var.getText();
+ int pos = text.indexOf(VARIABLE_ARG);
+ String name = null;
+ String arg = null;
+ if (pos > 0) {
+ name = text.substring(0, pos);
+ pos++;
+ if (pos < text.length()) {
+ arg = text.substring(pos);
+ }
+ } else {
+ name = text;
+ }
+ if( !manager.containsVariable(name)) {
+ if( reportUndefinedVariables )
+ throw new CoreException(new Status(IStatus.ERROR, ArchivesCorePlugin.PLUGIN_ID,
"Variable " + name + " undefined"));
+ return getOriginalVarText(var);
+ }
+
+ String ret = manager.getVariableValue(name, arg);
+ if(ret == null)
+ return getOriginalVarText(var);
+ return ret;
}
private String getOriginalVarText(VariableReference var) {