001package Torello.Java.Build;
002
003import Torello.Java.FileRW;
004import Torello.Java.StorageWriter;
005import Torello.Java.StringParse;
006import Torello.Java.GSUTIL;
007import Torello.Java.OSResponse;
008
009import java.io.IOException;
010
011/**
012 * This is the sixth Build-Stage, and it is part of the synchronization of a project with Google
013 * Cloud Platform Stroage Buckets.  This class relies heavily on the GCP Shell-Command
014 * {@code 'gsutil'} and it's Java implementation - {@link GSUTIL Torello.Java.GSUTIL}.
015 * 
016 * <BR /><BR />This class' synchronization-efforts entail copying the local / File-System 
017 * {@code '.tar'} and {@code '.jar'} files onto the (User-Specified) Google Cloud Server
018 * Storage-Bucket.
019 * 
020 * <EMBED CLASS=external-html DATA-FILE-ID=STAGE_PRIVATE_NOTE>
021 * <EMBED CLASS='external-html' DATA-FILE-ID=S06_SYNC_TAR_JAR>
022 */
023@Torello.JavaDoc.StaticFunctional
024public class S06_SyncTarJar
025{
026    // Completely irrelevant, and the 'private' modifier keeps it off of JavaDoc
027    private S06_SyncTarJar() { }
028
029    public static void sync(final BuilderRecord brec) throws IOException
030    {
031        brec.timers.startStage06();
032        Printing.startStep(6);
033
034        /*
035        final String CODE_DRIVE_BACKUP_FILE = (brec.BACKUP_TAR_FILE_GCS_DIR == null)
036
037            ? null 
038            :   brec.BACKUP_TAR_FILE_GCS_DIR +
039                StringParse.ymDateStr('/', true) + '/' +
040                StringParse.dateStr('-') + '-' + brec.TAR_FILE;
041        */
042
043        // final String CLOUD_JAR_DIR = brec.cli.GCS_DIR + "jar/";
044
045        // true ==> send to System.out
046        StorageWriter sw = new StorageWriter(true);
047
048
049        // Uses Shell-Contructor:
050        // (outputAppendable, commandStrAppendable, standardOutput, errorOutput)
051        //
052        // GSUTIL gsutil = new GSUTIL(sw, sw, null, null);
053
054        brec.cloudSync.initStage(sw, sw);
055
056
057        // These are three of the four ARCHIVE-FILES that have been created.
058        // One of them is 'too-big' for GSUTIL to handle, and must be copied over separately, or
059        // the whole program will freeze and hang for anywhere between 30 seconds and 10 minutes...
060        // 
061        // String[] cpArr = { brec.JAVADOC_TAR_FILE, brec.JAR_FILE };
062        // OSResponse osr = gsutil.CP(cpArr, GCS_JAR_DIR);
063
064        OSResponse osr = brec.cloudSync.copyJDTarAndJarToCloud();
065        Util.HALT_ON_ERROR(osr);
066        sw.println();
067
068        // if (brec.RUN_MAKE_PUBLIC)
069        if (brec.cloudSync.shouldRunMakePublic)
070        {
071            // osr = gsutil.MP
072            //     (GCS_JAR_DIR + brec.JAR_FILE, GCS_JAR_DIR + brec.JAVADOC_TAR_FILE);
073
074            osr = brec.cloudSync.makeJDTarAndJarPublic();
075            Util.HALT_ON_ERROR(osr);
076            sw.println();
077        }
078
079
080        // Drive backup page
081        // if (CODE_DRIVE_BACKUP_FILE != null)
082
083        if (brec.cloudSync.shouldSyncMainTarGzFile)
084        {
085            // osr = gsutil.CP(brec.TAR_FILE, CODE_DRIVE_BACKUP_FILE);
086            osr = brec.cloudSync.backupMainTarGzFile();
087            Util.HALT_ON_ERROR(osr);
088            sw.println();
089        }
090
091        // Move Archive files to the local BASH/UNIX - ~/jar/ directory.
092        if (brec.JAR_FILE_NAME != null)
093        {
094            sw.println(
095                "Moving File [" + brec.JAR_FILE + "] to " +
096                "[" + brec.JAR_FILE_NAME + "]\n"
097            );
098
099            FileRW.moveFile(brec.JAR_FILE, brec.JAR_FILE_NAME, false);
100            sw.println();
101        }
102
103
104        // Get rid of these files.  These were saved into the local 'jar/' directory, now,
105        // just get rid of them.  they are never used.
106
107        sw.println(
108            "Deleting File [" + brec.TAR_FILE  + "]\n" +
109            "Deleting File [" + brec.JAVADOC_TAR_FILE  + "]\n"
110        );
111
112        FileRW.deleteFiles(brec.TAR_FILE, brec.JAVADOC_TAR_FILE);
113        sw.println();
114
115        brec.logs.write_S06_LOG(sw.getString());
116        brec.cloudSync.endStage();
117        brec.timers.endStage06();
118    }
119}