/** * Constructs a build from a list of command args. Sets the same JavacRunner for both compilation * and annotation processing. * * @param optionsParser the parsed command line args. * @param extraPlugins extraneous plugins to use in addition to the strict dependency module. * @param depsBuilder a preconstructed dependency module builder. * @throws InvalidCommandLineException on any command line error */ public JavaLibraryBuildRequest( OptionsParser optionsParser, List<BlazeJavaCompilerPlugin> extraPlugins, DependencyModule.Builder depsBuilder) throws InvalidCommandLineException, IOException { depsBuilder.addDirectMappings(optionsParser.getDirectMappings()); depsBuilder.addIndirectMappings(optionsParser.getIndirectMappings()); if (optionsParser.getStrictJavaDeps() != null) { depsBuilder.setStrictJavaDeps(optionsParser.getStrictJavaDeps()); } if (optionsParser.getOutputDepsProtoFile() != null) { depsBuilder.setOutputDepsProtoFile(optionsParser.getOutputDepsProtoFile()); } depsBuilder.addDepsArtifacts(optionsParser.getDepsArtifacts()); if (optionsParser.reduceClasspath()) { depsBuilder.setReduceClasspath(); } if (optionsParser.getRuleKind() != null) { depsBuilder.setRuleKind(optionsParser.getRuleKind()); } if (optionsParser.getTargetLabel() != null) { depsBuilder.setTargetLabel(optionsParser.getTargetLabel()); } this.dependencyModule = depsBuilder.build(); AnnotationProcessingModule.Builder processingBuilder = AnnotationProcessingModule.builder(); if (optionsParser.getSourceGenDir() != null) { processingBuilder.setSourceGenDir(Paths.get(optionsParser.getSourceGenDir())); } if (optionsParser.getManifestProtoPath() != null) { processingBuilder.setManifestProtoPath(Paths.get(optionsParser.getManifestProtoPath())); } processingBuilder.addAllSourceRoots(optionsParser.getSourceRoots()); this.processingModule = processingBuilder.build(); ImmutableList.Builder<BlazeJavaCompilerPlugin> pluginsBuilder = ImmutableList.<BlazeJavaCompilerPlugin>builder().add(dependencyModule.getPlugin()); processingModule.registerPlugin(pluginsBuilder); pluginsBuilder.addAll(extraPlugins); this.plugins = pluginsBuilder.build(); this.compressJar = optionsParser.compressJar(); this.sourceFiles = optionsParser.getSourceFiles(); this.sourceJars = ImmutableList.copyOf(optionsParser.getSourceJars()); this.messageFiles = ImmutableList.copyOf(optionsParser.getMessageFiles()); this.resourceFiles = ImmutableList.copyOf(optionsParser.getResourceFiles()); this.resourceJars = ImmutableList.copyOf(optionsParser.getResourceJars()); this.rootResourceFiles = ImmutableList.copyOf(optionsParser.getRootResourceFiles()); this.classPath = optionsParser.getClassPath(); this.extdir = optionsParser.getExtdir(); this.processorPath = optionsParser.getProcessorPath(); this.processorNames = optionsParser.getProcessorNames(); // Since the default behavior of this tool with no arguments is "rm -fr <classDir>", let's not // default to ".", shall we? if (optionsParser.getClassDir() != null) { this.classDir = optionsParser.getClassDir(); } else { this.classDir = "classes"; } if (optionsParser.getTempDir() != null) { this.tempDir = optionsParser.getTempDir(); } else { this.tempDir = "_tmp"; } this.outputJar = optionsParser.getOutputJar(); ImmutableList.Builder<AbstractPostProcessor> postProcessors = ImmutableList.builder(); for (Entry<String, List<String>> entry : optionsParser.getPostProcessors().entrySet()) { postProcessors.add(AbstractPostProcessor.create(entry.getKey(), entry.getValue())); } this.postProcessors = postProcessors.build(); this.javacOpts = ImmutableList.copyOf(optionsParser.getJavacOpts()); this.sourceGenDir = optionsParser.getSourceGenDir(); this.generatedSourcesOutputJar = optionsParser.getGeneratedSourcesOutputJar(); this.generatedClassOutputJar = optionsParser.getManifestProtoPath(); }