public void execute()

in meecrowave-maven-plugin/src/main/java/org/apache/meecrowave/maven/MeecrowaveBundleMojo.java [173:318]


    public void execute() throws MojoExecutionException, MojoFailureException {
        if (skip) {
            getLog().warn(getClass().getSimpleName() + " skipped");
            return;
        }

        final File distroFolder = new File(buildDirectory, rootName == null ? artifactId + "-distribution" : rootName);
        if (distroFolder.exists()) {
            delete(distroFolder);
        }

        Stream.of("bin", "conf", "logs", "lib").forEach(i -> new File(distroFolder, i).mkdirs());

        copyProvidedFiles(distroFolder);

        write(new File(distroFolder, "logs/you_can_safely_delete.txt"), DELETE_TEXT);
        final Collection<String> includedArtifacts = project.getArtifacts().stream()
                .filter(this::isIncluded)
                .map(a -> {
                    addLib(distroFolder, a.getFile());
                    return a.getArtifactId();
                }).collect(toList());
        if (app.exists()) {
            addLib(distroFolder, app);
        }
        if (webapp != null && webapp.isDirectory()) {
            try {
                final Path rootSrc = webapp.toPath().toAbsolutePath();
                final Path rootTarget = distroFolder.toPath().toAbsolutePath().resolve("docBase");
                Files.walkFileTree(rootSrc, new SimpleFileVisitor<Path>() {
                    @Override
                    public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
                        final Path target = rootTarget.resolve(rootSrc.relativize(file));
                        target.toFile().getParentFile().mkdirs();
                        Files.copy(file, target, StandardCopyOption.REPLACE_EXISTING);
                        return super.visitFile(file, attrs);
                    }
                });
            } catch (final IOException e) {
                throw new MojoExecutionException(e.getMessage(), e);
            }
        }
        if (enforceCommonsCli && !includedArtifacts.contains("commons-cli")) {
            addLib(distroFolder, resolve("commons-cli", "commons-cli", "1.4", ""));
        }
        if (libs != null) {
            libs.forEach(l -> {
                final boolean transitive = l.endsWith("?transitive");
                final String coords = transitive ? l.substring(0, l.length() - "?transitive".length()) : l;
                final String[] c = coords.split(":");
                if (c.length < 3 || c.length > 5) {
                    throw new IllegalArgumentException("libs syntax is groupId:artifactId:version[:classifier][:type[?transitive]]");
                }
                if (!transitive) {
                    addLib(distroFolder, resolve(c[0], c[1], c[2], c.length == 4 ? c[3] : ""));
                } else {
                    addTransitiveDependencies(distroFolder, includedArtifacts, new Dependency() {{
                        setGroupId(c[0]);
                        setArtifactId(c[1]);
                        setVersion(c[2]);
                        if (c.length == 4 && !"-".equals(c[3])) {
                            setClassifier(c[3]);
                        }
                        if (c.length == 5) {
                            setType(c[4]);
                        }
                    }});
                }
            });
        }
        if (enforceMeecrowave && !includedArtifacts.contains("meecrowave-core")) {
            addTransitiveDependencies(distroFolder, includedArtifacts, new Dependency() {{
                setGroupId("org.apache.meecrowave");
                setArtifactId("meecrowave-core");
                setVersion(findVersion());
            }});
        }

        for (final String ext : asList("sh", "bat")) {
            try (final BufferedReader reader = new BufferedReader(new InputStreamReader(
                    Thread.currentThread().getContextClassLoader().getResourceAsStream("bin/meecrowave." + ext)))) {
                final File target = new File(distroFolder, "bin/meecrowave." + ext);
                if (!target.exists()) {
                    write(target, new Substitutor(new HashMap<String, String>() {{
                        put("main", main);
                        put("logManager", hasLog4j(distroFolder) ?
                                "org.apache.logging.log4j.jul.LogManager" : "org.apache.juli.ClassLoaderLogManager");
                    }}).replace(reader.lines().collect(joining("\n"))));
                }
            } catch (final IOException e) {
                throw new MojoExecutionException(e.getMessage(), e);
            }
        }
        if (fakeTomcatScripts) {
            Stream.of("catalina.sh", "shutdown.sh", "startup.sh").forEach(script -> {
                try (final BufferedReader reader = new BufferedReader(new InputStreamReader(
                        Thread.currentThread().getContextClassLoader().getResourceAsStream("bin/" + script)))) {
                    final File target = new File(distroFolder, "bin/" + script);
                    if (!target.exists()) {
                        write(target, reader.lines().collect(joining("\n")));
                    }
                } catch (final IOException e) {
                    throw new IllegalStateException(e.getMessage(), e);
                }
            });
        }

        final Path prefix = skipArchiveRootFolder ? distroFolder.toPath() : distroFolder.getParentFile().toPath();
        for (final String format : formats) {
            getLog().info(format + "-ing Custom Meecrowave Distribution");

            final File output = new File(buildDirectory, artifactId + "-meecrowave-distribution." + format);

            switch (format.toLowerCase(ENGLISH)) {
                case "tar.gz":
                    try (final TarArchiveOutputStream tarGz =
                                 new TarArchiveOutputStream(new GZIPOutputStream(new FileOutputStream(output)))) {
                        tarGz.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
                        for (final String entry : distroFolder.list()) {
                            tarGz(tarGz, new File(distroFolder, entry), prefix);
                        }
                    } catch (final IOException e) {
                        throw new MojoExecutionException(e.getMessage(), e);
                    }
                    break;
                case "zip":
                    try (final ZipArchiveOutputStream zos =
                                 new ZipArchiveOutputStream(new FileOutputStream(output))) {
                        for (final String entry : distroFolder.list()) {
                            zip(zos, new File(distroFolder, entry), prefix);
                        }
                    } catch (final IOException e) {
                        throw new MojoExecutionException(e.getMessage(), e);
                    }
                    break;
                default:
                    throw new IllegalArgumentException(format + " is not supported");
            }

            attach(format, output);
        }

        if (!keepExplodedFolder) {
            delete(distroFolder);
        }
    }