Skip to content

Commit 8e92558

Browse files
committed
Only write META-INF/json/ if annotations were found
Originally, we wanted to run the EclipseHelper only for a limited set of situations, using the test whether the first class path element of the current class loader is a directory as an indicator that we're running in Eclipse. We also wanted to use the time stamp of META-INF/json/ as an indicator whether we need to index the annotations or not. However, it turns out that we probably need to run in more situations, e.g. because the directories in question might be first indexed during a run inside a LegacyEnvironment. So let's just punt and run the EclipseHelper in more situations, but avoid to write META-INF/json/ unless we really have anything to write. This addresses #33. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 843e23c commit 8e92558

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ public abstract class AbstractIndexWriter {
6060
private final Map<String, Map<String, Object>> map =
6161
new TreeMap<String, Map<String, Object>>();
6262

63+
protected synchronized boolean foundAnnotations() {
64+
return !map.isEmpty();
65+
}
66+
6367
protected synchronized void add(final Map<String, Object> annotationValues,
6468
final String annotationName, final String className)
6569
{

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,16 +212,17 @@ private void index(File directory, ClassLoader loader) {
212212
+ ", up-to-date: " + upToDate(directory));
213213
return;
214214
}
215-
System.err.println("[ECLIPSE HELPER] Indexing annotations...");
215+
final File jsonDirectory = new File(directory, Index.INDEX_PREFIX);
216216
try {
217217
discoverAnnotations(directory, "", loader);
218+
if (!jsonDirectory.exists() && !foundAnnotations()) return;
219+
System.err.println("[ECLIPSE HELPER] Indexing annotations...");
218220
write(directory);
219221
}
220222
catch (IOException e) {
221223
e.printStackTrace();
222224
}
223225
// update the timestamp of META-INF/json/
224-
final File jsonDirectory = new File(directory, Index.INDEX_PREFIX);
225226
if (jsonDirectory.isDirectory()) {
226227
jsonDirectory.setLastModified(System.currentTimeMillis());
227228
}

0 commit comments

Comments
 (0)