/*
 * Bach - Java Shell Builder
 * Copyright (C) 2020 Christian Stein
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package de.sormuras.bach;

import de.sormuras.bach.util.Functions;
import de.sormuras.bach.util.Logbook;
import java.io.PrintWriter;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.lang.module.ModuleDescriptor.Version;
import java.net.http.HttpClient;
import java.util.function.Supplier;
import java.util.spi.ToolProvider;

/** Bach - Java Shell Builder. */
public class Bach {

  /** Version of the Java Shell Builder. */
  public static final Version VERSION = Version.parse("11.0-ea");

  /** Main entry-point. */
  public static void main(String... args) {
    Main.main(args);
  }

  /** Logbook instance. */
  private final Logbook logbook;

  /** HttpClient supplier. */
  private final Supplier<HttpClient> httpClient;

  /** Initialize this instance with default values. */
  public Bach() {
    this(HttpClient.newBuilder()::build);
  }

  /** Initialize this instance with the specified line printer, workspace, and other values. */
  public Bach(Supplier<HttpClient> httpClient) {
    this.logbook = new Logbook();
    this.httpClient = Functions.memoize(httpClient);
    logbook.log(Level.TRACE, "Initialized " + toString());
  }

  public Logger getLogger() {
    return logbook;
  }

  public HttpClient getHttpClient() {
    return httpClient.get();
  }

  @Override
  public String toString() {
    return "Bach.java " + VERSION;
  }
}

@@ -1932,16 +1932,1022 @@
 );%0A  %7D%0A%0A
+  void execute(Task task) %7B%0A    var label = task.getLabel();%0A    var tasks = task.getList();%0A    if (tasks.isEmpty()) %7B%0A      logbook.log(Level.TRACE, %22* %7B0%7D%22, label);%0A      try %7B%0A        task.execute(this);%0A      %7D catch (Throwable throwable) %7B%0A        var message = %22Task execution failed%22;%0A        logbook.log(Level.ERROR, message, throwable);%0A        throw new Error(message, throwable);%0A      %7D%0A      return;%0A    %7D%0A    logbook.log(Level.TRACE, %22+ %7B0%7D%22, label);%0A    var start = System.currentTimeMillis();%0A    for (var sub : tasks) execute(sub);%0A    var duration = System.currentTimeMillis() - start;%0A    logbook.log(Level.TRACE, %22= %7B0%7D took %7B1%7D ms%22, label, duration);%0A  %7D%0A%0A  void execute(ToolProvider tool, PrintWriter out, PrintWriter err, String... args) %7B%0A    var call = (tool.name() + ' ' + String.join(%22 %22, args)).trim();%0A    logbook.log(Level.DEBUG, call);%0A    var code = tool.run(out, err, args);%0A    if (code != 0) throw new AssertionError(%22Tool run exit code: %22 + code + %22%5Cn%5Ct%22 + call);%0A  %7D%0A%0A
   @Overr

Add execution support for tasks and tools