/* * Copyright (C) 2013 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.tools.idea.jps.builder; import com.android.SdkConstants; import com.android.tools.idea.jps.AndroidGradleJps; import com.android.tools.idea.jps.model.JpsAndroidGradleModuleExtension; import com.google.common.collect.ImmutableList; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.jps.ModuleChunk; import org.jetbrains.jps.android.AndroidSourceGeneratingBuilder; import org.jetbrains.jps.builders.DirtyFilesHolder; import org.jetbrains.jps.builders.java.JavaSourceRootDescriptor; import org.jetbrains.jps.incremental.BuilderCategory; import org.jetbrains.jps.incremental.CompileContext; import org.jetbrains.jps.incremental.ModuleBuildTarget; import org.jetbrains.jps.incremental.ModuleLevelBuilder; import org.jetbrains.jps.incremental.java.JavaBuilder; import org.jetbrains.jps.incremental.resources.ResourcesBuilder; import org.jetbrains.jps.incremental.resources.StandardResourceBuilderEnabler; import org.jetbrains.jps.model.JpsProject; import org.jetbrains.jps.model.module.JpsModule; import java.util.List; /** * The only purpose of this builder is to disable all instances of {@link ModuleLevelBuilder} that are not related to Gradle. */ public class AndroidGradleBuilder extends ModuleLevelBuilder { @NonNls private static final String BUILDER_NAME = "Android Gradle Builder"; protected AndroidGradleBuilder() { super(BuilderCategory.TRANSLATOR); ResourcesBuilder.registerEnabler(new StandardResourceBuilderEnabler() { @Override public boolean isResourceProcessingEnabled(JpsModule module) { JpsProject project = module.getProject(); return !AndroidGradleJps.hasAndroidGradleFacet(project); } }); } /** * Disables IDEA's Java and Android builders for Gradle-imported projects. They are no longer needed since we build with Gradle. */ @Override public void buildStarted(CompileContext context) { JpsProject project = context.getProjectDescriptor().getProject(); if (AndroidGradleJps.hasAndroidGradleFacet(project)) { JavaBuilder.IS_ENABLED.set(context, false); AndroidSourceGeneratingBuilder.IS_ENABLED.set(context, false); } } /** * It does nothing. * * @return {@link ExitCode#OK} if the modules to build are Gradle ones, otherwise it returns {@link ExitCode#NOTHING_DONE}. */ @NotNull @Override public ExitCode build(CompileContext context, ModuleChunk chunk, DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder, OutputConsumer outputConsumer) { JpsAndroidGradleModuleExtension extension = AndroidGradleJps.getFirstExtension(chunk); if (extension == null) { return ExitCode.NOTHING_DONE; } return ExitCode.OK; } @NotNull @Override public String getPresentableName() { return BUILDER_NAME; } @NotNull @Override public List<String> getCompilableFileExtensions() { return ImmutableList.of(SdkConstants.EXT_AIDL, SdkConstants.EXT_FS, SdkConstants.EXT_JAVA, SdkConstants.EXT_RS); } }