Search in sources :

Example 16 with Paths

use of java.nio.file.Paths in project buck by facebook.

the class JavacStepTest method failedCompileSendsStdoutAndStderrToConsole.

@Test
public void failedCompileSendsStdoutAndStderrToConsole() throws Exception {
    FakeJavac fakeJavac = new FakeJavac();
    BuildRuleResolver buildRuleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(buildRuleResolver);
    SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
    ProjectFilesystem fakeFilesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
    JavacOptions javacOptions = JavacOptions.builder().setSourceLevel("8.0").setTargetLevel("8.0").build();
    ClasspathChecker classpathChecker = new ClasspathChecker("/", ":", Paths::get, dir -> false, file -> false, (path, glob) -> ImmutableSet.of());
    JavacStep step = new JavacStep(Paths.get("output"), NoOpClassUsageFileWriter.instance(), Optional.empty(), ImmutableSortedSet.of(), Paths.get("pathToSrcsList"), ImmutableSortedSet.of(), fakeJavac, javacOptions, BuildTargetFactory.newInstance("//foo:bar"), Optional.empty(), sourcePathResolver, ruleFinder, fakeFilesystem, classpathChecker, Optional.empty());
    FakeProcess fakeJavacProcess = new FakeProcess(1, "javac stdout\n", "javac stderr\n");
    ExecutionContext executionContext = TestExecutionContext.newBuilder().setProcessExecutor(new FakeProcessExecutor(Functions.constant(fakeJavacProcess), new TestConsole())).build();
    BuckEventBusFactory.CapturingConsoleEventListener listener = new BuckEventBusFactory.CapturingConsoleEventListener();
    executionContext.getBuckEventBus().register(listener);
    StepExecutionResult result = step.execute(executionContext);
    // JavacStep itself writes stdout to the console on error; we expect the Build class to write
    // the stderr stream returned in the StepExecutionResult
    assertThat(result, equalTo(StepExecutionResult.of(1, Optional.of("javac stderr\n"))));
    assertThat(listener.getLogMessages(), equalTo(ImmutableList.of("javac stdout\n")));
}
Also used : BuckEventBusFactory(com.facebook.buck.event.BuckEventBusFactory) StepExecutionResult(com.facebook.buck.step.StepExecutionResult) FakeProcess(com.facebook.buck.util.FakeProcess) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Paths(java.nio.file.Paths) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 17 with Paths

use of java.nio.file.Paths in project buck by facebook.

the class JavacStepTest method existingBootclasspathDirSucceeds.

@Test
public void existingBootclasspathDirSucceeds() throws Exception {
    FakeJavac fakeJavac = new FakeJavac();
    BuildRuleResolver buildRuleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(buildRuleResolver);
    SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
    ProjectFilesystem fakeFilesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
    JavacOptions javacOptions = JavacOptions.builder().setSourceLevel("8.0").setTargetLevel("8.0").setBootclasspath("/this-totally-exists").build();
    ClasspathChecker classpathChecker = new ClasspathChecker("/", ":", Paths::get, dir -> true, file -> false, (path, glob) -> ImmutableSet.of());
    JavacStep step = new JavacStep(Paths.get("output"), NoOpClassUsageFileWriter.instance(), Optional.empty(), ImmutableSortedSet.of(), Paths.get("pathToSrcsList"), ImmutableSortedSet.of(), fakeJavac, javacOptions, BuildTargetFactory.newInstance("//foo:bar"), Optional.empty(), sourcePathResolver, ruleFinder, fakeFilesystem, classpathChecker, Optional.empty());
    FakeProcess fakeJavacProcess = new FakeProcess(0, "javac stdout\n", "javac stderr\n");
    ExecutionContext executionContext = TestExecutionContext.newBuilder().setProcessExecutor(new FakeProcessExecutor(Functions.constant(fakeJavacProcess), new TestConsole())).build();
    BuckEventBusFactory.CapturingConsoleEventListener listener = new BuckEventBusFactory.CapturingConsoleEventListener();
    executionContext.getBuckEventBus().register(listener);
    StepExecutionResult result = step.execute(executionContext);
    assertThat(result, equalTo(StepExecutionResult.SUCCESS));
    assertThat(listener.getLogMessages(), empty());
}
Also used : BuckEventBusFactory(com.facebook.buck.event.BuckEventBusFactory) StepExecutionResult(com.facebook.buck.step.StepExecutionResult) FakeProcess(com.facebook.buck.util.FakeProcess) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Paths(java.nio.file.Paths) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 18 with Paths

