use of com.intellij.openapi.roots.ModifiableRootModel in project intellij-plugins by JetBrains.
the class RubyMotionFacetConfigurator method configure.
public static void configure(VirtualFile baseDir, Module module) {
final RubyMotionFacet existingFacet = RubyMotionFacet.getInstance(module);
if (existingFacet != null) {
return;
}
FacetManager facetManager = FacetManager.getInstance(module);
final ModifiableFacetModel model = facetManager.createModifiableModel();
RubyMotionFacetType facetType = RubyMotionFacetType.getInstance();
RubyMotionFacetConfiguration configuration = ProjectFacetManager.getInstance(module.getProject()).createDefaultConfiguration(facetType);
//configuration.setProjectRootPath(baseDir.getPath());
VirtualFile testFolder = baseDir.findChild("spec");
final ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
if (testFolder != null) {
//configuration.setTestPath(testFolder.getPath());
addTestSources(testFolder, rootModel);
}
VirtualFile libFolder = baseDir.findChild("app");
if (libFolder != null) {
//configuration.setLibPath(libFolder.getPath());
}
RubyMotionFacet.updateMotionLibrary(rootModel);
IdeaInternalUtil.runInsideWriteAction(new ActionRunner.InterruptibleRunnable() {
public void run() throws Exception {
rootModel.commit();
}
});
RubyMotionFacet facet = facetManager.createFacet(facetType, facetType.getDefaultFacetName(), configuration, null);
model.addFacet(facet);
new WriteAction() {
protected void run(@NotNull final Result result) throws Throwable {
model.commit();
}
}.execute();
RubyMotionUtilExt.createMotionRunConfiguration(module);
}
use of com.intellij.openapi.roots.ModifiableRootModel in project android by JetBrains.
the class AndroidEclipseNatureImporter method doImport.
@Override
public void doImport(@NotNull Project project, @NotNull List<Module> modules) {
for (Module module : modules) {
final VirtualFile contentRoot = chooseMainContentRoot(module);
if (contentRoot == null) {
AndroidUtils.reportImportErrorToEventLog("Cannot find content root containing " + SdkConstants.FN_ANDROID_MANIFEST_XML + " file", module.getName(), project);
continue;
}
final AndroidFacet facet = AndroidUtils.addAndroidFacetInWriteAction(module, contentRoot, false);
final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
AndroidFrameworkDetector.doImportSdkAndFacetConfiguration(facet, modifiableModel);
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
modifiableModel.commit();
}
});
}
ImportDependenciesUtil.doImportDependencies(project, modules, true);
}
use of com.intellij.openapi.roots.ModifiableRootModel 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.roots.ModifiableRootModel in project android by JetBrains.
the class PostProjectBuildTasksExecutor method excludeOutputFolders.
private static void excludeOutputFolders(@NotNull AndroidFacet facet) {
AndroidModuleModel androidModel = AndroidModuleModel.get(facet);
if (androidModel == null) {
return;
}
File buildFolderPath = androidModel.getAndroidProject().getBuildFolder();
if (!buildFolderPath.isDirectory()) {
return;
}
Module module = facet.getModule();
if (module.getProject().isDisposed()) {
return;
}
ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
ModifiableRootModel rootModel = moduleRootManager.getModifiableModel();
try {
ContentEntry[] contentEntries = rootModel.getContentEntries();
ContentEntry parent = findParentContentEntry(buildFolderPath, contentEntries);
if (parent == null) {
rootModel.dispose();
return;
}
List<File> excludedFolderPaths = androidModel.getExcludedFolderPaths();
for (File folderPath : excludedFolderPaths) {
parent.addExcludeFolder(pathToIdeaUrl(folderPath));
}
} finally {
if (!rootModel.isDisposed()) {
rootModel.commit();
}
}
}
use of com.intellij.openapi.roots.ModifiableRootModel in project android by JetBrains.
the class ProjectStructureCleanupStep method cleanUpProject.
@Override
public void cleanUpProject(@NotNull Project project, @NotNull IdeModifiableModelsProvider ideModifiableModelsProvider, @Nullable ProgressIndicator indicator) {
Set<Sdk> androidSdks = new HashSet<>();
for (Module module : ideModifiableModelsProvider.getModules()) {
ModifiableRootModel rootModel = ideModifiableModelsProvider.getModifiableRootModel(module);
adjustInterModuleDependencies(module, ideModifiableModelsProvider);
Sdk sdk = rootModel.getSdk();
if (sdk != null) {
if (myAndroidSdks.isAndroidSdk(sdk)) {
androidSdks.add(sdk);
}
continue;
}
NativeAndroidProject nativeAndroidProject = getNativeAndroidProject(module);
if (nativeAndroidProject != null) {
// Native modules does not need any jdk entry.
continue;
}
Sdk jdk = IdeSdks.getInstance().getJdk();
rootModel.setSdk(jdk);
}
for (Sdk sdk : androidSdks) {
myAndroidSdks.refreshLibrariesIn(sdk);
}
}
Aggregations