1 /* 2 * Copyright (C) 2016 The Dagger Authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package dagger.internal.codegen; 18 19 import static com.google.common.base.StandardSystemProperty.JAVA_CLASS_PATH; 20 import static com.google.common.base.StandardSystemProperty.PATH_SEPARATOR; 21 import static com.google.testing.compile.Compiler.javac; 22 import static java.util.stream.Collectors.joining; 23 24 import com.google.auto.value.processor.AutoAnnotationProcessor; 25 import com.google.common.base.Splitter; 26 import com.google.common.collect.FluentIterable; 27 import com.google.common.collect.ImmutableList; 28 import com.google.testing.compile.Compiler; 29 import javax.annotation.processing.Processor; 30 31 /** {@link Compiler} instances for testing Dagger. */ 32 final class Compilers { 33 private static final String GUAVA = "guava"; 34 35 static final ImmutableList<String> CLASS_PATH_WITHOUT_GUAVA_OPTION = 36 ImmutableList.of( 37 "-classpath", 38 Splitter.on(PATH_SEPARATOR.value()).splitToList(JAVA_CLASS_PATH.value()).stream() 39 .filter(jar -> !jar.contains(GUAVA)) 40 .collect(joining(PATH_SEPARATOR.value()))); 41 42 /** 43 * Returns a compiler that runs the Dagger and {@code @AutoAnnotation} processors, along with 44 * extras. 45 */ daggerCompiler(Processor... extraProcessors)46 static Compiler daggerCompiler(Processor... extraProcessors) { 47 ImmutableList.Builder<Processor> processors = ImmutableList.builder(); 48 processors.add(new ComponentProcessor(), new AutoAnnotationProcessor()); 49 processors.add(extraProcessors); 50 return javac().withProcessors(processors.build()); 51 } 52 compilerWithOptions(CompilerMode... compilerModes)53 static Compiler compilerWithOptions(CompilerMode... compilerModes) { 54 FluentIterable<String> options = FluentIterable.of(); 55 for (CompilerMode compilerMode : compilerModes) { 56 options = options.append(compilerMode.javacopts()); 57 } 58 return daggerCompiler().withOptions(options); 59 } 60 } 61