Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for basic file filtering when adding an explicit file #44

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

# 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 ![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.

## 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

Expand Down
11 changes: 10 additions & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ Ensure that `.m2/settings.xml` contains the GitHub credentials:

<server>
<id>github</id>
<password><!-- access key --></password>
<username><!-- github user --></username>
<password><!-- password --></password>
</server>

And also your Sonatype account:

<server>
<id>ossrh</id>
<username><!-- sonatype user --></username>
<password><!-- password --></password>
</server>


Expand Down
33 changes: 22 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>de.dentrassi.maven</groupId>
<artifactId>rpm</artifactId>
<version>1.3.1-SNAPSHOT</version>
<groupId>com.github.fracpete</groupId>
<artifactId>rpm-maven-plugin</artifactId>
<version>1.4.1-SNAPSHOT</version>

<packaging>maven-plugin</packaging>

<name>Java RPM builder</name>
<description>Build RPM packages using plain Java on any platform</description>
<description>Build RPM packages using plain Java on any platform.
Fork of https://github.com/ctron/rpm-builder</description>

<url>https://ctron.github.io/rpm-builder</url>
<url>https://fracpete.github.io/rpm-builder</url>

<inceptionYear>2016</inceptionYear>

Expand All @@ -24,21 +25,23 @@
</developers>

<scm>
<url>https://github.com/ctron/rpm-builder</url>
<connection>scm:git:git://github.com/ctron/rpm-builder.git</connection>
<developerConnection>scm:git:[email protected]:ctron/rpm-builder.git</developerConnection>
<tag>HEAD</tag>
<url>https://github.com/fracpete/rpm-builder</url>
<connection>scm:git:git://github.com/fracpete/rpm-builder.git</connection>
<developerConnection>scm:git:[email protected]:fracpete/rpm-builder.git</developerConnection>
<tag>rpm-maven-plugin-1.4.0</tag>
</scm>

<issueManagement>
<url>https://github.com/ctron/rpm-builder/issues</url>
<url>https://github.com/fracpete/rpm-builder/issues</url>
<system>GitHub</system>
</issueManagement>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.release>8</maven.compiler.release>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>

<maven.version>3.3.9</maven.version>

Expand Down Expand Up @@ -122,6 +125,12 @@
<version>1.12</version>
</dependency>

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

<!-- EOTD -->

<dependency>
Expand All @@ -143,6 +152,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<release>8</release>
</configuration>
</plugin>
Expand Down Expand Up @@ -405,7 +416,7 @@
<execution>
<goals>
<goal>install</goal>
<goal>integration-test</goal>
<!--goal>integration-test</goal-->
<goal>verify</goal>
</goals>
</execution>
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/de/dentrassi/rpm/builder/PackageEntry.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/*******************************************************************************
* 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
* http://www.eclipse.org/legal/epl-2.0
*
* Contributors:
* IBH SYSTEMS GmbH - initial API and implementation
* University of Waikato - added filterFile flag
*******************************************************************************/
package de.dentrassi.rpm.builder;

Expand Down Expand Up @@ -95,6 +96,8 @@ public String toString ()

private String ruleset;

private boolean filterFile;

public String getName ()
{
return this.name;
Expand Down Expand Up @@ -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 ()
{
Expand Down
98 changes: 68 additions & 30 deletions src/main/java/de/dentrassi/rpm/builder/RpmMojo.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -13,32 +13,15 @@
* 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.github.fracpete.simplemavenfilefiltering.FilterUtils;
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;
Expand All @@ -65,11 +48,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
Expand Down Expand Up @@ -1027,24 +1029,61 @@ private void fillFromEntryDirectory ( final BuilderContext ctx, final PackageEnt
ctx.addDirectory ( entry.getName (), makeProvider ( entry, " - " ) );
}

private Map<String,String> getAdditionalVars()
{
HashMap<String,String> 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, " - " ) );
}

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 ();
Expand Down Expand Up @@ -1110,7 +1149,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 );
}
}
Expand Down
23 changes: 23 additions & 0 deletions src/site/markdown/entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,29 @@ There is no need for additional source information.
Adding a single file is done by: `<file>path/to/file</file>`. The path to the file is relative
to the Maven project.

Since version `1.3.1`, you can add `<filterFile>true</filterFile>`,
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: `<linkTo>link/target</linkTo>`. The path where the
Expand Down