Java Code Examples for org.eclipse.xtext.util.JavaVersion#isAtLeast()

The following examples show how to use org.eclipse.xtext.util.JavaVersion#isAtLeast() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaVersionCheckExtension.java    From sarl with Apache License 2.0 6 votes vote down vote up
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
	// Check if the minimal version of Java is used for running the tests.
	final JavaVersion cVersion = JavaVersion.fromQualifier(System.getProperty("java.specification.version"));
	if (cVersion == null) {
		return ConditionEvaluationResult.disabled("You must use JDK " + SARLVersion.MINIMAL_JDK_VERSION_FOR_SARL_COMPILATION_ENVIRONMENT + " or higher for running the tests.");
	}
	final JavaVersion mVersion = JavaVersion.fromQualifier(SARLVersion.MINIMAL_JDK_VERSION_FOR_SARL_COMPILATION_ENVIRONMENT);
	if (mVersion == null || !cVersion.isAtLeast(mVersion)) {
		return ConditionEvaluationResult.disabled("You must use JDK " + SARLVersion.MINIMAL_JDK_VERSION_FOR_SARL_COMPILATION_ENVIRONMENT + " or higher for running the tests.");
	}
	final JavaVersion xVersion = JavaVersion.fromQualifier(SARLVersion.INCOMPATIBLE_JDK_VERSION_FOR_SARL_COMPILATION_ENVIRONMENT);
	// If null the max version that is specified into the SARL configuration is not yey supported by Xtext enumeration
	if (xVersion != null && cVersion.isAtLeast(xVersion)) {
		return ConditionEvaluationResult.disabled("You must use JDK strictly below " + SARLVersion.INCOMPATIBLE_JDK_VERSION_FOR_SARL_COMPILATION_ENVIRONMENT + " for running the tests.");
	}
	return ConditionEvaluationResult.enabled("supported version of JDK");
}
 
Example 2
Source File: WizardNewXtextProjectCreationPage.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void fillBreeCombo(Combo comboToFill) {
	Set<String> brees = Sets.newLinkedHashSet();
	Set<String> availableBrees = Sets.newHashSet();
	for (IExecutionEnvironment ee : JavaRuntime.getExecutionEnvironmentsManager().getExecutionEnvironments()) {
		availableBrees.add(ee.getId());
	}
	for (JavaVersion supportedVersion : JavaVersion.values()) {
		if (supportedVersion.isAtLeast(JavaVersion.JAVA6)) {
			String bree = supportedVersion.getBree();
			if (availableBrees.contains(bree))
				brees.add(bree);
		}
	}
	String[] array = brees.toArray(new String[] {});
	String selectionMemento = comboToFill.getText();
	comboToFill.setItems(array);
	int index = comboToFill.indexOf(selectionMemento);
	String defaultBree = JREContainerProvider.getDefaultBREE();
	if (index < 0) {
		if (brees.contains(defaultBree)) {
			comboToFill.select(comboToFill.indexOf(defaultBree));
		} else {
			comboToFill.select(array.length - 1);
		}
	}
	comboToFill.select(index);
}
 
Example 3
Source File: AbstractXtendCompilerMojo.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
private String getBootClassPath() {
	Toolchain toolchain = toolchainManager.getToolchainFromBuildContext("jdk", session);
	if (toolchain instanceof DefaultJavaToolChain) {
		DefaultJavaToolChain javaToolChain = (DefaultJavaToolChain) toolchain;
		getLog().info("Using toolchain " + javaToolChain);

		if (javaSourceVersion != null) {
			JavaVersion version = JavaVersion.fromQualifier(javaSourceVersion);
			if (version.isAtLeast(JavaVersion.JAVA9)) {
				return ""; // bootclasspath only supported on Java8 and older
			}
		}

		String[] includes = { "jre/lib/*", "jre/lib/ext/*", "jre/lib/endorsed/*" };
		String[] excludes = new String[0];
		Xpp3Dom config = (Xpp3Dom) javaToolChain.getModel().getConfiguration();
		if (config != null) {
			Xpp3Dom bootClassPath = config.getChild("bootClassPath");
			if (bootClassPath != null) {
				Xpp3Dom includeParent = bootClassPath.getChild("includes");
				if (includeParent != null) {
					includes = getValues(includeParent.getChildren("include"));
				}
				Xpp3Dom excludeParent = bootClassPath.getChild("excludes");
				if (excludeParent != null) {
					excludes = getValues(excludeParent.getChildren("exclude"));
				}
			}
		}

		return scanBootclasspath(javaToolChain.getJavaHome(), includes, excludes);
	}
	return "";
}
 
