View Javadoc
1   /*
2    * Copyright (C) 2014 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  package com.simpligility.maven.plugins.android;
17  
18  import com.android.ide.common.process.ProcessException;
19  import com.android.ide.common.process.ProcessResult;
20  
21  /**
22   * Internal implementation of ProcessResult used by DefaultProcessExecutor.
23   */
24  class ProcessResultImplCopy implements ProcessResult
25  {
26      private final String mCommand;
27      private final int mExitValue;
28      private final Exception mFailure;
29      ProcessResultImplCopy( String command, int exitValue )
30      {
31          this( command, exitValue, null );
32      }
33      ProcessResultImplCopy( String command, Exception failure )
34      {
35          this( command, -1, failure );
36      }
37      ProcessResultImplCopy( String command, int exitValue, Exception failure )
38      {
39          mCommand = command;
40          mExitValue = exitValue;
41          mFailure = failure;
42      }
43      @Override
44      public ProcessResult assertNormalExitValue() throws ProcessException
45      {
46          if ( mExitValue != 0 )
47          {
48              throw new ProcessException(
49                      String.format( "Return code %d for process '%s'", mExitValue, mCommand ) );
50          }
51          return this;
52      }
53      @Override
54      public int getExitValue()
55      {
56          return mExitValue;
57      }
58      @Override
59      public ProcessResult rethrowFailure() throws ProcessException
60      {
61          if ( mFailure != null )
62          {
63              throw new ProcessException( "", mFailure );
64          }
65          return this;
66      }
67  }