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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
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;

/**
 * A few minor printing utilities.
 * 
 * <BR />
 * <EMBED CLASS='external-html' DATA-FILE-ID=INTERNAL_CLASS_NOTE>
 */
@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);

    // Used for the dataRecLogSB
    static final String DATA_REC_LOG_LINES =
        BRED + StringParse.nChars('=', LEN) + RESET + '\n' +
        BRED + StringParse.nChars('=', LEN) + RESET + '\n';

    // 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 int ERROR_EXIT_LEN = LEN + 10;

    static final String ERROR_EXIT_LINE =
        BBLUE_BKGND + StringParse.nChars(' ', ERROR_EXIT_LEN) + RESET;

    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(final 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
        );
    }

    /**
     * Used elsewhere.  Must be public until further notice.  This will hopefully one day be
     * relegated to the annals of "Package-Private".
     */
    public static void PLS(final Appendable a, final 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.
     */
    static void printFilesCount(
            final ReadOnlyList<BuildPackage>    packages,
            final ArrayList<Integer>            filesCount,
            final Appendable                    logAndScreen,
            final boolean                       javaOrClass
        )
        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;

        final String fileType = javaOrClass
            ? "'.java' Files: "
            : "'.class' Files: ";

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

            total += count;

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

        logAndScreen.append("\nTotal " + fileType + BRED + total + RESET + "\n\n");
    }
}