// Path: buildSrc/src/main/java/org/jazzcommunity/development/library/DetectOperatingSystem.java
// public class DetectOperatingSystem {
//   public static boolean isWindows() {
//     return OperatingSystem.current().isWindows();
//   }
// 
//   public static boolean isLinux() {
//     return OperatingSystem.current().isLinux();
//   }
// }
// 
// Path: buildSrc/src/main/java/org/jazzcommunity/development/library/file/FileReader.java
// public class FileReader {
//   private static final Logger logger = LoggerFactory.getLogger("FileReader");
// 
//   private FileReader() {}
// 
//   public static Stream<String> raw(File path) {
//     if (!path.exists()) {
//       logger.error("File {} does not exist", path);
//     }
// 
//     CharSource source = Files.asCharSource(path, StandardCharsets.UTF_8);
//     return raw(source);
//   }
// 
//   public static Stream<String> raw(CharSource source) {
//     try {
//       return source.lines();
//     } catch (IOException e) {
//       if (logger.isDebugEnabled()) {
//         e.printStackTrace();
//       }
//       logger.error("Error occurred reading files: {}", e.getMessage());
//       return Stream.empty();
//     }
//   }
// 
//   public static Stream<String> read(File path) {
//     return raw(path).map(String::trim);
//   }
// 
//   public static Stream<String> read(CharSource source) {
//     return raw(source).map(String::trim);
//   }
// }
// 
// Path: buildSrc/src/main/java/org/jazzcommunity/development/library/file/FileResolver.java
// public final class FileResolver {
//   private static final Logger logger = LoggerFactory.getLogger("FileResolver");
// 
//   private FileResolver() {}
// 
//   public static Stream<Path> findInDirectory(Path directory, String endsWith) {
//     try {
//       return Files.find(directory, 1, (p, b) -> p.getFileName().toString().endsWith(endsWith));
//     } catch (IOException e) {
//       if (logger.isDebugEnabled()) {
//         e.printStackTrace();
//       }
//       logger.info(
//           "File ending with '{}' in '{}' not found. Ignoring this entry.", directory, endsWith);
//       return null;
//     }
//   }
// }


import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;
import org.jazzcommunity.development.library.DetectOperatingSystem;
import org.jazzcommunity.development.library.file.FileReader;
import org.jazzcommunity.development.library.file.FileResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package org.jazzcommunity.development.library.config.plugin;


class ServiceEntry implements IniEntry {

  private final Logger logger = LoggerFactory.getLogger(this.getClass());
  private final File directory;

  public ServiceEntry(File directory) {
    this.directory = directory;
  }

  @Override
  public String getIniLine() {
    // TODO: duplicated code
    String formatted = directory.getPath();

    if (DetectOperatingSystem.isWindows()) {
      formatted = formatted.replaceAll("\\\\", "/");
      formatted = formatted.replaceAll(":", "\\\\:");
    }

    return String.format("reference\\:file\\:%s/plugin@start", formatted);
  }

  @Override
  public String getPropertiesLine() {
    File manifest = new File(directory, "plugin/META-INF/MANIFEST.MF");
    return FileReader.read(manifest)
        .filter(l -> l.startsWith("Bundle-SymbolicName"))
        .findFirst()
        .map(line -> String.format("%s=target/classes,target/dependency", toSymbolicName(line)))
        .orElseThrow(
            () ->
                new RuntimeException(
                    String.format(
                        "Missing Bundle-SymbolicName in %s. Malformed manifest", directory)));
  }

  @Override
// Path: buildSrc/src/main/java/org/jazzcommunity/development/library/DetectOperatingSystem.java
// public class DetectOperatingSystem {
//   public static boolean isWindows() {
//     return OperatingSystem.current().isWindows();
//   }
// 
//   public static boolean isLinux() {
//     return OperatingSystem.current().isLinux();
//   }
// }
// 
// Path: buildSrc/src/main/java/org/jazzcommunity/development/library/file/FileReader.java
// public class FileReader {
//   private static final Logger logger = LoggerFactory.getLogger("FileReader");
// 
//   private FileReader() {}
// 
//   public static Stream<String> raw(File path) {
//     if (!path.exists()) {
//       logger.error("File {} does not exist", path);
//     }
// 
//     CharSource source = Files.asCharSource(path, StandardCharsets.UTF_8);
//     return raw(source);
//   }
// 
//   public static Stream<String> raw(CharSource source) {
//     try {
//       return source.lines();
//     } catch (IOException e) {
//       if (logger.isDebugEnabled()) {
//         e.printStackTrace();
//       }
//       logger.error("Error occurred reading files: {}", e.getMessage());
//       return Stream.empty();
//     }
//   }
// 
//   public static Stream<String> read(File path) {
//     return raw(path).map(String::trim);
//   }
// 
//   public static Stream<String> read(CharSource source) {
//     return raw(source).map(String::trim);
//   }
// }
// 
// Path: buildSrc/src/main/java/org/jazzcommunity/development/library/file/FileResolver.java
// public final class FileResolver {
//   private static final Logger logger = LoggerFactory.getLogger("FileResolver");
// 
//   private FileResolver() {}
// 
//   public static Stream<Path> findInDirectory(Path directory, String endsWith) {
//     try {
//       return Files.find(directory, 1, (p, b) -> p.getFileName().toString().endsWith(endsWith));
//     } catch (IOException e) {
//       if (logger.isDebugEnabled()) {
//         e.printStackTrace();
//       }
//       logger.info(
//           "File ending with '{}' in '{}' not found. Ignoring this entry.", directory, endsWith);
//       return null;
//     }
//   }
// }


// Path: buildSrc/src/main/java/org/jazzcommunity/development/library/config/plugin/ServiceEntry.java
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;
import org.jazzcommunity.development.library.DetectOperatingSystem;
import org.jazzcommunity.development.library.file.FileReader;
import org.jazzcommunity.development.library.file.FileResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

package org.jazzcommunity.development.library.config.plugin;


class ServiceEntry implements IniEntry {

  private final Logger logger = LoggerFactory.getLogger(this.getClass());
  private final File directory;

  public ServiceEntry(File directory) {
    this.directory = directory;
  }

  @Override
  public String getIniLine() {
    // TODO: duplicated code
    String formatted = directory.getPath();

    if (DetectOperatingSystem.isWindows()) {
      formatted = formatted.replaceAll("\\\\", "/");
      formatted = formatted.replaceAll(":", "\\\\:");
    }

    return String.format("reference\\:file\\:%s/plugin@start", formatted);
  }

  @Override
  public String getPropertiesLine() {
    File manifest = new File(directory, "plugin/META-INF/MANIFEST.MF");
    return FileReader.read(manifest)
        .filter(l -> l.startsWith("Bundle-SymbolicName"))
        .findFirst()
        .map(line -> String.format("%s=target/classes,target/dependency", toSymbolicName(line)))
        .orElseThrow(
            () ->
                new RuntimeException(
                    String.format(
                        "Missing Bundle-SymbolicName in %s. Malformed manifest", directory)));
  }

  @Override
  public boolean needsPropertyEntry() {