|
| 1 | +/* |
| 2 | + * Copyright 2025 DiffPlug |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package com.diffplug.spotless.yaml; |
| 17 | + |
| 18 | +import java.io.File; |
| 19 | + |
| 20 | +import javax.annotation.Nullable; |
| 21 | + |
| 22 | +import com.diffplug.spotless.FormatterStep; |
| 23 | + |
| 24 | +/** |
| 25 | + * This step is a flag which marks that `ConfigurationCacheHackList` should |
| 26 | + * serialize each item individually into `byte[]` array, rather than using normal |
| 27 | + * serialization. |
| 28 | + * |
| 29 | + * The reason to use this is if you are using `toggleOffOn` *and* two kinds of |
| 30 | + * google-java-format (e.g. one for format and the other for imports), then |
| 31 | + * problems with Java's handling of object graphs will cause your up-to-date checks |
| 32 | + * to always fail. `CombinedJavaFormatStepTest` recreates this situation. By adding |
| 33 | + * this step, it will trigger this workaround which fixes the up-to-dateness bug. |
| 34 | + * |
| 35 | + * But, turning it on will break all `custom` steps that use Groovy closures. So |
| 36 | + * by default you get regular serialization. If you're using `toggleOffOn` and having |
| 37 | + * problems with up-to-dateness, then adding this step can be a workaround. |
| 38 | + */ |
| 39 | +public class SerializeToByteArrayHack implements FormatterStep { |
| 40 | + private static final long serialVersionUID = 8071047581828362545L; |
| 41 | + |
| 42 | + @Override |
| 43 | + public String getName() { |
| 44 | + return "hack to force serializing objects to byte array"; |
| 45 | + } |
| 46 | + |
| 47 | + @Nullable |
| 48 | + @Override |
| 49 | + public String format(String rawUnix, File file) throws Exception { |
| 50 | + return null; |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | + public void close() throws Exception { |
| 55 | + |
| 56 | + } |
| 57 | +} |
0 commit comments