Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 1 | // Copyright 2014 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | package com.google.devtools.build.lib.runtime; |
| 15 | |
| 16 | import com.google.devtools.build.lib.util.AbruptExitException; |
| 17 | import com.google.devtools.build.lib.util.ExitCode; |
| 18 | import com.google.devtools.common.options.OptionsParser; |
| 19 | import com.google.devtools.common.options.OptionsProvider; |
| 20 | |
| 21 | /** |
| 22 | * Interface implemented by Blaze commands. In addition to implementing this interface, each |
| 23 | * command must be annotated with a {@link Command} annotation. |
| 24 | */ |
| 25 | public interface BlazeCommand { |
| 26 | /** |
| 27 | * This method provides the imperative portion of the command. It takes |
| 28 | * a {@link OptionsProvider} instance {@code options}, which provides access |
| 29 | * to the options instances via {@link OptionsProvider#getOptions(Class)}, |
| 30 | * and access to the residue (the remainder of the command line) via |
| 31 | * {@link OptionsProvider#getResidue()}. The framework parses and makes |
| 32 | * available exactly the options that the command class specifies via the |
| 33 | * annotation {@link Command#options()}. The command may write to standard |
| 34 | * out and standard error via {@code outErr}. It indicates success / failure |
| 35 | * via its return value, which becomes the Unix exit status of the Blaze |
| 36 | * client process. It may indicate a shutdown request by throwing |
| 37 | * {@link BlazeCommandDispatcher.ShutdownBlazeServerException}. In that case, |
| 38 | * the Blaze server process (the memory resident portion of Blaze) will |
| 39 | * shut down and the exit status will be 0 (in case the shutdown succeeds |
| 40 | * without error). |
| 41 | * |
Ulf Adams | 633f539 | 2015-09-15 11:13:08 +0000 | [diff] [blame] | 42 | * @param env The environment for the current command invocation |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 43 | * @param options A parsed options instance initialized with the values for |
| 44 | * the options specified in {@link Command#options()}. |
| 45 | * |
| 46 | * @return The Unix exit status for the Blaze client. |
| 47 | * @throws BlazeCommandDispatcher.ShutdownBlazeServerException Indicates |
| 48 | * that the command wants to shutdown the Blaze server. |
| 49 | */ |
Ulf Adams | 633f539 | 2015-09-15 11:13:08 +0000 | [diff] [blame] | 50 | ExitCode exec(CommandEnvironment env, OptionsProvider options) |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 51 | throws BlazeCommandDispatcher.ShutdownBlazeServerException; |
| 52 | |
| 53 | /** |
| 54 | * Allows the command to provide command-specific option defaults and/or |
| 55 | * requirements. This method is called after all command-line and rc file options have been |
| 56 | * parsed. |
| 57 | * |
Ulf Adams | 633f539 | 2015-09-15 11:13:08 +0000 | [diff] [blame] | 58 | * @param env the command environment of the currently running command |
| 59 | * @param optionsParser the options parser for the current command |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 60 | * |
| 61 | * @throws AbruptExitException if something went wrong |
| 62 | */ |
Ulf Adams | 633f539 | 2015-09-15 11:13:08 +0000 | [diff] [blame] | 63 | void editOptions(CommandEnvironment env, OptionsParser optionsParser) throws AbruptExitException; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 64 | } |