use of java.nio.file.Paths in project buck by facebook.

the class ExecutableFinder method getPaths.

private ImmutableSet<Path> getPaths(ImmutableMap<String, String> env) {
    ImmutableSet.Builder<Path> paths = ImmutableSet.builder();
    // Add the empty path so that when we iterate over it, we can check for the suffixed version of
    // a given path, be it absolute or not.
    paths.add(Paths.get(""));
    String pathEnv = env.get("PATH");
    if (pathEnv != null) {
        pathEnv = pathEnv.trim();
        paths.addAll(StreamSupport.stream(Splitter.on(pathSeparator).omitEmptyStrings().split(pathEnv).spliterator(), false).map(Paths::get).iterator());
    }
    if (platform == Platform.MACOS) {
        Path osXPaths = Paths.get("/etc/paths");
        if (Files.exists(osXPaths)) {
            try {
                paths.addAll(Files.readAllLines(osXPaths, Charset.defaultCharset()).stream().map(Paths::get).iterator());
            } catch (IOException e) {
                LOG.warn("Unable to read mac-specific paths. Skipping");
            }
        }
    }
    return paths.build();
}
Also used : Path(java.nio.file.Path) ImmutableSet(com.google.common.collect.ImmutableSet) Paths(java.nio.file.Paths) IOException(java.io.IOException)

Example 19 with Paths

use of java.nio.file.Paths in project lucene-solr by apache.

the class SolrDispatchFilter method authenticateRequest.

