com.intellij.ide.util.importProject.ModuleDescriptor Java Examples

The following examples show how to use com.intellij.ide.util.importProject.ModuleDescriptor. 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: ProjectFromSourcesBuilderImplModified.java    From tmc-intellij with MIT License 6 votes vote down vote up
private static Module createModule(
        ProjectDescriptor projectDescriptor,
        final ModuleDescriptor descriptor,
        final Map<LibraryDescriptor, Library> projectLibs,
        final ModifiableModuleModel moduleModel) {

    logger.info("Starting createModule in ProjectFromSourcesBuilderImplModified");
    final String moduleFilePath = descriptor.computeModuleFilePath();
    ModuleBuilder.deleteModuleFile(moduleFilePath);

    final Module module =
            moduleModel.newModule(moduleFilePath, descriptor.getModuleType().getId());
    final ModifiableRootModel modifiableModel =
            ModuleRootManager.getInstance(module).getModifiableModel();
    setupRootModel(projectDescriptor, descriptor, modifiableModel, projectLibs);
    descriptor.updateModuleConfiguration(module, modifiableModel);
    modifiableModel.commit();
    logger.info("ending createModule in ProjectFromSourcesBuilderImplModified");
    return module;
}
 
Example #2
Source File: FlutterProjectStructureDetector.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void setupProjectStructure(@NotNull Collection<DetectedProjectRoot> roots,
                                  @NotNull ProjectDescriptor projectDescriptor,
                                  @NotNull ProjectFromSourcesBuilder builder) {
  final List<ModuleDescriptor> modules = new ArrayList<>();
  for (DetectedProjectRoot root : roots) {
    modules.add(new ModuleDescriptor(root.getDirectory(), FlutterModuleUtils.getFlutterModuleType(), Collections.emptyList()));
  }

  projectDescriptor.setModules(modules);
  builder.setupModulesByContentRoots(projectDescriptor, roots);
}
 
Example #3
Source File: FlutterProjectStructureDetector.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void setupProjectStructure(@NotNull Collection<DetectedProjectRoot> roots,
                                  @NotNull ProjectDescriptor projectDescriptor,
                                  @NotNull ProjectFromSourcesBuilder builder) {
  final List<ModuleDescriptor> modules = new ArrayList<>();
  for (DetectedProjectRoot root : roots) {
    modules.add(new ModuleDescriptor(root.getDirectory(), FlutterModuleUtils.getFlutterModuleType(), Collections.emptyList()));
  }

  projectDescriptor.setModules(modules);
  builder.setupModulesByContentRoots(projectDescriptor, roots);
}
 
Example #4
Source File: JavaProjectDescriptor.java    From tmc-intellij with MIT License 5 votes vote down vote up
/**
 * Creates ProjectDescriptor so project can be build from it's info.
 *
 * @param path project root dir
 * @param ignoredNames ie. compile output path
 * @return ProjectDescriptor
 */
public static ProjectDescriptor create(String path, Set<String> ignoredNames) {
    logger.info("Starting to create Project Descriptor in JavaProjectDescriptor.");

    logger.info("Initializing ProjectDescriptor");
    File contentFile = new File(path);
    ProjectDescriptor projectDescriptor = new ProjectDescriptor();
    List<ModuleDescriptor> moduleList = new ArrayList<>();
    List<LibraryDescriptor> libraryList = new ArrayList<>();
    projectDescriptor.setModules(moduleList);
    projectDescriptor.setLibraries(libraryList);

    logger.info("Searching for source files");
    //test file is considered as source file at this point
    Collection<JavaModuleSourceRoot> suggestedRoots =
            JavaSourceRootDetectionUtil.suggestRoots(contentFile);

    List<JavaModuleSourceRoot> rootList = new ArrayList<>();
    rootList.addAll(suggestedRoots);

    //Module insight creates module and library descriptors collecting data as long as roots are listed.
    ModuleInsight insight = new JavaModuleInsight(null, new HashSet<>(), new HashSet<>());
    List<File> entryPointRoots = new ArrayList<>();
    entryPointRoots.add(contentFile);

    logger.info("Setting up ModuleInsight roots");
    insight.setRoots(entryPointRoots, rootList, ignoredNames);

    logger.info("ModuleInsight scanning for modules and libraries");
    insight.scanLibraries();
    insight.scanModules();

    logger.info("Adding moduleDescriptors and LibraryDescriptors to projectDescriptor");
    libraryList.addAll(insight.getSuggestedLibraries());

    moduleList.addAll(insight.getSuggestedModules());

    logger.info("Ending to create Project Descriptor in JavaProjectDescriptor.");
    return projectDescriptor;
}
 
Example #5
Source File: HaxeModuleInsight.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@Override
public void scanModules() {
  File root = new File(myBuilder.getContext().getProjectFileDirectory());
  ModuleDescriptor descriptor = createModuleDescriptor(root, this.getSourceRootsToScan());
  List<ModuleDescriptor> list = new ArrayList<>();
  list.add(descriptor);
  addModules(list);
}
 
Example #6
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 #7
Source File: HaxeModuleInsight.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
@Override
protected ModuleDescriptor createModuleDescriptor(File moduleContentRoot, Collection<DetectedSourceRoot> sourceRoots) {
  return new ModuleDescriptor(moduleContentRoot, HaxeModuleType.getInstance(), sourceRoots);
}