mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
maven resource builder: properly handle FileNotFound exceptions when copying resources
This commit is contained in:
+35
-18
@@ -19,9 +19,7 @@ import org.jetbrains.jps.incremental.messages.CompilerMessage;
|
||||
import org.jetbrains.jps.maven.model.JpsMavenExtensionService;
|
||||
import org.jetbrains.jps.maven.model.impl.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.*;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -91,29 +89,48 @@ public class MavenResourcesBuilder extends TargetBuilder<MavenResourceRootDescri
|
||||
context.processMessage(new CompilerMessage("MavenResources", BuildMessage.Kind.WARNING, "File is too big to be filtered. Most likely it is a binary file and should be excluded from filtering", sourcePath));
|
||||
shouldFilter = false;
|
||||
}
|
||||
if (shouldFilter) {
|
||||
final PrintWriter printWriter = encoding != null? new PrintWriter(outputFile, encoding) : new PrintWriter(outputFile);
|
||||
try {
|
||||
final byte[] bytes = FileUtil.loadFileBytes(file);
|
||||
final String text = encoding != null? new String(bytes, encoding) : new String(bytes);
|
||||
doFilterText(
|
||||
getDelimitersPattern(), text, projectConfig, config, endsWith(file.getName(), ".properties") ? "\\" : null, getProperties(), null, printWriter
|
||||
);
|
||||
try {
|
||||
if (shouldFilter) {
|
||||
copyWithFiltering(file, outputFile);
|
||||
}
|
||||
finally {
|
||||
printWriter.close();
|
||||
else {
|
||||
FileUtil.copyContent(file, outputFile);
|
||||
}
|
||||
outputConsumer.registerOutputFile(outputFile.getPath(), Collections.singleton(sourcePath));
|
||||
}
|
||||
else {
|
||||
FileUtil.copyContent(file, outputFile);
|
||||
catch (UnsupportedEncodingException e) {
|
||||
context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.INFO, "Resource was not copied: " + e.getMessage(), sourcePath));
|
||||
}
|
||||
outputConsumer.registerOutputFile(outputFile.getPath(), Collections.singleton(sourcePath));
|
||||
if (cleanedSources != null) {
|
||||
cleanedSources.remove(file);
|
||||
finally {
|
||||
if (cleanedSources != null) {
|
||||
cleanedSources.remove(file);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void copyWithFiltering(File file, File outputFile) throws IOException {
|
||||
PrintWriter writer;
|
||||
try {
|
||||
writer = encoding != null ? new PrintWriter(outputFile, encoding) : new PrintWriter(outputFile);
|
||||
}
|
||||
catch (FileNotFoundException e) {
|
||||
FileUtil.createIfDoesntExist(outputFile);
|
||||
writer = encoding != null ? new PrintWriter(outputFile, encoding) : new PrintWriter(outputFile);
|
||||
}
|
||||
try {
|
||||
final byte[] bytes = FileUtil.loadFileBytes(file);
|
||||
final String text = encoding != null? new String(bytes, encoding) : new String(bytes);
|
||||
doFilterText(
|
||||
getDelimitersPattern(), text, projectConfig, config, endsWith(file.getName(), ".properties") ? "\\" : null, getProperties(), null,
|
||||
writer
|
||||
);
|
||||
}
|
||||
finally {
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
|
||||
private Pattern getDelimitersPattern() {
|
||||
Pattern pattern = myDelimitersPattern;
|
||||
if (pattern == null) {
|
||||
|
||||
Reference in New Issue
Block a user