Skip to content

Commit

Permalink
Fix for issue #616: re-connect project and runtime (aka IDE) classpaths
Browse files Browse the repository at this point in the history
for Java 9+ until proper modulepath support can be implemented
  • Loading branch information
eric-milles committed Jul 2, 2018
1 parent dd8281f commit 5f5723e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ private GroovyClassLoader[] getBatchGroovyClassLoaders(CompilerConfiguration com
}

private GroovyClassLoader[] getProjectGroovyClassLoaders(CompilerConfiguration compilerConfiguration) {
String projectName = compilerOptions.groovyProjectName; IProject project = findProject(projectName);
String projectName = compilerOptions.groovyProjectName;
IProject project = findProject(projectName);
try {
IJavaProject javaProject = JavaCore.create(project);
IClasspathEntry[] classpathEntries = javaProject.exists() ? javaProject.getResolvedClasspath(true) : new IClasspathEntry[0];
Expand All @@ -152,9 +153,15 @@ private GroovyClassLoader[] getProjectGroovyClassLoaders(CompilerConfiguration c
"Transform classpath: " + String.join(File.pathSeparator, xformPaths));
}

ClassLoader parentClassLoader = null; // no parent loader by default
// FIXME: This is a stopgap measure to provide basic support for Java 9+
if (classPaths.stream().anyMatch(path -> path.endsWith("jrt-fs.jar"))) {
parentClassLoader = GroovyParser.class.getClassLoader();
}

return new java.util.AbstractMap.SimpleEntry<>(classpathEntries, new GroovyClassLoader[] {
new GrapeAwareGroovyClassLoader(newClassLoader(classPaths, null/*no parent loader*/), compilerConfiguration),
new GroovyClassLoader(newClassLoader(xformPaths, GroovyParser.class.getClassLoader())/*, compilerConfiguration*/)
new GrapeAwareGroovyClassLoader(newClassLoader(classPaths, parentClassLoader), compilerConfiguration),
new GroovyClassLoader(newClassLoader(xformPaths, GroovyParser.class.getClassLoader())/*, compilerConfiguration*/),
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,3 @@
/*
* Copyright 2009-2018 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Copyright 2009-2018 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Copyright 2009-2018 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Copyright 2009-2018 the original author or authors.
*
Expand All @@ -60,7 +15,6 @@
*/
package org.codehaus.groovy.eclipse.core.test

import org.codehaus.groovy.eclipse.core.search.ISearchRequestor
import org.codehaus.groovy.eclipse.core.search.SyntheticAccessorSearchRequestor
import org.codehaus.groovy.eclipse.test.GroovyEclipseTestSuite
import org.eclipse.jdt.core.IJavaElement
Expand Down Expand Up @@ -276,27 +230,14 @@ final class SyntheticMemberSearchTests extends GroovyEclipseTestSuite {

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

private static class TestSearchRequestor implements ISearchRequestor {
List<SearchMatch> matches = []
public void acceptMatch(SearchMatch match) {
matches << match
}
}

private IJavaElement findSearchTarget(String name, IType type) {
for (IJavaElement child : type.children) {
if (child.elementName == name) {
return child
}
}
Assert.fail("child not found: $name")
}

private List<SearchMatch> performSearch(String searchName, IType type = gType) {
IJavaElement toSearch = findSearchTarget(searchName, type)
TestSearchRequestor requestor = new TestSearchRequestor()
new SyntheticAccessorSearchRequestor().findSyntheticMatches(toSearch, requestor, null)
return requestor.matches
IJavaElement target = type.children.find { it.elementName == searchName }
Assert.assertNotNull("child not found: $searchName", target)

List<SearchMatch> matches = []
new SyntheticAccessorSearchRequestor().findSyntheticMatches(
target, { match -> if (match.offset < 200) matches << match }, null)
return matches
}

/**
Expand Down

0 comments on commit 5f5723e

Please sign in to comment.