mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
external build: configurable log dir; build log default location moved under system/log directory
This commit is contained in:
@@ -103,9 +103,7 @@ import org.jetbrains.jps.model.serialization.JpsGlobalLoader;
|
||||
|
||||
import javax.tools.*;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.Charset;
|
||||
@@ -128,8 +126,6 @@ public class BuildManager implements ApplicationComponent{
|
||||
private static final String COMPILER_PROCESS_JDK_PROPERTY = "compiler.process.jdk";
|
||||
public static final String SYSTEM_ROOT = "compile-server";
|
||||
public static final String TEMP_DIR_NAME = "_temp_";
|
||||
private static final String LOGGER_CONFIG = "log.xml";
|
||||
private static final String DEFAULT_LOGGER_CONFIG = "defaultLogConfig.xml";
|
||||
private static final int MAKE_TRIGGER_DELAY = 300 /*300 ms*/;
|
||||
private static final int DOCUMENT_SAVE_TRIGGER_DELAY = 1500 /*1.5 sec*/;
|
||||
private final boolean IS_UNIT_TEST_MODE;
|
||||
@@ -841,10 +837,10 @@ public class BuildManager implements ApplicationComponent{
|
||||
}
|
||||
}
|
||||
|
||||
cmdLine.addParameter("-D" + GlobalOptions.LOG_DIR_OPTION + "=" + FileUtil.toSystemIndependentName(getBuildLogDirectory().getAbsolutePath()));
|
||||
|
||||
final File workDirectory = getBuildSystemDirectory();
|
||||
workDirectory.mkdirs();
|
||||
ensureLogConfigExists(workDirectory);
|
||||
|
||||
cmdLine.addParameter("-Djava.io.tmpdir=" + FileUtil.toSystemIndependentName(workDirectory.getPath()) + "/" + TEMP_DIR_NAME);
|
||||
|
||||
final List<String> cp = ClasspathBootstrap.getBuildProcessApplicationClasspath();
|
||||
@@ -881,6 +877,10 @@ public class BuildManager implements ApplicationComponent{
|
||||
return new File(mySystemDirectory, SYSTEM_ROOT);
|
||||
}
|
||||
|
||||
public File getBuildLogDirectory() {
|
||||
return new File(PathManager.getLogPath(), "build-log");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public File getProjectSystemDirectory(Project project) {
|
||||
final String projectPath = getProjectPath(project);
|
||||
@@ -911,33 +911,6 @@ public class BuildManager implements ApplicationComponent{
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static void ensureLogConfigExists(File workDirectory) {
|
||||
final File logConfig = new File(workDirectory, LOGGER_CONFIG);
|
||||
if (!logConfig.exists()) {
|
||||
FileUtil.createIfDoesntExist(logConfig);
|
||||
try {
|
||||
final InputStream in = BuildMain.class.getResourceAsStream("/" + DEFAULT_LOGGER_CONFIG);
|
||||
if (in != null) {
|
||||
try {
|
||||
final FileOutputStream out = new FileOutputStream(logConfig);
|
||||
try {
|
||||
FileUtil.copy(in, out);
|
||||
}
|
||||
finally {
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void stopListening() {
|
||||
final ChannelGroupFuture closeFuture = myAllOpenChannels.close();
|
||||
closeFuture.awaitUninterruptibly();
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<appender name="file" class="org.apache.log4j.RollingFileAppender">
|
||||
<param name="MaxFileSize" value="20Mb"/>
|
||||
<param name="MaxBackupIndex" value="20"/>
|
||||
<param name="file" value="server.log"/>
|
||||
<param name="file" value="$LOG_FILE_PATH$"/>
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%d [%7r] %6p - %30.30c - %m \n"/>
|
||||
</layout>
|
||||
|
||||
@@ -26,4 +26,5 @@ public interface GlobalOptions {
|
||||
String COMPILE_PARALLEL_OPTION = "compile.parallel";
|
||||
String COMPILE_PARALLEL_MAX_THREADS_OPTION = "compile.parallel.max.threads";
|
||||
String REBUILD_ON_DEPENDENCY_CHANGE_OPTION = "rebuild.on.dependency.change";
|
||||
String LOG_DIR_OPTION = "log.dir";
|
||||
}
|
||||
|
||||
@@ -18,7 +18,9 @@ package org.jetbrains.jps.cmdline;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.xml.DOMConfigurator;
|
||||
import org.jboss.netty.bootstrap.ClientBootstrap;
|
||||
import org.jboss.netty.channel.*;
|
||||
@@ -31,10 +33,11 @@ import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.api.CmdlineProtoUtil;
|
||||
import org.jetbrains.jps.api.CmdlineRemoteProto;
|
||||
import org.jetbrains.jps.api.GlobalOptions;
|
||||
import org.jetbrains.jps.incremental.Utils;
|
||||
import org.jetbrains.jps.service.SharedThreadPool;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.*;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -44,8 +47,11 @@ import java.util.UUID;
|
||||
*/
|
||||
public class BuildMain {
|
||||
public static final Key<String> FORCE_MODEL_LOADING_PARAMETER = Key.create("_force_model_loading");
|
||||
private static final String LOG_FILE_NAME = "log.xml";
|
||||
|
||||
private static final String LOG_CONFIG_FILE_NAME = "build-log.xml";
|
||||
private static final String LOG_FILE_NAME = "build.log";
|
||||
private static final String DEFAULT_LOGGER_CONFIG = "defaultLogConfig.xml";
|
||||
private static final String LOG_FILE_MACRO = "$LOG_FILE_PATH$";
|
||||
private static final Logger LOG;
|
||||
static {
|
||||
initLoggers();
|
||||
@@ -202,8 +208,18 @@ public class BuildMain {
|
||||
}
|
||||
|
||||
private static void initLoggers() {
|
||||
if (new File(LOG_FILE_NAME).exists()) {
|
||||
DOMConfigurator.configure(LOG_FILE_NAME);
|
||||
try {
|
||||
final String logDir = System.getProperty(GlobalOptions.LOG_DIR_OPTION, null);
|
||||
final File configFile = logDir != null? new File(logDir, LOG_CONFIG_FILE_NAME) : new File(LOG_CONFIG_FILE_NAME);
|
||||
ensureLogConfigExists(configFile);
|
||||
String text = FileUtil.loadFile(configFile);
|
||||
final String logFile = logDir != null? new File(logDir, LOG_FILE_NAME).getAbsolutePath() : LOG_FILE_NAME;
|
||||
text = StringUtil.replace(text, LOG_FILE_MACRO, StringUtil.replace(logFile, "\\", "\\\\"));
|
||||
new DOMConfigurator().doConfigure(new StringReader(text), LogManager.getLoggerRepository());
|
||||
}
|
||||
catch (IOException e) {
|
||||
System.err.println("Failed to configure logging: ");
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
|
||||
Logger.setFactory(new Logger.Factory() {
|
||||
@@ -261,4 +277,30 @@ public class BuildMain {
|
||||
});
|
||||
}
|
||||
|
||||
private static void ensureLogConfigExists(final File logConfig) {
|
||||
if (!logConfig.exists()) {
|
||||
FileUtil.createIfDoesntExist(logConfig);
|
||||
try {
|
||||
final InputStream in = BuildMain.class.getResourceAsStream("/" + DEFAULT_LOGGER_CONFIG);
|
||||
if (in != null) {
|
||||
try {
|
||||
final FileOutputStream out = new FileOutputStream(logConfig);
|
||||
try {
|
||||
FileUtil.copy(in, out);
|
||||
}
|
||||
finally {
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user