Search in sources :

Example 1 with ExtDslElement

use of com.android.tools.idea.gradle.dsl.parser.ext.ExtDslElement in project android by JetBrains.

the class GradleDslParser method getBlockElement.

private static GradlePropertiesDslElement getBlockElement(@NotNull List<String> qualifiedName, @NotNull GradlePropertiesDslElement parentElement) {
    GradlePropertiesDslElement resultElement = parentElement;
    for (String nestedElementName : qualifiedName) {
        nestedElementName = nestedElementName.trim();
        GradleDslElement element = resultElement.getPropertyElement(nestedElementName);
        if (element == null) {
            GradlePropertiesDslElement newElement;
            if (resultElement instanceof GradleDslFile || resultElement instanceof SubProjectsDslElement) {
                if (APPLY_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new ApplyDslElement(resultElement);
                } else if (EXT_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new ExtDslElement(resultElement);
                } else if (ANDROID_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new AndroidDslElement(resultElement);
                } else if (DEPENDENCIES_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new DependenciesDslElement(resultElement);
                } else if (SUBPROJECTS_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new SubProjectsDslElement(resultElement);
                } else if (BUILDSCRIPT_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new BuildScriptDslElement(resultElement);
                } else if (REPOSITORIES_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new RepositoriesDslElement(resultElement);
                } else {
                    String projectKey = ProjectPropertiesDslElement.getStandardProjectKey(nestedElementName);
                    if (projectKey != null) {
                        nestedElementName = projectKey;
                        newElement = new ProjectPropertiesDslElement(resultElement, nestedElementName);
                    } else {
                        return null;
                    }
                }
            } else if (resultElement instanceof BuildScriptDslElement) {
                if (DEPENDENCIES_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new DependenciesDslElement(resultElement);
                } else if (REPOSITORIES_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new RepositoriesDslElement(resultElement);
                } else {
                    return null;
                }
            } else if (resultElement instanceof RepositoriesDslElement) {
                if (MAVEN_BLOCK_NAME.equals(nestedElementName) || JCENTER_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new MavenRepositoryDslElement(resultElement, nestedElementName);
                } else if (FLAT_DIR_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new FlatDirRepositoryDslElement(resultElement);
                } else {
                    return null;
                }
            } else if (resultElement instanceof MavenRepositoryDslElement) {
                if (CREDENTIALS_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new MavenCredentialsDslElement(resultElement);
                } else {
                    return null;
                }
            } else if (resultElement instanceof AndroidDslElement) {
                if ("defaultConfig".equals(nestedElementName)) {
                    newElement = new ProductFlavorDslElement(resultElement, nestedElementName);
                } else if (PRODUCT_FLAVORS_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new ProductFlavorsDslElement(resultElement);
                } else if (BUILD_TYPES_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new BuildTypesDslElement(resultElement);
                } else if (COMPILE_OPTIONS_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new CompileOptionsDslElement(resultElement);
                } else if (EXTERNAL_NATIVE_BUILD_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new ExternalNativeBuildDslElement(resultElement);
                } else if (SIGNING_CONFIGS_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new SigningConfigsDslElement(resultElement);
                } else if (SOURCE_SETS_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new SourceSetsDslElement(resultElement);
                } else if (AAPT_OPTIONS_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new AaptOptionsDslElement(resultElement);
                } else if (ADB_OPTIONS_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new AdbOptionsDslElement(resultElement);
                } else if (DATA_BINDING_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new DataBindingDslElement(resultElement);
                } else if (DEX_OPTIONS_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new DexOptionsDslElement(resultElement);
                } else if (LINT_OPTIONS_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new LintOptionsDslElement(resultElement);
                } else if (PACKAGING_OPTIONS_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new PackagingOptionsDslElement(resultElement);
                } else if (SPLITS_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new SplitsDslElement(resultElement);
                } else if (TEST_OPTIONS_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new TestOptionsDslElement(resultElement);
                } else {
                    return null;
                }
            } else if (resultElement instanceof ExternalNativeBuildDslElement) {
                if (CMAKE_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new CMakeDslElement(resultElement);
                } else if (NDK_BUILD_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new NdkBuildDslElement(resultElement);
                } else {
                    return null;
                }
            } else if (resultElement instanceof ProductFlavorsDslElement) {
                newElement = new ProductFlavorDslElement(resultElement, nestedElementName);
            } else if (resultElement instanceof ProductFlavorDslElement) {
                if ("manifestPlaceholders".equals(nestedElementName) || "testInstrumentationRunnerArguments".equals(nestedElementName)) {
                    newElement = new GradleDslExpressionMap(resultElement, nestedElementName);
                } else if (EXTERNAL_NATIVE_BUILD_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new ExternalNativeBuildOptionsDslElement(resultElement);
                } else if (NDK_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new NdkOptionsDslElement(resultElement);
                } else {
                    return null;
                }
            } else if (resultElement instanceof BuildTypesDslElement) {
                newElement = new BuildTypeDslElement(resultElement, nestedElementName);
            } else if (resultElement instanceof BuildTypeDslElement && "manifestPlaceholders".equals(nestedElementName)) {
                newElement = new GradleDslExpressionMap(resultElement, nestedElementName);
            } else if (resultElement instanceof SigningConfigsDslElement) {
                newElement = new SigningConfigDslElement(resultElement, nestedElementName);
            } else if (resultElement instanceof SourceSetsDslElement) {
                newElement = new SourceSetDslElement(resultElement, nestedElementName);
            } else if (resultElement instanceof SourceSetDslElement) {
                if ("manifest".equals(nestedElementName)) {
                    newElement = new SourceFileDslElement(resultElement, nestedElementName);
                } else {
                    newElement = new SourceDirectoryDslElement(resultElement, nestedElementName);
                }
            } else if (resultElement instanceof ExternalNativeBuildOptionsDslElement) {
                if (CMAKE_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new CMakeOptionsDslElement(resultElement);
                } else if (NDK_BUILD_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new NdkBuildOptionsDslElement(resultElement);
                } else {
                    return null;
                }
            } else if (resultElement instanceof SplitsDslElement) {
                if (ABI_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new AbiDslElement(resultElement);
                } else if (DENSITY_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new DensityDslElement(resultElement);
                } else if (LANGUAGE_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new LanguageDslElement(resultElement);
                } else {
                    return null;
                }
            } else if (resultElement instanceof TestOptionsDslElement) {
                if (UNIT_TESTS_BLOCK_NAME.equals(nestedElementName)) {
                    newElement = new UnitTestsDslElement(resultElement);
                } else {
                    return null;
                }
            } else {
                return null;
            }
            resultElement.setParsedElement(nestedElementName, newElement);
            resultElement = newElement;
        } else if (element instanceof GradlePropertiesDslElement) {
            resultElement = (GradlePropertiesDslElement) element;
        } else {
            return null;
        }
    }
    return resultElement;
}
Also used : SubProjectsDslElement(com.android.tools.idea.gradle.dsl.parser.build.SubProjectsDslElement) AbiDslElement(com.android.tools.idea.gradle.dsl.parser.android.splits.AbiDslElement) UnitTestsDslElement(com.android.tools.idea.gradle.dsl.parser.android.testOptions.UnitTestsDslElement) MavenCredentialsDslElement(com.android.tools.idea.gradle.dsl.parser.repositories.MavenCredentialsDslElement) BuildScriptDslElement(com.android.tools.idea.gradle.dsl.parser.build.BuildScriptDslElement) ProjectPropertiesDslElement(com.android.tools.idea.gradle.dsl.parser.settings.ProjectPropertiesDslElement) FlatDirRepositoryDslElement(com.android.tools.idea.gradle.dsl.parser.repositories.FlatDirRepositoryDslElement) MavenRepositoryDslElement(com.android.tools.idea.gradle.dsl.parser.repositories.MavenRepositoryDslElement) ApplyDslElement(com.android.tools.idea.gradle.dsl.parser.apply.ApplyDslElement) CMakeOptionsDslElement(com.android.tools.idea.gradle.dsl.parser.android.productFlavors.externalNativeBuild.CMakeOptionsDslElement) DependenciesDslElement(com.android.tools.idea.gradle.dsl.parser.dependencies.DependenciesDslElement) NdkOptionsDslElement(com.android.tools.idea.gradle.dsl.parser.android.productFlavors.NdkOptionsDslElement) RepositoriesDslElement(com.android.tools.idea.gradle.dsl.parser.repositories.RepositoriesDslElement) SourceDirectoryDslElement(com.android.tools.idea.gradle.dsl.parser.android.sourceSets.SourceDirectoryDslElement) DensityDslElement(com.android.tools.idea.gradle.dsl.parser.android.splits.DensityDslElement) LanguageDslElement(com.android.tools.idea.gradle.dsl.parser.android.splits.LanguageDslElement) NdkBuildDslElement(com.android.tools.idea.gradle.dsl.parser.android.externalNativeBuild.NdkBuildDslElement) CMakeDslElement(com.android.tools.idea.gradle.dsl.parser.android.externalNativeBuild.CMakeDslElement) NdkBuildOptionsDslElement(com.android.tools.idea.gradle.dsl.parser.android.productFlavors.externalNativeBuild.NdkBuildOptionsDslElement) ExternalNativeBuildOptionsDslElement(com.android.tools.idea.gradle.dsl.parser.android.productFlavors.ExternalNativeBuildOptionsDslElement) ExtDslElement(com.android.tools.idea.gradle.dsl.parser.ext.ExtDslElement) SourceFileDslElement(com.android.tools.idea.gradle.dsl.parser.android.sourceSets.SourceFileDslElement)

