List of usage examples for org.apache.commons.lang SystemUtils JAVA_VERSION_TRIMMED
String JAVA_VERSION_TRIMMED
To view the source code for org.apache.commons.lang SystemUtils JAVA_VERSION_TRIMMED.
Click Source Link
Gets the Java version as a String
trimming leading letters.
The field will return null
if #JAVA_VERSION is null
.
From source file:org.apache.maven.plugins.enforcer.DisplayInfoMojo.java
/** * Entry point to the mojo//w w w . j av a2 s .c o m */ public void execute() throws MojoExecutionException { try { EnforcerExpressionEvaluator evaluator = new EnforcerExpressionEvaluator(session, translator, project); DefaultEnforcementRuleHelper helper = new DefaultEnforcementRuleHelper(session, evaluator, getLog(), container); RuntimeInformation rti = (RuntimeInformation) helper.getComponent(RuntimeInformation.class); getLog().info("Maven Version: " + rti.getApplicationVersion()); getLog().info("JDK Version: " + SystemUtils.JAVA_VERSION + " normalized as: " + RequireJavaVersion.normalizeJDKVersion(SystemUtils.JAVA_VERSION_TRIMMED)); RequireOS os = new RequireOS(); os.displayOSInfo(getLog(), true); } catch (ComponentLookupException e) { getLog().warn("Unable to Lookup component: " + e.getLocalizedMessage()); } }
From source file:org.apache.maven.plugins.enforcer.RequireJavaVersion.java
public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException { String java_version = SystemUtils.JAVA_VERSION_TRIMMED; Log log = helper.getLog();//from w w w. j a v a 2 s. c o m log.debug("Detected Java String: " + java_version); java_version = normalizeJDKVersion(java_version); log.debug("Normalized Java String: " + java_version); ArtifactVersion detectedJdkVersion = new DefaultArtifactVersion(java_version); log.debug("Parsed Version: Major: " + detectedJdkVersion.getMajorVersion() + " Minor: " + detectedJdkVersion.getMinorVersion() + " Incremental: " + detectedJdkVersion.getIncrementalVersion() + " Build: " + detectedJdkVersion.getBuildNumber() + " Qualifier: " + detectedJdkVersion.getQualifier()); enforceVersion(helper.getLog(), "JDK", version, detectedJdkVersion); }
From source file:org.apache.maven.plugins.enforcer.TestMavenVersion.java
/** * Test rule.//from w ww. j a v a2 s . c om * * @throws EnforcerRuleException the enforcer rule exception */ public void testRule() throws EnforcerRuleException { RequireMavenVersion rule = new RequireMavenVersion(); rule.setVersion("2.0.5"); EnforcerRuleHelper helper = EnforcerTestUtils.getHelper(); // test the singular version rule.execute(helper); // exclude this version rule.setVersion("(2.0.5"); try { rule.execute(helper); fail("Expected an exception."); } catch (EnforcerRuleException e) { // expected to catch this. } // this shouldn't crash rule.setVersion(SystemUtils.JAVA_VERSION_TRIMMED); rule.execute(helper); }
From source file:org.apache.maven.plugins.enforcer.TestRequireJavaVersion.java
/** * Test rule./*from w w w. java 2 s. c om*/ * * @throws EnforcerRuleException the enforcer rule exception */ public void testRule() throws EnforcerRuleException { String thisVersion = RequireJavaVersion.normalizeJDKVersion(SystemUtils.JAVA_VERSION_TRIMMED); RequireJavaVersion rule = new RequireJavaVersion(); rule.setVersion(thisVersion); EnforcerRuleHelper helper = EnforcerTestUtils.getHelper(); // test the singular version rule.execute(helper); // exclude this version rule.setVersion("(" + thisVersion); try { rule.execute(helper); fail("Expected an exception."); } catch (EnforcerRuleException e) { // expected to catch this. } // this shouldn't crash rule.setVersion(SystemUtils.JAVA_VERSION_TRIMMED); rule.execute(helper); }
From source file:org.sonar.core.platform.PluginLoader.java
/** * Instantiates collection of {@link org.sonar.api.Plugin} according to given metadata and classloaders * * @return the instances grouped by plugin key * @throws IllegalStateException if at least one plugin can't be correctly loaded */// www . j a v a 2 s.c om @VisibleForTesting Map<String, Plugin> instantiatePluginClasses(Map<PluginClassLoaderDef, ClassLoader> classloaders) { // instantiate plugins Map<String, Plugin> instancesByPluginKey = new HashMap<>(); for (Map.Entry<PluginClassLoaderDef, ClassLoader> entry : classloaders.entrySet()) { PluginClassLoaderDef def = entry.getKey(); ClassLoader classLoader = entry.getValue(); // the same classloader can be used by multiple plugins for (Map.Entry<String, String> mainClassEntry : def.getMainClassesByPluginKey().entrySet()) { String pluginKey = mainClassEntry.getKey(); String mainClass = mainClassEntry.getValue(); try { instancesByPluginKey.put(pluginKey, (Plugin) classLoader.loadClass(mainClass).newInstance()); } catch (UnsupportedClassVersionError e) { throw new IllegalStateException(String.format("The plugin [%s] does not support Java %s", pluginKey, SystemUtils.JAVA_VERSION_TRIMMED), e); } catch (Throwable e) { throw new IllegalStateException( String.format("Fail to instantiate class [%s] of plugin [%s]", mainClass, pluginKey), e); } } } return instancesByPluginKey; }
From source file:org.sonar.core.plugins.PluginClassloaders.java
public ClassLoader add(PluginMetadata plugin) { if (done) {/*from w w w . j a v a2 s . c om*/ throw new IllegalStateException("Plugin classloaders are already initialized"); } try { List<URL> resources = Lists.newArrayList(); List<URL> others = Lists.newArrayList(); for (File file : plugin.getDeployedFiles()) { if (isResource(file)) { resources.add(file.toURI().toURL()); } else { others.add(file.toURI().toURL()); } } ClassLoader parent; if (resources.isEmpty()) { parent = baseClassloader; } else { parent = new ResourcesClassloader(resources, baseClassloader); } final ClassRealm realm; if (plugin.isUseChildFirstClassLoader()) { ClassRealm parentRealm = world.newRealm(plugin.getKey() + "-parent", parent); realm = parentRealm.createChildRealm(plugin.getKey()); } else { realm = world.newRealm(plugin.getKey(), parent); } for (URL url : others) { realm.addURL(url); } return realm; } catch (UnsupportedClassVersionError e) { throw new SonarException("The plugin " + plugin.getKey() + " is not supported with Java " + SystemUtils.JAVA_VERSION_TRIMMED, e); } catch (Throwable e) { throw new SonarException("Fail to build the classloader of " + plugin.getKey(), e); } }
From source file:org.sonar.core.plugins.PluginClassloaders.java
public boolean extend(PluginMetadata plugin) { if (done) {/*from ww w. j av a2 s . c o m*/ throw new IllegalStateException("Plugin classloaders are already initialized"); } try { ClassRealm base = world.getRealm(plugin.getBasePlugin()); if (base == null) { // Ignored, because base plugin is not installed LOG.warn("Plugin " + plugin.getKey() + " is ignored because base plugin is not installed: " + plugin.getBasePlugin()); return false; } // we create new realm to be able to return it by key without conversion to baseKey base.createChildRealm(plugin.getKey()); for (File file : plugin.getDeployedFiles()) { base.addURL(file.toURI().toURL()); } return true; } catch (UnsupportedClassVersionError e) { throw new SonarException("The plugin " + plugin.getKey() + " is not supported with Java " + SystemUtils.JAVA_VERSION_TRIMMED, e); } catch (Throwable e) { throw new SonarException( "Fail to extend the plugin " + plugin.getBasePlugin() + " for " + plugin.getKey(), e); } }
From source file:org.sonar.core.plugins.PluginClassloaders.java
public Plugin instantiatePlugin(PluginMetadata plugin) { try {//from w w w . ja va 2 s . co m Class clazz = get(plugin.getKey()).loadClass(plugin.getMainClass()); return (Plugin) clazz.newInstance(); } catch (UnsupportedClassVersionError e) { throw new SonarException("The plugin " + plugin.getKey() + " is not supported with Java " + SystemUtils.JAVA_VERSION_TRIMMED, e); } catch (Throwable e) { throw new SonarException("Fail to load plugin " + plugin.getKey(), e); } }