mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
maven compiling tests: use CompilerTester to ensure that project configuration files are saved before starting build
This commit is contained in:
@@ -46,18 +46,24 @@ import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class CompilerTester {
|
||||
|
||||
private Module myModule;
|
||||
private Project myProject;
|
||||
private List<Module> myModules;
|
||||
private TempDirTestFixture myMainOutput;
|
||||
|
||||
public CompilerTester(Module module) throws Exception {
|
||||
myModule = module;
|
||||
this(module.getProject(), Collections.singletonList(module));
|
||||
}
|
||||
|
||||
public CompilerTester(Project project, List<Module> modules) throws Exception {
|
||||
myProject = project;
|
||||
myModules = modules;
|
||||
myMainOutput = new TempDirTestFixtureImpl();
|
||||
myMainOutput.setUp();
|
||||
|
||||
@@ -67,10 +73,11 @@ public class CompilerTester {
|
||||
//noinspection ConstantConditions
|
||||
CompilerProjectExtension.getInstance(getProject()).setCompilerOutputUrl(myMainOutput.findOrCreateDir("out").getUrl());
|
||||
CompilerTestUtil.enableExternalCompiler();
|
||||
ModuleRootModificationUtil.setModuleSdk(myModule, JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk());
|
||||
for (Module module : myModules) {
|
||||
ModuleRootModificationUtil.setModuleSdk(module, JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk());
|
||||
}
|
||||
}
|
||||
}.execute();
|
||||
|
||||
}
|
||||
|
||||
public void tearDown() {
|
||||
@@ -84,12 +91,12 @@ public class CompilerTester {
|
||||
}
|
||||
finally {
|
||||
myMainOutput = null;
|
||||
myModule = null;
|
||||
myModules = null;
|
||||
}
|
||||
}
|
||||
|
||||
private Project getProject() {
|
||||
return myModule.getProject();
|
||||
return myProject;
|
||||
}
|
||||
|
||||
public void deleteClassFile(final String className) throws IOException {
|
||||
@@ -173,6 +180,15 @@ public class CompilerTester {
|
||||
});
|
||||
}
|
||||
|
||||
public List<CompilerMessage> make(final CompileScope scope) {
|
||||
return runCompiler(new Consumer<ErrorReportingCallback>() {
|
||||
@Override
|
||||
public void consume(ErrorReportingCallback callback) {
|
||||
CompilerManager.getInstance(getProject()).make(scope, callback);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public List<CompilerMessage> compileFiles(final VirtualFile... files) {
|
||||
return runCompiler(new Consumer<ErrorReportingCallback>() {
|
||||
@Override
|
||||
@@ -192,11 +208,13 @@ public class CompilerTester {
|
||||
try {
|
||||
getProject().save();
|
||||
CompilerTestUtil.saveApplicationSettings();
|
||||
final VirtualFile moduleFile = myModule.getModuleFile();
|
||||
File ioFile = VfsUtil.virtualToIoFile(moduleFile);
|
||||
if (!ioFile.exists()) {
|
||||
getProject().save();
|
||||
assert ioFile.exists() : "File does not exist: " + ioFile.getPath();
|
||||
for (Module module : myModules) {
|
||||
final VirtualFile moduleFile = module.getModuleFile();
|
||||
File ioFile = VfsUtil.virtualToIoFile(moduleFile);
|
||||
if (!ioFile.exists()) {
|
||||
getProject().save();
|
||||
assert ioFile.exists() : "File does not exist: " + ioFile.getPath();
|
||||
}
|
||||
}
|
||||
runnable.consume(callback);
|
||||
}
|
||||
|
||||
@@ -521,7 +521,7 @@ public abstract class MavenImportingTestCase extends MavenTestCase {
|
||||
}
|
||||
|
||||
protected Sdk setupJdkForModule(final String moduleName) {
|
||||
final Sdk sdk = true ? JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk() : createJdk("Java 1.5");
|
||||
final Sdk sdk = JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
|
||||
ModuleRootModificationUtil.setModuleSdk(getModule(moduleName), sdk);
|
||||
return sdk;
|
||||
}
|
||||
|
||||
+16
-32
@@ -16,36 +16,33 @@
|
||||
package org.jetbrains.idea.maven.compiler;
|
||||
|
||||
import com.intellij.compiler.CompilerTestUtil;
|
||||
import com.intellij.compiler.CompilerWorkspaceConfiguration;
|
||||
import com.intellij.compiler.artifacts.ArtifactsTestUtil;
|
||||
import com.intellij.compiler.impl.ModuleCompileScope;
|
||||
import com.intellij.openapi.compiler.CompileContext;
|
||||
import com.intellij.openapi.compiler.CompileScope;
|
||||
import com.intellij.openapi.compiler.CompileStatusNotification;
|
||||
import com.intellij.openapi.compiler.CompilerManager;
|
||||
import com.intellij.openapi.compiler.CompilerMessage;
|
||||
import com.intellij.openapi.compiler.CompilerMessageCategory;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.packaging.artifacts.Artifact;
|
||||
import com.intellij.packaging.impl.compiler.ArtifactCompileScope;
|
||||
import com.intellij.util.concurrency.Semaphore;
|
||||
import com.intellij.testFramework.CompilerTester;
|
||||
import com.intellij.util.io.TestFileSystemBuilder;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.idea.maven.MavenImportingTestCase;
|
||||
import org.jetbrains.idea.maven.project.MavenProjectsManager;
|
||||
import org.jetbrains.idea.maven.project.MavenResourceCompilerConfigurationGenerator;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class MavenCompilingTestCase extends MavenImportingTestCase {
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
try {
|
||||
CompilerTestUtil.disableExternalCompiler(myProject);
|
||||
@@ -67,39 +64,26 @@ public abstract class MavenCompilingTestCase extends MavenImportingTestCase {
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Module module : scope.getAffectedModules()) {
|
||||
setupJdkForModule(module.getName());
|
||||
}
|
||||
new MavenResourceCompilerConfigurationGenerator(myProject, MavenProjectsManager.getInstance(myProject).getProjectsTreeForTests()).generateBuildConfiguration(false);
|
||||
}
|
||||
});
|
||||
|
||||
CompilerWorkspaceConfiguration.getInstance(myProject).CLEAR_OUTPUT_DIRECTORY = true;
|
||||
|
||||
final Semaphore semaphore = new Semaphore();
|
||||
semaphore.down();
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
CompilerTestUtil.enableExternalCompiler();
|
||||
CompilerManager.getInstance(myProject).make(scope, new CompileStatusNotification() {
|
||||
@Override
|
||||
public void finished(boolean aborted, int errors, int warnings, CompileContext compileContext) {
|
||||
//assertFalse(aborted);
|
||||
//assertEquals(collectMessages(compileContext, CompilerMessageCategory.ERROR), 0, errors);
|
||||
//assertEquals(collectMessages(compileContext, CompilerMessageCategory.WARNING), 0, warnings);
|
||||
semaphore.up();
|
||||
try {
|
||||
CompilerTester tester = new CompilerTester(myProject, Arrays.asList(scope.getAffectedModules()));
|
||||
try {
|
||||
List<CompilerMessage> messages = tester.make(scope);
|
||||
for (CompilerMessage message : messages) {
|
||||
if (message.getCategory() == CompilerMessageCategory.ERROR) {
|
||||
fail("Compilation failed with error: " + message.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
while (!semaphore.waitFor(100)) {
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
UIUtil.dispatchAllInvocationEvents();
|
||||
finally {
|
||||
tester.tearDown();
|
||||
}
|
||||
}
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
UIUtil.dispatchAllInvocationEvents();
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user