Java Code Examples for org.codehaus.groovy.runtime.ResourceGroovyMethods#newPrintWriter()
The following examples show how to use
org.codehaus.groovy.runtime.ResourceGroovyMethods#newPrintWriter() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GenerateLombokConfig.java From gradle-plugins with MIT License | 6 votes |
@TaskAction @SneakyThrows public void generateLombokConfig() { File file = outputFile.getAsFile().get(); if (file.isFile()) { try (Stream<String> lines = Files.lines(file.toPath(), StandardCharsets.ISO_8859_1)) { if (lines.noneMatch(line -> line.startsWith("#") && line.contains("io.freefair.lombok"))) { String message = file + " already exists and was not generated by this task"; getLogger().warn(message); throw new StopExecutionException(message); } } } try (PrintWriter writer = ResourceGroovyMethods.newPrintWriter(file, "ISO-8859-1")) { writer.println("# This file is generated by the 'io.freefair.lombok' Gradle plugin"); properties.get().entrySet().stream() .sorted(Map.Entry.comparingByKey(String.CASE_INSENSITIVE_ORDER)) .forEach(entry -> writer.println(entry.getKey() + " = " + entry.getValue()) ); } }
Example 2
Source File: GenerateLombokConfig.java From gradle-plugins with MIT License | 6 votes |
@TaskAction @SneakyThrows public void generateLombokConfig() { File file = outputFile.getAsFile().get(); if (file.isFile()) { try (Stream<String> lines = Files.lines(file.toPath(), StandardCharsets.ISO_8859_1)) { if (lines.noneMatch(line -> line.startsWith("#") && line.contains("io.freefair.lombok"))) { String message = file + " already exists and was not generated by this task"; getLogger().warn(message); throw new StopExecutionException(message); } } } try (PrintWriter writer = ResourceGroovyMethods.newPrintWriter(file, "ISO-8859-1")) { writer.println("# This file is generated by the 'io.freefair.lombok' Gradle plugin"); properties.get().entrySet().stream() .sorted(Map.Entry.comparingByKey(String.CASE_INSENSITIVE_ORDER)) .forEach(entry -> writer.println(entry.getKey() + " = " + entry.getValue()) ); } }
Example 3
Source File: PropertyDocumentation.java From joinfaces with Apache License 2.0 | 5 votes |
@TaskAction public void generatePropertyDocumentation() throws IOException { ConfigurationMetadataRepository configurationMetadataRepository; configurationMetadataRepository = ConfigurationMetadataRepositoryJsonBuilder.create() .withJsonResource(new FileInputStream(getInputFile().getAsFile().get())) .build(); try (PrintWriter writer = ResourceGroovyMethods.newPrintWriter(getOutputFile().getAsFile().get(), "UTF-8")) { writer.println("[source,properties,indent=0,subs=\"verbatim,attributes,macros\"]"); writer.println("----"); configurationMetadataRepository.getAllGroups().values().stream() .sorted(Comparator.comparing(ConfigurationMetadataGroup::getId)) .forEach(group -> { writer.printf("## %s\n", group.getId()); group.getSources().values() .stream() .map(ConfigurationMetadataSource::getShortDescription) .filter(s -> s != null && !s.isEmpty()) .forEach(d -> writer.printf("# %s\n", d)); group.getProperties().values().stream() .sorted(Comparator.comparing(ConfigurationMetadataProperty::getId)) .forEach(property -> printProperty(writer, property)); writer.println(); writer.flush(); }); writer.println("----"); } }
Example 4
Source File: BomDocumentation.java From joinfaces with Apache License 2.0 | 5 votes |
@TaskAction public void generateBomDocumentation() throws IOException, XmlPullParserException { MavenXpp3Reader reader = new MavenXpp3Reader(); Model model = reader.read(new FileReader(inputFile.getAsFile().get())); try (PrintWriter writer = ResourceGroovyMethods.newPrintWriter(getOutputFile().getAsFile().get(), "UTF-8")) { writer.println("|==="); writer.println("|Group ID |Artifact ID |Version"); model.getDependencyManagement() .getDependencies() .stream() .sorted(Comparator.comparing(Dependency::getGroupId).thenComparing(Dependency::getArtifactId)) .forEach(dependency -> { writer.println(); writer.printf("|`%s`\n", dependency.getGroupId()); writer.printf("|`%s`\n", dependency.getArtifactId()); writer.printf("|%s\n", dependency.getVersion()); }); writer.println("|==="); } }