Skip to content
This repository was archived by the owner on Apr 10, 2021. It is now read-only.

Commit 0e63a6b

Browse files
authored
Merge pull request #116 from emabrey/master
Closes: #115
2 parents be8f652 + c917374 commit 0e63a6b

File tree

3 files changed

+99
-56
lines changed

3 files changed

+99
-56
lines changed

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ sudo: false
55
language: java
66

77
jdk:
8+
- openjdk8
89
- oraclejdk8
9-
10+
- oraclejdk9
11+
# - oraclejdk10
12+
# - oraclejdk11
13+
1014
#Cache downloaded Maven artifacts between builds
1115
cache:
1216
directories:

pom.xml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
<nbm.signing.keystorealias></nbm.signing.keystorealias>
1818
<nbm.signing.keystorepassword></nbm.signing.keystorepassword>
1919
<nbm.skip>false</nbm.skip>
20+
21+
<!-- Set to a custom path of some local JDK to use it to execite nbm:run-ide -->
22+
<nbm.jdkHome>${env.JAVA_HOME}</nbm.jdkHome>
2023
</properties>
2124

2225
<repositories>
@@ -59,6 +62,12 @@
5962
<artifactId>org-netbeans-api-annotations-common</artifactId>
6063
<version>${netbeans.api.version}</version>
6164
</dependency>
65+
66+
<dependency>
67+
<groupId>org.netbeans.api</groupId>
68+
<artifactId>org-netbeans-modules-java-platform</artifactId>
69+
<version>${netbeans.api.version}</version>
70+
</dependency>
6271

6372
<!-- BaseDocument & Co. -->
6473
<dependency>
@@ -254,7 +263,7 @@
254263
<dependency>
255264
<groupId>org.netbeans.api</groupId>
256265
<artifactId>org-netbeans-modules-editor-util</artifactId>
257-
<version>RELEASE82</version>
266+
<version>${netbeans.api.version}</version>
258267
</dependency>
259268
</dependencies>
260269

@@ -278,6 +287,8 @@
278287
<publicPackages>
279288
<publicPackage>com.welovecoding.netbeans.plugin.editorconfig</publicPackage>
280289
</publicPackages>
290+
<additionalArguments>--jdkhome ${nbm.jdkHome}</additionalArguments>
291+
<debugAdditionalArguments></debugAdditionalArguments>
281292
</configuration>
282293
</plugin>
283294
<plugin>
@@ -300,6 +311,7 @@
300311
</execution>
301312
</executions>
302313
</plugin>
314+
303315
<plugin>
304316
<groupId>org.apache.maven.plugins</groupId>
305317
<artifactId>maven-compiler-plugin</artifactId>
@@ -309,6 +321,7 @@
309321
<target>1.7</target>
310322
<showWarnings>true</showWarnings>
311323
<optimize>true</optimize>
324+
<showDeprecation>true</showDeprecation>
312325
</configuration>
313326
</plugin>
314327
<plugin>

src/main/java/com/welovecoding/nbeditorconfig/listener/Installer.java

Lines changed: 80 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,79 +2,105 @@
22

33
import java.awt.event.ActionEvent;
44
import java.awt.event.ActionListener;
5+
import java.util.logging.Level;
6+
import java.util.logging.Logger;
7+
import javax.swing.Icon;
58
import javax.swing.plaf.metal.MetalIconFactory;
9+
import org.netbeans.api.java.platform.JavaPlatform;
10+
import org.netbeans.api.java.platform.JavaPlatformManager;
11+
import org.netbeans.api.java.platform.Specification;
612
import org.openide.DialogDisplayer;
713
import org.openide.NotifyDescriptor;
814
import org.openide.awt.NotificationDisplayer;
915
import org.openide.modules.ModuleInstall;
16+
import org.openide.modules.SpecificationVersion;
1017
import org.openide.util.NbBundle;
1118

