Search in sources :

Example 1 with IdeaModule

use of org.gradle.tooling.model.idea.IdeaModule in project gradle by gradle.

the class UseOtherTypesToFetchProjectModel method execute.

public Map<String, CustomModel> execute(BuildController controller) {
    // Use an IdeaModule to reference a project
    IdeaProject ideaProject = controller.getModel(IdeaProject.class);
    for (IdeaModule ideaModule : ideaProject.getModules()) {
        visit(ideaModule, controller, new HashMap<String, CustomModel>());
    }
    // Use an EclipseProject to reference a project
    EclipseProject eclipseProject = controller.getModel(EclipseProject.class);
    visit(eclipseProject, controller, new HashMap<String, CustomModel>());
    // Use a GradleProject to reference a project
    GradleProject rootProject = controller.getModel(GradleProject.class);
    Map<String, CustomModel> projects = new HashMap<String, CustomModel>();
    visit(rootProject, controller, projects);
    return projects;
}
Also used : EclipseProject(org.gradle.tooling.model.eclipse.EclipseProject) IdeaProject(org.gradle.tooling.model.idea.IdeaProject) IdeaModule(org.gradle.tooling.model.idea.IdeaModule) HashMap(java.util.HashMap) GradleProject(org.gradle.tooling.model.GradleProject) CustomModel(org.gradle.integtests.tooling.r16.CustomModel)

Example 2 with IdeaModule

use of org.gradle.tooling.model.idea.IdeaModule in project intellij-community by JetBrains.

the class GradleProjectResolver method extractExternalProjectModels.

private static void extractExternalProjectModels(@NotNull ProjectImportAction.AllModels models, @NotNull ProjectResolverContext resolverCtx) {
    resolverCtx.setModels(models);
    final Class<? extends ExternalProject> modelClazz = resolverCtx.isPreviewMode() ? ExternalProjectPreview.class : ExternalProject.class;
    final ExternalProject externalRootProject = models.getExtraProject((IdeaModule) null, modelClazz);
    if (externalRootProject == null)
        return;
    final DefaultExternalProject wrappedExternalRootProject = new DefaultExternalProject(externalRootProject);
    models.addExtraProject(wrappedExternalRootProject, ExternalProject.class);
    final Map<String, ExternalProject> externalProjectsMap = createExternalProjectsMap(null, wrappedExternalRootProject);
    DomainObjectSet<? extends IdeaModule> gradleModules = models.getIdeaProject().getModules();
    if (gradleModules != null && !gradleModules.isEmpty()) {
        for (IdeaModule ideaModule : gradleModules) {
            final ExternalProject externalProject = externalProjectsMap.get(getModuleId(resolverCtx, ideaModule));
            if (externalProject != null) {
                models.addExtraProject(externalProject, ExternalProject.class, ideaModule.getGradleProject());
            }
        }
    }
    for (IdeaProject project : models.getIncludedBuilds()) {
        DomainObjectSet<? extends IdeaModule> ideaModules = project.getModules();
        if (ideaModules.isEmpty())
            continue;
        GradleProject gradleProject = ideaModules.getAt(0).getGradleProject();
        while (gradleProject.getParent() != null) {
            gradleProject = gradleProject.getParent();
        }
        final ExternalProject externalIncludedRootProject = models.getExtraProject(gradleProject, modelClazz);
        if (externalIncludedRootProject == null)
            continue;
        final DefaultExternalProject wrappedExternalIncludedRootProject = new DefaultExternalProject(externalIncludedRootProject);
        wrappedExternalRootProject.getChildProjects().put(wrappedExternalIncludedRootProject.getName(), wrappedExternalIncludedRootProject);
        String compositePrefix = project.getName();
        final Map<String, ExternalProject> externalIncludedProjectsMap = createExternalProjectsMap(compositePrefix, wrappedExternalIncludedRootProject);
        for (IdeaModule ideaModule : ideaModules) {
            final ExternalProject externalProject = externalIncludedProjectsMap.get(getModuleId(resolverCtx, ideaModule));
            if (externalProject != null) {
                models.addExtraProject(externalProject, ExternalProject.class, ideaModule.getGradleProject());
            }
        }
    }
}
Also used : IdeaModule(org.gradle.tooling.model.idea.IdeaModule) IdeaProject(org.gradle.tooling.model.idea.IdeaProject) BasicIdeaProject(org.gradle.tooling.model.idea.BasicIdeaProject) GradleProject(org.gradle.tooling.model.GradleProject)

Example 3 with IdeaModule

use of org.gradle.tooling.model.idea.IdeaModule in project android by JetBrains.

the class JavaModuleDependency method copy.

@Nullable
public static JavaModuleDependency copy(IdeaModuleDependency original) {
    IdeaModule module = original.getDependencyModule();
    if (module != null && isNotEmpty(module.getName())) {
        String scope = null;
        IdeaDependencyScope originalScope = original.getScope();
        if (originalScope != null) {
            scope = originalScope.getScope();
        }
        return new JavaModuleDependency(module.getName(), scope, original.getExported());
    }
    return null;
}
Also used : IdeaModule(org.gradle.tooling.model.idea.IdeaModule) IdeaDependencyScope(org.gradle.tooling.model.idea.IdeaDependencyScope) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with IdeaModule

use of org.gradle.tooling.model.idea.IdeaModule in project android by JetBrains.

the class ModuleFactory method createModule.

