Skip to content
Permalink
Browse files

Use a different way to fill requirements for payload codings

  • Loading branch information
ctron committed Jan 4, 2019
1 parent 7ec92bb commit 5873aa275396ed75c8da0547b3bd070c6227ff3c
@@ -14,6 +14,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Optional;
import java.util.function.Consumer;

import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream;
@@ -24,7 +25,6 @@
{
protected BZip2PayloadCoding ()
{

}

@Override
@@ -34,9 +34,9 @@ public String getCoding ()
}

@Override
public Optional<Dependency> getDependency ()
public void fillRequirements ( final Consumer<Dependency> requirementsConsumer )
{
return Optional.of ( new Dependency ( "PayloadIsBzip2", "3.0.5-1", RpmDependencyFlags.LESS, RpmDependencyFlags.EQUAL, RpmDependencyFlags.RPMLIB ) );
requirementsConsumer.accept ( new Dependency ( "PayloadIsBzip2", "3.0.5-1", RpmDependencyFlags.LESS, RpmDependencyFlags.EQUAL, RpmDependencyFlags.RPMLIB ) );
}

@Override
@@ -52,7 +52,7 @@ public OutputStream createOutputStream ( final OutputStream out, final Optional<

final int blockSize;

if ( optionalFlags.isPresent () && ( flags = optionalFlags.get () ).length() > 0 )
if ( optionalFlags.isPresent () && ( flags = optionalFlags.get () ).length () > 0 )
{
blockSize = Integer.parseInt ( flags.substring ( 0, 1 ) );
}
@@ -14,6 +14,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.zip.Deflater;

import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
@@ -25,7 +26,6 @@
{
protected GzipPayloadCoding ()
{

}

@Override
@@ -35,9 +35,8 @@ public String getCoding ()
}

@Override
public Optional<Dependency> getDependency ()
public void fillRequirements ( final Consumer<Dependency> requirementsConsumer )
{
return Optional.empty ();
}

@Override
@@ -52,7 +51,7 @@ public OutputStream createOutputStream ( final OutputStream out, final Optional<
final String flags;
final int compressionLevel;

if ( optionalFlags.isPresent () && ( flags = optionalFlags.get () ).length() > 0 )
if ( optionalFlags.isPresent () && ( flags = optionalFlags.get () ).length () > 0 )
{
compressionLevel = Integer.parseInt ( flags.substring ( 0, 1 ) );
}
@@ -14,6 +14,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Optional;
import java.util.function.Consumer;

import org.apache.commons.compress.compressors.lzma.LZMACompressorInputStream;
import org.apache.commons.compress.compressors.lzma.LZMACompressorOutputStream;
@@ -24,7 +25,6 @@
{
protected LZMAPayloadCoding ()
{

}

@Override
@@ -34,9 +34,9 @@ public String getCoding ()
}

@Override
public Optional<Dependency> getDependency ()
public void fillRequirements ( final Consumer<Dependency> requirementsConsumer )
{
return Optional.of ( new Dependency ( "PayloadIsLzma", "4.4.6-1", RpmDependencyFlags.LESS, RpmDependencyFlags.EQUAL, RpmDependencyFlags.RPMLIB ) );
requirementsConsumer.accept ( new Dependency ( "PayloadIsLzma", "4.4.6-1", RpmDependencyFlags.LESS, RpmDependencyFlags.EQUAL, RpmDependencyFlags.RPMLIB ) );
}

@Override
@@ -14,14 +14,14 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Optional;
import java.util.function.Consumer;

import org.eclipse.packagedrone.utils.rpm.deps.Dependency;

public class NullPayloadCoding implements PayloadCoding
{
protected NullPayloadCoding ()
{

}

@Override
@@ -31,9 +31,8 @@ public String getCoding ()
}

@Override
public Optional<Dependency> getDependency ()
public void fillRequirements ( final Consumer<Dependency> requirementsConsumer )
{
return Optional.empty ();
}

@Override
@@ -13,15 +13,25 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;

import org.eclipse.packagedrone.utils.rpm.deps.Dependency;

public interface PayloadCoding
{
String getCoding ();

Optional<Dependency> getDependency ();
void fillRequirements ( final Consumer<Dependency> requirementsConsumer );

default List<Dependency> getRequirements ()
{
final List<Dependency> result = new LinkedList<> ();
fillRequirements ( result::add );
return result;
}

InputStream createInputStream ( final InputStream in ) throws IOException;

@@ -154,7 +154,7 @@ public Feature ( final String name, final String version, final String descripti

public String getDescription ()
{
return description;
return this.description;
}

public void setDescription ( final String description )
@@ -167,10 +167,10 @@ public int hashCode ()
{
final int prime = 31;
int result = 1;
result = prime * result + ( this.getFlags() == null ? 0 : this.getFlags().hashCode () );
result = prime * result + ( this.getName() == null ? 0 : this.getName().hashCode () );
result = prime * result + ( this.getVersion() == null ? 0 : this.getVersion().hashCode () );
result = prime * result + ( this.getDescription() == null ? 0 : this.getDescription().hashCode () );
result = prime * result + ( getFlags () == null ? 0 : getFlags ().hashCode () );
result = prime * result + ( getName () == null ? 0 : getName ().hashCode () );
result = prime * result + ( getVersion () == null ? 0 : getVersion ().hashCode () );
result = prime * result + ( getDescription () == null ? 0 : getDescription ().hashCode () );
return result;
}

@@ -190,47 +190,47 @@ public boolean equals ( final Object obj )
return false;
}
final Feature other = (Feature)obj;
if ( this.getFlags() == null )
if ( getFlags () == null )
{
if ( other.getFlags() != null )
if ( other.getFlags () != null )
{
return false;
}
}
else if ( !this.getFlags().equals ( other.getFlags() ) )
else if ( !getFlags ().equals ( other.getFlags () ) )
{
return false;
}
if ( this.getName() == null )
if ( getName () == null )
{
if ( other.getName() != null )
if ( other.getName () != null )
{
return false;
}
}
else if ( !this.getName().equals ( other.getName() ) )
else if ( !getName ().equals ( other.getName () ) )
{
return false;
}
if ( this.getVersion() == null )
if ( getVersion () == null )
{
if ( other.getVersion() != null )
if ( other.getVersion () != null )
{
return false;
}
}
else if ( !this.getVersion().equals ( other.getVersion() ) )
else if ( !getVersion ().equals ( other.getVersion () ) )
{
return false;
}
if ( this.getDescription() == null )
if ( getDescription () == null )
{
if ( other.getDescription() != null )
if ( other.getDescription () != null )
{
return false;
}
}
else if ( !this.getDescription().equals ( other.getDescription() ) )
else if ( !getDescription ().equals ( other.getDescription () ) )
{
return false;
}
@@ -240,7 +240,7 @@ else if ( !this.getDescription().equals ( other.getDescription() ) )
@Override
public String toString ()
{
return String.format ( "[%s, %s, %s, %s]", this.getName(), this.getVersion(), this.getFlags(), this.getDescription() );
return String.format ( "[%s, %s, %s, %s]", getName (), getVersion (), getFlags (), getDescription () );
}

}
@@ -777,6 +777,7 @@ public void setHeaderCustomizer ( final Consumer<Header<RpmTag>> headerCustomize

/**
* Fill extra requirements the RPM file itself may have
*
* @throws IOException
*/
private void fillRequirements () throws IOException
@@ -789,13 +790,7 @@ private void fillRequirements () throws IOException
}

this.requirements.add ( new Dependency ( "rpmlib(PayloadFilesHavePrefix)", "4.0-1", RpmDependencyFlags.LESS, RpmDependencyFlags.EQUAL, RpmDependencyFlags.RPMLIB ) );

final Optional<Dependency> optionalDependency = options.getPayloadCoding ().getDependency ();

if ( optionalDependency.isPresent () )
{
this.requirements.add ( optionalDependency.get() );
}
this.options.getPayloadCoding ().fillRequirements ( this.requirements::add );
}

private void fillProvides ()
@@ -807,14 +802,14 @@ private void fillHeader ()
{
this.header.putString ( RpmTag.PAYLOAD_FORMAT, "cpio" );

if ( recorder.getPayloadCoding () != null )
if ( this.recorder.getPayloadCoding () != null )
{
this.header.putString ( RpmTag.PAYLOAD_CODING, recorder.getPayloadCoding ().getCoding () );
this.header.putString ( RpmTag.PAYLOAD_CODING, this.recorder.getPayloadCoding ().getCoding () );
}

if ( recorder.getPayloadFlags ().isPresent () )
if ( this.recorder.getPayloadFlags ().isPresent () )
{
this.header.putString ( RpmTag.PAYLOAD_FLAGS, recorder.getPayloadFlags ().get () );
this.header.putString ( RpmTag.PAYLOAD_FLAGS, this.recorder.getPayloadFlags ().get () );
}

this.header.putStringArray ( 100, "C" );
@@ -860,7 +855,7 @@ private void fillHeader ()
{
if ( !this.options.getFileDigestAlgorithm ().equals ( DigestAlgorithm.MD5 ) )
{
this.header.putInt ( RpmTag.FILE_DIGESTALGO, this.options.getFileDigestAlgorithm ().getTag () );
this.header.putInt ( RpmTag.FILE_DIGESTALGO, this.options.getFileDigestAlgorithm ().getTag () );
}

final FileEntry[] files = this.files.values ().toArray ( new FileEntry[this.files.size ()] );
@@ -994,7 +989,6 @@ private String makeDefaultFileName ()
return this.options.getFileNameProvider ().getRpmFileName ( this.name, this.version, this.architecture );
}


/**
* Return the list of features supported by this builder.
*
@@ -14,6 +14,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Optional;
import java.util.function.Consumer;

import org.apache.commons.compress.compressors.xz.XZCompressorInputStream;
import org.apache.commons.compress.compressors.xz.XZCompressorOutputStream;
@@ -25,7 +26,6 @@
{
protected XZPayloadCoding ()
{

}

@Override
@@ -35,9 +35,9 @@ public String getCoding ()
}

@Override
public Optional<Dependency> getDependency ()
public void fillRequirements ( final Consumer<Dependency> requirementsConsumer )
{
return Optional.of ( new Dependency ( "PayloadIsXz", "5.2-1", RpmDependencyFlags.LESS, RpmDependencyFlags.EQUAL, RpmDependencyFlags.RPMLIB ) );
requirementsConsumer.accept ( new Dependency ( "PayloadIsXz", "5.2-1", RpmDependencyFlags.LESS, RpmDependencyFlags.EQUAL, RpmDependencyFlags.RPMLIB ) );
}

@Override
@@ -52,7 +52,7 @@ public OutputStream createOutputStream ( final OutputStream out, final Optional<
final String flags;
final int preset;

if ( optionalFlags.isPresent () && ( flags = optionalFlags.get () ).length() > 0 )
if ( optionalFlags.isPresent () && ( flags = optionalFlags.get () ).length () > 0 )
{
preset = Integer.parseInt ( flags.substring ( 0, 1 ) );
}
@@ -14,6 +14,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Optional;
import java.util.function.Consumer;

import org.apache.commons.compress.compressors.zstandard.ZstdCompressorInputStream;
import org.apache.commons.compress.compressors.zstandard.ZstdCompressorOutputStream;
@@ -25,7 +26,6 @@
{
protected ZstdPayloadCoding ()
{

}

@Override
@@ -35,17 +35,17 @@ public String getCoding ()
}

@Override
public Optional<Dependency> getDependency ()
public void fillRequirements ( final Consumer<Dependency> requirementsConsumer )
{
return Optional.of ( new Dependency ( "PayloadIsZstd", "5.4.18-1", RpmDependencyFlags.LESS, RpmDependencyFlags.EQUAL, RpmDependencyFlags.RPMLIB ) );
requirementsConsumer.accept ( new Dependency ( "PayloadIsZstd", "5.4.18-1", RpmDependencyFlags.LESS, RpmDependencyFlags.EQUAL, RpmDependencyFlags.RPMLIB ) );
}

@Override
public InputStream createInputStream ( final InputStream in ) throws IOException
{
if ( !ZstdUtils.isZstdCompressionAvailable () )
{
throw new IOException( "Zstandard compression is not available" );
throw new IOException ( "Zstandard compression is not available" );
}

return new ZstdCompressorInputStream ( in );
@@ -56,14 +56,14 @@ public OutputStream createOutputStream ( final OutputStream out, final Optional<
{
if ( !ZstdUtils.isZstdCompressionAvailable () )
{
throw new IOException( "Zstandard compression is not available" );
throw new IOException ( "Zstandard compression is not available" );
}

final String flags;

final int level;

if ( optionalFlags.isPresent () && ( flags = optionalFlags.get () ).length() > 0 )
if ( optionalFlags.isPresent () && ( flags = optionalFlags.get () ).length () > 0 )
{
level = Integer.parseInt ( flags.substring ( 0, 1 ) );
}

0 comments on commit 5873aa2

Please sign in to comment.
You can’t perform that action at this time.