Search in sources :

Example 1 with JpsElement

use of org.jetbrains.jps.model.JpsElement 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 2 with JpsElement

use of org.jetbrains.jps.model.JpsElement 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 3 with JpsElement

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

the class JpsIdeaSpecificSettings method readContentEntry.

@Override
public void readContentEntry(Element root, String contentUrl, JpsModule model) {
    for (Object o : root.getChildren(IdeaXml.TEST_FOLDER_TAG)) {
        final String url = ((Element) o).getAttributeValue(IdeaXml.URL_ATTR);
        JpsModuleSourceRoot folderToBeTest = null;
        for (JpsModuleSourceRoot folder : model.getSourceRoots()) {
            if (Comparing.strEqual(folder.getUrl(), url)) {
                folderToBeTest = folder;
                break;
            }
        }
        if (folderToBeTest != null) {
            model.removeSourceRoot(folderToBeTest.getUrl(), JavaSourceRootType.SOURCE);
        }
        model.addSourceRoot(url, JavaSourceRootType.TEST_SOURCE);
    }
    for (Object o : root.getChildren(IdeaXml.EXCLUDE_FOLDER_TAG)) {
        final String excludeUrl = ((Element) o).getAttributeValue(IdeaXml.URL_ATTR);
        if (FileUtil.isAncestor(new File(contentUrl), new File(excludeUrl), false)) {
            model.getExcludeRootsList().addUrl(excludeUrl);
        }
    }
    for (Object o : root.getChildren(IdeaXml.PACKAGE_PREFIX_TAG)) {
        Element ppElement = (Element) o;
        final String prefix = ppElement.getAttributeValue(IdeaXml.PACKAGE_PREFIX_VALUE_ATTR);
        final String url = ppElement.getAttributeValue(IdeaXml.URL_ATTR);
        for (JpsModuleSourceRoot sourceRoot : model.getSourceRoots()) {
            if (Comparing.strEqual(sourceRoot.getUrl(), url)) {
                JpsElement properties = sourceRoot.getProperties();
                if (properties instanceof JavaSourceRootProperties) {
                    ((JavaSourceRootProperties) properties).setPackagePrefix(prefix);
                }
                break;
            }
        }
    }
}
Also used : JpsModuleSourceRoot(org.jetbrains.jps.model.module.JpsModuleSourceRoot) JpsElement(org.jetbrains.jps.model.JpsElement) JpsElement(org.jetbrains.jps.model.JpsElement) Element(org.jdom.Element) File(java.io.File)

Example 4 with JpsElement

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

the class AndroidArtifactBuildTaskProvider method createArtifactBuildTasks.

@NotNull
@Override
public List<? extends BuildTask> createArtifactBuildTasks(@NotNull JpsArtifact artifact, @NotNull ArtifactBuildPhase buildPhase) {
    if (buildPhase != ArtifactBuildPhase.FINISHING_BUILD) {
        return Collections.emptyList();
    }
    if (!(artifact.getArtifactType() instanceof AndroidApplicationArtifactType)) {
        return Collections.emptyList();
    }
    final JpsElement props = artifact.getProperties();
    if (!(props instanceof JpsAndroidApplicationArtifactProperties)) {
        return Collections.emptyList();
    }
    final JpsAndroidApplicationArtifactProperties androidProps = (JpsAndroidApplicationArtifactProperties) props;
    if (!(artifact.getArtifactType() instanceof AndroidApplicationArtifactType)) {
        return Collections.emptyList();
    }
    final AndroidArtifactSigningMode signingMode = androidProps.getSigningMode();
    if (signingMode != AndroidArtifactSigningMode.RELEASE_SIGNED && signingMode != AndroidArtifactSigningMode.DEBUG_WITH_CUSTOM_CERTIFICATE) {
        return Collections.emptyList();
    }
    final JpsAndroidModuleExtension extension = AndroidJpsUtil.getPackagedFacet(artifact);
    return extension != null ? Collections.singletonList(new MyTask(artifact, extension, androidProps)) : Collections.<BuildTask>emptyList();
}
Also used : JpsElement(org.jetbrains.jps.model.JpsElement) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) JpsAndroidApplicationArtifactProperties(org.jetbrains.jps.android.model.JpsAndroidApplicationArtifactProperties) AndroidApplicationArtifactType(org.jetbrains.jps.android.model.AndroidApplicationArtifactType) AndroidArtifactSigningMode(org.jetbrains.android.compiler.artifact.AndroidArtifactSigningMode) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with JpsElement

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

