compile server: don't throw exception if there are errors in project configuration

This commit is contained in:
nik
2012-02-09 16:58:52 +04:00
parent 241c19c0e2
commit 8dc77f1d2a
7 changed files with 69 additions and 37 deletions
@@ -17,6 +17,7 @@ import org.jetbrains.jps.api.GlobalLibrary;
import org.jetbrains.jps.api.SdkLibrary;
import org.jetbrains.jps.artifacts.Artifact;
import org.jetbrains.jps.idea.IdeaProjectLoader;
import org.jetbrains.jps.idea.SystemOutErrorReporter;
import org.jetbrains.jps.incremental.*;
import org.jetbrains.jps.incremental.messages.BuildMessage;
import org.jetbrains.jps.incremental.messages.CompilerMessage;
@@ -205,7 +206,7 @@ class ServerState {
final Map<String, Artifact> artifactMap = pd.project.getArtifacts();
for (String name : artifactNames) {
final Artifact artifact = artifactMap.get(name);
if (!StringUtil.isEmpty(artifact.getOutputPath())) {
if (artifact != null && !StringUtil.isEmpty(artifact.getOutputPath())) {
artifacts.add(artifact);
}
}
@@ -331,7 +332,7 @@ class ServerState {
//String root = dirBased ? projectPath : projectFile.getParent();
final String loadPath = isDirectoryBased(projectFile) ? new File(projectFile, IDEA_PROJECT_DIRNAME).getPath() : projectPath;
IdeaProjectLoader.loadFromPath(project, loadPath, myPathVariables, getStartupScript());
IdeaProjectLoader.loadFromPath(project, loadPath, myPathVariables, getStartupScript(), new SystemOutErrorReporter(false));
final String globalEncoding = myGlobalEncoding;
if (globalEncoding != null && project.getProjectCharset() == null) {
project.setProjectCharset(globalEncoding);
@@ -58,6 +58,7 @@ class ArtifactLayoutElement extends ComplexLayoutElement {
Artifact artifact = project.artifacts[artifactName]
if (artifact == null) {
errorReporter.error("unknown artifact: $artifactName")
return []
}
def root = artifact.rootElement
if (root instanceof RootElement) {
@@ -58,12 +58,14 @@ class ArtifactLoader {
def name = tag."@name"
if (project.modules[name] == null) {
errorReporter.error("Unknown module '$name' in '$artifactName' artifact")
return null
}
return new ModuleOutputElement(moduleName: name);
case "module-test-output":
def name = tag."@name"
if (project.modules[name] == null) {
errorReporter.error("Unknown module '$name' in '$artifactName' artifact")
return null
}
return new ModuleTestOutputElement(moduleName: name);
case "library":
@@ -76,6 +78,7 @@ class ArtifactLoader {
}
errorReporter.error("unknown element in '$artifactName' artifact: $id");
return null
}
private LayoutElementTypeService findType(String typeId) {
@@ -118,6 +121,13 @@ class ArtifactLoader {
}
List<LayoutElement> loadChildren(Node node, String artifactName) {
node.element.collect { loadLayoutElement(it, artifactName) }
List<LayoutElement> children = []
node.element.each {
def child = loadLayoutElement(it, artifactName)
if (child != null) {
children << child
}
}
return children
}
}
@@ -0,0 +1,10 @@
package org.jetbrains.jps.idea;
/**
* @author nik
*/
public class CannotLoadProjectException extends RuntimeException {
public CannotLoadProjectException(String message) {
super(message);
}
}
@@ -36,7 +36,7 @@ public class IdeaProjectLoader {
}
public static ProjectMacroExpander loadFromPath(Project project, String path, Map<String, String> pathVariables, String script) {
return loadFromPath(project, path, pathVariables, script, new SystemOutErrorReporter())
return loadFromPath(project, path, pathVariables, script, new SystemOutErrorReporter(true))
}
public static ProjectMacroExpander loadFromPath(Project project, String path, Map<String, String> pathVariables, String script, ProjectLoadingErrorReporter errorReporter) {
@@ -111,12 +111,13 @@ public class IdeaProjectLoader {
def loadFromDirectoryBased(File dir) {
projectMacroExpander = new ProjectMacroExpander(pathVariables, dir.parentFile.absolutePath)
def modulesXml = new File(dir, "modules.xml")
if (!modulesXml.exists()) errorReporter.error("Cannot find modules.xml in $dir")
def miscXml = new File(dir, "misc.xml")
if (!miscXml.exists()) errorReporter.error("Cannot find misc.xml in $dir")
loadProjectJdkAndOutput(new XmlParser(false, false).parse(miscXml))
if (miscXml.exists()) {
loadProjectJdkAndOutput(new XmlParser(false, false).parse(miscXml))
}
else {
errorReporter.error("Cannot find misc.xml in $dir")
}
def encodingsXml = new File(dir, "encodings.xml")
if (encodingsXml.exists()) {
@@ -139,8 +140,15 @@ public class IdeaProjectLoader {
}
}
Node modulesXmlRoot = new XmlParser(false, false).parse(modulesXml)
loadModules(modulesXmlRoot.component[0])
def modulesXml = new File(dir, "modules.xml")
if (modulesXml.exists()) {
Node modulesXmlRoot = new XmlParser(false, false).parse(modulesXml)
loadModules(modulesXmlRoot.component[0])
}
else {
errorReporter.error("Cannot find modules.xml in $dir")
}
def artifactsFolder = new File(dir, "artifacts")
if (artifactsFolder.isDirectory()) {
@@ -505,8 +513,10 @@ public class IdeaProjectLoader {
if (projectOutputPath == null) {
errorReporter.error("Module '$currentModuleName' uses output path inherited from project but project output path is not specified")
}
currentModule.outputPath = FileUtil.toSystemIndependentName(new File(new File(projectOutputPath, "production"), currentModuleName).absolutePath)
currentModule.testOutputPath = FileUtil.toSystemIndependentName(new File(new File(projectOutputPath, "test"), currentModuleName).absolutePath)
else {
currentModule.outputPath = FileUtil.toSystemIndependentName(new File(new File(projectOutputPath, "production"), currentModuleName).absolutePath)
currentModule.testOutputPath = FileUtil.toSystemIndependentName(new File(new File(projectOutputPath, "test"), currentModuleName).absolutePath)
}
}
else {
currentModule.outputPath = moduleMacroExpander.expandMacros(IdeaProjectLoadingUtil.pathFromUrl(componentTag.output[0]?.@url))
@@ -1,24 +0,0 @@
package org.jetbrains.jps.idea
/**
* @author nik
*/
class CannotLoadProjectException extends RuntimeException {
CannotLoadProjectException(String message) {
super(message)
}
}
class SystemOutErrorReporter implements ProjectLoadingErrorReporter {
void error(String message) {
throw new CannotLoadProjectException(message)
}
void warning(String message) {
println("warn: " + message)
}
void info(String message) {
println("info: " + message)
}
}
@@ -0,0 +1,24 @@
package org.jetbrains.jps.idea;
public class SystemOutErrorReporter implements ProjectLoadingErrorReporter {
private boolean myFailOnError;
public SystemOutErrorReporter(boolean failOnError) {
myFailOnError = failOnError;
}
public void error(String message) {
if (myFailOnError) {
throw new CannotLoadProjectException(message);
}
System.out.println("error: " + message);
}
public void warning(String message) {
System.out.println("warn: " + message);
}
public void info(String message) {
System.out.println("info: " + message);
}
}