From 73ec4b00f609b42b2e996cbef855ff4039178c5c Mon Sep 17 00:00:00 2001 From: Peter Reutemann Date: Fri, 4 Oct 2019 13:43:37 +1300 Subject: [PATCH 01/17] added support for basic file filtering (similar to the debian-maven-plugin) when adding an explicit file --- .../de/dentrassi/rpm/builder/BeanUtils.java | 151 +++++++++++++++ .../de/dentrassi/rpm/builder/FilterUtils.java | 182 ++++++++++++++++++ .../dentrassi/rpm/builder/PackageEntry.java | 15 +- .../de/dentrassi/rpm/builder/RpmMojo.java | 97 +++++++--- src/site/markdown/entry.md | 23 +++ 5 files changed, 437 insertions(+), 31 deletions(-) create mode 100644 src/main/java/de/dentrassi/rpm/builder/BeanUtils.java create mode 100644 src/main/java/de/dentrassi/rpm/builder/FilterUtils.java diff --git a/src/main/java/de/dentrassi/rpm/builder/BeanUtils.java b/src/main/java/de/dentrassi/rpm/builder/BeanUtils.java new file mode 100644 index 0000000..e38e33f --- /dev/null +++ b/src/main/java/de/dentrassi/rpm/builder/BeanUtils.java @@ -0,0 +1,151 @@ +/******************************************************************************* + * Copyright (c) 2019 University of Waikato, Hamilton, NZ + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * Contributors: + * University of Waikato, Hamilton, NZ - initial API and implementation + *******************************************************************************/ +package de.dentrassi.rpm.builder; + +import org.apache.maven.plugin.logging.Log; + +import java.beans.BeanInfo; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; +import java.lang.reflect.Array; +import java.util.Arrays; +import java.util.List; + +/** + * Bean related operations. + * + * @author FracPete (fracpete at waikato dot ac dot nz) + */ +public class BeanUtils +{ + + /** + * Extracts the properties from an object. + * + * @param log for logging + * @param obj the object to inspect + * @return the properties + */ + public static PropertyDescriptor[] extractProperties(Log log, Object obj) + { + BeanInfo bi; + + if (obj == null) + { + log.warn("Null object provided, can't extract bean properties!"); + return new PropertyDescriptor[0]; + } + + try + { + bi = Introspector.getBeanInfo(obj.getClass()); + return bi.getPropertyDescriptors(); + } + catch (Exception e) + { + log.error("Failed to extract properties from: " + obj.getClass(), e); + return new PropertyDescriptor[0]; + } + } + + /** + * Extracts the value from the Object using the specified property path. + * + * @param log for logging + * @param obj the object to extract the value from + * @param path the property path, broken up + * @return the value, null if failed to located + */ + protected static Object extractValue(Log log, Object obj, List path) + { + PropertyDescriptor[] props; + String current; + int index; + Object value; + + current = path.get(0); + index = -1; + if (current.contains("[") && current.endsWith("]")) + { + index = Integer.parseInt(current.substring(current.indexOf("[") + 1, current.indexOf("]"))); + current = current.substring(0, current.indexOf("[")); + } + + props = extractProperties(log, obj); + for (PropertyDescriptor prop : props) + { + if (prop.getDisplayName().equals(current)) + { + try + { + value = prop.getReadMethod().invoke(obj); + } + catch (Exception e) + { + value = null; + log.error("Failed to obtain value from path '" + path.get(0) + "!", e); + } + + if (index > -1) + { + if (value.getClass().isArray()) + { + value = Array.get(value, index); + } + else if (value instanceof List) + { + value = ((List) value).get(index); + } + else + { + log.error("Cannot handle type (neither array nor list): " + value.getClass()); + } + } + + if (path.size() == 1) + { + return value; + } + else + { + return extractValue(log, value, path.subList(1, path.size())); + } + } + } + + log.warn("Failed to locate path: " + current); + return null; + } + + /** + * Extracts the value from the Object using the specified property path. + * + * @param log for logging + * @param obj the object to extract the value from + * @param path the property path + * @return the value, null if failed to located + */ + public static Object extractValue(Log log, Object obj, String path) + { + String[] parts; + + if (path.contains(".")) + { + parts = path.split("\\."); + } + else + { + parts = new String[]{path}; + } + + return extractValue(log, obj, Arrays.asList(parts)); + } +} diff --git a/src/main/java/de/dentrassi/rpm/builder/FilterUtils.java b/src/main/java/de/dentrassi/rpm/builder/FilterUtils.java new file mode 100644 index 0000000..d6ffe59 --- /dev/null +++ b/src/main/java/de/dentrassi/rpm/builder/FilterUtils.java @@ -0,0 +1,182 @@ +/******************************************************************************* + * Copyright (c) 2019 University of Waikato, Hamilton, NZ + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * Contributors: + * University of Waikato, Hamilton, NZ - initial API and implementation + *******************************************************************************/ +package de.dentrassi.rpm.builder; + +import org.apache.maven.model.Model; +import org.apache.maven.plugin.logging.Log; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; +import java.nio.file.StandardOpenOption; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * For filtering resources, replacing variables with actual values obtained from the model. + * + * @author FracPete (fracpete at waikato dot ac dot nz) + */ +public class FilterUtils +{ + + public static final String PROJECT = "project."; + + /** + * Extracts variables from a line: ${blah} -> blah. + * + * @param log for logging + * @param line the line to process + * @return the variables found + */ + protected static List extractVariables(Log log, String line) + { + List result; + int indexStart; + int indexEnd; + String original; + + original = line; + result = new ArrayList<>(); + while (line.length() > 0) + { + indexStart = line.indexOf("${"); + if (indexStart == -1) + { + line = ""; + } + else + { + if ((indexEnd = line.indexOf("}", indexStart)) == -1) + { + line = ""; + } + else + { + result.add(line.substring(indexStart + 2, indexEnd)); + line = line.substring(indexEnd + 1); + } + } + } + + if (result.size() > 0) + log.debug("Variables extracted from line '" + original + "': " + result); + + return result; + } + + /** + * Obtains the variable value from the model ("project.*"). + * + * @param log for logging + * @param var the variable + * @param model the model to obtain the value from + * @return null if not found or not a string object, otherwise the value + */ + protected static String variableValue(Log log, String var, Model model) + { + Object value; + + if (!var.startsWith(PROJECT)) + { + log.warn("Variable does not start with " + PROJECT + ": " + var); + return null; + } + + value = BeanUtils.extractValue(log, model, var.substring(PROJECT.length())); + if (value == null) + { + log.warn("Failed to extract value for variable: " + var); + return null; + } + else + { + log.debug("Value for variable " + var + ": " + value); + return "" + value; + } + } + + /** + * Filters a file, replacing any project or additional variables in it. + * + * @param log for logging + * @param input the input file + * @param output the output file + * @param model the model to use for resolving "project.*" variables + * @param additional additional variables with associated values + * @throws IOException if reading/writing of file fails + */ + public static void filterFile(Log log, Path input, Path output, Model model, Map additional) throws IOException + { + List lines; + int i; + String line; + List vars; + String value; + boolean updated; + boolean modified; + Map cache; + + lines = Files.readAllLines(input); + cache = new HashMap<>(); + modified = false; + for (i = 0; i < lines.size(); i++) + { + line = lines.get(i); + updated = false; + vars = extractVariables(log, line); + for (String var : vars) + { + if (cache.containsKey(var)) + { + value = cache.get(var); + } + else if (additional.containsKey(var)) + { + value = additional.get(var); + } + else + { + value = variableValue(log, var, model); + } + cache.put(var, value); + + if (value != null) + { + log.debug("Replacing variable '" + var + "' with value '" + value + "' in: " + line); + line = line.replace("${" + var + "}", value); + updated = true; + } + } + if (updated) + { + lines.set(i, line); + modified = true; + } + } + + if (modified) + { + log.debug("Writing filtered file " + input + " to " + output); + Files.createDirectories(output.getParent()); + Files.write(output, lines, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE); + } + else + { + log.debug("Copying unmodified file " + input + " to " + output); + Files.createDirectories(output.getParent()); + Files.copy(input, output, StandardCopyOption.REPLACE_EXISTING); + } + } +} diff --git a/src/main/java/de/dentrassi/rpm/builder/PackageEntry.java b/src/main/java/de/dentrassi/rpm/builder/PackageEntry.java index ccfeef5..f727b02 100644 --- a/src/main/java/de/dentrassi/rpm/builder/PackageEntry.java +++ b/src/main/java/de/dentrassi/rpm/builder/PackageEntry.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016 IBH SYSTEMS GmbH and others. + * Copyright (c) 2016,2019 IBH SYSTEMS GmbH and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBH SYSTEMS GmbH - initial API and implementation + * University of Waikato - added filterFile flag *******************************************************************************/ package de.dentrassi.rpm.builder; @@ -95,6 +96,8 @@ public String toString () private String ruleset; + private boolean filterFile; + public String getName () { return this.name; @@ -155,6 +158,16 @@ public String getRuleset () return this.ruleset; } + public void setFilterFile( final boolean filterFile ) + { + this.filterFile = filterFile; + } + + public boolean getFilterFile() + { + return this.filterFile; + } + @Override public void validate () { diff --git a/src/main/java/de/dentrassi/rpm/builder/RpmMojo.java b/src/main/java/de/dentrassi/rpm/builder/RpmMojo.java index 19a15c7..bf0295c 100644 --- a/src/main/java/de/dentrassi/rpm/builder/RpmMojo.java +++ b/src/main/java/de/dentrassi/rpm/builder/RpmMojo.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016, 2018 IBH SYSTEMS GmbH and others. + * Copyright (c) 2016, 2018, 2019 IBH SYSTEMS GmbH and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -13,32 +13,14 @@ * Lucian Burja - Added setting for creating relocatable RPM packages * Peter Wilkinson - add skip entry flag * Daniel Singhal - Added primary artifact support + * University of Waikato - applying the filterFile flag in fillFromEntryFile *******************************************************************************/ package de.dentrassi.rpm.builder; -import static java.nio.charset.StandardCharsets.US_ASCII; -import static java.nio.file.Files.readAllLines; - -import java.io.File; -import java.io.IOException; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.nio.file.FileAlreadyExistsException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.time.Instant; -import java.time.ZoneOffset; -import java.time.format.DateTimeFormatter; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.function.Supplier; -import java.util.stream.Collectors; - +import com.google.common.base.Strings; +import com.google.common.io.CharSource; +import de.dentrassi.rpm.builder.Naming.Case; +import de.dentrassi.rpm.builder.PackageEntry.Collector; import org.apache.maven.model.License; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; @@ -65,11 +47,30 @@ import org.eclipse.packager.rpm.signature.RsaHeaderSignatureProcessor; import org.eclipse.packager.rpm.signature.SignatureProcessor; -import com.google.common.base.Strings; -import com.google.common.io.CharSource; +import java.io.File; +import java.io.IOException; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.nio.file.FileAlreadyExistsException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.time.Instant; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.function.Consumer; +import java.util.function.Supplier; +import java.util.stream.Collectors; -import de.dentrassi.rpm.builder.Naming.Case; -import de.dentrassi.rpm.builder.PackageEntry.Collector; +import static java.nio.charset.StandardCharsets.US_ASCII; +import static java.nio.file.Files.readAllLines; /** * Build an RPM file @@ -1027,17 +1028,48 @@ private void fillFromEntryDirectory ( final BuilderContext ctx, final PackageEnt ctx.addDirectory ( entry.getName (), makeProvider ( entry, " - " ) ); } + private Map getAdditionalVars() + { + HashMap additional = new HashMap<>(); + additional.put("packageName", packageName); + additional.put("packager", packager); + additional.put("description", description); + additional.put("distribution", distribution); + additional.put("group", group); + additional.put("sourcePackage", sourcePackage); + additional.put("vendor", vendor); + additional.put("version", version); + return additional; + } + private void fillFromEntryFile ( final BuilderContext ctx, final PackageEntry entry ) throws IOException { this.logger.debug ( " as file:" ); final Path source = entry.getFile ().toPath ().toAbsolutePath (); this.logger.debug ( " - source: %s", source ); - ctx.addFile ( entry.getName (), source, makeProvider ( entry, " - " ) ); + if (entry.getFilterFile()) + { + File tmpFile = new File( System.getProperty( "java.io.tmpdir" ) + File.separator + "rpm-" + System.currentTimeMillis() + "-" + entry.getFile().getName() ); + tmpFile.deleteOnExit(); + final Path filtered = tmpFile.toPath(); + FilterUtils.filterFile( getLog(), source, filtered, project.getModel(), getAdditionalVars() ); + this.logger.debug ( " - filtered: %s", filtered ); + ctx.addFile ( entry.getName (), filtered, makeProvider ( entry, " - " ) ); + } + else + { + ctx.addFile ( entry.getName (), source, makeProvider ( entry, " - " ) ); + } } private void fillFromEntryLinkTo ( final BuilderContext ctx, final PackageEntry entry ) throws IOException { + if (entry.getFilterFile()) + { + getLog().error( "Cannot filter symbolic link: " + entry.getLinkTo() ); + } + this.logger.debug ( " as symbolic link:" ); this.logger.debug ( " - linkTo: %s", entry.getLinkTo () ); ctx.addSymbolicLink ( entry.getName (), entry.getLinkTo (), makeProvider ( entry, " - " ) ); @@ -1045,6 +1077,12 @@ private void fillFromEntryLinkTo ( final BuilderContext ctx, final PackageEntry private void fillFromEntryCollect ( final BuilderContext ctx, final PackageEntry entry ) throws IOException { + + if (entry.getFilterFile()) + { + getLog().error( "Cannot filter from collect: " + entry.getName() ); + } + this.logger.debug ( " as collector:" ); final Collector collector = entry.getCollect (); @@ -1110,7 +1148,6 @@ private void fillFromEntryCollect ( final BuilderContext ctx, final PackageEntry { RpmMojo.this.logger.debug ( "%s%s (file)", padding, file ); RpmMojo.this.logger.debug ( "%s - target: %s", padding, targetName ); - ctx.addFile ( targetName, file, provider ); } } diff --git a/src/site/markdown/entry.md b/src/site/markdown/entry.md index 5c8d64b..2aa3fb2 100644 --- a/src/site/markdown/entry.md +++ b/src/site/markdown/entry.md @@ -40,6 +40,29 @@ There is no need for additional source information. Adding a single file is done by: `path/to/file`. The path to the file is relative to the Maven project. +Since version `1.3.1`, you can add `true`, +if you want the file content to be filtered before being added to the RPM. +This allows you to place variables (`${varname}`) in the file and have them +expanded on-the-fly. + +In terms of what variables are supported, there are two types: +The *first* type being POM related ones, that start with `project.` like +`project.name` or `project.version`. Sub-properties from properties +in the POM that allow multiple values, like `licenses` can access these +via `[index]`, with the index being 0-based. The *second* type are +ones specific to this plugin. Here is a list of supported variables: + +``` +description +distribution +group +packageName +packager +sourcePackage +vendor +version +``` + ### Symbolic link Adding a single file is done by: `link/target`. The path where the From ec816c82828c6fa59f42315d9602977d3e9c7877 Mon Sep 17 00:00:00 2001 From: Peter Reutemann Date: Fri, 25 Oct 2019 12:15:14 +1300 Subject: [PATCH 02/17] switched to simple-maven-file-filtering libary for file filtering --- pom.xml | 6 + .../de/dentrassi/rpm/builder/BeanUtils.java | 151 --------------- .../de/dentrassi/rpm/builder/FilterUtils.java | 182 ------------------ .../de/dentrassi/rpm/builder/RpmMojo.java | 1 + 4 files changed, 7 insertions(+), 333 deletions(-) delete mode 100644 src/main/java/de/dentrassi/rpm/builder/BeanUtils.java delete mode 100644 src/main/java/de/dentrassi/rpm/builder/FilterUtils.java diff --git a/pom.xml b/pom.xml index 5cce37e..fd50fe4 100644 --- a/pom.xml +++ b/pom.xml @@ -122,6 +122,12 @@ 1.12 + + com.github.fracpete + simple-maven-file-filtering + 0.0.1 + + diff --git a/src/main/java/de/dentrassi/rpm/builder/BeanUtils.java b/src/main/java/de/dentrassi/rpm/builder/BeanUtils.java deleted file mode 100644 index e38e33f..0000000 --- a/src/main/java/de/dentrassi/rpm/builder/BeanUtils.java +++ /dev/null @@ -1,151 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2019 University of Waikato, Hamilton, NZ - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * Contributors: - * University of Waikato, Hamilton, NZ - initial API and implementation - *******************************************************************************/ -package de.dentrassi.rpm.builder; - -import org.apache.maven.plugin.logging.Log; - -import java.beans.BeanInfo; -import java.beans.Introspector; -import java.beans.PropertyDescriptor; -import java.lang.reflect.Array; -import java.util.Arrays; -import java.util.List; - -/** - * Bean related operations. - * - * @author FracPete (fracpete at waikato dot ac dot nz) - */ -public class BeanUtils -{ - - /** - * Extracts the properties from an object. - * - * @param log for logging - * @param obj the object to inspect - * @return the properties - */ - public static PropertyDescriptor[] extractProperties(Log log, Object obj) - { - BeanInfo bi; - - if (obj == null) - { - log.warn("Null object provided, can't extract bean properties!"); - return new PropertyDescriptor[0]; - } - - try - { - bi = Introspector.getBeanInfo(obj.getClass()); - return bi.getPropertyDescriptors(); - } - catch (Exception e) - { - log.error("Failed to extract properties from: " + obj.getClass(), e); - return new PropertyDescriptor[0]; - } - } - - /** - * Extracts the value from the Object using the specified property path. - * - * @param log for logging - * @param obj the object to extract the value from - * @param path the property path, broken up - * @return the value, null if failed to located - */ - protected static Object extractValue(Log log, Object obj, List path) - { - PropertyDescriptor[] props; - String current; - int index; - Object value; - - current = path.get(0); - index = -1; - if (current.contains("[") && current.endsWith("]")) - { - index = Integer.parseInt(current.substring(current.indexOf("[") + 1, current.indexOf("]"))); - current = current.substring(0, current.indexOf("[")); - } - - props = extractProperties(log, obj); - for (PropertyDescriptor prop : props) - { - if (prop.getDisplayName().equals(current)) - { - try - { - value = prop.getReadMethod().invoke(obj); - } - catch (Exception e) - { - value = null; - log.error("Failed to obtain value from path '" + path.get(0) + "!", e); - } - - if (index > -1) - { - if (value.getClass().isArray()) - { - value = Array.get(value, index); - } - else if (value instanceof List) - { - value = ((List) value).get(index); - } - else - { - log.error("Cannot handle type (neither array nor list): " + value.getClass()); - } - } - - if (path.size() == 1) - { - return value; - } - else - { - return extractValue(log, value, path.subList(1, path.size())); - } - } - } - - log.warn("Failed to locate path: " + current); - return null; - } - - /** - * Extracts the value from the Object using the specified property path. - * - * @param log for logging - * @param obj the object to extract the value from - * @param path the property path - * @return the value, null if failed to located - */ - public static Object extractValue(Log log, Object obj, String path) - { - String[] parts; - - if (path.contains(".")) - { - parts = path.split("\\."); - } - else - { - parts = new String[]{path}; - } - - return extractValue(log, obj, Arrays.asList(parts)); - } -} diff --git a/src/main/java/de/dentrassi/rpm/builder/FilterUtils.java b/src/main/java/de/dentrassi/rpm/builder/FilterUtils.java deleted file mode 100644 index d6ffe59..0000000 --- a/src/main/java/de/dentrassi/rpm/builder/FilterUtils.java +++ /dev/null @@ -1,182 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2019 University of Waikato, Hamilton, NZ - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * Contributors: - * University of Waikato, Hamilton, NZ - initial API and implementation - *******************************************************************************/ -package de.dentrassi.rpm.builder; - -import org.apache.maven.model.Model; -import org.apache.maven.plugin.logging.Log; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.StandardCopyOption; -import java.nio.file.StandardOpenOption; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * For filtering resources, replacing variables with actual values obtained from the model. - * - * @author FracPete (fracpete at waikato dot ac dot nz) - */ -public class FilterUtils -{ - - public static final String PROJECT = "project."; - - /** - * Extracts variables from a line: ${blah} -> blah. - * - * @param log for logging - * @param line the line to process - * @return the variables found - */ - protected static List extractVariables(Log log, String line) - { - List result; - int indexStart; - int indexEnd; - String original; - - original = line; - result = new ArrayList<>(); - while (line.length() > 0) - { - indexStart = line.indexOf("${"); - if (indexStart == -1) - { - line = ""; - } - else - { - if ((indexEnd = line.indexOf("}", indexStart)) == -1) - { - line = ""; - } - else - { - result.add(line.substring(indexStart + 2, indexEnd)); - line = line.substring(indexEnd + 1); - } - } - } - - if (result.size() > 0) - log.debug("Variables extracted from line '" + original + "': " + result); - - return result; - } - - /** - * Obtains the variable value from the model ("project.*"). - * - * @param log for logging - * @param var the variable - * @param model the model to obtain the value from - * @return null if not found or not a string object, otherwise the value - */ - protected static String variableValue(Log log, String var, Model model) - { - Object value; - - if (!var.startsWith(PROJECT)) - { - log.warn("Variable does not start with " + PROJECT + ": " + var); - return null; - } - - value = BeanUtils.extractValue(log, model, var.substring(PROJECT.length())); - if (value == null) - { - log.warn("Failed to extract value for variable: " + var); - return null; - } - else - { - log.debug("Value for variable " + var + ": " + value); - return "" + value; - } - } - - /** - * Filters a file, replacing any project or additional variables in it. - * - * @param log for logging - * @param input the input file - * @param output the output file - * @param model the model to use for resolving "project.*" variables - * @param additional additional variables with associated values - * @throws IOException if reading/writing of file fails - */ - public static void filterFile(Log log, Path input, Path output, Model model, Map additional) throws IOException - { - List lines; - int i; - String line; - List vars; - String value; - boolean updated; - boolean modified; - Map cache; - - lines = Files.readAllLines(input); - cache = new HashMap<>(); - modified = false; - for (i = 0; i < lines.size(); i++) - { - line = lines.get(i); - updated = false; - vars = extractVariables(log, line); - for (String var : vars) - { - if (cache.containsKey(var)) - { - value = cache.get(var); - } - else if (additional.containsKey(var)) - { - value = additional.get(var); - } - else - { - value = variableValue(log, var, model); - } - cache.put(var, value); - - if (value != null) - { - log.debug("Replacing variable '" + var + "' with value '" + value + "' in: " + line); - line = line.replace("${" + var + "}", value); - updated = true; - } - } - if (updated) - { - lines.set(i, line); - modified = true; - } - } - - if (modified) - { - log.debug("Writing filtered file " + input + " to " + output); - Files.createDirectories(output.getParent()); - Files.write(output, lines, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE); - } - else - { - log.debug("Copying unmodified file " + input + " to " + output); - Files.createDirectories(output.getParent()); - Files.copy(input, output, StandardCopyOption.REPLACE_EXISTING); - } - } -} diff --git a/src/main/java/de/dentrassi/rpm/builder/RpmMojo.java b/src/main/java/de/dentrassi/rpm/builder/RpmMojo.java index bf0295c..abab0f1 100644 --- a/src/main/java/de/dentrassi/rpm/builder/RpmMojo.java +++ b/src/main/java/de/dentrassi/rpm/builder/RpmMojo.java @@ -17,6 +17,7 @@ *******************************************************************************/ package de.dentrassi.rpm.builder; +import com.github.fracpete.simplemavenfilefiltering.FilterUtils; import com.google.common.base.Strings; import com.google.common.io.CharSource; import de.dentrassi.rpm.builder.Naming.Case; From 68e9a0ad482ca5d111bc4c2e0d7e7139c89d4643 Mon Sep 17 00:00:00 2001 From: Peter Reutemann Date: Fri, 25 Oct 2019 15:36:09 +1300 Subject: [PATCH 03/17] tweaked for separate deployment --- pom.xml | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index fd50fe4..5ba7064 100644 --- a/pom.xml +++ b/pom.xml @@ -1,16 +1,17 @@ 4.0.0 - de.dentrassi.maven - rpm - 1.3.1-SNAPSHOT + com.github.fracpete + rpm-maven-plugin + 1.4.0-SNAPSHOT maven-plugin Java RPM builder - Build RPM packages using plain Java on any platform + Build RPM packages using plain Java on any platform. + Fork of https://github.com/ctron/rpm-builder - https://ctron.github.io/rpm-builder + https://fracpete.github.io/rpm-builder 2016 @@ -24,14 +25,14 @@ - https://github.com/ctron/rpm-builder - scm:git:git://github.com/ctron/rpm-builder.git - scm:git:git@github.com:ctron/rpm-builder.git + https://github.com/fracpete/rpm-builder + scm:git:git://github.com/fracpete/rpm-builder.git + scm:git:git@github.com:fracpete/rpm-builder.git HEAD - https://github.com/ctron/rpm-builder/issues + https://github.com/fracpete/rpm-builder/issues GitHub @@ -39,6 +40,8 @@ UTF-8 UTF-8 8 + 1.8 + 1.8 3.3.9 @@ -149,6 +152,8 @@ maven-compiler-plugin 3.8.0 + ${maven.compiler.source} + ${maven.compiler.target} 8 From f81c9061daaba3c83906856abda80d48de7a9b23 Mon Sep 17 00:00:00 2001 From: Peter Reutemann Date: Fri, 25 Oct 2019 15:49:10 +1300 Subject: [PATCH 04/17] turned off integration tests --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5ba7064..9f21163 100644 --- a/pom.xml +++ b/pom.xml @@ -416,7 +416,7 @@ install - integration-test + verify From b1aa610180733a01a6caa8429c1a21ff9e06bad5 Mon Sep 17 00:00:00 2001 From: Peter Reutemann Date: Fri, 25 Oct 2019 15:49:29 +1300 Subject: [PATCH 05/17] [maven-release-plugin] prepare release rpm-maven-plugin-1.4.0 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 9f21163..d0bb3f2 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.fracpete rpm-maven-plugin - 1.4.0-SNAPSHOT + 1.4.0 maven-plugin @@ -28,7 +28,7 @@ https://github.com/fracpete/rpm-builder scm:git:git://github.com/fracpete/rpm-builder.git scm:git:git@github.com:fracpete/rpm-builder.git - HEAD + rpm-maven-plugin-1.4.0 From dd19cd28cf3005220ca4dd4ee61d54970afbc8ff Mon Sep 17 00:00:00 2001 From: Peter Reutemann Date: Fri, 25 Oct 2019 15:49:41 +1300 Subject: [PATCH 06/17] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index d0bb3f2..903dda1 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.fracpete rpm-maven-plugin - 1.4.0 + 1.4.1-SNAPSHOT maven-plugin @@ -28,7 +28,7 @@ https://github.com/fracpete/rpm-builder scm:git:git://github.com/fracpete/rpm-builder.git scm:git:git@github.com:fracpete/rpm-builder.git - rpm-maven-plugin-1.4.0 + HEAD From 866a4ea76eb8a5c576b333604dab06646907377b Mon Sep 17 00:00:00 2001 From: Peter Reutemann Date: Fri, 25 Oct 2019 15:58:08 +1300 Subject: [PATCH 07/17] downgraded version again --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 903dda1..9f21163 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.fracpete rpm-maven-plugin - 1.4.1-SNAPSHOT + 1.4.0-SNAPSHOT maven-plugin From 86d5e10986ac115a9f8ac7f6b5f387f46a64d6bd Mon Sep 17 00:00:00 2001 From: Peter Reutemann Date: Fri, 25 Oct 2019 15:58:30 +1300 Subject: [PATCH 08/17] [maven-release-plugin] prepare release rpm-maven-plugin-1.4.0 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 9f21163..d0bb3f2 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.fracpete rpm-maven-plugin - 1.4.0-SNAPSHOT + 1.4.0 maven-plugin @@ -28,7 +28,7 @@ https://github.com/fracpete/rpm-builder scm:git:git://github.com/fracpete/rpm-builder.git scm:git:git@github.com:fracpete/rpm-builder.git - HEAD + rpm-maven-plugin-1.4.0 From 5b34631442c810a31c75e1667c3707aa6703526d Mon Sep 17 00:00:00 2001 From: Peter Reutemann Date: Fri, 25 Oct 2019 15:58:49 +1300 Subject: [PATCH 09/17] [maven-release-plugin] rollback the release of rpm-maven-plugin-1.4.0 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index d0bb3f2..9f21163 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.fracpete rpm-maven-plugin - 1.4.0 + 1.4.0-SNAPSHOT maven-plugin @@ -28,7 +28,7 @@ https://github.com/fracpete/rpm-builder scm:git:git://github.com/fracpete/rpm-builder.git scm:git:git@github.com:fracpete/rpm-builder.git - rpm-maven-plugin-1.4.0 + HEAD From a825b92a03f35dfcb2429ac7d8815c2b32a64c12 Mon Sep 17 00:00:00 2001 From: Peter Reutemann Date: Fri, 25 Oct 2019 16:00:43 +1300 Subject: [PATCH 10/17] [maven-release-plugin] prepare release rpm-maven-plugin-1.4.0 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 9f21163..d0bb3f2 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.fracpete rpm-maven-plugin - 1.4.0-SNAPSHOT + 1.4.0 maven-plugin @@ -28,7 +28,7 @@ https://github.com/fracpete/rpm-builder scm:git:git://github.com/fracpete/rpm-builder.git scm:git:git@github.com:fracpete/rpm-builder.git - HEAD + rpm-maven-plugin-1.4.0 From a00e511af7837e445f7f877952ce2b73911ebb3b Mon Sep 17 00:00:00 2001 From: Peter Reutemann Date: Fri, 25 Oct 2019 16:02:39 +1300 Subject: [PATCH 11/17] added -SNAPSHOT again --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d0bb3f2..30927a4 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.fracpete rpm-maven-plugin - 1.4.0 + 1.4.0-SNAPSHOT maven-plugin From b159ff0993f982efa4a6954d2edabff5420df760 Mon Sep 17 00:00:00 2001 From: Peter Reutemann Date: Fri, 25 Oct 2019 16:03:00 +1300 Subject: [PATCH 12/17] [maven-release-plugin] prepare release rpm-maven-plugin-1.4.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 30927a4..d0bb3f2 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.fracpete rpm-maven-plugin - 1.4.0-SNAPSHOT + 1.4.0 maven-plugin From 30c9d7d97cf184b23898fdea20a24d9ba160bfe9 Mon Sep 17 00:00:00 2001 From: Peter Reutemann Date: Fri, 25 Oct 2019 16:03:11 +1300 Subject: [PATCH 13/17] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d0bb3f2..8d85c65 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.fracpete rpm-maven-plugin - 1.4.0 + 1.4.1-SNAPSHOT maven-plugin From 97d6dd07da86682aad650c3044daec36bed9482d Mon Sep 17 00:00:00 2001 From: Peter Reutemann Date: Fri, 25 Oct 2019 16:18:40 +1300 Subject: [PATCH 14/17] fixed links; removed travis --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1ddf29e..0dd5797 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -# RPM builder plugin [![Build status](https://api.travis-ci.org/ctron/rpm-builder.svg)](https://travis-ci.org/ctron/rpm-builder) ![Maven Central](https://img.shields.io/maven-central/v/de.dentrassi.maven/rpm.svg "Maven Central Status") +# RPM builder plugin This is a Maven Plugin which can build RPM files using plain Java. It does not require the `rpmbuild` command line tool. @@ -7,7 +7,7 @@ It does not require the `rpmbuild` command line tool. ## Usage For more information about how to use this plugin see -[the documentation](https://ctron.github.io/rpm-builder). +[the documentation](https://fracpete.github.io/rpm-builder). ## License From 338de65de116fbfc1d9e7b210484800952831b0c Mon Sep 17 00:00:00 2001 From: Peter Reutemann Date: Fri, 25 Oct 2019 16:23:41 +1300 Subject: [PATCH 15/17] updated RELEASE notes --- RELEASE.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/RELEASE.md b/RELEASE.md index 5d830d2..c7284ec 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -8,7 +8,16 @@ Ensure that `.m2/settings.xml` contains the GitHub credentials: github - + + + + +And also your Sonatype account: + + + ossrh + + From 81833fc9c429cf9f49c996f7d004209be3a5e87a Mon Sep 17 00:00:00 2001 From: Peter Reutemann Date: Fri, 25 Oct 2019 16:25:45 +1300 Subject: [PATCH 16/17] added maven version shield again --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0dd5797..b7d7acc 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -# RPM builder plugin +# RPM builder plugin ![Maven Central](https://img.shields.io/maven-central/v/com.github.fracpete/rpm-maven-plugin.svg "Maven Central Status") This is a Maven Plugin which can build RPM files using plain Java. It does not require the `rpmbuild` command line tool. From 7db80e3cf1e69eb79b99ebb65ca74ebe66959a5d Mon Sep 17 00:00:00 2001 From: Peter Reutemann Date: Tue, 29 Oct 2019 15:56:01 +1300 Subject: [PATCH 17/17] switched to 0.0.2 of simple-maven-file-filtering --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8d85c65..2b058c5 100644 --- a/pom.xml +++ b/pom.xml @@ -128,7 +128,7 @@ com.github.fracpete simple-maven-file-filtering - 0.0.1 + 0.0.2