From 2c0cf5ae161959e10117216c9be2c10fb2fd3a5c Mon Sep 17 00:00:00 2001 From: nik Date: Thu, 18 Dec 2014 21:18:42 +0300 Subject: [PATCH] external build: report problematic file when JPS model cannot be loaded (IDEA-96471, ZD-48285) --- .../jetbrains/jps/cmdline/BuildSession.java | 9 ++++- .../CannotLoadJpsModelException.java | 38 +++++++++++++++++++ .../model/serialization/JpsLoaderBase.java | 4 +- 3 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 jps/model-serialization/src/org/jetbrains/jps/model/serialization/CannotLoadJpsModelException.java diff --git a/jps/jps-builders/src/org/jetbrains/jps/cmdline/BuildSession.java b/jps/jps-builders/src/org/jetbrains/jps/cmdline/BuildSession.java index 1b14e508f5a2..a9e2be40d76d 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/cmdline/BuildSession.java +++ b/jps/jps-builders/src/org/jetbrains/jps/cmdline/BuildSession.java @@ -39,6 +39,7 @@ import org.jetbrains.jps.incremental.fs.BuildFSState; import org.jetbrains.jps.incremental.messages.*; import org.jetbrains.jps.incremental.storage.Timestamps; import org.jetbrains.jps.model.module.JpsModule; +import org.jetbrains.jps.model.serialization.CannotLoadJpsModelException; import org.jetbrains.jps.service.SharedThreadPool; import java.io.*; @@ -565,7 +566,13 @@ final class BuildSession implements Runnable, CanceledStatus { private void finishBuild(Throwable error, boolean hadBuildErrors, boolean doneSomething) { CmdlineRemoteProto.Message lastMessage = null; try { - if (error != null) { + if (error instanceof CannotLoadJpsModelException) { + String text = "Failed to load project configuration: " + StringUtil.decapitalize(error.getMessage()); + String path = ((CannotLoadJpsModelException)error).getFile().getAbsolutePath(); + lastMessage = CmdlineProtoUtil.toMessage(mySessionId, CmdlineProtoUtil.createCompileMessage(BuildMessage.Kind.ERROR, text, path, + -1, -1, -1, -1, -1, -1.0f)); + } + else if (error != null) { Throwable cause = error.getCause(); if (cause == null) { cause = error; diff --git a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/CannotLoadJpsModelException.java b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/CannotLoadJpsModelException.java new file mode 100644 index 000000000000..14c31e8601cf --- /dev/null +++ b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/CannotLoadJpsModelException.java @@ -0,0 +1,38 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.jps.model.serialization; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.io.File; + +/** + * @author nik + */ +public class CannotLoadJpsModelException extends RuntimeException { + @NotNull private final File myFile; + + public CannotLoadJpsModelException(@NotNull File file, @NotNull String message, @Nullable Throwable cause) { + super(message, cause); + myFile = file; + } + + @NotNull + public File getFile() { + return myFile; + } +} diff --git a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/JpsLoaderBase.java b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/JpsLoaderBase.java index cf8c0cba3667..5bac18442d7d 100644 --- a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/JpsLoaderBase.java +++ b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/JpsLoaderBase.java @@ -74,10 +74,10 @@ public abstract class JpsLoaderBase { return element; } catch (JDOMException e) { - throw new RuntimeException("Cannot parse xml file " + file.getAbsolutePath() + ": " + e.getMessage(), e); + throw new CannotLoadJpsModelException(file, "Cannot parse xml file " + file.getAbsolutePath() + ": " + e.getMessage(), e); } catch (IOException e) { - throw new RuntimeException("Cannot read file " + file.getAbsolutePath() + ": " + e.getMessage(), e); + throw new CannotLoadJpsModelException(file, "Cannot read file " + file.getAbsolutePath() + ": " + e.getMessage(), e); } }