001package Torello.Java.Build;
002
003import Torello.Java.GSUTIL;
004import Torello.Java.OSResponse;
005
006import Torello.Java.Additional.AppendableSafe;
007import Torello.Java.Additional.BiAppendable;
008
009import static Torello.Java.C.*;
010
011import java.io.IOException;
012import java.io.File;
013
014/**
015 * This is the last 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 involve setting a simple Browser
020 * {@code 'CACHE-CONTROL'} configuration for all Java-Documentation Files on the relevant Google
021 * Cloud Server Storage-Bucket.  The setting prevents browsers from caching Java-Doc Web-Pages so
022 * that development efforts where classes and their members are changing frequently won't be cached
023 * by the browser (and, therefore, won't impede developer-progress)!
024 * 
025 * <EMBED CLASS='external-html' DATA-FILE-ID=S08_SET_MAX_AGE>
026 */
027@Torello.JavaDoc.StaticFunctional
028public class S08_SetMaxAge
029{
030    // Completely irrelevant, and the 'private' modifier keeps it off of JavaDoc
031    private S08_SetMaxAge() { }
032
033    public static void set(Builder builder) throws IOException
034    {
035        builder.timers.startStage08();
036        Printing.startStep(8);
037
038        StringBuilder logOnly = new StringBuilder();
039
040        final AppendableSafe logAndScreen = new AppendableSafe(
041            new BiAppendable(System.out, logOnly),
042            AppendableSafe.USE_APPENDABLE_ERROR
043        );
044
045        // Uses Shell-Contructor:
046        // (outputAppendable, commandStrAppendable, standardOutput, errorOutput)
047
048        // GSUTIL gsutil = new GSUTIL(logOnly, logAndScreen, null, null);
049        builder.cloudSync.initStage08(logOnly, logAndScreen);
050
051        OSResponse osr = null;
052
053        if (builder.stage8GCSDirs == null)
054            // osr = gsutil.SMA(builder.cli.GCS_DIR + "**", 120);
055            osr = builder.cloudSync.setMaxAgeAll();
056
057        else
058        {
059            logAndScreen.append(BGREEN + "Set Max Age (Browser-Cache):\n\n" + RESET);
060            for (String gcsDir : builder.stage8GCSDirs) logAndScreen.append('\t' + gcsDir + "\n");
061            logAndScreen.append('\n');
062
063            // osr = gsutil.SMA(builder.stage8GCSDirs, 120);
064            osr = builder.cloudSync.setMaxAgeSome();
065        }
066
067        Util.HALT_ON_ERROR(osr);
068
069        builder.logs.write_S08_LOG(logOnly.toString());
070        builder.cloudSync.endStage08();
071        builder.timers.endStage08();
072    }
073}