use of java.nio.file.NoSuchFileException in project elasticsearch by elastic.
the class InstallPluginCommandTests method testMissingDescriptor.
public void testMissingDescriptor() throws Exception {
Tuple<Path, Environment> env = createEnv(fs, temp);
Path pluginDir = createPluginDir(temp);
Files.createFile(pluginDir.resolve("fake.yml"));
String pluginZip = writeZip(pluginDir, "elasticsearch");
NoSuchFileException e = expectThrows(NoSuchFileException.class, () -> installPlugin(pluginZip, env.v1()));
assertTrue(e.getMessage(), e.getMessage().contains("plugin-descriptor.properties"));
assertInstallCleaned(env.v2());
}
use of java.nio.file.NoSuchFileException in project buck by facebook.
the class AppleSdkDiscovery method discoverAppleSdkPaths.
/**
* Given a path to an Xcode developer directory and a map of
* (xctoolchain ID: path) pairs as returned by
* {@link AppleToolchainDiscovery}, walks through the platforms
* and builds a map of ({@link AppleSdk}: {@link AppleSdkPaths})
* objects describing the paths to the SDKs inside.
*
* The {@link AppleSdk#getName()} strings match the ones displayed by {@code xcodebuild -showsdks}
* and look like {@code macosx10.9}, {@code iphoneos8.0}, {@code iphonesimulator8.0},
* etc.
*/
public static ImmutableMap<AppleSdk, AppleSdkPaths> discoverAppleSdkPaths(Optional<Path> developerDir, ImmutableList<Path> extraDirs, ImmutableMap<String, AppleToolchain> xcodeToolchains, AppleConfig appleConfig) throws IOException {
Optional<AppleToolchain> defaultToolchain = Optional.ofNullable(xcodeToolchains.get(DEFAULT_TOOLCHAIN_ID));
ImmutableMap.Builder<AppleSdk, AppleSdkPaths> appleSdkPathsBuilder = ImmutableMap.builder();
HashSet<Path> platformPaths = new HashSet<Path>(extraDirs);
if (developerDir.isPresent()) {
Path platformsDir = developerDir.get().resolve("Platforms");
LOG.debug("Searching for Xcode platforms under %s", platformsDir);
platformPaths.add(platformsDir);
}
// We need to find the most recent SDK for each platform so we can
// make the fall-back SDKs with no version number in their name
// ("macosx", "iphonesimulator", "iphoneos").
//
// To do this, we store a map of (platform: [sdk1, sdk2, ...])
// pairs where the SDKs for each platform are ordered by version.
TreeMultimap<ApplePlatform, AppleSdk> orderedSdksForPlatform = TreeMultimap.create(Ordering.natural(), APPLE_SDK_VERSION_ORDERING);
for (Path platforms : platformPaths) {
if (!Files.exists(platforms)) {
LOG.debug("Skipping platform search path %s that does not exist", platforms);
continue;
}
LOG.debug("Searching for Xcode SDKs in %s", platforms);
try (DirectoryStream<Path> platformStream = Files.newDirectoryStream(platforms, "*.platform")) {
for (Path platformDir : platformStream) {
Path developerSdksPath = platformDir.resolve("Developer/SDKs");
try (DirectoryStream<Path> sdkStream = Files.newDirectoryStream(developerSdksPath, "*.sdk")) {
Set<Path> scannedSdkDirs = new HashSet<>();
for (Path sdkDir : sdkStream) {
LOG.debug("Fetching SDK name for %s", sdkDir);
sdkDir = sdkDir.toRealPath();
if (scannedSdkDirs.contains(sdkDir)) {
LOG.debug("Skipping already scanned SDK directory %s", sdkDir);
continue;
}
AppleSdk.Builder sdkBuilder = AppleSdk.builder();
if (buildSdkFromPath(sdkDir, sdkBuilder, xcodeToolchains, defaultToolchain, appleConfig)) {
AppleSdk sdk = sdkBuilder.build();
LOG.debug("Found SDK %s", sdk);
AppleSdkPaths.Builder xcodePathsBuilder = AppleSdkPaths.builder();
for (AppleToolchain toolchain : sdk.getToolchains()) {
xcodePathsBuilder.addToolchainPaths(toolchain.getPath());
}
AppleSdkPaths xcodePaths = xcodePathsBuilder.setDeveloperPath(developerDir).setPlatformPath(platformDir).setSdkPath(sdkDir).build();
appleSdkPathsBuilder.put(sdk, xcodePaths);
orderedSdksForPlatform.put(sdk.getApplePlatform(), sdk);
}
scannedSdkDirs.add(sdkDir);
}
} catch (NoSuchFileException e) {
LOG.warn(e, "Couldn't discover SDKs at path %s, ignoring platform %s", developerSdksPath, platformDir);
}
}
}
}
// Get a snapshot of what's in appleSdkPathsBuilder, then for each
// ApplePlatform, add to appleSdkPathsBuilder the most recent
// SDK with an unversioned name.
ImmutableMap<AppleSdk, AppleSdkPaths> discoveredSdkPaths = appleSdkPathsBuilder.build();
for (ApplePlatform platform : orderedSdksForPlatform.keySet()) {
Set<AppleSdk> platformSdks = orderedSdksForPlatform.get(platform);
boolean shouldCreateUnversionedSdk = true;
for (AppleSdk sdk : platformSdks) {
shouldCreateUnversionedSdk &= !sdk.getName().equals(platform.getName());
}
if (shouldCreateUnversionedSdk) {
AppleSdk mostRecentSdkForPlatform = orderedSdksForPlatform.get(platform).last();
appleSdkPathsBuilder.put(mostRecentSdkForPlatform.withName(platform.getName()), discoveredSdkPaths.get(mostRecentSdkForPlatform));
}
}
// the unversioned aliases added just above.
return appleSdkPathsBuilder.build();
}
use of java.nio.file.NoSuchFileException in project buck by facebook.
the class AppleSdkDiscovery method buildSdkFromPath.
private static boolean buildSdkFromPath(Path sdkDir, AppleSdk.Builder sdkBuilder, ImmutableMap<String, AppleToolchain> xcodeToolchains, Optional<AppleToolchain> defaultToolchain, AppleConfig appleConfig) throws IOException {
try (InputStream sdkSettingsPlist = Files.newInputStream(sdkDir.resolve("SDKSettings.plist"));
BufferedInputStream bufferedSdkSettingsPlist = new BufferedInputStream(sdkSettingsPlist)) {
NSDictionary sdkSettings;
try {
sdkSettings = (NSDictionary) PropertyListParser.parse(bufferedSdkSettingsPlist);
} catch (PropertyListFormatException | ParseException | SAXException e) {
LOG.error(e, "Malformatted SDKSettings.plist. Skipping SDK path %s.", sdkDir);
return false;
} catch (ParserConfigurationException e) {
throw new IOException(e);
}
String name = sdkSettings.objectForKey("CanonicalName").toString();
String version = sdkSettings.objectForKey("Version").toString();
NSDictionary defaultProperties = (NSDictionary) sdkSettings.objectForKey("DefaultProperties");
Optional<ImmutableList<String>> toolchains = appleConfig.getToolchainsOverrideForSDKName(name);
boolean foundToolchain = false;
if (!toolchains.isPresent()) {
NSArray settingsToolchains = (NSArray) sdkSettings.objectForKey("Toolchains");
if (settingsToolchains != null) {
toolchains = Optional.of(Arrays.stream(settingsToolchains.getArray()).map(Object::toString).collect(MoreCollectors.toImmutableList()));
}
}
if (toolchains.isPresent()) {
for (String toolchainId : toolchains.get()) {
AppleToolchain toolchain = xcodeToolchains.get(toolchainId);
if (toolchain != null) {
foundToolchain = true;
sdkBuilder.addToolchains(toolchain);
} else {
LOG.debug("Specified toolchain %s not found for SDK path %s", toolchainId, sdkDir);
}
}
}
if (!foundToolchain && defaultToolchain.isPresent()) {
foundToolchain = true;
sdkBuilder.addToolchains(defaultToolchain.get());
}
if (!foundToolchain) {
LOG.warn("No toolchains found and no default toolchain. Skipping SDK path %s.", sdkDir);
return false;
} else {
NSString platformName = (NSString) defaultProperties.objectForKey("PLATFORM_NAME");
ApplePlatform applePlatform = ApplePlatform.of(platformName.toString());
sdkBuilder.setName(name).setVersion(version).setApplePlatform(applePlatform);
ImmutableList<String> architectures = validArchitecturesForPlatform(applePlatform, sdkDir);
sdkBuilder.addAllArchitectures(architectures);
return true;
}
} catch (NoSuchFileException e) {
LOG.warn(e, "Skipping SDK at path %s, no SDKSettings.plist found", sdkDir);
return false;
}
}
use of java.nio.file.NoSuchFileException in project buck by facebook.
the class AppleSimulatorDiscovery method discoverAppleSimulatorProfile.
/**
* Given a simulators, looks up metadata on the supported architectures
* and product families for that simulator (if present).
*/
public static Optional<AppleSimulatorProfile> discoverAppleSimulatorProfile(AppleSimulator appleSimulator, Path iphonesimulatorPlatformRoot) throws IOException {
Path simulatorProfilePlistPath = iphonesimulatorPlatformRoot.resolve(String.format("Developer/Library/CoreSimulator/Profiles/DeviceTypes/%s.simdevicetype/" + "Contents/Resources/profile.plist", appleSimulator.getName()));
LOG.debug("Parsing simulator profile plist %s", simulatorProfilePlistPath);
try (InputStream inputStream = Files.newInputStream(simulatorProfilePlistPath)) {
// This might return Optional.empty() if the input could not be parsed.
return AppleSimulatorProfileParsing.parseProfilePlistStream(inputStream);
} catch (FileNotFoundException | NoSuchFileException e) {
LOG.warn(e, "Could not open simulator profile %s, ignoring", simulatorProfilePlistPath);
return Optional.empty();
}
}
use of java.nio.file.NoSuchFileException in project elasticsearch by elastic.
the class IndexFolderUpgrader method upgrade.
/**
* Moves the index folder found in <code>source</code> to <code>target</code>
*/
void upgrade(final Index index, final Path source, final Path target) throws IOException {
boolean success = false;
try {
Files.move(source, target, StandardCopyOption.ATOMIC_MOVE);
success = true;
} catch (NoSuchFileException | FileNotFoundException exception) {
// thrown when the source is non-existent because the folder was renamed
// by another node (shared FS) after we checked if the target exists
logger.error((Supplier<?>) () -> new ParameterizedMessage("multiple nodes trying to upgrade [{}] in parallel, retry " + "upgrading with single node", target), exception);
throw exception;
} finally {
if (success) {
logger.info("{} moved from [{}] to [{}]", index, source, target);
logger.trace("{} syncing directory [{}]", index, target);
IOUtils.fsync(target, true);
}
}
}
Aggregations