// Path: buildSrc/src/main/java/org/jazzcommunity/development/library/RuntimeDetector.java
// public final class RuntimeDetector {
//   private RuntimeDetector() {}
// 
//   public static String getTargetPlatform(Project project) {
//     String initializedVersion = FileTools.newestVersion("jde/dev/initialize");
//     if (initializedVersion != null) {
//       String path = String.format("jde/dev/initialize/%s/sdk", initializedVersion);
//       return FileTools.toAbsolute(path).getAbsolutePath();
//     }
// 
//     // fall back to default runtime
//     String newestSdk = String.format("jde/runtime/%s/sdk", get(project).get());
//     return FileTools.toAbsolute(newestSdk).getPath();
//   }
// 
//   public static Optional<String> get(Project project) {
//     String runtime =
//         !project.hasProperty("runtime")
//             ? FileTools.newestVersion("jde/runtime")
//             : (String) project.getProperties().get("runtime");
// 
//     if (runtime == null) {
//       return Optional.empty();
//     }
// 
//     return Optional.of(runtime);
//   }
// 
//   public static Stream<Runtime> getRuntimes() {
//     return Arrays.stream(FileTools.getFiles("jde/runtime")).map(Runtime::new);
//   }
// 
//   public static Runtime getRuntime(String version) {
//     return getRuntimes()
//         .filter(r -> r.getVersion().equals(version))
//         .findFirst()
//         .orElseThrow(
//             () -> new RuntimeException(String.format("Invalid run time setup for %s", version)));
//   }
// }
// 
// Path: buildSrc/src/main/java/org/jazzcommunity/development/library/config/ConfigWriter.java
// public final class ConfigWriter {
//   private static final Logger logger = LoggerFactory.getLogger("ConfigWriter");
// 
//   private ConfigWriter() {}
// 
//   public static void prepareConfigurations(String runtime) {
//     String folder = runtime.isEmpty() ? FileTools.newestVersion("jde/runtime") : runtime;
//     System.out.println("Generate run time configurations.");
//     System.out.println(String.format("Preparing %s run time", folder));
// 
//     try {
//       System.out.println("Writing config.ini");
//       writeIni(folder);
//       System.out.println("Writing dev.properties");
//       writeProperties(folder);
//       System.out.println("Copying log4j configuration");
//       copyLogConfig(folder);
//       System.out.println("Creating executable files");
//       writeExecutables(folder);
//     } catch (IOException e) {
//       logger.error("Runtime configuration failed: {}", e.getMessage());
//     }
//   }
// 
//   private static void copyLogConfig(String folder) {
//     String destination = String.format("jde/runtime/%s/conf/", folder);
//     FileTools.copyFile("jde/user/log4j/log4j.properties", destination);
//   }
// 
//   private static void writeExecutables(String folder) throws IOException {
//     String to = String.format("jde/runtime/%s/", folder);
//     Runtime runtime = RuntimeDetector.getRuntime(folder);
//     String executable = ConfigReader.javaPath();
//     makeScript("tool/scripts/run_jetty_bash.twig", to + "run_jetty.sh", executable, runtime);
//     makeScript("tool/scripts/run_jetty_powershell.twig", to + "run_jetty.ps1", executable, runtime);
//     FileTools.setExecutable(String.format("jde/runtime/%s/run_jetty.sh", folder));
//   }
// 
//   private static void makeScript(
//       String source, String destination, String executable, Runtime runtime) throws IOException {
//     CharSink out = Files.asCharSink(FileTools.toAbsolute(destination), StandardCharsets.UTF_8);
//     List<String> parameters = ConfigReader.runtimeParameters();
//     JtwigTemplate template = JtwigTemplate.fileTemplate(FileTools.toAbsolute(source));
//     JtwigModel model =
//         JtwigModel.newModel()
//             .with("executable", executable)
//             .with("launcher", runtime.getLauncherPath())
//             .with("parameters", parameters);
//     out.write(template.render(model));
//   }
// 
//   private static void writeProperties(String folder) throws IOException {
//     CharSink file =
//         Files.asCharSink(
//             FileTools.toAbsolute(String.format("jde/runtime/%s/conf/dev.properties", folder)),
//             StandardCharsets.UTF_8);
// 
//     List<String> properties =
//         ConfigReader.userConfiguration()
//             .filter(IniEntry::needsPropertyEntry)
//             .map(IniEntry::getPropertiesLine)
//             .collect(Collectors.toList());
// 
//     JtwigTemplate template =
//         JtwigTemplate.fileTemplate(FileTools.toAbsolute("tool/templates/dev.twig"));
//     JtwigModel model = JtwigModel.newModel().with("properties", properties);
//     file.write(template.render(model));
//   }
// 
//   private static void writeIni(String folder) throws IOException {
//     CharSink ini =
//         Files.asCharSink(
//             FileTools.toAbsolute(String.format("jde/runtime/%s/conf/config.ini", folder)),
//             StandardCharsets.UTF_8);
// 
//     JtwigTemplate template =
//         JtwigTemplate.fileTemplate(FileTools.toAbsolute("tool/templates/config.twig"));
// 
//     Runtime runtime = RuntimeDetector.getRuntime(folder);
// 
//     JtwigModel model =
//         JtwigModel.newModel()
//             .with("osgiPath", runtime.getOsgi())
//             .with("configurator", runtime.getConfigurator())
//             .with("bundles", ConfigReader.sdkFiles(folder).collect(Collectors.toList()))
//             .with(
//                 "configs",
//                 ConfigReader.userConfiguration()
//                     .map(IniEntry::getIniLine)
//                     .collect(Collectors.toList()));
//     ini.write(template.render(model));
//   }
// }