the class AndroidJpsUtil method getProGuardConfigIfShouldRun.

public static ProGuardOptions getProGuardConfigIfShouldRun(@NotNull CompileContext context, @NotNull JpsAndroidModuleExtension extension) throws IOException {
    if (extension.isRunProguard()) {
        return new ProGuardOptions(extension.getProguardConfigFiles(extension.getModule()));
    }
    final String cfgPathsStrFromContext = context.getBuilderParameter(AndroidCommonUtils.PROGUARD_CFG_PATHS_OPTION);
    if (cfgPathsStrFromContext != null && cfgPathsStrFromContext.length() > 0) {
        final String[] paths = cfgPathsStrFromContext.split(File.pathSeparator);
        if (paths.length > 0) {
            final File[] files = toFiles(paths);
            return new ProGuardOptions(Arrays.asList(files));
        }
    }
    for (JpsArtifact artifact : getAndroidArtifactsToBuild(context)) {
        final JpsAndroidModuleExtension facetFromArtifact = getPackagedFacet(artifact);
        final JpsModule moduleFromArtifact = facetFromArtifact != null ? facetFromArtifact.getModule() : null;
        if (moduleFromArtifact != null && moduleFromArtifact.equals(extension.getModule())) {
            final JpsElement props = artifact.getProperties();
            if (props instanceof JpsAndroidApplicationArtifactProperties) {
                final JpsAndroidApplicationArtifactProperties androidProps = (JpsAndroidApplicationArtifactProperties) props;
                if (androidProps.isRunProGuard()) {
                    final List<String> cfgFileUrls = androidProps.getProGuardCfgFiles(moduleFromArtifact);
                    final List<File> cfgPaths = cfgFileUrls != null ? urlsToFiles(cfgFileUrls) : null;
                    return new ProGuardOptions(cfgPaths);
                }
            }
        }
    }
    return null;
}
Also used : JpsElement(org.jetbrains.jps.model.JpsElement) JpsArtifact(org.jetbrains.jps.model.artifact.JpsArtifact)

Aggregations

JpsElement (org.jetbrains.jps.model.JpsElement)17 Element (org.jdom.Element)7 JpsModuleSourceRoot (org.jetbrains.jps.model.module.JpsModuleSourceRoot)5 JpsDummyElement (org.jetbrains.jps.model.JpsDummyElement)4 JavaSourceRootProperties (org.jetbrains.jps.model.java.JavaSourceRootProperties)4 SourceFolder (com.intellij.openapi.roots.SourceFolder)3 File (java.io.File)3 JpsAndroidApplicationArtifactProperties (org.jetbrains.jps.android.model.JpsAndroidApplicationArtifactProperties)3 JpsContentEntry (com.intellij.project.model.impl.module.content.JpsContentEntry)2 JpsSourceFolder (com.intellij.project.model.impl.module.content.JpsSourceFolder)2 AndroidArtifactSigningMode (org.jetbrains.android.compiler.artifact.AndroidArtifactSigningMode)2 NotNull (org.jetbrains.annotations.NotNull)2 JpsAndroidModuleExtension (org.jetbrains.jps.android.model.JpsAndroidModuleExtension)2 JpsArtifact (org.jetbrains.jps.model.artifact.JpsArtifact)2 JpsLibrary (org.jetbrains.jps.model.library.JpsLibrary)2 JpsRootModel (com.intellij.project.model.impl.module.JpsRootModel)1 HashMap (com.intellij.util.containers.HashMap)1 HashSet (com.intellij.util.containers.HashSet)1 THashSet (gnu.trove.THashSet)1 TObjectLongHashMap (gnu.trove.TObjectLongHashMap)1