@NotNull
Module createModule(@NotNull IdeaModule ideaModule, @NotNull SyncAction.ModuleModels moduleModels) {
    File imlFilePath = getModuleImlFilePath(ideaModule, moduleModels);
    Module newModule = myModelsProvider.newModule(imlFilePath.getPath(), StdModuleTypes.JAVA.getId());
    ModifiableRootModel rootModel = myModelsProvider.getModifiableRootModel(newModule);
    rootModel.inheritSdk();
    // Remove all dependencies.
    DependencyRemover dependencyRemover = new DependencyRemover(rootModel);
    for (OrderEntry orderEntry : rootModel.getOrderEntries()) {
        orderEntry.accept(dependencyRemover, null);
    }
    // Remove all facets.
    ModifiableFacetModel facetModel = myModelsProvider.getModifiableFacetModel(newModule);
    for (Facet facet : facetModel.getAllFacets()) {
        facetModel.removeFacet(facet);
    }
    return newModule;
}
Also used : ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) IdeaModule(org.gradle.tooling.model.idea.IdeaModule) Module(com.intellij.openapi.module.Module) File(java.io.File) Facet(com.intellij.facet.Facet) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with IdeaModule

use of org.gradle.tooling.model.idea.IdeaModule in project android by JetBrains.

the class ProjectSetupImplTest method SetUpProjectWithAndroidModule.

// Test fails in build server, but not locally.
public void SetUpProjectWithAndroidModule() throws Exception {
    // Obtain models for 'simpleApplication' from Gradle.
    prepareProjectForImport(SIMPLE_APPLICATION);
    Project project = getProject();
    // Sync with Gradle.
    NewGradleSync gradleSync = new NewGradleSync();
    CountDownLatch latch = new CountDownLatch(1);
    NewGradleSync.Callback sync = gradleSync.sync(project);
    sync.doWhenRejected(() -> {
        latch.countDown();
        Throwable error = sync.getSyncError();
        if (error != null) {
            rethrowAllAsUnchecked(error);
        }
        throw new RuntimeException("Sync failed");
    });
    sync.doWhenDone(latch::countDown);
    if (!sync.isProcessed()) {
        latch.await();
    }
    SyncAction.ProjectModels projectModels = sync.getModels();
    assertNotNull("Gradle models", projectModels);
    Map<String, IdeaModule> moduleModelsByName = getModuleModelsByName(projectModels);
    // 2 modules: root and "app"
    assertThat(moduleModelsByName).hasSize(2);
    // Simulate ModuleFactory create root module from Gradle models.
    Module rootModule = simulateModelCreation(projectModels, moduleModelsByName.get(project.getName()));
    // Simulate ModuleFactory create "app" module from Gradle models.
    Module appModule = simulateModelCreation(projectModels, moduleModelsByName.get("app"));
    Module[] modules = { rootModule, appModule };
    when(myModelsProvider.getModules()).thenReturn(modules);
    // Add AndroidFacet and AndroidGradleModel to "app" module, to ensure that the validator gets invoked.
    AndroidModuleModel appAndroidModel = mock(AndroidModuleModel.class);
    AndroidFacet appAndroidFacet = createAndAddAndroidFacet(appModule);
    appAndroidFacet.setAndroidModel(appAndroidModel);
    // This happens before AndroidModuleValidator gets invoked. AndroidFacet and AndroidGradleModel need to be set in the module to
    // participate in validation.
    simulateAndroidFacetLookup(rootModule, null);
    simulateAndroidFacetLookup(appModule, appAndroidFacet);
    myProjectSetup.setUpProject(projectModels, myProgressIndicator);
    verify(myModuleSetup).setUpModule(rootModule, projectModels.getModels(":"), myProgressIndicator);
    verify(myModuleSetup).setUpModule(appModule, projectModels.getModels(":app"), myProgressIndicator);
    verify(myAndroidModuleValidator).validate(appModule, appAndroidModel);
    verify(myAndroidModuleValidator).fixAndReportFoundIssues();
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) Facets.createAndAddAndroidFacet(com.android.tools.idea.testing.Facets.createAndAddAndroidFacet) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Project(com.intellij.openapi.project.Project) IdeaModule(org.gradle.tooling.model.idea.IdeaModule) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) IdeaModule(org.gradle.tooling.model.idea.IdeaModule) Module(com.intellij.openapi.module.Module)

Aggregations

IdeaModule (org.gradle.tooling.model.idea.IdeaModule)15 IdeaProject (org.gradle.tooling.model.idea.IdeaProject)5 DataNode (com.intellij.openapi.externalSystem.model.DataNode)4 Module (com.intellij.openapi.module.Module)4 File (java.io.File)4 BasicIdeaProject (org.gradle.tooling.model.idea.BasicIdeaProject)4 NotNull (org.jetbrains.annotations.NotNull)4 GradleProject (org.gradle.tooling.model.GradleProject)3 Test (org.junit.Test)3 JavaProjectData (com.intellij.externalSystem.JavaProjectData)2 Project (com.intellij.openapi.project.Project)2 BuildEnvironment (org.gradle.tooling.model.build.BuildEnvironment)2 Nullable (org.jetbrains.annotations.Nullable)2 GradleSourceSetData (org.jetbrains.plugins.gradle.model.data.GradleSourceSetData)2 GradleBuildParticipant (org.jetbrains.plugins.gradle.settings.GradleBuildParticipant)2 ImportedModule (com.android.tools.idea.gradle.ImportedModule)1 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 Facets.createAndAddAndroidFacet (com.android.tools.idea.testing.Facets.createAndAddAndroidFacet)1 ParametersList (com.intellij.execution.configurations.ParametersList)1 Facet (com.intellij.facet.Facet)1