Java Code Examples for com.intellij.openapi.roots.ModifiableRootModel#addContentEntry()

The following examples show how to use com.intellij.openapi.roots.ModifiableRootModel#addContentEntry() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpringBootModuleBuilder.java    From crud-intellij-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public void setupRootModel(ModifiableRootModel rootModel) throws ConfigurationException {
	Selection selection = SelectionContext.copyToSelection();
	if (this.myJdk != null) {
		rootModel.setSdk(this.myJdk);
	} else {
		rootModel.inheritSdk();
	}
	SelectionContext.clearAllSet();
	Project project = rootModel.getProject();
	VirtualFile root = createAndGetContentEntry();
	rootModel.addContentEntry(root);
	CrudUtils.runWhenInitialized(project, () -> new WriteCommandAction<VirtualFile>(project) {
		@Override
		protected void run(@NotNull Result<VirtualFile> result) throws Throwable {
			initProject(project, selection);
		}
	}.execute());
}
 
Example 2
Source File: DubboPluginModuleBuilder.java    From intellij-idea-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public void setupRootModel(ModifiableRootModel rootModel) throws ConfigurationException {

    String s = new Gson().toJson(userChooseDependency);
    System.out.println("set up root model json is:" + s);
    Project project = rootModel.getProject();
    VirtualFile root = createAndGetContentEntry();
    rootModel.addContentEntry(root);
    if (myJdk != null) {
        rootModel.setSdk(myJdk);
    } else {
        rootModel.inheritSdk();
    }
    System.out.println("start to create folder in path");


}
 
Example 3
Source File: MuleMavenModuleBuilder.java    From mule-intellij-plugins with Apache License 2.0 6 votes vote down vote up
@Override
public void setupRootModel(ModifiableRootModel rootModel) throws ConfigurationException {
    super.setupRootModel(rootModel);

    addListener(new ModuleBuilderListener() {
        @Override
        public void moduleCreated(@NotNull Module module) {
            setMuleFramework(module);
        }
    });

    setMuleFacet(rootModel.getModule());

    final Project project = rootModel.getProject();
    final VirtualFile root = createAndGetContentEntry();
    rootModel.addContentEntry(root);

    //Check if this is a module and has parent
    final MavenId parentId = (this.getParentProject() != null ? this.getParentProject().getMavenId() : null);

    MavenUtil.runWhenInitialized(project, (DumbAwareRunnable) () -> {
        new MuleMavenProjectBuilderHelper().configure(project, getProjectId(), muleVersion, root, parentId);
    });
}
 
Example 4
Source File: SlingMavenModuleBuilder.java    From aem-ide-tooling-4-intellij with Apache License 2.0 6 votes vote down vote up
public void setupRootModel(ModifiableRootModel rootModel) {
    final Project project = rootModel.getProject();

    final VirtualFile root = createAndGetContentEntry();
    rootModel.addContentEntry(root);

    // todo this should be moved to generic ModuleBuilder
    if (myJdk != null){
        rootModel.setSdk(myJdk);
    } else {
        rootModel.inheritSdk();
    }

    MavenUtil.runWhenInitialized(
        project, new DumbAwareRunnable() {
        public void run() {
            if (myEnvironmentForm != null) {
                myEnvironmentForm.setData(MavenProjectsManager.getInstance(project).getGeneralSettings());
            }

            new MavenModuleBuilderHelper(myProjectId, myAggregatorProject, myParentProject, myInheritGroupId,
                myInheritVersion, archetypeTemplate.getMavenArchetype(), myPropertiesToCreateByArtifact, "Create new Sling Maven module").configure(project, root, false);
            }
        }
    );
}
 
Example 5
Source File: RPiJavaModuleBuilder.java    From embeddedlinux-jvmdebugger-intellij with Apache License 2.0 6 votes vote down vote up
/**
 * Used to define the hierachy of the project definition
 *
 * @param rootModel
 * @throws ConfigurationException
 */
@Override
public void setupRootModel(final ModifiableRootModel rootModel) throws ConfigurationException {
    super.setupRootModel(rootModel);

    final Project project = rootModel.getProject();

    final VirtualFile root = createAndGetContentEntry();
    rootModel.addContentEntry(root);

    if (myJdk != null) {
        rootModel.setSdk(myJdk);
    } else {
        rootModel.inheritSdk();
    }

    createProjectFiles(rootModel, project);

}
 
Example 6
Source File: AsposeMavenModuleBuilder.java    From Aspose.OCR-for-Java with MIT License 6 votes vote down vote up
@Override
public void setupRootModel(ModifiableRootModel rootModel) throws com.intellij.openapi.options.ConfigurationException {

    final Project project = rootModel.getProject();
    setMyProject(rootModel.getProject());
    final VirtualFile root = createAndGetContentEntry();
    rootModel.addContentEntry(root);

    rootModel.inheritSdk();

    RunnableHelper.runWhenInitialized(getMyProject(), new Runnable() {
        public void run() {

            AsposeMavenModuleBuilderHelper mavenBuilder = new AsposeMavenModuleBuilderHelper(getMyProjectId(), "Create new Maven module", project, root);
            mavenBuilder.configure();

        }
    });

}
 
