Skip to content

Commit 976b6f5

Browse files
committed
Do not auto-detect Eclipse when calling the EclipseHelper as main class
There needs to be a way to force the EclipseHelper to index all it can, even when it thinks it is not running inside Eclipse at all. The best idea is to make this automatic when calling EclipseHelper as a main class because we *know* that the developer wants to index the annotations in this case, even if Eclipse Indigo has passed the class path elements in a semi-random order. Wished-for by Christian Dietz. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent e69a235 commit 976b6f5

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/main/java/org/scijava/annotations/EclipseHelper.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,13 @@
9797
*/
9898
public class EclipseHelper extends DirectoryIndexer {
9999

100+
private static final String FORCE_ANNOTATION_INDEX_PROPERTY = "force.annotation.index";
100101
static Set<URL> indexed = new HashSet<URL>();
101102
private boolean bannerShown;
102103

103104
private static boolean debug =
104105
"debug".equals(System.getProperty("scijava.log.level"));
106+
private boolean autoDetectEclipse = true;
105107

106108
private static void debug(final String message) {
107109
if (debug) {
@@ -131,10 +133,13 @@ public static void updateAnnotationIndex(final ClassLoader loader) {
131133
return;
132134
}
133135
EclipseHelper helper = new EclipseHelper();
136+
if (Boolean.getBoolean(FORCE_ANNOTATION_INDEX_PROPERTY)) {
137+
helper.autoDetectEclipse = false;
138+
}
134139
boolean first = true;
135140
for (final URL url : ((URLClassLoader) loader).getURLs()) {
136141
debug("Checking URL: " + url);
137-
if (first) {
142+
if (helper.autoDetectEclipse && first) {
138143
if (!"file".equals(url.getProtocol()) ||
139144
(!url.getPath().endsWith("/") && !url.getPath().contains("surefire")))
140145
{
@@ -177,7 +182,7 @@ private void maybeIndex(final URL url, final ClassLoader loader) {
177182
* but crucially also the target/classes/ and target/test-classes/
178183
* directories which may need to be indexed.
179184
*/
180-
if (path.matches(".*/target/surefire/surefirebooter[0-9]*\\.jar")) try {
185+
if (!autoDetectEclipse || path.matches(".*/target/surefire/surefirebooter[0-9]*\\.jar")) try {
181186
final JarFile jar = new JarFile(path);
182187
Manifest manifest = jar.getManifest();
183188
if (manifest != null) {
@@ -286,6 +291,7 @@ else if (file.isDirectory()) {
286291
* </p>
287292
*/
288293
public static void main(final String... args) {
294+
System.setProperty(FORCE_ANNOTATION_INDEX_PROPERTY, "true");
289295
updateAnnotationIndex(Thread.currentThread().getContextClassLoader());
290296
}
291297

0 commit comments

Comments
 (0)