Skip to content

Commit

Permalink
Fix for #1299: re-apply project classpath to saved script launch config
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Dec 5, 2021
1 parent e17d6ea commit e9cfaf8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2020 the original author or authors.
* Copyright 2009-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,6 +24,7 @@ import org.eclipse.core.resources.IFile
import org.eclipse.core.resources.IncrementalProjectBuilder
import org.eclipse.core.resources.ResourcesPlugin
import org.eclipse.core.runtime.Adapters
import org.eclipse.debug.core.DebugPlugin
import org.eclipse.debug.internal.ui.DebugUIPlugin
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants
import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants
Expand Down Expand Up @@ -51,6 +52,9 @@ final class GroovyScriptLaunchShortcutTests extends GroovyEclipseTestSuite {
setToDefault(IDebugPreferenceConstants.CONSOLE_OPEN_ON_OUT)
setToDefault(IInternalDebugUIConstants.PREF_WAIT_FOR_BUILD)
}

def configType = new GroovyScriptLaunchShortcut().groovyLaunchConfigType
DebugPlugin.getDefault().launchManager.getLaunchConfigurations(configType).each { it.delete() }
}

@Test
Expand Down Expand Up @@ -288,6 +292,28 @@ final class GroovyScriptLaunchShortcutTests extends GroovyEclipseTestSuite {
launchScriptAndAssertExitValue(type)
}

@Test // https://github.com/groovy/groovy-eclipse/issues/1299
void testScriptLaunch15() {
def shortcut = new GroovyScriptLaunchShortcut()
def unitType = addGroovySource('print "hello"', 'script').getType('script')

def newLaunchConfig = { ->
def workCopy = shortcut.findOrCreateLaunchConfig(shortcut.createLaunchProperties(unitType, unitType.javaProject), unitType.fullyQualifiedName)
try {
String arguments = workCopy.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, '')
return arguments
} finally {
workCopy.doSave()
}
}

assert !newLaunchConfig().contains('jupiter')

addJUnit(5) // change the project's classpath

assert newLaunchConfig().contains('jupiter')
}

//--------------------------------------------------------------------------

private String buildScriptClasspath(IJavaProject javaProject) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2020 the original author or authors.
* Copyright 2009-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -354,22 +354,26 @@ private String getWorkingDirectory(final IType runType, final IJavaProject javaP
* creates one.
*/
protected ILaunchConfigurationWorkingCopy findOrCreateLaunchConfig(final Map<String, String> launchProperties, final String launchName) throws CoreException {
String projectName = launchProperties.get(ATTR_PROJECT_NAME);
ILaunchConfiguration config = findConfiguration(projectName, launchProperties.get(GROOVY_TYPE_TO_RUN));
return (config != null ? config.getWorkingCopy() : createLaunchConfig(launchProperties, launchName));
ILaunchConfiguration config = findConfiguration(launchProperties.get(ATTR_PROJECT_NAME), launchProperties.get(GROOVY_TYPE_TO_RUN));
if (config == null) {
return createLaunchConfig(launchProperties, launchName);
} else {
ILaunchConfigurationWorkingCopy workingCopy = config.getWorkingCopy();
// program arguments contains project's classpath, so always use fresh value
workingCopy.setAttribute(ATTR_PROGRAM_ARGUMENTS, launchProperties.get(ATTR_PROGRAM_ARGUMENTS));

return workingCopy;
}
}

/**
* Creates a launch configuration for the given name and properties.
*/
private ILaunchConfigurationWorkingCopy createLaunchConfig(final Map<String, String> launchProperties, final String launchName) throws CoreException {
ILaunchConfigurationWorkingCopy workingCopy = getGroovyLaunchConfigType().newInstance(
null, getLaunchManager().generateLaunchConfigurationName(launchName));

ILaunchConfigurationWorkingCopy workingCopy = getGroovyLaunchConfigType().newInstance(null, getLaunchManager().generateLaunchConfigurationName(launchName));
for (Map.Entry<String, String> entry : launchProperties.entrySet()) {
workingCopy.setAttribute(entry.getKey(), entry.getValue());
}

return workingCopy;
}

Expand Down

0 comments on commit e9cfaf8

Please sign in to comment.