use of com.intellij.openapi.module.ModuleManager in project android by JetBrains.
the class AndroidGradleProjectComponent method trackLegacyIdeaAndroidProject.
private void trackLegacyIdeaAndroidProject() {
if (!UsageTracker.getInstance().getAnalyticsSettings().hasOptedIn()) {
return;
}
StartupManager.getInstance(myProject).runWhenProjectIsInitialized(() -> {
String packageName = null;
ModuleManager moduleManager = ModuleManager.getInstance(myProject);
for (Module module : moduleManager.getModules()) {
AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet != null && !facet.requiresAndroidModel()) {
if (facet.isAppProject()) {
// Prefer the package name from an app module.
packageName = getPackageNameInLegacyIdeaAndroidModule(facet);
if (packageName != null) {
break;
}
} else if (packageName == null) {
String modulePackageName = getPackageNameInLegacyIdeaAndroidModule(facet);
if (modulePackageName != null) {
packageName = modulePackageName;
}
}
}
if (packageName != null) {
AndroidStudioEvent.Builder event = AndroidStudioEvent.newBuilder().setCategory(EventCategory.GRADLE).setKind(EventKind.LEGACY_IDEA_ANDROID_PROJECT).setProjectId(anonymizeUtf8(packageName));
UsageTracker.getInstance().log(event);
}
}
});
}
use of com.intellij.openapi.module.ModuleManager in project android by JetBrains.
the class AndroidProjectStructureConfigurable method reset.
@Override
public void reset() {
// Need this to ensure VFS operations will not block because of storage flushing and other maintenance IO tasks run in background.
AccessToken token = HeavyProcessLatch.INSTANCE.processStarted("Resetting project structure");
try {
for (Configurable configurable : myConfigurables) {
configurable.reset();
}
if (myUiInitialized) {
validateState();
// Prepare module entries but don't add them until after developer services
ModuleManager moduleManager = ModuleManager.getInstance(myProject);
Module[] modules = moduleManager.getModules();
Arrays.sort(modules, ModuleTypeComparator.INSTANCE);
List<AndroidModuleConfigurable> moduleConfigurables = Lists.newArrayList();
for (Module module : modules) {
AndroidModuleConfigurable configurable = addModule(module);
if (configurable != null) {
moduleConfigurables.add(configurable);
}
}
// Populate the "Developer Services" section
removeServices();
if (Projects.isBuildWithGradle(myProject)) {
DefaultComboBoxModel moduleList = new DefaultComboBoxModel();
for (AndroidModuleConfigurable moduleConfigurable : moduleConfigurables) {
// Collect only Android modules
if (AndroidFacet.getInstance(moduleConfigurable.getModule()) != null) {
moduleList.addElement(moduleConfigurable.getModule());
}
}
if (!myProject.isDefault() && moduleList.getSize() > 0) {
// into that event.
for (int i = 0; i < moduleList.getSize(); i++) {
Module module = (Module) moduleList.getElementAt(i);
for (DeveloperService service : DeveloperServices.getAll(module)) {
service.getContext().restore();
}
}
Module module = (Module) moduleList.getSelectedItem();
Set<ServiceCategory> categories = Sets.newHashSet();
for (DeveloperService s : DeveloperServices.getAll(module)) {
if (!s.getContext().hiddenFromStructureDialog().get()) {
categories.add(s.getCategory());
}
}
ArrayList<ServiceCategory> categoriesSorted = Lists.newArrayList(categories);
Collections.sort(categoriesSorted);
for (ServiceCategory category : categoriesSorted) {
myConfigurables.add(new ServiceCategoryConfigurable(moduleList, category));
}
}
}
// Populate the "Modules" section.
removeModules();
Module toSelect = null;
for (Module module : modules) {
AndroidModuleConfigurable configurable = addModule(module);
if (configurable != null) {
myConfigurables.add(configurable);
if (configurable.getDisplayName().equals(myUiState.lastSelectedConfigurable)) {
toSelect = module;
}
}
}
if (myUiState.proportion > 0) {
mySplitter.setProportion(myUiState.proportion);
}
mySidePanel.reset();
if (toSelect != null) {
mySidePanel.select(toSelect);
} else {
mySidePanel.selectSdk();
}
}
} finally {
token.finish();
}
}
use of com.intellij.openapi.module.ModuleManager in project android by JetBrains.
the class AndroidApkFacet method getInstance.
@Nullable
public static AndroidApkFacet getInstance(@NotNull Project project) {
ModuleManager moduleManager = ModuleManager.getInstance(project);
// Only 1 module existed for Apk project
Module[] modules = moduleManager.getModules();
if (modules.length == 1) {
return getInstance(modules[0]);
}
return null;
}
use of com.intellij.openapi.module.ModuleManager in project android by JetBrains.
the class NewProjectImportGradleSyncListener method createTopLevelModule.
@VisibleForTesting
public static void createTopLevelModule(@NotNull Project project) {
ModuleManager moduleManager = ModuleManager.getInstance(project);
File projectRootDir = getBaseDirPath(project);
VirtualFile contentRoot = findFileByIoFile(projectRootDir, true);
if (contentRoot != null) {
File moduleFile = new File(projectRootDir, projectRootDir.getName() + ".iml");
Module module = moduleManager.newModule(moduleFile.getPath(), JAVA.getId());
// This prevents the balloon "Unsupported Modules detected".
ExternalSystemModulePropertyManager.getInstance(module).setExternalId(GRADLE_SYSTEM_ID);
ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
model.addContentEntry(contentRoot);
if (IdeInfo.getInstance().isAndroidStudio()) {
// If sync fails, make sure that the project has a JDK, otherwise Groovy indices won't work (a common scenario where
// users will update build.gradle files to fix Gradle sync.)
// See: https://code.google.com/p/android/issues/detail?id=194621
Sdk jdk = IdeSdks.getInstance().getJdk();
if (jdk != null) {
model.setSdk(jdk);
}
}
model.commit();
FacetManager facetManager = FacetManager.getInstance(module);
ModifiableFacetModel facetModel = facetManager.createModifiableModel();
try {
GradleFacet gradleFacet = GradleFacet.getInstance(module);
if (gradleFacet == null) {
// Add "gradle" facet, to avoid balloons about unsupported compilation of modules.
gradleFacet = facetManager.createFacet(GradleFacet.getFacetType(), GradleFacet.getFacetName(), null);
facetModel.addFacet(gradleFacet);
}
gradleFacet.getConfiguration().GRADLE_PROJECT_PATH = GRADLE_PATH_SEPARATOR;
// Add "android" facet to avoid the balloon "Android Framework detected".
AndroidFacet androidFacet = AndroidFacet.getInstance(module);
if (androidFacet == null) {
androidFacet = facetManager.createFacet(AndroidFacet.getFacetType(), AndroidFacet.NAME, null);
facetModel.addFacet(androidFacet);
}
// This is what actually stops Studio from showing the balloon.
androidFacet.getProperties().ALLOW_USER_CONFIGURATION = false;
} finally {
facetModel.commit();
}
}
}
use of com.intellij.openapi.module.ModuleManager in project android by JetBrains.
the class GradleBuildInvoker method rebuild.
public void rebuild() {
BuildMode buildMode = REBUILD;
setProjectBuildMode(buildMode);
ModuleManager moduleManager = ModuleManager.getInstance(myProject);
List<String> tasks = findTasksToExecute(moduleManager.getModules(), buildMode, TestCompileType.NONE);
executeTasks(tasks);
}
Aggregations