Search in sources :

Example 1 with CompilerModuleExtension

use of com.intellij.openapi.roots.CompilerModuleExtension in project intellij-plugins by StepicOrg.

the class AbstractModuleBuilder method setupRootModel.

@Override
public void setupRootModel(ModifiableRootModel rootModel) throws ConfigurationException {
    CompilerModuleExtension compilerModuleExtension = rootModel.getModuleExtension(CompilerModuleExtension.class);
    compilerModuleExtension.setExcludeOutput(true);
    if (this.myJdk != null) {
        rootModel.setSdk(this.myJdk);
    } else {
        rootModel.inheritSdk();
    }
    compilerModuleExtension.inheritCompilerOutputPath(true);
    doAddContentEntry(rootModel);
}
Also used : CompilerModuleExtension(com.intellij.openapi.roots.CompilerModuleExtension)

Example 2 with CompilerModuleExtension

use of com.intellij.openapi.roots.CompilerModuleExtension in project intellij-community by JetBrains.

the class ExcludeCompilerOutputPolicy method getExcludeRootsForModule.

@NotNull
@Override
public VirtualFilePointer[] getExcludeRootsForModule(@NotNull final ModuleRootModel rootModel) {
    ArrayList<VirtualFilePointer> result = new ArrayList<>();
    final CompilerModuleExtension extension = rootModel.getModuleExtension(CompilerModuleExtension.class);
    if (extension == null) {
        return VirtualFilePointer.EMPTY_ARRAY;
    }
    if (extension.isCompilerOutputPathInherited()) {
        ContainerUtil.addIfNotNull(result, CompilerProjectExtension.getInstance(myProject).getCompilerOutputPointer());
    } else {
        if (!extension.isExcludeOutput())
            return VirtualFilePointer.EMPTY_ARRAY;
        ContainerUtil.addIfNotNull(result, extension.getCompilerOutputPointer());
        ContainerUtil.addIfNotNull(result, extension.getCompilerOutputForTestsPointer());
    }
    return result.isEmpty() ? VirtualFilePointer.EMPTY_ARRAY : result.toArray(new VirtualFilePointer[result.size()]);
}
Also used : ArrayList(java.util.ArrayList) CompilerModuleExtension(com.intellij.openapi.roots.CompilerModuleExtension) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with CompilerModuleExtension

use of com.intellij.openapi.roots.CompilerModuleExtension in project intellij-community by JetBrains.

the class JaCoCoCoverageRunner method loadExecutionData.

