Skip to content

Commit

Permalink
Fix for sources and javadoc attachment within Groovy Libraries container
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Jul 9, 2017
1 parent 77db5b0 commit ad6bd3f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,12 @@

public class GroovyClasspathContainer implements IClasspathContainer {

public static final String DESC = "Groovy Libraries";

public static final Path CONTAINER_ID = new Path("GROOVY_SUPPORT");

public static final IClasspathAttribute MINIMAL_ATTRIBUTE = new ClasspathAttribute("minimal", "true");

public static final String DESC = "Groovy Libraries";

public static final IClasspathAttribute[] MINIMAL_ATTRIBUTE_ARR = new IClasspathAttribute[] { MINIMAL_ATTRIBUTE };

private IClasspathEntry[] entries;

private IProject project;
Expand Down Expand Up @@ -84,26 +82,15 @@ private void updateEntries() {
final List<IClasspathEntry> cpEntries = new ArrayList<IClasspathEntry>(libraries.size());

for (IPath jarPath : libraries) {
IPath srcPath = null;

// check for sources
File srcJarFile = new File(jarPath.removeFileExtension().toString() + "-sources.jar");
if (srcJarFile.exists()) {
srcPath = new Path(srcJarFile.getAbsolutePath());
}
IPath srcPath = CompilerUtils.getJarInGroovyLib(jarPath.removeFileExtension().lastSegment() + "-sources.jar");

// check for javadoc
IClasspathAttribute[] cpAttrs;
File docJarFile = new File(jarPath.removeFileExtension().toString() + "-javadoc.jar");
if (docJarFile.exists()) {
cpAttrs = new IClasspathAttribute[] {
new ClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, docJarFile.getAbsolutePath())
};
} else {
cpAttrs = new IClasspathAttribute[0];
}

cpEntries.add(newLibraryEntry(jarPath, srcPath, null, null, cpAttrs, true));
IPath docPath = CompilerUtils.getJarInGroovyLib(jarPath.removeFileExtension().lastSegment() + "-javadoc.jar");

cpEntries.add(newLibraryEntry(jarPath, srcPath, null, null, (docPath == null) ? null : new IClasspathAttribute[] {
new ClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, docPath.toFile().toURL().toString())
}, true));
}

if (!minimalLibraries && useGroovyLibs()) {
Expand Down Expand Up @@ -134,16 +121,14 @@ public static boolean hasMinimalAttribute(IClasspathEntry entry) throws JavaMode

private boolean useGroovyLibs() {
IScopeContext projectScope = new ProjectScope(project);
IEclipsePreferences projectNode = projectScope
.getNode(GroovyCoreActivator.PLUGIN_ID);
IEclipsePreferences projectNode = projectScope.getNode(GroovyCoreActivator.PLUGIN_ID);
String val = projectNode.get(PreferenceConstants.GROOVY_CLASSPATH_USE_GROOVY_LIB, "default");
if (val.equals(Boolean.TRUE.toString())) {
return true;
} else if (val.equals(Boolean.FALSE.toString())) {
return false;
} else {
return GroovyCoreActivator.getDefault().getPreference(
PreferenceConstants.GROOVY_CLASSPATH_USE_GROOVY_LIB_GLOBAL, true);
return GroovyCoreActivator.getDefault().getPreference(PreferenceConstants.GROOVY_CLASSPATH_USE_GROOVY_LIB_GLOBAL, true);
}
}

Expand All @@ -154,7 +139,7 @@ private Collection<IClasspathEntry> getGroovyJarsInDotGroovyLib() {
File[] files = CompilerUtils.findJarsInDotGroovyLocation();
final List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(files.length);
for (File file : files) {
IClasspathEntry entry = newLibraryEntry(new Path(file.getAbsolutePath()), null, null, null, new IClasspathAttribute[0], true);
IClasspathEntry entry = newLibraryEntry(new Path(file.getAbsolutePath()), null, null, null, null, true);
newEntries.add(entry);
}
return newEntries;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,7 @@ public static IPath getJarInGroovyLib(String jarName) {
Bundle groovyBundle = CompilerUtils.getActiveGroovyBundle();
Enumeration<URL> enu = groovyBundle.findEntries("lib", jarName, false);
if (enu != null && enu.hasMoreElements()) {
URL jarUrl = enu.nextElement();
if (jarUrl.getFile().endsWith("-sources.jar") && enu.hasMoreElements()) {
jarUrl = enu.nextElement();
}
return toFilePath(jarUrl);
return toFilePath(enu.nextElement());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ private static void internalAddGroovyClasspathContainer(IJavaProject javaProject

private static IClasspathEntry createContainerEntry(boolean isMinimal) {
return JavaCore.newContainerEntry(GroovyClasspathContainer.CONTAINER_ID, new IAccessRule[0],
(isMinimal ? GroovyClasspathContainer.MINIMAL_ATTRIBUTE_ARR : new IClasspathAttribute[0]), true);
(isMinimal ? new IClasspathAttribute[] {GroovyClasspathContainer.MINIMAL_ATTRIBUTE} : new IClasspathAttribute[0]), true);
}

public static void addMinimalGroovyClasspathContainer(IJavaProject javaProject) {
Expand Down

0 comments on commit ad6bd3f

Please sign in to comment.