forked from MobiVM/robovm
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request MobiVM#707 from dkimitsa/maintenance/gradle
* maintenance -- gradle
- Loading branch information
Showing
11 changed files
with
134 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
plugins/gradle/src/main/java/org/robovm/gradle/RoboVMGradleException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.robovm.gradle; | ||
|
||
import org.gradle.api.GradleException; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class RoboVMGradleException extends GradleException { | ||
public RoboVMGradleException() { | ||
} | ||
|
||
public RoboVMGradleException(String message) { | ||
super(message); | ||
} | ||
|
||
public RoboVMGradleException(String message, @Nullable Throwable cause) { | ||
super(buildMessage(message, cause), cause); | ||
} | ||
|
||
@Override | ||
public String getLocalizedMessage() { | ||
return super.getLocalizedMessage(); | ||
} | ||
|
||
private static String buildMessage(String message, Throwable cause) { | ||
if (cause == null) | ||
return message; | ||
|
||
try { | ||
// combine all cause messages into single multi-line string | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append(message); | ||
Set<Throwable> visitedCause = new HashSet<>(); | ||
Throwable c = cause; | ||
String lastMessage = message; | ||
int deep = 10; | ||
while (c != null && !visitedCause.contains(c) && deep > 0) { | ||
if (visitedCause.contains(c)) | ||
break; | ||
|
||
visitedCause.add(c); | ||
deep--; | ||
String m = c.getLocalizedMessage(); | ||
if (m != null && !m.isEmpty() && (lastMessage == null || !lastMessage.equals(m))) { | ||
sb.append('\n'); | ||
sb.append(m); | ||
lastMessage = m; | ||
} | ||
|
||
if (c instanceof RoboVMGradleException) { | ||
// its localized message has all causes already built, nothing to add there | ||
break; | ||
} | ||
|
||
c = c.getCause(); | ||
} | ||
return sb.toString(); | ||
} catch (Exception ignored) { | ||
return message; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.