Example 7
Source File: NutzBootModuleBuilder.java    From NutzCodeInsight with Apache License 2.0 5 votes vote down vote up
@Override
public void setupRootModel(ModifiableRootModel rootModel) throws ConfigurationException {
    VirtualFile root = createAndGetContentEntry();
    rootModel.addContentEntry(root);
    if (myJdk != null) {
        rootModel.setSdk(myJdk);
    } else {
        rootModel.inheritSdk();
    }
    System.out.println("start to create folder in path");
}
 
Example 8
Source File: MuleDomainMavenModuleBuilder.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public void setupRootModel(ModifiableRootModel rootModel) throws ConfigurationException {
    super.setupRootModel(rootModel);

    setMuleFacet(rootModel.getModule());

    final Project project = rootModel.getProject();
    final VirtualFile root = createAndGetContentEntry();
    rootModel.addContentEntry(root);
    MavenUtil.runWhenInitialized(project, (DumbAwareRunnable) () -> new MuleDomainMavenProjectBuilderHelper().configure(project, getProjectId(), muleVersion, root));
}
 
Example 9
Source File: ResourceModuleContentRootCustomizer.java    From intellij with Apache License 2.0 5 votes vote down vote up
private static void setupSampleDataContentRoot(
    @NotNull ModifiableRootModel model, @NotNull SourceFolder resSourceFolder) {
  VirtualFile resFolder = resSourceFolder.getFile();
  if (resFolder == null) {
    return;
  }

  VirtualFile sampleDataDirectory =
      BlazeSampleDataDirectoryProvider.getSampleDataDirectoryForResFolder(resFolder);
  if (sampleDataDirectory != null && sampleDataDirectory.exists()) {
    model.addContentEntry(sampleDataDirectory);
  }
}
 
Example 10
Source File: ProjectUpdateSyncTask.java    From intellij with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a module that includes the user's data directory.
 *
 * <p>This is useful to be able to edit the project view without IntelliJ complaining it's outside
 * the project.
 */
private void createProjectDataDirectoryModule(
    ModuleEditor moduleEditor, File projectDataDirectory, ModuleType moduleType) {
  Module module = moduleEditor.createModule(".project-data-dir", moduleType);
  ModifiableRootModel modifiableModel = moduleEditor.editModule(module);
  ContentEntry rootContentEntry =
      modifiableModel.addContentEntry(pathToUrl(projectDataDirectory));
  rootContentEntry.addExcludeFolder(pathToUrl(new File(projectDataDirectory, ".idea")));
  rootContentEntry.addExcludeFolder(
      pathToUrl(BlazeDataStorage.getProjectDataDir(importSettings)));
}
 
Example 11
Source File: GaugeLibHelper.java    From Intellij-Plugin with Apache License 2.0 5 votes vote down vote up
private void checkProjectSourceAndOutputDirectory(ModifiableRootModel modifiableModel) {
    VirtualFile[] sourceRoots = modifiableModel.getSourceRoots();
    if (sourceRoots.length < 1) {
        ContentEntry contentEntry = modifiableModel.addContentEntry(modifiableModel.getProject().getBaseDir());
        VirtualFile srcPath = srcPath(modifiableModel);
        if (srcPath != null) {
            contentEntry.addSourceFolder(srcPath, false);
        }
        CompilerModuleExtension compilerModuleExtension = modifiableModel.getModuleExtension(CompilerModuleExtension.class);
        compilerModuleExtension.setCompilerOutputPath(outputPath(modifiableModel.getModule()));
        compilerModuleExtension.setCompilerOutputPathForTests(testOutputPath(modifiableModel.getModule()));
        compilerModuleExtension.inheritCompilerOutputPath(false);
        compilerModuleExtension.commit();
    }
}
 
Example 12
Source File: ContentRootDataService.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static ContentEntry findOrCreateContentRoot(@Nonnull ModifiableRootModel model, @Nonnull String path) {
  ContentEntry[] entries = model.getContentEntries();

  for (ContentEntry entry : entries) {
    VirtualFile file = entry.getFile();
    if (file == null) {
      continue;
    }
    if (ExternalSystemApiUtil.getLocalFileSystemPath(file).equals(path)) {
      return entry;
    }
  }
  return model.addContentEntry(toVfsUrl(path));
}
 
Example 13
Source File: SandModuleImportProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Override
public void process(@Nonnull ModuleImportContext context, @Nonnull Project project, @Nonnull ModifiableModuleModel model, @Nonnull Consumer<Module> newModuleConsumer) {
  String path = context.getPath();

  Module module = model.newModule(context.getName(), path);

  ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
  modifiableModel.addContentEntry(VfsUtil.pathToUrl(path));
  WriteAction.runAndWait(modifiableModel::commit);

  newModuleConsumer.accept(module);
}
 