private boolean authenticateRequest(ServletRequest request, ServletResponse response, final AtomicReference<ServletRequest> wrappedRequest) throws IOException {
    boolean requestContinues = false;
    final AtomicBoolean isAuthenticated = new AtomicBoolean(false);
    AuthenticationPlugin authenticationPlugin = cores.getAuthenticationPlugin();
    if (authenticationPlugin == null) {
        return true;
    } else {
        //otherwise it's just enough to have getServletPath()
        if (PKIAuthenticationPlugin.PATH.equals(((HttpServletRequest) request).getServletPath()) || PKIAuthenticationPlugin.PATH.equals(((HttpServletRequest) request).getPathInfo()))
            return true;
        String header = ((HttpServletRequest) request).getHeader(PKIAuthenticationPlugin.HEADER);
        if (header != null && cores.getPkiAuthenticationPlugin() != null)
            authenticationPlugin = cores.getPkiAuthenticationPlugin();
        try {
            log.debug("Request to authenticate: {}, domain: {}, port: {}", request, request.getLocalName(), request.getLocalPort());
            // upon successful authentication, this should call the chain's next filter.
            requestContinues = authenticationPlugin.doAuthenticate(request, response, (req, rsp) -> {
                isAuthenticated.set(true);
                wrappedRequest.set(req);
            });
        } catch (Exception e) {
            log.info("Error authenticating", e);
            throw new SolrException(ErrorCode.SERVER_ERROR, "Error during request authentication, ", e);
        }
    }
    // multiple code paths.
    if (!requestContinues || !isAuthenticated.get()) {
        response.flushBuffer();
        return false;
    }
    return true;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Arrays(java.util.Arrays) FilterChain(javax.servlet.FilterChain) StringUtils(org.apache.commons.lang.StringUtils) ServletException(javax.servlet.ServletException) HttpServletRequestWrapper(javax.servlet.http.HttpServletRequestWrapper) LoggerFactory(org.slf4j.LoggerFactory) CoreContainer(org.apache.solr.core.CoreContainer) SolrException(org.apache.solr.common.SolrException) SolrXmlConfig(org.apache.solr.core.SolrXmlConfig) Matcher(java.util.regex.Matcher) AuthenticationPlugin(org.apache.solr.security.AuthenticationPlugin) ByteArrayInputStream(java.io.ByteArrayInputStream) CloseShieldInputStream(org.apache.commons.io.input.CloseShieldInputStream) Locale(java.util.Locale) MemoryUsageGaugeSet(com.codahale.metrics.jvm.MemoryUsageGaugeSet) NodeConfig(org.apache.solr.core.NodeConfig) Path(java.nio.file.Path) ExecutorUtil(org.apache.solr.common.util.ExecutorUtil) SolrCore(org.apache.solr.core.SolrCore) MethodHandles(java.lang.invoke.MethodHandles) Set(java.util.Set) Instant(java.time.Instant) CountDownLatch(java.util.concurrent.CountDownLatch) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) ServletResponse(javax.servlet.ServletResponse) ClassLoadingGaugeSet(com.codahale.metrics.jvm.ClassLoadingGaugeSet) HttpServletResponseWrapper(javax.servlet.http.HttpServletResponseWrapper) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) Pattern(java.util.regex.Pattern) FileCleaningTracker(org.apache.commons.io.FileCleaningTracker) OperatingSystemMetricSet(org.apache.solr.metrics.OperatingSystemMetricSet) ServletInputStream(javax.servlet.ServletInputStream) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletOutputStream(javax.servlet.ServletOutputStream) HttpClient(org.apache.http.client.HttpClient) AltBufferPoolMetricSet(org.apache.solr.metrics.AltBufferPoolMetricSet) SSLConfigurationsFactory(org.apache.solr.util.configuration.SSLConfigurationsFactory) ErrorCode(org.apache.solr.common.SolrException.ErrorCode) SolrRequestInfo(org.apache.solr.request.SolrRequestInfo) OutputStream(java.io.OutputStream) CloseShieldOutputStream(org.apache.commons.io.output.CloseShieldOutputStream) ServletRequest(javax.servlet.ServletRequest) Properties(java.util.Properties) Logger(org.slf4j.Logger) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) MetricsMap(org.apache.solr.metrics.MetricsMap) SolrFileCleaningTracker(org.apache.solr.util.SolrFileCleaningTracker) Version(org.apache.lucene.util.Version) ThreadStatesGaugeSet(com.codahale.metrics.jvm.ThreadStatesGaugeSet) UnavailableException(javax.servlet.UnavailableException) Paths(java.nio.file.Paths) SolrInfoBean(org.apache.solr.core.SolrInfoBean) FilterConfig(javax.servlet.FilterConfig) GarbageCollectorMetricSet(com.codahale.metrics.jvm.GarbageCollectorMetricSet) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) InputStream(java.io.InputStream) V2HttpCall(org.apache.solr.api.V2HttpCall) PKIAuthenticationPlugin(org.apache.solr.security.PKIAuthenticationPlugin) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AuthenticationPlugin(org.apache.solr.security.AuthenticationPlugin) PKIAuthenticationPlugin(org.apache.solr.security.PKIAuthenticationPlugin) ServletException(javax.servlet.ServletException) SolrException(org.apache.solr.common.SolrException) IOException(java.io.IOException) UnavailableException(javax.servlet.UnavailableException) SolrException(org.apache.solr.common.SolrException)

Aggregations

Paths (java.nio.file.Paths)19 Path (java.nio.file.Path)12 IOException (java.io.IOException)10 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)8 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)8 ImmutableSet (com.google.common.collect.ImmutableSet)8 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)7 ExecutionContext (com.facebook.buck.step.ExecutionContext)7 List (java.util.List)7 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)6 ImmutableList (com.google.common.collect.ImmutableList)6 ImmutableMap (com.google.common.collect.ImmutableMap)6 Optional (java.util.Optional)6 BuckEventBusFactory (com.facebook.buck.event.BuckEventBusFactory)5 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)5 SourcePath (com.facebook.buck.rules.SourcePath)5 StepExecutionResult (com.facebook.buck.step.StepExecutionResult)5 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)5 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)5 BuildTarget (com.facebook.buck.model.BuildTarget)4