Search in sources :

Example 1 with JpsModuleSourceRootType

use of org.jetbrains.jps.model.module.JpsModuleSourceRootType in project intellij-community by JetBrains.

the class MavenSourceFoldersModuleExtension method commit.

@Override
public void commit() {
    if (!isJpsSourceFoldersChanged)
        return;
    for (ContentEntry eachEntry : myRootModel.getContentEntries()) {
        for (SourceFolder eachFolder : eachEntry.getSourceFolders()) {
            boolean found = false;
            for (JpsSourceFolder jpsSourceFolder : myJpsSourceFolders) {
                if (StringUtil.equals(jpsSourceFolder.getUrl(), eachFolder.getUrl()) && eachFolder.getRootType().equals(jpsSourceFolder.getRootType())) {
                    found = true;
                    if (eachFolder.getRootType() instanceof JavaSourceRootType) {
                        final JavaSourceRootProperties jpsJavaSourceRootProperties = jpsSourceFolder.getJpsElement().getProperties((JavaSourceRootType) eachFolder.getRootType());
                        final JavaSourceRootProperties javaSourceRootProperties = eachFolder.getJpsElement().getProperties((JavaSourceRootType) eachFolder.getRootType());
                        if (javaSourceRootProperties != null && jpsJavaSourceRootProperties != null) {
                            javaSourceRootProperties.applyChanges(jpsJavaSourceRootProperties);
                        }
                    }
                    myJpsSourceFolders.remove(jpsSourceFolder);
                    Disposer.dispose(jpsSourceFolder);
                    break;
                }
            }
            if (!found) {
                eachEntry.removeSourceFolder(eachFolder);
            }
        }
    }
    for (JpsSourceFolder jpsSourceFolder : myJpsSourceFolders) {
        Url url = new Url(jpsSourceFolder.getUrl());
        ContentEntry e = getContentRootFor(url);
        if (e == null)
            continue;
        //noinspection unchecked
        JpsModuleSourceRootType<JpsElement> sourceRootType = (JpsModuleSourceRootType<JpsElement>) jpsSourceFolder.getRootType();
        final JpsElementBase properties = (JpsElementBase) jpsSourceFolder.getSourceRoot().getProperties();
        //noinspection unchecked
        properties.setParent(null);
        e.addSourceFolder(url.getUrl(), sourceRootType, properties);
    }
    isJpsSourceFoldersChanged = false;
}
Also used : JpsSourceFolder(com.intellij.project.model.impl.module.content.JpsSourceFolder) JpsElement(org.jetbrains.jps.model.JpsElement) JpsModuleSourceRootType(org.jetbrains.jps.model.module.JpsModuleSourceRootType) JpsContentEntry(com.intellij.project.model.impl.module.content.JpsContentEntry) JpsElementBase(org.jetbrains.jps.model.ex.JpsElementBase) JpsSourceFolder(com.intellij.project.model.impl.module.content.JpsSourceFolder) JavaSourceRootType(org.jetbrains.jps.model.java.JavaSourceRootType) JavaSourceRootProperties(org.jetbrains.jps.model.java.JavaSourceRootProperties) Url(org.jetbrains.idea.maven.utils.Url)

Example 2 with JpsModuleSourceRootType

use of org.jetbrains.jps.model.module.JpsModuleSourceRootType in project android by JetBrains.

the class IdeFrameFixture method getSourceFolderRelativePaths.

/**
   * Returns a list of system independent paths
   */
