1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package Torello.Java.Build;

import static Torello.Java.C.*;

import Torello.Java.StringParse;
import Torello.Java.ReadOnly.ReadOnlyList;

import java.io.IOException;
import java.util.ArrayList;

@Torello.JavaDoc.StaticFunctional
public class Printing
{
    // Completely irrelevant, and the 'private' modifier keeps it off of JavaDoc
    private Printing() { }

    static final int LEN = 80;

    private static final String BLANKS = StringParse.nChars(' ', LEN);

    // startStep(int)
    static final String BEGIN_STAGE_LINE = BRED_BKGND + BLANKS + RESET;

    // Logs
    static final String LOG_LINE = BCYAN_BKGND + BLANKS + RESET;

    // Timers
    static final String TIMER_SUMMARY_LINE = BPURPLE_BKGND + BLANKS + RESET;

    // Util.ERROR_EXIT
    static final String ERROR_EXIT_LINE =
        BBLUE_BKGND + StringParse.nChars(' ', LEN + 40) + RESET;

    public static final String TAR_JAR_DIVIDER =
        "\n\n" +
        StringParse.nChars('*', LEN) + '\n' + 
        StringParse.nChars('*', LEN) + "\n\n";


    // These are printed by Timers.PRINT_STEP_TIME(int, boolean) and by Util.startStep(int)
    static final ReadOnlyList<String> STAGES = ReadOnlyList.of(
    
        /* Stage 00 */ "", // Array[0] ==> Not Used
        /* Stage 01 */ "Run javac",
        /* Stage 02 */ "Run javadoc",
        /* Stage 03 */ "Torello.JavaDoc.Upgrade",
        /* Stage 04 */ "Build TAR & JAR Files",
        /* Stage 05 */ "Sync javadoc/ Files to GCS",
        /* Stage 06 */ "Sync TAR & JAR Files to GCS",
        /* Stage 07 */ "Sync Log Files to GCS",
        /* Stage 08 */ "Set Cache-Control Max-Age"        
    );

    private static final String MESSAGE_BEGINNING =
        '\n' + Printing.BEGIN_STAGE_LINE + "\n" + BRED_BKGND + " " + RESET + " Stage 0";

    private static final String MESSAGE_ENDING =
        BRED_BKGND + " " + RESET + "\n" + Printing.BEGIN_STAGE_LINE + '\n';

    static void startStep(int stageNumber)
    {
        if ((stageNumber < 1) || (stageNumber > 8)) throw new IllegalArgumentException
            ("An Illegal Step Number has been passed to method 'startStep(int)'");

        System.out.println(
            MESSAGE_BEGINNING +

            stageNumber + ": " + Printing.STAGES.get(stageNumber) +

            // "# Stage 0X: ".length() ==> 12
            // NOTE: The extra '-1' is so that the closing '#' is on the line-end, not after it!

            StringParse.nChars
                (' ', Printing.LEN - Printing.STAGES.get(stageNumber).length() - 12 - 1) +

            MESSAGE_ENDING
        );
    }

    public static void PLS(Appendable a, boolean unixColors) throws IOException
    {
        a.append(
            "\n\n" +
            (unixColors ? BCYAN : "") +
            "*********************************************************************************\n" +
            "*********************************************************************************\n" +
            (unixColors ? RESET : "") +
            "\n\n"
        );
    }

    /**
     * Prints out a list of file-counts to the screen and to the log.
     * 
     * @param packages a list of packages (as instances of class {@link BuildPackage}).  This list
     * is a parallel data-set to {@code 'filesCount'}.  Each element of {@code 'packages'}
     * identifies exactly one package within the current build-processes.  In the exact same list
     * location in {@code 'filesCount'} there is an integer that specifies how many relevant files
     * are contained in the package at any particular list index.
     * 
     * @param filesCount A parallel list to {@code 'packages'}, this parameter contains the file
     * count for each package listed.
     * 
     * @see S01_JavaCompiler
     * @see S02_JavaDoc
     */
    public static void printFilesCount(
            ReadOnlyList<BuildPackage>  packages,
            ArrayList<Integer>          filesCount,
            Appendable                  logAndScreen
        )
        throws IOException
    {
        double  log10   = -1;
        double  max     = 0;

        for (Integer c : filesCount)
            if ((log10 = Math.log10(c)) > max)
                max = log10;

        final int spacing = 2 + ((int) max);

        int total = 0;

        for (int i=0; i < packages.size(); i++)
        {
            final int count = filesCount.get(i);

            total += count;

            logAndScreen.append(
                BRED + StringParse.rightSpacePad("" + count, spacing) + RESET +
                    "'.java' Files: " +
                packages.get(i).fullName + '\n'
            );
        }

        logAndScreen.append("\nTotal '.java' Files: " + BRED + total + RESET + "\n\n");
    }
}