Merge remote-tracking branch 'origin/master'

This commit is contained in:
Vassiliy.Kudryashov
2017-12-21 23:10:10 +03:00
47 changed files with 389 additions and 822 deletions
+6 -17
View File
@@ -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-2017 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.
*/
@@ -103,7 +91,7 @@ binding.setVariable("guessHome", {
binding.setVariable("loadProject", {
defineJdk("IDEA jdk", setupJdkPath("jdkHome", "$home/build/jdk/1.6", "JDK_16_x64"))
defineJdk("1.8", setupJdkPath("jdk8Home", "$home/build/jdk/1.8", "JDK_18_x64"))
setupKotlin()
def bundledKotlinPath = "$home/build/dependencies/build/kotlin/Kotlin/kotlinc"
if (!new File(bundledKotlinPath, "lib/kotlin-runtime.jar").exists()) {
@@ -195,9 +183,10 @@ private String setupJdkPath(String propertyName, String defaultDir, String envVa
}
else {
jdk = guessJdk()
def version = JdkVersionDetector.instance.detectJdkVersion(jdk)
if (propertyName.contains("8") && !version.contains("1.8.")) {
projectBuilder.error("JDK 1.8 is required to compile the project, but '$propertyName' property and '$envVarName' environment variable aren't defined and default JDK $jdk ($version) cannot be used as JDK 1.8")
def jdkInfo = JdkVersionDetector.instance.detectJdkVersionInfo(jdk)
if (propertyName.contains("8") && jdkInfo.version.contains("1.8.")) {
projectBuilder.error("JDK 1.8 is required to compile the project, but '$propertyName' property and '$envVarName' environment variable" +
" aren't defined and default JDK $jdk ($jdkInfo) cannot be used as JDK 1.8")
return null
}
projectBuilder.info("'$envVarName' isn't defined and '$defaultDir' doesn't exist, $propertyName set to $jdk")
@@ -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-2017 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 com.intellij.execution.util;
@@ -26,17 +14,17 @@ import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.text.StringUtil;
import org.jetbrains.jps.model.java.JdkVersionDetector;
public class JreVersionDetector {
private String myLastAlternativeJrePath ; //awful hack
private boolean myLastIsJre50;
public boolean isModuleJre50Configured(final ModuleBasedConfiguration configuration) {
final Module module = configuration.getConfigurationModule().getModule();
if (module != null && !module.isDisposed()) {
return isJre50(ModuleRootManager.getInstance(module).getSdk());
}
return isJre50(ProjectRootManager.getInstance(configuration.getProject()).getProjectSdk());
Module module = configuration.getConfigurationModule().getModule();
Sdk sdk = module != null && !module.isDisposed() ? ModuleRootManager.getInstance(module).getSdk()
: ProjectRootManager.getInstance(configuration.getProject()).getProjectSdk();
return JavaSdkUtil.isJdkAtLeast(sdk, JavaSdkVersion.JDK_1_5);
}
public boolean isJre50Configured(final CommonJavaRunConfigurationParameters configuration) {
@@ -48,22 +36,12 @@ public class JreVersionDetector {
}
myLastAlternativeJrePath = alternativeJrePath;
String versionString = SdkVersionUtil.detectJdkVersion(myLastAlternativeJrePath);
myLastIsJre50 = versionString != null && isJre50(versionString);
JdkVersionDetector.JdkVersionInfo jdkInfo = SdkVersionUtil.getJdkVersionInfo(myLastAlternativeJrePath);
myLastIsJre50 = jdkInfo != null && jdkInfo.version.feature >= 5;
return myLastIsJre50;
}
}
return false;
}
private static boolean isJre50(Sdk jdk) {
return JavaSdkUtil.isJdkAtLeast(jdk, JavaSdkVersion.JDK_1_5);
}
private static boolean isJre50(String versionString) {
if (versionString == null) return false;
JavaSdkVersion version = JavaSdkVersion.fromVersionString(versionString);
return version != null && version.isAtLeast(JavaSdkVersion.JDK_1_5);
}
}
@@ -1,4 +1,6 @@
// Copyright 2000-2017 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.
/*
* Copyright 2000-2017 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 com.intellij.openapi.projectRoots.impl;
import com.intellij.icons.AllIcons;
@@ -16,24 +18,23 @@ import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.*;
import com.intellij.openapi.vfs.jrt.JrtFileSystem;
import com.intellij.util.PathUtil;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.MultiMap;
import com.intellij.util.lang.JavaVersion;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.jps.model.java.JdkVersionDetector;
import org.jetbrains.jps.model.java.impl.JavaSdkUtil;
import javax.swing.*;
import java.io.File;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;
/**
@@ -46,12 +47,9 @@ public class JavaSdkImpl extends JavaSdk {
public static final DataKey<Boolean> KEY = DataKey.create("JavaSdk");
private static final String VM_EXE_NAME = "java"; // do not use JavaW.exe for Windows because of issues with encoding
private static final Pattern VERSION_STRING_PATTERN = Pattern.compile("^(.*)java version \"([1234567890_.]*)\"(.*)$");
private static final String JAVA_VERSION_PREFIX = "java version ";
private static final String OPENJDK_VERSION_PREFIX = "openjdk version ";
private final Map<String, String> myCachedSdkHomeToVersionString = new ConcurrentHashMap<>();
private final Map<String, JavaSdkVersion> myCachedVersionStringToJavaVersion = new ConcurrentHashMap<>();
private final Map<String, JavaSdkVersion> myCachedVersionStringToJdkVersion = new ConcurrentHashMap<>();
public JavaSdkImpl(final VirtualFileManager fileManager, final FileTypeManager fileTypeManager) {
super("JavaSDK");
@@ -73,11 +71,10 @@ public class JavaSdkImpl extends JavaSdk {
}
private void updateCache(VirtualFileEvent event) {
final VirtualFile file = event.getFile();
if (FileTypes.ARCHIVE.equals(fileTypeManager.getFileTypeByFileName(event.getFileName()))) {
final String filePath = file.getPath();
String filePath = event.getFile().getPath();
if (myCachedSdkHomeToVersionString.keySet().removeIf(sdkHome -> FileUtil.isAncestor(sdkHome, filePath, false))) {
myCachedVersionStringToJavaVersion.clear();
myCachedVersionStringToJdkVersion.clear();
}
}
}
@@ -201,50 +198,14 @@ public class JavaSdkImpl extends JavaSdk {
@Override
public String suggestSdkName(String currentSdkName, String sdkHome) {
final String suggestedName;
if (currentSdkName != null && !currentSdkName.isEmpty()) {
final Matcher matcher = VERSION_STRING_PATTERN.matcher(currentSdkName);
final boolean replaceNameWithVersion = matcher.matches();
if (replaceNameWithVersion){
// user did not change name -> set it automatically
final String versionString = getVersionString(sdkHome);
suggestedName = versionString == null ? currentSdkName : matcher.replaceFirst("$1" + versionString + "$3");
}
else {
suggestedName = currentSdkName;
}
}
else {
String versionString = getVersionString(sdkHome);
suggestedName = versionString == null ? ProjectBundle.message("sdk.java.unknown.name") : getVersionNumber(versionString);
}
return suggestedName;
}
JavaVersion version = JavaVersion.tryParse(getVersionString(sdkHome));
if (version == null) return currentSdkName;
@NotNull
private static String getVersionNumber(@NotNull String versionString) {
if (versionString.startsWith(JAVA_VERSION_PREFIX) || versionString.startsWith(OPENJDK_VERSION_PREFIX)) {
boolean openJdk = versionString.startsWith(OPENJDK_VERSION_PREFIX);
versionString = versionString.substring(openJdk ? OPENJDK_VERSION_PREFIX.length() : JAVA_VERSION_PREFIX.length());
if (versionString.startsWith("\"") && versionString.endsWith("\"")) {
versionString = versionString.substring(1, versionString.length() - 1);
}
int dotIdx = versionString.indexOf('.');
if (dotIdx > 0) {
try {
int major = Integer.parseInt(versionString.substring(0, dotIdx));
int minorDot = versionString.indexOf('.', dotIdx + 1);
if (minorDot > 0) {
int minor = Integer.parseInt(versionString.substring(dotIdx + 1, minorDot));
versionString = major + "." + minor;
}
}
catch (NumberFormatException e) {
// Do nothing. Use original version string if failed to parse according to major.minor pattern.
}
}
}
return versionString;
StringBuilder suggested = new StringBuilder();
if (version.feature < 9) suggested.append("1.");
suggested.append(version.feature);
if (version.ea) suggested.append("-ea");
return suggested.toString();
}
@Override
@@ -324,21 +285,17 @@ public class JavaSdkImpl extends JavaSdk {
@Override
public final String getVersionString(String sdkHome) {
String versionString = myCachedSdkHomeToVersionString.get(sdkHome);
if (versionString == null) {
versionString = SdkVersionUtil.detectJdkVersion(sdkHome);
if (!StringUtil.isEmpty(versionString)) {
myCachedSdkHomeToVersionString.put(sdkHome, versionString);
}
}
return versionString;
return myCachedSdkHomeToVersionString.computeIfAbsent(sdkHome, k -> {
JdkVersionDetector.JdkVersionInfo jdkInfo = SdkVersionUtil.getJdkVersionInfo(k);
return jdkInfo != null ? JdkVersionDetector.formatVersionString(jdkInfo.version) : null;
});
}
@Override
public JavaSdkVersion getVersion(@NotNull Sdk sdk) {
String versionString = sdk.getVersionString();
return versionString == null ? null :
myCachedVersionStringToJavaVersion.computeIfAbsent(versionString, JavaSdkVersion::fromVersionString);
myCachedVersionStringToJdkVersion.computeIfAbsent(versionString, JavaSdkVersion::fromVersionString);
}
@Override
@@ -1,29 +1,14 @@
/*
* 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-2017 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 com.intellij.openapi.projectRoots;
import com.intellij.openapi.util.Version;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.lang.JavaVersion;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Represents version of Java SDK. Use {@code JavaSdk#getVersion(Sdk)} method to obtain version of an {@code Sdk}.
@@ -32,29 +17,25 @@ import java.util.regex.Pattern;
* @see LanguageLevel
*/
public enum JavaSdkVersion {
JDK_1_0(LanguageLevel.JDK_1_3, 0, new String[]{"1.0"}),
JDK_1_1(LanguageLevel.JDK_1_3, 1, new String[]{"1.1"}),
JDK_1_2(LanguageLevel.JDK_1_3, 2, new String[]{"1.2"}),
JDK_1_3(LanguageLevel.JDK_1_3, 3, new String[]{"1.3"}),
JDK_1_4(LanguageLevel.JDK_1_4, 4, new String[]{"1.4"}),
JDK_1_5(LanguageLevel.JDK_1_5, 5, new String[]{"1.5", "5.0"}),
JDK_1_6(LanguageLevel.JDK_1_6, 6, new String[]{"1.6", "6.0"}),
JDK_1_7(LanguageLevel.JDK_1_7, 7, new String[]{"1.7", "7.0"}),
JDK_1_8(LanguageLevel.JDK_1_8, 8, new String[]{"1.8", "8.0"}),
JDK_1_9(LanguageLevel.JDK_1_9, 9, new String[]{"1.9", "9.0", "9-ea"}),
JDK_10(LanguageLevel.JDK_1_9, 10, new String[]{"10.0", "10-ea"});
JDK_1_0(LanguageLevel.JDK_1_3, new String[]{"1.0"}),
JDK_1_1(LanguageLevel.JDK_1_3, new String[]{"1.1"}),
JDK_1_2(LanguageLevel.JDK_1_3, new String[]{"1.2"}),
JDK_1_3(LanguageLevel.JDK_1_3, new String[]{"1.3"}),
JDK_1_4(LanguageLevel.JDK_1_4, new String[]{"1.4"}),
JDK_1_5(LanguageLevel.JDK_1_5, new String[]{"1.5", "5.0"}),
JDK_1_6(LanguageLevel.JDK_1_6, new String[]{"1.6", "6.0"}),
JDK_1_7(LanguageLevel.JDK_1_7, new String[]{"1.7", "7.0"}),
JDK_1_8(LanguageLevel.JDK_1_8, new String[]{"1.8", "8.0"}),
JDK_1_9(LanguageLevel.JDK_1_9, new String[]{"1.9", "9.0", "9-ea"}),
JDK_10(LanguageLevel.JDK_1_9, new String[]{"10.0", "10-ea"});
private static final JavaSdkVersion MAX_JDK = JDK_1_9;
private static final Pattern JAVA_VERSION = Pattern.compile("java version \"(\\d.*)\"");
private final LanguageLevel myMaxLanguageLevel;
private final int myRelease;
private final String[] myVersionStrings;
JavaSdkVersion(@NotNull LanguageLevel maxLanguageLevel, int release, @NotNull String[] description) {
JavaSdkVersion(@NotNull LanguageLevel maxLanguageLevel, @NotNull String[] description) {
myMaxLanguageLevel = maxLanguageLevel;
myRelease = release;
myVersionStrings = description;
}
@@ -93,31 +74,16 @@ public enum JavaSdkVersion {
throw new IllegalArgumentException("Can't map " + languageLevel + " to any of " + Arrays.toString(values()));
}
/**
* Version string could be an actual version (like {@code "1.8.0_131"}),
* or a string returned by "java -version" command (like {@code "java version \"9-ea\""}).
*/
/** See {@link JavaVersion#parse(String)} for supported formats. */
@Nullable
public static JavaSdkVersion fromVersionString(@NotNull String versionString) {
Matcher matcher = JAVA_VERSION.matcher(versionString.trim());
if (matcher.matches()) {
versionString = matcher.group(1);
}
JavaVersion version = JavaVersion.tryParse(versionString);
return version != null ? fromJavaVersion(version) : null;
}
Version parsed = Version.parseVersion(versionString);
if (parsed != null && parsed.major > 0) {
int release = parsed.major == 1 ? parsed.minor : parsed.major;
return ContainerUtil.find(values(), v -> v.myRelease == release);
}
for (JavaSdkVersion version : values()) {
for (String pattern : version.myVersionStrings) {
if (versionString.contains(pattern)) {
return version;
}
}
}
return null;
@Nullable
public static JavaSdkVersion fromJavaVersion(@NotNull JavaVersion version) {
JavaSdkVersion[] values = values();
return version.feature < values.length ? values[version.feature] : null;
}
}
@@ -1,17 +1,5 @@
/*
* Copyright 2000-2014 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-2017 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 com.intellij.projectView;
@@ -132,7 +120,7 @@ public class NavigateFromSourceTest extends BaseProjectViewTestCase {
psiClass = psiFile.getClasses()[0];
pane.select(psiClass, virtualFile, true);
PlatformTestUtil.waitUntilBusy(tree);
PlatformTestUtil.waitWhileBusy(tree);
PlatformTestUtil.assertTreeEqual(tree, expected, true);
}
}
@@ -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-2017 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 com.intellij.projectView;
@@ -249,7 +237,7 @@ public class ProjectTreeSortingTest extends BaseProjectViewTestCase {
private void assertTree(String expected) {
TreePath path = PlatformTestUtil.waitForPromise(myPane.promisePathToElement(getContentDirectory()));
PlatformTestUtil.waitUntilBusy(myPane.getTree());
PlatformTestUtil.waitWhileBusy(myPane.getTree());
Object element = path.getLastPathComponent();
assertNotNull("Element for " + getContentDirectory() + " not found", element);
assertEquals(expected, PlatformTestUtil.print(myPane.getTree(), element, new Queryable.PrintInfo(), false));
@@ -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-2017 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 com.intellij.projectView;
@@ -50,7 +38,7 @@ public class ProjectViewUpdatingTest extends BaseProjectViewTestCase {
final AbstractProjectViewPSIPane pane = myStructure.createPane();
getProjectTreeStructure().setProviders();
pane.select(element, element.getContainingFile().getVirtualFile(), true);
PlatformTestUtil.waitUntilBusy(pane.getTree());
PlatformTestUtil.waitWhileBusy(pane.getTree());
PlatformTestUtil.assertTreeEqual(pane.getTree(), "-Project\n" +
" -PsiDirectory: standardProviders\n" +
" -PsiDirectory: src\n" +
@@ -102,7 +90,7 @@ public class ProjectViewUpdatingTest extends BaseProjectViewTestCase {
final PsiClass aClass = classFile.getClasses()[0];
final PsiFile containingFile = aClass.getContainingFile();
pane.select(aClass, containingFile.getVirtualFile(), true);
PlatformTestUtil.waitUntilBusy(pane.getTree());
PlatformTestUtil.waitWhileBusy(pane.getTree());
PlatformTestUtil.assertTreeEqual(pane.getTree(), "-Project\n" +
" -PsiDirectory: updateProjectView\n" +
" -PsiDirectory: src\n" +
@@ -148,7 +136,7 @@ public class ProjectViewUpdatingTest extends BaseProjectViewTestCase {
PlatformTestUtil.waitForAlarm(600);
final PsiFile containingFile2 = aClass2.getContainingFile();
pane.select(aClass2, containingFile2.getVirtualFile(), true);
PlatformTestUtil.waitUntilBusy(pane.getTree());
PlatformTestUtil.waitWhileBusy(pane.getTree());
PlatformTestUtil.assertTreeEqual(pane.getTree(), "-Project\n" +
" -PsiDirectory: updateProjectView\n" +
" -PsiDirectory: src\n" +
@@ -181,7 +169,7 @@ public class ProjectViewUpdatingTest extends BaseProjectViewTestCase {
PsiClass aClass = classFile.getClasses()[0];
PsiFile containingFile = aClass.getContainingFile();
pane.select(aClass, containingFile.getVirtualFile(), true);
PlatformTestUtil.waitUntilBusy(pane.getTree());
PlatformTestUtil.waitWhileBusy(pane.getTree());
PlatformTestUtil.assertTreeEqual(pane.getTree(), "-Project\n" +
" -PsiDirectory: showClassMembers\n" +
" -PsiDirectory: src\n" +
@@ -228,7 +216,7 @@ public class ProjectViewUpdatingTest extends BaseProjectViewTestCase {
final PsiField lastField = aClass.getFields()[1];
pane.select(lastField, containingFile.getVirtualFile(), true);
PlatformTestUtil.waitUntilBusy(pane.getTree());
PlatformTestUtil.waitWhileBusy(pane.getTree());
PlatformTestUtil.assertTreeEqual(pane.getTree(), "-Project\n" +
" -PsiDirectory: showClassMembers\n" +
" -PsiDirectory: src\n" +
@@ -395,7 +383,7 @@ public class ProjectViewUpdatingTest extends BaseProjectViewTestCase {
AbstractTreeBuilder builder = pane.getTreeBuilder();
if (builder == null) {
pane.updateFromRoot(false);
PlatformTestUtil.waitUntilBusy(tree);
PlatformTestUtil.waitWhileBusy(tree);
PlatformTestUtil.assertTreeEqual(tree, "-Project\n" +
" -1\n" +
" +01.2\n" +
@@ -1,17 +1,5 @@
/*
* Copyright 2000-2015 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-2017 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 com.intellij.projectView;
@@ -137,7 +125,7 @@ public class StructureViewUpdatingTest extends TestSourceBasedTestCase {
svc.select(innerClassField, true);
PlatformTestUtil.waitUntilBusy(svc.getTree());
PlatformTestUtil.waitWhileBusy(svc.getTree());
PlatformTestUtil.assertTreeEqual(
svc.getTree(),
"-Class2.java\n" +
@@ -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-2017 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 com.intellij.openapi.projectRoots;
@@ -57,7 +45,7 @@ public abstract class JavaSdk extends SdkType implements JavaSdkType {
return JdkUtil.checkForJre(file);
}
/** @deprecated use {@link SdkVersionUtil#detectJdkVersion} (to be removed in IDEA 2019) */
/** @deprecated use {@link SdkVersionUtil#getJdkVersionInfo} (to be removed in IDEA 2019) */
public static String getJdkVersion(@NotNull String sdkHome) {
return SdkVersionUtil.detectJdkVersion(sdkHome);
}
@@ -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-2017 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 com.intellij.testFramework;
@@ -35,6 +23,7 @@ import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.TestOnly;
import org.junit.Assert;
import org.junit.Assume;
import java.io.File;
@@ -169,19 +158,18 @@ public class IdeaTestUtil extends PlatformTestUtil {
}
@TestOnly
public static void setTestVersion(@NotNull final JavaSdkVersion testVersion, @NotNull Module module, @NotNull Disposable parentDisposable) {
ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
final Sdk sdk = rootManager.getSdk();
final String oldVersionString = sdk.getVersionString();
public static void setTestVersion(@NotNull JavaSdkVersion testVersion, @NotNull Module module, @NotNull Disposable parentDisposable) {
Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
Assert.assertNotNull(sdk);
String oldVersionString = sdk.getVersionString();
// hack
((SdkModificator)sdk).setVersionString(testVersion.getDescription());
assert JavaSdk.getInstance().getVersion(sdk) == testVersion;
Assert.assertSame(testVersion, JavaSdk.getInstance().getVersion(sdk));
Disposer.register(parentDisposable, () -> ((SdkModificator)sdk).setVersionString(oldVersionString));
}
@NotNull
public static String requireRealJdkHome() {
String javaHome = SystemProperties.getJavaHome();
@@ -192,7 +180,8 @@ public class IdeaTestUtil extends PlatformTestUtil {
return path;
}
}
//noinspection ConstantConditions
Assume.assumeTrue("Cannot find JDK, checked paths: " + paths, false);
return null;
}
}
}
@@ -1,21 +1,10 @@
/*
* 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-2017 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.openapi.util.Bitness;
import com.intellij.util.lang.JavaVersion;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.service.JpsServiceManager;
@@ -30,18 +19,21 @@ public abstract class JdkVersionDetector {
return JpsServiceManager.getInstance().getService(JdkVersionDetector.class);
}
/**
* Returns java version for JDK located at {@code homePath} in format like<br>
* <tt>java version "1.8.0_40"</tt><br>
* by running '<tt>java -version</tt>' command
* @param homePath path to JDK home directory
* @return version string of {@code null} if version cannot be determined
*/
/** @deprecated use {@link #detectJdkVersionInfo(String)} (to be removed in IDEA 2019) */
@Nullable
public abstract String detectJdkVersion(@NotNull String homePath);
@SuppressWarnings("deprecation")
public String detectJdkVersion(@NotNull String homePath) {
JdkVersionInfo info = detectJdkVersionInfo(homePath);
return info != null ? info.getVersion() : null;
}
/** @deprecated use {@link #detectJdkVersionInfo(String, ActionRunner)} (to be removed in IDEA 2019) */
@Nullable
public abstract String detectJdkVersion(@NotNull String homePath, @NotNull ActionRunner actionRunner);
@SuppressWarnings("deprecation")
public String detectJdkVersion(@NotNull String homePath, @NotNull ActionRunner runner) {
JdkVersionInfo info = detectJdkVersionInfo(homePath, runner);
return info != null ? info.getVersion() : null;
}
@Nullable
public abstract JdkVersionInfo detectJdkVersionInfo(@NotNull String homePath);
@@ -55,22 +47,31 @@ public abstract class JdkVersionDetector {
}
public static final class JdkVersionInfo {
private final String myVersion;
private final Bitness myBitness;
public final JavaVersion version;
public final Bitness bitness;
public JdkVersionInfo(@NotNull String version, @NotNull Bitness bitness) {
myVersion = version;
myBitness = bitness;
public JdkVersionInfo(@NotNull JavaVersion version, @NotNull Bitness bitness) {
this.version = version;
this.bitness = bitness;
}
@NotNull
@Override
public String toString() {
return version + " " + bitness;
}
/** @deprecated use {@link #version} (to be removed in IDEA 2019) */
public String getVersion() {
return myVersion;
return formatVersionString(version);
}
@NotNull
/** @deprecated use {@link #bitness} (to be removed in IDEA 2019) */
public Bitness getBitness() {
return myBitness;
return bitness;
}
}
public static String formatVersionString(@NotNull JavaVersion version) {
return "java version \"" + version + '"';
}
}
@@ -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-2017 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.impl;
@@ -21,6 +9,7 @@ import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.CharsetToolkit;
import com.intellij.util.io.BaseOutputReader;
import com.intellij.util.lang.JavaVersion;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.model.java.JdkVersionDetector;
@@ -44,67 +33,58 @@ public class JdkVersionDetectorImpl extends JdkVersionDetector {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.projectRoots.impl.SdkVersionUtil");
private static final ActionRunner ACTION_RUNNER = r -> SharedThreadPool.getInstance().executeOnPooledThread(r);
@Override
@Nullable
public String detectJdkVersion(@NotNull String homePath) {
return detectJdkVersion(homePath, ACTION_RUNNER);
}
@Nullable
public String detectJdkVersion(@NotNull String homePath, @NotNull ActionRunner runner) {
File rtFile = new File(homePath, "jre/lib/rt.jar");
if (rtFile.isFile()) {
try (JarFile rtJar = new JarFile(rtFile, false)) {
Manifest manifest = rtJar.getManifest();
if (manifest != null) {
String version = manifest.getMainAttributes().getValue("Implementation-Version");
if (version != null) {
return "java version \"" + version + "\"";
}
}
}
catch (IOException e) {
LOG.info(e);
}
}
JdkVersionInfo info = detectJdkVersionInfo(homePath, runner);
return info != null ? info.getVersion() : null;
}
@Override
public JdkVersionInfo detectJdkVersionInfo(@NotNull String homePath) {
return detectJdkVersionInfo(homePath, ACTION_RUNNER);
}
@Nullable
@Override
public JdkVersionInfo detectJdkVersionInfo(@NotNull String homePath, @NotNull ActionRunner runner) {
// Java 1.7+
File releaseFile = new File(homePath, "release");
if (releaseFile.isFile()) {
try {
Properties p = new Properties();
p.load(new FileInputStream(releaseFile));
String version = p.getProperty("JAVA_FULL_VERSION", p.getProperty("JAVA_VERSION"));
if (version != null) {
version = StringUtil.unquoteString(version);
int i = version.indexOf('+');
if (i > 0) {
version = version.substring(0, i);
}
Properties p = new Properties();
try (FileInputStream stream = new FileInputStream(releaseFile)) {
p.load(stream);
String versionString = p.getProperty("JAVA_FULL_VERSION", p.getProperty("JAVA_VERSION"));
if (versionString != null) {
JavaVersion version = JavaVersion.parse(versionString);
String arch = StringUtil.unquoteString(p.getProperty("OS_ARCH", ""));
boolean x64 = "x86_64".equals(arch) || "amd64".equals(arch);
return new JdkVersionInfo("java version \"" + version + "\"", x64 ? Bitness.x64 : Bitness.x32);
return new JdkVersionInfo(version, x64 ? Bitness.x64 : Bitness.x32);
}
}
catch (IOException e) {
LOG.info(e);
catch (IOException | IllegalArgumentException e) {
LOG.info(releaseFile.getPath(), e);
}
}
String javaExe = homePath + File.separator + "bin" + File.separator + (SystemInfo.isWindows ? "java.exe" : "java");
if (new File(javaExe).canExecute()) {
// Java 1.2 - 1.8
File rtFile = new File(homePath, "jre/lib/rt.jar");
if (rtFile.isFile()) {
try (JarFile rtJar = new JarFile(rtFile, false)) {
Manifest manifest = rtJar.getManifest();
if (manifest != null) {
String versionString = manifest.getMainAttributes().getValue("Implementation-Version");
if (versionString != null) {
JavaVersion version = JavaVersion.parse(versionString);
boolean x64 = new File(rtFile.getParent(), "amd64").isDirectory();
return new JdkVersionInfo(version, x64 ? Bitness.x64 : Bitness.x32);
}
}
}
catch (IOException | IllegalArgumentException e) {
LOG.info(rtFile.getPath(), e);
}
}
// last resort
File javaExe = new File(homePath, "bin/" + (SystemInfo.isWindows ? "java.exe" : "java"));
if (javaExe.canExecute()) {
try {
Process process = new ProcessBuilder(javaExe, "-version").redirectErrorStream(true).start();
Process process = new ProcessBuilder(javaExe.getPath(), "-version").redirectErrorStream(true).start();
VersionOutputReader reader = new VersionOutputReader(process.getInputStream(), runner);
try {
reader.waitFor();
@@ -113,10 +93,17 @@ public class JdkVersionDetectorImpl extends JdkVersionDetector {
LOG.info(e);
process.destroy();
}
return reader.getVersionInfo();
if (!reader.myLines.isEmpty()) {
JavaVersion base = JavaVersion.parse(reader.myLines.get(0));
JavaVersion rt = JavaVersion.tryParse(reader.myLines.size() > 2 ? reader.myLines.get(1) : null);
JavaVersion version = rt != null && rt.feature == base.feature && rt.minor == base.minor ? rt : base;
boolean x64 = reader.myLines.stream().anyMatch(s -> s.contains("64-Bit") || s.contains("x86_64") || s.contains("amd64"));
return new JdkVersionInfo(version, x64 ? Bitness.x64 : Bitness.x32);
}
}
catch (IOException e) {
LOG.info(e);
catch (IOException | IllegalArgumentException e) {
LOG.info(javaExe.getPath(), e);
}
}
@@ -150,27 +137,7 @@ public class JdkVersionDetectorImpl extends JdkVersionDetector {
@Override
protected void onTextAvailable(@NotNull String text) {
myLines.add(text);
LOG.debug("text: " + text);
}
@Nullable
public JdkVersionInfo getVersionInfo() {
String version = null;
Bitness arch = Bitness.x32;
for (String line : myLines) {
if (line.contains("version")) {
if (version == null) {
version = line;
}
}
else if (line.contains("64-Bit") || line.contains("x86_64") || line.contains("amd64")) {
arch = Bitness.x64;
}
}
LOG.debug("Returning " + version + " " + arch);
return version != null ? new JdkVersionInfo(version, arch) : null;
LOG.trace("text: " + text);
}
}
}
@@ -1,4 +1,6 @@
// Copyright 2000-2017 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.
/*
* Copyright 2000-2017 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.impl;
import com.intellij.openapi.util.io.FileUtil;
@@ -128,7 +130,9 @@ public class JpsJavaExtensionServiceImpl extends JpsJavaExtensionService {
@Override
public JpsTypedLibrary<JpsSdk<JpsDummyElement>> addJavaSdk(@NotNull JpsGlobal global, @NotNull String name, @NotNull String homePath) {
String version = JdkVersionDetector.getInstance().detectJdkVersion(homePath);
JdkVersionDetector.JdkVersionInfo jdkInfo = JdkVersionDetector.getInstance().detectJdkVersionInfo(homePath);
assert jdkInfo != null : homePath;
String version = JdkVersionDetector.formatVersionString(jdkInfo.version);
JpsTypedLibrary<JpsSdk<JpsDummyElement>> sdk = global.addSdk(name, homePath, version, JpsJavaSdkType.INSTANCE);
File homeDir = new File(FileUtil.toSystemDependentName(homePath));
List<File> roots = JavaSdkUtil.getJdkClassesRoots(homeDir, false);
@@ -1,23 +1,22 @@
// Copyright 2000-2017 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.
/*
* Copyright 2000-2017 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
import com.intellij.openapi.util.Bitness
import com.intellij.openapi.util.SystemInfo
import com.intellij.util.lang.JavaVersion
import org.assertj.core.api.Assertions.assertThat
import org.jetbrains.jps.model.java.JdkVersionDetector
import org.junit.Test
class JdkVersionDetectorTest {
@Test fun detectJdkVersion() {
val jdkHome = System.getProperty("java.home")
val jdkVersion = JdkVersionDetector.getInstance().detectJdkVersion(jdkHome)
assertThat(jdkVersion).contains("\"${SystemInfo.JAVA_VERSION.removeSuffix("-ea")}\"")
}
@Test fun detectJdkVersionInfo() {
val jdkHome = System.getProperty("java.home")
val jdkVersion = JdkVersionDetector.getInstance().detectJdkVersionInfo(jdkHome)
assertThat(jdkVersion?.version).contains("\"${SystemInfo.JAVA_VERSION.removeSuffix("-ea")}\"")
assertThat(jdkVersion?.version?.feature).isEqualTo(JavaVersion.current().feature)
assertThat(jdkVersion?.version?.minor).isEqualTo(JavaVersion.current().minor)
assertThat(jdkVersion?.version?.update).isEqualTo(JavaVersion.current().update)
assertThat(jdkVersion?.bitness).isEqualTo(if (SystemInfo.is64Bit) Bitness.x64 else Bitness.x32)
}
}
@@ -17,7 +17,6 @@ com.intellij.codeInspection.miscGenerics.SuspiciousCollectionsMethodCallsInspect
com.intellij.codeInspection.nullable.NullableStuffInspection
com.intellij.codeInspection.suspiciousNameCombination.SuspiciousNameCombinationInspection
com.intellij.codeInspection.uncheckedWarnings.UncheckedWarningLocalInspection
com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection
com.intellij.codeInspection.varScopeCanBeNarrowed.FieldCanBeLocalInspection
com.intellij.codeInspection.visibility.VisibilityInspection
com.intellij.lang.javascript.inspections.JSMismatchedCollectionQueryUpdateInspection
@@ -116,11 +115,8 @@ com.siyeh.ig.encapsulation.UseOfAnotherObjectsPrivateFieldInspection
com.siyeh.ig.errorhandling.BadExceptionCaughtInspection
com.siyeh.ig.errorhandling.BadExceptionDeclaredInspection
com.siyeh.ig.errorhandling.BadExceptionThrownInspection
com.siyeh.ig.errorhandling.EmptyCatchBlockInspection
com.siyeh.ig.errorhandling.ExceptionFromCatchWhichDoesntWrapInspection
com.siyeh.ig.errorhandling.ThrowCaughtLocallyInspection
com.siyeh.ig.errorhandling.UnusedCatchParameterInspection
com.siyeh.ig.finalization.FinalizeCallsSuperFinalizeInspection
com.siyeh.ig.finalization.FinalizeInspection
com.siyeh.ig.inheritance.InterfaceNeverImplementedInspection
com.siyeh.ig.inheritance.NonProtectedConstructorInAbstractClassInspection
@@ -165,8 +161,6 @@ com.siyeh.ig.naming.PackageNamingConventionInspection
com.siyeh.ig.naming.ParameterNameDiffersFromOverriddenParameterInspection
com.siyeh.ig.naming.ParameterNamingConventionInspection
com.siyeh.ig.naming.QuestionableNameInspection
com.siyeh.ig.naming.StaticMethodNamingConventionInspection
com.siyeh.ig.naming.StaticVariableNamingConventionInspection
com.siyeh.ig.numeric.CastThatLosesPrecisionInspection
com.siyeh.ig.numeric.ImplicitNumericConversionInspection
com.siyeh.ig.numeric.IntegerMultiplicationImplicitCastToLongInspection
@@ -178,7 +172,6 @@ com.siyeh.ig.packaging.PackageWithTooManyClassesInspection
com.siyeh.ig.performance.CallToSimpleGetterInClassInspection
com.siyeh.ig.performance.CallToSimpleSetterInClassInspection
com.siyeh.ig.performance.MethodMayBeStaticInspection
com.siyeh.ig.performance.SizeReplaceableByIsEmptyInspection
com.siyeh.ig.performance.StringConcatenationInLoopsInspection
com.siyeh.ig.performance.StringConstructorInspection
com.siyeh.ig.performance.StringReplaceableByStringBufferInspection
@@ -203,7 +196,6 @@ com.siyeh.ig.style.RedundantImplementsInspection
com.siyeh.ig.style.UnnecessarilyQualifiedInnerClassAccessInspection
com.siyeh.ig.style.UnnecessarilyQualifiedStaticUsageInspection
com.siyeh.ig.style.UnnecessaryBlockStatementInspection
com.siyeh.ig.style.UnnecessaryFinalOnParameterInspection
com.siyeh.ig.style.UnnecessaryFullyQualifiedNameInspection
com.siyeh.ig.style.UnnecessaryParenthesesInspection
com.siyeh.ig.style.UnqualifiedInnerClassAccessInspection
@@ -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-2017 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.intellij.build.impl
@@ -54,9 +42,10 @@ class JdkUtils {
}
else {
jdkDir = getCurrentJdk()
def version = JdkVersionDetector.instance.detectJdkVersion(jdkDir)
if (propertyName.contains("8") && !version.contains("1.8.")) {
messages.error("JDK 1.8 is required to compile the project, but '$propertyName' property and '$envVarName' environment variable aren't defined and default JDK $jdkDir ($version) cannot be used as JDK 1.8")
def jdkInfo = JdkVersionDetector.instance.detectJdkVersionInfo(jdkDir)
if (propertyName.contains("8") && !jdkInfo.version.contains("1.8.")) {
messages.error("JDK 1.8 is required to compile the project, but '$propertyName' property and '$envVarName' environment variable" +
" aren't defined and default JDK $jdkDir ($jdkInfo) cannot be used as JDK 1.8")
return null
}
messages.info("'$envVarName' isn't defined and '$defaultDir' doesn't exist, $propertyName set to $jdkDir")
@@ -16,24 +16,23 @@
package com.intellij.facet;
import com.intellij.openapi.util.JDOMExternalizable;
import com.intellij.facet.ui.FacetEditorContext;
import com.intellij.facet.ui.FacetEditorTab;
import com.intellij.facet.ui.FacetValidatorsManager;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.facet.ui.FacetEditorTab;
import com.intellij.facet.ui.FacetEditorContext;
import com.intellij.facet.ui.FacetValidatorsManager;
import org.jdom.Element;
/**
* Implementations of this interface contain settings of a specific facet.
*
* <p>
* Implement {@link com.intellij.openapi.components.PersistentStateComponent} instead of {@link com.intellij.openapi.util.JDOMExternalizable}
* in your implementation of {@link com.intellij.facet.FacetConfiguration}
* Implement {@link com.intellij.openapi.components.PersistentStateComponent} instead of overriding {@link #readExternal(Element)} and
* {@link #writeExternal(Element)} methods in your implementation of {@link com.intellij.facet.FacetConfiguration}
*
* @author nik
*/
public interface FacetConfiguration extends JDOMExternalizable {
public interface FacetConfiguration {
/**
* Creates editor which will be used to edit this facet configuration
@@ -46,14 +45,14 @@ public interface FacetConfiguration extends JDOMExternalizable {
/**
* @deprecated implement {@link com.intellij.openapi.components.PersistentStateComponent#loadState(Object)} instead
*/
@Override
@Deprecated
void readExternal(final Element element) throws InvalidDataException;
default void readExternal(final Element element) throws InvalidDataException {
}
/**
* @deprecated implement {@link com.intellij.openapi.components.PersistentStateComponent#getState()} instead
*/
@Override
@Deprecated
void writeExternal(final Element element) throws WriteExternalException;
default void writeExternal(final Element element) throws WriteExternalException {
}
}
@@ -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-2017 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 com.intellij.openapi.projectRoots;
@@ -20,6 +8,7 @@ import com.intellij.openapi.projectRoots.impl.SdkVersionUtil;
import com.intellij.openapi.util.io.FileUtil;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.java.JdkVersionDetector;
import java.io.File;
@@ -52,8 +41,7 @@ public class SimpleJavaSdkType extends SdkType implements JavaSdkType {
}
@Override
public void saveAdditionalData(@NotNull SdkAdditionalData additionalData, @NotNull Element additional) {
}
public void saveAdditionalData(@NotNull SdkAdditionalData additionalData, @NotNull Element additional) { }
@Override
public String getBinPath(@NotNull Sdk sdk) {
@@ -87,6 +75,7 @@ public class SimpleJavaSdkType extends SdkType implements JavaSdkType {
@Override
public final String getVersionString(final String sdkHome) {
return SdkVersionUtil.detectJdkVersion(sdkHome);
JdkVersionDetector.JdkVersionInfo jdkInfo = SdkVersionUtil.getJdkVersionInfo(sdkHome);
return jdkInfo != null ? JdkVersionDetector.formatVersionString(jdkInfo.version) : null;
}
}
@@ -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-2017 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 com.intellij.openapi.projectRoots.impl;
@@ -29,13 +17,7 @@ public class SdkVersionUtil {
private SdkVersionUtil() { }
/** @deprecated use {@link #detectJdkVersion(String)} to be removed in IDEA 2018 */
@Nullable
@SuppressWarnings("unused")
public static String readVersionFromProcessOutput(@NotNull String homePath, @NotNull String[] command, String versionLineMarker) {
return JdkVersionDetector.getInstance().detectJdkVersion(homePath, ACTION_RUNNER);
}
/** @deprecated use {@link #getJdkVersionInfo(String)} (to be removed in IDEA 2019) */
@Nullable
public static String detectJdkVersion(@NotNull String homePath) {
return JdkVersionDetector.getInstance().detectJdkVersion(homePath, ACTION_RUNNER);
@@ -16,14 +16,11 @@
package com.intellij.facet.impl.invalid;
import com.intellij.facet.FacetConfiguration;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.serialization.facet.FacetState;
import com.intellij.facet.ui.FacetEditorContext;
import com.intellij.facet.ui.FacetEditorTab;
import com.intellij.facet.ui.FacetValidatorsManager;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.WriteExternalException;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.serialization.facet.FacetState;
/**
* @author nik
@@ -49,14 +46,6 @@ public class InvalidFacetConfiguration implements FacetConfiguration {
};
}
@Override
public void readExternal(Element element) throws InvalidDataException {
}
@Override
public void writeExternal(Element element) throws WriteExternalException {
}
public String getErrorMessage() {
return myErrorMessage;
}
@@ -68,20 +68,15 @@ public class ModuleGroup {
Set<List<String>> moduleAsGroupsPaths = ContainerUtil.map2Set(grouper.getAllModules(), module -> grouper.getModuleAsGroupPath(module));
for (final Module module : grouper.getAllModules()) {
List<String> group = grouper.getGroupPath(module);
if (myGroupPath.equals(group) || isChild(myGroupPath, group) && (recursively || allIntermediatePathsAreFromSet(myGroupPath, group, moduleAsGroupsPaths))) {
if (myGroupPath.equals(group) || isChild(myGroupPath, group) && (recursively || isUnderGroupWithSameNameAsSomeModule(myGroupPath, group, moduleAsGroupsPaths))) {
result.add(module);
}
}
return result;
}
private static boolean allIntermediatePathsAreFromSet(List<String> parent, List<String> descendant, Set<List<String>> set) {
for (int i = parent.size() + 1; i < descendant.size() - 1; i++) {
if (!set.contains(descendant.subList(0, i))) {
return false;
}
}
return true;
private static boolean isUnderGroupWithSameNameAsSomeModule(List<String> parent, List<String> descendant, Set<List<String>> moduleNamesAsGroups) {
return descendant.size() > parent.size() && moduleNamesAsGroups.contains(descendant.subList(0, parent.size() + 1));
}
@NotNull
@@ -90,9 +85,11 @@ public class ModuleGroup {
Set<List<String>> moduleAsGroupsPaths = ContainerUtil.map2Set(grouper.getAllModules(), module -> grouper.getModuleAsGroupPath(module));
for (Module module : grouper.getAllModules()) {
List<String> group = grouper.getGroupPath(module);
if (!moduleAsGroupsPaths.contains(group) && isChild(myGroupPath, group)) {
if (isChild(myGroupPath, group)) {
final List<String> directChild = ContainerUtil.append(myGroupPath, group.get(myGroupPath.size()));
result.add(new ModuleGroup(directChild));
if (!moduleAsGroupsPaths.contains(directChild)) {
result.add(new ModuleGroup(directChild));
}
}
}
@@ -98,6 +98,15 @@ public final class ConsentOptions {
return confirmedConsent == null? Permission.UNDEFINED : confirmedConsent.isAccepted()? Permission.YES : Permission.NO;
}
public boolean setSendingUsageStatsAllowed(boolean allowed) {
final Consent defConsent = loadDefaultConsents().get(STATISTICS_OPTION_ID);
if (defConsent != null && !defConsent.isDeleted()) {
saveConfirmedConsents(Collections.singleton(new ConfirmedConsent(defConsent.getId(), defConsent.getVersion(), allowed, 0L)));
return true;
}
return false;
}
@Nullable
public String getConfirmedConsentsString() {
final Map<String, Consent> defaults = loadDefaultConsents();
@@ -130,7 +130,7 @@ public class StartupUtil {
if (!Main.isHeadless()) {
AppUIUtil.updateWindowIcon(JOptionPane.getRootFrame());
AppUIUtil.registerBundledFonts();
AppUIUtil.showEndUserAgreement();
AppUIUtil.showUserAgreementAndConsentsIfNeeded();
}
appStarter.start(newConfigFolder);
@@ -15,11 +15,11 @@
*/
package com.intellij.internal.statistic.actions;
import com.intellij.internal.statistic.utils.StatisticsUploadAssistant;
import com.intellij.internal.statistic.ApplicationStatisticsPersistenceComponent;
import com.intellij.internal.statistic.connect.StatisticsResult;
import com.intellij.internal.statistic.connect.StatisticsService;
import com.intellij.internal.statistic.ApplicationStatisticsPersistenceComponent;
import com.intellij.internal.statistic.persistence.UsageStatisticsPersistenceComponent;
import com.intellij.internal.statistic.utils.StatisticsUploadAssistant;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.application.ApplicationManager;
@@ -45,10 +45,14 @@ public class SendStatisticsAction extends AnAction {
@Override
public void run(@NotNull ProgressIndicator indicator) {
UsageStatisticsPersistenceComponent statisticsPersistenceComponent = UsageStatisticsPersistenceComponent.getInstance();
boolean sendAllowed = statisticsPersistenceComponent.isAllowed();
statisticsPersistenceComponent.setAllowed(true);
ApplicationStatisticsPersistenceComponent.persistOpenedProjects();
statisticsPersistenceComponent.setAllowed(sendAllowed);
final boolean sendAllowed = statisticsPersistenceComponent.isAllowed();
try {
statisticsPersistenceComponent.setAllowed(true);
ApplicationStatisticsPersistenceComponent.persistOpenedProjects();
}
finally {
statisticsPersistenceComponent.setAllowed(sendAllowed);
}
StatisticsService service = StatisticsUploadAssistant.getStatisticsService();
final StatisticsResult result = service.send();
@@ -1,76 +0,0 @@
// Copyright 2000-2017 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 com.intellij.internal.statistic.configurable;
import com.intellij.internal.statistic.persistence.UsageStatisticsPersistenceComponent;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.SearchableConfigurable;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
public class StatisticsConfigurable implements SearchableConfigurable, Configurable.NoScroll {
private boolean modifiedByDefault;
public StatisticsConfigurable() {
this(false);
}
public StatisticsConfigurable(boolean isModifiedByDefault) {
modifiedByDefault = isModifiedByDefault;
}
private StatisticsConfigurationComponent myConfig;
@Nls
public String getDisplayName() {
return "Usage Statistics";
}
@Override
@Nullable
@NonNls
public String getHelpTopic() {
return "preferences.usage.statictics";
}
public JComponent createComponent() {
myConfig = new StatisticsConfigurationComponent();
return myConfig.getJComponent();
}
public boolean isModified() {
final UsageStatisticsPersistenceComponent persistenceComponent = UsageStatisticsPersistenceComponent.getInstance();
return myConfig.isAllowed() != persistenceComponent.isAllowed() ||
myConfig.getPeriod() != persistenceComponent.getPeriod() ||
modifiedByDefault;
}
public void apply() throws ConfigurationException {
final UsageStatisticsPersistenceComponent persistenceComponent = UsageStatisticsPersistenceComponent.getInstance();
//persistenceComponent.setPeriod(myConfig.getPeriod());
persistenceComponent.setAllowed(myConfig.isAllowed());
persistenceComponent.setShowNotification(false);
modifiedByDefault = false;
}
public void reset() {
myConfig.reset();
}
public void disposeUIResources() {
myConfig = null;
}
@NotNull
@Override
public String getId() {
return "usage.statistics";
}
}
@@ -1,74 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.internal.statistic.configurable.StatisticsConfigurationComponent">
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="335" height="268"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<vspacer id="4250b">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<grid id="ef0a7" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="2f6db" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="6149c" class="javax.swing.JCheckBox" binding="myAllowToSendUsagesCheckBox" default-binding="true">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<selected value="true"/>
<text value=""/>
</properties>
</component>
</children>
</grid>
<component id="67819" class="javax.swing.JLabel" binding="myLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
</children>
</grid>
<component id="9c047" class="javax.swing.JLabel" binding="myTitle">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<hspacer id="244b1">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
</children>
</grid>
<buttonGroups>
<group name="buttonGroup">
<member id="181ac"/>
<member id="181ac"/>
<member id="1f52"/>
<member id="c628d"/>
</group>
</buttonGroups>
</form>
@@ -1,71 +0,0 @@
// Copyright 2000-2017 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 com.intellij.internal.statistic.configurable;
import com.intellij.internal.statistic.StatisticsBundle;
import com.intellij.internal.statistic.connect.StatisticsService;
import com.intellij.internal.statistic.persistence.UsageStatisticsPersistenceComponent;
import com.intellij.internal.statistic.utils.StatisticsUploadAssistant;
import com.intellij.openapi.application.ApplicationInfo;
import com.intellij.openapi.application.ApplicationNamesInfo;
import com.intellij.ui.RelativeFont;
import javax.swing.*;
import java.util.Map;
public class StatisticsConfigurationComponent {
private JPanel myMainPanel;
private JLabel myTitle;
private JCheckBox myAllowToSendUsagesCheckBox;
private JLabel myLabel;
public StatisticsConfigurationComponent() {
String product = ApplicationNamesInfo.getInstance().getFullProductName();
String company = ApplicationInfo.getInstance().getCompanyName();
myTitle.setText(StatisticsBundle.message("stats.title", product, company));
myLabel.setText(StatisticsBundle.message("stats.config.details", company));
RelativeFont.SMALL.install(myLabel);
myAllowToSendUsagesCheckBox.setText(StatisticsBundle.message("stats.config.allow.send.stats.text", company));
// Let current statistics service override labels
StatisticsService service = StatisticsUploadAssistant.getStatisticsService();
if (service != null) {
Map<String, String> overrides = service.getStatisticsConfigurationLabels();
if (overrides != null) {
String s = overrides.get(StatisticsService.TITLE);
if (s != null) {
myTitle.setText(s);
}
s = overrides.get(StatisticsService.DETAILS);
if (s != null) {
myLabel.setText(s);
}
s = overrides.get(StatisticsService.ALLOW_CHECKBOX);
if (s != null) {
myAllowToSendUsagesCheckBox.setText(s);
}
}
}
myTitle.setText(myTitle.getText().replace("%company%", company));
myLabel.setText(myLabel.getText().replace("%company%", company));
myAllowToSendUsagesCheckBox.setText(myAllowToSendUsagesCheckBox.getText().replace("%company%", company));
}
public JPanel getJComponent() {
return myMainPanel;
}
public boolean isAllowed() {
return myAllowToSendUsagesCheckBox.isSelected();
}
public void reset() {
myAllowToSendUsagesCheckBox.setSelected(UsageStatisticsPersistenceComponent.getInstance().isAllowed());
}
public SendPeriod getPeriod() {
return SendPeriod.DAILY;
}
}
@@ -2,6 +2,7 @@
package com.intellij.internal.statistic.persistence;
import com.intellij.ide.gdpr.ConsentOptions;
import com.intellij.internal.statistic.beans.ConvertUsagesUtil;
import com.intellij.internal.statistic.beans.GroupDescriptor;
import com.intellij.internal.statistic.beans.UsageDescriptor;
@@ -25,7 +26,6 @@ import java.util.Set;
public class UsageStatisticsPersistenceComponent extends BasicSentUsagesPersistenceComponent
implements NamedComponent, PersistentStateComponent<Element> {
@NonNls private boolean isAllowed = false;
@NonNls private boolean isShowNotification = true;
@NotNull private SendPeriod myPeriod = SendPeriod.DAILY;
@@ -73,8 +73,11 @@ public class UsageStatisticsPersistenceComponent extends BasicSentUsagesPersiste
setSentTime(0);
}
// compatibility: if was previously allowed, transfer the setting to the new place
final String isAllowedValue = element.getAttributeValue(IS_ALLOWED_ATTR);
setAllowed(!StringUtil.isEmptyOrSpaces(isAllowedValue) && Boolean.parseBoolean(isAllowedValue));
if (!StringUtil.isEmptyOrSpaces(isAllowedValue) && Boolean.parseBoolean(isAllowedValue)) {
setAllowed(true);
}
final String isShowNotificationValue = element.getAttributeValue(SHOW_NOTIFICATION_ATTR);
setShowNotification(StringUtil.isEmptyOrSpaces(isShowNotificationValue) || Boolean.parseBoolean(isShowNotificationValue));
@@ -100,9 +103,9 @@ public class UsageStatisticsPersistenceComponent extends BasicSentUsagesPersiste
element.setAttribute(LAST_TIME_ATTR, String.valueOf(lastTimeSent));
}
if (isAllowed()) {
element.setAttribute(IS_ALLOWED_ATTR, "true");
}
//if (isAllowed()) {
// element.setAttribute(IS_ALLOWED_ATTR, "true");
//}
if (!isShowNotification()) {
element.setAttribute(SHOW_NOTIFICATION_ATTR, "false");
}
@@ -131,12 +134,12 @@ public class UsageStatisticsPersistenceComponent extends BasicSentUsagesPersiste
}
public void setAllowed(boolean allowed) {
isAllowed = allowed;
ConsentOptions.getInstance().setSendingUsageStatsAllowed(allowed);
}
@Override
public boolean isAllowed() {
return isAllowed;
return ConsentOptions.getInstance().isSendingUsageStatsAllowed() == ConsentOptions.Permission.YES;
}
public void setShowNotification(boolean showNotification) {
@@ -1,19 +1,18 @@
package com.intellij.internal.statistic.updater;
import com.intellij.internal.statistic.configurable.StatisticsConfigurable;
import com.intellij.ide.gdpr.Consent;
import com.intellij.ide.gdpr.ConsentOptions;
import com.intellij.internal.statistic.connect.StatisticsService;
import com.intellij.internal.statistic.persistence.UsageStatisticsPersistenceComponent;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationListener;
import com.intellij.notification.Notifications;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.options.ShowSettingsUtil;
import com.intellij.openapi.wm.IdeFrame;
import com.intellij.openapi.wm.ex.WindowManagerEx;
import com.intellij.ui.AppUIUtil;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import java.util.Collection;
public class StatisticsNotificationManager {
@@ -56,9 +55,10 @@ public class StatisticsNotificationManager {
notification.expire();
}
else if ("settings".equals(description)) {
final ShowSettingsUtil util = ShowSettingsUtil.getInstance();
IdeFrame ideFrame = WindowManagerEx.getInstanceEx().findFrameFor(null);
util.editConfigurable((JFrame)ideFrame, new StatisticsConfigurable(true));
final Collection<Consent> result = AppUIUtil.confirmConsentOptions(ConsentOptions.getInstance().getConsents().first);
if (result != null) {
ConsentOptions.getInstance().setConsents(result);
}
notification.expire();
}
}
@@ -254,7 +254,7 @@ public class AppUIUtil {
return iconPath;
}
public static void showEndUserAgreement() {
public static void showUserAgreementAndConsentsIfNeeded() {
if (ApplicationInfoImpl.getShadowInstance().isVendorJetBrains()) {
EndUserAgreement.Document agreement = EndUserAgreement.getLatestDocument();
if (!agreement.isAccepted()) {
@@ -415,9 +415,6 @@
<statistics.usagesCollector implementation="com.intellij.internal.statistic.customUsageCollectors.ideSettings.IdeInitialConfigUsageCollectors$DownloadedPlugins"/>
<statistics.usagesCollector implementation="com.intellij.openapi.editor.colors.impl.EditorColorSchemesUsagesCollector"/>
<applicationConfigurable parentId="preferences.general" instance="com.intellij.internal.statistic.configurable.StatisticsConfigurable" id="usage.statistics"
displayName="Usage Statistics"/>
<vfs.local.pluggableFileWatcher implementation="com.intellij.openapi.vfs.impl.local.NativeFileWatcherImpl" />
<virtualFileSystem key="dummy" implementationClass="com.intellij.openapi.vfs.ex.dummy.DummyFileSystem"/>
@@ -1,4 +1,4 @@
<!-- 1.5 -->
<!-- 1.7 -->
<head>
<meta charset="UTF-8">
</head>
@@ -12,7 +12,7 @@
<p>This Policy may be amended from time to time. The respective latest version of the policy at the
point of time of the purchase/registration of a <strong>JetBrains Software Product</strong>
(whichever occurs later) shall apply. The data controller is JetBrains s.r.o., Praha 4, Na hřebenech
II 1718/10, PSČ 147 00, Česká republika
II 1718/10, PSČ 140 00, Česká republika
</p>
<p>In this Privacy Policy, we describe the type of data, including personal data (collectively, “data”),
@@ -297,9 +297,6 @@
Website works
</li>
<li>For security purposes</li>
<li>Make sure you connect to the right service on our Website when we make any changes to the way the
Website works
</li>
</ul>
<p>Accepting these cookies is a condition of using the Website, so if you prevent these cookies we can't
@@ -0,0 +1,9 @@
[
{
"consentId": "rsch.send.usage.stat",
"version": "1.0",
"text": "I consent to submit anonymous usage statistics to help JetBrains improve their products. I agree that the following information will be sent to JetBrains and processed in accordance with JetBrains Privacy Policy https://www.jetbrains.com/company/privacy.html\n * Information about which product features are used\n * General statistics (number of files, file types) of the solutions I am working on\n * General information about my hardware configuration (for example, amount of RAM, CPU speed and number of cores)\n * General information about my software configuration (for example, OS version)\nI can revoke my consent at any time in this Data Sharing Options dialog available at Help | Data Sharing Options",
"printableName": "Send anonymous usage statistics to JetBrains",
"accepted": "false"
}
]
@@ -60,9 +60,25 @@ class GroupModulesByQualifiedNamesTest : PlatformTestCase() {
fun `test module as a group`() {
val module1 = createModule("a.foo")
val module2 = createModule("a.foo.bar")
val module3 = createModule("a.foo.bar.baz")
assertEquals("foo", grouper.getShortenedName(module1))
assertEquals("bar", grouper.getShortenedName(module2))
assertEquals("baz", grouper.getShortenedName(module3))
val parentGroup = ModuleGroup(listOf("a"))
assertSameElements(parentGroup.modulesInGroup(grouper, false), module1, module2, module3)
assertSameElements(parentGroup.modulesInGroup(grouper, true), module1, module2, module3)
assertEmpty(parentGroup.childGroups(grouper))
}
fun `test module as a group with deep ancestor`() {
val module1 = createModule("a.foo")
val module2 = createModule("a.foo.bar.baz")
assertEquals("foo", grouper.getShortenedName(module1))
assertEquals("baz", grouper.getShortenedName(module2))
val parentGroup = ModuleGroup(listOf("a"))
assertSameElements(parentGroup.modulesInGroup(grouper, false), module1, module2)
@@ -1,17 +1,5 @@
/*
* Copyright 2000-2015 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-2017 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 com.intellij.projectView;
@@ -42,7 +30,7 @@ public class TestProjectTreeStructure extends AbstractProjectTreeStructure imple
public void checkNavigateFromSourceBehaviour(PsiElement element, VirtualFile virtualFile, AbstractProjectViewPSIPane pane) {
Assert.assertNull(ProjectViewTestUtil.getNodeForElement(element, pane));
pane.select(element, virtualFile, true);
PlatformTestUtil.waitUntilBusy(pane.getTree());
PlatformTestUtil.waitWhileBusy(pane.getTree());
Assert.assertTrue(ProjectViewTestUtil.isExpanded(element, pane));
}
@@ -50,7 +38,7 @@ public class TestProjectTreeStructure extends AbstractProjectTreeStructure imple
final AbstractProjectViewPSIPane pane = new TestProjectViewPSIPane(myProject, this, 9);
pane.createComponent();
Disposer.register(this, pane);
PlatformTestUtil.waitUntilBusy(pane.getTree());
PlatformTestUtil.waitWhileBusy(pane.getTree());
return pane;
}
@@ -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-2017 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 com.intellij.testFramework;
@@ -258,7 +246,7 @@ public class PlatformTestUtil {
public static void expand(JTree tree, int... rows) {
for (int row : rows) {
tree.expandRow(row);
waitUntilBusy(tree);
waitWhileBusy(tree);
}
}
@@ -284,7 +272,7 @@ public class PlatformTestUtil {
}
@TestOnly
public static void waitUntilBusy(JTree tree) {
public static void waitWhileBusy(JTree tree) {
assert EventQueue.isDispatchThread();
long millis = 10000L + System.currentTimeMillis();
while (isBusy(tree)) {
@@ -148,8 +148,8 @@ open class GuiTestCase {
* is a Mac native.
*/
fun chooseFileInFileChooser(path: String, timeout: Long = defaultTimeout) {
val macNativeFileChooser = SystemInfo.isMac() && (System.getProperty("ide.mac.file.chooser.native", "true").toLowerCase() == "true")
if (!macNativeFileChooser) {
val macNativeFileChooser = SystemInfo.isMac() && (System.getProperty("ide.mac.file.chooser.native", "true").toLowerCase() == "false")
if (macNativeFileChooser) {
MacFileChooserDialogFixture(robot()).selectByPath(path)
}
else {
@@ -5,6 +5,7 @@ package com.intellij.util.lang;
import com.intellij.openapi.util.text.StringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
@@ -129,6 +130,8 @@ public final class JavaVersion {
return current;
}
private static final int MAX_ACCEPTED_VERSION = 25; // sanity check
/**
* <p>Parses a Java version string.</p>
*
@@ -144,7 +147,7 @@ public final class JavaVersion {
*/
public static @NotNull JavaVersion parse(@NotNull String versionString) throws IllegalArgumentException {
// trimming
String str = versionString;
String str = versionString.trim();
if (str.contains("Runtime Environment")) {
int p = str.indexOf("(build ");
if (p > 0) str = str.substring(p);
@@ -169,7 +172,7 @@ public final class JavaVersion {
int feature = Integer.parseInt(numbers.get(0)), minor = 0, update = 0, build = 0;
boolean ea = false;
if (feature > 8 && feature < 50 /*sanity check*/) {
if (feature > 8 && feature < MAX_ACCEPTED_VERSION) {
// Java 9+
p = 1;
while (p < separators.size() && ".".equals(separators.get(p))) p++;
@@ -195,7 +198,7 @@ public final class JavaVersion {
else if (feature == 1 && numbers.size() > 1 && separators.size() > 1 && ".".equals(separators.get(1))) {
// Java 1.0 .. 1.8
feature = Integer.parseInt(numbers.get(1));
if (feature <= 8) {
if (feature <= MAX_ACCEPTED_VERSION) {
if (numbers.size() > 2 && separators.size() > 2 && ".".equals(separators.get(2))) {
minor = Integer.parseInt(numbers.get(2));
if (numbers.size() > 3 && separators.size() > 3 && "_".equals(separators.get(3))) {
@@ -226,4 +229,18 @@ public final class JavaVersion {
private static boolean startsWithWord(String s, String word) {
return s.startsWith(word) && (s.length() == word.length() || !Character.isLetterOrDigit(s.charAt(word.length())));
}
/**
* A safe version of {@link #parse(String)} - returns {@code null} if can't parse a version string.
*/
public static @Nullable JavaVersion tryParse(String versionString) {
if (versionString != null) {
try {
return parse(versionString);
}
catch (IllegalArgumentException ignored) { }
}
return null;
}
}
@@ -23,6 +23,7 @@ class JavaVersionTest {
@Test fun `1_8_0_45-internal`() = doTest("1.8.0_45-internal", 8, 0, 45, 0, true)
@Test fun `1_8_0_121-2-whatever-b11`() = doTest("1.8.0_121-2-whatever-b11", 8, 0, 121, 11)
@Test fun `1_8_0_121-(big-number)-b11`() = doTest("1.8.0_121-99${Long.MAX_VALUE}-b11", 8, 0, 121, 11)
@Test fun `1_10`() = doTest("1.10", 10)
@Test fun `9`() = doTest("9", 9)
@Test fun `9-ea`() = doTest("9-ea", 9, 0, 0, 0, true)
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2017 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,21 +16,26 @@
package com.siyeh.ig.encapsulation;
import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiTreeUtil;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.psiutils.MethodUtils;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
public class UseOfAnotherObjectsPrivateFieldInspectionBase
extends BaseInspection {
public class UseOfAnotherObjectsPrivateFieldInspectionBase extends BaseInspection {
@SuppressWarnings({"PublicField"})
public boolean ignoreSameClass = false;
@SuppressWarnings({"PublicField"})
public boolean ignoreInnerClasses = false;
@SuppressWarnings({"PublicField"})
public boolean ignoreEquals = false;
@@ -56,34 +61,36 @@ public class UseOfAnotherObjectsPrivateFieldInspectionBase
@Override
public JComponent createOptionsPanel() {
final MultipleCheckboxOptionsPanel panel =
new MultipleCheckboxOptionsPanel(this);
panel.addCheckbox(InspectionGadgetsBundle.message(
"ignore.accesses.from.the.same.class"), "ignoreSameClass");
panel.addCheckbox(InspectionGadgetsBundle.message(
"ignore.accesses.from.equals.method"), "ignoreEquals");
final MultipleCheckboxOptionsPanel panel = new MultipleCheckboxOptionsPanel(this);
final JCheckBox box = panel.addCheckboxEx(InspectionGadgetsBundle.message("ignore.accesses.from.the.same.class"), "ignoreSameClass");
panel.addDependentCheckBox("Ignore accesses from inner classes", "ignoreInnerClasses", box);
panel.addCheckbox(InspectionGadgetsBundle.message("ignore.accesses.from.equals.method"), "ignoreEquals");
return panel;
}
@Override
public void writeSettings(@NotNull Element node) throws WriteExternalException {
// this inspection uses old style serialization, make sure newly introduced setting field does not change profile.
defaultWriteSettings(node, "ignoreInnerClasses");
writeBooleanOption(node, "ignoreInnerClasses", false);
}
@Override
public BaseInspectionVisitor buildVisitor() {
return new UseOfAnotherObjectsPrivateFieldVisitor();
}
private class UseOfAnotherObjectsPrivateFieldVisitor
extends BaseInspectionVisitor {
private class UseOfAnotherObjectsPrivateFieldVisitor extends BaseInspectionVisitor {
@Override
public void visitReferenceExpression(
@NotNull PsiReferenceExpression expression) {
public void visitReferenceExpression(@NotNull PsiReferenceExpression expression) {
super.visitReferenceExpression(expression);
final PsiExpression qualifier = expression.getQualifierExpression();
if (qualifier == null || qualifier instanceof PsiThisExpression) {
return;
}
if (ignoreEquals) {
final PsiMethod method =
PsiTreeUtil.getParentOfType(expression, PsiMethod.class);
final PsiMethod method = PsiTreeUtil.getParentOfType(expression, PsiMethod.class);
if (MethodUtils.isEquals(method)) {
return;
}
@@ -94,10 +101,10 @@ public class UseOfAnotherObjectsPrivateFieldInspectionBase
}
final PsiField field = (PsiField)referent;
if (ignoreSameClass) {
final PsiClass parent =
PsiTreeUtil.getParentOfType(expression, PsiClass.class);
final PsiClass parent = PsiTreeUtil.getParentOfType(expression, PsiClass.class);
final PsiClass containingClass = field.getContainingClass();
if (parent != null && parent.equals(containingClass)) {
if (parent != null && (parent.equals(containingClass) ||
ignoreInnerClasses && PsiTreeUtil.isAncestor(containingClass, parent, true))) {
return;
}
}
@@ -108,8 +115,7 @@ public class UseOfAnotherObjectsPrivateFieldInspectionBase
if (field.hasModifierProperty(PsiModifier.STATIC)) {
return;
}
final PsiElement fieldNameElement =
expression.getReferenceNameElement();
final PsiElement fieldNameElement = expression.getReferenceNameElement();
if (fieldNameElement == null) {
return;
}
@@ -10,6 +10,7 @@ using proxies.
<p>
Use the first checkbox below to ignore accesses from the same class and only report accesses
from inner or outer classes.
To ignore accesses from inner classes also, use the nested checkbox.
<p>
Use the second checkbox below to ignore accesses from an <b>equals()</b> method.
<p>
@@ -1,16 +0,0 @@
package com.siyeh.igtest.encapsulation;
public class UseOfAnotherObjectsPrivateFieldInspection {
public int foo;
protected int bar;
private int baz;
public void fooBar(UseOfAnotherObjectsPrivateFieldInspection copy)
{
foo = copy.foo;
bar = copy.bar;
baz = copy.baz;
foo = this.baz;
foo = baz;
}
}
@@ -0,0 +1,33 @@
/*
* Copyright 2000-2017 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 com.siyeh.igtest.encapsulation;
public class UseOfAnotherObjectsPrivateField {
public int foo;
protected int bar;
private int baz;
public void fooBar(UseOfAnotherObjectsPrivateField copy)
{
foo = copy.foo;
bar = copy.bar;
baz = copy.baz;
foo = this.baz;
foo = baz;
}
class Inside {
int f(UseOfAnotherObjectsPrivateField pugnacious) {
return pugnacious.baz;
}
}
}
class SomewhereElse {
void m(UseOfAnotherObjectsPrivateField tenacious) {
tenacious.<warning descr="Direct access of non-public field 'bar' on another object">bar</warning> = 1;
tenacious.foo = 2;
}
}
@@ -0,0 +1,27 @@
/*
* Copyright 2000-2017 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 com.siyeh.ig.encapsulation;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.siyeh.ig.LightInspectionTestCase;
import org.jetbrains.annotations.Nullable;
/**
* @author Bas Leijdekkers
*/
public class UseOfAnotherObjectsPrivateFieldInspectionTest extends LightInspectionTestCase {
public void testUseOfAnotherObjectsPrivateField() {
doTest();
}
@Nullable
@Override
protected InspectionProfileEntry getInspection() {
final UseOfAnotherObjectsPrivateFieldInspection inspection = new UseOfAnotherObjectsPrivateFieldInspection();
inspection.ignoreSameClass = true;
inspection.ignoreInnerClasses = true;
return inspection;
}
}
@@ -20,9 +20,6 @@ import com.intellij.facet.ui.FacetEditorContext;
import com.intellij.facet.ui.FacetEditorTab;
import com.intellij.facet.ui.FacetValidatorsManager;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.WriteExternalException;
import org.jdom.Element;
import org.jetbrains.jps.appengine.model.PersistenceApi;
import org.jetbrains.jps.appengine.model.impl.AppEngineModuleExtensionProperties;
@@ -40,12 +37,6 @@ public class AppEngineFacetConfiguration implements FacetConfiguration, Persiste
};
}
public void readExternal(Element element) throws InvalidDataException {
}
public void writeExternal(Element element) throws WriteExternalException {
}
public AppEngineModuleExtensionProperties getState() {
return myProperties;
}
@@ -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-2017 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 com.intellij.lang.properties;
@@ -115,7 +103,7 @@ public class PropertiesProjectViewTest extends LightPlatformCodeInsightFixtureTe
PsiFile psiFile = getPsiManager().findFile(myFixture.findFileInTempDir(getTestName(true) + "/xxx.properties"));
assert psiFile != null;
pane.select(psiFile, psiFile.getVirtualFile(), sortByType);
PlatformTestUtil.waitUntilBusy(pane.getTree());
PlatformTestUtil.waitWhileBusy(pane.getTree());
return pane;
}
}
@@ -3,6 +3,7 @@ package com.jetbrains.python;
import com.intellij.navigation.ItemPresentation;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.testFramework.PlatformTestUtil;
import com.jetbrains.python.fixtures.PyTestCase;
import com.jetbrains.python.psi.PyFunction;
import com.jetbrains.python.structureView.PyStructureViewElement;
@@ -134,6 +135,7 @@ public class PyStructureViewTest extends PyTestCase {
private void doTest(final String expected, final boolean inherited) {
myFixture.testStructureView(component -> {
component.setActionActive("SHOW_INHERITED", !inherited);
PlatformTestUtil.waitWhileBusy(component.getTree());
assertTreeEqual(component.getTree(), expected);
});
}