Skip to content

Commit

Permalink
Do not require file or directory for ghost entries (ctron#56).
Browse files Browse the repository at this point in the history
  • Loading branch information
dranuhl committed Nov 29, 2021
1 parent ef7287d commit a44e959
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/de/dentrassi/rpm/builder/PackageEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,11 @@ public void validate ()
sources += this.file != null ? 1 : 0;
sources += this.collect != null ? 1 : 0;
sources += this.linkTo != null ? 1 : 0;
sources += Boolean.TRUE.equals ( this.getGhost () ) ? 1 : 0;

if ( sources != 1 )
{
throw new IllegalStateException ( "Exactly one of 'file', 'directory', 'linkTo' or 'collect' must be specified." );
throw new IllegalStateException ( "Exactly one of 'file', 'directory', 'linkTo', 'collect' or 'ghost' must be specified." );
}

super.validate ();
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/de/dentrassi/rpm/builder/RpmMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -1101,6 +1102,10 @@ else if ( entry.getCollect () != null )
{
fillFromEntryCollect ( ctx, entry );
}
else if ( Boolean.TRUE.equals ( entry.getGhost () ) )
{
fillFromEntryGhost ( ctx, entry );
}
}

private void fillFromEntryDirectory ( final BuilderContext ctx, final PackageEntry entry ) throws IOException
Expand All @@ -1118,6 +1123,13 @@ private void fillFromEntryFile ( final BuilderContext ctx, final PackageEntry en
ctx.addFile ( entry.getName (), source, makeProvider ( entry, " - " ) );
}

private void fillFromEntryGhost ( final BuilderContext ctx, final PackageEntry entry ) throws IOException
{
this.logger.debug ( " as ghost:" );

ctx.addFile ( entry.getName (), ByteBuffer.allocate ( 0 ), makeProvider ( entry, " - " ) );
}

private void fillFromEntryLinkTo ( final BuilderContext ctx, final PackageEntry entry ) throws IOException
{
this.logger.debug ( " as symbolic link:" );
Expand Down

0 comments on commit a44e959

Please sign in to comment.