private void bootstrapCoursier()

in src/main/java/software/amazon/smithy/plugin/SmithyPostStartupActivity.java [69:104]


    private void bootstrapCoursier(Project project) {
        File dir = new File(project.getBasePath() + COURSIER_DIR);
        if (!dir.exists()) {
            boolean created = dir.mkdir();
            if (!created) {
                throw new RuntimeException("Could not make directory for Coursier: " + project.getBasePath()
                        + COURSIER_DIR);
            }
        }

        String bin = project.getBasePath() + COURSIER_BIN;
        // If Coursier cli has already been setup and can be executed, return early.
        File existingCoursier = new File(bin);
        if (existingCoursier.exists() && existingCoursier.canExecute()) {
            return;
        }

        // Copy Coursier cli from jar to temporary location, setting it as executable.
        try (
                InputStream inputStream = getClass().getResource(COURSIER_JAR).openStream();
                OutputStream outputStream = new FileOutputStream(bin);
        ) {
            byte[] b = new byte[2048];
            int length;

            while ((length = inputStream.read(b)) != -1) {
                outputStream.write(b, 0, length);
            }
            inputStream.close();
            outputStream.close();
            File coursier = new File(bin);
            coursier.setExecutable(true);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }