package lwjar.precompile;

import lwjar.GlobalOption;
import lwjar.primitive.Directory;
import lwjar.primitive.RelativePath;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;

class ErrorLogFile {
    private final static String FILE_NAME = "compile-errors.log";
    private final Path file;

    ErrorLogFile(OutputDirectory outputDirectory) {
        this.file = outputDirectory.resolve(FILE_NAME).getPath();
    }
    
    void append(String text) {
        if (text.isEmpty()) {
            return;
        }

        try {
            Files.write(this.file, text.getBytes(GlobalOption.getEncoding()), StandardOpenOption.APPEND, StandardOpenOption.CREATE);
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }
}

@@ -73,25 +73,30 @@
 imitive.
-Directory
+ProcessingFile
 ;%0D%0Aimpor
@@ -134,104 +134,8 @@
 %0D%0A%0D%0A
-import java.io.IOException;%0D%0Aimport java.io.UncheckedIOException;%0D%0Aimport java.nio.file.Files;%0D%0A
 impo
@@ -155,16 +155,17 @@
 ile.Path
+s
 ;%0D%0Aimpor
@@ -175,89 +175,76 @@
 ava.
-nio.file.Paths;%0D%0Aimport java.nio.file.StandardOpenOption;%0D%0A%0D%0Aclass ErrorLogFile %7B
+util.Objects;%0D%0A%0D%0Aclass ErrorLogFile %7B%0D%0A    private static int n = 1;
 %0D%0A  
@@ -300,16 +300,19 @@
 e-errors
+-%25d
 .log%22;%0D%0A
@@ -333,20 +333,46 @@
 nal 
-Path file;%0D%0A
+OutputDirectory outputDirectory;%0D%0A    
 %0D%0A  
@@ -439,15 +439,8 @@
 his.
-file = 
 outp
@@ -454,68 +454,93 @@
 tory
-.resolve(FILE_NAME).getPath();%0D%0A    %7D%0D%0A    %0D%0A    void append
+ = Objects.requireNonNull(outputDirectory);%0D%0A    %7D%0D%0A    %0D%0A    synchronized void write
 (Str
@@ -629,241 +629,237 @@
     
+S
 tr
-y %7B%0D%0A            Files.write(
+ing fileName = String.format(FILE_NAME, n);%0D%0A        ProcessingFile file = this.outputDirectory.resolveFile(new RelativePath(Pa
 th
-i
 s.
-file, text.getBytes(GlobalOption.getEncoding()), StandardOpenOption.APPEND, StandardOpenOption.CREATE);%0D%0A        %7D catch (IOException e) %7B%0D%0A            throw new UncheckedIOException(e);%0D%0A        %7D
+get(fileName)));%0D%0A        file.write(text, GlobalOption.getEncoding());%0D%0A        %0D%0A        n++;
 %0D%0A  

split compile error file