001package Torello.Java.Build;
002
003import Torello.Java.GSUTIL;
004import Torello.Java.Shell;
005import Torello.Java.OSResponse;
006
007import Torello.Java.UnreachableError;
008
009import Torello.JDUInternal.ParseJavaSource.JavaSourceCodeFile;
010
011import java.io.IOException;
012import java.io.File;
013
014/**
015 * This is the seventh Build-Stage, and it is part of the synchronization of a project with Google
016 * Cloud Platform Stroage Buckets.  This class relies heavily on the GCP Shell-Command
017 * {@code 'gsutil'} and it's Java implementation - {@link GSUTIL Torello.Java.GSUTIL}.
018 * 
019 * <BR /><BR />This class' synchronization-efforts entail copying the local / File-System 
020 * Log-Files onto the (User-Specified) Google Cloud Server Storage-Bucket.
021 * 
022 * <EMBED CLASS='external-html' DATA-FILE-ID=S07_SYNC_LOGS>
023 */
024@Torello.JavaDoc.StaticFunctional
025public class S07_SyncLogs
026{
027    // Completely irrelevant, and the 'private' modifier keeps it off of JavaDoc
028    private S07_SyncLogs() { }
029
030
031    // ********************************************************************************************
032    // ********************************************************************************************
033    // Copies The Log Files to GCS
034    // ********************************************************************************************
035    // ********************************************************************************************
036
037
038    public static void sync(Builder builder) throws IOException
039    {
040        builder.timers.startStage07();
041        Printing.startStep(7);
042
043        final String CLOUD_LOG_DIR = builder.cli.GCS_DIR + "logs/";
044
045        // Uses Shell-Contructor:
046        // (outputAppendable, commandStrAppendable, standardOutput, errorOutput)
047
048        // GSUTIL gsutil = new GSUTIL(System.out, System.out, null, null);
049        builder.cloudSync.initStage07();
050
051        // OSResponse osr = gsutil.CP(builder.logs.LOG_DIR + '*', GCS_LOG_DIR);
052        OSResponse osr = builder.cloudSync.copyLogDirToCloud(CLOUD_LOG_DIR);
053        Util.HALT_ON_ERROR(osr);
054        System.out.println();
055
056        // osr = gsutil.CONTENT_TYPE(GCS_LOG_DIR + "*.html", GSUTIL.SCT_HTML_UTF8);
057        osr = builder.cloudSync.setCloudLogsContentType(CLOUD_LOG_DIR);
058        Util.HALT_ON_ERROR(osr);
059        System.out.println();
060
061        // JavaHTML.torello.directory has bucket-level public access
062        if (builder.RUN_MAKE_PUBLIC)
063        {
064            // osr = gsutil.MP(CLOUD_LOG_DIR + "*");
065            osr = builder.cloudSync.makeLogsPublic(CLOUD_LOG_DIR);
066            Util.HALT_ON_ERROR(osr);
067            System.out.println();
068        }
069
070        builder.cloudSync.endStage07();
071        builder.timers.endStage07();
072    }
073
074
075    // ********************************************************************************************
076    // ********************************************************************************************
077    // NEW FEATURE: Copy the "TestAll Log"
078    // ********************************************************************************************
079    // ********************************************************************************************
080
081
082    static void copyDebuggerLogs(Builder builder, byte LOG_KIND)
083        throws IOException
084    {
085        builder.timers.startStage07();
086
087        // Uses Shell-Contructor:
088        // (outputAppendable, commandStrAppendable, standardOutput, errorOutput)
089
090        final GSUTIL    gsutil  = new GSUTIL(System.out, System.out, null, null);
091        final Shell     shell   = new Shell(System.out, System.out, null, null);
092
093        OSResponse osr = null;
094
095        if (new File(Torello.Test.TestAll.TEST_ALL_OUTPUT_FILENAME).exists())
096        {
097            osr = shell.MV(Torello.Test.TestAll.TEST_ALL_OUTPUT_FILENAME, builder.logs.LOG_DIR);
098            Util.HALT_ON_ERROR(osr);
099            System.out.println();
100        }
101
102        final String fName      = builder.logs.LOG_DIR + Torello.Test.TestAll.TEST_ALL_OUTPUT_FILENAME;
103        final String gcsName    = builder.cli.GCS_DIR + "logs/" + fName;
104
105        osr = gsutil.CP(fName, gcsName);
106        Util.HALT_ON_ERROR(osr);
107        System.out.println();
108
109        osr = gsutil.CONTENT_TYPE(gcsName, GSUTIL.SCT_HTML_UTF8);
110        Util.HALT_ON_ERROR(osr);
111        System.out.println();
112
113        if (! builder.RUN_MAKE_PUBLIC)
114        {
115            osr = gsutil.MP(gcsName);
116            Util.HALT_ON_ERROR(osr);
117            System.out.println();
118        }
119
120        // For old time's sake, this is how it has always been done.  Why change it now?
121        if (! builder.cli.toReleaseOrDeveloper)
122        {
123            osr = gsutil.SMA(gcsName, 100);
124            Util.HALT_ON_ERROR(osr);
125            System.out.println();
126        }
127
128        System.out.println("View Log File:\n\nhttp://" + gcsName.substring(5) + "\n");
129
130        builder.timers.endStage07();
131    }
132}