@Test void shouldParseVersionedBuildGradle() { URL gradleInitial = GradleInfoReaderTest.class.getClassLoader().getResource(GRADLE_VERSIONED); File file = Urls.toFile(gradleInitial); Path root = file.toPath().getParent(); BuildInfo info = new GradleInfoReader().getInfo(root); assertNotNull(info); assertEquals("myartifact", info.getName()); assertEquals("jar", info.getPackaging()); assertEquals("1.0.0", info.getVersion()); }
@Override public BuildInfo getInfo(Path root) { Path buildGradle = root.resolve(BUILD_GRADLE_GROOVY); Path settingsGradle = root.resolve(SETTINGS_GRADLE_GROOVY); boolean kts = root.resolve(BUILD_GRADLE_KTS).toFile().exists(); if (kts) { buildGradle = root.resolve(BUILD_GRADLE_KTS); settingsGradle = root.resolve(SETTINGS_GRADLE_KTS); } String language = detectLanguage(root); Path gradleProperties = root.resolve(GRADLE_PROPERTIES); Map<String, String> properties = new HashMap<>(); properties.putAll(readSettingsGradle(settingsGradle)); properties.putAll(readGradleProperties(gradleProperties)); properties.putAll(readBuildGradle(buildGradle)); String name = properties.getOrDefault(NAME, properties.getOrDefault(BASENAME, root.getFileName().toString())); String version = properties.get(VERSION); String classifier = properties.get(CLASSIFIER); String extension = properties.getOrDefault(EXTENSION, JAR); String destinationDir = properties.getOrDefault(DESTINATION_DIR, BUILD + File.separator + LIBS + File.separator); Path outputDir = root.resolve(destinationDir); StringBuilder sb = new StringBuilder(); sb.append(name); if (Strings.isNotNullOrEmpty(version)) { sb.append(DASH).append(version); } if (Strings.isNotNullOrEmpty(classifier)) { sb.append(DASH).append(classifier); } sb.append(DOT).append(extension); if (version == null) { LOGGER.warning("Could not detect project version. Using 'latest'."); version = "latest"; } return new BuildInfoBuilder() .withName(name) .withVersion(version) .withPackaging(extension) .withBuildTool(GRADLE) .withBuildToolVersion(Gradle.getVersion(root)) .withOutputFile(outputDir.resolve(sb.toString())) .withClassOutputDir(root.resolve(BUILD).resolve(CLASSES).resolve(language).resolve(MAIN)) .withResourceDir(root.resolve(SRC).resolve(MAIN).resolve(RESOURCES)) .build(); }
GradleInfoReader implements BuildInfoReader { @Override public BuildInfo getInfo(Path root) { Path buildGradle = root.resolve(BUILD_GRADLE_GROOVY); Path settingsGradle = root.resolve(SETTINGS_GRADLE_GROOVY); boolean kts = root.resolve(BUILD_GRADLE_KTS).toFile().exists(); if (kts) { buildGradle = root.resolve(BUILD_GRADLE_KTS); settingsGradle = root.resolve(SETTINGS_GRADLE_KTS); } String language = detectLanguage(root); Path gradleProperties = root.resolve(GRADLE_PROPERTIES); Map<String, String> properties = new HashMap<>(); properties.putAll(readSettingsGradle(settingsGradle)); properties.putAll(readGradleProperties(gradleProperties)); properties.putAll(readBuildGradle(buildGradle)); String name = properties.getOrDefault(NAME, properties.getOrDefault(BASENAME, root.getFileName().toString())); String version = properties.get(VERSION); String classifier = properties.get(CLASSIFIER); String extension = properties.getOrDefault(EXTENSION, JAR); String destinationDir = properties.getOrDefault(DESTINATION_DIR, BUILD + File.separator + LIBS + File.separator); Path outputDir = root.resolve(destinationDir); StringBuilder sb = new StringBuilder(); sb.append(name); if (Strings.isNotNullOrEmpty(version)) { sb.append(DASH).append(version); } if (Strings.isNotNullOrEmpty(classifier)) { sb.append(DASH).append(classifier); } sb.append(DOT).append(extension); if (version == null) { LOGGER.warning("Could not detect project version. Using 'latest'."); version = "latest"; } return new BuildInfoBuilder() .withName(name) .withVersion(version) .withPackaging(extension) .withBuildTool(GRADLE) .withBuildToolVersion(Gradle.getVersion(root)) .withOutputFile(outputDir.resolve(sb.toString())) .withClassOutputDir(root.resolve(BUILD).resolve(CLASSES).resolve(language).resolve(MAIN)) .withResourceDir(root.resolve(SRC).resolve(MAIN).resolve(RESOURCES)) .build(); } }
GradleInfoReader implements BuildInfoReader { @Override public BuildInfo getInfo(Path root) { Path buildGradle = root.resolve(BUILD_GRADLE_GROOVY); Path settingsGradle = root.resolve(SETTINGS_GRADLE_GROOVY); boolean kts = root.resolve(BUILD_GRADLE_KTS).toFile().exists(); if (kts) { buildGradle = root.resolve(BUILD_GRADLE_KTS); settingsGradle = root.resolve(SETTINGS_GRADLE_KTS); } String language = detectLanguage(root); Path gradleProperties = root.resolve(GRADLE_PROPERTIES); Map<String, String> properties = new HashMap<>(); properties.putAll(readSettingsGradle(settingsGradle)); properties.putAll(readGradleProperties(gradleProperties)); properties.putAll(readBuildGradle(buildGradle)); String name = properties.getOrDefault(NAME, properties.getOrDefault(BASENAME, root.getFileName().toString())); String version = properties.get(VERSION); String classifier = properties.get(CLASSIFIER); String extension = properties.getOrDefault(EXTENSION, JAR); String destinationDir = properties.getOrDefault(DESTINATION_DIR, BUILD + File.separator + LIBS + File.separator); Path outputDir = root.resolve(destinationDir); StringBuilder sb = new StringBuilder(); sb.append(name); if (Strings.isNotNullOrEmpty(version)) { sb.append(DASH).append(version); } if (Strings.isNotNullOrEmpty(classifier)) { sb.append(DASH).append(classifier); } sb.append(DOT).append(extension); if (version == null) { LOGGER.warning("Could not detect project version. Using 'latest'."); version = "latest"; } return new BuildInfoBuilder() .withName(name) .withVersion(version) .withPackaging(extension) .withBuildTool(GRADLE) .withBuildToolVersion(Gradle.getVersion(root)) .withOutputFile(outputDir.resolve(sb.toString())) .withClassOutputDir(root.resolve(BUILD).resolve(CLASSES).resolve(language).resolve(MAIN)) .withResourceDir(root.resolve(SRC).resolve(MAIN).resolve(RESOURCES)) .build(); }  }
GradleInfoReader implements BuildInfoReader { @Override public BuildInfo getInfo(Path root) { Path buildGradle = root.resolve(BUILD_GRADLE_GROOVY); Path settingsGradle = root.resolve(SETTINGS_GRADLE_GROOVY); boolean kts = root.resolve(BUILD_GRADLE_KTS).toFile().exists(); if (kts) { buildGradle = root.resolve(BUILD_GRADLE_KTS); settingsGradle = root.resolve(SETTINGS_GRADLE_KTS); } String language = detectLanguage(root); Path gradleProperties = root.resolve(GRADLE_PROPERTIES); Map<String, String> properties = new HashMap<>(); properties.putAll(readSettingsGradle(settingsGradle)); properties.putAll(readGradleProperties(gradleProperties)); properties.putAll(readBuildGradle(buildGradle)); String name = properties.getOrDefault(NAME, properties.getOrDefault(BASENAME, root.getFileName().toString())); String version = properties.get(VERSION); String classifier = properties.get(CLASSIFIER); String extension = properties.getOrDefault(EXTENSION, JAR); String destinationDir = properties.getOrDefault(DESTINATION_DIR, BUILD + File.separator + LIBS + File.separator); Path outputDir = root.resolve(destinationDir); StringBuilder sb = new StringBuilder(); sb.append(name); if (Strings.isNotNullOrEmpty(version)) { sb.append(DASH).append(version); } if (Strings.isNotNullOrEmpty(classifier)) { sb.append(DASH).append(classifier); } sb.append(DOT).append(extension); if (version == null) { LOGGER.warning("Could not detect project version. Using 'latest'."); version = "latest"; } return new BuildInfoBuilder() .withName(name) .withVersion(version) .withPackaging(extension) .withBuildTool(GRADLE) .withBuildToolVersion(Gradle.getVersion(root)) .withOutputFile(outputDir.resolve(sb.toString())) .withClassOutputDir(root.resolve(BUILD).resolve(CLASSES).resolve(language).resolve(MAIN)) .withResourceDir(root.resolve(SRC).resolve(MAIN).resolve(RESOURCES)) .build(); }  @Override int order(); @Override boolean isApplicable(Path root); @Override BuildInfo getInfo(Path root); }
GradleInfoReader implements BuildInfoReader { @Override public BuildInfo getInfo(Path root) { Path buildGradle = root.resolve(BUILD_GRADLE_GROOVY); Path settingsGradle = root.resolve(SETTINGS_GRADLE_GROOVY); boolean kts = root.resolve(BUILD_GRADLE_KTS).toFile().exists(); if (kts) { buildGradle = root.resolve(BUILD_GRADLE_KTS); settingsGradle = root.resolve(SETTINGS_GRADLE_KTS); } String language = detectLanguage(root); Path gradleProperties = root.resolve(GRADLE_PROPERTIES); Map<String, String> properties = new HashMap<>(); properties.putAll(readSettingsGradle(settingsGradle)); properties.putAll(readGradleProperties(gradleProperties)); properties.putAll(readBuildGradle(buildGradle)); String name = properties.getOrDefault(NAME, properties.getOrDefault(BASENAME, root.getFileName().toString())); String version = properties.get(VERSION); String classifier = properties.get(CLASSIFIER); String extension = properties.getOrDefault(EXTENSION, JAR); String destinationDir = properties.getOrDefault(DESTINATION_DIR, BUILD + File.separator + LIBS + File.separator); Path outputDir = root.resolve(destinationDir); StringBuilder sb = new StringBuilder(); sb.append(name); if (Strings.isNotNullOrEmpty(version)) { sb.append(DASH).append(version); } if (Strings.isNotNullOrEmpty(classifier)) { sb.append(DASH).append(classifier); } sb.append(DOT).append(extension); if (version == null) { LOGGER.warning("Could not detect project version. Using 'latest'."); version = "latest"; } return new BuildInfoBuilder() .withName(name) .withVersion(version) .withPackaging(extension) .withBuildTool(GRADLE) .withBuildToolVersion(Gradle.getVersion(root)) .withOutputFile(outputDir.resolve(sb.toString())) .withClassOutputDir(root.resolve(BUILD).resolve(CLASSES).resolve(language).resolve(MAIN)) .withResourceDir(root.resolve(SRC).resolve(MAIN).resolve(RESOURCES)) .build(); }  @Override int order(); @Override boolean isApplicable(Path root); @Override BuildInfo getInfo(Path root);  }