Example 2 with ExtDslElement

use of com.android.tools.idea.gradle.dsl.parser.ext.ExtDslElement in project android by JetBrains.

the class GradleDslExpression method resolveReferenceInParentModules.

@Nullable
private static GradleDslElement resolveReferenceInParentModules(@NotNull GradleDslFile dslFile, @NotNull String referenceText) {
    GradleDslFile parentDslFile = dslFile.getParentModuleDslFile();
    while (parentDslFile != null) {
        ExtDslElement extDslElement = parentDslFile.getPropertyElement(EXT_BLOCK_NAME, ExtDslElement.class);
        if (extDslElement != null) {
            GradleDslElement extPropertyElement = extDslElement.getPropertyElement(referenceText);
            if (extPropertyElement != null) {
                return extPropertyElement;
            }
        }
        if (parentDslFile.getParentModuleDslFile() == null) {
            // resolveReferenceInSameModule method.
            return null;
        }
        GradleDslElement propertyElement = resolveReferenceInPropertiesFile(parentDslFile, referenceText);
        if (propertyElement != null) {
            return propertyElement;
        }
        parentDslFile = parentDslFile.getParentModuleDslFile();
    }
    return null;
}
Also used : ExtDslElement(com.android.tools.idea.gradle.dsl.parser.ext.ExtDslElement) GradleDslFile(com.android.tools.idea.gradle.dsl.parser.GradleDslFile) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with ExtDslElement