private static void loadExecutionData(@NotNull final File sessionDataFile, ProjectData data, @NotNull Project project) throws IOException {
    final ExecutionDataStore executionDataStore = new ExecutionDataStore();
    FileInputStream fis = null;
    try {
        fis = new FileInputStream(sessionDataFile);
        final ExecutionDataReader executionDataReader = new ExecutionDataReader(fis);
        executionDataReader.setExecutionDataVisitor(executionDataStore);
        executionDataReader.setSessionInfoVisitor(new ISessionInfoVisitor() {

            public void visitSessionInfo(SessionInfo info) {
                System.out.println(info.toString());
            }
        });
        while (executionDataReader.read()) {
        }
    } finally {
        if (fis != null) {
            fis.close();
        }
    }
    final CoverageBuilder coverageBuilder = new CoverageBuilder();
    final Analyzer analyzer = new Analyzer(executionDataStore, coverageBuilder);
    final Module[] modules = ModuleManager.getInstance(project).getModules();
    for (Module module : modules) {
        final CompilerModuleExtension compilerModuleExtension = CompilerModuleExtension.getInstance(module);
        if (compilerModuleExtension != null) {
            final VirtualFile[] roots = compilerModuleExtension.getOutputRoots(true);
            for (VirtualFile root : roots) {
                analyzer.analyzeAll(VfsUtil.virtualToIoFile(root));
            }
        }
    }
    for (IClassCoverage classCoverage : coverageBuilder.getClasses()) {
        String className = classCoverage.getName();
        className = className.replace('\\', '.').replace('/', '.');
        final ClassData classData = data.getOrCreateClassData(className);
        final Collection<IMethodCoverage> methods = classCoverage.getMethods();
        LineData[] lines = new LineData[classCoverage.getLastLine() + 1];
        for (IMethodCoverage method : methods) {
            final String desc = method.getName() + method.getDesc();
            // Line numbers are 1-based here.
            final int firstLine = method.getFirstLine();
            final int lastLine = method.getLastLine();
            for (int i = firstLine; i <= lastLine; i++) {
                final ILine methodLine = method.getLine(i);
                final int methodLineStatus = methodLine.getStatus();
                if (methodLineStatus == ICounter.EMPTY)
                    continue;
                final LineData lineData = new LineData(i, desc) {

                    @Override
                    public int getStatus() {
                        switch(methodLineStatus) {
                            case ICounter.FULLY_COVERED:
                                return LineCoverage.FULL;
                            case ICounter.PARTLY_COVERED:
                                return LineCoverage.PARTIAL;
                            default:
                                return LineCoverage.NONE;
                        }
                    }
                };
                lineData.setHits(methodLineStatus == ICounter.FULLY_COVERED || methodLineStatus == ICounter.PARTLY_COVERED ? 1 : 0);
                lines[i] = lineData;
            }
        }
        classData.setLines(lines);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ISessionInfoVisitor(org.jacoco.core.data.ISessionInfoVisitor) SessionInfo(org.jacoco.core.data.SessionInfo) CompilerModuleExtension(com.intellij.openapi.roots.CompilerModuleExtension) FileInputStream(java.io.FileInputStream) ExecutionDataReader(org.jacoco.core.data.ExecutionDataReader) LineData(com.intellij.rt.coverage.data.LineData) ClassData(com.intellij.rt.coverage.data.ClassData) ExecutionDataStore(org.jacoco.core.data.ExecutionDataStore) Module(com.intellij.openapi.module.Module)

Example 4 with CompilerModuleExtension

use of com.intellij.openapi.roots.CompilerModuleExtension in project intellij-community by JetBrains.

the class GradleResourceCompilerConfigurationGenerator method generateAffectedGradleModulesConfiguration.

@NotNull
private Map<String, GradleModuleResourceConfiguration> generateAffectedGradleModulesConfiguration(@NotNull CompileContext context) {
    final Map<String, GradleModuleResourceConfiguration> affectedGradleModuleConfigurations = ContainerUtil.newTroveMap();
    //noinspection MismatchedQueryAndUpdateOfCollection
    final Map<String, ExternalProject> lazyExternalProjectMap = new FactoryMap<String, ExternalProject>() {

        @Nullable
        @Override
        protected ExternalProject create(String gradleProjectPath) {
            return externalProjectDataCache.getRootExternalProject(GradleConstants.SYSTEM_ID, new File(gradleProjectPath));
        }
    };
    for (Module module : context.getCompileScope().getAffectedModules()) {
        if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module))
            continue;
        final String gradleProjectPath = ExternalSystemApiUtil.getExternalRootProjectPath(module);
        assert gradleProjectPath != null;
        if (shouldBeBuiltByExternalSystem(module))
            continue;
        final ExternalProject externalRootProject = lazyExternalProjectMap.get(gradleProjectPath);
        if (externalRootProject == null) {
            context.addMessage(CompilerMessageCategory.ERROR, String.format("Unable to make the module: %s, related gradle configuration was not found. " + "Please, re-import the Gradle project and try again.", module.getName()), VfsUtilCore.pathToUrl(gradleProjectPath), -1, -1);
            continue;
        }
        Map<String, ExternalSourceSet> externalSourceSets = externalProjectDataCache.findExternalProject(externalRootProject, module);
        if (externalSourceSets.isEmpty()) {
            LOG.debug("Unable to find source sets config for module: " + module.getName());
            continue;
        }
        GradleModuleResourceConfiguration resourceConfig = new GradleModuleResourceConfiguration();
        resourceConfig.id = new ModuleVersion(ExternalSystemApiUtil.getExternalProjectGroup(module), ExternalSystemApiUtil.getExternalProjectId(module), ExternalSystemApiUtil.getExternalProjectVersion(module));
        for (ExternalSourceSet sourceSet : externalSourceSets.values()) {
            addResources(resourceConfig.resources, sourceSet.getSources().get(ExternalSystemSourceType.RESOURCE), sourceSet.getSources().get(ExternalSystemSourceType.SOURCE));
            addResources(resourceConfig.testResources, sourceSet.getSources().get(ExternalSystemSourceType.TEST_RESOURCE), sourceSet.getSources().get(ExternalSystemSourceType.TEST));
        }
        final CompilerModuleExtension compilerModuleExtension = CompilerModuleExtension.getInstance(module);
        if (compilerModuleExtension != null && compilerModuleExtension.isCompilerOutputPathInherited()) {
            String outputPath = VfsUtilCore.urlToPath(compilerModuleExtension.getCompilerOutputUrl());
            for (ResourceRootConfiguration resource : resourceConfig.resources) {
                resource.targetPath = outputPath;
            }
            String testOutputPath = VfsUtilCore.urlToPath(compilerModuleExtension.getCompilerOutputUrlForTests());
            for (ResourceRootConfiguration resource : resourceConfig.testResources) {
                resource.targetPath = testOutputPath;
            }
        }
        affectedGradleModuleConfigurations.put(module.getName(), resourceConfig);
    }
    return affectedGradleModuleConfigurations;
}
Also used : FactoryMap(com.intellij.util.containers.FactoryMap) ExternalSourceSet(org.jetbrains.plugins.gradle.model.ExternalSourceSet) ExternalProject(org.jetbrains.plugins.gradle.model.ExternalProject) CompilerModuleExtension(com.intellij.openapi.roots.CompilerModuleExtension) Module(com.intellij.openapi.module.Module) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with CompilerModuleExtension

