Search in sources :

Example 11 with JavaSourceRootProperties

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);
}
Also used : JavaSourceRootType(org.jetbrains.jps.model.java.JavaSourceRootType) JavaSourceRootProperties(org.jetbrains.jps.model.java.JavaSourceRootProperties)

Example 12 with JavaSourceRootProperties

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);
            }
        });
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SourceFolder(com.intellij.openapi.roots.SourceFolder) IOException(java.io.IOException) JavaSourceRootProperties(org.jetbrains.jps.model.java.JavaSourceRootProperties)

Example 13 with JavaSourceRootProperties

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"));
}
Also used : JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsModuleSourceRoot(org.jetbrains.jps.model.module.JpsModuleSourceRoot) JavaSourceRootProperties(org.jetbrains.jps.model.java.JavaSourceRootProperties)

Example 14 with JavaSourceRootProperties

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);
}
Also used : JavaSourceRootProperties(org.jetbrains.jps.model.java.JavaSourceRootProperties)

Example 15 with JavaSourceRootProperties

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");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) JavaSourceRootProperties(org.jetbrains.jps.model.java.JavaSourceRootProperties)

Aggregations

JavaSourceRootProperties (org.jetbrains.jps.model.java.JavaSourceRootProperties)17 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 SourceFolder (com.intellij.openapi.roots.SourceFolder)3 JavaSourceRootType (org.jetbrains.jps.model.java.JavaSourceRootType)3 JpsModuleSourceRoot (org.jetbrains.jps.model.module.JpsModuleSourceRoot)3 Nullable (org.jetbrains.annotations.Nullable)2 JpsElement (org.jetbrains.jps.model.JpsElement)2 JavaResourceRootProperties (org.jetbrains.jps.model.java.JavaResourceRootProperties)2 AnalysisScope (com.intellij.analysis.AnalysisScope)1 ModuleSourceRootEditHandler (com.intellij.openapi.roots.ui.configuration.ModuleSourceRootEditHandler)1 JpsContentEntry (com.intellij.project.model.impl.module.content.JpsContentEntry)1 JpsSourceFolder (com.intellij.project.model.impl.module.content.JpsSourceFolder)1 IconActionComponent (com.intellij.ui.roots.IconActionComponent)1 File (java.io.File)1 IOException (java.io.IOException)1 NotNull (org.jetbrains.annotations.NotNull)1 Url (org.jetbrains.idea.maven.utils.Url)1 JpsElementBase (org.jetbrains.jps.model.ex.JpsElementBase)1 JpsModule (org.jetbrains.jps.model.module.JpsModule)1 JpsModuleSourceRootType (org.jetbrains.jps.model.module.JpsModuleSourceRootType)1