Skip to content

Commit 41a27d3

Browse files
committed
Record location of tracked objects, too
We will need this later, because we really want to verify, when compiling usage statistics, which update site (if any) the relevant file came from. If we cannot deduce the update site, we don't care about the object's usage, because it is not part of the "known ecosystem" of modules etc.
1 parent 3469e92 commit 41a27d3

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/main/java/org/scijava/usage/DefaultUsageService.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.util.Map;
3636

3737
import org.scijava.Identifiable;
38+
import org.scijava.Locatable;
3839
import org.scijava.event.EventHandler;
3940
import org.scijava.module.ModuleInfo;
4041
import org.scijava.module.event.ModuleExecutedEvent;
@@ -71,12 +72,13 @@ public void clearStats() {
7172

7273
@Override
7374
public UsageStats getUsage(final Object o) {
74-
if (!(o instanceof Identifiable)) {
75-
// only track objects with an identifier
75+
if (!(o instanceof Identifiable) || !(o instanceof Locatable)) {
76+
// only track objects with an identifier and a location
7677
return null;
7778
}
7879
final String id = ((Identifiable) o).getIdentifier();
79-
if (!stats.containsKey(id)) stats.put(id, new UsageStats(id));
80+
final String url = ((Locatable) o).getLocation();
81+
if (!stats.containsKey(id)) stats.put(id, new UsageStats(id, url));
8082
return stats.get(id);
8183
}
8284

src/main/java/org/scijava/usage/UsageStats.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,27 @@
3232
package org.scijava.usage;
3333

3434
import org.scijava.Identifiable;
35+
import org.scijava.Locatable;
3536

3637
/**
3738
* Data structure storing usage statistics for a particular identifier.
3839
*
3940
* @author Curtis Rueden
4041
*/
41-
public class UsageStats implements Identifiable {
42+
public class UsageStats implements Identifiable, Locatable {
4243

4344
/** The object's unique identifier. */
4445
private String id;
4546

47+
/** This object's location URL. */
48+
private String url;
49+
4650
/** Number of times the object was used. */
4751
private long count;
4852

49-
public UsageStats(final String id) {
53+
public UsageStats(final String id, final String url) {
5054
this.id = id;
55+
this.url = url;
5156
}
5257

5358
/** Gets the number of times the object has been used. */
@@ -67,4 +72,11 @@ public String getIdentifier() {
6772
return id;
6873
}
6974

75+
// -- Locatable methods --
76+
77+
@Override
78+
public String getLocation() {
79+
return url;
80+
}
81+
7082
}

0 commit comments

Comments
 (0)