Search in sources :

Example 1 with JpsSourceFolder

use of com.intellij.project.model.impl.module.content.JpsSourceFolder in project intellij-community by JetBrains.

the class MavenSourceFoldersModuleExtension method addJspSourceFolder.

private void addJspSourceFolder(@NotNull JpsModuleSourceRoot jpsModuleSourceRoot, @NotNull String url) {
    final JpsContentEntry dummyJpsContentEntry = new JpsContentEntry(myDummyJpsModule, myDummyJpsRootModel, url);
    final JpsSourceFolder jpsSourceFolder = new JpsSourceFolder(jpsModuleSourceRoot, dummyJpsContentEntry);
    myJpsSourceFolders.add(jpsSourceFolder);
    // since dummyJpsContentEntry created for each source folder, we will dispose it on that source folder disposal
    Disposer.register(jpsSourceFolder, dummyJpsContentEntry);
}
Also used : JpsContentEntry(com.intellij.project.model.impl.module.content.JpsContentEntry) JpsSourceFolder(com.intellij.project.model.impl.module.content.JpsSourceFolder)

Example 2 with JpsSourceFolder

use of com.intellij.project.model.impl.module.content.JpsSourceFolder in project intellij-community by JetBrains.

the class MavenSourceFoldersModuleExtension method clearSourceFolders.

public void clearSourceFolders() {
    for (JpsSourceFolder folder : myJpsSourceFolders) {
        Disposer.dispose(folder);
    }
    myJpsSourceFolders.clear();
    isJpsSourceFoldersChanged = true;
}
Also used : JpsSourceFolder(com.intellij.project.model.impl.module.content.JpsSourceFolder)

Example 3 with JpsSourceFolder

use of com.intellij.project.model.impl.module.content.JpsSourceFolder in project intellij-community by JetBrains.

the class MavenSourceFoldersModuleExtension method init.

public void init(@NotNull Module module, @NotNull ModifiableRootModel modifiableRootModel) {
    myRootModel = modifiableRootModel;
    myDummyJpsModule = JpsElementFactory.getInstance().createModule(module.getName(), JpsJavaModuleType.INSTANCE, JpsElementFactory.getInstance().createDummyElement());
    myDummyJpsRootModel = new JpsRootModel(module, myDummyJpsModule);
    for (JpsSourceFolder folder : myJpsSourceFolders) {
        Disposer.dispose(folder);
    }
    myJpsSourceFolders.clear();
    for (ContentEntry eachEntry : modifiableRootModel.getContentEntries()) {
        for (SourceFolder eachFolder : eachEntry.getSourceFolders()) {
            //noinspection unchecked
            final JpsModuleSourceRoot jpsModuleSourceRoot = JpsElementFactory.getInstance().createModuleSourceRoot(eachFolder.getUrl(), (JpsModuleSourceRootType<JpsElement>) eachFolder.getRootType(), eachFolder.getJpsElement().getProperties().getBulkModificationSupport().createCopy());
            addJspSourceFolder(jpsModuleSourceRoot, eachFolder.getUrl());
        }
    }
}
Also used : JpsRootModel(com.intellij.project.model.impl.module.JpsRootModel) JpsSourceFolder(com.intellij.project.model.impl.module.content.JpsSourceFolder) JpsModuleSourceRoot(org.jetbrains.jps.model.module.JpsModuleSourceRoot) JpsElement(org.jetbrains.jps.model.JpsElement) JpsContentEntry(com.intellij.project.model.impl.module.content.JpsContentEntry) JpsSourceFolder(com.intellij.project.model.impl.module.content.JpsSourceFolder)

Example 4 with JpsSourceFolder

use of com.intellij.project.model.impl.module.content.JpsSourceFolder 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 5 with JpsSourceFolder

use of com.intellij.project.model.impl.module.content.JpsSourceFolder in project intellij-community by JetBrains.

the class MavenSourceFoldersModuleExtension method addSourceFolder.

public <P extends JpsElement> void addSourceFolder(@NotNull final Url url, @NotNull final JpsModuleSourceRootType<P> rootType, @NotNull final P properties) {
    for (Iterator<JpsSourceFolder> iterator = myJpsSourceFolders.iterator(); iterator.hasNext(); ) {
        JpsSourceFolder eachFolder = iterator.next();
        if (VfsUtilCore.isEqualOrAncestor(url.getUrl(), eachFolder.getUrl()) || VfsUtilCore.isEqualOrAncestor(eachFolder.getUrl(), url.getUrl())) {
            iterator.remove();
            Disposer.dispose(eachFolder);
        }
    }
    final JpsModuleSourceRoot jpsModuleSourceRoot = JpsElementFactory.getInstance().createModuleSourceRoot(url.getUrl(), rootType, properties);
    addJspSourceFolder(jpsModuleSourceRoot, url.getUrl());
    isJpsSourceFoldersChanged = true;
}
Also used : JpsModuleSourceRoot(org.jetbrains.jps.model.module.JpsModuleSourceRoot) JpsSourceFolder(com.intellij.project.model.impl.module.content.JpsSourceFolder)

Aggregations

JpsSourceFolder (com.intellij.project.model.impl.module.content.JpsSourceFolder)6 JpsContentEntry (com.intellij.project.model.impl.module.content.JpsContentEntry)3 JpsElement (org.jetbrains.jps.model.JpsElement)2 JpsModuleSourceRoot (org.jetbrains.jps.model.module.JpsModuleSourceRoot)2 JpsRootModel (com.intellij.project.model.impl.module.JpsRootModel)1 Url (org.jetbrains.idea.maven.utils.Url)1 JpsElementBase (org.jetbrains.jps.model.ex.JpsElementBase)1 JavaSourceRootProperties (org.jetbrains.jps.model.java.JavaSourceRootProperties)1 JavaSourceRootType (org.jetbrains.jps.model.java.JavaSourceRootType)1 JpsModuleSourceRootType (org.jetbrains.jps.model.module.JpsModuleSourceRootType)1