diff --git a/platform/bootstrap/src/com/intellij/ide/BootstrapClassLoaderUtil.java b/platform/bootstrap/src/com/intellij/ide/BootstrapClassLoaderUtil.java index a70a3853ef8f..4dd5aa9a60a2 100644 --- a/platform/bootstrap/src/com/intellij/ide/BootstrapClassLoaderUtil.java +++ b/platform/bootstrap/src/com/intellij/ide/BootstrapClassLoaderUtil.java @@ -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); diff --git a/platform/bootstrap/src/com/intellij/idea/Main.java b/platform/bootstrap/src/com/intellij/idea/Main.java index aec20a123a56..d7ca5274a6a2 100644 --- a/platform/bootstrap/src/com/intellij/idea/Main.java +++ b/platform/bootstrap/src/com/intellij/idea/Main.java @@ -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 HEADLESS_COMMANDS = Arrays.asList( "ant", "duplocate", "traverseUI", "buildAppcodeCache", "format", "keymap", "update", "inspections", "intentions"); private static final List GUI_COMMANDS = Arrays.asList("diff", "merge"); diff --git a/platform/core-impl/src/com/intellij/ide/plugins/PluginManagerCore.java b/platform/core-impl/src/com/intellij/ide/plugins/PluginManagerCore.java index 0676117a286f..f0a5e215358a 100644 --- a/platform/core-impl/src/com/intellij/ide/plugins/PluginManagerCore.java +++ b/platform/core-impl/src/com/intellij/ide/plugins/PluginManagerCore.java @@ -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); } diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginLogo.java b/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginLogo.java index 155be0c5621f..b9784419a79d 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginLogo.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginLogo.java @@ -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)) { diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginLogoApi.java b/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginLogoApi.java index f3464214fb8e..d938528e0351 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginLogoApi.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginLogoApi.java @@ -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)) { diff --git a/platform/util-rt/src/com/intellij/openapi/util/io/FileUtilRt.java b/platform/util-rt/src/com/intellij/openapi/util/io/FileUtilRt.java index ebb80f395c12..85bdde8019d9 100644 --- a/platform/util-rt/src/com/intellij/openapi/util/io/FileUtilRt.java +++ b/platform/util-rt/src/com/intellij/openapi/util/io/FileUtilRt.java @@ -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); diff --git a/platform/util/src/com/intellij/openapi/application/PathManager.java b/platform/util/src/com/intellij/openapi/application/PathManager.java index ae742a71f332..7243c2bf0d0e 100644 --- a/platform/util/src/com/intellij/openapi/application/PathManager.java +++ b/platform/util/src/com/intellij/openapi/application/PathManager.java @@ -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 binDirs = ContainerUtil.newSmartList(); + List 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 properties = FileUtil.loadProperties(reader); + Map properties = PropertiesUtil.loadProperties(reader); for (Map.Entry 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; diff --git a/platform/util/src/com/intellij/openapi/util/PropertiesUtil.java b/platform/util/src/com/intellij/openapi/util/PropertiesUtil.java new file mode 100644 index 000000000000..1a3bdb82675d --- /dev/null +++ b/platform/util/src/com/intellij/openapi/util/PropertiesUtil.java @@ -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 loadProperties(@NotNull Reader reader) throws IOException { + final Map 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; + } +} diff --git a/platform/util/src/com/intellij/openapi/util/io/FileUtil.java b/platform/util/src/com/intellij/openapi/util/io/FileUtil.java index 1a537f8d0e90..dc6e892094cf 100644 --- a/platform/util/src/com/intellij/openapi/util/io/FileUtil.java +++ b/platform/util/src/com/intellij/openapi/util/io/FileUtil.java @@ -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 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 loadProperties(@NotNull Reader reader) throws IOException { - final Map 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]:[/\\\\]"); } diff --git a/platform/util/testSrc/com/intellij/openapi/util/io/FileUtilLightTest.java b/platform/util/testSrc/com/intellij/openapi/util/io/FileUtilLightTest.java index 154878255138..2c9792b12842 100644 --- a/platform/util/testSrc/com/intellij/openapi/util/io/FileUtilLightTest.java +++ b/platform/util/testSrc/com/intellij/openapi/util/io/FileUtilLightTest.java @@ -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 map = FileUtil.loadProperties(new StringReader(data)); + Map map = PropertiesUtil.loadProperties(new StringReader(data)); assertEquals(ContainerUtil.newArrayList("key2", "key1", "key3"), new ArrayList<>(map.keySet())); } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenJUnitPatcher.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenJUnitPatcher.java index 7746d284769e..9ce1acdca917 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenJUnitPatcher.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenJUnitPatcher.java @@ -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 properties = FileUtil.loadProperties(fis); + Map properties = PropertiesUtil.loadProperties(fis); properties.forEach((pName, pValue) -> javaParameters.getVMParametersList().addProperty(pName, pValue)); } finally {