simple-maven-file-filtering

Basic support for file-filtering (ie replacing variables in text files) for maven plugins.

License

License

Categories

Categories

Maven Build Tools
GroupId

GroupId

com.github.fracpete
ArtifactId

ArtifactId

simple-maven-file-filtering
Last Version

Last Version

0.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

simple-maven-file-filtering
Basic support for file-filtering (ie replacing variables in text files) for maven plugins.
Project Organization

Project Organization

University of Waikato, Hamilton, NZ
Source Code Management

Source Code Management

https://github.com/fracpete/simple-maven-file-filtering

Download simple-maven-file-filtering

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.fracpete/simple-maven-file-filtering/ -->
<dependency>
    <groupId>com.github.fracpete</groupId>
    <artifactId>simple-maven-file-filtering</artifactId>
    <version>0.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.fracpete/simple-maven-file-filtering/
implementation 'com.github.fracpete:simple-maven-file-filtering:0.0.2'
// https://jarcasting.com/artifacts/com.github.fracpete/simple-maven-file-filtering/
implementation ("com.github.fracpete:simple-maven-file-filtering:0.0.2")
'com.github.fracpete:simple-maven-file-filtering:jar:0.0.2'
<dependency org="com.github.fracpete" name="simple-maven-file-filtering" rev="0.0.2">
  <artifact name="simple-maven-file-filtering" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.fracpete', module='simple-maven-file-filtering', version='0.0.2')
)
libraryDependencies += "com.github.fracpete" % "simple-maven-file-filtering" % "0.0.2"
[com.github.fracpete/simple-maven-file-filtering "0.0.2"]

Dependencies

compile (1)

Group / Artifact Type Version
org.apache.maven : maven-plugin-api jar 3.2.5

test (2)

Group / Artifact Type Version
junit : junit jar 3.8.2
org.codehaus.plexus : plexus-component-api jar 1.0-alpha-33

Project Modules

There are no modules declared in this project.

simple-maven-file-filtering

Library for applying simple file filtering (ie expanding of variables) in text files to be used with maven plugins.

Examples

Use the following call of FilterUtils.filterFile to expand only project-related variables (like ${project.name} or ${project.version}):

import com.github.fracpete.simplemavenfilefiltering.FilterUtils;
import org.apache.maven.model.Model;
import org.apache.maven.plugin.logging.Log;
import java.nio.file.Path;

Model model = ...;  // the Maven model that your plugin has access to 
Log log = ...;      // the log instance from your plugin
Path source = ...;  // the source file with the variables unexpanded
Path target = ...;  // the target file to write with the variables expanded   

FilterUtils.filterFile(log, source, target, model);

If you want to replace other variables, e.g., parameters form your own plugin, then you can supply a map of variables:

import com.github.fracpete.simplemavenfilefiltering.FilterUtils;
import org.apache.maven.model.Model;
import org.apache.maven.plugin.logging.Log;
import java.nio.file.Path;
import java.utils.Map;
import java.utils.HashMap;

Model model = ...;  // the Maven model that your plugin has access to 
Log log = ...;      // the log instance from your plugin
Path source = ...;  // the source file with the variables unexpanded
Path target = ...;  // the target file to write with the variables expanded   
Map<String, String> vars = new HashMap<>();
vars.put("myvar1", "some_value");
vars.put("something", "else");

FilterUtils.filterFile(log, source, target, model, vars);

If you have to use a variable prefix/suffix pair other than the default ${ and }, you can supply these using the following methods:

  • filterFile(Log log, Path input, Path output, Model model, String varPrefix, String varSuffix)
  • filterFile(Log log, Path input, Path output, Model model, Map<String, String> additional, String varPrefix, String varSuffix)

Maven

Use the following dependency to include the library in your Maven plugin:

    <dependency>
      <groupId>com.github.fracpete</groupId>
      <artifactId>simple-maven-file-filtering</artifactId>
      <version>0.0.1</version>
    </dependency>

Versions

Version
0.0.2
0.0.1