Search in sources :

Example 91 with FileSystem

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);
    }
}
Also used : Path(java.nio.file.Path) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) OptionsParser(com.google.devtools.common.options.OptionsParser) Control(com.google.devtools.build.xcode.xcodegen.proto.XcodeGenProtos.Control) TargetControl(com.google.devtools.build.xcode.xcodegen.proto.XcodeGenProtos.TargetControl) FileSystem(java.nio.file.FileSystem) PBXProject(com.facebook.buck.apple.xcode.xcodeproj.PBXProject)

Example 92 with FileSystem

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());
}
Also used : Path(java.nio.file.Path) Configuration(com.google.common.jimfs.Configuration) FileSystem(java.nio.file.FileSystem) Environment(org.elasticsearch.env.Environment)

Example 93 with FileSystem

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));
}
Also used : FileSystemProvider(java.nio.file.spi.FileSystemProvider) FilterFileSystemProvider(org.apache.lucene.mockfile.FilterFileSystemProvider) FileSystem(java.nio.file.FileSystem) BeforeClass(org.junit.BeforeClass)

Example 94 with FileSystem

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()));
}
Also used : ResponseException(org.elasticsearch.client.ResponseException) RestClient(org.elasticsearch.client.RestClient) ClientYamlSuiteRestSpec(org.elasticsearch.test.rest.yaml.restspec.ClientYamlSuiteRestSpec) Version(org.elasticsearch.Version) HttpHost(org.apache.http.HttpHost) FileSystem(java.nio.file.FileSystem) Before(org.junit.Before)

Example 95 with FileSystem

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;
}
Also used : Path(java.nio.file.Path) Set(java.util.Set) ClientYamlTestSection(org.elasticsearch.test.rest.yaml.section.ClientYamlTestSection) FileSystem(java.nio.file.FileSystem) ArrayList(java.util.ArrayList) ClientYamlTestSuite(org.elasticsearch.test.rest.yaml.section.ClientYamlTestSuite)

Aggregations

FileSystem (java.nio.file.FileSystem)156 Path (java.nio.file.Path)109 Test (org.junit.Test)66 IOException (java.io.IOException)25 File (java.io.File)17 ArrayList (java.util.ArrayList)14 FilterFileSystem (org.apache.lucene.mockfile.FilterFileSystem)13 FilterPath (org.apache.lucene.mockfile.FilterPath)11 InputStream (java.io.InputStream)10 OutputStream (java.io.OutputStream)10 URI (java.net.URI)10 FileStore (java.nio.file.FileStore)8 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)6 HashMap (java.util.HashMap)6 DefaultProjectFilesystemDelegate (com.facebook.buck.io.DefaultProjectFilesystemDelegate)5 ProjectFilesystemDelegate (com.facebook.buck.io.ProjectFilesystemDelegate)5 WindowsFS (org.apache.lucene.mockfile.WindowsFS)5 FSDirectory (org.apache.lucene.store.FSDirectory)5 BuckConfig (com.facebook.buck.cli.BuckConfig)4 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)4