mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
less class loading on startup
GitOrigin-RevId: 3028fee91f62f2820182bc8257c0fe4b7e4f3c3e
This commit is contained in:
committed by
intellij-monorepo-bot
parent
4dc0c5ad96
commit
13e63ea2ec
@@ -5,7 +5,7 @@ import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.ClassLoaderUtil;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.io.FileUtilRt;
|
||||
import com.intellij.util.lang.UrlClassLoader;
|
||||
import com.intellij.util.text.StringTokenizer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -121,7 +121,7 @@ public class BootstrapClassLoaderUtil extends ClassUtilCore {
|
||||
if (files == null) return;
|
||||
|
||||
for (File file : files) {
|
||||
if (FileUtil.isJarOrZip(file)) {
|
||||
if (FileUtilRt.isJarOrZip(file)) {
|
||||
URL url = file.toURI().toURL();
|
||||
if (!selfRootUrl.equals(url)) {
|
||||
classPath.add(url);
|
||||
|
||||
@@ -4,7 +4,7 @@ package com.intellij.idea;
|
||||
import com.intellij.ide.Bootstrap;
|
||||
import com.intellij.openapi.application.JetBrainsProtocolHandler;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ArrayUtilRt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -33,7 +33,7 @@ public class Main {
|
||||
|
||||
private static final String AWT_HEADLESS = "java.awt.headless";
|
||||
private static final String PLATFORM_PREFIX_PROPERTY = "idea.platform.prefix";
|
||||
private static final String[] NO_ARGS = ArrayUtil.EMPTY_STRING_ARRAY;
|
||||
private static final String[] NO_ARGS = ArrayUtilRt.EMPTY_STRING_ARRAY;
|
||||
private static final List<String> HEADLESS_COMMANDS = Arrays.asList(
|
||||
"ant", "duplocate", "traverseUI", "buildAppcodeCache", "format", "keymap", "update", "inspections", "intentions");
|
||||
private static final List<String> GUI_COMMANDS = Arrays.asList("diff", "merge");
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.intellij.openapi.extensions.impl.PicoPluginExtensionInitializationExc
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.*;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.io.FileUtilRt;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.util.text.StringUtilRt;
|
||||
import com.intellij.serialization.SerializationException;
|
||||
@@ -829,7 +830,7 @@ public class PluginManagerCore {
|
||||
descriptor = descriptor1;
|
||||
}
|
||||
}
|
||||
else if (FileUtil.isJarOrZip(f, false)) {
|
||||
else if (FileUtilRt.isJarOrZip(f, false)) {
|
||||
if (files.length == 1) {
|
||||
pluginJarFiles = Collections.singletonList(f);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.ThrowableComputable;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.io.FileUtilRt;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.Url;
|
||||
@@ -229,7 +230,7 @@ public class PluginLogo {
|
||||
@NotNull LazyPluginLogoIcon lazyIcon,
|
||||
@NotNull File path,
|
||||
boolean put) {
|
||||
if (!FileUtil.isJarOrZip(path) || !path.exists()) {
|
||||
if (!FileUtilRt.isJarOrZip(path) || !path.exists()) {
|
||||
return false;
|
||||
}
|
||||
try (ZipFile zipFile = new ZipFile(path)) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.intellij.ide.plugins.IdeaPluginDescriptor;
|
||||
import com.intellij.openapi.application.JetBrainsProtocolHandler;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.io.FileUtilRt;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -106,7 +106,7 @@ public class PluginLogoApi {
|
||||
|
||||
@Nullable
|
||||
private Icon tryLoadJarIcon(@NotNull File path) {
|
||||
if (!FileUtil.isJarOrZip(path) || !path.exists()) {
|
||||
if (!FileUtilRt.isJarOrZip(path) || !path.exists()) {
|
||||
return null;
|
||||
}
|
||||
try (ZipFile zipFile = new ZipFile(path)) {
|
||||
|
||||
@@ -54,6 +54,20 @@ public class FileUtilRt {
|
||||
|
||||
private static String ourCanonicalTempPathCache;
|
||||
|
||||
public static boolean isJarOrZip(@NotNull File file) {
|
||||
return isJarOrZip(file, true);
|
||||
}
|
||||
|
||||
public static boolean isJarOrZip(@NotNull File file, boolean isCheckIsDirectory) {
|
||||
if (isCheckIsDirectory && file.isDirectory()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// do not use getName to avoid extra String creation (File.getName() calls substring)
|
||||
final String path = file.getPath();
|
||||
return StringUtilRt.endsWithIgnoreCase(path, ".jar") || StringUtilRt.endsWithIgnoreCase(path, ".zip");
|
||||
}
|
||||
|
||||
protected interface SymlinkResolver {
|
||||
@NotNull
|
||||
String resolveSymlinksAndCanonicalize(@NotNull String path, char separatorChar, boolean removeLastSlash);
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
package com.intellij.openapi.application;
|
||||
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.PropertiesUtil;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.SystemInfoRt;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ArrayUtilRt;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.SystemProperties;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.io.URLUtil;
|
||||
import com.intellij.util.lang.UrlClassLoader;
|
||||
import com.sun.jna.TypeMapper;
|
||||
@@ -55,7 +57,9 @@ public class PathManager {
|
||||
private static final String SYSTEM_FOLDER = "system";
|
||||
private static final String PATHS_SELECTOR = System.getProperty(PROPERTY_PATHS_SELECTOR);
|
||||
|
||||
private static final Pattern PROPERTY_REF = Pattern.compile("\\$\\{(.+?)}");
|
||||
private static class Lazy {
|
||||
private static final Pattern PROPERTY_REF = Pattern.compile("\\$\\{(.+?)}");
|
||||
}
|
||||
|
||||
private static String ourHomePath;
|
||||
private static String[] ourBinDirectories;
|
||||
@@ -89,12 +93,12 @@ public class PathManager {
|
||||
else if (insideIde) {
|
||||
ourHomePath = getHomePathFor(PathManager.class);
|
||||
if (ourHomePath == null) {
|
||||
String advice = SystemInfo.isMac ? "reinstall the software." : "make sure bin/idea.properties is present in the installation directory.";
|
||||
String advice = SystemInfoRt.isMac ? "reinstall the software." : "make sure bin/idea.properties is present in the installation directory.";
|
||||
throw new RuntimeException("Could not find installation home path. Please " + advice);
|
||||
}
|
||||
}
|
||||
|
||||
if (ourHomePath != null && SystemInfo.isWindows) {
|
||||
if (ourHomePath != null && SystemInfoRt.isWindows) {
|
||||
ourHomePath = canonicalPath(ourHomePath);
|
||||
}
|
||||
|
||||
@@ -128,10 +132,10 @@ public class PathManager {
|
||||
|
||||
@NotNull
|
||||
private static String[] getBinDirectories(@NotNull File root) {
|
||||
List<String> binDirs = ContainerUtil.newSmartList();
|
||||
List<String> binDirs = new SmartList<>();
|
||||
|
||||
String[] subDirs = {BIN_FOLDER, "community/bin", "ultimate/community/bin"};
|
||||
String osSuffix = SystemInfo.isWindows ? "win" : SystemInfo.isMac ? "mac" : "linux";
|
||||
String osSuffix = SystemInfoRt.isWindows ? "win" : SystemInfoRt.isMac ? "mac" : "linux";
|
||||
|
||||
for (String subDir : subDirs) {
|
||||
File dir = new File(root, subDir);
|
||||
@@ -144,7 +148,7 @@ public class PathManager {
|
||||
}
|
||||
}
|
||||
|
||||
return ArrayUtil.toStringArray(binDirs);
|
||||
return ArrayUtilRt.toStringArray(binDirs);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -262,7 +266,7 @@ public class PathManager {
|
||||
if (System.getProperty(PROPERTY_PLUGINS_PATH) != null) {
|
||||
ourPluginsPath = getAbsolutePath(trimPathQuotes(System.getProperty(PROPERTY_PLUGINS_PATH)));
|
||||
}
|
||||
else if (SystemInfo.isMac && PATHS_SELECTOR != null) {
|
||||
else if (SystemInfoRt.isMac && PATHS_SELECTOR != null) {
|
||||
ourPluginsPath = platformPath(PATHS_SELECTOR, "Library/Application Support", "");
|
||||
}
|
||||
else {
|
||||
@@ -274,7 +278,7 @@ public class PathManager {
|
||||
|
||||
@NotNull
|
||||
public static String getDefaultPluginPathFor(@NotNull String selector) {
|
||||
if (SystemInfo.isMac) {
|
||||
if (SystemInfoRt.isMac) {
|
||||
return platformPath(selector, "Library/Application Support", "");
|
||||
}
|
||||
else {
|
||||
@@ -332,7 +336,7 @@ public class PathManager {
|
||||
if (System.getProperty(PROPERTY_LOG_PATH) != null) {
|
||||
ourLogPath = getAbsolutePath(trimPathQuotes(System.getProperty(PROPERTY_LOG_PATH)));
|
||||
}
|
||||
else if (SystemInfo.isMac && PATHS_SELECTOR != null) {
|
||||
else if (SystemInfoRt.isMac && PATHS_SELECTOR != null) {
|
||||
ourLogPath = SystemProperties.getUserHome() + "/Library/Logs/" + PATHS_SELECTOR;
|
||||
}
|
||||
else {
|
||||
@@ -423,7 +427,7 @@ public class PathManager {
|
||||
for (String path : paths) {
|
||||
if (path != null && new File(path).exists()) {
|
||||
try (@SuppressWarnings("ImplicitDefaultCharsetUsage") Reader reader = new FileReader(path)) {
|
||||
Map<String, String> properties = FileUtil.loadProperties(reader);
|
||||
Map<String, String> properties = PropertiesUtil.loadProperties(reader);
|
||||
for (Map.Entry<String, String> entry : properties.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
if (PROPERTY_HOME_PATH.equals(key) || PROPERTY_HOME.equals(key)) {
|
||||
@@ -459,7 +463,7 @@ public class PathManager {
|
||||
s = ideaHomePath + "/" + BIN_FOLDER + "/" + s;
|
||||
}
|
||||
|
||||
Matcher m = PROPERTY_REF.matcher(s);
|
||||
Matcher m = Lazy.PROPERTY_REF.matcher(s);
|
||||
while (m.find()) {
|
||||
String key = m.group(1);
|
||||
String value = System.getProperty(key);
|
||||
@@ -482,7 +486,7 @@ public class PathManager {
|
||||
}
|
||||
|
||||
s = StringUtil.replace(s, m.group(), value);
|
||||
m = PROPERTY_REF.matcher(s);
|
||||
m = Lazy.PROPERTY_REF.matcher(s);
|
||||
}
|
||||
|
||||
return s;
|
||||
@@ -586,11 +590,11 @@ public class PathManager {
|
||||
@NotNull String fallback) {
|
||||
String userHome = SystemProperties.getUserHome();
|
||||
|
||||
if (macPart != null && SystemInfo.isMac) {
|
||||
if (macPart != null && SystemInfoRt.isMac) {
|
||||
return userHome + "/" + macPart + "/" + selector;
|
||||
}
|
||||
|
||||
if (winVar != null && SystemInfo.isWindows) {
|
||||
if (winVar != null && SystemInfoRt.isWindows) {
|
||||
String dir = System.getenv(winVar);
|
||||
if (dir != null) {
|
||||
return dir + "/" + selector;
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
// Copyright 2000-2019 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.util;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
public class PropertiesUtil {
|
||||
/**
|
||||
* Like {@link Properties#load(Reader)}, but preserves the order of key/value pairs.
|
||||
*/
|
||||
@NotNull
|
||||
public static Map<String, String> loadProperties(@NotNull Reader reader) throws IOException {
|
||||
final Map<String, String> map = new LinkedHashMap<>();
|
||||
|
||||
new Properties() {
|
||||
@Override
|
||||
public synchronized Object put(Object key, Object value) {
|
||||
map.put(String.valueOf(key), String.valueOf(value));
|
||||
//noinspection UseOfPropertiesAsHashtable
|
||||
return super.put(key, value);
|
||||
}
|
||||
}.load(reader);
|
||||
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -1444,20 +1444,6 @@ public class FileUtil extends FileUtilRt {
|
||||
return list;
|
||||
}
|
||||
|
||||
public static boolean isJarOrZip(@NotNull File file) {
|
||||
return isJarOrZip(file, true);
|
||||
}
|
||||
|
||||
public static boolean isJarOrZip(@NotNull File file, boolean isCheckIsDirectory) {
|
||||
if (isCheckIsDirectory && file.isDirectory()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// do not use getName to avoid extra String creation (File.getName() calls substring)
|
||||
final String path = file.getPath();
|
||||
return StringUtilRt.endsWithIgnoreCase(path, ".jar") || StringUtilRt.endsWithIgnoreCase(path, ".zip");
|
||||
}
|
||||
|
||||
public static boolean visitFiles(@NotNull File root, @NotNull Processor<? super File> processor) {
|
||||
if (!processor.process(root)) {
|
||||
return false;
|
||||
@@ -1475,25 +1461,6 @@ public class FileUtil extends FileUtilRt {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Like {@link Properties#load(Reader)}, but preserves the order of key/value pairs.
|
||||
*/
|
||||
@NotNull
|
||||
public static Map<String, String> loadProperties(@NotNull Reader reader) throws IOException {
|
||||
final Map<String, String> map = new LinkedHashMap<>();
|
||||
|
||||
new Properties() {
|
||||
@Override
|
||||
public synchronized Object put(Object key, Object value) {
|
||||
map.put(String.valueOf(key), String.valueOf(value));
|
||||
//noinspection UseOfPropertiesAsHashtable
|
||||
return super.put(key, value);
|
||||
}
|
||||
}.load(reader);
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
public static boolean isRootPath(@NotNull String path) {
|
||||
return path.equals("/") || path.matches("[a-zA-Z]:[/\\\\]");
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2000-2019 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.util.io;
|
||||
|
||||
import com.intellij.openapi.util.PropertiesUtil;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.util.SystemProperties;
|
||||
import com.intellij.util.ThreeState;
|
||||
@@ -138,7 +139,7 @@ public class FileUtilLightTest {
|
||||
@Test
|
||||
public void testLoadProperties() throws IOException {
|
||||
String data = "key2=value2\nkey1=value1\nkey3=value3";
|
||||
Map<String, String> map = FileUtil.loadProperties(new StringReader(data));
|
||||
Map<String, String> map = PropertiesUtil.loadProperties(new StringReader(data));
|
||||
assertEquals(ContainerUtil.newArrayList("key2", "key1", "key3"), new ArrayList<>(map.keySet()));
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -6,6 +6,7 @@ import com.intellij.execution.configurations.JavaParameters;
|
||||
import com.intellij.execution.configurations.ParametersList;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.util.PropertiesUtil;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jdom.Element;
|
||||
@@ -95,7 +96,7 @@ public class MavenJUnitPatcher extends JUnitPatcher {
|
||||
try {
|
||||
Reader fis = new BufferedReader(new FileReader(systemPropertiesFilePath));
|
||||
try {
|
||||
Map<String, String> properties = FileUtil.loadProperties(fis);
|
||||
Map<String, String> properties = PropertiesUtil.loadProperties(fis);
|
||||
properties.forEach((pName, pValue) -> javaParameters.getVMParametersList().addProperty(pName, pValue));
|
||||
}
|
||||
finally {
|
||||
|
||||
Reference in New Issue
Block a user