void copyIcon()

in nbm-maven-plugin/src/main/java/org/apache/netbeans/nbm/BuildMacMojo.java [207:229]


    void copyIcon(File resourcesDir) throws IOException, MojoExecutionException {
        Path icnsPath = resourcesDir.toPath().resolve(brandingToken + ".icns");

        if (macIconFile != null) {
            FileUtils.copyFile(macIconFile, icnsPath.toFile());
        } else {
            URL harnessResource = getClass().getClassLoader().getResource("harness");
            JarURLConnection jarConnection = (JarURLConnection) harnessResource.openConnection();
            JarFile jarFile = jarConnection.getJarFile();

            JarEntry entry = jarFile.getJarEntry("harness/etc/applicationIcon.icns");

            if (entry == null) {
                throw new MojoExecutionException("macOS icon not found in harness or via macIconFile parameter");
            }

            try (InputStream entryInputStream = jarFile.getInputStream(entry)) {
                Files.copy(entryInputStream, icnsPath, StandardCopyOption.REPLACE_EXISTING);
            }

            getLog().info("macOS icon not provided with macIconFile, using default icon.");
        }
    }