import org.gradle.api.tasks.Exec;
import org.jazzcommunity.development.library.RuntimeDetector;
import org.jazzcommunity.development.library.config.ConfigWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package org.jazzcommunity.development;


public class RunTask extends Exec {
  private final Logger logger = LoggerFactory.getLogger(this.getClass());

  @Override
  protected void exec() {
// Path: buildSrc/src/main/java/org/jazzcommunity/development/library/RuntimeDetector.java
// public final class RuntimeDetector {
//   private RuntimeDetector() {}
// 
//   public static String getTargetPlatform(Project project) {
//     String initializedVersion = FileTools.newestVersion("jde/dev/initialize");
//     if (initializedVersion != null) {
//       String path = String.format("jde/dev/initialize/%s/sdk", initializedVersion);
//       return FileTools.toAbsolute(path).getAbsolutePath();
//     }
// 
//     // fall back to default runtime
//     String newestSdk = String.format("jde/runtime/%s/sdk", get(project).get());
//     return FileTools.toAbsolute(newestSdk).getPath();
//   }
// 
//   public static Optional<String> get(Project project) {
//     String runtime =
//         !project.hasProperty("runtime")
//             ? FileTools.newestVersion("jde/runtime")
//             : (String) project.getProperties().get("runtime");
// 
//     if (runtime == null) {
//       return Optional.empty();
//     }
// 
//     return Optional.of(runtime);
//   }
// 
//   public static Stream<Runtime> getRuntimes() {
//     return Arrays.stream(FileTools.getFiles("jde/runtime")).map(Runtime::new);
//   }
// 
//   public static Runtime getRuntime(String version) {
//     return getRuntimes()
//         .filter(r -> r.getVersion().equals(version))
//         .findFirst()
//         .orElseThrow(
//             () -> new RuntimeException(String.format("Invalid run time setup for %s", version)));
//   }
// }
// 
// Path: buildSrc/src/main/java/org/jazzcommunity/development/library/config/ConfigWriter.java
// public final class ConfigWriter {
//   private static final Logger logger = LoggerFactory.getLogger("ConfigWriter");
// 
//   private ConfigWriter() {}
// 
//   public static void prepareConfigurations(String runtime) {
//     String folder = runtime.isEmpty() ? FileTools.newestVersion("jde/runtime") : runtime;
//     System.out.println("Generate run time configurations.");
//     System.out.println(String.format("Preparing %s run time", folder));
// 
//     try {
//       System.out.println("Writing config.ini");
//       writeIni(folder);
//       System.out.println("Writing dev.properties");
//       writeProperties(folder);
//       System.out.println("Copying log4j configuration");
//       copyLogConfig(folder);
//       System.out.println("Creating executable files");
//       writeExecutables(folder);
//     } catch (IOException e) {
//       logger.error("Runtime configuration failed: {}", e.getMessage());
//     }
//   }
// 
//   private static void copyLogConfig(String folder) {
//     String destination = String.format("jde/runtime/%s/conf/", folder);
//     FileTools.copyFile("jde/user/log4j/log4j.properties", destination);
//   }
// 
//   private static void writeExecutables(String folder) throws IOException {
//     String to = String.format("jde/runtime/%s/", folder);
//     Runtime runtime = RuntimeDetector.getRuntime(folder);
//     String executable = ConfigReader.javaPath();
//     makeScript("tool/scripts/run_jetty_bash.twig", to + "run_jetty.sh", executable, runtime);
//     makeScript("tool/scripts/run_jetty_powershell.twig", to + "run_jetty.ps1", executable, runtime);
//     FileTools.setExecutable(String.format("jde/runtime/%s/run_jetty.sh", folder));
//   }
// 
//   private static void makeScript(
//       String source, String destination, String executable, Runtime runtime) throws IOException {
//     CharSink out = Files.asCharSink(FileTools.toAbsolute(destination), StandardCharsets.UTF_8);
//     List<String> parameters = ConfigReader.runtimeParameters();
//     JtwigTemplate template = JtwigTemplate.fileTemplate(FileTools.toAbsolute(source));
//     JtwigModel model =
//         JtwigModel.newModel()
//             .with("executable", executable)
//             .with("launcher", runtime.getLauncherPath())
//             .with("parameters", parameters);
//     out.write(template.render(model));
//   }
// 
//   private static void writeProperties(String folder) throws IOException {
//     CharSink file =
//         Files.asCharSink(
//             FileTools.toAbsolute(String.format("jde/runtime/%s/conf/dev.properties", folder)),
//             StandardCharsets.UTF_8);
// 
//     List<String> properties =
//         ConfigReader.userConfiguration()
//             .filter(IniEntry::needsPropertyEntry)
//             .map(IniEntry::getPropertiesLine)
//             .collect(Collectors.toList());
// 
//     JtwigTemplate template =
//         JtwigTemplate.fileTemplate(FileTools.toAbsolute("tool/templates/dev.twig"));
//     JtwigModel model = JtwigModel.newModel().with("properties", properties);
//     file.write(template.render(model));
//   }
// 
//   private static void writeIni(String folder) throws IOException {
//     CharSink ini =
//         Files.asCharSink(
//             FileTools.toAbsolute(String.format("jde/runtime/%s/conf/config.ini", folder)),
//             StandardCharsets.UTF_8);
// 
//     JtwigTemplate template =
//         JtwigTemplate.fileTemplate(FileTools.toAbsolute("tool/templates/config.twig"));
// 
//     Runtime runtime = RuntimeDetector.getRuntime(folder);
// 
//     JtwigModel model =
//         JtwigModel.newModel()
//             .with("osgiPath", runtime.getOsgi())
//             .with("configurator", runtime.getConfigurator())
//             .with("bundles", ConfigReader.sdkFiles(folder).collect(Collectors.toList()))
//             .with(
//                 "configs",
//                 ConfigReader.userConfiguration()
//                     .map(IniEntry::getIniLine)
//                     .collect(Collectors.toList()));
//     ini.write(template.render(model));
//   }
// }


// Path: buildSrc/src/main/java/org/jazzcommunity/development/RunTask.java
import org.gradle.api.tasks.Exec;
import org.jazzcommunity.development.library.RuntimeDetector;
import org.jazzcommunity.development.library.config.ConfigWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

package org.jazzcommunity.development;


public class RunTask extends Exec {
  private final Logger logger = LoggerFactory.getLogger(this.getClass());

  @Override
  protected void exec() {
    RuntimeDetector.get(getProject()).ifPresent(ConfigWriter::prepareConfigurations);