@NotNull
public Collection<String> getSourceFolderRelativePaths(@NotNull String moduleName, @NotNull JpsModuleSourceRootType<?> sourceType) {
    Set<String> paths = Sets.newHashSet();
    Module module = getModule(moduleName);
    ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
    execute(new GuiTask() {

        @Override
        protected void executeInEDT() throws Throwable {
            ModifiableRootModel rootModel = moduleRootManager.getModifiableModel();
            try {
                for (ContentEntry contentEntry : rootModel.getContentEntries()) {
                    for (SourceFolder folder : contentEntry.getSourceFolders()) {
                        JpsModuleSourceRootType<?> rootType = folder.getRootType();
                        if (rootType.equals(sourceType)) {
                            String path = urlToPath(folder.getUrl());
                            String relativePath = getRelativePath(myProjectPath, new File(toSystemDependentName(path)));
                            paths.add(PathUtil.toSystemIndependentName(relativePath));
                        }
                    }
                }
            } finally {
                rootModel.dispose();
            }
        }
    });
    return paths;
}
Also used : GuiTask(org.fest.swing.edt.GuiTask) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) SourceFolder(com.intellij.openapi.roots.SourceFolder) JpsModuleSourceRootType(org.jetbrains.jps.model.module.JpsModuleSourceRootType) ContentEntry(com.intellij.openapi.roots.ContentEntry) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) GradleUtil.getGradleBuildFile(com.android.tools.idea.gradle.util.GradleUtil.getGradleBuildFile) Assert.assertNotNull(junit.framework.Assert.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with JpsModuleSourceRootType

use of org.jetbrains.jps.model.module.JpsModuleSourceRootType in project android by JetBrains.

the class AndroidContentEntriesSetup method addGeneratedSourceFolders.

private void addGeneratedSourceFolders(@NotNull BaseArtifact artifact, @NotNull List<ContentEntry> contentEntries, boolean isTest) {
    JpsModuleSourceRootType sourceType = getSourceType(isTest);
    GradleVersion modelVersion = myAndroidModel.getModelVersion();
    if (artifact instanceof AndroidArtifact || (modelVersion != null && modelVersion.compareIgnoringQualifiers("1.2") >= 0)) {
        // getGeneratedSourceFolders used to be in AndroidArtifact only.
        Collection<File> generatedSourceFolders = getGeneratedSourceFolders(artifact);
        //noinspection ConstantConditions - this returned null in 1.2
        if (generatedSourceFolders != null) {
            addSourceFolders(generatedSourceFolders, contentEntries, sourceType, true);
        }
    }
    if (artifact instanceof AndroidArtifact) {
        sourceType = getResourceSourceType(isTest);
        AndroidArtifact androidArtifact = (AndroidArtifact) artifact;
        addSourceFolders(androidArtifact.getGeneratedResourceFolders(), contentEntries, sourceType, true);
    }
}
Also used : JpsModuleSourceRootType(org.jetbrains.jps.model.module.JpsModuleSourceRootType) GradleVersion(com.android.ide.common.repository.GradleVersion) File(java.io.File)

Example 4 with JpsModuleSourceRootType

use of org.jetbrains.jps.model.module.JpsModuleSourceRootType in project intellij-community by JetBrains.

the class ContentRootPanel method addFolderGroupComponents.

protected void addFolderGroupComponents() {
    final SourceFolder[] sourceFolders = getContentEntry().getSourceFolders();
    MultiMap<JpsModuleSourceRootType<?>, SourceFolder> folderByType = new MultiMap<>();
    for (SourceFolder folder : sourceFolders) {
        if (!folder.isSynthetic()) {
            folderByType.putValue(folder.getRootType(), folder);
        }
    }
    Insets insets = JBUI.insetsBottom(10);
    GridBagConstraints constraints = new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, insets, 0, 0);
    for (ModuleSourceRootEditHandler<?> editor : myModuleSourceRootEditHandlers) {
        Collection<SourceFolder> folders = folderByType.get(editor.getRootType());
        if (folders.isEmpty())
            continue;
        ContentFolder[] foldersArray = folders.toArray(new ContentFolder[folders.size()]);
        final JComponent sourcesComponent = createFolderGroupComponent(editor.getRootsGroupTitle(), foldersArray, editor.getRootsGroupColor(), editor);
        add(sourcesComponent, constraints);
    }
    ExcludeFolder[] excluded = getContentEntry().getExcludeFolders();
    if (excluded.length > 0) {
        final JComponent excludedComponent = createFolderGroupComponent(ProjectBundle.message("module.paths.excluded.group"), excluded, EXCLUDED_COLOR, null);
        this.add(excludedComponent, constraints);
    }
}
Also used : SourceFolder(com.intellij.openapi.roots.SourceFolder) MultiMap(com.intellij.util.containers.MultiMap) JpsModuleSourceRootType(org.jetbrains.jps.model.module.JpsModuleSourceRootType) ContentFolder(com.intellij.openapi.roots.ContentFolder) ExcludeFolder(com.intellij.openapi.roots.ExcludeFolder)

Example 5 with JpsModuleSourceRootType

use of org.jetbrains.jps.model.module.JpsModuleSourceRootType in project android by JetBrains.

the class AndroidContentEntriesSetup method addSourceFolder.

private void addSourceFolder(@NotNull SourceProvider sourceProvider, @NotNull List<ContentEntry> contentEntries, boolean isTest) {
    JpsModuleSourceRootType sourceType = getResourceSourceType(isTest);
    addSourceFolders(sourceProvider.getResDirectories(), contentEntries, sourceType, false);
    addSourceFolders(sourceProvider.getResourcesDirectories(), contentEntries, sourceType, false);
    addSourceFolders(sourceProvider.getAssetsDirectories(), contentEntries, sourceType, false);
    sourceType = getSourceType(isTest);
    addSourceFolders(sourceProvider.getAidlDirectories(), contentEntries, sourceType, false);
    addSourceFolders(sourceProvider.getJavaDirectories(), contentEntries, sourceType, false);
    if (myHasNativeModel) {
        addSourceFolders(sourceProvider.getCDirectories(), contentEntries, sourceType, false);
        addSourceFolders(sourceProvider.getCppDirectories(), contentEntries, sourceType, false);
    }
    addSourceFolders(sourceProvider.getRenderscriptDirectories(), contentEntries, sourceType, false);
    if (myAndroidModel.getFeatures().isShadersSupported()) {
        addSourceFolders(sourceProvider.getShadersDirectories(), contentEntries, sourceType, false);
    }
}
Also used : JpsModuleSourceRootType(org.jetbrains.jps.model.module.JpsModuleSourceRootType)

Aggregations

JpsModuleSourceRootType (org.jetbrains.jps.model.module.JpsModuleSourceRootType)8 File (java.io.File)4 Module (com.intellij.openapi.module.Module)3 SourceFolder (com.intellij.openapi.roots.SourceFolder)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 NotNull (org.jetbrains.annotations.NotNull)3 ContentEntry (com.intellij.openapi.roots.ContentEntry)2 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)2 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)2 GradleVersion (com.android.ide.common.repository.GradleVersion)1 GradleUtil.getGradleBuildFile (com.android.tools.idea.gradle.util.GradleUtil.getGradleBuildFile)1 FacetManager (com.intellij.facet.FacetManager)1 ModifiableFacetModel (com.intellij.facet.ModifiableFacetModel)1 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)1 Application (com.intellij.openapi.application.Application)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 Logger (com.intellij.openapi.diagnostic.Logger)1 ModifiableModuleModel (com.intellij.openapi.module.ModifiableModuleModel)1 ModuleManager (com.intellij.openapi.module.ModuleManager)1 StdModuleTypes (com.intellij.openapi.module.StdModuleTypes)1