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;
}
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;
}
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);
}
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;
}
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"));
});
});
}
Aggregations