use of java.nio.file.FileSystem in project bazel by bazelbuild.
the class XcodeGen method main.
public static void main(String[] args) throws IOException, OptionsParsingException {
OptionsParser parser = OptionsParser.newOptionsParser(XcodeGenOptions.class);
parser.parse(args);
XcodeGenOptions options = parser.getOptions(XcodeGenOptions.class);
if (options.control == null) {
throw new IllegalArgumentException("--control must be specified\n" + Options.getUsage(XcodeGenOptions.class));
}
FileSystem fileSystem = FileSystems.getDefault();
Control controlPb;
try (InputStream in = Files.newInputStream(fileSystem.getPath(options.control))) {
controlPb = Control.parseFrom(in);
}
Path pbxprojPath = fileSystem.getPath(controlPb.getPbxproj());
Iterator<String> srcList = allSourceFilePaths(controlPb).iterator();
Path workspaceRoot;
// TODO(bazel-team): Remove this if-else clause once Bazel passes in the workspace root.
if (controlPb.hasWorkspaceRoot()) {
workspaceRoot = fileSystem.getPath(controlPb.getWorkspaceRoot());
} else if (!srcList.hasNext()) {
workspaceRoot = XcodeprojGeneration.relativeWorkspaceRoot(pbxprojPath);
} else {
// Get the absolute path to the workspace root.
// TODO(bazel-team): Remove this hack, possibly by converting Xcodegen to be run with
// "bazel run" and using RUNFILES to get the workspace root. For now, this is needed to work
// around Xcode's handling of symlinks not playing nicely with how Bazel stores output
// artifacts in /private/var/tmp. This means a relative path from .xcodeproj in bazel-out to
// the workspace root in .xcodeproj will not work properly at certain times during
// Xcode/xcodebuild execution. Walking up the path of a known source file prevents having
// to reason about a file that might only be accessible through a symlink, like a tools jar.
Path relSourceFilePath = fileSystem.getPath(srcList.next());
Path absSourceFilePath = relSourceFilePath.toAbsolutePath();
workspaceRoot = absSourceFilePath;
for (int i = 0; i < relSourceFilePath.getNameCount(); i++) {
workspaceRoot = workspaceRoot.getParent();
}
}
try (OutputStream out = Files.newOutputStream(pbxprojPath)) {
// This workspace root here is relative to the PWD, so that the .xccurrentversion
// files can actually be read. The other workspaceRoot is relative to the .xcodeproj
// root or is absolute.
Path relativeWorkspaceRoot = fileSystem.getPath(".");
PBXProject project = XcodeprojGeneration.xcodeproj(workspaceRoot, controlPb, ImmutableList.of(new CurrentVersionSetter(relativeWorkspaceRoot), new PbxReferencesGrouper(fileSystem)));
XcodeprojGeneration.write(out, project);
}
}
use of java.nio.file.FileSystem in project elasticsearch by elastic.
the class KeyStoreCommandTestCase method setupEnv.
void setupEnv(boolean posix) throws IOException {
final Configuration configuration;
if (posix) {
configuration = Configuration.unix().toBuilder().setAttributeViews("basic", "owner", "posix", "unix").build();
} else {
configuration = Configuration.unix();
}
FileSystem fs = Jimfs.newFileSystem(configuration);
fileSystems.add(fs);
// restored by restoreFileSystem in ESTestCase
PathUtilsForTesting.installMock(fs);
Path home = fs.getPath("/", "test-home");
Files.createDirectories(home.resolve("config"));
env = new Environment(Settings.builder().put("path.home", home).build());
}
use of java.nio.file.FileSystem in project elasticsearch by elastic.
the class NewPathForShardTests method installMockUsableSpaceFS.
@BeforeClass
public static void installMockUsableSpaceFS() throws Exception {
FileSystem current = PathUtils.getDefaultFileSystem();
aPathPart = current.getSeparator() + 'a' + current.getSeparator();
bPathPart = current.getSeparator() + 'b' + current.getSeparator();
FileSystemProvider mock = new MockUsableSpaceFileSystemProvider(current);
PathUtilsForTesting.installMock(mock.getFileSystem(null));
}
use of java.nio.file.FileSystem in project elasticsearch by elastic.
the class ESClientYamlSuiteTestCase method initAndResetContext.
@Before
public void initAndResetContext() throws IOException {
if (restTestExecutionContext == null) {
assert adminExecutionContext == null;
assert blacklistPathMatchers == null;
String[] specPaths = resolvePathsProperty(REST_TESTS_SPEC, DEFAULT_SPEC_PATH);
ClientYamlSuiteRestSpec restSpec = null;
FileSystem fileSystem = getFileSystem();
// ... and you can't close() the default filesystem
try {
restSpec = ClientYamlSuiteRestSpec.parseFrom(fileSystem, DEFAULT_SPEC_PATH, specPaths);
} finally {
IOUtils.close(fileSystem);
}
validateSpec(restSpec);
List<HttpHost> hosts = getClusterHosts();
RestClient restClient = client();
Version infoVersion = readVersionsFromInfo(restClient, hosts.size());
Version esVersion;
try {
Tuple<Version, Version> versionVersionTuple = readVersionsFromCatNodes(restClient);
esVersion = versionVersionTuple.v1();
Version masterVersion = versionVersionTuple.v2();
logger.info("initializing yaml client, minimum es version: [{}] master version: [{}] hosts: {}", esVersion, masterVersion, hosts);
} catch (ResponseException ex) {
if (ex.getResponse().getStatusLine().getStatusCode() == 403) {
logger.warn("Fallback to simple info '/' request, _cat/nodes is not authorized");
esVersion = infoVersion;
logger.info("initializing yaml client, minimum es version: [{}] hosts: {}", esVersion, hosts);
} else {
throw ex;
}
}
ClientYamlTestClient clientYamlTestClient = new ClientYamlTestClient(restSpec, restClient, hosts, esVersion);
restTestExecutionContext = new ClientYamlTestExecutionContext(clientYamlTestClient, randomizeContentType());
adminExecutionContext = new ClientYamlTestExecutionContext(clientYamlTestClient, false);
String[] blacklist = resolvePathsProperty(REST_TESTS_BLACKLIST, null);
blacklistPathMatchers = new ArrayList<>();
for (String entry : blacklist) {
blacklistPathMatchers.add(new BlacklistedPathPatternMatcher(entry));
}
}
assert restTestExecutionContext != null;
assert adminExecutionContext != null;
assert blacklistPathMatchers != null;
// admin context must be available for @After always, regardless of whether the test was blacklisted
adminExecutionContext.clear();
//skip test if it matches one of the blacklist globs
for (BlacklistedPathPatternMatcher blacklistedPathMatcher : blacklistPathMatchers) {
String testPath = testCandidate.getSuitePath() + "/" + testCandidate.getTestSection().getName();
assumeFalse("[" + testCandidate.getTestPath() + "] skipped, reason: blacklisted", blacklistedPathMatcher.isSuffixMatch(testPath));
}
restTestExecutionContext.clear();
//skip test if the whole suite (yaml file) is disabled
assumeFalse(testCandidate.getSetupSection().getSkipSection().getSkipMessage(testCandidate.getSuitePath()), testCandidate.getSetupSection().getSkipSection().skip(restTestExecutionContext.esVersion()));
//skip test if the whole suite (yaml file) is disabled
assumeFalse(testCandidate.getTeardownSection().getSkipSection().getSkipMessage(testCandidate.getSuitePath()), testCandidate.getTeardownSection().getSkipSection().skip(restTestExecutionContext.esVersion()));
//skip test if test section is disabled
assumeFalse(testCandidate.getTestSection().getSkipSection().getSkipMessage(testCandidate.getTestPath()), testCandidate.getTestSection().getSkipSection().skip(restTestExecutionContext.esVersion()));
}
use of java.nio.file.FileSystem in project elasticsearch by elastic.
the class ESClientYamlSuiteTestCase method collectTestCandidates.
private static List<ClientYamlTestCandidate> collectTestCandidates() throws IOException {
List<ClientYamlTestCandidate> testCandidates = new ArrayList<>();
FileSystem fileSystem = getFileSystem();
// ... and you can't close() the default filesystem
try {
String[] paths = resolvePathsProperty(REST_TESTS_SUITE, DEFAULT_TESTS_PATH);
Map<String, Set<Path>> yamlSuites = FileUtils.findYamlSuites(fileSystem, DEFAULT_TESTS_PATH, paths);
//yaml suites are grouped by directory (effectively by api)
for (String api : yamlSuites.keySet()) {
List<Path> yamlFiles = new ArrayList<>(yamlSuites.get(api));
for (Path yamlFile : yamlFiles) {
ClientYamlTestSuite restTestSuite = ClientYamlTestSuite.parse(api, yamlFile);
for (ClientYamlTestSection testSection : restTestSuite.getTestSections()) {
testCandidates.add(new ClientYamlTestCandidate(restTestSuite, testSection));
}
}
}
} finally {
IOUtils.close(fileSystem);
}
//sort the candidates so they will always be in the same order before being shuffled, for repeatability
Collections.sort(testCandidates, (o1, o2) -> o1.getTestPath().compareTo(o2.getTestPath()));
return testCandidates;
}
Aggregations