use of org.jetbrains.jps.model.java.JavaSourceRootProperties in project intellij-community by JetBrains.
the class JpsContentEntry method addSourceFolder.
private SourceFolder addSourceFolder(final String url, boolean isTestSource, String packagePrefix) {
final JavaSourceRootType rootType = isTestSource ? JavaSourceRootType.TEST_SOURCE : JavaSourceRootType.SOURCE;
JavaSourceRootProperties properties = JpsJavaExtensionService.getInstance().createSourceRootProperties(packagePrefix);
return addSourceFolder(url, rootType, properties);
}
use of org.jetbrains.jps.model.java.JavaSourceRootProperties in project intellij-community by JetBrains.
the class ContentRootDataService method createSourceRootIfAbsent.
private static void createSourceRootIfAbsent(@NotNull ContentEntry entry, @NotNull final SourceRoot root, @NotNull String moduleName, @NotNull JpsModuleSourceRootType<?> sourceRootType, boolean generated, boolean createEmptyContentRootDirectories) {
SourceFolder[] folders = entry.getSourceFolders();
for (SourceFolder folder : folders) {
VirtualFile file = folder.getFile();
if (file == null) {
continue;
}
if (ExternalSystemApiUtil.getLocalFileSystemPath(file).equals(root.getPath())) {
final JpsModuleSourceRootType<?> folderRootType = folder.getRootType();
if (JavaSourceRootType.SOURCE.equals(folderRootType) || sourceRootType.equals(folderRootType)) {
return;
}
if (JavaSourceRootType.TEST_SOURCE.equals(folderRootType) && JavaResourceRootType.TEST_RESOURCE.equals(sourceRootType)) {
return;
}
entry.removeSourceFolder(folder);
}
}
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("Importing %s for content root '%s' of module '%s'", root, entry.getUrl(), moduleName));
}
SourceFolder sourceFolder = entry.addSourceFolder(toVfsUrl(root.getPath()), sourceRootType);
if (!StringUtil.isEmpty(root.getPackagePrefix())) {
sourceFolder.setPackagePrefix(root.getPackagePrefix());
}
if (generated) {
JavaSourceRootProperties properties = sourceFolder.getJpsElement().getProperties(JavaModuleSourceRootTypes.SOURCES);
if (properties != null) {
properties.setForGeneratedSources(true);
}
}
if (createEmptyContentRootDirectories) {
ExternalSystemApiUtil.doWriteAction(() -> {
try {
VfsUtil.createDirectoryIfMissing(root.getPath());
} catch (IOException e) {
LOG.warn(String.format("Unable to create directory for the path: %s", root.getPath()), e);
}
});
}
}
use of org.jetbrains.jps.model.java.JavaSourceRootProperties in project intellij-community by JetBrains.
the class ResourceCopyingTest method testPackagePrefix.
public void testPackagePrefix() {
String file = createFile("src/a.xml");
JpsModule m = addModule("m", PathUtil.getParentPath(file));
JpsModuleSourceRoot sourceRoot = assertOneElement(m.getSourceRoots());
JpsTypedModuleSourceRoot<JavaSourceRootProperties> typed = sourceRoot.asTyped(JavaSourceRootType.SOURCE);
assertNotNull(typed);
typed.getProperties().setPackagePrefix("xxx");
rebuildAllModules();
assertOutput(m, fs().dir("xxx").file("a.xml"));
}
use of org.jetbrains.jps.model.java.JavaSourceRootProperties in project intellij-community by JetBrains.
the class MavenImportingTestCase method assertGeneratedSources.
protected void assertGeneratedSources(String moduleName, String... expectedSources) {
ContentEntry contentRoot = getContentRoot(moduleName);
List<ContentFolder> folders = new ArrayList<>();
for (SourceFolder folder : contentRoot.getSourceFolders(JavaSourceRootType.SOURCE)) {
JavaSourceRootProperties properties = folder.getJpsElement().getProperties(JavaSourceRootType.SOURCE);
assertNotNull(properties);
if (properties.isForGeneratedSources()) {
folders.add(folder);
}
}
doAssertContentFolders(contentRoot, folders, expectedSources);
}
use of org.jetbrains.jps.model.java.JavaSourceRootProperties in project intellij-community by JetBrains.
the class MavenFoldersImporterTest method testMarkSourcesAsGeneratedOnReImport.
public void testMarkSourcesAsGeneratedOnReImport() throws IOException {
importProject("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>");
new File(myProjectRoot.getPath(), "target/generated-sources/xxx/z").mkdirs();
updateProjectFolders();
assertGeneratedSources("project", "target/generated-sources/xxx");
ModuleRootModificationUtil.updateModel(getModule("project"), model -> {
for (SourceFolder folder : model.getContentEntries()[0].getSourceFolders()) {
JavaSourceRootProperties properties = folder.getJpsElement().getProperties(JavaModuleSourceRootTypes.SOURCES);
assertNotNull(properties);
properties.setForGeneratedSources(false);
}
});
assertGeneratedSources("project");
importProject();
assertGeneratedSources("project", "target/generated-sources/xxx");
}
Aggregations