use of com.facebook.buck.util.VersionStringComparator in project buck by facebook.
the class DefaultAndroidDirectoryResolver method findBuildTools.
private Optional<Path> findBuildTools() {
if (!sdk.isPresent()) {
buildToolsErrorMessage = Optional.of(TOOLS_NEED_SDK_MESSAGE);
return Optional.empty();
}
final Path sdkDir = sdk.get();
final Path toolsDir = sdkDir.resolve("build-tools");
if (toolsDir.toFile().isDirectory()) {
// In older versions of the ADT that have been upgraded via the SDK manager, the build-tools
// directory appears to contain subfolders of the form "17.0.0". However, newer versions of
// the ADT that are downloaded directly from http://developer.android.com/ appear to have
// subfolders of the form android-4.2.2. There also appear to be cases where subfolders
// are named build-tools-18.0.0. We need to support all of these scenarios.
File[] directories;
try {
directories = toolsDir.toFile().listFiles(pathname -> {
if (!pathname.isDirectory()) {
return false;
}
String version = stripBuildToolsPrefix(pathname.getName());
if (!VersionStringComparator.isValidVersionString(version)) {
throw new HumanReadableException("%s in %s is not a valid build tools directory.%n" + "Build tools directories should be follow the naming scheme: " + "android-<VERSION>, build-tools-<VERSION>, or <VERSION>. Please remove " + "directory %s.", pathname.getName(), buildTools, pathname.getName());
}
if (targetBuildToolsVersion.isPresent()) {
return targetBuildToolsVersion.get().equals(pathname.getName());
}
return true;
});
} catch (HumanReadableException e) {
buildToolsErrorMessage = Optional.of(e.getHumanReadableErrorMessage());
return Optional.empty();
}
if (targetBuildToolsVersion.isPresent()) {
if (directories.length == 0) {
buildToolsErrorMessage = unableToFindTargetBuildTools();
return Optional.empty();
} else {
return Optional.of(directories[0].toPath());
}
}
// We aren't looking for a specific version, so we pick the newest version
final VersionStringComparator comparator = new VersionStringComparator();
File newestBuildDir = null;
String newestBuildDirVersion = null;
for (File directory : directories) {
String currentDirVersion = stripBuildToolsPrefix(directory.getName());
if (newestBuildDir == null || newestBuildDirVersion == null || comparator.compare(newestBuildDirVersion, currentDirVersion) < 0) {
newestBuildDir = directory;
newestBuildDirVersion = currentDirVersion;
}
}
if (newestBuildDir == null) {
buildToolsErrorMessage = Optional.of(buildTools + " was empty, but should have " + "contained a subdirectory with build tools. Install them using the Android " + "SDK Manager (" + toolsDir.getParent().resolve("tools").resolve("android") + ").");
return Optional.empty();
}
return Optional.of(newestBuildDir.toPath());
}
if (targetBuildToolsVersion.isPresent()) {
// We were looking for a specific version, but we aren't going to find it at this point since
// nothing under platform-tools was versioned.
buildToolsErrorMessage = unableToFindTargetBuildTools();
return Optional.empty();
}
// Build tools used to exist inside of platform-tools, so fallback to that.
return Optional.of(sdkDir.resolve("platform-tools"));
}
use of com.facebook.buck.util.VersionStringComparator in project buck by facebook.
the class PythonTestIntegrationTest method assumePythonVersionIsAtLeast.
private void assumePythonVersionIsAtLeast(String expectedVersion, String message) throws InterruptedException {
PythonVersion actualVersion = new PythonBuckConfig(FakeBuckConfig.builder().build(), new ExecutableFinder()).getPythonEnvironment(new DefaultProcessExecutor(new TestConsole())).getPythonVersion();
assumeTrue(String.format("Needs at least Python-%s, but found Python-%s: %s", expectedVersion, actualVersion, message), new VersionStringComparator().compare(actualVersion.getVersionString(), expectedVersion) >= 0);
}
use of com.facebook.buck.util.VersionStringComparator in project buck by facebook.
the class DefaultAndroidDirectoryResolver method findNdkFromRepository.
private Optional<Path> findNdkFromRepository(Path repository) {
ImmutableSet<Path> repositoryContents;
try (DirectoryStream<Path> stream = Files.newDirectoryStream(repository)) {
repositoryContents = ImmutableSet.copyOf(stream);
} catch (IOException e) {
ndkErrorMessage = Optional.of("Unable to read contents of Android ndk.repository or " + "ANDROID_NDK_REPOSITORY at " + repository);
return Optional.empty();
}
VersionStringComparator versionComparator = new VersionStringComparator();
List<Pair<Path, Optional<String>>> availableNdks = repositoryContents.stream().filter(Files::isDirectory).map(p -> new Pair<>(p, findNdkVersion(p))).filter(pair -> pair.getSecond().isPresent()).sorted((o1, o2) -> versionComparator.compare(o2.getSecond().get(), o1.getSecond().get())).collect(Collectors.toList());
if (availableNdks.isEmpty()) {
ndkErrorMessage = Optional.of(repository + " does not contain any valid Android NDK. Make" + " sure to specify ANDROID_NDK_REPOSITORY or ndk.repository.");
return Optional.empty();
}
if (targetNdkVersion.isPresent()) {
if (targetNdkVersion.get().isEmpty()) {
ndkErrorMessage = Optional.of(NDK_TARGET_VERSION_IS_EMPTY_MESSAGE);
return Optional.empty();
}
Optional<Path> targetNdkPath = availableNdks.stream().filter(p -> versionsMatch(targetNdkVersion.get(), p.getSecond().get())).map(Pair::getFirst).findFirst();
if (targetNdkPath.isPresent()) {
return targetNdkPath;
}
ndkErrorMessage = Optional.of("Target NDK version " + targetNdkVersion.get() + " is not " + "available. The following versions are available: " + availableNdks.stream().map(Pair::getSecond).map(Optional::get).collect(Collectors.joining(", ")));
return Optional.empty();
}
return Optional.of(availableNdks.get(0).getFirst());
}
use of com.facebook.buck.util.VersionStringComparator in project buck by facebook.
the class AndroidResourceFilterIntegrationTest method findBuildToolsVersion.
@BeforeClass
public static void findBuildToolsVersion() {
AssumeAndroidPlatform.assumeSdkIsAvailable();
ProjectFilesystem filesystem = new ProjectFilesystem(Paths.get(".").toAbsolutePath());
AndroidDirectoryResolver resolver = new DefaultAndroidDirectoryResolver(filesystem.getRootPath().getFileSystem(), ImmutableMap.copyOf(System.getenv()), Optional.empty(), Optional.empty());
pathToAapt = AndroidPlatformTarget.getDefaultPlatformTarget(resolver, Optional.empty()).getAaptExecutable();
String buildToolsVersion = pathToAapt.getParent().getFileName().toString();
isBuildToolsNew = new VersionStringComparator().compare(buildToolsVersion, "21") >= 0;
}
Aggregations