public void testSimpleJavaLibrary() throws Exception { Path buildFilePath = scratch.file( "com/google/example/BUILD", "java_library(", " name = 'simple',", " srcs = ['simple/Simple.java']", ")"); Map<String, RuleIdeInfo> ruleIdeInfos = buildRuleIdeInfo("//com/google/example:simple"); assertThat(ruleIdeInfos.size()).isEqualTo(1); RuleIdeInfo ruleIdeInfo = getRuleInfoAndVerifyLabel("//com/google/example:simple", ruleIdeInfos); assertThat(ruleIdeInfo.getBuildFile()).isEqualTo(buildFilePath.toString()); assertThat(ruleIdeInfo.getKind()).isEqualTo(Kind.JAVA_LIBRARY); assertThat(ruleIdeInfo.getDependenciesCount()).isEqualTo(0); assertThat(relativePathsForSourcesOf(ruleIdeInfo)) .containsExactly("com/google/example/simple/Simple.java"); assertThat( transform(ruleIdeInfo.getJavaRuleIdeInfo().getJarsList(), LIBRARY_ARTIFACT_TO_STRING)) .containsExactly( jarString( "com/google/example", "libsimple.jar", "libsimple-ijar.jar", "libsimple-src.jar")); assertThat(getIdeResolveFiles()) .containsExactly( "com/google/example/libsimple.jar", "com/google/example/libsimple-ijar.jar", "com/google/example/libsimple-src.jar"); }
/** * Generates a command line to run for the test action, taking into account coverage and {@code * --run_under} settings. * * @param testScript the setup script that invokes the test * @param coverageScript a script interjected between setup script and rest of command line to * collect coverage data. If this is an empty string, it is ignored. * @param testAction The test action. * @return the command line as string list. */ protected List<String> getArgs( String testScript, String coverageScript, TestRunnerAction testAction) { List<String> args = Lists.newArrayList(); if (OS.getCurrent() == OS.WINDOWS) { args.add(testAction.getShExecutable().getPathString()); args.add("-c"); args.add("$0 $*"); } args.add(testScript); TestTargetExecutionSettings execSettings = testAction.getExecutionSettings(); List<String> execArgs = new ArrayList<>(); if (!coverageScript.isEmpty() && isCoverageMode(testAction)) { execArgs.add(coverageScript); } // Execute the test using the alias in the runfiles tree, as mandated by // the Test Encyclopedia. execArgs.add(execSettings.getExecutable().getRootRelativePath().getPathString()); execArgs.addAll(execSettings.getArgs()); // Insert the command prefix specified by the "--run_under=<command-prefix>" option, // if any. if (execSettings.getRunUnder() == null) { args.addAll(execArgs); } else if (execSettings.getRunUnderExecutable() != null) { args.add(execSettings.getRunUnderExecutable().getRootRelativePath().getPathString()); args.addAll(execSettings.getRunUnder().getOptions()); args.addAll(execArgs); } else { args.add(testAction.getConfiguration().getShellExecutable().getPathString()); args.add("-c"); String runUnderCommand = ShellEscaper.escapeString(execSettings.getRunUnder().getCommand()); Path fullySpecified = SearchPath.which( SearchPath.parse( testAction.getTestLog().getPath().getFileSystem(), clientEnv.get("PATH")), runUnderCommand); if (fullySpecified != null) { runUnderCommand = fullySpecified.toString(); } args.add( runUnderCommand + ' ' + ShellEscaper.escapeJoinAll( Iterables.concat(execSettings.getRunUnder().getOptions(), execArgs))); } return args; }
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); RemoteWorkResponse.Builder workResponse = RemoteWorkResponse.newBuilder(); // TODO(alpha): Choose a better temp directory name. Path tempRoot = workPath.getRelative("build-" + UUID.randomUUID().toString()); FileSystemUtils.createDirectoryAndParents(tempRoot); boolean deleteTree = true; try { String workJson = CharStreams.toString(request.getReader()); RemoteWorkRequest.Builder workRequest = RemoteWorkRequest.newBuilder(); JsonFormat.parser().merge(workJson, workRequest); RemoteWorkRequest work = workRequest.build(); final MemcacheActionCache actionCache = new MemcacheActionCache(tempRoot, remoteOptions, cache); final MemcacheWorkExecutor workExecutor = new MemcacheWorkExecutor(actionCache, executorService, tempRoot); if (options.debug) { System.out.println( "[INFO] Work received has " + work.getInputFilesCount() + " inputs files and " + work.getOutputFilesCount() + " output files."); } RemoteWorkExecutor.Response executorResponse = workExecutor.submit(work).get(); if (options.debug) { if (!executorResponse.success()) { deleteTree = false; System.out.println("[WARNING] Work failed."); System.out.println(workJson); } else { System.out.println("[INFO] Work completed."); } } workResponse .setSuccess(executorResponse.success()) .setOut(executorResponse.getOut()) .setErr(executorResponse.getErr()); } catch (Exception e) { workResponse.setSuccess(false).setOut("").setErr("").setException(e.toString()); } finally { if (deleteTree) { FileSystemUtils.deleteTree(tempRoot); } else { System.out.println("[WARNING] Preserving work directory " + tempRoot.toString() + "."); } response.setStatus(HttpServletResponse.SC_OK); response.getWriter().print(JsonFormat.printer().print(workResponse.build())); } }
@Override public void executeSynchronously( RemoteWorkRequest request, StreamObserver<RemoteWorkResponse> responseObserver) { Path tempRoot = workPath.getRelative("build-" + UUID.randomUUID().toString()); try { FileSystemUtils.createDirectoryAndParents(tempRoot); final ConcurrentMapActionCache actionCache = new ConcurrentMapActionCache(tempRoot, cache); final MemcacheWorkExecutor workExecutor = MemcacheWorkExecutor.createLocalWorkExecutor(actionCache, tempRoot); if (LOG_FINER) { LOG.fine( "Work received has " + request.getInputFilesCount() + " input files and " + request.getOutputFilesCount() + " output files."); } RemoteWorkResponse response = workExecutor.executeLocally(request); responseObserver.onNext(response); if (options.debug) { if (!response.getSuccess()) { LOG.warning("Work failed. Request: " + request.toString() + "."); } else if (LOG_FINER) { LOG.fine("Work completed."); } } if (!options.debug || response.getSuccess()) { FileSystemUtils.deleteTree(tempRoot); } else { LOG.warning("Preserving work directory " + tempRoot.toString() + "."); } } catch (IOException | InterruptedException e) { RemoteWorkResponse.Builder response = RemoteWorkResponse.newBuilder(); response.setSuccess(false).setOut("").setErr("").setException(e.toString()); responseObserver.onNext(response.build()); if (e instanceof InterruptedException) { Thread.currentThread().interrupt(); } } finally { responseObserver.onCompleted(); } }