1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.tools.build.apkzlib.zip;
18 
19 import com.google.common.collect.ImmutableList;
20 import javax.annotation.Nonnull;
21 
22 /**
23  * The verify log contains verification messages. It is used to capture validation issues with a
24  * zip file or with parts of a zip file.
25  */
26 public interface VerifyLog {
27 
28     /**
29      * Logs a message.
30      *
31      * @param message the message to verify
32      */
log(@onnull String message)33     void log(@Nonnull String message);
34 
35     /**
36      * Obtains all save logged messages.
37      *
38      * @return the logged messages
39      */
40     @Nonnull
getLogs()41     ImmutableList<String> getLogs();
42 
43     /**
44      * Performs verification of a non-critical condition, logging a message if the condition is
45      * not verified.
46      *
47      * @param condition the condition
48      * @param message the message to write if {@code condition} is {@code false}.
49      * @param args arguments for formatting {@code message} using {@code String.format}
50      */
verify(boolean condition, @Nonnull String message, @Nonnull Object... args)51     default void verify(boolean condition, @Nonnull String message, @Nonnull Object... args) {
52         if (!condition) {
53             log(String.format(message, args));
54         }
55     }
56 }
57