• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 java.util.ArrayList;
21 import java.util.List;
22 import javax.annotation.Nonnull;
23 
24 /**
25  * Factory for verification logs.
26  */
27 final class VerifyLogs {
28 
VerifyLogs()29     private VerifyLogs() {}
30 
31     /**
32      * Creates a {@link VerifyLog} that ignores all messages logged.
33      *
34      * @return the log
35      */
36     @Nonnull
devNull()37     static VerifyLog devNull() {
38         return new VerifyLog() {
39             @Override
40             public void log(@Nonnull String message) {}
41 
42             @Nonnull
43             @Override
44             public ImmutableList<String> getLogs() {
45                 return ImmutableList.of();
46             }
47         };
48     }
49 
50     /**
51      * Creates a {@link VerifyLog} that stores all log messages.
52      *
53      * @return the log
54      */
55     @Nonnull
56     static VerifyLog unlimited() {
57         return new VerifyLog() {
58 
59             /**
60              * All saved messages.
61              */
62             @Nonnull
63             private final List<String> messages = new ArrayList<>();
64 
65             @Override
66             public void log(@Nonnull String message) {
67                 messages.add(message);
68             }
69 
70             @Nonnull
71             @Override
72             public ImmutableList<String> getLogs() {
73                 return ImmutableList.copyOf(messages);
74             }
75         };
76     }
77 }
78