mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[jps] migrates to new Java version parser
This commit is contained in:
@@ -1,17 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
*/
|
||||
package org.jetbrains.jps.incremental.java;
|
||||
|
||||
@@ -23,7 +11,6 @@ import com.intellij.openapi.util.io.FileFilters;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.ExceptionUtil;
|
||||
import com.intellij.util.SystemProperties;
|
||||
import com.intellij.util.concurrency.Semaphore;
|
||||
import com.intellij.util.concurrency.SequentialTaskExecutor;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
@@ -31,6 +18,7 @@ import com.intellij.util.containers.JBIterable;
|
||||
import com.intellij.util.containers.SmartHashSet;
|
||||
import com.intellij.util.execution.ParametersListUtil;
|
||||
import com.intellij.util.io.PersistentEnumeratorBase;
|
||||
import com.intellij.util.lang.JavaVersion;
|
||||
import gnu.trove.THashMap;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -69,8 +57,7 @@ import org.jetbrains.jps.model.serialization.PathMacroUtil;
|
||||
import org.jetbrains.jps.service.JpsServiceManager;
|
||||
import org.jetbrains.jps.service.SharedThreadPool;
|
||||
|
||||
import javax.tools.Diagnostic;
|
||||
import javax.tools.JavaFileObject;
|
||||
import javax.tools.*;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
@@ -95,7 +82,6 @@ public class JavaBuilder extends ModuleLevelBuilder {
|
||||
public static final Key<Boolean> IS_ENABLED = Key.create("_java_compiler_enabled_");
|
||||
public static final FileFilter JAVA_SOURCES_FILTER = FileFilters.withExtension(JAVA_EXTENSION);
|
||||
|
||||
private static final Key<Integer> JAVA_COMPILER_VERSION_KEY = GlobalContextKey.create("_java_compiler_version_");
|
||||
private static final Key<Boolean> PREFER_TARGET_JDK_COMPILER = GlobalContextKey.create("_prefer_target_jdk_javac_");
|
||||
private static final Key<JavaCompilingTool> COMPILING_TOOL = Key.create("_java_compiling_tool_");
|
||||
private static final Key<ConcurrentMap<String, Collection<String>>> COMPILER_USAGE_STATISTICS = Key.create("_java_compiler_usage_stats_");
|
||||
@@ -382,7 +368,7 @@ public class JavaBuilder extends ModuleLevelBuilder {
|
||||
|
||||
final Set<JpsModule> modules = chunk.getModules();
|
||||
ProcessorConfigProfile profile = null;
|
||||
|
||||
|
||||
if (modules.size() == 1) {
|
||||
final JpsJavaCompilerConfiguration compilerConfig =
|
||||
JpsJavaExtensionService.getInstance().getCompilerConfiguration(context.getProjectDescriptor().getProject());
|
||||
@@ -413,7 +399,7 @@ public class JavaBuilder extends ModuleLevelBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
final int compilerSdkVersion = forkSdk == null? getCompilerSdkVersion(context) : forkSdk.getSecond();
|
||||
final int compilerSdkVersion = forkSdk == null ? JavaVersion.current().feature : forkSdk.getSecond();
|
||||
|
||||
final Pair<List<String>, List<String>> vm_compilerOptions = getCompilationOptions(
|
||||
compilerSdkVersion, context, chunk, profile, compilingTool
|
||||
@@ -598,7 +584,7 @@ public class JavaBuilder extends ModuleLevelBuilder {
|
||||
if (!isJavac(COMPILING_TOOL.get(context))) {
|
||||
return false; // applicable to javac only
|
||||
}
|
||||
final int compilerSdkVersion = getCompilerSdkVersion(context);
|
||||
final int compilerSdkVersion = JavaVersion.current().feature;
|
||||
|
||||
if (preferTargetJdkCompiler(context)) {
|
||||
final Pair<JpsSdk<JpsDummyElement>, Integer> sdkVersionPair = getAssociatedSdk(chunk);
|
||||
@@ -831,7 +817,7 @@ public class JavaBuilder extends ModuleLevelBuilder {
|
||||
CompileContext context,
|
||||
ModuleChunk chunk,
|
||||
@Nullable ProcessorConfigProfile profile) {
|
||||
addCompilationOptions(getCompilerSdkVersion(context), options, context, chunk, profile);
|
||||
addCompilationOptions(JavaVersion.current().feature, options, context, chunk, profile);
|
||||
}
|
||||
|
||||
private static void addCompilationOptions(int compilerSdkVersion,
|
||||
@@ -1013,23 +999,13 @@ public class JavaBuilder extends ModuleLevelBuilder {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static int getCompilerSdkVersion(CompileContext context) {
|
||||
final Integer cached = JAVA_COMPILER_VERSION_KEY.get(context);
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
}
|
||||
int javaVersion = JpsJavaSdkType.parseVersion(SystemProperties.getJavaVersion());
|
||||
JAVA_COMPILER_VERSION_KEY.set(context, javaVersion);
|
||||
return javaVersion;
|
||||
}
|
||||
|
||||
private static int getChunkSdkVersion(ModuleChunk chunk) {
|
||||
int chunkSdkVersion = -1;
|
||||
for (JpsModule module : chunk.getModules()) {
|
||||
final JpsSdk<JpsDummyElement> sdk = module.getSdk(JpsJavaSdkType.INSTANCE);
|
||||
if (sdk != null) {
|
||||
final int moduleSdkVersion = JpsJavaSdkType.parseVersion(sdk.getVersionString());
|
||||
if (moduleSdkVersion != 0 /*could determine the version*/&& (chunkSdkVersion < 0 || chunkSdkVersion > moduleSdkVersion)) {
|
||||
final int moduleSdkVersion = JpsJavaSdkType.getJavaVersion(sdk);
|
||||
if (moduleSdkVersion != 0 /*could determine the version*/ && (chunkSdkVersion < 0 || chunkSdkVersion > moduleSdkVersion)) {
|
||||
chunkSdkVersion = moduleSdkVersion;
|
||||
}
|
||||
}
|
||||
@@ -1071,7 +1047,7 @@ public class JavaBuilder extends ModuleLevelBuilder {
|
||||
// assuming all modules in the chunk have the same associated JDK;
|
||||
// this constraint should be validated on build start
|
||||
final JpsSdk<JpsDummyElement> sdk = chunk.representativeTarget().getModule().getSdk(JpsJavaSdkType.INSTANCE);
|
||||
return sdk != null? Pair.create(sdk, JpsJavaSdkType.parseVersion(sdk.getVersionString())) : null;
|
||||
return sdk != null ? Pair.create(sdk, JpsJavaSdkType.getJavaVersion(sdk)) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,20 +1,9 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
*/
|
||||
package org.jetbrains.jps.model.java;
|
||||
|
||||
import com.intellij.util.lang.JavaVersion;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.JpsDummyElement;
|
||||
@@ -45,40 +34,11 @@ public class JpsJavaSdkType extends JpsSdkType<JpsDummyElement> implements JpsEl
|
||||
}
|
||||
|
||||
public static int getJavaVersion(@Nullable JpsSdk<?> sdk) {
|
||||
return parseVersion(sdk != null && sdk.getSdkType() instanceof JpsJavaSdkType? sdk.getVersionString() : null);
|
||||
return parseVersion(sdk != null && sdk.getSdkType() instanceof JpsJavaSdkType ? sdk.getVersionString() : null);
|
||||
}
|
||||
|
||||
public static int parseVersion(String javaVersionString) {
|
||||
if (javaVersionString == null) {
|
||||
return 0;
|
||||
}
|
||||
final int quoteBegin = javaVersionString.indexOf('\"');
|
||||
if (quoteBegin >= 0) {
|
||||
final int quoteEnd = javaVersionString.indexOf('\"', quoteBegin + 1);
|
||||
if (quoteEnd > quoteBegin) {
|
||||
javaVersionString = javaVersionString.substring(quoteBegin + 1, quoteEnd);
|
||||
}
|
||||
}
|
||||
if (javaVersionString.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
final String prefix = "1.";
|
||||
final int parseBegin = javaVersionString.startsWith(prefix) ? prefix.length() : 0;
|
||||
|
||||
int parseEnd = parseBegin;
|
||||
while (parseEnd < javaVersionString.length()) {
|
||||
if (!Character.isDigit(javaVersionString.charAt(parseEnd))) {
|
||||
break;
|
||||
}
|
||||
parseEnd++;
|
||||
}
|
||||
try {
|
||||
return Integer.parseInt(javaVersionString.substring(parseBegin, parseEnd));
|
||||
}
|
||||
catch (NumberFormatException ignored) {
|
||||
}
|
||||
return 0;
|
||||
JavaVersion version = JavaVersion.tryParse(javaVersionString);
|
||||
return version != null ? version.feature : 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+7
-22
@@ -1,17 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
*/
|
||||
package org.jetbrains.jps.incremental.groovy;
|
||||
|
||||
@@ -20,12 +8,12 @@ import com.intellij.compiler.instrumentation.FailSafeClassReader;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import com.intellij.util.lang.JavaVersion;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.ModuleChunk;
|
||||
@@ -150,7 +138,7 @@ public abstract class JpsGroovycRunner<R extends BuildRootDescriptor, T extends
|
||||
if (myForStubs) {
|
||||
clearContinuation(context, chunk);
|
||||
}
|
||||
|
||||
|
||||
GroovycContinuation continuation = takeContinuation(context, chunk);
|
||||
if (continuation != null) {
|
||||
if (Utils.IS_TEST_MODE || LOG.isDebugEnabled()) {
|
||||
@@ -162,9 +150,9 @@ public abstract class JpsGroovycRunner<R extends BuildRootDescriptor, T extends
|
||||
final Set<String> toCompilePaths = getPathsToCompile(toCompile);
|
||||
|
||||
JpsSdk<JpsDummyElement> jdk = GroovyBuilder.getJdk(chunk);
|
||||
String version = jdk == null ? SystemInfo.JAVA_RUNTIME_VERSION : jdk.getVersionString();
|
||||
int version = jdk != null ? JpsJavaSdkType.getJavaVersion(jdk) : JavaVersion.current().feature;
|
||||
boolean inProcess = shouldRunGroovycInProcess(version);
|
||||
boolean mayDependOnUtilJar = version != null && JpsJavaSdkType.parseVersion(version) >= 6;
|
||||
boolean mayDependOnUtilJar = version >= 6;
|
||||
boolean optimizeClassLoading = !inProcess && mayDependOnUtilJar && ourOptimizeThreshold != 0 && toCompilePaths.size() >= ourOptimizeThreshold;
|
||||
|
||||
Map<String, String> class2Src = buildClassToSourceMap(chunk, context, toCompilePaths, finalOutputs);
|
||||
@@ -197,12 +185,9 @@ public abstract class JpsGroovycRunner<R extends BuildRootDescriptor, T extends
|
||||
return parser;
|
||||
}
|
||||
|
||||
private static boolean shouldRunGroovycInProcess(@Nullable String jdkVersion) {
|
||||
private static boolean shouldRunGroovycInProcess(int jdkVersion) {
|
||||
String explicitProperty = System.getProperty("groovyc.in.process");
|
||||
if (explicitProperty == null) {
|
||||
return jdkVersion != null && JpsJavaSdkType.parseVersion(jdkVersion) == JpsJavaSdkType.parseVersion(SystemInfo.JAVA_RUNTIME_VERSION);
|
||||
}
|
||||
return "true".equals(explicitProperty);
|
||||
return explicitProperty != null ? "true".equals(explicitProperty) : jdkVersion == JavaVersion.current().feature;
|
||||
}
|
||||
|
||||
static void clearContinuation(CompileContext context, ModuleChunk chunk) {
|
||||
|
||||
Reference in New Issue
Block a user