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.apache.cocoon.jcr.JackrabbitRepository.java
public void configure(Configuration config) throws ConfigurationException { super.configure(config); // Java VM must be at least 1.4 if (SystemUtils.isJavaVersionAtLeast(140) == false) { String message = "The jcr block needs at least a java VM version 1.4 to run properly. Please update to a newer java or exclude the jcr block from your Cocoon block configuration."; getLogger().error(message);/*from w w w . java 2s . c om*/ throw new ConfigurationException(message); } String homeURI = config.getChild("home").getAttribute("src"); String homePath; String configURI = config.getChild("configuration").getAttribute("src"); // having to release sources is a major PITA... SourceResolver resolver = null; try { resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE); // Ensure home uri is a file and absolutize it Source homeSrc = resolver.resolveURI(homeURI); try { if (!(homeSrc instanceof FileSource)) { throw new ConfigurationException("Home path '" + homeURI + "' should map to a file, at " + config.getChild("home").getLocation()); } homePath = ((FileSource) homeSrc).getFile().getAbsolutePath(); } finally { resolver.release(homeSrc); } // Load repository configuration Source configSrc = resolver.resolveURI(configURI); RepositoryConfig repoConfig; try { InputSource is = SourceUtil.getInputSource(configSrc); repoConfig = RepositoryConfig.create(is, homePath); } finally { resolver.release(configSrc); } // And create the repository this.delegate = RepositoryImpl.create(repoConfig); } catch (ConfigurationException ce) { throw ce; } catch (Exception e) { throw new ConfigurationException("Cannot access configuration information at " + config.getLocation(), e); } finally { this.manager.release(resolver); } }
From source file:org.apache.maven.plugin.javadoc.FixJavadocMojoTest.java
/** * @throws Exception if any// www. j a v a 2 s . c om */ public void testFixJdk5() throws Exception { if (!SystemUtils.isJavaVersionAtLeast(1.5f)) { getContainer().getLogger().warn("JDK 5.0 or more is required to run fix for '" + getClass().getName() + "#" + getName() + "()'."); return; } File testPomBasedir = new File(getBasedir(), "target/test/unit/fix-jdk5-test"); executeMojoAndTest(testPomBasedir, new String[] { "ClassWithJavadoc.java", "ClassWithNoJavadoc.java", "InterfaceWithJavadoc.java", "InterfaceWithNoJavadoc.java", "SubClassWithJavadoc.java" }); }
From source file:org.apache.maven.plugin.javadoc.FixJavadocMojoTest.java
/** * @throws Exception if any/* w w w .j a va 2 s.c o m*/ */ public void testFixJdk6() throws Exception { if (!SystemUtils.isJavaVersionAtLeast(1.6f)) { getContainer().getLogger().warn("JDK 6.0 or more is required to run fix for '" + getClass().getName() + "#" + getName() + "()'."); return; } File testPomBasedir = new File(getBasedir(), "target/test/unit/fix-jdk6-test"); executeMojoAndTest(testPomBasedir, new String[] { "ClassWithJavadoc.java", "InterfaceWithJavadoc.java" }); }
From source file:org.apache.maven.plugin.javadoc.FixJavadocMojoTest.java
/** * @throws Throwable if any/*ww w . ja va 2 s .co m*/ */ public void testJavadocCommentJdk5() throws Throwable { if (!SystemUtils.isJavaVersionAtLeast(1.5f)) { getContainer().getLogger().warn("JDK 5.0 or more is required to run fix for '" + getClass().getName() + "#" + getName() + "()'."); return; } String content = "/**" + EOL + " * Dummy Class." + EOL + " */" + EOL + "public class DummyClass" + EOL + "{" + EOL + " /**" + EOL + " * Dummy method." + EOL + " *" + EOL + " * @param <K> The Key type for the method" + EOL + " * @param <V> The Value type for the method" + EOL + " * @param name The name." + EOL + " * @return A map configured." + EOL + " */" + EOL + " public <K, V> java.util.Map<K, V> dummyMethod( String name )" + EOL + " {" + EOL + " return null;" + EOL + " }" + EOL + "}"; JavaDocBuilder builder = new JavaDocBuilder(); builder.setEncoding("UTF-8"); builder.addSource(new StringReader(content)); JavaClass[] classes = builder.getClasses(); JavaClass clazz = classes[0]; JavaMethod javaMethod = clazz.getMethods()[0]; String methodJavadoc = (String) PrivateAccessor.invoke(AbstractFixJavadocMojo.class, "getJavadocComment", new Class[] { String.class, AbstractJavaEntity.class }, new Object[] { content, javaMethod }); assertEquals(" * Dummy method." + EOL + " *", methodJavadoc); assertEquals(4, javaMethod.getTags().length); AbstractFixJavadocMojo mojoInstance = new FixJavadocMojo(); setVariableValueToObject(mojoInstance, "fixTagsSplitted", new String[] { "all" }); DocletTag tag = javaMethod.getTags()[0]; String tagJavadoc = (String) PrivateAccessor.invoke(mojoInstance, "getJavadocComment", new Class[] { String.class, AbstractInheritableJavaEntity.class, DocletTag.class }, new Object[] { content, javaMethod, tag }); assertEquals(" * @param <K> The Key type for the method", tagJavadoc); tag = javaMethod.getTags()[1]; tagJavadoc = (String) PrivateAccessor.invoke(mojoInstance, "getJavadocComment", new Class[] { String.class, AbstractInheritableJavaEntity.class, DocletTag.class }, new Object[] { content, javaMethod, tag }); assertEquals(" * @param <V> The Value type for the method", tagJavadoc); tag = javaMethod.getTags()[2]; tagJavadoc = (String) PrivateAccessor.invoke(mojoInstance, "getJavadocComment", new Class[] { String.class, AbstractInheritableJavaEntity.class, DocletTag.class }, new Object[] { content, javaMethod, tag }); assertEquals(" * @param name The name.", tagJavadoc); tag = javaMethod.getTags()[3]; tagJavadoc = (String) PrivateAccessor.invoke(mojoInstance, "getJavadocComment", new Class[] { String.class, AbstractInheritableJavaEntity.class, DocletTag.class }, new Object[] { content, javaMethod, tag }); assertEquals(" * @return A map configured.", tagJavadoc); }
From source file:org.apache.maven.plugin.javadoc.JavadocReportTest.java
/** * Method to test the jdk5 javadoc//from w w w . jav a 2 s. co m * * @throws Exception if any */ public void testJdk5() throws Exception { if (!SystemUtils.isJavaVersionAtLeast(1.5f)) { getContainer().getLogger().warn("JDK 5.0 or more is required to run javadoc for '" + getClass().getName() + "#" + getName() + "()'."); return; } File testPom = new File(unit, "jdk5-test/jdk5-test-plugin-config.xml"); JavadocReport mojo = (JavadocReport) lookupMojo("javadoc", testPom); mojo.execute(); File apidocs = new File(getBasedir(), "target/test/unit/jdk5-test/target/site/apidocs"); File index = new File(apidocs, "index.html"); assertTrue(FileUtils.fileExists(index.getAbsolutePath())); File overviewSummary = new File(apidocs, "overview-summary.html"); assertTrue(overviewSummary.exists()); String content = readFile(overviewSummary); assertTrue(content.contains("<b>Test the package-info</b>")); File packageSummary = new File(apidocs, "jdk5/test/package-summary.html"); assertTrue(packageSummary.exists()); content = readFile(packageSummary); assertTrue(content.contains("<b>Test the package-info</b>")); }
From source file:org.apache.maven.plugin.javadoc.JavadocReportTest.java
/** * Method to test the jdk6 javadoc//from www . j a v a 2 s . c o m * * @throws Exception if any */ public void testJdk6() throws Exception { if (!SystemUtils.isJavaVersionAtLeast(1.6f)) { getContainer().getLogger().warn("JDK 6.0 or more is required to run javadoc for '" + getClass().getName() + "#" + getName() + "()'."); return; } File testPom = new File(unit, "jdk6-test/jdk6-test-plugin-config.xml"); JavadocReport mojo = (JavadocReport) lookupMojo("javadoc", testPom); mojo.execute(); File apidocs = new File(getBasedir(), "target/test/unit/jdk6-test/target/site/apidocs"); assertTrue(new File(apidocs, "index.html").exists()); File overviewSummary = new File(apidocs, "overview-summary.html"); assertTrue(overviewSummary.exists()); String content = readFile(overviewSummary); assertTrue(content.contains("Top - Copyright © All rights reserved.")); assertTrue(content.contains("Header - Copyright © All rights reserved.")); assertTrue(content.contains("Footer - Copyright © All rights reserved.")); File packageSummary = new File(apidocs, "jdk6/test/package-summary.html"); assertTrue(packageSummary.exists()); content = readFile(packageSummary); assertTrue(content.contains("Top - Copyright © All rights reserved.")); assertTrue(content.contains("Header - Copyright © All rights reserved.")); assertTrue(content.contains("Footer - Copyright © All rights reserved.")); }
From source file:org.codehaus.gmaven.plugin.ProviderMojoSupport.java
protected String detectCompatibleProvider() { String provider;// w w w . ja v a 2 s. co m if (SystemUtils.isJavaVersionAtLeast(1.5f)) { provider = "1.6"; } else { provider = "1.5"; } log.debug("Detected compatible provider: {}", provider); return provider; }
From source file:org.eclipse.wb.internal.core.nls.bundle.StandardPropertiesAccessor.java
private static void load0(Properties properties, InputStream is, String charset) throws Exception { if (charset.equals("UTF-8") && SystemUtils.isJavaVersionAtLeast(1.6f)) { Method loadMethod = Properties.class.getMethod("load", Reader.class); Reader reader = new InputStreamReader(is, charset); loadMethod.invoke(properties, reader); } else {// ww w . ja va2 s.c om properties.load(is); } }
From source file:org.eclipse.wb.internal.core.nls.bundle.StandardPropertiesAccessor.java
private static void store0(Properties properties, OutputStream os, String charset, String comments) throws Exception { if (charset.equals("UTF-8") && SystemUtils.isJavaVersionAtLeast(1.6f)) { Method loadMethod = Properties.class.getMethod("store", Writer.class, String.class); Writer reader = new OutputStreamWriter(os, charset); loadMethod.invoke(properties, reader, comments); } else {/*from ww w .j a v a 2 s. c om*/ properties.store(os, comments); } }
From source file:org.jamwiki.servlets.SetupServlet.java
/** * This method handles the request after its parent class receives control. * // w ww. j av a2 s . c o m * @param request * - Standard HttpServletRequest object. * @param response * - Standard HttpServletResponse object. * @return A <code>ModelAndView</code> object to be handled by the rest of the * Spring framework. */ protected ModelAndView handleJAMWikiRequest(HttpServletRequest request, HttpServletResponse response, ModelAndView next, WikiPageInfo pageInfo) throws Exception { if (!WikiUtil.isFirstUse()) { throw new WikiException(new WikiMessage("setup.error.notrequired")); } String function = (request.getParameter("function") == null) ? request.getParameter("override") : request.getParameter("function"); if (function == null) { function = ""; } try { if (!SystemUtils.isJavaVersionAtLeast(MINIMUM_JDK_VERSION)) { throw new WikiException(new WikiMessage("setup.error.jdk", Integer.valueOf(MINIMUM_JDK_VERSION).toString(), System.getProperty("java.version"))); } if (!StringUtils.isBlank(function) && initialize(request, next, pageInfo)) { ServletUtil.redirect(next, WikiBase.DEFAULT_VWIKI, Environment.getValue(Environment.PROP_BASE_DEFAULT_TOPIC)); } else { view(request, next, pageInfo); } } catch (Exception e) { handleSetupError(request, next, pageInfo, e); } return next; }