mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
tests: print debug log from build process
This will help to investigate in case of test failures.
This commit is contained in:
@@ -1314,7 +1314,7 @@ public class BuildManager implements Disposable {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private File getBuildLogDirectory() {
|
||||
public static File getBuildLogDirectory() {
|
||||
return new File(PathManager.getLogPath(), "build-log");
|
||||
}
|
||||
|
||||
|
||||
@@ -23,10 +23,7 @@ import com.intellij.openapi.vfs.newvfs.NewVirtualFile;
|
||||
import com.intellij.packaging.artifacts.Artifact;
|
||||
import com.intellij.packaging.artifacts.ArtifactManager;
|
||||
import com.intellij.packaging.impl.compiler.ArtifactCompileScope;
|
||||
import com.intellij.testFramework.ModuleTestCase;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
import com.intellij.testFramework.VfsTestUtil;
|
||||
import com.intellij.testFramework.*;
|
||||
import com.intellij.util.concurrency.Semaphore;
|
||||
import com.intellij.util.io.TestFileSystemBuilder;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
@@ -250,20 +247,31 @@ public abstract class BaseCompilerTestCase extends ModuleTestCase {
|
||||
};
|
||||
PlatformTestUtil.saveProject(myProject);
|
||||
CompilerTestUtil.saveApplicationSettings();
|
||||
try {
|
||||
CompilerTester.enableDebugLogging();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
action.accept(callback);
|
||||
});
|
||||
|
||||
final long start = System.currentTimeMillis();
|
||||
while (!semaphore.waitFor(10)) {
|
||||
if (System.currentTimeMillis() - start > 5 * 60 * 1000) {
|
||||
throw new RuntimeException("timeout");
|
||||
try {
|
||||
final long start = System.currentTimeMillis();
|
||||
while (!semaphore.waitFor(10)) {
|
||||
if (System.currentTimeMillis() - start > 50 * 60 * 1000) {
|
||||
throw new RuntimeException("timeout");
|
||||
}
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
UIUtil.dispatchAllInvocationEvents();
|
||||
}
|
||||
}
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
UIUtil.dispatchAllInvocationEvents();
|
||||
}
|
||||
}
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
UIUtil.dispatchAllInvocationEvents();
|
||||
finally {
|
||||
CompilerTester.printBuildLog();
|
||||
}
|
||||
|
||||
return result.get();
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
<orderEntry type="module" module-name="intellij.java.execution" exported="" />
|
||||
<orderEntry type="module" module-name="intellij.platform.externalSystem.impl" scope="RUNTIME" />
|
||||
<orderEntry type="library" name="KotlinTest" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.jps.build" />
|
||||
</component>
|
||||
<component name="copyright">
|
||||
<Base>
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.intellij.testFramework;
|
||||
|
||||
import com.intellij.compiler.CompilerManagerImpl;
|
||||
import com.intellij.compiler.CompilerTestUtil;
|
||||
import com.intellij.compiler.server.BuildManager;
|
||||
import com.intellij.diagnostic.ThreadDumper;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.PathMacros;
|
||||
@@ -21,6 +22,7 @@ import com.intellij.openapi.roots.CompilerProjectExtension;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
@@ -40,12 +42,12 @@ import com.intellij.util.io.FileTreePrinterKt;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.cmdline.LogSetup;
|
||||
import org.jetbrains.jps.model.serialization.JpsGlobalLoader;
|
||||
import org.junit.Assert;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
@@ -221,6 +223,7 @@ public class CompilerTester {
|
||||
}
|
||||
}
|
||||
}
|
||||
enableDebugLogging();
|
||||
runnable.consume(callback);
|
||||
});
|
||||
|
||||
@@ -232,6 +235,7 @@ public class CompilerTester {
|
||||
}
|
||||
}
|
||||
|
||||
printBuildLog();
|
||||
callback.throwException();
|
||||
|
||||
if (!((CompilerManagerImpl)CompilerManager.getInstance(getProject())).waitForExternalJavacToTerminate(1, TimeUnit.MINUTES)) {
|
||||
@@ -241,6 +245,45 @@ public class CompilerTester {
|
||||
return callback.getMessages();
|
||||
}
|
||||
|
||||
public static void printBuildLog() {
|
||||
File logDirectory = BuildManager.getBuildLogDirectory();
|
||||
File[] files = logDirectory.listFiles(file -> file.getName().endsWith(".log"));
|
||||
if (files == null || files.length == 0) {
|
||||
LOG.debug("No *.log files in " + logDirectory + " after build");
|
||||
return;
|
||||
}
|
||||
|
||||
Arrays.sort(files, Comparator.comparing(File::getName));
|
||||
for (File file : files) {
|
||||
LOG.debug(file.getName() + ":");
|
||||
try {
|
||||
List<String> lines = FileUtil.loadLines(file);
|
||||
for (String line : lines) {
|
||||
LOG.debug(line);
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.debug("Failed to load contents: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void enableDebugLogging() throws IOException {
|
||||
File logDirectory = BuildManager.getBuildLogDirectory();
|
||||
FileUtil.delete(logDirectory);
|
||||
FileUtil.createDirectory(logDirectory);
|
||||
Properties properties = new Properties();
|
||||
try (InputStream config = LogSetup.readDefaultLogConfig()) {
|
||||
properties.load(config);
|
||||
}
|
||||
|
||||
properties.setProperty("log4j.rootLogger", "debug, file");
|
||||
File logFile = new File(logDirectory, LogSetup.LOG_CONFIG_FILE_NAME);
|
||||
try (OutputStream output = new BufferedOutputStream(new FileOutputStream(logFile))) {
|
||||
properties.store(output, null);
|
||||
}
|
||||
}
|
||||
|
||||
private static void refreshVfs(String path) {
|
||||
VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(path));
|
||||
if (vFile != null) {
|
||||
|
||||
@@ -32,9 +32,8 @@ import java.nio.charset.StandardCharsets;
|
||||
*/
|
||||
public class LogSetup {
|
||||
|
||||
private static final String LOG_CONFIG_FILE_NAME = "build-log.properties";
|
||||
public static final String LOG_CONFIG_FILE_NAME = "build-log.properties";
|
||||
private static final String LOG_FILE_NAME = "build.log";
|
||||
private static final String DEFAULT_LOGGER_CONFIG = "defaultLogConfig.properties";
|
||||
private static final String LOG_FILE_MACRO = "$LOG_FILE_PATH$";
|
||||
|
||||
public static void initLoggers() {
|
||||
@@ -64,7 +63,7 @@ public class LogSetup {
|
||||
private static void ensureLogConfigExists(final File logConfig) throws IOException {
|
||||
if (!logConfig.exists()) {
|
||||
FileUtil.createIfDoesntExist(logConfig);
|
||||
try(InputStream in = LogSetup.class.getResourceAsStream("/" + DEFAULT_LOGGER_CONFIG)) {
|
||||
try(InputStream in = readDefaultLogConfig()) {
|
||||
if (in != null) {
|
||||
try (FileOutputStream out = new FileOutputStream(logConfig)) {
|
||||
FileUtil.copy(in, out);
|
||||
@@ -74,6 +73,10 @@ public class LogSetup {
|
||||
}
|
||||
}
|
||||
|
||||
public static InputStream readDefaultLogConfig() {
|
||||
return LogSetup.class.getResourceAsStream("/defaultLogConfig.properties");
|
||||
}
|
||||
|
||||
private static class MyLoggerFactory implements Logger.Factory {
|
||||
@NotNull
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user