Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Schwarz2012-10-22 06:34:01 -0400
committerTobias Schwarz2012-10-22 06:34:38 -0400
commit3f6109bedbf34e43ec86e2c6202db8ec7fc697ae (patch)
treee4b2d694eb894171f46d03db105b6162d09f053a /target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime
parent12af7faaa3b155d79fded5aa33eab7c25f005946 (diff)
downloadorg.eclipse.tcf-3f6109bedbf34e43ec86e2c6202db8ec7fc697ae.tar.gz
org.eclipse.tcf-3f6109bedbf34e43ec86e2c6202db8ec7fc697ae.tar.xz
org.eclipse.tcf-3f6109bedbf34e43ec86e2c6202db8ec7fc697ae.zip
[Target Explorer] variable delegates and provider für persistence
delegates
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractPathVariableDelegate.java41
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractVariableDelegate.java126
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/GsonMapPersistenceDelegate.java8
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/PersistenceManager.java11
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IVariableDelegate.java15
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IVariableProvider.java25
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/VariableProvider.java48
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/VariableProviderExtensionPointManager.java79
8 files changed, 347 insertions, 6 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractPathVariableDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractPathVariableDelegate.java
new file mode 100644
index 000000000..09da17128
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractPathVariableDelegate.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Wind River Systems, Inc. and others. All rights reserved.
+ * This program and the accompanying materials are 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:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tcf.te.runtime.persistence;
+
+import org.eclipse.core.runtime.Path;
+import org.eclipse.tcf.te.runtime.utils.Host;
+
+/**
+ * AbstractPathVariableDelegate
+ */
+public abstract class AbstractPathVariableDelegate extends AbstractVariableDelegate {
+
+ /**
+ * Return true, if the key represents a path value.
+ * @param key The key to check.
+ * @return <code>true</code> if the key represents a path value.
+ */
+ protected abstract boolean isPathKey(String key);
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.AbstractVariableDelegate#useVariable(java.lang.String, java.lang.Object, java.lang.String, java.lang.String)
+ */
+ @Override
+ protected Object useVariable(String key, Object value, String variableName, String variableValue) {
+ if (isPathKey(key) && value instanceof String) {
+ String valuePath = new Path(Host.isWindowsHost() ? ((String)value).toLowerCase() : (String)value).toString();
+ String variablePath = new Path(Host.isWindowsHost() ? variableValue.toLowerCase() : (String)variableValue).toString();
+ return super.useVariable(key, valuePath, variableName, variablePath);
+ }
+
+ return super.useVariable(key, value, variableName, variableValue);
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractVariableDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractVariableDelegate.java
new file mode 100644
index 000000000..b709d41d8
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/AbstractVariableDelegate.java
@@ -0,0 +1,126 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Wind River Systems, Inc. and others. All rights reserved.
+ * This program and the accompanying materials are 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:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tcf.te.runtime.persistence;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IVariableDelegate;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IVariableProvider;
+
+/**
+ * AbstractVariableDelegate
+ */
+public abstract class AbstractVariableDelegate implements IVariableDelegate {
+
+ /**
+ * Get the list of keys this delegate is handling.
+ * @return The list of handled keys.
+ */
+ protected abstract String[] getKeysToHandle();
+
+ /**
+ * Try to use a variable inside the given value.
+ * @param key The key of the value.
+ * @param value The value to inspect.
+ * @param variableName The variable name to use.
+ * @param variableValue The variable value.
+ * @return The new value if the variable was used, <code>null</code> otherwise.
+ */
+ protected Object useVariable(String key, Object value, String variableName, String variableValue) {
+ if (value instanceof String && ((String)value).contains(variableValue)) {
+ return ((String)value).replaceAll(variableValue, "<"+variableName+">"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return null;
+ }
+
+ /**
+ * Try to restore a variable inside the given value.
+ * @param key The key of the value.
+ * @param value The value to inspect.
+ * @param variableName The variable name to restore.
+ * @param variableValue The variable value.
+ * @return The new value if the variable was used, <code>null</code> otherwise.
+ */
+ protected Object restoreValue(String key, Object value, String variableName, String variableValue) {
+ if (value instanceof String && ((String)value).contains("<"+variableName+">")) { //$NON-NLS-1$ //$NON-NLS-2$
+ return ((String)value).replaceAll("<"+variableName+">", variableValue); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IVariableDelegate#getVariables(java.util.Map)
+ */
+ @Override
+ public Map<String,String> getVariables(Map<String, Object> map) {
+ Map<String,String> usedVariables = new HashMap<String, String>();
+
+ for (String key : getKeysToHandle()) {
+ if (map.get(key) != null) {
+ for (Entry<String,String> variable : getVariablesMap(null).entrySet()) {
+ Object newValue = useVariable(key, map.get(key), variable.getKey(), variable.getValue());
+ if (newValue != null) {
+ map.put(key, newValue);
+ usedVariables.put(variable.getKey(), variable.getValue());
+ }
+ }
+ }
+ }
+
+ return usedVariables;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IVariableDelegate#putVariables(java.util.Map, java.util.Map)
+ */
+ @Override
+ public Map<String,Object> putVariables(Map<String,Object> map, Map<String,String> defaultVariables) {
+ for (String key : getKeysToHandle()) {
+ if (map.get(key) != null) {
+ for (Entry<String,String> variable : getVariablesMap(defaultVariables).entrySet()) {
+ Object newValue = restoreValue(key, map.get(key), variable.getKey(), variable.getValue());
+ if (newValue != null) {
+ map.put(key, newValue);
+ }
+ }
+ }
+ }
+
+ return map;
+ }
+
+ /**
+ * Calculate and return the map of variables to use.
+ * If a map of default variables is given, all variables will be added to the result
+ * map if the name does not exist in the list of provided {@link IVariableProvider} variables.
+ * @param defaultVariables Default variables or <code>null</code>.
+ * @return Map of variables to use.
+ */
+ protected Map<String,String> getVariablesMap(Map<String,String> defaultVariables) {
+ Map<String,String> variables = new HashMap<String, String>();
+ for (IVariableProvider provider : PersistenceManager.getInstance().getVariableProviders()) {
+ variables.putAll(provider.getVariables());
+ }
+
+ if (defaultVariables != null) {
+ for (Entry<String,String> defaultVariable : defaultVariables.entrySet()) {
+ if (!variables.containsKey(defaultVariable.getKey())) {
+ variables.put(defaultVariable.getKey(), defaultVariable.getValue());
+ }
+ }
+ }
+
+ return variables;
+ }
+
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/GsonMapPersistenceDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/GsonMapPersistenceDelegate.java
index 71b4e4409..06c37d5b0 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/GsonMapPersistenceDelegate.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/GsonMapPersistenceDelegate.java
@@ -134,12 +134,12 @@ public class GsonMapPersistenceDelegate extends ExecutableExtension implements I
Map<String,Object> data = toMap(context);
if (data != null) {
- Map<String,String> variables = new HashMap<String, String>();
+ Map<String,String> variables = null;
IVariableDelegate[] delegates = PersistenceManager.getInstance().getVariableDelegates(this);
for (IVariableDelegate delegate : delegates) {
- delegate.getVariables(data, variables);
+ variables = delegate.getVariables(data);
}
- if (!variables.isEmpty()) {
+ if (variables != null && !variables.isEmpty()) {
data.put(VARIABLES, variables);
}
}
@@ -196,7 +196,7 @@ public class GsonMapPersistenceDelegate extends ExecutableExtension implements I
Map<String,String> variables = (Map<String,String>)data.remove(VARIABLES);
IVariableDelegate[] delegates = PersistenceManager.getInstance().getVariableDelegates(this);
for (IVariableDelegate delegate : delegates) {
- delegate.putVariables(data, variables);
+ data = delegate.putVariables(data, variables);
}
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/PersistenceManager.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/PersistenceManager.java
index 795c9b564..b89b29d3f 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/PersistenceManager.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/PersistenceManager.java
@@ -22,9 +22,11 @@ import org.eclipse.tcf.te.runtime.extensions.ExecutableExtensionProxy;
import org.eclipse.tcf.te.runtime.persistence.activator.CoreBundleActivator;
import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate;
import org.eclipse.tcf.te.runtime.persistence.interfaces.IVariableDelegate;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IVariableProvider;
import org.eclipse.tcf.te.runtime.persistence.internal.PersistenceDelegateBinding;
import org.eclipse.tcf.te.runtime.persistence.internal.PersistenceDelegateBindingExtensionPointManager;
import org.eclipse.tcf.te.runtime.persistence.internal.VariableDelegateExtensionPointManager;
+import org.eclipse.tcf.te.runtime.persistence.internal.VariableProviderExtensionPointManager;
/**
* Persistence delegate manager implementation.
@@ -155,4 +157,13 @@ public class PersistenceManager extends AbstractExtensionPointManager<IPersisten
public IVariableDelegate[] getVariableDelegates(IPersistenceDelegate persistenceDelegate) {
return VariableDelegateExtensionPointManager.getInstance().getDelegates(persistenceDelegate);
}
+
+ /**
+ * Returns all variable providers.
+ *
+ * @return The list of variable providers or an empty array.
+ */
+ public IVariableProvider[] getVariableProviders() {
+ return VariableProviderExtensionPointManager.getInstance().getProviders();
+ }
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IVariableDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IVariableDelegate.java
index 5a95009c9..7817f54be 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IVariableDelegate.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IVariableDelegate.java
@@ -17,7 +17,18 @@ import java.util.Map;
*/
public interface IVariableDelegate {
- public void getVariables(Map<String,Object> map, Map<String,String> variables);
+ /**
+ * Extract variables from map and use them inside map values.
+ * @param map The map to inspect.
+ * @return The used variables.
+ */
+ public Map<String,String> getVariables(Map<String, Object> map);
- public void putVariables(Map<String,Object> map, Map<String,String> variables);
+ /**
+ * Replace all variables inside map values by current variable value or given default.
+ * @param map The map with variables to inspect.
+ * @param defaultVariables The default variables.
+ * @return The map without variables.
+ */
+ public Map<String,Object> putVariables(Map<String,Object> map, Map<String,String> defaultVariables);
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IVariableProvider.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IVariableProvider.java
new file mode 100644
index 000000000..a13ca029b
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/interfaces/IVariableProvider.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Wind River Systems, Inc. and others. All rights reserved.
+ * This program and the accompanying materials are 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:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tcf.te.runtime.persistence.interfaces;
+
+import java.util.Map;
+
+/**
+ * IVariableProvider
+ */
+public interface IVariableProvider {
+
+ /**
+ * Get the list of provided variables.
+ * @return The provided variables.
+ */
+ public Map<String,String> getVariables();
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/VariableProvider.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/VariableProvider.java
new file mode 100644
index 000000000..bbf3b0861
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/VariableProvider.java
@@ -0,0 +1,48 @@
+/**
+ * VariableProvider.java
+ * Created on 22.10.2012
+ *
+ * Copyright (c) 2012 Wind River Systems, Inc.
+ *
+ * The right to copy, distribute, modify, or otherwise make use
+ * of this software may be licensed only pursuant to the terms
+ * of an applicable Wind River license agreement.
+ */
+package org.eclipse.tcf.te.runtime.persistence.internal;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.variables.IDynamicVariable;
+import org.eclipse.core.variables.VariablesPlugin;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IVariableProvider;
+
+/**
+ *
+ */
+public class VariableProvider implements IVariableProvider {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IVariableProvider#getVariables()
+ */
+ @Override
+ public Map<String, String> getVariables() {
+ Map<String,String> variables = new HashMap<String, String>();
+
+ try {
+ IDynamicVariable variable = VariablesPlugin.getDefault().getStringVariableManager().getDynamicVariable("workspace_loc"); //$NON-NLS-1$
+ if (variable != null) {
+ String value = variable.getValue(null);
+ if (value != null) {
+ variables.put("WORKSPACE_LOC", new Path(value).toString()); //$NON-NLS-1$
+ }
+ }
+ }
+ catch (Exception e) {
+ }
+
+ return variables;
+ }
+
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/VariableProviderExtensionPointManager.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/VariableProviderExtensionPointManager.java
new file mode 100644
index 000000000..452b3193d
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/VariableProviderExtensionPointManager.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Wind River Systems, Inc. and others. All rights reserved.
+ * This program and the accompanying materials are 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:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.runtime.persistence.internal;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager;
+import org.eclipse.tcf.te.runtime.extensions.ExecutableExtensionProxy;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IVariableProvider;
+
+
+/**
+ * VariableProviderExtensionPointManager
+ */
+public class VariableProviderExtensionPointManager extends AbstractExtensionPointManager<IVariableProvider> {
+
+ /*
+ * Thread save singleton instance creation.
+ */
+ private static class LazyInstance {
+ public static VariableProviderExtensionPointManager instance = new VariableProviderExtensionPointManager();
+ }
+
+ /**
+ * Constructor.
+ */
+ VariableProviderExtensionPointManager() {
+ super();
+ }
+
+ /**
+ * Returns the singleton instance of the extension point manager.
+ */
+ public static VariableProviderExtensionPointManager getInstance() {
+ return LazyInstance.instance;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager#getExtensionPointId()
+ */
+ @Override
+ protected String getExtensionPointId() {
+ return "org.eclipse.tcf.te.runtime.persistence.variableProviders"; //$NON-NLS-1$
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager#getConfigurationElementName()
+ */
+ @Override
+ protected String getConfigurationElementName() {
+ return "provider"; //$NON-NLS-1$
+ }
+
+ /**
+ * Returns all variable providers.
+ *
+ * @return The list of variable providers or an empty array.
+ */
+ public IVariableProvider[] getProviders() {
+ List<IVariableProvider> contributions = new ArrayList<IVariableProvider>();
+ Collection<ExecutableExtensionProxy<IVariableProvider>> delegates = getExtensions().values();
+ for (ExecutableExtensionProxy<IVariableProvider> delegate : delegates) {
+ IVariableProvider instance = delegate.getInstance();
+ if (instance != null && !contributions.contains(instance)) {
+ contributions.add(instance);
+ }
+ }
+ return contributions.toArray(new IVariableProvider[contributions.size()]);
+ }
+}

Back to the top