List of usage examples for org.apache.commons.lang SystemUtils isJavaVersionAtLeast
public static boolean isJavaVersionAtLeast(int requiredVersion)
Is the Java version at least the requested version.
Example input:
120
to test for JDK 1.2 or greater131
to test for JDK 1.3.1 or greaterFrom source file:org.zaproxy.zap.extension.ascanrules.SourceCodeDisclosureWEBINF.java
@Override public void init() { // Does not work with Java 9+ // https://github.com/zaproxy/zaproxy/issues/4038 if (SystemUtils.isJavaVersionAtLeast(1.9f)) { getParent().pluginSkipped(this, Constant.messages.getString("ascanrules.sourcecodedisclosurewebinf.skipJava9")); }/*from w w w.ja va 2 s. c om*/ }
From source file:phex.Main.java
/** * // ww w.j a v a 2 s . c o m */ private static void validateJavaVersion() { if (SystemUtils.isJavaVersionAtLeast(1.5f)) { return; } JFrame frame = new JFrame("Wrong Java Version"); frame.setSize(new Dimension(0, 0)); frame.setVisible(true); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension winSize = frame.getSize(); Rectangle rect = new Rectangle((screenSize.width - winSize.width) / 2, (screenSize.height - winSize.height) / 2, winSize.width, winSize.height); frame.setBounds(rect); JOptionPane.showMessageDialog(frame, "Please use a newer Java VM.\n" + "Phex requires at least Java 1.5.0. You are using Java " + SystemUtils.JAVA_VERSION + "\n" + "To get the latest Java release go to http://java.com.", "Wrong Java Version", JOptionPane.WARNING_MESSAGE); System.exit(1); }
From source file:sk.baka.webvm.analyzer.Deadlock.java
/** * Checks that the threads are running and no exception was thrown. */// w w w .j a v a 2 s . c o m @Test public void checkThreads() { assertNull("An exception was thrown while forming a deadlock: " + t, t); assertTrue("Both threads must be alive as they are deadlocked", t1.isAlive()); assertTrue("Both threads must be alive as they are deadlocked", t2.isAlive()); // sanity-check for JVM to report correct values final long ids[] = ProblemAnalyzer.findDeadlockedThreads(ManagementFactory.getThreadMXBean()); // this assumption fails on 1.5 as it does not support finding deadlocks in a ReentrantLock. // we could form a deadlock using the synchronized keyword but there is no way to interrupt // wait in the synchronized block thus the threads will never end - this will interfere with other tests. // Just skip the tests on 1.5. if (SystemUtils.isJavaVersionAtLeast(160)) { assertTrue("Two threads are expected to be deadlocked, but the following was found: " + (ids == null ? "null" : Arrays.toString(ids)), ids != null && ids.length == 2); } }
From source file:sk.baka.webvm.analyzer.HistorySamplerTest.java
/** * Test of getProblemHistory method, of class HistorySampler. * @throws Exception //from w w w . j a v a2s .co m */ @Test public void testGetProblemHistory() throws Exception { // Skip this test on java 5.x as Java 1.5.x does not report deadlock in Locks assumeTrue(SystemUtils.isJavaVersionAtLeast(160)); // na Windows nejak thready startuju pomalsie alebo co, proste test nefunguje assumeTrue(OS.isLinux()); final HistorySampler hs = new HistorySampler(new SamplerConfig(100, Integer.MAX_VALUE, Integer.MAX_VALUE), new SamplerConfig(100, 75, 0), new ProblemAnalyzer(new Config(), new MemoryJMXStrategy()), null); hs.start(); try { Thread.sleep(100); List<List<ProblemReport>> history = hs.getProblemHistory(); assertEquals(new ArrayList<Object>(), history); final Deadlock d = new Deadlock(); d.simulate(); try { d.checkThreads(); Thread.sleep(200); history = hs.getProblemHistory(); assertEquals(1, history.size()); } finally { d.cancel(); } Thread.sleep(200); history = hs.getProblemHistory(); assertEquals(2, history.size()); } finally { hs.stop(); } }
From source file:sk.baka.webvm.analyzer.ProblemAnalyzerTest.java
/** * Test of getDeadlockReport method, of class ProblemAnalyzer. * @throws Exception/*from ww w.j a v a 2s . c o m*/ */ @Test public void testGetDeadlockReport() throws Exception { if (!SystemUtils.isJavaVersionAtLeast(160)) { System.out.println( "Skipping ProblemAnalyzerTest.testGetDeadlockReport() as Java 1.5.x does not report deadlock in Locks"); return; } final Deadlock d = new Deadlock(); d.simulate(); try { d.checkThreads(); final ProblemReport pr = ProblemAnalyzer.getDeadlockReport(); assertTrue(pr.isProblem); assertTrue(pr.diagnosis.contains("deadlock1")); assertTrue(pr.diagnosis.contains("deadlock2")); // check for the stack-trace presence assertTrue(pr.diagnosis.contains(Deadlock.class.getName())); assertTrue(pr.diagnosis.contains("run(")); } finally { d.cancel(); } }
From source file:VASSAL.tools.image.ImageIOImageLoaderTest.java
@Test(expected = BrokenImageException.class) public void testLoadLCMS_Error() throws IOException { // this appears to be fixed in Java >= 1.7 if (SystemUtils.isJavaVersionAtLeast(1.7f)) { throw new BrokenImageException("bogus"); }/* www . j av a 2s . co m*/ final String afile = "test/VASSAL/tools/image/09.jpg"; final ImageTypeConverter mconv = new MemoryImageTypeConverter(); final ImageIOImageLoader loader = new ImageIOImageLoader(mconv); final BufferedImage actual = read(loader, afile); }
From source file:VASSAL.tools.image.ImageIOImageLoaderTest.java
@Test(expected = BrokenImageException.class) public void testSizeLCMS_Error() throws IOException { // this appears to be fixed in Java >= 1.7 if (SystemUtils.isJavaVersionAtLeast(1.7f)) { throw new BrokenImageException("bogus"); }//from ww w. ja v a 2 s. c om final String afile = "test/VASSAL/tools/image/09.jpg"; final ImageTypeConverter mconv = new MemoryImageTypeConverter(); final ImageIOImageLoader loader = new ImageIOImageLoader(mconv); final Dimension ad = size(loader, afile); }