Skip to content

Commit

Permalink
fix ci extract inner class
Browse files Browse the repository at this point in the history
  • Loading branch information
timlueg committed Jul 28, 2024
1 parent 48e88a5 commit 0fb1f4c
Showing 1 changed file with 50 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,44 +57,15 @@ public Timestamp getStartTime() {
}

@Override
@IgnoreJRERequirement
public String getCallerClassName(final int depth) {
StackWalker walker = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
return walker.walk(new Function<Stream<StackFrame>, String>() {
@Override
public String apply(final Stream<StackFrame> frames) {
return frames.skip(depth)
.findFirst()
.map(new Function<StackFrame, String>() {
@Override
public String apply(final StackFrame stackFrame) {
return stackFrame.getClassName();
}
})
.orElse(null);
}
});
return walker.walk(new ClassNameExtractorByDepth(depth));
}

@Override
@IgnoreJRERequirement
public String getCallerClassName(final String loggerClassName) {
return StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE).walk(new Function<Stream<StackFrame>, String>() {
@Override
public String apply(final Stream<StackFrame> stream) {
return stream.map(new Function<StackFrame, String>() {
@Override
public String apply(final StackFrame stackFrame) {
return stackFrame.getClassName();
}
}).dropWhile(new Predicate<String>() {
@Override
public boolean test(final String name) {
return !name.equals(loggerClassName);
}
}).skip(1).findFirst().orElse(null);
}
});
StackWalker walker = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
return walker.walk(new ClassNameExtractorByLoggerClassName(loggerClassName));
}

@Override
Expand Down Expand Up @@ -133,6 +104,52 @@ private static ProcessHandle getCurrentProcess() {
}
}

@IgnoreJRERequirement
private static class ClassNameExtractorByDepth implements Function<Stream<StackFrame>, String> {
private final int depth;

private ClassNameExtractorByDepth(int depth) {
this.depth = depth;
}

@Override
public String apply(final Stream<StackFrame> frames) {
return frames.skip(depth)
.findFirst()
.map(new Function<StackFrame, String>() {
@Override
public String apply(StackFrame stackFrame) {
return stackFrame.getClassName();
}
})
.orElse(null);
}
}

@IgnoreJRERequirement
private static final class ClassNameExtractorByLoggerClassName implements Function<Stream<StackFrame>, String> {
private final String loggerClassName;

private ClassNameExtractorByLoggerClassName(String loggerClassName) {
this.loggerClassName = loggerClassName;
}

@Override
public String apply(final Stream<StackFrame> stream) {
return stream.map(new Function<StackFrame, String>() {
@Override
public String apply(final StackFrame stackFrame) {
return stackFrame.getClassName();
}
}).dropWhile(new Predicate<String>() {
@Override
public boolean test(final String name) {
return !name.equals(loggerClassName);
}
}).skip(1).findFirst().orElse(null);
}
}

/**
* Extractor for extracting a stack frame from stack trace at a defined index.
*/
Expand Down Expand Up @@ -192,5 +209,5 @@ public StackFrame apply(final Stream<StackFrame> stream) {
return null;
}
}

}

0 comments on commit 0fb1f4c

Please sign in to comment.