Search in sources :

Example 1 with IValueVariable

use of org.eclipse.core.variables.IValueVariable in project eclipse.jdt.ui by eclipse-jdt.

the class TomcatLaunchDelegate method getCatalinaHome.

/**
 * Returns the value of the <code>${catalina_home}</code> launch variable.
 *
 * @return the value of the <code>${catalina_home}</code> launch variable
 * @exception CoreException if the variable or value is undefined
 */
public static String getCatalinaHome() throws CoreException {
    // $NON-NLS-1$
    IValueVariable variable = VariablesPlugin.getDefault().getStringVariableManager().getValueVariable("catalina_home");
    IStatus err = null;
    if (variable == null) {
        err = new Status(IStatus.ERROR, JspUIPlugin.getDefault().getBundle().getSymbolicName(), 0, LaunchingMessages.TomcatLaunchDelegate_9, null);
    } else {
        String home = variable.getValue();
        if (home != null && home.length() > 0) {
            File file = new File(home);
            if (file.exists() && file.isDirectory()) {
                return home;
            } else {
                err = new Status(IStatus.ERROR, JspUIPlugin.getDefault().getBundle().getSymbolicName(), 0, MessageFormat.format(LaunchingMessages.TomcatLaunchDelegate_7, home), null);
            }
        } else {
            err = new Status(IStatus.ERROR, JspUIPlugin.getDefault().getBundle().getSymbolicName(), 0, LaunchingMessages.TomcatLaunchDelegate_8, null);
        }
    }
    throw new CoreException(err);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) IValueVariable(org.eclipse.core.variables.IValueVariable) File(java.io.File)

Example 2 with IValueVariable

use of org.eclipse.core.variables.IValueVariable in project Pydev by fabioz.

the class PythonRunnerConfigTestWorkbench method testPythonCommandLine.

public void testPythonCommandLine() throws Exception {
    PythonNature nature = PythonNature.getPythonNature(mod1);
    // Create a temporary variable for testing
    IStringVariableManager variableManager = VariablesPlugin.getDefault().getStringVariableManager();
    IValueVariable myCustomVariable = variableManager.newValueVariable("pydev_python_runner_config_test_var", "", true, "my_custom_value");
    variableManager.addVariables(new IValueVariable[] { myCustomVariable });
    try {
        IInterpreterManager manager = InterpreterManagersAPI.getPythonInterpreterManager(true);
        InterpreterInfo info = (InterpreterInfo) manager.getDefaultInterpreterInfo(false);
        info.setEnvVariables(new String[] { "MY_CUSTOM_VAR_FOR_TEST=FOO", "MY_CUSTOM_VAR_FOR_TEST2=FOO2", "MY_CUSTOM_VAR_WITH_VAR=${pydev_python_runner_config_test_var}" });
        // Make sure variable hasn't been expanded too early
        assertTrue(arrayContains(info.getEnvVariables(), "MY_CUSTOM_VAR_WITH_VAR=${pydev_python_runner_config_test_var}"));
        PythonRunnerConfig runnerConfig = createConfig();
        assertTrue(arrayContains(runnerConfig.envp, "MY_CUSTOM_VAR_FOR_TEST=FOO"));
        assertTrue(arrayContains(runnerConfig.envp, "MY_CUSTOM_VAR_FOR_TEST2=FOO2"));
        assertTrue(arrayContains(runnerConfig.envp, "MY_CUSTOM_VAR_WITH_VAR=my_custom_value"));
        String[] argv = runnerConfig.getCommandLine(false);
        assertFalse(arrayContains(argv, PythonRunnerConfig.getRunFilesScript()));
        assertTrue(arrayContains(argv, mod1.getLocation().toOSString()));
        nature.setVersion(IPythonNature.Versions.PYTHON_VERSION_LATEST, IPythonNature.DEFAULT_INTERPRETER);
        assertEquals(manager.getDefaultInterpreterInfo(false).getExecutableOrJar(), nature.getProjectInterpreter().getExecutableOrJar());
        runnerConfig = createConfig();
        argv = runnerConfig.getCommandLine(false);
        assertEquals(manager.getDefaultInterpreterInfo(false).getExecutableOrJar(), argv[0]);
        IInterpreterManager interpreterManager = nature.getRelatedInterpreterManager();
        InterpreterInfo info2 = new InterpreterInfo(IPythonNature.PYTHON_VERSION_2_6, "c:\\interpreter\\py25.exe", new ArrayList<String>());
        interpreterManager.setInfos(new IInterpreterInfo[] { info, info2 }, null, null);
        nature.setVersion(IPythonNature.Versions.PYTHON_VERSION_LATEST, "c:\\interpreter\\py25.exe");
        assertEquals("c:\\interpreter\\py25.exe", nature.getProjectInterpreter().getExecutableOrJar());
        runnerConfig = createConfig();
        argv = runnerConfig.getCommandLine(false);
        assertEquals("c:\\interpreter\\py25.exe", argv[0]);
        nature.setVersion(IPythonNature.Versions.PYTHON_VERSION_LATEST, IPythonNature.DEFAULT_INTERPRETER);
        ILaunchConfiguration config;
        config = new LaunchShortcut().createDefaultLaunchConfiguration(FileOrResource.createArray(new IResource[] { mod1 }));
        ILaunchConfigurationWorkingCopy workingCopy = config.getWorkingCopy();
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("VAR_SPECIFIED_IN_LAUNCH", "BAR");
        // The one in the launch configuration always has preference.
        map.put("MY_CUSTOM_VAR_FOR_TEST2", "BAR2");
        workingCopy.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, map);
        config = workingCopy.doSave();
        runnerConfig = new PythonRunnerConfig(config, ILaunchManager.RUN_MODE, PythonRunnerConfig.RUN_REGULAR);
        assertTrue(arrayContains(runnerConfig.envp, "VAR_SPECIFIED_IN_LAUNCH=BAR"));
        assertTrue(arrayContains(runnerConfig.envp, "MY_CUSTOM_VAR_FOR_TEST=FOO"));
        assertTrue(arrayContains(runnerConfig.envp, "MY_CUSTOM_VAR_FOR_TEST2=BAR2"));
        assertTrue(arrayContains(runnerConfig.envp, "MY_CUSTOM_VAR_WITH_VAR=my_custom_value"));
    } catch (Throwable e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    } finally {
        // restore the default!
        nature.setVersion(IPythonNature.Versions.PYTHON_VERSION_LATEST, IPythonNature.DEFAULT_INTERPRETER);
        variableManager.removeVariables(new IValueVariable[] { myCustomVariable });
    }
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) IPythonNature(org.python.pydev.core.IPythonNature) PythonNature(org.python.pydev.plugin.nature.PythonNature) HashMap(java.util.HashMap) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) IInterpreterManager(org.python.pydev.core.IInterpreterManager) IStringVariableManager(org.eclipse.core.variables.IStringVariableManager) IValueVariable(org.eclipse.core.variables.IValueVariable) InterpreterInfo(org.python.pydev.ast.interpreter_managers.InterpreterInfo) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo)

