mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 23:39:07 +07:00
[jps model] refactoring: replace inheritance from JpsLoaderBase by delegation and rename it to JpsComponentLoader
This is needed to refactor simplify JpsProjectLoader to allow reusing its code in the new implementation of the JPS model (IJPL-409). GitOrigin-RevId: b88fb246454601489e7133df4b078e5e52f6da58
This commit is contained in:
committed by
intellij-monorepo-bot
parent
7669d82323
commit
c0bc5811fb
@@ -19,13 +19,13 @@ import java.nio.file.NoSuchFileException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public abstract class JpsLoaderBase {
|
||||
private static final Logger LOG = Logger.getInstance(JpsLoaderBase.class);
|
||||
public class JpsComponentLoader {
|
||||
private static final Logger LOG = Logger.getInstance(JpsComponentLoader.class);
|
||||
private static final int MAX_ATTEMPTS = 5;
|
||||
protected final @Nullable Path myExternalConfigurationDirectory;
|
||||
private final JpsMacroExpander myMacroExpander;
|
||||
|
||||
protected JpsLoaderBase(JpsMacroExpander macroExpander, @Nullable Path externalConfigurationDirectory) {
|
||||
public JpsComponentLoader(JpsMacroExpander macroExpander, @Nullable Path externalConfigurationDirectory) {
|
||||
myMacroExpander = macroExpander;
|
||||
myExternalConfigurationDirectory = externalConfigurationDirectory;
|
||||
}
|
||||
@@ -33,7 +33,7 @@ public abstract class JpsLoaderBase {
|
||||
/**
|
||||
* Returns null if file doesn't exist
|
||||
*/
|
||||
protected @Nullable Element loadRootElement(@NotNull Path file) {
|
||||
public @Nullable Element loadRootElement(@NotNull Path file) {
|
||||
return loadRootElement(file, myMacroExpander);
|
||||
}
|
||||
|
||||
@@ -16,15 +16,16 @@ import org.jetbrains.jps.model.serialization.impl.JpsPathVariablesConfigurationI
|
||||
import java.nio.file.Path;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public class JpsGlobalLoader extends JpsLoaderBase {
|
||||
public class JpsGlobalLoader {
|
||||
public static final JpsElementChildRole<JpsPathVariablesConfiguration> PATH_VARIABLES_ROLE = JpsElementChildRoleBase.create("path variables");
|
||||
public static final JpsGlobalExtensionSerializer FILE_TYPES_SERIALIZER = new FileTypesSerializer();
|
||||
private static final Logger LOG = Logger.getInstance(JpsGlobalLoader.class);
|
||||
private final JpsGlobal myGlobal;
|
||||
private final JpsGlobalExtensionSerializer @NotNull [] myBundledSerializers;
|
||||
private final JpsComponentLoader myComponentLoader;
|
||||
|
||||
public JpsGlobalLoader(JpsMacroExpander macroExpander, JpsGlobal global, JpsGlobalExtensionSerializer @NotNull [] bundledSerializers) {
|
||||
super(macroExpander, null);
|
||||
myComponentLoader = new JpsComponentLoader(macroExpander, null);
|
||||
myGlobal = global;
|
||||
myBundledSerializers = bundledSerializers;
|
||||
}
|
||||
@@ -49,7 +50,7 @@ public class JpsGlobalLoader extends JpsLoaderBase {
|
||||
}
|
||||
|
||||
protected void loadGlobalComponents(@NotNull Path optionsDir, @NotNull Path defaultConfigFile, JpsGlobalExtensionSerializer serializer) {
|
||||
loadComponents(optionsDir, defaultConfigFile.getParent(), serializer, myGlobal);
|
||||
myComponentLoader.loadComponents(optionsDir, defaultConfigFile.getParent(), serializer, myGlobal);
|
||||
}
|
||||
|
||||
public static final class PathVariablesSerializer extends JpsGlobalExtensionSerializer {
|
||||
|
||||
@@ -48,7 +48,7 @@ import java.util.concurrent.ExecutorService;
|
||||
* Use {@link JpsSerializationManager} to load a project.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public final class JpsProjectLoader extends JpsLoaderBase {
|
||||
public final class JpsProjectLoader {
|
||||
public static final String MODULE_MANAGER_COMPONENT = "ProjectModuleManager";
|
||||
public static final String MODULES_TAG = "modules";
|
||||
public static final String MODULE_TAG = "module";
|
||||
@@ -71,6 +71,8 @@ public final class JpsProjectLoader extends JpsLoaderBase {
|
||||
private final Map<String, String> myPathVariables;
|
||||
private final JpsPathMapper myPathMapper;
|
||||
private final boolean myLoadUnloadedModules;
|
||||
private final JpsComponentLoader myComponentLoader;
|
||||
private final @Nullable Path myExternalConfigurationDirectory;
|
||||
|
||||
private JpsProjectLoader(JpsProject project,
|
||||
Map<String, String> pathVariables,
|
||||
@@ -78,7 +80,9 @@ public final class JpsProjectLoader extends JpsLoaderBase {
|
||||
@NotNull Path baseDir,
|
||||
@Nullable Path externalConfigurationDirectory,
|
||||
boolean loadUnloadedModules) {
|
||||
super(createProjectMacroExpander(pathVariables, baseDir), externalConfigurationDirectory);
|
||||
JpsMacroExpander macroExpander = createProjectMacroExpander(pathVariables, baseDir);
|
||||
myExternalConfigurationDirectory = externalConfigurationDirectory;
|
||||
myComponentLoader = new JpsComponentLoader(macroExpander, myExternalConfigurationDirectory);
|
||||
myProject = project;
|
||||
myPathVariables = pathVariables;
|
||||
myPathMapper = pathMapper;
|
||||
@@ -157,10 +161,10 @@ public final class JpsProjectLoader extends JpsLoaderBase {
|
||||
private void loadFromDirectory(@NotNull Path dir, @NotNull Executor executor) {
|
||||
myProject.setName(getDirectoryBaseProjectName(dir));
|
||||
Path defaultConfigFile = dir.resolve("misc.xml");
|
||||
JpsSdkType<?> projectSdkType = loadProjectRoot(loadRootElement(defaultConfigFile));
|
||||
JpsSdkType<?> projectSdkType = loadProjectRoot(myComponentLoader.loadRootElement(defaultConfigFile));
|
||||
for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
|
||||
for (JpsProjectExtensionSerializer serializer : extension.getProjectExtensionSerializers()) {
|
||||
loadComponents(dir, defaultConfigFile, serializer, myProject);
|
||||
myComponentLoader.loadComponents(dir, defaultConfigFile, serializer, myProject);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,13 +177,13 @@ public final class JpsProjectLoader extends JpsLoaderBase {
|
||||
externalConfigDir = null;
|
||||
}
|
||||
|
||||
Element moduleData = JDomSerializationUtil.findComponent(loadRootElement(dir.resolve("modules.xml")), MODULE_MANAGER_COMPONENT);
|
||||
Element moduleData = JDomSerializationUtil.findComponent(myComponentLoader.loadRootElement(dir.resolve("modules.xml")), MODULE_MANAGER_COMPONENT);
|
||||
Element externalModuleData;
|
||||
if (externalConfigDir == null) {
|
||||
externalModuleData = null;
|
||||
}
|
||||
else {
|
||||
Element rootElement = loadRootElement(externalConfigDir.resolve("modules.xml"));
|
||||
Element rootElement = myComponentLoader.loadRootElement(externalConfigDir.resolve("modules.xml"));
|
||||
if (rootElement == null) {
|
||||
externalModuleData = null;
|
||||
}
|
||||
@@ -211,30 +215,31 @@ public final class JpsProjectLoader extends JpsLoaderBase {
|
||||
|
||||
Runnable timingLog = TimingLog.startActivity("loading project libraries");
|
||||
for (Path libraryFile : listXmlFiles(dir.resolve("libraries"))) {
|
||||
loadProjectLibraries(loadRootElement(libraryFile));
|
||||
loadProjectLibraries(myComponentLoader.loadRootElement(libraryFile));
|
||||
}
|
||||
|
||||
if (externalConfigDir != null) {
|
||||
loadProjectLibraries(loadRootElement(externalConfigDir.resolve("libraries.xml")));
|
||||
loadProjectLibraries(myComponentLoader.loadRootElement(externalConfigDir.resolve("libraries.xml")));
|
||||
}
|
||||
|
||||
timingLog.run();
|
||||
|
||||
Runnable artifactsTimingLog = TimingLog.startActivity("loading artifacts");
|
||||
for (Path artifactFile : listXmlFiles(dir.resolve("artifacts"))) {
|
||||
loadArtifacts(loadRootElement(artifactFile));
|
||||
loadArtifacts(myComponentLoader.loadRootElement(artifactFile));
|
||||
}
|
||||
if (externalConfigDir != null) {
|
||||
loadArtifacts(loadRootElement(externalConfigDir.resolve("artifacts.xml")));
|
||||
loadArtifacts(myComponentLoader.loadRootElement(externalConfigDir.resolve("artifacts.xml")));
|
||||
}
|
||||
artifactsTimingLog.run();
|
||||
|
||||
if (hasRunConfigurationSerializers()) {
|
||||
Runnable runConfTimingLog = TimingLog.startActivity("loading run configurations");
|
||||
for (Path configurationFile : listXmlFiles(dir.resolve("runConfigurations"))) {
|
||||
JpsRunConfigurationSerializer.loadRunConfigurations(myProject, loadRootElement(configurationFile));
|
||||
JpsRunConfigurationSerializer.loadRunConfigurations(myProject, myComponentLoader.loadRootElement(configurationFile));
|
||||
}
|
||||
JpsRunConfigurationSerializer.loadRunConfigurations(myProject, JDomSerializationUtil.findComponent(loadRootElement(workspaceFile), "RunManager"));
|
||||
JpsRunConfigurationSerializer.loadRunConfigurations(myProject, JDomSerializationUtil.findComponent(
|
||||
myComponentLoader.loadRootElement(workspaceFile), "RunManager"));
|
||||
runConfTimingLog.run();
|
||||
}
|
||||
}
|
||||
@@ -260,12 +265,12 @@ public final class JpsProjectLoader extends JpsLoaderBase {
|
||||
}
|
||||
|
||||
private void loadFromIpr(@NotNull Path iprFile, @NotNull Executor executor) {
|
||||
final Element iprRoot = loadRootElement(iprFile);
|
||||
final Element iprRoot = myComponentLoader.loadRootElement(iprFile);
|
||||
|
||||
String projectName = FileUtilRt.getNameWithoutExtension(iprFile.getFileName().toString());
|
||||
myProject.setName(projectName);
|
||||
Path iwsFile = iprFile.getParent().resolve(projectName + ".iws");
|
||||
Element iwsRoot = loadRootElement(iwsFile);
|
||||
Element iwsRoot = myComponentLoader.loadRootElement(iwsFile);
|
||||
|
||||
JpsSdkType<?> projectSdkType = loadProjectRoot(iprRoot);
|
||||
for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
|
||||
@@ -322,7 +327,7 @@ public final class JpsProjectLoader extends JpsLoaderBase {
|
||||
|
||||
Set<String> unloadedModules = new HashSet<>();
|
||||
if (!myLoadUnloadedModules && workspaceFile.toFile().exists()) {
|
||||
Element unloadedModulesList = JDomSerializationUtil.findComponent(loadRootElement(workspaceFile), "UnloadedModulesList");
|
||||
Element unloadedModulesList = JDomSerializationUtil.findComponent(myComponentLoader.loadRootElement(workspaceFile), "UnloadedModulesList");
|
||||
for (Element element : JDOMUtil.getChildren(unloadedModulesList, "module")) {
|
||||
unloadedModules.add(element.getAttributeValue("name"));
|
||||
}
|
||||
@@ -371,10 +376,10 @@ public final class JpsProjectLoader extends JpsLoaderBase {
|
||||
futureModuleFilesContents.add(CompletableFuture.supplyAsync(() -> {
|
||||
JpsMacroExpander expander = createModuleMacroExpander(pathVariables, file);
|
||||
|
||||
Element data = loadRootElement(file, expander);
|
||||
Element data = JpsComponentLoader.loadRootElement(file, expander);
|
||||
if (externalModuleDir != null) {
|
||||
String externalName = FileUtilRt.getNameWithoutExtension(file.getFileName().toString()) + ".xml";
|
||||
Element externalData = loadRootElement(externalModuleDir.resolve(externalName), expander);
|
||||
Element externalData = JpsComponentLoader.loadRootElement(externalModuleDir.resolve(externalName), expander);
|
||||
if (externalData != null) {
|
||||
if (data == null) {
|
||||
data = externalData;
|
||||
|
||||
@@ -7,14 +7,12 @@ import com.intellij.openapi.util.io.FileUtilRt;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.util.PathUtil;
|
||||
import com.intellij.util.SystemProperties;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.model.JpsModelTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -87,9 +85,4 @@ public abstract class JpsSerializationTestCase extends JpsModelTestCase {
|
||||
protected Path getTestDataAbsoluteFile(@NotNull String relativePath) {
|
||||
return Paths.get(getTestDataFileAbsolutePath(relativePath));
|
||||
}
|
||||
|
||||
protected static Element loadModuleRootTag(@NotNull Path imlFile) {
|
||||
JpsMacroExpander expander = JpsProjectLoader.createModuleMacroExpander(Collections.emptyMap(), imlFile);
|
||||
return JpsLoaderBase.loadRootElement(imlFile, expander);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,14 +5,16 @@ import com.intellij.openapi.components.ExpandMacroToPathMap
|
||||
import com.intellij.platform.workspace.jps.serialization.impl.JpsFileContentReader
|
||||
import org.jdom.Element
|
||||
import org.jetbrains.jps.model.serialization.JDomSerializationUtil
|
||||
import org.jetbrains.jps.model.serialization.JpsLoaderBase
|
||||
import org.jetbrains.jps.model.serialization.JpsComponentLoader
|
||||
import org.jetbrains.jps.model.serialization.JpsMacroExpander
|
||||
import org.jetbrains.jps.util.JpsPathUtil
|
||||
import kotlin.io.path.Path
|
||||
|
||||
internal class DirectJpsFileContentReader(private val macroExpander: JpsMacroExpander) : JpsLoaderBase(macroExpander, null), JpsFileContentReader {
|
||||
internal class DirectJpsFileContentReader(private val macroExpander: JpsMacroExpander) : JpsFileContentReader {
|
||||
private val componentLoader = JpsComponentLoader(macroExpander, null)
|
||||
|
||||
override fun loadComponent(fileUrl: String, componentName: String, customModuleFilePath: String?): Element? {
|
||||
val rootElement = loadRootElement(Path(JpsPathUtil.urlToPath(fileUrl))) ?: return null
|
||||
val rootElement = componentLoader.loadRootElement(Path(JpsPathUtil.urlToPath(fileUrl))) ?: return null
|
||||
return JDomSerializationUtil.findComponent(rootElement, componentName)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user