mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
gant tool for new JPS builders: processing build messages
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
def ctx = context(scope: scriptScope(), filetypes : ["gant"])
|
||||
|
||||
contributor ([ctx], {
|
||||
property name:"project", type:"org.jetbrains.jps.model.JpsProject"
|
||||
property name:"global", type:"org.jetbrains.jps.model.JpsGlobal"
|
||||
property name:"projectBuilder", type:"org.jetbrains.jps.gant.JpsGantProjectBuilder"
|
||||
method name:"jdk", type:"void", params:[name:"String", jdkPath:"String"]
|
||||
method name:"jdk", type:"void", params:[name:"String", jdkPath:"String", initializer:{}]
|
||||
|
||||
method name:"layout", type:"org.jetbrains.jps.gant.LayoutInfo", params: [name:"String", layout:{}]
|
||||
method name:"module", type:"void", params: [name:"String"]
|
||||
method name:"module", type:"void", params: [name:"String", layout:{}]
|
||||
["jar", "dir", "zip"].each { methodName ->
|
||||
method name:methodName, type:"void", params: [name:"String", layout:{}]
|
||||
}
|
||||
})
|
||||
@@ -104,16 +104,8 @@ public class Standalone {
|
||||
return;
|
||||
}
|
||||
|
||||
runBuild(loader, dataStorageRoot, buildType, modulesSet, artifactsList, true);
|
||||
}
|
||||
|
||||
public static void runBuild(JpsModelLoader loader, final File dataStorageRoot, BuildType buildType, Set<String> modulesSet,
|
||||
List<String> artifactsList, final boolean includeTests) {
|
||||
final BuildRunner buildRunner = new BuildRunner(loader, modulesSet, buildType, artifactsList, Collections.<String>emptyList(), Collections.<String, String>emptyMap());
|
||||
final ConsoleMessageHandler messageHandler = new ConsoleMessageHandler();
|
||||
try {
|
||||
ProjectDescriptor descriptor = buildRunner.load(messageHandler, dataStorageRoot, new BuildFSState(true));
|
||||
buildRunner.runBuild(descriptor, CanceledStatus.NULL, null, messageHandler, includeTests);
|
||||
runBuild(loader, dataStorageRoot, buildType, modulesSet, artifactsList, true, new ConsoleMessageHandler());
|
||||
}
|
||||
catch (Throwable t) {
|
||||
System.err.println("Internal error: " + t.getMessage());
|
||||
@@ -121,6 +113,13 @@ public class Standalone {
|
||||
}
|
||||
}
|
||||
|
||||
public static void runBuild(JpsModelLoader loader, final File dataStorageRoot, BuildType buildType, Set<String> modulesSet,
|
||||
List<String> artifactsList, final boolean includeTests, final MessageHandler messageHandler) throws Exception {
|
||||
final BuildRunner buildRunner = new BuildRunner(loader, modulesSet, buildType, artifactsList, Collections.<String>emptyList(), Collections.<String, String>emptyMap());
|
||||
ProjectDescriptor descriptor = buildRunner.load(messageHandler, dataStorageRoot, new BuildFSState(true));
|
||||
buildRunner.runBuild(descriptor, CanceledStatus.NULL, null, messageHandler, includeTests);
|
||||
}
|
||||
|
||||
private static class ConsoleMessageHandler implements MessageHandler {
|
||||
@Override
|
||||
public void processMessage(BuildMessage msg) {
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.jetbrains.jps.gant;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class DefaultBuildInfoPrinter implements BuildInfoPrinter {
|
||||
@Override
|
||||
public void printProgressMessage(JpsGantProjectBuilder project, String message) {
|
||||
project.info(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printCompilationErrors(JpsGantProjectBuilder project, String compilerName, String messages) {
|
||||
project.error(messages);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printCompilationFinish(JpsGantProjectBuilder project, String compilerName) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printCompilationStart(JpsGantProjectBuilder project, String compilerName) {
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,18 @@
|
||||
package org.jetbrains.jps.gant;
|
||||
|
||||
import com.intellij.openapi.diagnostic.DefaultLogger;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.Project;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.api.BuildType;
|
||||
import org.jetbrains.jps.build.Standalone;
|
||||
import org.jetbrains.jps.cmdline.JpsModelLoader;
|
||||
import org.jetbrains.jps.incremental.MessageHandler;
|
||||
import org.jetbrains.jps.incremental.messages.BuildMessage;
|
||||
import org.jetbrains.jps.incremental.messages.CompilerMessage;
|
||||
import org.jetbrains.jps.model.JpsModel;
|
||||
import org.jetbrains.jps.model.java.JpsJavaClasspathKind;
|
||||
import org.jetbrains.jps.model.java.JpsJavaDependenciesEnumerator;
|
||||
@@ -26,7 +33,7 @@ public class JpsGantProjectBuilder {
|
||||
private File myDataStorageRoot;
|
||||
private JpsModelLoader myModelLoader;
|
||||
private boolean myDryRun;
|
||||
private BuildInfoPrinter myBuildInfoPrinter;
|
||||
private BuildInfoPrinter myBuildInfoPrinter = new DefaultBuildInfoPrinter();
|
||||
|
||||
public JpsGantProjectBuilder(Project project, JpsModel model, org.jetbrains.jps.Project oldProject) {
|
||||
myProject = project;
|
||||
@@ -66,11 +73,11 @@ public class JpsGantProjectBuilder {
|
||||
myBuildInfoPrinter = printer;
|
||||
}
|
||||
|
||||
public void setUseInProcessJavac() {
|
||||
public void setUseInProcessJavac(boolean value) {
|
||||
//doesn't make sense for new builders
|
||||
}
|
||||
|
||||
public void setArrangeModuleCyclesOutputs() {
|
||||
public void setArrangeModuleCyclesOutputs(boolean value) {
|
||||
//doesn't make sense for new builders
|
||||
}
|
||||
|
||||
@@ -78,6 +85,10 @@ public class JpsGantProjectBuilder {
|
||||
throw new BuildException(message);
|
||||
}
|
||||
|
||||
public void error(Throwable t) {
|
||||
throw new BuildException(t);
|
||||
}
|
||||
|
||||
public void warning(String message) {
|
||||
myProject.log(message, Project.MSG_WARN);
|
||||
}
|
||||
@@ -87,12 +98,11 @@ public class JpsGantProjectBuilder {
|
||||
}
|
||||
|
||||
public void stage(String message) {
|
||||
if (myBuildInfoPrinter != null) {
|
||||
myBuildInfoPrinter.printProgressMessage(this, message);
|
||||
}
|
||||
else {
|
||||
myProject.log(message, Project.MSG_INFO);
|
||||
}
|
||||
myBuildInfoPrinter.printProgressMessage(this, message);
|
||||
}
|
||||
|
||||
public File getDataStorageRoot() {
|
||||
return myDataStorageRoot;
|
||||
}
|
||||
|
||||
public void setDataStorageRoot(File dataStorageRoot) {
|
||||
@@ -151,15 +161,30 @@ public class JpsGantProjectBuilder {
|
||||
|
||||
private void runBuild(final Set<String> modulesSet, boolean includeTests) {
|
||||
if (!myDryRun) {
|
||||
info("Starting build, caches are saved to " + myDataStorageRoot.getAbsolutePath());
|
||||
Standalone.runBuild(myModelLoader, myDataStorageRoot, BuildType.PROJECT_REBUILD, modulesSet, Collections.<String>emptyList(),
|
||||
includeTests);
|
||||
final AntMessageHandler messageHandler = new AntMessageHandler();
|
||||
Logger.setFactory(new AntLoggerFactory(messageHandler));
|
||||
info("Starting build: modules = " + modulesSet + ", caches are saved to " + myDataStorageRoot.getAbsolutePath());
|
||||
try {
|
||||
Standalone.runBuild(myModelLoader, myDataStorageRoot, BuildType.PROJECT_REBUILD, modulesSet, Collections.<String>emptyList(),
|
||||
includeTests, messageHandler);
|
||||
}
|
||||
catch (Throwable e) {
|
||||
error(e);
|
||||
}
|
||||
}
|
||||
else {
|
||||
info("Building skipped as we're running dry");
|
||||
}
|
||||
}
|
||||
|
||||
public String moduleOutput(JpsModule module) {
|
||||
return getModuleOutput(module, false);
|
||||
}
|
||||
|
||||
public String moduleTestsOutput(JpsModule module) {
|
||||
return getModuleOutput(module, true);
|
||||
}
|
||||
|
||||
public String getModuleOutput(JpsModule module, boolean forTests) {
|
||||
File directory = JpsJavaExtensionService.getInstance().getOutputDirectory(module, forTests);
|
||||
return directory != null ? directory.getAbsolutePath() : null;
|
||||
@@ -174,4 +199,59 @@ public class JpsGantProjectBuilder {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private class AntMessageHandler implements MessageHandler {
|
||||
@Override
|
||||
public void processMessage(BuildMessage msg) {
|
||||
BuildMessage.Kind kind = msg.getKind();
|
||||
String text = msg.getMessageText();
|
||||
switch (kind) {
|
||||
case ERROR:
|
||||
String compilerName = msg instanceof CompilerMessage ? ((CompilerMessage)msg).getCompilerName() : "";
|
||||
myBuildInfoPrinter.printCompilationErrors(JpsGantProjectBuilder.this, compilerName, text);
|
||||
break;
|
||||
case WARNING:
|
||||
warning(text);
|
||||
break;
|
||||
case INFO:
|
||||
if (!text.isEmpty()) {
|
||||
info(text);
|
||||
}
|
||||
break;
|
||||
case PROGRESS:
|
||||
myBuildInfoPrinter.printProgressMessage(JpsGantProjectBuilder.this, text);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class AntLoggerFactory implements Logger.Factory {
|
||||
private static final String COMPILER_NAME = "build runner";
|
||||
|
||||
private final AntMessageHandler myMessageHandler;
|
||||
|
||||
public AntLoggerFactory(AntMessageHandler messageHandler) {
|
||||
myMessageHandler = messageHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger getLoggerInstance(String category) {
|
||||
return new DefaultLogger(category) {
|
||||
@Override
|
||||
public void error(@NonNls String message, @Nullable Throwable t, @NonNls String... details) {
|
||||
if (t != null) {
|
||||
myMessageHandler.processMessage(new CompilerMessage(COMPILER_NAME, t));
|
||||
}
|
||||
else {
|
||||
myMessageHandler.processMessage(new CompilerMessage(COMPILER_NAME, BuildMessage.Kind.ERROR, message));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(@NonNls String message, @Nullable Throwable t) {
|
||||
myMessageHandler.processMessage(new CompilerMessage(COMPILER_NAME, BuildMessage.Kind.WARNING, message));
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +89,10 @@ final class JpsGantTool {
|
||||
IdeaProjectLoader.loadFromPath(oldProject, path, [:])
|
||||
JpsProjectLoader.loadProject(model.project, [:], path)
|
||||
builder.exportModuleOutputProperties();
|
||||
builder.setDataStorageRoot(Utils.getDataStorageRoot(path))
|
||||
if (builder.getDataStorageRoot() == null) {
|
||||
builder.setDataStorageRoot(Utils.getDataStorageRoot(path))
|
||||
}
|
||||
builder.info("Loaded project " + path + ": " + model.getProject().getModules().size() + " modules, " + model.getProject().getLibraryCollection().getLibraries().size() + " libraries")
|
||||
}
|
||||
|
||||
private void createJavaSdk(JpsGlobal global, String name, String homePath, Closure initializer) {
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package org.jetbrains.jps.idea;
|
||||
|
||||
import groovy.lang.Script;
|
||||
import org.jetbrains.jps.gant.JpsGantTool;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class IdeaProjectLoader {
|
||||
//todo[nik] inline this method later
|
||||
public static String guessHome(Script script) {
|
||||
return JpsGantTool.guessHome(script);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user