[jps] uses NIO in Java module index

... because of better diagnostics
This commit is contained in:
Roman Shevchenko
2017-11-23 19:01:58 +01:00
parent 6246c057d9
commit a9621dba5b
@@ -1,18 +1,4 @@
/*
* 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-2017 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 org.jetbrains.jps.model.java.impl;
import com.intellij.openapi.util.io.FileUtil;
@@ -30,6 +16,8 @@ import org.jetbrains.jps.model.module.JpsModuleSourceRoot;
import org.jetbrains.jps.util.JpsPathUtil;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.Map;
import java.util.Properties;
@@ -104,22 +92,22 @@ public class JavaModuleIndexImpl extends JpsElementBase<JavaModuleIndexImpl> imp
p.setProperty(key, path != null ? FileUtil.toSystemDependentName(path) : NULL_PATH);
}
File index = new File(storageRoot, INDEX_PATH);
FileUtil.createParentDirs(index);
Path index = new File(storageRoot, INDEX_PATH).toPath();
Files.createDirectories(index.getParent());
try (Writer writer = new OutputStreamWriter(new FileOutputStream(index), CharsetToolkit.UTF8_CHARSET)) {
try (Writer writer = Files.newBufferedWriter(index, CharsetToolkit.UTF8_CHARSET)) {
p.store(writer, null);
}
}
public static JavaModuleIndex load(@NotNull File storageRoot, @NotNull JpsCompilerExcludes excludes) {
File index = new File(storageRoot, INDEX_PATH);
if (!index.exists()) {
Path index = new File(storageRoot, INDEX_PATH).toPath();
if (!Files.exists(index)) {
return new JavaModuleIndexImpl(excludes);
}
Properties p = new Properties();
try (Reader reader = new InputStreamReader(new FileInputStream(index), CharsetToolkit.UTF8_CHARSET)) {
try (Reader reader = Files.newBufferedReader(index, CharsetToolkit.UTF8_CHARSET)) {
p.load(reader);
}
catch (IOException e) {