Skip to content

Commit afbcbf4

Browse files
committed
Move version info away from Designer
- This allows consumers (ie: pmd-cli) to access the Designer version without requiring JavaFX
1 parent c51a04f commit afbcbf4

File tree

5 files changed

+78
-64
lines changed

5 files changed

+78
-64
lines changed

src/main/java/net/sourceforge/pmd/util/fxdesigner/Designer.java

Lines changed: 6 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,13 @@
55
package net.sourceforge.pmd.util.fxdesigner;
66

77
import java.io.IOException;
8-
import java.io.InputStream;
98
import java.util.Arrays;
109
import java.util.List;
1110
import java.util.Objects;
12-
import java.util.Optional;
13-
import java.util.Properties;
1411
import java.util.logging.Level;
1512
import java.util.logging.Logger;
1613
import java.util.stream.Collectors;
1714

18-
import net.sourceforge.pmd.PMDVersion;
19-
import net.sourceforge.pmd.lang.ast.xpath.Attribute;
20-
import net.sourceforge.pmd.util.fxdesigner.app.DesignerParams;
21-
import net.sourceforge.pmd.util.fxdesigner.app.DesignerRoot;
22-
import net.sourceforge.pmd.util.fxdesigner.app.DesignerRootImpl;
23-
import net.sourceforge.pmd.util.fxdesigner.util.DesignerUtil;
24-
import net.sourceforge.pmd.util.fxdesigner.util.ResourceUtil;
25-
2615
import javafx.application.Application;
2716
import javafx.application.Platform;
2817
import javafx.collections.ObservableList;
@@ -31,6 +20,11 @@
3120
import javafx.scene.Scene;
3221
import javafx.scene.image.Image;
3322
import javafx.stage.Stage;
23+
import net.sourceforge.pmd.lang.ast.xpath.Attribute;
24+
import net.sourceforge.pmd.util.fxdesigner.app.DesignerParams;
25+
import net.sourceforge.pmd.util.fxdesigner.app.DesignerRoot;
26+
import net.sourceforge.pmd.util.fxdesigner.app.DesignerRootImpl;
27+
import net.sourceforge.pmd.util.fxdesigner.util.DesignerUtil;
3428

3529

