Search in sources :

Example 1 with GradleDslExpressionMap

use of com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpressionMap in project android by JetBrains.

the class GradleBuildModel method applyPlugin.

@NotNull
public GradleBuildModel applyPlugin(@NotNull String plugin) {
    if (getValues(appliedPlugins()).contains(plugin.trim())) {
        return this;
    }
    GradleDslExpressionMap applyMap = new GradleDslExpressionMap(myGradleDslFile, APPLY_BLOCK_NAME);
    applyMap.addNewLiteral(PLUGIN, plugin.trim());
    myToBeAppliedPlugins.add(applyMap);
    return this;
}
Also used : GradleDslExpressionMap(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpressionMap) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with GradleDslExpressionMap

use of com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpressionMap in project android by JetBrains.

the class DependencyConfigurationModel method excludes.

@NotNull
public List<ExcludedDependencyModel> excludes() {
    GradleDslElementList elementList = myConfigurationElement.getPropertyElement(EXCLUDE, GradleDslElementList.class);
    if (elementList == null) {
        return ImmutableList.of();
    }
    List<ExcludedDependencyModel> excludedDependencies = new ArrayList<>();
    for (GradleDslExpressionMap excludeElement : elementList.getElements(GradleDslExpressionMap.class)) {
        excludedDependencies.add(new ExcludedDependencyModel(excludeElement));
    }
    return excludedDependencies;
}
Also used : GradleDslElementList(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElementList) GradleDslExpressionMap(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpressionMap) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with GradleDslExpressionMap

use of com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpressionMap in project android by JetBrains.

the class GradleBuildModel method appliedPlugins.

@NotNull
public List<GradleNotNullValue<String>> appliedPlugins() {
    ApplyDslElement applyDslElement = myGradleDslFile.getPropertyElement(APPLY_BLOCK_NAME, ApplyDslElement.class);
    if (applyDslElement == null) {
        return ImmutableList.of();
    }
    List<GradleNotNullValue<String>> listProperty = applyDslElement.getListProperty(PLUGIN, String.class);
    if (listProperty == null) {
        return ImmutableList.of();
    }
    List<GradleNotNullValue<String>> plugins = new ArrayList<>();
    Set<String> pluginValues = new HashSet<>();
    for (GradleNotNullValue<String> plugin : listProperty) {
        if (pluginValues.add(plugin.value())) {
            // Avoid duplicate plugin entries.
            plugins.add(plugin);
        }
    }
    for (GradleDslExpressionMap toBeAppliedPlugin : myToBeAppliedPlugins) {
        GradleNullableValue<String> plugin = toBeAppliedPlugin.getLiteralProperty(PLUGIN, String.class);
        assert plugin instanceof GradleNotNullValue;
        if (pluginValues.add(plugin.value())) {
            // Avoid duplicate plugin entries.
            plugins.add((GradleNotNullValue<String>) plugin);
        }
    }
    return plugins;
}
Also used : GradleDslExpressionMap(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpressionMap) ApplyDslElement(com.android.tools.idea.gradle.dsl.parser.apply.ApplyDslElement) ArrayList(java.util.ArrayList) GradleNotNullValue(com.android.tools.idea.gradle.dsl.model.values.GradleNotNullValue) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with GradleDslExpressionMap

use of com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpressionMap in project android by JetBrains.

the class GradleBuildModel method removePlugin.

@NotNull
public GradleBuildModel removePlugin(@NotNull String plugin) {
    plugin = plugin.trim();
    ApplyDslElement applyDslElement = myGradleDslFile.getPropertyElement(APPLY_BLOCK_NAME, ApplyDslElement.class);
    if (applyDslElement == null) {
        return this;
    }
    List<GradleDslExpressionMap> toBeRemovedPlugins = new ArrayList<>();
    for (GradleDslExpressionMap applyMap : myToBeAppliedPlugins) {
        if (plugin.equals(applyMap.getLiteralProperty(PLUGIN, String.class).value())) {
            toBeRemovedPlugins.add(applyMap);
        }
    }
    myToBeAppliedPlugins.removeAll(toBeRemovedPlugins);
    while (getValues(applyDslElement.getListProperty(PLUGIN, String.class)).contains(plugin)) {
        applyDslElement.removeFromExpressionList(PLUGIN, plugin);
    }
    return this;
}
Also used : GradleDslExpressionMap(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpressionMap) ApplyDslElement(com.android.tools.idea.gradle.dsl.parser.apply.ApplyDslElement) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with GradleDslExpressionMap

use of com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpressionMap in project android by JetBrains.

the class GradleBuildModel method applyChanges.

@Override
public void applyChanges() {
    // needs to be added.
    for (GradleDslExpressionMap applyMap : myToBeAppliedPlugins) {
        applyMap.create();
        applyMap.applyChanges();
        myGradleDslFile.addParsedElement(APPLY_BLOCK_NAME, applyMap);
    }
    myToBeAppliedPlugins.clear();
    super.applyChanges();
}
Also used : GradleDslExpressionMap(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpressionMap)

Aggregations

GradleDslExpressionMap (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpressionMap)6 NotNull (org.jetbrains.annotations.NotNull)4 ArrayList (java.util.ArrayList)3 ApplyDslElement (com.android.tools.idea.gradle.dsl.parser.apply.ApplyDslElement)2 GradleNotNullValue (com.android.tools.idea.gradle.dsl.model.values.GradleNotNullValue)1 GradleDslElement (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElement)1 GradleDslElementList (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElementList)1 GradleDslExpression (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpression)1 GradleDslExpressionList (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpressionList)1 HashSet (com.intellij.util.containers.HashSet)1 Map (java.util.Map)1