package lwjar;

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

public class PreCompileCommand implements Command {

    private final Path sourceFileDir;
    private final Path classesFileDir;
    private final Path outputDir;
    private final Path workSrcDir;
    private final Path workClassesDir;

    public PreCompileCommand(Path sourceFileDir, Path classesFileDir, Path outputDir) {
        this.sourceFileDir = sourceFileDir;
        this.classesFileDir = classesFileDir;
        this.outputDir = outputDir;
        this.workSrcDir = this.outputDir.resolve("src");
        this.workClassesDir = this.outputDir.resolve("classes");
    }

    @Override
    public void execute() throws IOException {
        this.copySourceFiles();
    }

    private void copySourceFiles() throws IOException {
        Files.createDirectories(this.workSrcDir);

        Files.walk(this.sourceFileDir)
            .filter(path -> path.getFileName().toString().endsWith(".java"))
            .forEach(javaFile -> {
                Path relativePath = this.sourceFileDir.relativize(javaFile);
                Path copyTo = this.workSrcDir.resolve(relativePath);

                if (Files.notExists(copyTo.getParent())) {
                    try {
                        Files.createDirectories(copyTo.getParent());
                    } catch (IOException e) {
                        throw new UncheckedIOException("failed to create output directory.", e);
                    }
                }

                try {
                    Files.copy(javaFile, copyTo);
                } catch (IOException e) {
                    throw new UncheckedIOException("failed to copy source file.", e);
                }
            });
    }
}

@@ -827,24 +827,58 @@
 ceFiles();%0D%0A
+        this.copyClassesFiles();%0D%0A
     %7D%0D%0A%0D%0A   
@@ -1880,12 +1880,899 @@
 %0D%0A    %7D%0D
+%0A%0D%0A    private void copyClassesFiles() throws IOException %7B%0D%0A        Files.walk(this.classesFileDir)%0D%0A            .forEach(classFile -%3E %7B%0D%0A                Path relativePath = this.classesFileDir.relativize(classFile);%0D%0A                Path copyTo = this.workClassesDir.resolve(relativePath);%0D%0A%0D%0A                if (Files.notExists(copyTo.getParent())) %7B%0D%0A                    try %7B%0D%0A                        Files.createDirectories(copyTo.getParent());%0D%0A                    %7D catch (IOException e) %7B%0D%0A                        throw new UncheckedIOException(%22failed to create output directory.%22, e);%0D%0A                    %7D%0D%0A                %7D%0D%0A%0D%0A                try %7B%0D%0A                    Files.copy(classFile, copyTo);%0D%0A                %7D catch (IOException e) %7B%0D%0A                    throw new UncheckedIOException(%22failed to copy class file.%22, e);%0D%0A                %7D%0D%0A            %7D);%0D%0A    %7D%0D
 %0A%7D%0D%0A

copy class files