mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
JPS loader — use Path instead of File
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -25,6 +25,9 @@ import org.jetbrains.jps.model.serialization.JpsProjectLoader;
|
||||
import org.jetbrains.jps.model.serialization.PathMacroUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@@ -66,19 +69,19 @@ public class Utils {
|
||||
String name;
|
||||
final int locationHash;
|
||||
|
||||
final File rootFile = new File(projectPath);
|
||||
if (!rootFile.isDirectory() && projectPath.endsWith(".ipr")) {
|
||||
name = StringUtil.trimEnd(rootFile.getName(), ".ipr");
|
||||
final Path rootFile = Paths.get(projectPath);
|
||||
if (!Files.isDirectory(rootFile) && projectPath.endsWith(".ipr")) {
|
||||
name = StringUtil.trimEnd(rootFile.getFileName().toString(), ".ipr");
|
||||
locationHash = projectPath.hashCode();
|
||||
}
|
||||
else {
|
||||
File directoryBased = null;
|
||||
if (PathMacroUtil.DIRECTORY_STORE_NAME.equals(rootFile.getName())) {
|
||||
Path directoryBased = null;
|
||||
if (rootFile.endsWith(PathMacroUtil.DIRECTORY_STORE_NAME)) {
|
||||
directoryBased = rootFile;
|
||||
}
|
||||
else {
|
||||
File child = new File(rootFile, PathMacroUtil.DIRECTORY_STORE_NAME);
|
||||
if (child.exists()) {
|
||||
Path child = rootFile.resolve(PathMacroUtil.DIRECTORY_STORE_NAME);
|
||||
if (Files.exists(child)) {
|
||||
directoryBased = child;
|
||||
}
|
||||
}
|
||||
@@ -86,7 +89,7 @@ public class Utils {
|
||||
return null;
|
||||
}
|
||||
name = PathUtilRt.suggestFileName(JpsProjectLoader.getDirectoryBaseProjectName(directoryBased));
|
||||
locationHash = directoryBased.getPath().hashCode();
|
||||
locationHash = directoryBased.toString().hashCode();
|
||||
}
|
||||
|
||||
return new File(systemRoot, name.toLowerCase(Locale.US) + "_" + Integer.toHexString(locationHash));
|
||||
|
||||
+7
-6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -29,8 +29,9 @@ import org.jetbrains.jps.model.serialization.impl.JpsPathVariablesConfigurationI
|
||||
import org.jetbrains.jps.model.serialization.library.JpsLibraryTableSerializer;
|
||||
import org.jetbrains.jps.model.serialization.library.JpsSdkTableSerializer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -53,7 +54,7 @@ public class JpsGlobalLoader extends JpsLoaderBase {
|
||||
}
|
||||
|
||||
public static void loadGlobalSettings(JpsGlobal global, String optionsPath) throws IOException {
|
||||
File optionsDir = new File(FileUtil.toCanonicalPath(optionsPath));
|
||||
Path optionsDir = Paths.get(FileUtil.toCanonicalPath(optionsPath));
|
||||
new JpsGlobalLoader(global, Collections.emptyMap()).loadGlobalComponents(optionsDir, new PathVariablesSerializer());
|
||||
Map<String, String> pathVariables = JpsModelSerializationDataService.computeAllPathVariables(global);
|
||||
new JpsGlobalLoader(global, pathVariables).load(optionsDir);
|
||||
@@ -67,8 +68,8 @@ public class JpsGlobalLoader extends JpsLoaderBase {
|
||||
return JpsModelSerializationDataService.getPathVariableValue(global, name);
|
||||
}
|
||||
|
||||
private void load(File optionsDir) {
|
||||
LOG.debug("Loading config from " + optionsDir.getAbsolutePath());
|
||||
private void load(@NotNull Path optionsDir) {
|
||||
LOG.debug("Loading config from " + optionsDir.toAbsolutePath());
|
||||
for (JpsGlobalExtensionSerializer serializer : SERIALIZERS) {
|
||||
loadGlobalComponents(optionsDir, serializer);
|
||||
}
|
||||
@@ -79,7 +80,7 @@ public class JpsGlobalLoader extends JpsLoaderBase {
|
||||
}
|
||||
}
|
||||
|
||||
private void loadGlobalComponents(File optionsDir, JpsGlobalExtensionSerializer serializer) {
|
||||
private void loadGlobalComponents(@NotNull Path optionsDir, JpsGlobalExtensionSerializer serializer) {
|
||||
loadComponents(optionsDir, "other.xml", serializer, myGlobal);
|
||||
}
|
||||
|
||||
|
||||
+15
-13
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -20,11 +20,13 @@ import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.JDOMException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.TimingLog;
|
||||
import org.jetbrains.jps.model.JpsElement;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
@@ -38,19 +40,19 @@ public abstract class JpsLoaderBase {
|
||||
myMacroExpander = macroExpander;
|
||||
}
|
||||
|
||||
protected Element loadRootElement(final File file) {
|
||||
protected Element loadRootElement(@NotNull Path file) {
|
||||
return loadRootElement(file, myMacroExpander);
|
||||
}
|
||||
|
||||
protected <E extends JpsElement> void loadComponents(File dir,
|
||||
protected <E extends JpsElement> void loadComponents(@NotNull Path dir,
|
||||
final String defaultFileName,
|
||||
JpsElementExtensionSerializerBase<E> serializer,
|
||||
final E element) {
|
||||
String fileName = serializer.getConfigFileName();
|
||||
File configFile = new File(dir, fileName != null ? fileName : defaultFileName);
|
||||
Runnable timingLog = TimingLog.startActivity("loading: " + configFile.getName() + ":" + serializer.getComponentName());
|
||||
Path configFile = dir.resolve(fileName != null ? fileName : defaultFileName);
|
||||
Runnable timingLog = TimingLog.startActivity("loading: " + configFile.getFileName() + ":" + serializer.getComponentName());
|
||||
Element componentTag;
|
||||
if (configFile.exists()) {
|
||||
if (Files.exists(configFile)) {
|
||||
componentTag = JDomSerializationUtil.findComponent(loadRootElement(configFile), serializer.getComponentName());
|
||||
}
|
||||
else {
|
||||
@@ -66,24 +68,24 @@ public abstract class JpsLoaderBase {
|
||||
timingLog.run();
|
||||
}
|
||||
|
||||
protected static Element loadRootElement(final File file, final JpsMacroExpander macroExpander) {
|
||||
protected static Element loadRootElement(@NotNull Path file, final JpsMacroExpander macroExpander) {
|
||||
try {
|
||||
final Element element = tryLoadRootElement(file);
|
||||
macroExpander.substitute(element, SystemInfo.isFileSystemCaseSensitive);
|
||||
return element;
|
||||
}
|
||||
catch (JDOMException e) {
|
||||
throw new CannotLoadJpsModelException(file, "Cannot parse xml file " + file.getAbsolutePath() + ": " + e.getMessage(), e);
|
||||
throw new CannotLoadJpsModelException(file.toFile(), "Cannot parse xml file " + file.toAbsolutePath() + ": " + e.getMessage(), e);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new CannotLoadJpsModelException(file, "Cannot read file " + file.getAbsolutePath() + ": " + e.getMessage(), e);
|
||||
throw new CannotLoadJpsModelException(file.toFile(), "Cannot read file " + file.toAbsolutePath() + ": " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private static Element tryLoadRootElement(File file) throws IOException, JDOMException {
|
||||
private static Element tryLoadRootElement(@NotNull Path file) throws IOException, JDOMException {
|
||||
for (int i = 0; i < MAX_ATTEMPTS - 1; i++) {
|
||||
try {
|
||||
return JDOMUtil.load(file);
|
||||
return JDOMUtil.load(Files.newBufferedReader(file));
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.info("Loading attempt #" + i + " failed", e);
|
||||
@@ -95,6 +97,6 @@ public abstract class JpsLoaderBase {
|
||||
}
|
||||
catch (InterruptedException ignored) { }
|
||||
}
|
||||
return JDOMUtil.load(file);
|
||||
return JDOMUtil.load(Files.newBufferedReader(file));
|
||||
}
|
||||
}
|
||||
|
||||
+65
-61
@@ -18,12 +18,11 @@ 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.FileFilters;
|
||||
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.ArrayUtil;
|
||||
import com.intellij.util.concurrency.BoundedTaskExecutor;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -50,14 +49,13 @@ import org.jetbrains.jps.service.SharedThreadPool;
|
||||
|
||||
import java.io.File;
|
||||
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.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
@@ -70,81 +68,82 @@ public class JpsProjectLoader extends JpsLoaderBase {
|
||||
private final JpsProject myProject;
|
||||
private final Map<String, String> myPathVariables;
|
||||
|
||||
private JpsProjectLoader(JpsProject project, Map<String, String> pathVariables, File baseDir) {
|
||||
private JpsProjectLoader(JpsProject project, Map<String, String> pathVariables, Path baseDir) {
|
||||
super(createProjectMacroExpander(pathVariables, baseDir));
|
||||
myProject = project;
|
||||
myPathVariables = pathVariables;
|
||||
myProject.getContainer().setChild(JpsProjectSerializationDataExtensionImpl.ROLE, new JpsProjectSerializationDataExtensionImpl(baseDir));
|
||||
}
|
||||
|
||||
static JpsMacroExpander createProjectMacroExpander(Map<String, String> pathVariables, File baseDir) {
|
||||
static JpsMacroExpander createProjectMacroExpander(Map<String, String> pathVariables, @NotNull Path baseDir) {
|
||||
final JpsMacroExpander expander = new JpsMacroExpander(pathVariables);
|
||||
expander.addFileHierarchyReplacements(PathMacroUtil.PROJECT_DIR_MACRO_NAME, baseDir);
|
||||
expander.addFileHierarchyReplacements(PathMacroUtil.PROJECT_DIR_MACRO_NAME, baseDir.toFile());
|
||||
return expander;
|
||||
}
|
||||
|
||||
public static void loadProject(final JpsProject project, Map<String, String> pathVariables, String projectPath) throws IOException {
|
||||
File file = new File(FileUtil.toCanonicalPath(projectPath));
|
||||
if (file.isFile() && projectPath.endsWith(".ipr")) {
|
||||
new JpsProjectLoader(project, pathVariables, file.getParentFile()).loadFromIpr(file);
|
||||
Path file = Paths.get(FileUtil.toCanonicalPath(projectPath));
|
||||
if (Files.isRegularFile(file) && projectPath.endsWith(".ipr")) {
|
||||
new JpsProjectLoader(project, pathVariables, file.getParent()).loadFromIpr(file);
|
||||
}
|
||||
else {
|
||||
File dotIdea = new File(file, PathMacroUtil.DIRECTORY_STORE_NAME);
|
||||
File directory;
|
||||
if (dotIdea.isDirectory()) {
|
||||
Path dotIdea = file.resolve(PathMacroUtil.DIRECTORY_STORE_NAME);
|
||||
Path directory;
|
||||
if (Files.isDirectory(dotIdea)) {
|
||||
directory = dotIdea;
|
||||
}
|
||||
else if (file.isDirectory() && file.getName().equals(PathMacroUtil.DIRECTORY_STORE_NAME)) {
|
||||
else if (Files.isDirectory(file) && file.endsWith(PathMacroUtil.DIRECTORY_STORE_NAME)) {
|
||||
directory = file;
|
||||
}
|
||||
else {
|
||||
throw new IOException("Cannot find IntelliJ IDEA project files at " + projectPath);
|
||||
}
|
||||
new JpsProjectLoader(project, pathVariables, directory.getParentFile()).loadFromDirectory(directory);
|
||||
new JpsProjectLoader(project, pathVariables, directory.getParent()).loadFromDirectory(directory);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getDirectoryBaseProjectName(File dir) {
|
||||
File nameFile = new File(dir, ".name");
|
||||
if (nameFile.isFile()) {
|
||||
try {
|
||||
return FileUtilRt.loadFile(nameFile).trim();
|
||||
}
|
||||
catch (IOException ignored) {
|
||||
@NotNull
|
||||
public static String getDirectoryBaseProjectName(@NotNull Path dir) {
|
||||
try (Stream<String> stream = Files.lines(dir.resolve(".name"))) {
|
||||
String value = stream.findFirst().map(String::trim).orElse(null);
|
||||
if (value != null) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return dir.getParentFile().getName();
|
||||
catch (IOException ignored) {
|
||||
}
|
||||
return dir.getParent().getFileName().toString();
|
||||
}
|
||||
|
||||
private void loadFromDirectory(File dir) {
|
||||
private void loadFromDirectory(@NotNull Path dir) {
|
||||
myProject.setName(getDirectoryBaseProjectName(dir));
|
||||
JpsSdkType<?> projectSdkType = loadProjectRoot(loadRootElement(new File(dir, "misc.xml")));
|
||||
JpsSdkType<?> projectSdkType = loadProjectRoot(loadRootElement(dir.resolve("misc.xml")));
|
||||
for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
|
||||
for (JpsProjectExtensionSerializer serializer : extension.getProjectExtensionSerializers()) {
|
||||
loadComponents(dir, "misc.xml", serializer, myProject);
|
||||
}
|
||||
}
|
||||
loadModules(loadRootElement(new File(dir, "modules.xml")), projectSdkType);
|
||||
loadModules(loadRootElement(dir.resolve("modules.xml")), projectSdkType);
|
||||
|
||||
Runnable timingLog = TimingLog.startActivity("loading project libraries");
|
||||
for (File libraryFile : listXmlFiles(new File(dir, "libraries"))) {
|
||||
for (Path libraryFile : listXmlFiles(dir.resolve("libraries"))) {
|
||||
loadProjectLibraries(loadRootElement(libraryFile));
|
||||
}
|
||||
timingLog.run();
|
||||
|
||||
Runnable artifactsTimingLog = TimingLog.startActivity("loading artifacts");
|
||||
for (File artifactFile : listXmlFiles(new File(dir, "artifacts"))) {
|
||||
for (Path artifactFile : listXmlFiles(dir.resolve("artifacts"))) {
|
||||
loadArtifacts(loadRootElement(artifactFile));
|
||||
}
|
||||
artifactsTimingLog.run();
|
||||
|
||||
if (hasRunConfigurationSerializers()) {
|
||||
Runnable runConfTimingLog = TimingLog.startActivity("loading run configurations");
|
||||
for (File configurationFile : listXmlFiles(new File(dir, "runConfigurations"))) {
|
||||
for (Path configurationFile : listXmlFiles(dir.resolve("runConfigurations"))) {
|
||||
JpsRunConfigurationSerializer.loadRunConfigurations(myProject, loadRootElement(configurationFile));
|
||||
}
|
||||
File workspaceFile = new File(dir, "workspace.xml");
|
||||
if (workspaceFile.exists()) {
|
||||
Path workspaceFile = dir.resolve("workspace.xml");
|
||||
if (Files.exists(workspaceFile)) {
|
||||
Element runManager = JDomSerializationUtil.findComponent(loadRootElement(workspaceFile), "RunManager");
|
||||
JpsRunConfigurationSerializer.loadRunConfigurations(myProject, runManager);
|
||||
}
|
||||
@@ -162,18 +161,24 @@ public class JpsProjectLoader extends JpsLoaderBase {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static File[] listXmlFiles(final File dir) {
|
||||
File[] files = dir.listFiles(FileFilters.filesWithExtension("xml"));
|
||||
return files != null ? files : ArrayUtil.EMPTY_FILE_ARRAY;
|
||||
private static List<Path> listXmlFiles(@NotNull Path dir) {
|
||||
try {
|
||||
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, it -> it.getFileName().toString().endsWith(".xml") && Files.isRegularFile(it))) {
|
||||
return ContainerUtil.collect(stream.iterator());
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
private void loadFromIpr(File iprFile) {
|
||||
private void loadFromIpr(@NotNull Path iprFile) {
|
||||
final Element iprRoot = loadRootElement(iprFile);
|
||||
|
||||
String projectName = FileUtil.getNameWithoutExtension(iprFile);
|
||||
String projectName = FileUtil.getNameWithoutExtension(iprFile.getFileName().toString());
|
||||
myProject.setName(projectName);
|
||||
File iwsFile = new File(iprFile.getParent(), projectName + ".iws");
|
||||
Element iwsRoot = iwsFile.exists() ? loadRootElement(iwsFile) : null;
|
||||
Path iwsFile = iprFile.getParent().resolve(projectName + ".iws");
|
||||
Element iwsRoot = Files.exists(iwsFile) ? loadRootElement(iwsFile) : null;
|
||||
|
||||
JpsSdkType<?> projectSdkType = loadProjectRoot(iprRoot);
|
||||
for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
|
||||
@@ -226,11 +231,11 @@ public class JpsProjectLoader extends JpsLoaderBase {
|
||||
if (componentRoot == null) return;
|
||||
|
||||
|
||||
final Set<File> foundFiles = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
|
||||
final List<File> moduleFiles = new ArrayList<>();
|
||||
final Set<Path> foundFiles = new THashSet<>();
|
||||
final List<Path> moduleFiles = new ArrayList<>();
|
||||
for (Element moduleElement : JDOMUtil.getChildren(componentRoot.getChild("modules"), "module")) {
|
||||
final String path = moduleElement.getAttributeValue("filepath");
|
||||
final File file = new File(path);
|
||||
final Path file = Paths.get(path);
|
||||
if (foundFiles.add(file)) {
|
||||
moduleFiles.add(file);
|
||||
}
|
||||
@@ -244,28 +249,28 @@ public class JpsProjectLoader extends JpsLoaderBase {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<JpsModule> loadModules(@NotNull List<File> moduleFiles, @Nullable final JpsSdkType<?> projectSdkType,
|
||||
public static List<JpsModule> loadModules(@NotNull List<Path> moduleFiles, @Nullable final JpsSdkType<?> projectSdkType,
|
||||
@NotNull final Map<String, String> pathVariables) {
|
||||
List<JpsModule> modules = new ArrayList<>();
|
||||
List<Future<Pair<File, Element>>> futureModuleFilesContents = new ArrayList<>();
|
||||
List<Future<Pair<Path, Element>>> futureModuleFilesContents = new ArrayList<>();
|
||||
String externalProjectConfigDir = System.getProperty("external.project.config");
|
||||
Path externalModuleDir = StringUtil.isEmptyOrSpaces(externalProjectConfigDir) ? null : Paths.get(externalProjectConfigDir, "modules");
|
||||
if (externalModuleDir != null) {
|
||||
LOG.info("External project config dir is used: " + externalProjectConfigDir);
|
||||
}
|
||||
|
||||
for (final File file : moduleFiles) {
|
||||
for (Path file : moduleFiles) {
|
||||
futureModuleFilesContents.add(ourThreadPool.submit(() -> {
|
||||
final JpsMacroExpander expander = createModuleMacroExpander(pathVariables, file);
|
||||
|
||||
Element data = null;
|
||||
if (file.exists()) {
|
||||
if (Files.exists(file)) {
|
||||
data = loadRootElement(file, expander);
|
||||
}
|
||||
|
||||
Path externalPath = externalModuleDir == null ? null : externalModuleDir.resolve(FileUtilRt.getNameWithoutExtension(file.getName()) + ".xml");
|
||||
Path externalPath = externalModuleDir == null ? null : externalModuleDir.resolve(FileUtilRt.getNameWithoutExtension(file.getFileName().toString()) + ".xml");
|
||||
if (externalPath != null && Files.exists(externalPath)) {
|
||||
Element externalData = loadRootElement(externalPath.toFile(), expander);
|
||||
Element externalData = loadRootElement(externalPath, expander);
|
||||
if (data == null) {
|
||||
data = externalData;
|
||||
}
|
||||
@@ -275,17 +280,16 @@ public class JpsProjectLoader extends JpsLoaderBase {
|
||||
}
|
||||
|
||||
if (data == null) {
|
||||
LOG.info("Module '" + FileUtil.getNameWithoutExtension(file) + "' is skipped: " + file.getAbsolutePath() + " doesn't exist");
|
||||
LOG.info("Module '" + FileUtil.getNameWithoutExtension(file.getFileName().toString()) + "' is skipped: " + file.toAbsolutePath() + " doesn't exist");
|
||||
}
|
||||
|
||||
//new File(file.getName())
|
||||
return Pair.create(file, data);
|
||||
}));
|
||||
}
|
||||
|
||||
try {
|
||||
final List<String> classpathDirs = new ArrayList<>();
|
||||
for (Future<Pair<File, Element>> moduleFile : futureModuleFilesContents) {
|
||||
for (Future<Pair<Path, Element>> moduleFile : futureModuleFilesContents) {
|
||||
final String classpathDir = moduleFile.get().getSecond().getAttributeValue(CLASSPATH_DIR_ATTRIBUTE);
|
||||
if (classpathDir != null) {
|
||||
classpathDirs.add(classpathDir);
|
||||
@@ -293,8 +297,8 @@ public class JpsProjectLoader extends JpsLoaderBase {
|
||||
}
|
||||
|
||||
List<Future<JpsModule>> futures = new ArrayList<>();
|
||||
for (final Future<Pair<File, Element>> futureModuleFile : futureModuleFilesContents) {
|
||||
final Pair<File, Element> moduleFile = futureModuleFile.get();
|
||||
for (final Future<Pair<Path, Element>> futureModuleFile : futureModuleFilesContents) {
|
||||
final Pair<Path, Element> moduleFile = futureModuleFile.get();
|
||||
futures.add(ourThreadPool.submit(
|
||||
() -> loadModule(moduleFile.getFirst(), moduleFile.getSecond(), classpathDirs, projectSdkType, pathVariables)));
|
||||
}
|
||||
@@ -311,21 +315,21 @@ public class JpsProjectLoader extends JpsLoaderBase {
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static JpsModule loadModule(@NotNull File file, @NotNull Element moduleRoot, List<String> paths,
|
||||
@NotNull
|
||||
private static JpsModule loadModule(@NotNull Path file, @NotNull Element moduleRoot, List<String> paths,
|
||||
@Nullable JpsSdkType<?> projectSdkType, Map<String, String> pathVariables) {
|
||||
String name = FileUtil.getNameWithoutExtension(file);
|
||||
String name = FileUtil.getNameWithoutExtension(file.getFileName().toString());
|
||||
final String typeId = moduleRoot.getAttributeValue("type");
|
||||
final JpsModulePropertiesSerializer<?> serializer = getModulePropertiesSerializer(typeId);
|
||||
final JpsModule module = createModule(name, moduleRoot, serializer);
|
||||
module.getContainer().setChild(JpsModuleSerializationDataExtensionImpl.ROLE,
|
||||
new JpsModuleSerializationDataExtensionImpl(file.getParentFile()));
|
||||
new JpsModuleSerializationDataExtensionImpl(file.getParent()));
|
||||
|
||||
for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
|
||||
extension.loadModuleOptions(module, moduleRoot);
|
||||
}
|
||||
|
||||
String baseModulePath = FileUtil.toSystemIndependentName(file.getParent());
|
||||
String baseModulePath = FileUtil.toSystemIndependentName(file.getParent().toString());
|
||||
String classpath = moduleRoot.getAttributeValue(CLASSPATH_ATTRIBUTE);
|
||||
if (classpath == null) {
|
||||
JpsModuleRootModelSerializer.loadRootModel(module, JDomSerializationUtil.findComponent(moduleRoot, "NewModuleRootManager"),
|
||||
@@ -345,9 +349,9 @@ public class JpsProjectLoader extends JpsLoaderBase {
|
||||
return module;
|
||||
}
|
||||
|
||||
static JpsMacroExpander createModuleMacroExpander(final Map<String, String> pathVariables, File moduleFile) {
|
||||
static JpsMacroExpander createModuleMacroExpander(final Map<String, String> pathVariables, @NotNull Path moduleFile) {
|
||||
final JpsMacroExpander expander = new JpsMacroExpander(pathVariables);
|
||||
String moduleDirPath = PathMacroUtil.getModuleDir(moduleFile.getAbsolutePath());
|
||||
String moduleDirPath = PathMacroUtil.getModuleDir(moduleFile.toAbsolutePath().toString());
|
||||
if (moduleDirPath != null) {
|
||||
expander.addFileHierarchyReplacements(PathMacroUtil.MODULE_DIR_MACRO_NAME, new File(FileUtil.toSystemDependentName(moduleDirPath)));
|
||||
}
|
||||
|
||||
+5
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -22,6 +22,7 @@ import org.jetbrains.jps.model.ex.JpsElementChildRoleBase;
|
||||
import org.jetbrains.jps.model.serialization.module.JpsModuleSerializationDataExtension;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
@@ -29,9 +30,9 @@ import java.io.File;
|
||||
public class JpsModuleSerializationDataExtensionImpl extends JpsElementBase<JpsModuleSerializationDataExtensionImpl> implements
|
||||
JpsModuleSerializationDataExtension {
|
||||
public static final JpsElementChildRole<JpsModuleSerializationDataExtension> ROLE = JpsElementChildRoleBase.create("module serialization data");
|
||||
private File myBaseDirectory;
|
||||
private Path myBaseDirectory;
|
||||
|
||||
public JpsModuleSerializationDataExtensionImpl(File baseDirectory) {
|
||||
public JpsModuleSerializationDataExtensionImpl(@NotNull Path baseDirectory) {
|
||||
myBaseDirectory = baseDirectory;
|
||||
}
|
||||
|
||||
@@ -48,6 +49,6 @@ public class JpsModuleSerializationDataExtensionImpl extends JpsElementBase<JpsM
|
||||
@NotNull
|
||||
@Override
|
||||
public File getBaseDirectory() {
|
||||
return myBaseDirectory;
|
||||
return myBaseDirectory.toFile();
|
||||
}
|
||||
}
|
||||
|
||||
+5
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -22,15 +22,16 @@ import org.jetbrains.jps.model.ex.JpsElementChildRoleBase;
|
||||
import org.jetbrains.jps.model.serialization.JpsProjectSerializationDataExtension;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JpsProjectSerializationDataExtensionImpl extends JpsElementBase<JpsProjectSerializationDataExtensionImpl> implements JpsProjectSerializationDataExtension {
|
||||
public static final JpsElementChildRole<JpsProjectSerializationDataExtension> ROLE = JpsElementChildRoleBase.create("serialization data");
|
||||
private File myBaseDirectory;
|
||||
private Path myBaseDirectory;
|
||||
|
||||
public JpsProjectSerializationDataExtensionImpl(File baseDirectory) {
|
||||
public JpsProjectSerializationDataExtensionImpl(@NotNull Path baseDirectory) {
|
||||
myBaseDirectory = baseDirectory;
|
||||
}
|
||||
|
||||
@@ -47,6 +48,6 @@ public class JpsProjectSerializationDataExtensionImpl extends JpsElementBase<Jps
|
||||
@NotNull
|
||||
@Override
|
||||
public File getBaseDirectory() {
|
||||
return myBaseDirectory;
|
||||
return myBaseDirectory.toFile();
|
||||
}
|
||||
}
|
||||
|
||||
+10
-7
@@ -21,9 +21,12 @@ import org.jetbrains.jps.model.artifact.JpsArtifact;
|
||||
import org.jetbrains.jps.model.artifact.JpsArtifactService;
|
||||
import org.jetbrains.jps.model.serialization.artifact.JpsArtifactSerializer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.intellij.testFramework.assertions.Assertions.assertThat;
|
||||
import static org.jetbrains.jps.model.serialization.JpsProjectSerializationTest.SAMPLE_PROJECT_PATH;
|
||||
@@ -40,22 +43,22 @@ public class JpsArtifactSerializationTest extends JpsSerializationTestCase {
|
||||
assertEquals("jar", artifacts.get(1).getName());
|
||||
}
|
||||
|
||||
public void testSaveProject() {
|
||||
public void testSaveProject() throws IOException {
|
||||
loadProject(SAMPLE_PROJECT_PATH);
|
||||
File[] artifactFiles = new File(getTestDataFileAbsolutePath(SAMPLE_PROJECT_PATH + "/.idea/artifacts")).listFiles();
|
||||
List<Path> artifactFiles = Files.list(getTestDataAbsoluteFile(SAMPLE_PROJECT_PATH + ".idea/artifacts")).collect(Collectors.toList());
|
||||
assertNotNull(artifactFiles);
|
||||
for (File file : artifactFiles) {
|
||||
JpsArtifact artifact = getService().createReference(FileUtil.getNameWithoutExtension(file)).asExternal(myModel).resolve();
|
||||
for (Path file : artifactFiles) {
|
||||
JpsArtifact artifact = getService().createReference(FileUtil.getNameWithoutExtension(file.getFileName().toString())).asExternal(myModel).resolve();
|
||||
assertNotNull(artifact);
|
||||
doTestSaveArtifact(artifact, file);
|
||||
}
|
||||
}
|
||||
|
||||
private void doTestSaveArtifact(JpsArtifact artifact, File expectedFile) {
|
||||
private void doTestSaveArtifact(JpsArtifact artifact, Path expectedFile) {
|
||||
Element actual = new Element("component").setAttribute("name", "ArtifactManager");
|
||||
JpsArtifactSerializer.saveArtifact(artifact, actual);
|
||||
JpsMacroExpander
|
||||
expander = JpsProjectLoader.createProjectMacroExpander(Collections.emptyMap(), new File(getTestDataFileAbsolutePath(SAMPLE_PROJECT_PATH)));
|
||||
expander = JpsProjectLoader.createProjectMacroExpander(Collections.emptyMap(), getTestDataAbsoluteFile(SAMPLE_PROJECT_PATH));
|
||||
assertThat(actual).isEqualTo(JpsLoaderBase.loadRootElement(expectedFile, expander));
|
||||
}
|
||||
|
||||
|
||||
+10
-9
@@ -22,6 +22,7 @@ import org.jetbrains.jps.model.library.JpsLibrary;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import static com.intellij.testFramework.assertions.Assertions.assertThat;
|
||||
@@ -45,17 +46,17 @@ public class JpsGlobalSerializationTest extends JpsSerializationTestCase {
|
||||
|
||||
public void testSaveSdksAndGlobalLibraries() {
|
||||
loadGlobalSettings(OPTIONS_DIR);
|
||||
File targetOptionsDir = saveGlobalSettings();
|
||||
File originalOptionsDir = new File(getTestDataFileAbsolutePath(OPTIONS_DIR));
|
||||
Path targetOptionsDir = saveGlobalSettings();
|
||||
Path originalOptionsDir = getTestDataAbsoluteFile(OPTIONS_DIR);
|
||||
assertOptionsFilesEqual(originalOptionsDir, targetOptionsDir, "jdk.table.xml");
|
||||
assertOptionsFilesEqual(originalOptionsDir, targetOptionsDir, "applicationLibraries.xml");
|
||||
}
|
||||
|
||||
private File saveGlobalSettings() {
|
||||
private Path saveGlobalSettings() {
|
||||
try {
|
||||
File targetOptionsDir = FileUtil.createTempDirectory("options", null);
|
||||
JpsSerializationManager.getInstance().saveGlobalSettings(myModel.getGlobal(), targetOptionsDir.getAbsolutePath());
|
||||
return targetOptionsDir;
|
||||
return targetOptionsDir.toPath();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -75,15 +76,15 @@ public class JpsGlobalSerializationTest extends JpsSerializationTestCase {
|
||||
JpsPathVariablesConfiguration configuration = JpsModelSerializationDataService.getOrCreatePathVariablesConfiguration(myModel.getGlobal());
|
||||
configuration.addPathVariable("TOMCAT_HOME", "/home/nik/applications/tomcat");
|
||||
|
||||
File targetOptionsDir = saveGlobalSettings();
|
||||
File originalOptionsDir = new File(getTestDataFileAbsolutePath(OPTIONS_DIR + "AfterChange"));
|
||||
Path targetOptionsDir = saveGlobalSettings();
|
||||
Path originalOptionsDir = getTestDataAbsoluteFile(OPTIONS_DIR + "AfterChange");
|
||||
assertOptionsFilesEqual(originalOptionsDir, targetOptionsDir, "path.macros.xml");
|
||||
}
|
||||
|
||||
private void assertOptionsFilesEqual(File originalOptionsDir, File targetOptionsDir, final String fileName) {
|
||||
private void assertOptionsFilesEqual(Path originalOptionsDir, Path targetOptionsDir, final String fileName) {
|
||||
JpsMacroExpander expander = new JpsMacroExpander(getPathVariables());
|
||||
Element actual = JpsLoaderBase.loadRootElement(new File(targetOptionsDir, fileName), expander);
|
||||
assertThat(actual).isEqualTo(JpsLoaderBase.loadRootElement(new File(originalOptionsDir, fileName), expander));
|
||||
Element actual = JpsLoaderBase.loadRootElement(targetOptionsDir.resolve(fileName), expander);
|
||||
assertThat(actual).isEqualTo(JpsLoaderBase.loadRootElement(originalOptionsDir.resolve(fileName), expander));
|
||||
}
|
||||
|
||||
public void testLoadEncoding() {
|
||||
|
||||
+17
-12
@@ -18,6 +18,7 @@ package org.jetbrains.jps.model.serialization;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.model.JpsDummyElement;
|
||||
import org.jetbrains.jps.model.JpsEncodingConfigurationService;
|
||||
import org.jetbrains.jps.model.JpsEncodingProjectConfiguration;
|
||||
@@ -32,8 +33,12 @@ import org.jetbrains.jps.model.serialization.library.JpsLibraryTableSerializer;
|
||||
import org.jetbrains.jps.model.serialization.module.JpsModuleRootModelSerializer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.intellij.testFramework.assertions.Assertions.assertThat;
|
||||
|
||||
@@ -45,8 +50,8 @@ public class JpsProjectSerializationTest extends JpsSerializationTestCase {
|
||||
|
||||
public void testLoadProject() {
|
||||
loadProject(SAMPLE_PROJECT_PATH);
|
||||
String baseDirPath = getTestDataFileAbsolutePath(SAMPLE_PROJECT_PATH);
|
||||
assertTrue(FileUtil.filesEqual(new File(baseDirPath), JpsModelSerializationDataService.getBaseDirectory(myProject)));
|
||||
File baseDirPath = getTestDataAbsoluteFile(SAMPLE_PROJECT_PATH).toFile();
|
||||
assertTrue(FileUtil.filesEqual(baseDirPath, JpsModelSerializationDataService.getBaseDirectory(myProject)));
|
||||
assertEquals("sampleProjectName", myProject.getName());
|
||||
List<JpsModule> modules = myProject.getModules();
|
||||
assertEquals(3, modules.size());
|
||||
@@ -84,10 +89,10 @@ public class JpsProjectSerializationTest extends JpsSerializationTestCase {
|
||||
|
||||
public void testFileBasedProjectNameAndBaseDir() {
|
||||
String relativePath = "/jps/model-serialization/testData/run-configurations/run-configurations.ipr";
|
||||
String absolutePath = getTestDataFileAbsolutePath(relativePath);
|
||||
Path absolutePath = getTestDataAbsoluteFile(relativePath);
|
||||
loadProject(relativePath);
|
||||
assertEquals("run-configurations", myProject.getName());
|
||||
assertTrue(FileUtil.filesEqual(new File(absolutePath).getParentFile(), JpsModelSerializationDataService.getBaseDirectory(myProject)));
|
||||
assertTrue(FileUtil.filesEqual(absolutePath.getParent().toFile(), JpsModelSerializationDataService.getBaseDirectory(myProject)));
|
||||
}
|
||||
|
||||
public void testDirectoryBasedProjectName() {
|
||||
@@ -207,7 +212,7 @@ public class JpsProjectSerializationTest extends JpsSerializationTestCase {
|
||||
assertEquals(relativeOutput, properties.getRelativeOutputPath());
|
||||
}
|
||||
|
||||
public void testSaveProject() {
|
||||
public void testSaveProject() throws IOException {
|
||||
loadProject(SAMPLE_PROJECT_PATH);
|
||||
List<JpsModule> modules = myProject.getModules();
|
||||
doTestSaveModule(modules.get(0), SAMPLE_PROJECT_PATH + "/main.iml");
|
||||
@@ -215,17 +220,17 @@ public class JpsProjectSerializationTest extends JpsSerializationTestCase {
|
||||
//tod[nik] remember that test output root wasn't specified and doesn't save it to avoid unnecessary modifications of iml files
|
||||
//doTestSaveModule(modules.get(2), "xxx/xxx.iml");
|
||||
|
||||
File[] libs = getFileInSampleProject(".idea/libraries").listFiles();
|
||||
List<Path> libs = Files.list(getFileInSampleProject(".idea/libraries")).collect(Collectors.toList());
|
||||
assertNotNull(libs);
|
||||
for (File libFile : libs) {
|
||||
String libName = FileUtil.getNameWithoutExtension(libFile);
|
||||
for (Path libFile : libs) {
|
||||
String libName = FileUtil.getNameWithoutExtension(libFile.getFileName().toString());
|
||||
JpsLibrary library = myProject.getLibraryCollection().findLibrary(libName);
|
||||
assertNotNull(libName, library);
|
||||
doTestSaveLibrary(libFile, libName, library);
|
||||
}
|
||||
}
|
||||
|
||||
private void doTestSaveLibrary(File libFile, String libName, JpsLibrary library) {
|
||||
private void doTestSaveLibrary(@NotNull Path libFile, String libName, JpsLibrary library) {
|
||||
Element actual = new Element("library");
|
||||
JpsLibraryTableSerializer.saveLibrary(library, actual, libName);
|
||||
JpsMacroExpander
|
||||
@@ -238,7 +243,7 @@ public class JpsProjectSerializationTest extends JpsSerializationTestCase {
|
||||
try {
|
||||
Element actual = JDomSerializationUtil.createComponentElement("NewModuleRootManager");
|
||||
JpsModuleRootModelSerializer.saveRootModel(module, actual);
|
||||
File imlFile = new File(getTestDataFileAbsolutePath(moduleFilePath));
|
||||
Path imlFile = getTestDataAbsoluteFile(moduleFilePath);
|
||||
Element rootElement = loadModuleRootTag(imlFile);
|
||||
assertThat(actual).isEqualTo(JDomSerializationUtil.findComponent(rootElement, "NewModuleRootManager"));
|
||||
}
|
||||
@@ -247,8 +252,8 @@ public class JpsProjectSerializationTest extends JpsSerializationTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public File getFileInSampleProject(String relativePath) {
|
||||
return new File(getTestDataFileAbsolutePath(SAMPLE_PROJECT_PATH + "/" + relativePath));
|
||||
public Path getFileInSampleProject(String relativePath) {
|
||||
return getTestDataAbsoluteFile(SAMPLE_PROJECT_PATH + "/" + relativePath);
|
||||
}
|
||||
|
||||
public void testLoadIdeaProject() {
|
||||
|
||||
+10
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -22,10 +22,12 @@ 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.File;
|
||||
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,7 +89,12 @@ public abstract class JpsSerializationTestCase extends JpsModelTestCase {
|
||||
return PathManagerEx.findFileUnderProjectHome(relativePath, getClass()).getAbsolutePath();
|
||||
}
|
||||
|
||||
protected static Element loadModuleRootTag(File imlFile) {
|
||||
@NotNull
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user