use of com.intellij.openapi.roots.ModifiableRootModel in project intellij-plugins by JetBrains.
the class Flexmojos3GenerateConfigTask method updateMainClass.
public static void updateMainClass(final Module module, final VirtualFile configFile) {
// Project Structure open
if (FlexBuildConfigurationsExtension.getInstance().getConfigurator().getConfigEditor() != null)
return;
try {
final String mainClassPath = FlexUtils.findXMLElement(configFile.getInputStream(), "<flex-config><file-specs><path-element>");
final VirtualFile mainClassFile = mainClassPath == null ? null : LocalFileSystem.getInstance().findFileByPath(mainClassPath);
if (mainClassFile == null || mainClassFile.isDirectory())
return;
final VirtualFile sourceRoot = ProjectRootManager.getInstance(module.getProject()).getFileIndex().getSourceRootForFile(mainClassFile);
final String relativePath = sourceRoot == null ? null : VfsUtilCore.getRelativePath(mainClassFile, sourceRoot, '/');
final String mainClass = relativePath == null ? mainClassFile.getNameWithoutExtension() : FileUtil.getNameWithoutExtension(relativePath).replace('/', '.');
final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
final LibraryTable.ModifiableModel librariesModel = ProjectLibraryTable.getInstance(module.getProject()).getModifiableModel();
final FlexProjectConfigurationEditor flexEditor = FlexProjectConfigurationEditor.createEditor(module.getProject(), Collections.singletonMap(module, modifiableModel), librariesModel, null);
final ModifiableFlexBuildConfiguration[] bcs = flexEditor.getConfigurations(module);
final ModifiableFlexBuildConfiguration mainBC = ContainerUtil.find(bcs, bc -> bc.getOutputType() == OutputType.Application && module.getName().equals(bc.getName()));
if (mainBC != null) {
mainBC.setMainClass(mainClass);
}
flexEditor.commit();
Disposer.dispose(librariesModel);
modifiableModel.dispose();
} catch (IOException ignore) {
/**/
} catch (ConfigurationException ignore) {
/**/
}
}
use of com.intellij.openapi.roots.ModifiableRootModel in project intellij-plugins by JetBrains.
the class FlashBuilderImporter method commit.
public List<Module> commit(final Project project, final ModifiableModuleModel model, final ModulesProvider modulesProvider, final ModifiableArtifactModel artifactModel) {
//FlexModuleBuilder.setupResourceFilePatterns(project);
final boolean needToCommit = model == null;
final ModifiableModuleModel moduleModel = model != null ? model : ModuleManager.getInstance(project).getModifiableModel();
final List<String> paths = getList();
final boolean isArchive = paths.size() == 1 && FlashBuilderProjectFinder.hasArchiveExtension(paths.get(0));
final List<String> dotProjectPaths = getDotProjectPaths(project);
final List<FlashBuilderProject> flashBuilderProjects = FlashBuilderProjectLoadUtil.loadProjects(dotProjectPaths, isArchive);
final Map<FlashBuilderProject, ModifiableRootModel> flashBuilderProjectToModifiableModelMap = new THashMap<>();
final Map<Module, ModifiableRootModel> moduleToModifiableModelMap = new THashMap<>();
final Set<String> moduleNames = new THashSet<>(flashBuilderProjects.size());
final FlexProjectConfigurationEditor currentFlexEditor = FlexBuildConfigurationsExtension.getInstance().getConfigurator().getConfigEditor();
assert needToCommit == (currentFlexEditor == null);
for (FlashBuilderProject flashBuilderProject : flashBuilderProjects) {
final String moduleName = makeUnique(flashBuilderProject.getName(), moduleNames);
moduleNames.add(moduleName);
final String moduleFilePath = flashBuilderProject.getProjectRootPath() + "/" + moduleName + ModuleFileType.DOT_DEFAULT_EXTENSION;
if (LocalFileSystem.getInstance().findFileByPath(moduleFilePath) != null) {
ApplicationManager.getApplication().runWriteAction(() -> ModuleBuilder.deleteModuleFile(moduleFilePath));
}
final Module module = moduleModel.newModule(moduleFilePath, FlexModuleType.getInstance().getId());
final ModifiableRootModel rootModel = currentFlexEditor != null ? currentFlexEditor.getModifiableRootModel(module) : ModuleRootManager.getInstance(module).getModifiableModel();
flashBuilderProjectToModifiableModelMap.put(flashBuilderProject, rootModel);
moduleToModifiableModelMap.put(module, rootModel);
}
final FlexProjectConfigurationEditor flexConfigEditor = currentFlexEditor != null ? currentFlexEditor : FlexProjectConfigurationEditor.createEditor(project, moduleToModifiableModelMap, null, null);
final FlashBuilderSdkFinder sdkFinder = new FlashBuilderSdkFinder(project, getParameters().myInitiallySelectedPath, flashBuilderProjects);
final FlashBuilderModuleImporter flashBuilderModuleImporter = new FlashBuilderModuleImporter(project, flexConfigEditor, flashBuilderProjects, sdkFinder);
for (final FlashBuilderProject flashBuilderProject : flashBuilderProjects) {
flashBuilderModuleImporter.setupModule(flashBuilderProjectToModifiableModelMap.get(flashBuilderProject), flashBuilderProject);
}
if (needToCommit) {
try {
flexConfigEditor.commit();
} catch (ConfigurationException e) {
Logger.getInstance(FlashBuilderImporter.class).error(e);
}
ApplicationManager.getApplication().runWriteAction(() -> {
ModifiableModelCommitter.multiCommit(moduleToModifiableModelMap.values(), moduleModel);
});
}
return new ArrayList<>(moduleToModifiableModelMap.keySet());
}
use of com.intellij.openapi.roots.ModifiableRootModel in project android by JetBrains.
the class CompilerOutputModuleSetupStep method doSetUpModule.
@Override
protected void doSetUpModule(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModelsProvider, @NotNull JavaModuleModel javaModuleModel, @Nullable SyncAction.ModuleModels gradleModels, @Nullable ProgressIndicator indicator) {
File mainClassesFolder = null;
File testClassesFolder = null;
ExtIdeaCompilerOutput compilerOutput = javaModuleModel.getCompilerOutput();
if (compilerOutput == null) {
File buildFolderPath = javaModuleModel.getBuildFolderPath();
if (buildFolderPath != null) {
mainClassesFolder = new File(buildFolderPath, join(CLASSES_FOLDER_NAME, "main"));
testClassesFolder = new File(buildFolderPath, join(CLASSES_FOLDER_NAME, "test"));
}
} else {
mainClassesFolder = compilerOutput.getMainClassesDir();
testClassesFolder = compilerOutput.getTestClassesDir();
}
if (mainClassesFolder != null) {
// This folder is null for modules that are just folders containing other modules. This type of modules are later on removed by
// PostProjectSyncTaskExecutor.
ModifiableRootModel moduleModel = ideModelsProvider.getModifiableRootModel(module);
myCompilerSettingsSetup.setOutputPaths(moduleModel, mainClassesFolder, testClassesFolder);
}
}
use of com.intellij.openapi.roots.ModifiableRootModel in project android by JetBrains.
the class ContentRootsModuleSetupStep method doSetUpModule.
@Override
protected void doSetUpModule(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModelsProvider, @NotNull JavaModuleModel javaModuleModel, @Nullable SyncAction.ModuleModels gradleModels, @Nullable ProgressIndicator indicator) {
ModifiableRootModel moduleModel = ideModelsProvider.getModifiableRootModel(module);
JavaContentEntriesSetup setup = new JavaContentEntriesSetup(javaModuleModel, moduleModel);
List<ContentEntry> contentEntries = findContentEntries(moduleModel, javaModuleModel);
setup.execute(contentEntries);
}
use of com.intellij.openapi.roots.ModifiableRootModel in project android by JetBrains.
the class DependenciesModuleSetupStep method updateDependency.
private static void updateDependency(@NotNull Module module, @NotNull IdeModifiableModelsProvider modelsProvider, @NotNull JavaModuleDependency dependency) {
DependencySetupErrors setupErrors = DependencySetupErrors.getInstance(module.getProject());
String moduleName = dependency.getModuleName();
Module found = null;
for (Module m : modelsProvider.getModules()) {
if (moduleName.equals(m.getName())) {
found = m;
}
}
ModifiableRootModel moduleModel = modelsProvider.getModifiableRootModel(module);
if (found != null) {
AndroidFacet androidFacet = findFacet(found, modelsProvider, AndroidFacet.ID);
if (androidFacet == null) {
ModuleOrderEntry entry = moduleModel.addModuleOrderEntry(found);
entry.setExported(true);
} else {
// If it depends on an android module, we should skip that.
setupErrors.addInvalidModuleDependency(moduleModel.getModule(), found.getName(), "Java modules cannot depend on Android modules");
}
return;
}
setupErrors.addMissingModule(moduleName, module.getName(), null);
}
Aggregations