Search in sources :

Example 1 with JavaModuleModel

use of com.android.tools.idea.gradle.project.model.JavaModuleModel in project android by JetBrains.

the class DataNodeCaches method isCacheMissingModels.

private static boolean isCacheMissingModels(@NotNull DataNode<ModuleData> cache, @NotNull Module module) {
    GradleFacet gradleFacet = GradleFacet.getInstance(module);
    if (gradleFacet != null) {
        DataNode<GradleModuleModel> gradleDataNode = find(cache, GRADLE_MODULE_MODEL);
        if (gradleDataNode == null) {
            return true;
        }
        AndroidFacet androidFacet = AndroidFacet.getInstance(module);
        if (androidFacet != null) {
            DataNode<AndroidModuleModel> androidDataNode = find(cache, ANDROID_MODEL);
            if (androidDataNode == null || !isValidProxyObject(androidDataNode.getData().getAndroidProject())) {
                return true;
            }
        } else {
            JavaFacet javaFacet = JavaFacet.getInstance(module);
            if (javaFacet != null) {
                DataNode<JavaModuleModel> javaProjectDataNode = find(cache, JAVA_MODULE_MODEL);
                if (javaProjectDataNode == null) {
                    return true;
                }
            }
        }
    }
    NdkFacet ndkFacet = NdkFacet.getInstance(module);
    if (ndkFacet != null) {
        DataNode<NdkModuleModel> ndkModuleModelDataNode = find(cache, NDK_MODEL);
        if (ndkModuleModelDataNode == null || !isValidProxyObject(ndkModuleModelDataNode.getData().getAndroidProject())) {
            return true;
        }
    }
    return false;
}
Also used : GradleModuleModel(com.android.tools.idea.gradle.project.model.GradleModuleModel) JavaFacet(com.android.tools.idea.gradle.project.facet.java.JavaFacet) JavaModuleModel(com.android.tools.idea.gradle.project.model.JavaModuleModel) GradleFacet(com.android.tools.idea.gradle.project.facet.gradle.GradleFacet) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) NdkFacet(com.android.tools.idea.gradle.project.facet.ndk.NdkFacet) NdkModuleModel(com.android.tools.idea.gradle.project.model.NdkModuleModel) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 2 with JavaModuleModel

use of com.android.tools.idea.gradle.project.model.JavaModuleModel in project android by JetBrains.

the class PsJavaDependencyCollection method addDependencies.

private void addDependencies() {
    PsParsedDependencies parsedDependencies = myParent.getParsedDependencies();
    JavaModuleModel gradleModel = myParent.getGradleModel();
    for (JarLibraryDependency libraryDependency : gradleModel.getJarLibraryDependencies()) {
        GradleModuleVersion moduleVersion = libraryDependency.getModuleVersion();
        if (moduleVersion != null) {
            PsArtifactDependencySpec spec = PsArtifactDependencySpec.create(moduleVersion);
            ArtifactDependencyModel parsed = parsedDependencies.findLibraryDependency(moduleVersion);
            PsLibraryJavaDependency dependency = new PsLibraryJavaDependency(myParent, spec, libraryDependency, parsed);
            myLibraryDependenciesBySpec.put(spec.toString(), dependency);
        }
    }
}
Also used : JavaModuleModel(com.android.tools.idea.gradle.project.model.JavaModuleModel) JarLibraryDependency(com.android.tools.idea.gradle.model.java.JarLibraryDependency) PsArtifactDependencySpec(com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec) ArtifactDependencyModel(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel) PsParsedDependencies(com.android.tools.idea.gradle.structure.model.PsParsedDependencies) GradleModuleVersion(org.gradle.tooling.model.GradleModuleVersion)

Example 3 with JavaModuleModel

use of com.android.tools.idea.gradle.project.model.JavaModuleModel in project android by JetBrains.

the class ArtifactsByConfigurationModuleSetupStepTest method testDoSetUpModuleWithCompiledJar.

public void testDoSetUpModuleWithCompiledJar() throws IOException {
    Module module = getModule();
    String moduleName = module.getName();
    File buildFolderPath = createTempDir("build");
    File jarFilePath = new File(buildFolderPath, moduleName + ".jar");
    createIfDoesntExist(jarFilePath);
    Project project = getProject();
    IdeModifiableModelsProvider modelsProvider = new IdeModifiableModelsProviderImpl(project);
    Map<String, Set<File>> artifactsByConfiguration = new HashMap<>();
    artifactsByConfiguration.put("default", Collections.singleton(jarFilePath));
    JavaModuleModel model = new JavaModuleModel(moduleName, Collections.emptyList(), Collections.emptyList(), artifactsByConfiguration, null, buildFolderPath, null, true, false);
    mySetupStep.doSetUpModule(module, modelsProvider, model, null, null);
    ApplicationManager.getApplication().runWriteAction(modelsProvider::commit);
    LibraryTable libraryTable = ProjectLibraryTable.getInstance(project);
    Library[] libraries = libraryTable.getLibraries();
    assertThat(libraries).isEmpty();
    assertAbout(libraryDependencies()).that(module).isEmpty();
    // No libraries were created, nothing should be marked as "used".
    verify(myLibraryRegistry, never()).markAsUsed(any(), any());
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) JavaModuleModel(com.android.tools.idea.gradle.project.model.JavaModuleModel) IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider) Project(com.intellij.openapi.project.Project) ProjectLibraryTable(com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module) File(java.io.File)