use of com.android.tools.idea.gradle.dsl.parser.ext.ExtDslElement in project android by JetBrains.

the class GradleBuildModel method ext.

@NotNull
public ExtModel ext() {
    ExtDslElement extDslElement = myGradleDslFile.getPropertyElement(EXT_BLOCK_NAME, ExtDslElement.class);
    if (extDslElement == null) {
        extDslElement = new ExtDslElement(myGradleDslFile);
        myGradleDslFile.setNewElement(EXT_BLOCK_NAME, extDslElement);
    }
    return new ExtModel(extDslElement);
}
Also used : ExtDslElement(com.android.tools.idea.gradle.dsl.parser.ext.ExtDslElement) ExtModel(com.android.tools.idea.gradle.dsl.model.ext.ExtModel) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with ExtDslElement

use of com.android.tools.idea.gradle.dsl.parser.ext.ExtDslElement in project android by JetBrains.

the class GradleDslExpression method resolveReferenceInSameModule.

@Nullable
private static GradleDslElement resolveReferenceInSameModule(GradleDslElement startElement, @NotNull String referenceText) {
    // Try to resolve in the build.gradle file the startElement is belongs to.
    GradleDslElement element = startElement;
    while (element != null) {
        if (element instanceof GradlePropertiesDslElement) {
            GradleDslElement propertyElement = ((GradlePropertiesDslElement) element).getPropertyElement(referenceText);
            if (propertyElement != null) {
                return propertyElement;
            }
            if (element instanceof GradleDslFile) {
                ExtDslElement extDslElement = ((GradleDslFile) element).getPropertyElement(EXT_BLOCK_NAME, ExtDslElement.class);
                if (extDslElement != null) {
                    GradleDslElement extPropertyElement = extDslElement.getPropertyElement(referenceText);
                    if (extPropertyElement != null) {
                        return extPropertyElement;
                    }
                }
                break;
            }
        }
        element = element.getParent();
    }
    // TODO: Add support to look at <GRADLE_USER_HOME>/gradle.properties before looking at this module's gradle.properties file.
    // Try to resolve in the gradle.properties file of the startElement's module.
    GradleDslFile dslFile = startElement.getDslFile();
    GradleDslElement propertyElement = resolveReferenceInPropertiesFile(dslFile, referenceText);
    if (propertyElement != null) {
        return propertyElement;
    }
    if (dslFile.getParentModuleDslFile() == null) {
        // This is the root project build.gradle file and there is no further path to look up.
        return null;
    }
    // Try to resolve in the root project gradle.properties file.
    GradleDslFile rootProjectDslFile = dslFile;
    while (true) {
        GradleDslFile parentModuleDslFile = rootProjectDslFile.getParentModuleDslFile();
        if (parentModuleDslFile == null) {
            break;
        }
        rootProjectDslFile = parentModuleDslFile;
    }
    return resolveReferenceInPropertiesFile(rootProjectDslFile, referenceText);
}
Also used : ExtDslElement(com.android.tools.idea.gradle.dsl.parser.ext.ExtDslElement) GradleDslFile(com.android.tools.idea.gradle.dsl.parser.GradleDslFile) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ExtDslElement (com.android.tools.idea.gradle.dsl.parser.ext.ExtDslElement)4 GradleDslFile (com.android.tools.idea.gradle.dsl.parser.GradleDslFile)2 Nullable (org.jetbrains.annotations.Nullable)2 ExtModel (com.android.tools.idea.gradle.dsl.model.ext.ExtModel)1 CMakeDslElement (com.android.tools.idea.gradle.dsl.parser.android.externalNativeBuild.CMakeDslElement)1 NdkBuildDslElement (com.android.tools.idea.gradle.dsl.parser.android.externalNativeBuild.NdkBuildDslElement)1 ExternalNativeBuildOptionsDslElement (com.android.tools.idea.gradle.dsl.parser.android.productFlavors.ExternalNativeBuildOptionsDslElement)1 NdkOptionsDslElement (com.android.tools.idea.gradle.dsl.parser.android.productFlavors.NdkOptionsDslElement)1 CMakeOptionsDslElement (com.android.tools.idea.gradle.dsl.parser.android.productFlavors.externalNativeBuild.CMakeOptionsDslElement)1 NdkBuildOptionsDslElement (com.android.tools.idea.gradle.dsl.parser.android.productFlavors.externalNativeBuild.NdkBuildOptionsDslElement)1 SourceDirectoryDslElement (com.android.tools.idea.gradle.dsl.parser.android.sourceSets.SourceDirectoryDslElement)1 SourceFileDslElement (com.android.tools.idea.gradle.dsl.parser.android.sourceSets.SourceFileDslElement)1 AbiDslElement (com.android.tools.idea.gradle.dsl.parser.android.splits.AbiDslElement)1 DensityDslElement (com.android.tools.idea.gradle.dsl.parser.android.splits.DensityDslElement)1 LanguageDslElement (com.android.tools.idea.gradle.dsl.parser.android.splits.LanguageDslElement)1 UnitTestsDslElement (com.android.tools.idea.gradle.dsl.parser.android.testOptions.UnitTestsDslElement)1 ApplyDslElement (com.android.tools.idea.gradle.dsl.parser.apply.ApplyDslElement)1 BuildScriptDslElement (com.android.tools.idea.gradle.dsl.parser.build.BuildScriptDslElement)1 SubProjectsDslElement (com.android.tools.idea.gradle.dsl.parser.build.SubProjectsDslElement)1 DependenciesDslElement (com.android.tools.idea.gradle.dsl.parser.dependencies.DependenciesDslElement)1