Skip to content

Commit 4a8d799

Browse files
committed
Cache pom versions
No reason this should change for a given POM object. So let's cache it to avoid reading the XML repeatedly.
1 parent 509b5c1 commit 4a8d799

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/main/java/org/scijava/util/POM.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
*/
5353
public class POM extends XML implements Comparable<POM>, Versioned {
5454

55+
private String version;
56+
5557
/** Parses a POM from the given file. */
5658
public POM(final File file) throws ParserConfigurationException,
5759
SAXException, IOException
@@ -145,9 +147,15 @@ public int compareTo(final POM pom) {
145147
/** Gets the POM's version. */
146148
@Override
147149
public String getVersion() {
148-
final String version = cdata("//project/version");
149-
if (version != null) return version;
150-
return cdata("//project/parent/version");
150+
if (version == null) {
151+
synchronized (this) {
152+
if (version == null) {
153+
version = cdata("//project/version");
154+
if (version == null) version = cdata("//project/parent/version");
155+
}
156+
}
157+
}
158+
return version;
151159
}
152160

153161
// -- Utility methods --

0 commit comments

Comments
 (0)