Search in sources :

Example 6 with CompilerModuleExtension

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

the class CompilerPaths method getModuleOutputDirectory.

/**
   * @param forTestClasses true if directory for test sources, false - for sources.
   * @return a directory to which the sources (or test sources depending on the second partameter) should be compiled.
   * Null is returned if output directory is not specified or is not valid
   */
@Nullable
public static VirtualFile getModuleOutputDirectory(final Module module, boolean forTestClasses) {
    final CompilerModuleExtension compilerModuleExtension = CompilerModuleExtension.getInstance(module);
    if (compilerModuleExtension == null) {
        return null;
    }
    VirtualFile outPath;
    if (forTestClasses) {
        final VirtualFile path = compilerModuleExtension.getCompilerOutputPathForTests();
        if (path != null) {
            outPath = path;
        } else {
            outPath = compilerModuleExtension.getCompilerOutputPath();
        }
    } else {
        outPath = compilerModuleExtension.getCompilerOutputPath();
    }
    if (outPath == null) {
        return null;
    }
    if (!outPath.isValid()) {
        LOG.info("Requested output path for module " + module.getName() + " is not valid");
        return null;
    }
    return outPath;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CompilerModuleExtension(com.intellij.openapi.roots.CompilerModuleExtension) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with CompilerModuleExtension

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

the class CompilerPaths method getModuleOutputPath.

/**
   * The same as {@link #getModuleOutputDirectory} but returns String.
   * The method still returns a non-null value if the output path is specified in Settings but does not exist on disk.
   */
@Nullable
public static String getModuleOutputPath(final Module module, boolean forTestClasses) {
    final String outPathUrl;
    final Application application = ApplicationManager.getApplication();
    final CompilerModuleExtension extension = CompilerModuleExtension.getInstance(module);
    if (extension == null) {
        return null;
    }
    if (forTestClasses) {
        if (application.isDispatchThread()) {
            final String url = extension.getCompilerOutputUrlForTests();
            outPathUrl = url != null ? url : extension.getCompilerOutputUrl();
        } else {
            outPathUrl = application.runReadAction(new Computable<String>() {

                @Override
                public String compute() {
                    final String url = extension.getCompilerOutputUrlForTests();
                    return url != null ? url : extension.getCompilerOutputUrl();
                }
            });
        }
    } else {
        // for ordinary classes
        if (application.isDispatchThread()) {
            outPathUrl = extension.getCompilerOutputUrl();
        } else {
            outPathUrl = application.runReadAction(new Computable<String>() {

                @Override
                public String compute() {
                    return extension.getCompilerOutputUrl();
                }
            });
        }
    }
    return outPathUrl != null ? VirtualFileManager.extractPath(outPathUrl) : null;
}
Also used : Application(com.intellij.openapi.application.Application) CompilerModuleExtension(com.intellij.openapi.roots.CompilerModuleExtension) Computable(com.intellij.openapi.util.Computable) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with CompilerModuleExtension

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

the class ConfigurationsTest method getOutput.

private static String getOutput(Module module1, boolean test) {
    CompilerModuleExtension compilerModuleExtension = CompilerModuleExtension.getInstance(module1);
    assertNotNull(compilerModuleExtension);
    VirtualFile output = test ? compilerModuleExtension.getCompilerOutputPathForTests() : compilerModuleExtension.getCompilerOutputPath();
    return getFSPath(output);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CompilerModuleExtension(com.intellij.openapi.roots.CompilerModuleExtension)

Example 9 with CompilerModuleExtension

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

the class IdeaClassFinder method getClassPathEntries.

@Override
protected Collection getClassPathEntries() {
    final Collection entries = super.getClassPathEntries();
    final Module[] modules = ModuleManager.getInstance(myProject).getModules();
    for (Module module : modules) {
        final CompilerModuleExtension extension = CompilerModuleExtension.getInstance(module);
        if (extension != null) {
            final VirtualFile outputFile = extension.getCompilerOutputPath();
            try {
                if (outputFile != null) {
                    final URL outputURL = VfsUtilCore.virtualToIoFile(outputFile).toURI().toURL();
                    entries.add(new ClassPathEntry(outputFile.getPath(), UrlClassLoader.build().urls(outputURL).get()));
                }
                if (myCurrentSuite.isTrackTestFolders()) {
                    final VirtualFile testOutput = extension.getCompilerOutputPathForTests();
                    if (testOutput != null) {
                        final URL testOutputURL = VfsUtilCore.virtualToIoFile(testOutput).toURI().toURL();
                        entries.add(new ClassPathEntry(testOutput.getPath(), UrlClassLoader.build().urls(testOutputURL).get()));
                    }
                }
            } catch (MalformedURLException e1) {
                LOG.error(e1);
            }
        }
    }
    return entries;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MalformedURLException(java.net.MalformedURLException) Collection(java.util.Collection) Module(com.intellij.openapi.module.Module) CompilerModuleExtension(com.intellij.openapi.roots.CompilerModuleExtension) URL(java.net.URL) ClassPathEntry(com.intellij.rt.coverage.util.classFinder.ClassPathEntry)

Example 10 with CompilerModuleExtension

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

the class JUnit4IntegrationTest method before.

@Before
public void before() throws Throwable {
    EdtTestUtil.runInEdtAndWait(() -> {
        setUp();
        Module module = createEmptyModule();
        String communityPath = PlatformTestUtil.getCommunityPath().replace(File.separatorChar, '/');
        String methodName = myNameRule.getMethodName();
        methodName = methodName.substring(0, methodName.indexOf("["));
        String testDataPath = communityPath + File.separator + "plugins" + File.separator + "junit5_rt_tests" + File.separator + "testData" + File.separator + "integration" + File.separator + methodName;
        MavenId mavenId = new MavenId("junit", "junit", myJUnitVersion);
        MavenRepositoryInfo repositoryInfo = new MavenRepositoryInfo("maven", "maven", "http://maven.labs.intellij.net/repo1");
        RepositoryAttachHandler.doResolveInner(getProject(), mavenId, Collections.emptyList(), Collections.singleton(repositoryInfo), artifacts -> {
            for (MavenArtifact artifact : artifacts) {
                ModuleRootModificationUtil.addModuleLibrary(module, VfsUtilCore.pathToUrl(artifact.getPath()));
            }
            return true;
        }, new DumbProgressIndicator());
        ModuleRootModificationUtil.setModuleSdk(module, JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk());
        ModuleRootModificationUtil.updateModel(module, model -> {
            ContentEntry contentEntry = model.addContentEntry(VfsUtilCore.pathToUrl(testDataPath));
            contentEntry.addSourceFolder(VfsUtilCore.pathToUrl(testDataPath + File.separator + "test"), true);
            CompilerModuleExtension moduleExtension = model.getModuleExtension(CompilerModuleExtension.class);
            moduleExtension.inheritCompilerOutputPath(false);
            moduleExtension.setCompilerOutputPathForTests(VfsUtilCore.pathToUrl(testDataPath + File.separator + "out"));
        });
    });
}
Also used : MavenId(org.jetbrains.idea.maven.model.MavenId) ContentEntry(com.intellij.openapi.roots.ContentEntry) MavenRepositoryInfo(org.jetbrains.idea.maven.model.MavenRepositoryInfo) Module(com.intellij.openapi.module.Module) DumbProgressIndicator(com.intellij.openapi.progress.DumbProgressIndicator) MavenArtifact(org.jetbrains.idea.maven.model.MavenArtifact) CompilerModuleExtension(com.intellij.openapi.roots.CompilerModuleExtension) Before(org.junit.Before)

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