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")));
}
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());
}
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();
}
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;
}
Aggregations