Skip to content

Commit 24f3637

Browse files
committed
Merge pull request #61 from scijava/force-eclipse-helper
Do not auto-detect Eclipse when calling the EclipseHelper as main class
2 parents 159d78a + 976b6f5 commit 24f3637

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

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

Lines changed: 9 additions & 3 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) {
@@ -186,7 +191,7 @@ private void maybeIndex(final URL url, final ClassLoader loader) {
186191
if (classPath != null) {
187192
for (final String element : classPath.split(" +"))
188193
try {
189-
maybeIndex(new URL(element), loader);
194+
maybeIndex(new URL(url, element), loader);
190195
}
191196
catch (MalformedURLException e) {
192197
e.printStackTrace();
@@ -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)