public static void main()

in src/main/java/org/apache/tomee/website/SvnPub.java [56:162]


    public static void main(final String[] args) throws SVNException, IOException, Base64DecodingException {
        SVNJNAUtil.setJNAEnabled(false); // svnkit and java 8 == easy sigsev on ubuntu (fixed when upgrading svnkit version)

        final String username = System.getProperty("site.username", System.getenv("USER"));
        final String password = args == null || args.length == 0 ?
                System.getProperty("site.password") : ofNullable(args[0]).filter(s -> !"notset".equalsIgnoreCase(s)).orElse(null);
        if (password == null) {
            throw new IllegalArgumentException("No site.password system property set");
        }

        final ISVNAuthenticationManager authenticationManager = SVNWCUtil.createDefaultAuthenticationManager(username, password.toCharArray());
        final SVNClientManager client = SVNClientManager.newInstance(new DefaultSVNOptions(), authenticationManager);
        final SVNUpdateClient update = client.getUpdateClient();
        update.setIgnoreExternals(true);
        final File copy = new File(".content-site-checkout");
        if (copy.exists()) {
            System.out.println("Cleaning up local copy");
            client.getWCClient().doCleanup(copy);

            System.out.println("Reverting local copy to start from a clean one");
            final SvnRevert revert = update.getOperationsFactory().createRevert();
            revert.setPreserveModifiedCopies(false);
            revert.setRevertMissingDirectories(true);
            revert.setDepth(SVNDepth.INFINITY);
            revert.addTarget(SvnTarget.fromFile(copy));
            revert.run();

            System.out.println("SVN site revision #" + update.doUpdate(copy, SVNRevision.HEAD, SVNDepth.INFINITY, false, true));
        } else {
            System.out.println("Doing a site checkout, can be a bit long the first time but it is cached, grab a coffee ;)");
            System.out.println("SVN site revision #" + update.doCheckout(
                    SVNURL.parseURIEncoded("https://svn.apache.org/repos/asf/tomee/site/trunk/content/"),
                    copy, SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.INFINITY, true));
        }

        // synchronize the generated site and the copy
        final File[] site = new File("target").listFiles(pathname -> pathname.getName().startsWith("site-") && pathname.isDirectory());
        if (site == null || site.length != 1) {
            throw new IllegalArgumentException("Can't find the site: " + asList(site));
        }
        FileUtils.copyDirectory(site[0], copy);

        final Path sitePath = copy.getAbsoluteFile().toPath();

        final SVNStatusClient statusClient = client.getStatusClient();

        Files.walk(sitePath)
                .map(Path::toFile)
                .filter(file -> !file.getAbsolutePath().endsWith(".svn"))
                .filter(file -> !file.getAbsolutePath().contains(".svn/"))
                .forEach(file -> {
                    try {
                        final SVNStatus status = statusClient.doStatus(file, false);
                        final SVNStatusType contentsStatus = status.getContentsStatus();
                        final String path = sitePath.relativize(file.getAbsoluteFile().toPath()).toString();

                        if (contentsStatus == SVNStatusType.STATUS_NORMAL) return;

                        if (contentsStatus == SVNStatusType.STATUS_MODIFIED) {
                            System.out.println("M " + path);
                            return;
                        }

                        if (contentsStatus == SVNStatusType.STATUS_UNVERSIONED || contentsStatus == SVNStatusType.STATUS_NONE) {

                            client.getWCClient().doAdd(file, false, false, false, SVNDepth.INFINITY, false, false, true);
                            System.out.println("A " + path);

                        } else if (contentsStatus == SVNStatusType.STATUS_MODIFIED || contentsStatus == SVNStatusType.STATUS_REPLACED) {

                            System.out.println("M " + path);

                        }
                    } catch (SVNException e) {
                        throw new IllegalStateException(e);
                    }
                });


        // now update it remotely, note: we could use the status output to do it more efficiently
        final String message = ofNullable(args == null || args.length < 2 ? System.getProperty("site.message") : args[1])
                .filter(m -> !"notset".equalsIgnoreCase(m))
                .orElseGet(() -> "Maven update of the website on the " + new Date() + " from " + username);

        final File[] commit = new File[]{copy};

        System.out.println("Committing... ");

        final boolean keepLocks = false;
        final SVNProperties revisionProperties = null;
        final String[] changelists = null;
        final boolean keepChangelist = false;
        final boolean force = false;
        final SVNDepth depth = SVNDepth.INFINITY;
        final SVNCommitInfo commitInfo = client.getCommitClient().doCommit(commit, keepLocks, message, revisionProperties, changelists, keepChangelist, force, depth);

        if (commitInfo.getErrorMessage() != null) {
            throw new IllegalStateException(commitInfo.getErrorMessage().toString());
        }

        System.out.println(commitInfo.toString());

        // do we want to POST https://cms.apache.org/tomee/publish?diff=1 \
        // message=&submit=Submit&key=commitInfo.getNewRevision()&source_url=https%3A%2F%2Fsvn.apache.org%2Frepos%2Fasf%2Ftomee%2Fsite&referer=
        //
        // to automatically publish on prod?
    }