Example 3 with IValueVariable

use of org.eclipse.core.variables.IValueVariable in project jbosstools-server by jbosstools.

the class StringSubstitutionTest method testSetVariable.

public void testSetVariable() {
    try {
        IValueVariable[] variables = new IValueVariable[] { new ValueVariable("test_variable", null, false, "/here") };
        VariablesPlugin.getDefault().getStringVariableManager().addVariables(variables);
        WorkspaceVFS vfs = (WorkspaceVFS) ArchivesCore.getInstance().getVFS();
        String out = vfs.performStringSubstitution("${test_variable}", null, true);
        assertEquals("/here", out);
        VariablesPlugin.getDefault().getStringVariableManager().removeVariables(variables);
    } catch (CoreException ce) {
        fail(ce.getMessage());
    }
}
Also used : IValueVariable(org.eclipse.core.variables.IValueVariable) ValueVariable(org.eclipse.core.internal.variables.ValueVariable) CoreException(org.eclipse.core.runtime.CoreException) IValueVariable(org.eclipse.core.variables.IValueVariable) WorkspaceVFS(org.jboss.ide.eclipse.archives.core.model.other.internal.WorkspaceVFS)

Aggregations

IValueVariable (org.eclipse.core.variables.IValueVariable)3 CoreException (org.eclipse.core.runtime.CoreException)2 File (java.io.File)1 HashMap (java.util.HashMap)1 ValueVariable (org.eclipse.core.internal.variables.ValueVariable)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 IStringVariableManager (org.eclipse.core.variables.IStringVariableManager)1 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)1 ILaunchConfigurationWorkingCopy (org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)1 WorkspaceVFS (org.jboss.ide.eclipse.archives.core.model.other.internal.WorkspaceVFS)1 InterpreterInfo (org.python.pydev.ast.interpreter_managers.InterpreterInfo)1 IInterpreterInfo (org.python.pydev.core.IInterpreterInfo)1 IInterpreterManager (org.python.pydev.core.IInterpreterManager)1 IPythonNature (org.python.pydev.core.IPythonNature)1 PythonNature (org.python.pydev.plugin.nature.PythonNature)1