Skip to content

Commit

Permalink
Using custom in a gradle script now works with and without the conf…
Browse files Browse the repository at this point in the history
…iguration cache.
  • Loading branch information
nedtwigg committed Jan 3, 2025
1 parent ce33f86 commit eaf0e71
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2024 DiffPlug
* Copyright 2016-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -457,12 +457,11 @@ protected Integer calculateState() throws Exception {
*/
public void custom(String name, Closure<String> formatter) {
requireNonNull(formatter, "formatter");
Closure<String> dehydrated = formatter.dehydrate();
custom(name, new ClosureFormatterFunc(dehydrated));
custom(name, new ClosureFormatterFunc(formatter));
}

static class ClosureFormatterFunc implements FormatterFunc, Serializable {
private final Closure<String> closure;
private Closure<String> closure;

ClosureFormatterFunc(Closure<String> closure) {
this.closure = closure;
Expand All @@ -472,6 +471,14 @@ static class ClosureFormatterFunc implements FormatterFunc, Serializable {
public String apply(String unixNewlines) {
return closure.call(unixNewlines);
}

private void writeObject(java.io.ObjectOutputStream stream) throws java.io.IOException {
stream.writeObject(closure.dehydrate());
}

private void readObject(java.io.ObjectInputStream stream) throws java.io.IOException, ClassNotFoundException {
this.closure = (Closure<String>) stream.readObject();
}
}

/**
Expand Down

0 comments on commit eaf0e71

Please sign in to comment.