Java Code Examples for com.intellij.openapi.roots.ContentEntry#addSourceFolder()

The following examples show how to use com.intellij.openapi.roots.ContentEntry#addSourceFolder() . 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: OCamlModuleBuilder.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
@Override
public void setupRootModel(@NotNull ModifiableRootModel rootModel) {
    rootModel.inheritSdk();

    ContentEntry contentEntry = doAddContentEntry(rootModel);
    if (contentEntry != null) {
        List<Pair<String, String>> sourcePaths = getSourcePaths();

        if (sourcePaths != null) {
            for (final Pair<String, String> sourcePath : sourcePaths) {
                String first = sourcePath.first;
                boolean created = new File(first).mkdirs();
                if (created) {
                    VirtualFile sourceRoot = LocalFileSystem.getInstance().refreshAndFindFileByPath(FileUtil.toSystemIndependentName(first));
                    if (sourceRoot != null) {
                        contentEntry.addSourceFolder(sourceRoot, false, sourcePath.second);
                    }
                }
            }
        }
    }
}
 
Example 2
Source File: ArmaModuleBuilder.java    From arma-intellij-plugin with MIT License 6 votes vote down vote up
@Override
public void setupRootModel(ModifiableRootModel rootModel) throws ConfigurationException {
	ContentEntry contentEntry = doAddContentEntry(rootModel);
	if (contentEntry != null) {
		final List<Pair<String, String>> sourcePaths = getSourcePaths();

		if (sourcePaths != null) {
			for (final Pair<String, String> sourcePath : sourcePaths) {
				String first = sourcePath.first;
				new File(first).mkdirs();
				final VirtualFile sourceRoot = LocalFileSystem.getInstance().refreshAndFindFileByPath(FileUtil.toSystemIndependentName(first));
				if (sourceRoot != null) {
					contentEntry.addSourceFolder(sourceRoot, false, sourcePath.second);
				}
			}
		}
	}
}
 
Example 3
Source File: JavaSourceFolderProvider.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Override
public SourceFolder setSourceFolderForLocation(
    ContentEntry contentEntry, SourceFolder parentFolder, File file, boolean isTestSource) {
  SourceFolder sourceFolder;
  if (isResource(parentFolder)) {
    JavaResourceRootType resourceRootType =
        isTestSource ? JavaResourceRootType.TEST_RESOURCE : JavaResourceRootType.RESOURCE;
    sourceFolder =
        contentEntry.addSourceFolder(UrlUtil.pathToUrl(file.getPath()), resourceRootType);
  } else {
    sourceFolder = contentEntry.addSourceFolder(UrlUtil.pathToUrl(file.getPath()), isTestSource);
  }
  sourceFolder.setPackagePrefix(derivePackagePrefix(file, parentFolder));
  JpsModuleSourceRoot sourceRoot = sourceFolder.getJpsElement();
  JpsElement properties = sourceRoot.getProperties();
  if (properties instanceof JavaSourceRootProperties) {
    ((JavaSourceRootProperties) properties).setForGeneratedSources(isGenerated(parentFolder));
  }
  return sourceFolder;
}
 
Example 4
Source File: ArmaModuleBuilder.java    From arma-intellij-plugin with MIT License 6 votes vote down vote up
@Override
public void setupRootModel(ModifiableRootModel rootModel) throws ConfigurationException {
	ContentEntry contentEntry = doAddContentEntry(rootModel);
	if (contentEntry != null) {
		final List<Pair<String, String>> sourcePaths = getSourcePaths();

		if (sourcePaths != null) {
			for (final Pair<String, String> sourcePath : sourcePaths) {
				String first = sourcePath.first;
				new File(first).mkdirs();
				final VirtualFile sourceRoot = LocalFileSystem.getInstance().refreshAndFindFileByPath(FileUtil.toSystemIndependentName(first));
				if (sourceRoot != null) {
					contentEntry.addSourceFolder(sourceRoot, false, sourcePath.second);
				}
			}
		}
	}
}
 
Example 5
Source File: JavaSourceFolderProvider.java    From intellij with Apache License 2.0 5 votes vote down vote up
private static SourceFolder addSourceFolderToContentEntry(
    ContentEntry contentEntry, BlazeSourceDirectory sourceDirectory) {
  File sourceDir = sourceDirectory.getDirectory();

  // Create the source folder
  SourceFolder sourceFolder;
  if (sourceDirectory.isResource()) {
    sourceFolder =
        contentEntry.addSourceFolder(
            UrlUtil.pathToUrl(sourceDir.getPath()), JavaResourceRootType.RESOURCE);
  } else {
    sourceFolder = contentEntry.addSourceFolder(UrlUtil.pathToUrl(sourceDir.getPath()), false);
  }
  JpsModuleSourceRoot sourceRoot = sourceFolder.getJpsElement();
  JpsElement properties = sourceRoot.getProperties();
  if (properties instanceof JavaSourceRootProperties) {
    JavaSourceRootProperties rootProperties = (JavaSourceRootProperties) properties;
    if (sourceDirectory.isGenerated()) {
      rootProperties.setForGeneratedSources(true);
    }
  }
  String packagePrefix = sourceDirectory.getPackagePrefix();
  if (!Strings.isNullOrEmpty(packagePrefix)) {
    sourceFolder.setPackagePrefix(packagePrefix);
  }
  return sourceFolder;
}
 
Example 6
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 7
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 8
Source File: GenericSourceFolderProvider.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Override
public SourceFolder setSourceFolderForLocation(
    ContentEntry contentEntry, SourceFolder parentFolder, File file, boolean isTestSource) {
  return contentEntry.addSourceFolder(UrlUtil.fileToIdeaUrl(file), isTestSource);
}