SbtInfoReader implements BuildInfoReader { @Override public BuildInfo getInfo(Path root) { Path gradlePath = root.resolve(BUILD_SBT); Map<String, String> properties = new HashMap<>(); try { Files.lines(gradlePath).map(l -> l.replaceAll("[ ]*", "")).filter(l -> l.contains(SET)).forEach(l -> { String key = l.substring(0, l.lastIndexOf(SET)); String value = l.substring(l.lastIndexOf(SET) + 2).replaceAll(DOUBLE_QUOTE, ""); properties.put(key, value); }); } catch (IOException e) { throw DekorateException.launderThrowable(e); } String name = properties.getOrDefault(NAME, root.getFileName().toString()); String version = properties.getOrDefault(VERSION, DEFAULT_VERSION); String scalaVersion = properties.getOrDefault(SCALA_VERSION, getSystemScalaVersion()); String extension = JAR; Path outputFile = root.resolve(TARGET).resolve(name + UNDERSCORE + scalaVersion + DASH + version + DOT + extension); Path resourceOutputDir = root.resolve(TARGET).resolve(CLASSES); return new BuildInfoBuilder() .withName(name) .withVersion(version) .withPackaging(JAR) .withBuildTool(SBT) .withBuildToolVersion(null) .withOutputFile(outputFile) .withResourceDir(resourceOutputDir) .build(); }  @Override int order(); @Override boolean isApplicable(Path root); @Override BuildInfo getInfo(Path root);  }
@Test void shouldParsePlainBuildSbt() { URL sbtInitial = SbtInfoReader.class.getClassLoader().getResource(SBT_INITIAL); File file = Urls.toFile(sbtInitial); Path root = file.toPath().getParent(); BuildInfo info = new SbtInfoReader().getInfo(root); assertNotNull(info); assertEquals("sbt-initial", info.getName()); assertEquals("jar", info.getPackaging()); assertEquals(SbtInfoReader.DEFAULT_VERSION, info.getVersion()); String expectedOutputFile = root.resolve("target/") .resolve(info.getName() + "_" + systemScalaVersion + "-" + info.getVersion() + ".jar").toAbsolutePath() .toString(); assertEquals(expectedOutputFile, info.getOutputFile().toAbsolutePath().toString()); }
@Test void shouldParseVersionedBuildSbt() { URL sbtVersioned = SbtInfoReader.class.getClassLoader().getResource(SBT_VERSIONED); File file = Urls.toFile(sbtVersioned); Path root = file.toPath().getParent(); BuildInfo info = new SbtInfoReader().getInfo(root); assertNotNull(info); assertEquals("sbt-versioned", info.getName()); assertEquals("jar", info.getPackaging()); assertEquals("1.0.0", info.getVersion()); String expectedOutputFile = root.resolve("target/") .resolve(info.getName() + "_" + systemScalaVersion + "-" + info.getVersion() + ".jar").toAbsolutePath() .toString(); assertEquals(expectedOutputFile, info.getOutputFile().toAbsolutePath().toString()); }