1 /* 2 * Copyright (C) 2020 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.android.internal.proguard; 18 19 import androidx.room.compiler.processing.XProcessingEnv; 20 import androidx.room.compiler.processing.XProcessingStep; 21 import androidx.room.compiler.processing.javac.JavacBasicAnnotationProcessor; 22 import com.google.auto.service.AutoService; 23 import com.google.common.collect.ImmutableList; 24 import javax.annotation.processing.Processor; 25 import javax.lang.model.SourceVersion; 26 27 /** 28 * An {@linkplain Processor annotation processor} to generate dagger-android's specific proguard 29 * needs. This is only intended to run over the dagger-android project itself, as the alternative is 30 * to create an intermediary java_library for proguard rules to be consumed by the project. 31 * 32 * <p>Basic structure looks like this: 33 * 34 * <pre><code> 35 * resources/META-INF/com.android.tools/proguard/dagger-android.pro 36 * resources/META-INF/com.android.tools/r8/dagger-android.pro 37 * resources/META-INF/proguard/dagger-android.pro 38 * </code></pre> 39 */ 40 @AutoService(Processor.class) 41 public final class ProguardProcessor extends JavacBasicAnnotationProcessor { 42 private XProcessingEnv env; 43 44 @Override initialize(XProcessingEnv env)45 public void initialize(XProcessingEnv env) { 46 this.env = env; 47 } 48 49 @Override processingSteps()50 public Iterable<XProcessingStep> processingSteps() { 51 return ImmutableList.of(new ProguardProcessingStep(env)); 52 } 53 54 @Override getSupportedSourceVersion()55 public SourceVersion getSupportedSourceVersion() { 56 return SourceVersion.latestSupported(); 57 } 58 } 59