3630
/**
@@ -41,44 +35,6 @@
4135
*/
4236
public class Designer extends Application {
4337

44-
/**
45-
* Constant that contains always the current version of the designer.
46-
*/
47-
private static final String VERSION;
48-
private static final String PMD_CORE_MIN_VERSION;
49-
private static final String UNKNOWN_VERSION = "unknown";
50-
51-
52-
/**
53-
* Determines the version from maven's generated pom.properties file.
54-
*/
55-
static {
56-
VERSION = readProperty("/META-INF/maven/net.sourceforge.pmd/pmd-ui/pom.properties", "version").orElse(UNKNOWN_VERSION);
57-
PMD_CORE_MIN_VERSION = readProperty(ResourceUtil.resolveResource("designer.properties"), "pmd.core.version").orElse(UNKNOWN_VERSION);
58-
}
59-
60-
61-
public static String getCurrentVersion() {
62-
return VERSION;
63-
}
64-
65-
public static String getPmdCoreMinVersion() {
66-
return PMD_CORE_MIN_VERSION;
67-
}
68-
69-
private static Optional<String> readProperty(String resourcePath, String key) {
70-
try (InputStream stream = PMDVersion.class.getResourceAsStream(resourcePath)) {
71-
if (stream != null) {
72-
final Properties properties = new Properties();
73-
properties.load(stream);
74-
return Optional.ofNullable(properties.getProperty(key));
75-
}
76-
} catch (final IOException ignored) {
77-
// fallthrough
78-
}
79-
return Optional.empty();
80-
}
81-
8238
private long initStartTimeMillis;
8339
private DesignerRoot designerRoot;
8440

@@ -101,7 +57,7 @@ public void stop() {
10157
public void start(Stage stage, DesignerRoot owner) throws IOException {
10258
this.designerRoot = owner;
10359

104-
stage.setTitle("PMD Rule Designer (v " + Designer.VERSION + ')');
60+
stage.setTitle("PMD Rule Designer (v " + DesignerVersion.getCurrentVersion() + ')');
10561
setIcons(stage);
10662

10763
Logger.getLogger(Attribute.class.getName()).setLevel(Level.OFF);
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3+
*/
4+
5+
package net.sourceforge.pmd.util.fxdesigner;
6+
7+
import java.io.IOException;
8+
import java.io.InputStream;
9+
import java.util.Optional;
10+
import java.util.Properties;
11+
12+
import net.sourceforge.pmd.PMDVersion;
13+
import net.sourceforge.pmd.util.fxdesigner.util.ResourceUtil;
14+
15+
/**
16+
* Stores the current Designer and PMD version and provides utility methods around them.
17+
*/
18+
public class DesignerVersion {
19+
20+
/**
21+
* Constant that contains always the current version of the designer.
22+
*/
23+
private static final String VERSION;
24+
private static final String PMD_CORE_MIN_VERSION;
25+
private static final String UNKNOWN_VERSION = "unknown";
26+
27+
/**
28+
* Determines the version from maven's generated pom.properties file.
29+
*/
30+
static {
31+
VERSION = readProperty("/META-INF/maven/net.sourceforge.pmd/pmd-ui/pom.properties", "version").orElse(UNKNOWN_VERSION);
32+
PMD_CORE_MIN_VERSION = readProperty(ResourceUtil.resolveResource("designer.properties"), "pmd.core.version").orElse(UNKNOWN_VERSION);
33+
}
34+
35+
private DesignerVersion() {
36+
throw new AssertionError("Can't instantiate a utility class.");
37+
}
38+
39+
public static String getCurrentVersion() {
40+
return VERSION;
41+
}
42+
43+
public static String getPmdCoreMinVersion() {
44+
return PMD_CORE_MIN_VERSION;
45+
}
46+
47+
private static Optional<String> readProperty(String resourcePath, String key) {
48+
try (InputStream stream = PMDVersion.class.getResourceAsStream(resourcePath)) {
49+
if (stream != null) {
50+
final Properties properties = new Properties();
51+
properties.load(stream);
52+
return Optional.ofNullable(properties.getProperty(key));
53+
}
54+
} catch (final IOException ignored) {
55+
// fallthrough
56+
}
57+
return Optional.empty();
58+
}
59+
}

src/main/java/net/sourceforge/pmd/util/fxdesigner/app/services/GlobalDiskManagerImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import java.util.List;
1212
import java.util.stream.Collectors;
1313

14-
import net.sourceforge.pmd.util.fxdesigner.Designer;
14+
import net.sourceforge.pmd.util.fxdesigner.DesignerVersion;
1515
import net.sourceforge.pmd.util.fxdesigner.app.ApplicationComponent;
1616
import net.sourceforge.pmd.util.fxdesigner.app.DesignerRoot;
1717

@@ -33,7 +33,7 @@ public GlobalDiskManagerImpl(DesignerRoot root, Path settingsDirectory) {
3333
this.settingsDirectory = settingsDirectory;
3434

3535

36-
Path curVersionStamp = settingsDirectory.resolve("version-" + Designer.getCurrentVersion());
36+
Path curVersionStamp = settingsDirectory.resolve("version-" + DesignerVersion.getCurrentVersion());
3737

3838

3939
List<Path> diskVersionStamps = getDiskVersionStamps();
@@ -62,7 +62,7 @@ private List<Path> getDiskVersionStamps() {
6262
.filter(it -> !Files.isDirectory(it))
6363
.filter(it -> it.getFileName().toString().startsWith(STAMP_PREFIX))
6464
.collect(Collectors.toList());
65-
} catch (IOException e) {
65+
} catch (IOException ignored) {
6666
return Collections.emptyList();
6767
}
6868
}

src/main/java/net/sourceforge/pmd/util/fxdesigner/app/services/OnDiskPersistenceManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import java.nio.file.Path;
1010
import java.util.concurrent.CompletableFuture;
1111

12-
import net.sourceforge.pmd.util.fxdesigner.Designer;
12+
import net.sourceforge.pmd.util.fxdesigner.DesignerVersion;
1313
import net.sourceforge.pmd.util.fxdesigner.app.DesignerRoot;
1414
import net.sourceforge.pmd.util.fxdesigner.util.beans.SettingsOwner;
1515
import net.sourceforge.pmd.util.fxdesigner.util.beans.SettingsPersistenceUtil;
@@ -85,7 +85,7 @@ private void commitAppState() throws IOException, InterruptedException {
8585
process.start().waitFor();
8686
process.command("git", "add", output.toString());
8787
process.start().waitFor();
88-
process.command("git", "commit", "-m", "\"On version " + Designer.getCurrentVersion() + "\"");
88+
process.command("git", "commit", "-m", "\"On version " + DesignerVersion.getCurrentVersion() + "\"");
8989
process.start().waitFor();
9090

9191
}

src/main/java/net/sourceforge/pmd/util/fxdesigner/popups/SimplePopups.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@
1919
import org.reactfx.EventSource;
2020
import org.reactfx.EventStream;
2121

22-
import net.sourceforge.pmd.PMDVersion;
23-
import net.sourceforge.pmd.lang.Language;
24-
import net.sourceforge.pmd.util.fxdesigner.Designer;
25-
import net.sourceforge.pmd.util.fxdesigner.app.DesignerRoot;
26-
import net.sourceforge.pmd.util.fxdesigner.util.AuxLanguageRegistry;
27-
import net.sourceforge.pmd.util.fxdesigner.util.DesignerUtil;
28-
2922
import javafx.animation.Animation;
3023
import javafx.animation.Interpolator;
3124
import javafx.animation.Transition;
@@ -39,6 +32,12 @@
3932
import javafx.scene.layout.StackPane;
4033
import javafx.stage.Popup;
4134
import javafx.util.Duration;
35+
import net.sourceforge.pmd.PMDVersion;
36+
import net.sourceforge.pmd.lang.Language;
37+
import net.sourceforge.pmd.util.fxdesigner.DesignerVersion;
38+
import net.sourceforge.pmd.util.fxdesigner.app.DesignerRoot;
39+
import net.sourceforge.pmd.util.fxdesigner.util.AuxLanguageRegistry;
40+
import net.sourceforge.pmd.util.fxdesigner.util.DesignerUtil;
4241

4342

4443
/**
@@ -213,8 +212,8 @@ public static void showAboutPopup(DesignerRoot root) {
213212

214213
String sb =
215214
"PMD core version:\t\t\t" + PMDVersion.VERSION + "\n"
216-
+ "Designer version:\t\t\t" + Designer.getCurrentVersion()
217-
+ " (supports PMD core " + Designer.getPmdCoreMinVersion() + ")\n"
215+
+ "Designer version:\t\t\t" + DesignerVersion.getCurrentVersion()
216+
+ " (supports PMD core " + DesignerVersion.getPmdCoreMinVersion() + ")\n"
218217
+ "Designer settings dir:\t\t"
219218
+ root.getService(DesignerRoot.DISK_MANAGER).getSettingsDirectory() + "\n"
220219
+ "Available languages:\t\t"

0 commit comments

Comments
 (0)