Example 4 with JavaModuleModel

use of com.android.tools.idea.gradle.project.model.JavaModuleModel in project android by JetBrains.

the class ProjectSubset method containsSourceFile.

/**
   * Checks in the Android and Java models to see if the module contains the given file.
   *
   * @param moduleInfos represents the module that is not included yet in the IDE.
   * @param file        the given file.
   * @param selected    indicates whether the module is included in the project.
   * @return the result of the search, or {@code null} if this module does not contain the given file.
   */
@Nullable
private static ModuleSearchResult containsSourceFile(@NotNull DataNode<ModuleData> moduleInfos, @NotNull File file, boolean selected) {
    DataNode<AndroidModuleModel> androidProjectNode = find(moduleInfos, ANDROID_MODEL);
    if (androidProjectNode != null) {
        AndroidModuleModel androidModel = androidProjectNode.getData();
        SourceFileContainerInfo result = androidModel.containsSourceFile(file);
        if (result != null) {
            return new ModuleSearchResult(moduleInfos, result, selected);
        }
    }
    DataNode<JavaModuleModel> javaProjectNode = find(moduleInfos, JAVA_MODULE_MODEL);
    if (javaProjectNode != null) {
        JavaModuleModel javaModuleModel = javaProjectNode.getData();
        if (javaModuleModel.containsSourceFile(file)) {
            return new ModuleSearchResult(moduleInfos, null, selected);
        }
    }
    return null;
}
Also used : SourceFileContainerInfo(com.android.tools.idea.gradle.project.model.AndroidModuleModel.SourceFileContainerInfo) JavaModuleModel(com.android.tools.idea.gradle.project.model.JavaModuleModel) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with JavaModuleModel

use of com.android.tools.idea.gradle.project.model.JavaModuleModel in project android by JetBrains.

the class ModuleSetup method setUpJavaModule.

private void setUpJavaModule(@NotNull Module module, @NotNull SyncAction.ModuleModels models, @NotNull ProgressIndicator indicator, boolean androidProjectWithoutVariants) {
    ModuleExtendedModel javaModel = models.findModel(ModuleExtendedModel.class);
    JavaModuleModel javaModuleModel = new JavaModuleModel(models.getModule(), javaModel, androidProjectWithoutVariants);
    myJavaModuleSetup.setUpModule(module, myIdeModelsProvider, javaModuleModel, models, indicator);
}
Also used : ModuleExtendedModel(org.jetbrains.plugins.gradle.model.ModuleExtendedModel) JavaModuleModel(com.android.tools.idea.gradle.project.model.JavaModuleModel)

Aggregations

JavaModuleModel (com.android.tools.idea.gradle.project.model.JavaModuleModel)12 Module (com.intellij.openapi.module.Module)7 File (java.io.File)6 JavaFacet (com.android.tools.idea.gradle.project.facet.java.JavaFacet)4 Facets.createAndAddJavaFacet (com.android.tools.idea.testing.Facets.createAndAddJavaFacet)3 IdeModifiableModelsProvider (com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider)3 IdeModifiableModelsProviderImpl (com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl)3 Project (com.intellij.openapi.project.Project)3 HashMap (java.util.HashMap)3 Set (java.util.Set)3 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)2 Library (com.intellij.openapi.roots.libraries.Library)2 ModuleExtendedModel (org.jetbrains.plugins.gradle.model.ModuleExtendedModel)2 ArtifactDependencyModel (com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel)1 JarLibraryDependency (com.android.tools.idea.gradle.model.java.JarLibraryDependency)1 GradleFacet (com.android.tools.idea.gradle.project.facet.gradle.GradleFacet)1 NdkFacet (com.android.tools.idea.gradle.project.facet.ndk.NdkFacet)1 SourceFileContainerInfo (com.android.tools.idea.gradle.project.model.AndroidModuleModel.SourceFileContainerInfo)1 GradleModuleModel (com.android.tools.idea.gradle.project.model.GradleModuleModel)1 NdkModuleModel (com.android.tools.idea.gradle.project.model.NdkModuleModel)1