Example 14
Source File: ProjectFromSourcesBuilderImplModified.java    From tmc-intellij with MIT License 4 votes vote down vote up
private static void setupRootModel(
        ProjectDescriptor projectDescriptor,
        final ModuleDescriptor descriptor,
        final ModifiableRootModel rootModel,
        final Map<LibraryDescriptor, Library> projectLibs) {
    final CompilerModuleExtension compilerModuleExtension =
            rootModel.getModuleExtension(CompilerModuleExtension.class);
    compilerModuleExtension.setExcludeOutput(true);
    rootModel.inheritSdk();

    //Module root model seems to store .iml files root dependencies. (src, test, lib)
    logger.info("Starting setupRootModel in ProjectFromSourcesBuilderImplModified");
    final Set<File> contentRoots = descriptor.getContentRoots();
    for (File contentRoot : contentRoots) {
        final LocalFileSystem lfs = LocalFileSystem.getInstance();
        VirtualFile moduleContentRoot =
                lfs.refreshAndFindFileByPath(
                        FileUtil.toSystemIndependentName(contentRoot.getPath()));
        if (moduleContentRoot != null) {
            final ContentEntry contentEntry = rootModel.addContentEntry(moduleContentRoot);
            final Collection<DetectedSourceRoot> sourceRoots =
                    descriptor.getSourceRoots(contentRoot);
            for (DetectedSourceRoot srcRoot : sourceRoots) {
                final String srcpath =
                        FileUtil.toSystemIndependentName(srcRoot.getDirectory().getPath());
                final VirtualFile sourceRoot = lfs.refreshAndFindFileByPath(srcpath);
                if (sourceRoot != null) {
                    contentEntry.addSourceFolder(
                            sourceRoot,
                            shouldBeTestRoot(srcRoot.getDirectory()),
                            getPackagePrefix(srcRoot));
                }
            }
        }
    }
    logger.info("Inherits compiler output path from project");
    compilerModuleExtension.inheritCompilerOutputPath(true);

    logger.info("Starting to create module level libraries");
    final LibraryTable moduleLibraryTable = rootModel.getModuleLibraryTable();
    for (LibraryDescriptor libDescriptor :
            ModuleInsight.getLibraryDependencies(
                    descriptor, projectDescriptor.getLibraries())) {
        final Library projectLib = projectLibs.get(libDescriptor);
        if (projectLib != null) {
            rootModel.addLibraryEntry(projectLib);
        } else {
            // add as module library
            final Collection<File> jars = libDescriptor.getJars();
            for (File file : jars) {
                Library library = moduleLibraryTable.createLibrary();
                Library.ModifiableModel modifiableModel = library.getModifiableModel();
                modifiableModel.addRoot(
                        VfsUtil.getUrlForLibraryRoot(file), OrderRootType.CLASSES);
                modifiableModel.commit();
            }
        }
    }
    logger.info("Ending setupRootModel in ProjectFromSourcesBuilderImplModified");
}
 
Example 15
Source File: ContentEntryEditor.java    From intellij with Apache License 2.0 4 votes vote down vote up
public static void createContentEntries(
    Project project,
    WorkspaceRoot workspaceRoot,
    ProjectViewSet projectViewSet,
    BlazeProjectData blazeProjectData,
    DirectoryStructure rootDirectoryStructure,
    ModifiableRootModel modifiableRootModel) {
  ImportRoots importRoots =
      ImportRoots.builder(workspaceRoot, Blaze.getBuildSystem(project))
          .add(projectViewSet)
          .build();
  Collection<WorkspacePath> rootDirectories = importRoots.rootDirectories();
  Collection<WorkspacePath> excludeDirectories = importRoots.excludeDirectories();
  Multimap<WorkspacePath, WorkspacePath> excludesByRootDirectory =
      sortExcludesByRootDirectory(rootDirectories, excludeDirectories);

  SourceTestConfig testConfig = new SourceTestConfig(projectViewSet);
  SourceFolderProvider provider = SourceFolderProvider.getSourceFolderProvider(blazeProjectData);

  for (WorkspacePath rootDirectory : rootDirectories) {
    File rootFile = workspaceRoot.fileForPath(rootDirectory);
    ContentEntry contentEntry =
        modifiableRootModel.addContentEntry(UrlUtil.pathToUrl(rootFile.getPath()));

    for (WorkspacePath exclude : excludesByRootDirectory.get(rootDirectory)) {
      File excludeFolder = workspaceRoot.fileForPath(exclude);
      contentEntry.addExcludeFolder(UrlUtil.fileToIdeaUrl(excludeFolder));
    }

    ImmutableMap<File, SourceFolder> sourceFolders =
        provider.initializeSourceFolders(contentEntry);
    SourceFolder rootSource = sourceFolders.get(rootFile);
    walkFileSystem(
        workspaceRoot,
        testConfig,
        excludesByRootDirectory.get(rootDirectory),
        contentEntry,
        provider,
        sourceFolders,
        rootSource,
        rootDirectory,
        rootDirectoryStructure.directories.get(rootDirectory));
  }
}