use of com.intellij.openapi.roots.CompilerModuleExtension in project android by JetBrains.

the class ExcludedRoots method addFolderPathsFromExcludedModules.

private void addFolderPathsFromExcludedModules() {
    for (Module module : myExcludedModules) {
        ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
        for (ContentEntry entry : rootManager.getContentEntries()) {
            for (SourceFolder sourceFolder : entry.getSourceFolders()) {
                myExcludedRoots.add(urlToFilePath(sourceFolder.getUrl()));
            }
            CompilerModuleExtension compiler = rootManager.getModuleExtension(CompilerModuleExtension.class);
            String url = compiler.getCompilerOutputUrl();
            if (isNotEmpty(url)) {
                myExcludedRoots.add(urlToFilePath(url));
            }
        }
        AndroidModuleModel androidModuleModel = AndroidModuleModel.get(module);
        if (androidModuleModel != null) {
            myExcludedRoots.add(androidModuleModel.getMainArtifact().getJavaResourcesFolder());
        }
    }
}
Also used : SourceFolder(com.intellij.openapi.roots.SourceFolder) ContentEntry(com.intellij.openapi.roots.ContentEntry) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Module(com.intellij.openapi.module.Module) CompilerModuleExtension(com.intellij.openapi.roots.CompilerModuleExtension)

Aggregations

CompilerModuleExtension (com.intellij.openapi.roots.CompilerModuleExtension)12 Module (com.intellij.openapi.module.Module)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 Nullable (org.jetbrains.annotations.Nullable)3 ContentEntry (com.intellij.openapi.roots.ContentEntry)2 NotNull (org.jetbrains.annotations.NotNull)2 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 AndroidModel (com.android.tools.idea.model.AndroidModel)1 Application (com.intellij.openapi.application.Application)1 DumbProgressIndicator (com.intellij.openapi.progress.DumbProgressIndicator)1 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)1 SourceFolder (com.intellij.openapi.roots.SourceFolder)1 Computable (com.intellij.openapi.util.Computable)1 VirtualFilePointer (com.intellij.openapi.vfs.pointers.VirtualFilePointer)1 ClassData (com.intellij.rt.coverage.data.ClassData)1 LineData (com.intellij.rt.coverage.data.LineData)1 ClassPathEntry (com.intellij.rt.coverage.util.classFinder.ClassPathEntry)1 FactoryMap (com.intellij.util.containers.FactoryMap)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1