Example 4
Source File: XtendBatchCompiler.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * This option is only supported on JDK 8 and older and will be ignored when source level is 9 or newer.
 * @since 2.7
 * @see <a href="https://www.oracle.com/technetwork/java/javase/9-relnote-issues-3704069.html">Java 9 Release Notes</a>
 */
public void setBootClassPath(String bootClassPath) {
	JavaVersion version = JavaVersion.fromQualifier(getJavaSourceVersion());
	if (version.isAtLeast(JavaVersion.JAVA9)) {
		if (!bootClassPath.isEmpty()) {
			log.warn("Option bootClassPath is only valid for Java 8 and lower. The value '"+bootClassPath+"' will be ignored.");
		}
	} else {
		this.bootClassPath = bootClassPath;
	}
}
 
Example 5
Source File: AbstractSarlBatchCompilerMojo.java    From sarl with Apache License 2.0 5 votes vote down vote up
private String getBootClassPath() throws MojoExecutionException {
	// Bootclasspath is only supported on Java8 and older
	final String sourceVersionStr = getSourceVersion();
	if (!Strings.isEmpty(sourceVersionStr)) {
		final JavaVersion sourceVersion = JavaVersion.fromQualifier(sourceVersionStr);
		if (sourceVersion != null && sourceVersion.isAtLeast(JavaVersion.JAVA9)) {
			return ""; //$NON-NLS-1$
		}
	}
	final Toolchain toolchain = this.toolchainManager.getToolchainFromBuildContext("jdk", this.mavenHelper.getSession()); //$NON-NLS-1$
	if (toolchain instanceof JavaToolchain && toolchain instanceof ToolchainPrivate) {
		final JavaToolchain javaToolChain = (JavaToolchain) toolchain;
		final ToolchainPrivate privateJavaToolChain = (ToolchainPrivate) toolchain;
		getLog().info(MessageFormat.format(Messages.AbstractSarlBatchCompilerMojo_5, javaToolChain));

		String[] includes = {"jre/lib/*", "jre/lib/ext/*", "jre/lib/endorsed/*"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
		String[] excludes = new String[0];
		final Xpp3Dom config = (Xpp3Dom) privateJavaToolChain.getModel().getConfiguration();
		if (config != null) {
			final Xpp3Dom bootClassPath = config.getChild("bootClassPath"); //$NON-NLS-1$
			if (bootClassPath != null) {
				final Xpp3Dom includeParent = bootClassPath.getChild("includes"); //$NON-NLS-1$
				if (includeParent != null) {
					includes = getValues(includeParent.getChildren("include")); //$NON-NLS-1$
				}
				final Xpp3Dom excludeParent = bootClassPath.getChild("excludes"); //$NON-NLS-1$
				if (excludeParent != null) {
					excludes = getValues(excludeParent.getChildren("exclude")); //$NON-NLS-1$
				}
			}
		}

		try {
			return scanBootclasspath(Objects.toString(this.reflect.invoke(javaToolChain, "getJavaHome")), includes, excludes); //$NON-NLS-1$
		} catch (Exception e) {
			throw new MojoExecutionException(e.getLocalizedMessage(), e);
		}
	}
	return ""; //$NON-NLS-1$
}
 
Example 6
Source File: SarlBatchCompiler.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Change the boot classpath.
 * This option is only supported on JDK 8 and older and will be ignored when source level is 9 or newer.
 *
 * <p>The boot classpath is a list the names of folders or jar files that are separated by {@link File#pathSeparator}.
 *
 * @param bootClasspath the new boot classpath.
 * @see "https://www.oracle.com/technetwork/java/javase/9-relnote-issues-3704069.html"
 */
public void setBootClassPath(String bootClasspath) {
	final JavaVersion version = JavaVersion.fromQualifier(getJavaSourceVersion());
	if (version.isAtLeast(JavaVersion.JAVA9)) {
		reportInternalWarning(MessageFormat.format(Messages.SarlBatchCompiler_63, bootClasspath));
	}
	if (Strings.isEmpty(bootClasspath)) {
		this.bootClasspath = null;
	} else {
		this.bootClasspath = new ArrayList<>();
		for (final String path : Strings.split(bootClasspath, File.pathSeparator)) {
			this.bootClasspath.add(normalizeFile(path));
		}
	}
}
 
Example 7
Source File: SarlBatchCompiler.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Change the boot classpath.
 * This option is only supported on JDK 8 and older and will be ignored when source level is 9 or newer.
 *
 * @param bootClasspath the new boot classpath.
 * @see "https://www.oracle.com/technetwork/java/javase/9-relnote-issues-3704069.html"
 */
public void setBootClassPath(Collection<File> bootClasspath) {
	final JavaVersion version = JavaVersion.fromQualifier(getJavaSourceVersion());
	if (version.isAtLeast(JavaVersion.JAVA9)) {
		reportInternalWarning(MessageFormat.format(Messages.SarlBatchCompiler_63,
				Joiner.on(File.pathSeparator).join(bootClasspath)));
	}
	if (bootClasspath == null || bootClasspath.isEmpty()) {
		this.bootClasspath = null;
	} else {
		this.bootClasspath = new ArrayList<>(bootClasspath);
	}
}
 
Example 8
Source File: WizardNewXtextProjectCreationPage.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected boolean validatePage() {
	if (!super.validatePage())
		return false;
	IStatus status = validateProjectName();
	if (!status.isOK()) {
		setErrorMessage(status.getMessage());
		return false;
	}
	if (languageNameField == null) // See the comment in createControl
		return true;
	if (languageNameField.getText().length() == 0)
		return false;

	status = JavaConventions.validateJavaTypeName(languageNameField.getText(), JavaCore.VERSION_1_5, JavaCore.VERSION_1_5);
	if (!status.isOK()) {
		setErrorMessage(Messages.WizardNewXtextProjectCreationPage_ErrorMessageLanguageName + status.getMessage());
		return false;
	}

	if (!languageNameField.getText().contains(".")) { //$NON-NLS-1$
		setErrorMessage(Messages.WizardNewXtextProjectCreationPage_ErrorMessageLanguageNameWithoutPackage);
		return false;
	}

	if (extensionsField.getText().length() == 0)
		return false;
	if (!PATTERN_EXTENSIONS.matcher(extensionsField.getText()).matches()) {
		setErrorMessage(Messages.WizardNewXtextProjectCreationPage_ErrorMessageExtensions);
		return false;
	}
	JavaVersion javaVersion = JavaVersion.fromBree(breeCombo.getText());
	if (javaVersion != null && !javaVersion.isAtLeast(JavaVersion.JAVA8)) {
		setMessage(Messages.WizardNewXtextProjectCreationPage_MessageAtLeastJava8, IStatus.WARNING);
		return true;
	}
	if (!Sets.newHashSet(JREContainerProvider.getConfiguredBREEs()).contains(breeCombo.getText())) {
		setMessage(Messages.WizardNewXtextProjectCreationPage_eeInfo_0 + breeCombo.getText()
				+ Messages.WizardNewXtextProjectCreationPage_eeInfo_1, IMessageProvider.INFORMATION);
		return true;
	}
	setErrorMessage(null);
	setMessage(null);
	return true;
}
 
Example 9
Source File: XtendBatchCompiler.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @since 2.8
 */
protected boolean preCompile(File classDirectory, Iterable<String> sourcePathDirectories, Iterable<String> classPathEntries) {
	List<String> commandLine = Lists.newArrayList();
	// todo args
	if (isVerbose()) {
		commandLine.add("-verbose");
	}
	if (getJavaSourceVersion() != null) {
		JavaVersion version = JavaVersion.fromQualifier(getJavaSourceVersion());
		if (!version.isAtLeast(JavaVersion.JAVA9)) {
			List<String> bootClassPathEntries = getBootClassPathEntries();
			if (!isEmpty(bootClassPathEntries)) {
				commandLine.add("-bootclasspath \"" + concat(File.pathSeparator, bootClassPathEntries) + "\"");
			}
		}
	}
	if (!isEmpty(classPathEntries)) {
		commandLine.add("-cp \"" + Joiner.on(File.pathSeparator).join(classPathEntries) + "\"");
	}
	commandLine.add("-d \"" + classDirectory.toString() + "\"");
	commandLine.add("-" + getComplianceLevel());
	commandLine.add("-proceedOnError");
	if (encodingProvider.getDefaultEncoding() != null) {
		commandLine.add("-encoding \"" + encodingProvider.getDefaultEncoding() + "\"");
	}
	if (additionalPreCompileArgs != null) {
		commandLine.add(additionalPreCompileArgs);
	}
	List<String> sourceDirectories = newArrayList(sourcePathDirectories);
	commandLine.add(concat(" ", transform(sourceDirectories, new Function<String, String>() {
		@Override
		public String apply(String path) {
			return "\"" + path + "\"";
		}
	})));
	if (log.isDebugEnabled()) {
		log.debug("invoke batch compiler with '" + concat(" ", commandLine) + "'");
	}
	PrintWriter outWriter = getStubCompilerOutputWriter();
	return BatchCompiler.compile(concat(" ", commandLine), outWriter, outWriter, null);
}