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;
}
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());
}
}
}
}
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;
}
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;
}
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();
}
Aggregations