@Override @SuppressWarnings("PMD.PrematureDeclaration") int runCommandWithOptionsInternal(BuildCommandOptions options) throws IOException { // Set the logger level based on the verbosity option. Verbosity verbosity = console.getVerbosity(); Logging.setLoggingLevelForVerbosity(verbosity); // Create artifact cache to initialize Cassandra connection, if appropriate. ArtifactCache artifactCache = getArtifactCache(); try { buildTargets = getBuildTargets(options.getArgumentsFormattedAsBuildTargets()); } catch (NoSuchBuildTargetException e) { console.printBuildFailureWithoutStacktrace(e); return 1; } if (buildTargets.isEmpty()) { console.printBuildFailure("Must specify at least one build target."); // If there are aliases defined in .buckconfig, suggest that the user // build one of them. We show the user only the first 10 aliases. ImmutableSet<String> aliases = options.getBuckConfig().getAliases(); if (!aliases.isEmpty()) { console .getStdErr() .println( String.format( "Try building one of the following targets:\n%s", Joiner.on(' ').join(Iterators.limit(aliases.iterator(), 10)))); } return 1; } getBuckEventBus().post(BuildEvent.started(buildTargets)); // Parse the build files to create a DependencyGraph. DependencyGraph dependencyGraph; try { dependencyGraph = getParser() .parseBuildFilesForTargets( buildTargets, options.getDefaultIncludes(), getBuckEventBus()); } catch (BuildTargetException | BuildFileParseException e) { console.printBuildFailureWithoutStacktrace(e); return 1; } // Create and execute the build. build = options.createBuild( options.getBuckConfig(), dependencyGraph, getProjectFilesystem(), getAndroidDirectoryResolver(), artifactCache, console, getBuckEventBus(), Optional.<TargetDevice>absent(), getCommandRunnerParams().getPlatform()); int exitCode = 0; try { exitCode = executeBuildAndPrintAnyFailuresToConsole(build, console); } finally { // Shutdown the Executor Service once the build completes. // Note: we need to use shutdown() instead of shutdownNow() to ensure that tasks submitted to // the Execution Service are completed. build.getStepRunner().getListeningExecutorService().shutdown(); } getBuckEventBus().post(BuildEvent.finished(buildTargets, exitCode)); if (exitCode != 0) { return exitCode; } return 0; }