|
35 | 35 | import java.net.URLClassLoader; |
36 | 36 | import java.nio.charset.Charset; |
37 | 37 | import java.nio.charset.IllegalCharsetNameException; |
| 38 | +import java.nio.charset.StandardCharsets; |
38 | 39 | import java.nio.file.FileVisitResult; |
39 | 40 | import java.nio.file.Files; |
40 | 41 | import java.nio.file.Path; |
@@ -825,46 +826,57 @@ protected static void invokeMaven( |
825 | 826 | InvocationResult result = invoke(log, invoker, request, invokerLog, goals, properties, null); |
826 | 827 |
|
827 | 828 | if (result.getExitCode() != 0) { |
828 | | - String invokerLogContent = readFile(invokerLog, "UTF-8"); |
| 829 | + try { |
| 830 | + String invokerLogContent = new String(Files.readAllBytes(invokerLog.toPath()), StandardCharsets.UTF_8); |
829 | 831 |
|
830 | | - // see DefaultMaven |
831 | | - if (invokerLogContent != null |
832 | | - && (!invokerLogContent.contains("Scanning for projects...") |
833 | | - || invokerLogContent.contains(OutOfMemoryError.class.getName()))) { |
834 | | - if (log != null) { |
835 | | - log.error("Error occurred during initialization of VM, trying to use an empty MAVEN_OPTS..."); |
| 832 | + // see DefaultMaven |
| 833 | + if (!invokerLogContent.contains("Scanning for projects...") |
| 834 | + || invokerLogContent.contains(OutOfMemoryError.class.getName())) { |
| 835 | + if (log != null) { |
| 836 | + log.error("Error occurred during initialization of VM, trying to use an empty MAVEN_OPTS..."); |
836 | 837 |
|
837 | | - if (log.isDebugEnabled()) { |
838 | | - log.debug("Reinvoking Maven for the goals: " + goals + " with an empty MAVEN_OPTS..."); |
| 838 | + if (log.isDebugEnabled()) { |
| 839 | + log.debug("Reinvoking Maven for the goals: " + goals + " with an empty MAVEN_OPTS..."); |
| 840 | + } |
839 | 841 | } |
840 | 842 | } |
841 | | - result = invoke(log, invoker, request, invokerLog, goals, properties, ""); |
| 843 | + } catch (IOException e) { |
| 844 | + // ignore |
842 | 845 | } |
| 846 | + result = invoke(log, invoker, request, invokerLog, goals, properties, ""); |
843 | 847 | } |
844 | 848 |
|
845 | 849 | if (result.getExitCode() != 0) { |
846 | | - String invokerLogContent = readFile(invokerLog, "UTF-8"); |
| 850 | + try { |
| 851 | + String invokerLogContent = new String(Files.readAllBytes(invokerLog.toPath()), StandardCharsets.UTF_8); |
847 | 852 |
|
848 | | - // see DefaultMaven |
849 | | - if (invokerLogContent != null |
850 | | - && (!invokerLogContent.contains("Scanning for projects...") |
851 | | - || invokerLogContent.contains(OutOfMemoryError.class.getName()))) { |
852 | | - throw new MavenInvocationException(ERROR_INIT_VM); |
853 | | - } |
| 853 | + // see DefaultMaven |
| 854 | + if (!invokerLogContent.contains("Scanning for projects...") |
| 855 | + || invokerLogContent.contains(OutOfMemoryError.class.getName())) { |
| 856 | + throw new MavenInvocationException(ERROR_INIT_VM); |
| 857 | + } |
854 | 858 |
|
855 | | - throw new MavenInvocationException( |
856 | | - "Error when invoking Maven, consult the invoker log file: " + invokerLog.getAbsolutePath()); |
| 859 | + throw new MavenInvocationException( |
| 860 | + "Error when invoking Maven, consult the invoker log file: " + invokerLog.getAbsolutePath()); |
| 861 | + } catch (IOException ex) { |
| 862 | + // ignore |
| 863 | + } |
| 864 | + throw new MavenInvocationException(ERROR_INIT_VM); |
857 | 865 | } |
858 | 866 | } |
859 | 867 |
|
860 | 868 | /** |
861 | 869 | * Read the given file and return the content or null if an IOException occurs. |
862 | 870 | * |
863 | | - * @param javaFile not null |
864 | | - * @param encoding could be null |
865 | | - * @return the content of the given javaFile using the given encoding |
| 871 | + * @param javaFile the file to read; not null |
| 872 | + * @param encoding a character set name; not null |
| 873 | + * @return the content of the given file using the given encoding; null if an IOException occurs |
866 | 874 | * @since 2.6.1 |
| 875 | + * @throws java.nio.charset.UnsupportedCharsetException if the named charset is not supported |
| 876 | + * @throws NullPointerException if the javaFile or encoding is null |
| 877 | + * @deprecated use Files.readString(Path, Charset) in Java 11+ or new String(Files.readAllBytes(Path), Charset) in Java 8 |
867 | 878 | */ |
| 879 | + @Deprecated |
868 | 880 | protected static String readFile(final File javaFile, final String encoding) { |
869 | 881 | try { |
870 | 882 | return new String(Files.readAllBytes(javaFile.toPath()), Charset.forName(encoding)); |
|
0 commit comments