mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
file copying with NIO with fallback to FileUtil extracted to a utility method; Updated MavenResourcesBuilder (followup IDEA-CR-39342)
This commit is contained in:
@@ -40,10 +40,7 @@ import org.jetbrains.jps.model.module.JpsModule;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.FileVisitResult;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.SimpleFileVisitor;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@@ -350,6 +347,30 @@ public class FSOperations {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
public static void copy(File fromFile, File toFile) throws IOException {
|
||||
final Path from = fromFile.toPath();
|
||||
final Path to = toFile.toPath();
|
||||
try {
|
||||
try {
|
||||
Files.copy(from, to, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
catch (NoSuchFileException e) {
|
||||
final File parent = toFile.getParentFile();
|
||||
if (parent != null && parent.mkdirs()) {
|
||||
Files.copy(from, to, StandardCopyOption.REPLACE_EXISTING); // repeat on successful target dir creation
|
||||
}
|
||||
else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
// fallback: trying 'classic' copying via streams
|
||||
LOG.info("Error copying "+ fromFile.getPath() + " to " + toFile.getPath() + " with NIO API", e);
|
||||
FileUtil.copyContent(fromFile, toFile);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isMarkedDirty(CompileContext context, BuildTarget<?> target) {
|
||||
synchronized (TARGETS_COMPLETELY_MARKED_DIRTY) {
|
||||
Set<BuildTarget<?>> marked = TARGETS_COMPLETELY_MARKED_DIRTY.get(context);
|
||||
|
||||
@@ -9,10 +9,7 @@ import org.jetbrains.jps.builders.DirtyFilesHolder;
|
||||
import org.jetbrains.jps.builders.java.ResourceRootDescriptor;
|
||||
import org.jetbrains.jps.builders.java.ResourcesTargetType;
|
||||
import org.jetbrains.jps.builders.storage.BuildDataCorruptedException;
|
||||
import org.jetbrains.jps.incremental.CompileContext;
|
||||
import org.jetbrains.jps.incremental.ProjectBuildException;
|
||||
import org.jetbrains.jps.incremental.ResourcesTarget;
|
||||
import org.jetbrains.jps.incremental.TargetBuilder;
|
||||
import org.jetbrains.jps.incremental.*;
|
||||
import org.jetbrains.jps.incremental.messages.BuildMessage;
|
||||
import org.jetbrains.jps.incremental.messages.CompilerMessage;
|
||||
import org.jetbrains.jps.incremental.messages.ProgressMessage;
|
||||
@@ -20,10 +17,6 @@ import org.jetbrains.jps.model.module.JpsModule;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@@ -118,30 +111,9 @@ public class ResourcesBuilder extends TargetBuilder<ResourceRootDescriptor, Reso
|
||||
targetPath.append('/').append(relativePath);
|
||||
|
||||
context.processMessage(new ProgressMessage("Copying resources... [" + rd.getTarget().getModule().getName() + "]"));
|
||||
|
||||
final File targetFile = new File(targetPath.toString());
|
||||
try {
|
||||
final Path from = file.toPath();
|
||||
final Path to = targetFile.toPath();
|
||||
try {
|
||||
try {
|
||||
Files.copy(from, to, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
catch (NoSuchFileException e) {
|
||||
final File parent = targetFile.getParentFile();
|
||||
if (parent != null && parent.mkdirs()) {
|
||||
Files.copy(from, to, StandardCopyOption.REPLACE_EXISTING); // repeat on successful target dir creation
|
||||
}
|
||||
else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
// fallback: trying 'classic' copying via streams
|
||||
LOG.info("Error copying resource "+ file.getPath() + " to " + targetFile.getPath() + " with NIO API", e);
|
||||
FileUtil.copyContent(file, targetFile);
|
||||
}
|
||||
final File targetFile = new File(targetPath.toString());
|
||||
FSOperations.copy(file, targetFile);
|
||||
outputConsumer.registerOutputFile(targetFile, Collections.singletonList(file.getPath()));
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
||||
+2
-15
@@ -21,6 +21,7 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.incremental.CompileContext;
|
||||
import org.jetbrains.jps.incremental.FSOperations;
|
||||
import org.jetbrains.jps.incremental.messages.BuildMessage;
|
||||
import org.jetbrains.jps.incremental.messages.CompilerMessage;
|
||||
import org.jetbrains.jps.maven.model.impl.MavenModuleResourceConfiguration;
|
||||
@@ -31,10 +32,6 @@ import org.jetbrains.jps.model.JpsEncodingProjectConfiguration;
|
||||
import org.jetbrains.jps.model.JpsProject;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
@@ -81,17 +78,7 @@ public class MavenResourceFileProcessor {
|
||||
copyWithFiltering(file, targetFile);
|
||||
}
|
||||
else {
|
||||
final Path from = file.toPath();
|
||||
final Path to = targetFile.toPath();
|
||||
try {
|
||||
Files.copy(from, to, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
catch (NoSuchFileException e) {
|
||||
final File parent = targetFile.getParentFile();
|
||||
if (parent != null && parent.mkdirs()) {
|
||||
Files.copy(from, to, StandardCopyOption.REPLACE_EXISTING); // repeat on successful target dir creation
|
||||
}
|
||||
}
|
||||
FSOperations.copy(file, targetFile);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user