All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.freefair.gradle.plugins.lombok.internal.CleanLombokConfig Maven / Gradle / Ivy

The newest version!
package io.freefair.gradle.plugins.lombok.internal;

import io.freefair.gradle.plugins.lombok.tasks.LombokConfig;
import lombok.SneakyThrows;
import org.gradle.api.Action;
import org.gradle.api.NonNullApi;
import org.gradle.api.Task;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author Lars Grefer
 */
@NonNullApi
public class CleanLombokConfig implements Action {

    @Override
    @SneakyThrows(IOException.class)
    public void execute(Task task) {
        LombokConfig lombokConfig = (LombokConfig) task;

        Path file = lombokConfig.getOutputFile().get().getAsFile().toPath();

        List filtered;
        try (Stream lines = Files.lines(file)) {
            filtered = lines.filter(line -> line.contains("="))
                    .sorted()
                    .distinct()
                    .collect(Collectors.toList());
        }
        Files.write(file, filtered);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy