From 8dc77f1d2a8d9439f7553550d8d6c1999e76989a Mon Sep 17 00:00:00 2001 From: nik Date: Thu, 9 Feb 2012 16:58:26 +0400 Subject: [PATCH] compile server: don't throw exception if there are errors in project configuration --- .../org/jetbrains/jps/server/ServerState.java | 5 ++-- .../jps/artifacts/ComplexLayoutElement.groovy | 1 + .../jetbrains/jps/idea/ArtifactLoader.groovy | 12 +++++++- .../jps/idea/CannotLoadProjectException.java | 10 +++++++ .../jps/idea/IdeaProjectLoader.groovy | 30 ++++++++++++------- .../jps/idea/SystemOutErrorReporter.groovy | 24 --------------- .../jps/idea/SystemOutErrorReporter.java | 24 +++++++++++++++ 7 files changed, 69 insertions(+), 37 deletions(-) create mode 100644 jps/model/src/org/jetbrains/jps/idea/CannotLoadProjectException.java delete mode 100644 jps/model/src/org/jetbrains/jps/idea/SystemOutErrorReporter.groovy create mode 100644 jps/model/src/org/jetbrains/jps/idea/SystemOutErrorReporter.java diff --git a/jps/jps-builders/src/org/jetbrains/jps/server/ServerState.java b/jps/jps-builders/src/org/jetbrains/jps/server/ServerState.java index 444918206990..d8b201ba316c 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/server/ServerState.java +++ b/jps/jps-builders/src/org/jetbrains/jps/server/ServerState.java @@ -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 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); diff --git a/jps/model/src/org/jetbrains/jps/artifacts/ComplexLayoutElement.groovy b/jps/model/src/org/jetbrains/jps/artifacts/ComplexLayoutElement.groovy index f70e86c7609e..2404c7b889f4 100644 --- a/jps/model/src/org/jetbrains/jps/artifacts/ComplexLayoutElement.groovy +++ b/jps/model/src/org/jetbrains/jps/artifacts/ComplexLayoutElement.groovy @@ -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) { diff --git a/jps/model/src/org/jetbrains/jps/idea/ArtifactLoader.groovy b/jps/model/src/org/jetbrains/jps/idea/ArtifactLoader.groovy index a87d620825f4..85349d528c99 100644 --- a/jps/model/src/org/jetbrains/jps/idea/ArtifactLoader.groovy +++ b/jps/model/src/org/jetbrains/jps/idea/ArtifactLoader.groovy @@ -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 loadChildren(Node node, String artifactName) { - node.element.collect { loadLayoutElement(it, artifactName) } + List children = [] + node.element.each { + def child = loadLayoutElement(it, artifactName) + if (child != null) { + children << child + } + } + return children } } diff --git a/jps/model/src/org/jetbrains/jps/idea/CannotLoadProjectException.java b/jps/model/src/org/jetbrains/jps/idea/CannotLoadProjectException.java new file mode 100644 index 000000000000..0d11ab1f77a0 --- /dev/null +++ b/jps/model/src/org/jetbrains/jps/idea/CannotLoadProjectException.java @@ -0,0 +1,10 @@ +package org.jetbrains.jps.idea; + +/** + * @author nik + */ +public class CannotLoadProjectException extends RuntimeException { + public CannotLoadProjectException(String message) { + super(message); + } +} diff --git a/jps/model/src/org/jetbrains/jps/idea/IdeaProjectLoader.groovy b/jps/model/src/org/jetbrains/jps/idea/IdeaProjectLoader.groovy index 922e9a90061d..96bab165bc75 100644 --- a/jps/model/src/org/jetbrains/jps/idea/IdeaProjectLoader.groovy +++ b/jps/model/src/org/jetbrains/jps/idea/IdeaProjectLoader.groovy @@ -36,7 +36,7 @@ public class IdeaProjectLoader { } public static ProjectMacroExpander loadFromPath(Project project, String path, Map 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 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)) diff --git a/jps/model/src/org/jetbrains/jps/idea/SystemOutErrorReporter.groovy b/jps/model/src/org/jetbrains/jps/idea/SystemOutErrorReporter.groovy deleted file mode 100644 index 619afac8d82a..000000000000 --- a/jps/model/src/org/jetbrains/jps/idea/SystemOutErrorReporter.groovy +++ /dev/null @@ -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) - } -} diff --git a/jps/model/src/org/jetbrains/jps/idea/SystemOutErrorReporter.java b/jps/model/src/org/jetbrains/jps/idea/SystemOutErrorReporter.java new file mode 100644 index 000000000000..df73294214bd --- /dev/null +++ b/jps/model/src/org/jetbrains/jps/idea/SystemOutErrorReporter.java @@ -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); + } +}