Home | History | Annotate | Download | only in repository
      1 /*
      2  * Copyright (C) 2011 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.sdklib.internal.repository;
     18 
     19 import com.android.sdklib.ISdkLog;
     20 import com.android.sdklib.NullSdkLog;
     21 
     22 
     23 /**
     24  * A no-op implementation of the {@link ITaskMonitor} interface.
     25  * <p/>
     26  * This can be passed to methods that require a monitor when the caller doesn't
     27  * have any UI to update or means to report tracked progress.
     28  * A custom {@link ISdkLog} is used. Clients could use {@link NullSdkLog} if
     29  * they really don't care about the logging either.
     30  */
     31 public class NullTaskMonitor implements ITaskMonitor {
     32 
     33     private final ISdkLog mLog;
     34 
     35     /**
     36      * Creates a no-op {@link ITaskMonitor} that defers logging to the specified
     37      * logger.
     38      * <p/>
     39      * This can be passed to methods that require a monitor when the caller doesn't
     40      * have any UI to update or means to report tracked progress.
     41      *
     42      * @param log An {@link ISdkLog}. Must not be null. Consider using {@link NullSdkLog}.
     43      */
     44     public NullTaskMonitor(ISdkLog log) {
     45         mLog = log;
     46     }
     47 
     48     @Override
     49     public void setDescription(String format, Object...args) {
     50         // pass
     51     }
     52 
     53     @Override
     54     public void log(String format, Object...args) {
     55         mLog.printf(format, args);
     56     }
     57 
     58     @Override
     59     public void logError(String format, Object...args) {
     60         mLog.error(null /*throwable*/, format, args);
     61     }
     62 
     63     @Override
     64     public void logVerbose(String format, Object...args) {
     65         mLog.printf(format, args);
     66     }
     67 
     68     @Override
     69     public void setProgressMax(int max) {
     70         // pass
     71     }
     72 
     73     @Override
     74     public int getProgressMax() {
     75         return 0;
     76     }
     77 
     78     @Override
     79     public void incProgress(int delta) {
     80         // pass
     81     }
     82 
     83     /** Always return 1. */
     84     @Override
     85     public int getProgress() {
     86         return 1;
     87     }
     88 
     89     /** Always return false. */
     90     @Override
     91     public boolean isCancelRequested() {
     92         return false;
     93     }
     94 
     95     @Override
     96     public ITaskMonitor createSubMonitor(int tickCount) {
     97         return this;
     98     }
     99 
    100     /** Always return false. */
    101     @Override
    102     public boolean displayPrompt(final String title, final String message) {
    103         return false;
    104     }
    105 
    106     /** Always return null. */
    107     @Override
    108     public UserCredentials displayLoginCredentialsPrompt(String title, String message) {
    109         return null;
    110     }
    111 
    112     // --- ISdkLog ---
    113 
    114     @Override
    115     public void error(Throwable t, String errorFormat, Object... args) {
    116         mLog.error(t, errorFormat, args);
    117     }
    118 
    119     @Override
    120     public void warning(String warningFormat, Object... args) {
    121         mLog.warning(warningFormat, args);
    122     }
    123 
    124     @Override
    125     public void printf(String msgFormat, Object... args) {
    126         mLog.printf(msgFormat, args);
    127     }
    128 
    129 }
    130