| 1 |
/* |
| 2 |
* Copyright (C) 2014 The Android Open Source Project |
| 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 com.android.build.gradle.model; |
| 18 |
|
| 19 |
import static com.android.build.gradle.model.ModelConstants.IS_APPLICATION; |
| 20 |
import static com.android.build.gradle.model.ModelConstants.TASK_MANAGER; |
| 21 |
|
| 22 |
import com.android.build.gradle.AndroidConfig; |
| 23 |
import com.android.build.gradle.internal.DependencyManager; |
| 24 |
import com.android.build.gradle.internal.ExtraModelInfo; |
| 25 |
import com.android.build.gradle.internal.SdkHandler; |
| 26 |
import com.android.build.gradle.internal.TaskManager; |
| 27 |
import com.android.build.gradle.internal.ndk.NdkHandler; |
| 28 |
import com.android.build.gradle.internal.profile.ProfilerInitializer; |
| 29 |
import com.android.build.gradle.internal.variant.ApplicationVariantFactory; |
| 30 |
import com.android.build.gradle.internal.variant.VariantFactory; |
| 31 |
import com.android.builder.Version; |
| 32 |
import com.android.builder.core.AndroidBuilder; |
| 33 |
import com.android.builder.profile.ProcessRecorder; |
| 34 |
import com.google.wireless.android.sdk.stats.AndroidStudioStats; |
| 35 |
|
| 36 |
import org.gradle.api.Plugin; |
| 37 |
import org.gradle.api.Project; |
| 38 |
import org.gradle.internal.reflect.Instantiator; |
| 39 |
import org.gradle.internal.service.ServiceRegistry; |
| 40 |
import org.gradle.model.Model; |
| 41 |
import org.gradle.model.RuleSource; |
| 42 |
import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry; |
| 43 |
|
| 44 |
import android.databinding.tool.DataBindingBuilder; |
| 45 |
|
| 46 |
/** |
| 47 |
* Gradle component model plugin class for 'application' projects. |
| 48 |
*/ |
| 49 |
public class AppComponentModelPlugin implements Plugin<Project> { |
| 50 |
|
| 51 |
@Override |
| 52 |
public void apply(Project project) { |
| 53 |
ProfilerInitializer.init(project); |
| 54 |
ProcessRecorder.getProject(project.getPath()) |
| 55 |
.setAndroidPluginVersion(Version.ANDROID_GRADLE_PLUGIN_VERSION) |
| 56 |
.setAndroidPlugin( |
| 57 |
AndroidStudioStats.GradleBuildProject.PluginType.APPLICATION) |
| 58 |
.setPluginGeneration( |
| 59 |
AndroidStudioStats.GradleBuildProject.PluginGeneration.COMPONENT_MODEL); |
| 60 |
|
| 61 |
project.getPluginManager().apply(BaseComponentModelPlugin.class); |
| 62 |
|
| 63 |
project.getPluginManager().apply(AndroidComponentModelTestPlugin.class); |
| 64 |
} |
| 65 |
|
| 66 |
public static class Rules extends RuleSource { |
| 67 |
|
| 68 |
@SuppressWarnings("NonBooleanMethodNameMayNotStartWithQuestion") |
| 69 |
@Model(IS_APPLICATION) |
| 70 |
public static Boolean isApplication() { |
| 71 |
return true; |
| 72 |
} |
| 73 |
|
| 74 |
@Model(TASK_MANAGER) |
| 75 |
public static TaskManager createTaskManager( |
| 76 |
AndroidConfig androidExtension, |
| 77 |
Project project, |
| 78 |
AndroidBuilder androidBuilder, |
| 79 |
DataBindingBuilder dataBindingBuilder, |
| 80 |
SdkHandler sdkHandler, |
| 81 |
NdkHandler ndkHandler, |
| 82 |
ExtraModelInfo extraModelInfo, |
| 83 |
ToolingModelBuilderRegistry toolingRegistry) { |
| 84 |
DependencyManager dependencyManager = new DependencyManager( |
| 85 |
project, |
| 86 |
extraModelInfo, |
| 87 |
sdkHandler); |
| 88 |
|
| 89 |
return new ApplicationComponentTaskManager( |
| 90 |
project, |
| 91 |
androidBuilder, |
| 92 |
dataBindingBuilder, |
| 93 |
androidExtension, |
| 94 |
sdkHandler, |
| 95 |
ndkHandler, |
| 96 |
dependencyManager, |
| 97 |
toolingRegistry); |
| 98 |
} |
| 99 |
|
| 100 |
@Model |
| 101 |
public static VariantFactory createVariantFactory( |
| 102 |
ServiceRegistry serviceRegistry, |
| 103 |
AndroidBuilder androidBuilder, |
| 104 |
AndroidConfig extension) { |
| 105 |
Instantiator instantiator = serviceRegistry.get(Instantiator.class); |
| 106 |
return new ApplicationVariantFactory(instantiator, androidBuilder, extension); |
| 107 |
} |
| 108 |
} |
| 109 |
} |