From f357cf9adade4759646b240c187f355d3ee12b39 Mon Sep 17 00:00:00 2001 From: Eric Milles Date: Thu, 6 Apr 2017 11:48:54 -0500 Subject: [PATCH] Fix for issue #277: Gradle plug-in's icon takes precedence for *.gradle --- .../internal/GroovyLanguageSupport.java | 4 +- .../MultiplexingCommentRecorderParser.java | 4 +- .../groovy/core/util/ContentTypeUtils.java | 339 ++++++++++-------- .../ui/decorators/GroovyImageDecorator.java | 10 +- .../ui/decorators/GroovyPluginImages.java | 16 +- 5 files changed, 218 insertions(+), 155 deletions(-) diff --git a/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/integration/internal/GroovyLanguageSupport.java b/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/integration/internal/GroovyLanguageSupport.java index efbc6f6187..394d2fae2d 100644 --- a/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/integration/internal/GroovyLanguageSupport.java +++ b/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/integration/internal/GroovyLanguageSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2016 the original author or authors. + * Copyright 2009-2017 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. @@ -182,7 +182,7 @@ public boolean isSourceFile(String fileName, boolean isInterestingProject) { if (isInterestingProject) { return Util.isJavaLikeFileName(fileName); } else { - return ContentTypeUtils.isJavaLikeButNotGroovyLikeExtension(fileName); + return ContentTypeUtils.isJavaLikeButNotGroovyLikeFileName(fileName); } } diff --git a/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/integration/internal/MultiplexingCommentRecorderParser.java b/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/integration/internal/MultiplexingCommentRecorderParser.java index 752c8c1800..0e3d5d2584 100644 --- a/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/integration/internal/MultiplexingCommentRecorderParser.java +++ b/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/integration/internal/MultiplexingCommentRecorderParser.java @@ -16,7 +16,7 @@ package org.codehaus.jdt.groovy.integration.internal; import static org.eclipse.jdt.groovy.core.util.ContentTypeUtils.isGroovyLikeFileName; -import static org.eclipse.jdt.groovy.core.util.ContentTypeUtils.isJavaLikeButNotGroovyLikeExtension; +import static org.eclipse.jdt.groovy.core.util.ContentTypeUtils.isJavaLikeButNotGroovyLikeFileName; import java.util.regex.Pattern; @@ -61,7 +61,7 @@ public CompilationUnitDeclaration dietParse(ICompilationUnit sourceUnit, Compila } private static boolean isGroovyLikeSourceUnit(ICompilationUnit sourceUnit) { - if (sourceUnit.getFileName() == null || !isJavaLikeButNotGroovyLikeExtension(String.valueOf(sourceUnit.getFileName()))) { + if (sourceUnit.getFileName() == null || !isJavaLikeButNotGroovyLikeFileName(String.valueOf(sourceUnit.getFileName()))) { if (GROOVY_SOURCE_DISCRIMINATOR.matcher(new CharArraySequence(sourceUnit.getContents())).find()) { Util.log(1, "Identified a Groovy source unit through inspection of its contents: " + String.valueOf(sourceUnit.getContents(), 0, Math.min(250, sourceUnit.getContents().length))); diff --git a/base/org.eclipse.jdt.groovy.core/src/org/eclipse/jdt/groovy/core/util/ContentTypeUtils.java b/base/org.eclipse.jdt.groovy.core/src/org/eclipse/jdt/groovy/core/util/ContentTypeUtils.java index c5741f8b58..40ff8d9337 100644 --- a/base/org.eclipse.jdt.groovy.core/src/org/eclipse/jdt/groovy/core/util/ContentTypeUtils.java +++ b/base/org.eclipse.jdt.groovy.core/src/org/eclipse/jdt/groovy/core/util/ContentTypeUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2016 the original author or authors. + * Copyright 2009-2017 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. @@ -15,10 +15,13 @@ */ package org.eclipse.jdt.groovy.core.util; +import static org.eclipse.jdt.internal.core.util.Util.getJavaLikeExtensions; + import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; -import java.util.HashSet; +import java.util.Comparator; import java.util.List; import java.util.Set; import java.util.TreeSet; @@ -30,147 +33,220 @@ import org.eclipse.jdt.internal.core.util.Util; /** - * Utility methods for dealing with Groovy content types - * - * @author Andrew Eisenberg - * @created Jun 23, 2009 + * Utility methods for dealing with Groovy content types. */ public class ContentTypeUtils { - private ContentTypeUtils() { - // uninstantiable + private ContentTypeUtils() {} + + /** + * Returns the registered Gradle-like extensions. + */ + public static char[][] getGradleLikeExtensions() { + if (GRADLE_LIKE_EXTENSIONS == null) { + IContentTypeManager contentTypeManager = Platform.getContentTypeManager(); + if (contentTypeManager != null) { + IContentType gradleContentType = contentTypeManager.getContentType(GRADLE_SCRIPT_CONTENT_TYPE); + String[] gradleFileExtensions = gradleContentType.getFileSpecs(IContentType.FILE_EXTENSION_SPEC); + + GRADLE_LIKE_EXTENSIONS = toCharArrayArray(Arrays.asList(gradleFileExtensions)); + } else { + GRADLE_LIKE_EXTENSIONS = new char[][] {"gradle".toCharArray()}; + } + } + return GRADLE_LIKE_EXTENSIONS; } - static { - IContentTypeManager contentTypeManager = Platform.getContentTypeManager(); - if (contentTypeManager != null) { - contentTypeManager.addContentTypeChangeListener(new IContentTypeManager.IContentTypeChangeListener() { - public void contentTypeChanged(ContentTypeChangeEvent event) { - // we can be more specific here, but content types change so rarely, that - // I am not concerned about being overly eager to invalidate the cache - GROOVY_FILE_NAMES = null; - GROOVY_LIKE_EXTENSIONS = null; - JAVA_LIKE_BUT_NOT_GROOVY_LIKE_EXTENSIONS = null; + /** + * Returns the registered Groovy-like extensions. + */ + public static char[][] getGroovyLikeExtensions() { + if (GROOVY_LIKE_EXTENSIONS == null) { + IContentTypeManager contentTypeManager = Platform.getContentTypeManager(); + if (contentTypeManager != null) { + Set extensions = new TreeSet(new Comparator() { + public int compare(String s1, String s2) { + if (s1.equals("groovy")) return -1; + if (s2.equals("groovy")) return +1; + return s1.compareTo(s2); + } + }); + IContentType groovyContentType = contentTypeManager.getContentType(GROOVY_SOURCE_CONTENT_TYPE); + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=121715 + // content types derived from Groovy content type should be included + for (IContentType contentType : contentTypeManager.getAllContentTypes()) { + if (contentType.isKindOf(groovyContentType)) { + for (String fileExtension : contentType.getFileSpecs(IContentType.FILE_EXTENSION_SPEC)) { + extensions.add(fileExtension); + } + } } - }); + if (extensions.isEmpty()) { + // Shouldn't happen, but it seems it does. See: STS-3936 + // Probably means user's workspace is already severely broken... + // Still it is not nice to throw exceptions. So handle the case and log an error instead. + if (!noGroovyContentTypesErrorLogged) { + noGroovyContentTypesErrorLogged = true; + Util.log(new IllegalStateException("No Groovy Content Types found. This shouldn't happen. Is the workspace metadata corrupted?")); + } + // Don't cache it. Maybe its only looking funky because we are looking 'too early'. + return new char[][] {"groovy".toCharArray()}; + } + GROOVY_LIKE_EXTENSIONS = toCharArrayArray(extensions); + } else { + GROOVY_LIKE_EXTENSIONS = new char[][] {"groovy".toCharArray()}; + } } + return GROOVY_LIKE_EXTENSIONS; } - private static Set GROOVY_FILE_NAMES; - private static char[][] GROOVY_LIKE_EXTENSIONS; - private static char[][] JAVA_LIKE_BUT_NOT_GROOVY_LIKE_EXTENSIONS; + /** + * Returns the registered Java-like extensions (excluding the Groovy-like ones). + */ + public static char[][] getJavaButNotGroovyLikeExtensions() { + if (JAVA_LIKE_BUT_NOT_GROOVY_LIKE_EXTENSIONS == null) { + char[][] javaLikeExtensions = getJavaLikeExtensions(); + char[][] groovyLikeExtensiosn = getGroovyLikeExtensions(); + List interestingExtensions = new ArrayList(); + for (char[] javaLike : javaLikeExtensions) { + boolean found = false; + for (char[] groovyLike : groovyLikeExtensiosn) { + if (Arrays.equals(javaLike, groovyLike)) { + found = true; + break; + } + } + if (!found) { + interestingExtensions.add(javaLike); + } + } + JAVA_LIKE_BUT_NOT_GROOVY_LIKE_EXTENSIONS = interestingExtensions.toArray(new char[interestingExtensions.size()][]); + + // ensure "java" is first + int javaIndex = 0; + char[] javaArr = "java".toCharArray(); + while (javaIndex < JAVA_LIKE_BUT_NOT_GROOVY_LIKE_EXTENSIONS.length) { + if (Arrays.equals(javaArr, JAVA_LIKE_BUT_NOT_GROOVY_LIKE_EXTENSIONS[javaIndex])) { + break; + } + javaIndex++; + } + if (javaIndex < JAVA_LIKE_BUT_NOT_GROOVY_LIKE_EXTENSIONS.length) { + JAVA_LIKE_BUT_NOT_GROOVY_LIKE_EXTENSIONS[javaIndex] = JAVA_LIKE_BUT_NOT_GROOVY_LIKE_EXTENSIONS[0]; + JAVA_LIKE_BUT_NOT_GROOVY_LIKE_EXTENSIONS[0] = javaArr; + } else { + Util.log(null, "'java' not registered as a java-like extension"); + } + } + return JAVA_LIKE_BUT_NOT_GROOVY_LIKE_EXTENSIONS; + } - public static final String GROOVY_SOURCE_CONTENT_TYPE = "org.eclipse.jdt.groovy.core.groovySource"; + /** + * Determines if the given file is a Gradle script file. + * + * @param fileName absolute path or simple name is fine + * @return {@code true} iff the file name is Gradle-like + */ + public static boolean isGradleLikeFileName(char[] fileName) { + if (fileName != null && fileName.length > 0) { + return isGradleLikeFileName(new CharArraySequence(fileName)); + } + return false; + } - private static boolean noGroovyContentTypesErrorLogged = false; // To avoid spamming error into the log repeatedly. + /** + * Determines if the given file is a Gradle script file. + * + * @param fileName absolute path or simple name is fine + * @return {@code true} iff the file name is Gradle-like + */ + public static boolean isGradleLikeFileName(CharSequence fileName) { + if (fileName != null && fileName.length() > 0) { + if (endsWithAny(fileName, getGradleLikeExtensions())) { + return true; + } + // TODO: Gradle file names + } + return false; + } /** - * Uses the Eclipse content type extension point to determine if a file is a groovy file. + * Determines if the given file is a Groovy source file. * - * @param fileName (absolute path or simple name is fine) + * @param fileName absolute path or simple name is fine * @return {@code true} iff the file name is Groovy-like */ public static boolean isGroovyLikeFileName(char[] fileName) { if (fileName != null && fileName.length > 0) { - return isGroovyLikeFileName(String.valueOf(fileName)); + return isGroovyLikeFileName(new CharArraySequence(fileName)); } return false; } /** - * Uses the Eclipse content type extension point to determine if a file is a groovy file. + * Determines if the given file is a Groovy source file. * - * @param fileName (absolute path or simple name is fine) + * @param fileName absolute path or simple name is fine * @return {@code true} iff the file name is Groovy-like */ - public static boolean isGroovyLikeFileName(String fileName) { - if (fileName != null && fileName.length() > 0 && !fileName.endsWith(".java")) { - if (indexOfGroovyLikeExtension(fileName) != -1) { + public static boolean isGroovyLikeFileName(CharSequence fileName) { + if (fileName != null && fileName.length() > 0) { + if (endsWithAny(fileName, getGroovyLikeExtensions())) { return true; } if (GROOVY_FILE_NAMES == null) { GROOVY_FILE_NAMES = loadGroovyFileNames(); } - fileName = fileName.substring(fileName.lastIndexOf('/') + 1); - return GROOVY_FILE_NAMES.contains(fileName); + fileName = fileName.subSequence( + lastIndexOf(fileName, '/') + 1, fileName.length()); + return GROOVY_FILE_NAMES.contains(fileName.toString()); } return false; } /** - * Returns the index of the Groovy like extension of the given file name or -1 if it doesn't end with a known Java like - * extension. Note this is the index of the '.' even if it is not considered part of the extension. Adapted from - * {@link org.eclipse.jdt.internal.core.util.Util#indexOfJavaLikeExtension}. + * Determines if the given file is a Java source file. + * + * @param fileName absolute path or simple name is fine + * @return {@code true} iff the file name is Java-like (but not Groovy-like) */ - public static int indexOfGroovyLikeExtension(String fileName) { - if (fileName != null) { - int fileNameLength = fileName.length(); - if (fileNameLength > 0) { - for (char[] extension : getGroovyLikeExtensions()) { - int offset = (fileNameLength - extension.length); - if (offset < 1 || fileName.charAt(offset - 1) != '.') - continue; - if (Arrays.equals(extension, fileName.substring(offset).toCharArray())) - return (offset - 1); - } + public static boolean isJavaLikeButNotGroovyLikeFileName(CharSequence fileName) { + if (fileName != null && fileName.length() > 0) { + if (endsWithAny(fileName, getJavaButNotGroovyLikeExtensions())) { + return true; } } - return -1; + return false; } - /** - * Returns the registered Java like extensions. Taken from org.eclipse.jdt.internal.core.util.Util.getJavaLikeExtensions - */ - public static char[][] getGroovyLikeExtensions() { - if (GROOVY_LIKE_EXTENSIONS == null) { - Set fileExtensions = loadGroovyFileExtensions(); - if (fileExtensions.isEmpty()) { - // Shouldn't happen, but it seems it does. - // See: STS-3936 - // Probably means user's workspace is already severely broken... - // Still it is not nice to throw exceptions. So handle the case and log an error instead. - if (!noGroovyContentTypesErrorLogged) { - noGroovyContentTypesErrorLogged = true; - Util.log(new IllegalStateException( - "No Groovy Content Types found. This shouldn't happen. Is the workspace metadata corrupted?")); - } - // Don't cache it. Maybe its only looking funky because we are looking 'too early'. - return new char[][] { "groovy".toCharArray() }; - } else { - int length = fileExtensions.size(); - char[][] extensions = new char[length][]; - extensions[0] = "groovy".toCharArray(); // ensure that "groovy" is first - int index = 1; - for (String fileExtension : fileExtensions) { - if ("groovy".equals(fileExtension)) - continue; - extensions[index++] = fileExtension.toCharArray(); - } - GROOVY_LIKE_EXTENSIONS = extensions; - } - } - return GROOVY_LIKE_EXTENSIONS; - } + //-------------------------------------------------------------------------- - private static Set loadGroovyFileExtensions() { + static { IContentTypeManager contentTypeManager = Platform.getContentTypeManager(); if (contentTypeManager != null) { - IContentType groovyContentType = contentTypeManager.getContentType(GROOVY_SOURCE_CONTENT_TYPE); - Set extensions = new HashSet(); - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=121715 - // content types derived from groovy content type should be included - for (IContentType contentType : contentTypeManager.getAllContentTypes()) { - if (contentType.isKindOf(groovyContentType)) { // note that contentType.isKindOf(javaContentType) == true - for (String fileExtension : contentType.getFileSpecs(IContentType.FILE_EXTENSION_SPEC)) { - extensions.add(fileExtension); - } + contentTypeManager.addContentTypeChangeListener(new IContentTypeManager.IContentTypeChangeListener() { + public void contentTypeChanged(ContentTypeChangeEvent event) { + // we can be more specific here, but content types change so rarely, that + // I am not concerned about being overly eager to invalidate the cache + GROOVY_FILE_NAMES = null; + GROOVY_LIKE_EXTENSIONS = null; + GRADLE_LIKE_EXTENSIONS = null; + JAVA_LIKE_BUT_NOT_GROOVY_LIKE_EXTENSIONS = null; } - } - return extensions; + }); } - return Collections.singleton("groovy"); } + private static Set GROOVY_FILE_NAMES; + private static char[][] GROOVY_LIKE_EXTENSIONS; + private static char[][] GRADLE_LIKE_EXTENSIONS; + private static char[][] JAVA_LIKE_BUT_NOT_GROOVY_LIKE_EXTENSIONS; + + private static final String GRADLE_SCRIPT_CONTENT_TYPE = "org.eclipse.jdt.groovy.core.gradleScript"; + private static final String GROOVY_SOURCE_CONTENT_TYPE = "org.eclipse.jdt.groovy.core.groovySource"; + + private static boolean noGroovyContentTypesErrorLogged = false; // To avoid spamming error into the log repeatedly. + private static Set loadGroovyFileNames() { IContentTypeManager contentTypeManager = Platform.getContentTypeManager(); if (contentTypeManager != null) { @@ -189,70 +265,37 @@ private static Set loadGroovyFileNames() { return Collections.emptySet(); } - public static boolean isJavaLikeButNotGroovyLikeExtension(String fileName) { - if (JAVA_LIKE_BUT_NOT_GROOVY_LIKE_EXTENSIONS == null) { - initJavaLikeButNotGroovyLikeExtensions(); - } + //-------------------------------------------------------------------------- - int fileNameLength = fileName.length(); - extensions: for (int i = 0, length = JAVA_LIKE_BUT_NOT_GROOVY_LIKE_EXTENSIONS.length; i < length; i++) { - char[] extension = JAVA_LIKE_BUT_NOT_GROOVY_LIKE_EXTENSIONS[i]; - int extensionLength = extension.length; - int extensionStart = fileNameLength - extensionLength; - int dotIndex = extensionStart - 1; - if (dotIndex < 0) + private static boolean endsWithAny(CharSequence sequence, char[]... extensions) { + int length = sequence.length(); + for (char[] extension : extensions) { + int offset = (length - extension.length); + if (offset < 1 || sequence.charAt(offset - 1) != '.') { continue; - if (fileName.charAt(dotIndex) != '.') - continue; - for (int j = 0; j < extensionLength; j++) { - if (fileName.charAt(extensionStart + j) != extension[j]) - continue extensions; } - return true; + if (sequence.subSequence(offset, length).toString().equals(String.valueOf(extension))) { + return true; + } } - return false; } - private static void initJavaLikeButNotGroovyLikeExtensions() { - char[][] javaLikeExtensions = Util.getJavaLikeExtensions(); - char[][] groovyLikeExtensiosn = getGroovyLikeExtensions(); - List interestingExtensions = new ArrayList(); - for (char[] javaLike : javaLikeExtensions) { - boolean found = false; - for (char[] groovyLike : groovyLikeExtensiosn) { - if (Arrays.equals(javaLike, groovyLike)) { - found = true; - break; - } - } - if (!found) { - interestingExtensions.add(javaLike); + private static int lastIndexOf(CharSequence sequence, char character) { + for (int i = sequence.length() - 1; i >= 0; i -= 1) { + if (sequence.charAt(i) == character) { + return i; } } - JAVA_LIKE_BUT_NOT_GROOVY_LIKE_EXTENSIONS = interestingExtensions.toArray(new char[interestingExtensions.size()][]); - - // ensure "java" is first - int javaIndex = 0; - char[] javaArr = "java".toCharArray(); - while (javaIndex < JAVA_LIKE_BUT_NOT_GROOVY_LIKE_EXTENSIONS.length) { - if (Arrays.equals(javaArr, JAVA_LIKE_BUT_NOT_GROOVY_LIKE_EXTENSIONS[javaIndex])) { - break; - } - javaIndex++; - } - if (javaIndex < JAVA_LIKE_BUT_NOT_GROOVY_LIKE_EXTENSIONS.length) { - JAVA_LIKE_BUT_NOT_GROOVY_LIKE_EXTENSIONS[javaIndex] = JAVA_LIKE_BUT_NOT_GROOVY_LIKE_EXTENSIONS[0]; - JAVA_LIKE_BUT_NOT_GROOVY_LIKE_EXTENSIONS[0] = javaArr; - } else { - Util.log(null, "'java' not registered as a java-like extension"); - } + return -1; } - public static char[][] getJavaButNotGroovyLikeExtensions() { - if (JAVA_LIKE_BUT_NOT_GROOVY_LIKE_EXTENSIONS == null) { - initJavaLikeButNotGroovyLikeExtensions(); + private static char[][] toCharArrayArray(Collection strings) { + int i = 0, n = strings.size(); + char[][] arrays = new char[n][]; + for (String string : strings) { + arrays[i++] = string.toCharArray(); } - return JAVA_LIKE_BUT_NOT_GROOVY_LIKE_EXTENSIONS; + return arrays; } } diff --git a/ide/org.codehaus.groovy.eclipse.ui/src/org/codehaus/groovy/eclipse/ui/decorators/GroovyImageDecorator.java b/ide/org.codehaus.groovy.eclipse.ui/src/org/codehaus/groovy/eclipse/ui/decorators/GroovyImageDecorator.java index 8c3b169ba6..414ad0faf2 100644 --- a/ide/org.codehaus.groovy.eclipse.ui/src/org/codehaus/groovy/eclipse/ui/decorators/GroovyImageDecorator.java +++ b/ide/org.codehaus.groovy.eclipse.ui/src/org/codehaus/groovy/eclipse/ui/decorators/GroovyImageDecorator.java @@ -20,11 +20,13 @@ import java.util.HashMap; import java.util.Map; +import org.codehaus.groovy.eclipse.GroovyPlugin; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.groovy.core.util.ContentTypeUtils; import org.eclipse.jdt.groovy.core.util.ScriptFolderSelector; import org.eclipse.jdt.internal.ui.JavaPlugin; import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider; @@ -95,7 +97,10 @@ private Image getJavaElementImageDescriptor(Image image, IResource resource) { if (image != null && image.getBounds().width > 16) { size = JavaElementImageProvider.BIG_SIZE; } - ImageDescriptor desc = GroovyPluginImages.DESC_GROOVY_FILE; + + boolean isGradle = (GroovyPluginImages.DESC_GRADLE_FILE != null && ContentTypeUtils.isGradleLikeFileName(resource.getName())); + ImageDescriptor desc = isGradle ? GroovyPluginImages.DESC_GRADLE_FILE : GroovyPluginImages.DESC_GROOVY_FILE; + if (!isGradle) try { if (isGroovyProject(resource.getProject())) { if (isRuntimeCompiled(resource)) { @@ -107,8 +112,9 @@ private Image getJavaElementImageDescriptor(Image image, IResource resource) { flags |= JavaElementImageDescriptor.BUILDPATH_ERROR; } } catch (Exception e) { - e.printStackTrace(); + GroovyPlugin.getDefault().logError("Failed to apply image overlay(s) to: " + resource.getName(), e); } + return getImage(new JavaElementImageDescriptor(desc, flags, size)); } diff --git a/ide/org.codehaus.groovy.eclipse.ui/src/org/codehaus/groovy/eclipse/ui/decorators/GroovyPluginImages.java b/ide/org.codehaus.groovy.eclipse.ui/src/org/codehaus/groovy/eclipse/ui/decorators/GroovyPluginImages.java index 75e12130b9..87bac2c038 100644 --- a/ide/org.codehaus.groovy.eclipse.ui/src/org/codehaus/groovy/eclipse/ui/decorators/GroovyPluginImages.java +++ b/ide/org.codehaus.groovy.eclipse.ui/src/org/codehaus/groovy/eclipse/ui/decorators/GroovyPluginImages.java @@ -20,12 +20,26 @@ public final class GroovyPluginImages { + public static final ImageDescriptor DESC_GRADLE_FILE = createDescriptor2( + "platform:/plugin/org.eclipse.buildship.ui/icons/full/obj16/gradle_file.png"); public static final ImageDescriptor DESC_GROOVY_FILE = createDescriptor("icons/groovy_file.gif"); - public static final ImageDescriptor DESC_NEW_GROOVY_PROJECT = createDescriptor("icons/full/newgroovyprj_wiz.gif"); private static ImageDescriptor createDescriptor(String path) { // create the image descriptor without causing this bundle to be activated return ImageDescriptor.createFromURL(FrameworkUtil.getBundle(GroovyPluginImages.class).getEntry(path)); } + + private static ImageDescriptor createDescriptor2(String path) { + ImageDescriptor desc; + try { + desc = ImageDescriptor.createFromURL(new java.net.URL(path)); + org.eclipse.swt.graphics.Image img = desc.createImage(false); + if (img != null) { img.dispose(); } else { desc = null; } + } catch (Exception e) { + e.printStackTrace(); + desc = null; + } + return desc; + } }