1219
public class Installer extends ModuleInstall {
20+
21+
/**
22+
* Class Logger
23+
*/
24+
private static final Logger INSTALLER_LOGGER = Logger.getLogger(Installer.class.getName());
1325

14-
private static final int MIN_JAVA_VERSION = 8;
26+
/**
27+
* A representation of the minimum required version of Java as a
28+
* {@link SpecificationVersion} compatible "Dewey-decimal version".
29+
*/
30+
private static final String MIN_JAVA_VERSION = "1.7.0";
1531

1632
@Override
17-
public void restored() {
18-
if (detectOldJava()) {
19-
final String title = NbBundle.getMessage(Installer.class, "wlc-nbeditorconfig-version-error-title");
20-
final String message = NbBundle.getMessage(Installer.class, "wlc-nbeditorconfig-version-error-message");
21-
final int messageType = NotifyDescriptor.ERROR_MESSAGE;
22-
23-
ActionListener actionListener = new ActionListener() {
24-
@Override
25-
public void actionPerformed(ActionEvent e) {
26-
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(message, messageType));
27-
}
28-
};
29-
NotificationDisplayer.getDefault().notify(title, new MetalIconFactory.FileIcon16(), message, actionListener);
33+
public void restored() {
34+
if (isJavaVersionIncompatiable()) {
35+
registerIncompatabilityNotification();
3036
}
3137
}
3238

33-
private boolean detectOldJava() {
34-
return JavaVersion.getMinor() < MIN_JAVA_VERSION;
35-
}
39+
/**
40+
* Displays a notification in the default notification UI containing
41+
* information on the plugin's incompatibility with the current IDE's version
42+
* of the JVM
43+
*/
44+
private static void registerIncompatabilityNotification() {
3645

37-
private static class JavaVersion {
46+
//These are the title, message and icon displayed in the notification area and within popup if user interacts with notification
47+
final String incompatTitle = NbBundle.getMessage(Installer.class, "wlc-nbeditorconfig-version-error-title");
48+
final String incompatMessage = NbBundle.getMessage(Installer.class, "wlc-nbeditorconfig-version-error-message");
49+
final Icon incompatIcon = new MetalIconFactory.FileIcon16();
50+
51+
INSTALLER_LOGGER.log(Level.SEVERE, incompatMessage);
3852

39-
private JavaVersion() {
40-
}
41-
42-
public int getMajor() {
43-
try {
44-
return Integer.parseInt(getMappedVersion()[0]);
45-
} catch (Exception ex) {
46-
return 0;
53+
final ActionListener notificationInteractionListener = new ActionListener() {
54+
@Override
55+
public void actionPerformed(ActionEvent e) {
56+
NotifyDescriptor.Message pluginIncompatiableMessage = new NotifyDescriptor.Message(incompatMessage, NotifyDescriptor.ERROR_MESSAGE);
57+
DialogDisplayer.getDefault().notify(pluginIncompatiableMessage);
4758
}
48-
}
59+
};
4960

50-
public static int getMinor() {
51-
try {
52-
return Integer.parseInt(getMappedVersion()[1]);
53-
} catch (Exception ex) {
54-
return 0;
55-
}
56-
}
61+
NotificationDisplayer.getDefault().notify(incompatTitle, incompatIcon, incompatMessage, notificationInteractionListener);
5762

58-
/**
59-
* Example: Patch version is "0_31" in Java 1.8.0_31
60-
*
61-
* @return
62-
*/
63-
public static String getPatch() {
64-
try {
65-
return getMappedVersion()[2];
66-
} catch (Exception ex) {
67-
return "";
68-
}
69-
}
63+
}
7064

71-
private static String[] getMappedVersion() throws Exception {
72-
String[] splittedVersion = System.getProperty("java.version").split("\\."); // NOI18N
73-
if (splittedVersion.length >= 3) {
74-
return splittedVersion;
75-
} else {
76-
throw new RuntimeException("Could not determine Java version");
77-
}
78-
}
65+
/**
66+
* Evaluates the compatibility of the current JVM running the IDE against
67+
* {@link #MIN_JAVA_VERSION}.
68+
*
69+
* @return True if the JVM running the IDE is not compatible with this
70+
* plugin.
71+
*/
72+
private boolean isJavaVersionIncompatiable() {
73+
SpecificationVersion javaVersion = getJavaPlatformVersion();
74+
75+
INSTALLER_LOGGER.log(Level.FINE, "Found Java version: " + javaVersion);
76+
INSTALLER_LOGGER.log(Level.FINE, "Expected Java version: " + MIN_JAVA_VERSION);
77+
78+
return javaVersion.compareTo(getMinimumRequiredJavaVersion()) < 0;
79+
}
80+
81+
/**
82+
* Convenience/readability method for generating a
83+
* {@link SpecificationVersion} containing the version information equivalent
84+
* to {@link #MIN_JAVA_VERSION}.
85+
*
86+
* @return
87+
*/
88+
private static SpecificationVersion getMinimumRequiredJavaVersion() {
89+
return new SpecificationVersion(MIN_JAVA_VERSION);
90+
}
91+
92+
/**
93+
* Determines the version of the Java environment the IDE is running within
94+
* utilizing {@link JavaPlatform}.
95+
*
96+
* @return A {@link SpecificationVersion} instance containing the version
97+
* information of the IDE JVM using a "Dewey-decimal format".
98+
*/
99+
private static SpecificationVersion getJavaPlatformVersion() {
100+
JavaPlatformManager idePlatformManager = JavaPlatformManager.getDefault();
101+
JavaPlatform idePlatform = idePlatformManager.getDefaultPlatform();
102+
Specification idePlatformSpec = idePlatform.getSpecification();
103+
104+
return idePlatformSpec.getVersion();
79105
}
80106
}

0 commit comments

Comments
 (0)