JpsMacroExpander - avoid using of FileUtil (reduce classloading)

GitOrigin-RevId: c063f7d6dca475033b996770a6f83d1dbeb48590
This commit is contained in:
Vladimir Krivosheev
2023-08-27 17:04:59 +03:00
committed by intellij-monorepo-bot
parent 738c3054bc
commit 97661aa3c0
3 changed files with 19 additions and 32 deletions

View File

@@ -57,6 +57,7 @@ import com.intellij.openapi.roots.*;
import com.intellij.openapi.startup.StartupActivity;
import com.intellij.openapi.util.*;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.FileUtilRt;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.util.registry.RegistryManager;
import com.intellij.openapi.util.registry.RegistryManagerKt;
@@ -469,7 +470,7 @@ public final class BuildManager implements Disposable {
home = parent;
}
}
return FileUtil.toSystemIndependentName(home);
return FileUtilRt.toSystemIndependentName(home);
}
private static @NotNull List<Project> getOpenProjects() {

View File

@@ -1,23 +1,9 @@
/*
* 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-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.jps.model.serialization;
import com.intellij.openapi.components.ExpandMacroToPathMap;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.util.io.FileUtilRt;
import com.intellij.openapi.util.text.StringUtilRt;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -25,7 +11,7 @@ import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.util.Map;
public class JpsMacroExpander {
public final class JpsMacroExpander {
private final ExpandMacroToPathMap myExpandMacroMap;
public JpsMacroExpander(Map<String, String> pathVariables) {
@@ -39,16 +25,19 @@ public class JpsMacroExpander {
doAddFileHierarchyReplacements("$" + macroName + "$", file);
}
protected void addMacro(String macroName, String path) {
private void addMacro(String macroName, String path) {
myExpandMacroMap.addMacroExpand(macroName, path);
}
private void doAddFileHierarchyReplacements(String macro, @Nullable File file) {
if (file == null) return;
if (file == null) {
return;
}
doAddFileHierarchyReplacements(macro + "/..", file.getParentFile());
final String path = FileUtil.toSystemIndependentName(file.getPath());
if (StringUtil.endsWithChar(path, '/')) {
String path = FileUtilRt.toSystemIndependentName(file.getPath());
if (StringUtilRt.endsWithChar(path, '/')) {
myExpandMacroMap.put(macro + "/", path);
myExpandMacroMap.put(macro, path.substring(0, path.length()-1));
}

View File

@@ -1,12 +1,10 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.jps.model.serialization;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.JDOMUtil;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.FileUtilRt;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.concurrency.AppExecutorUtil;
import com.intellij.util.containers.CollectionFactory;
import com.intellij.util.containers.ContainerUtil;
@@ -40,7 +38,6 @@ import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
@@ -338,7 +335,7 @@ public final class JpsProjectLoader extends JpsLoaderBase {
for (Element moduleElement : JDOMUtil.getChildren(componentElement.getChild(MODULES_TAG), MODULE_TAG)) {
final String path = moduleElement.getAttributeValue(FILE_PATH_ATTRIBUTE);
if (path != null) {
final Path file = Paths.get(path);
final Path file = Path.of(path);
if (foundFiles.add(file) && !unloadedModules.contains(getModuleName(file))) {
moduleFiles.add(file);
}
@@ -354,7 +351,7 @@ public final class JpsProjectLoader extends JpsLoaderBase {
private static @Nullable Path resolveExternalProjectConfig(@NotNull String subDirName) {
String externalProjectConfigDir = System.getProperty("external.project.config");
return StringUtil.isEmptyOrSpaces(externalProjectConfigDir) ? null : Paths.get(externalProjectConfigDir, subDirName);
return (externalProjectConfigDir == null || externalProjectConfigDir.isBlank()) ? null : Path.of(externalProjectConfigDir, subDirName);
}
public static @NotNull List<JpsModule> loadModules(@NotNull List<? extends Path> moduleFiles,
@@ -471,7 +468,7 @@ public final class JpsProjectLoader extends JpsLoaderBase {
extension.loadModuleOptions(module, moduleRoot);
}
String baseModulePath = FileUtil.toSystemIndependentName(file.getParent().toString());
String baseModulePath = FileUtilRt.toSystemIndependentName(file.getParent().toString());
String classpath = moduleRoot.getAttributeValue(CLASSPATH_ATTRIBUTE);
if (classpath == null) {
try {
@@ -513,10 +510,10 @@ public final class JpsProjectLoader extends JpsLoaderBase {
}
static JpsMacroExpander createModuleMacroExpander(final Map<String, String> pathVariables, @NotNull Path moduleFile) {
final JpsMacroExpander expander = new JpsMacroExpander(pathVariables);
JpsMacroExpander expander = new JpsMacroExpander(pathVariables);
String moduleDirPath = PathMacroUtil.getModuleDir(moduleFile.toAbsolutePath().toString());
if (moduleDirPath != null) {
expander.addFileHierarchyReplacements(PathMacroUtil.MODULE_DIR_MACRO_NAME, new File(FileUtil.toSystemDependentName(moduleDirPath)));
expander.addFileHierarchyReplacements(PathMacroUtil.MODULE_DIR_MACRO_NAME, new File(FileUtilRt.toSystemDependentName(moduleDirPath)));
}
return expander;
}