Skip to content

Commit

Permalink
Feature verify flags (#43)
Browse files Browse the repository at this point in the history
* New test EntryDetailsTest
* see #42
* EntryDetailsTest: verify return value of EntryDetails.apply(..)
* Allow to control verification flags.
* Requires modifications from eclipse/packager#6
* Fix for #41.
* upgrade org.eclipse.packager:packager-rpm to 0.16.0
* resolve merge conflict
* rename VerifyDetails.md5 to fileDigest, add javadoc
* add license header
* primitive boolean rather than Boolean,
* dadaistic javadoc to suppress warnings

Signed-off-by: Oliver Matz <oliver.matz@dataport.de>
  • Loading branch information
OliverMatz authored and ctron committed Sep 18, 2019
1 parent 22717c5 commit 6ce869e
Show file tree
Hide file tree
Showing 4 changed files with 419 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/main/java/de/dentrassi/rpm/builder/EntryDetails.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,35 @@ public class EntryDetails

private Boolean skip = false;

/**
* Controls verify flags.
* If null, the behaviour is unchanged, the verify flags bitmap will be set to -1, meaning: verify everthing.
* If (for example) empty, the verify flags bitmap will be set to 0, meaning: verify nothing.
* See https://github.com/ctron/rpm-builder/issues/41.
* <br>
* The following combination is a reasonable example in the sense of https://stackoverflow.com/a/38996621/11917731:
* <entry>
* ...
* <configuration>true</configuration>
* <noreplace>true</noreplace>
* <verify>
* <user>true</user>
* <group>true</group>
* </verify>
* </entry>
*/
private VerifyDetails verify;

public final VerifyDetails getVerify ()
{
return verify;
}

public final void setVerify ( final VerifyDetails verify )
{
this.verify = verify;
}

public void setMode ( final String mode )
{
this.mode = Short.parseShort ( mode, 8 );
Expand Down Expand Up @@ -210,6 +239,11 @@ public boolean apply ( final FileInformation info )
info.setMode ( this.mode );
didApply = true;
}
if ( this.verify != null )
{
this.verify.apply ( info );
didApply = true;
}
return didApply;
}

Expand Down
236 changes: 236 additions & 0 deletions src/main/java/de/dentrassi/rpm/builder/VerifyDetails.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
/*
* Copyright (c) 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:
* Oliver Matz - initial API and implementation
*******************************************************************************/
package de.dentrassi.rpm.builder;

import org.eclipse.packager.rpm.VerifyFlags;
import org.eclipse.packager.rpm.build.FileInformation;

import java.util.EnumSet;
import java.util.Set;

/**
* Each member of this class corresponds to one bit in the verify flags.
* See http://ftp.rpm.org/api/4.14.0/group__rpmvf.html.
* See https://github.com/ctron/rpm-builder/issues/41
*/
public final class VerifyDetails {
private boolean fileDigest;
private boolean size;
private boolean linkto;
private boolean user;
private boolean group;
private boolean mtime;
private boolean mode;
private boolean rdev;
private boolean caps;

/**
* Corresponds to rpm verify option --nofiledigest.
* @return true iff fileDigest shall be verified
*/
public boolean getFileDigest() {
return fileDigest;
}

/**
* Corresponds to rpm verify option --nofiledigest.
* @param fileDigest true iff fileDigest shall be verified
*/
public void setFileDigest(boolean fileDigest) {
this.fileDigest = fileDigest;
}

/**
* Corresponds to rpm verify option --nosize.
* @return true iff file size shall be verified
*/
public boolean getSize() {
return size;
}

/**
* Corresponds to rpm verify option --nosize.
* @param size true iff file size shall be verified
*/
public void setSize(boolean size) {
this.size = size;
}

/**
* Corresponds to rpm verify option --nolinkto.
* @return true iff linkto shall be verified
*/
public boolean getLinkto() {
return linkto;
}

/**
* Corresponds to rpm verify option --nolinkto.
* @param linkto true iff linkto shall be verified
*/
public void setLinkto(boolean linkto) {
this.linkto = linkto;
}

/**
* Corresponds to rpm verify option --nouser.
* @return true iff user shall be verified
*/
public boolean getUser() {
return user;
}

/**
* Corresponds to rpm verify option --nouser.
* @param user true iff user shall be verified
*/
public void setUser(boolean user) {
this.user = user;
}

/**
* Corresponds to rpm verify option --nogroup.
* @return true iff group shall be verified
*/
public boolean getGroup() {
return group;
}

/**
* Corresponds to rpm verify option --nogroup.
* @param group true iff group shall be verified
*/
public void setGroup(boolean group) {
this.group = group;
}

/**
* Corresponds to rpm verify option --nomtime.
* @return true iff mtime shall be verified
*/
public boolean getMtime() {
return mtime;
}

/**
* Corresponds to rpm verify option --nomtime.
* @param mtime true iff mtime shall be verified
*/
public void setMtime(boolean mtime) {
this.mtime = mtime;
}

/**
* Corresponds to rpm verify option --nomode.
* @return true iff mode shall be verified
*/
public boolean getMode() {
return mode;
}

/**
* Corresponds to rpm verify option --nomode.
* @param mode true iff mode shall be verified
*/
public void setMode(boolean mode) {
this.mode = mode;
}

/**
* Corresponds to rpm verify option --nordev.
* @return true iff rdev shall be verified
*/
public boolean getRdev() {
return rdev;
}

/**
* Corresponds to rpm verify option --nordev.
* @param rdev true iff rdev shall be verified
*/
public void setRdev(boolean rdev) {
this.rdev = rdev;
}

/**
* Corresponds to rpm verify option --nocaps.
* @return true iff caps shall be verified
*/
public boolean getCaps() {
return caps;
}

/**
* Corresponds to rpm verify option --nocaps.
* @param caps true iff caps shall be verified
*/
public void setCaps(boolean caps) {
this.caps = caps;
}

/**
* @see EntryDetails#apply(org.eclipse.packager.rpm.build.FileInformation)
*/
void apply ( final FileInformation info )
{
final Set<VerifyFlags> verifyFlags = EnumSet.noneOf(VerifyFlags.class);
transfer(verifyFlags, this.fileDigest, VerifyFlags.MD5 );
transfer(verifyFlags, this.size, VerifyFlags.SIZE );
transfer(verifyFlags, this.linkto, VerifyFlags.LINKTO );
transfer(verifyFlags, this.user, VerifyFlags.USER );
transfer(verifyFlags, this.group, VerifyFlags.GROUP );
transfer(verifyFlags, this.mtime, VerifyFlags.MTIME );
transfer(verifyFlags, this.mode, VerifyFlags.MODE );
transfer(verifyFlags, this.caps, VerifyFlags.CAPS );
info.setVerifyFlags ( verifyFlags );
}

private static void transfer(Set<VerifyFlags> target, boolean val, VerifyFlags flag)
{
if (!val)
{
// target.remove(val); // not needed, target cannot contain flag
return;
}
target.add(flag);
}

@Override
public String toString() {
final StringBuilder ret = new StringBuilder("VerifyDetails{");
if (fileDigest) {
ret.append("fileDigest,");
}
if (size) {
ret.append("size,");
}
if (linkto) {
ret.append("linkto,");
}
if (user) {
ret.append("user,");
}
if (group) {
ret.append("group,");
}
if (mode) {
ret.append("mode,");
}
if (rdev) {
ret.append("rdev,");
}
if (caps) {
ret.append("caps,");
}
ret.append("}");
return ret.toString();
}
}
61 changes: 61 additions & 0 deletions src/test/java/de/dentrassi/rpm/builder/EntryDetailsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package de.dentrassi.rpm.builder;

import org.eclipse.packager.rpm.FileFlags;
import org.eclipse.packager.rpm.build.FileInformation;
import org.junit.Test;

import java.util.Set;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;

/**
* Test class de.dentrassi.rpm.builder.EntryDetails.
*/
public class EntryDetailsTest
{
/**
* Verify that empty {@link EntryDetails} result in empty set of {@link FileFlags}.
*/
@Test
public void applyEmpty()
{
final EntryDetails entryDetails = new EntryDetails();
doTest(new FileFlags[] {}, false, entryDetails);
}

/**
* Verify that {@link EntryDetails#setReadme(java.lang.Boolean)} correctly controls {@link FileFlags#README}.
*/
@Test
public void applyReadmeTrue()
{
final EntryDetails entryDetails = new EntryDetails();
entryDetails.setReadme(true);
doTest(new FileFlags[] {FileFlags.README}, true, entryDetails);
}

/**
* False negative? See https://github.com/ctron/rpm-builder/issues/42
*/
@Test
public void applyReadmeFalse()
{
final EntryDetails entryDetails = new EntryDetails();
entryDetails.setReadme(false);
doTest(new FileFlags[] {FileFlags.README}, true, entryDetails); // questionable
}

/**
* invokes {@link EntryDetails#apply(org.eclipse.packager.rpm.build.FileInformation)}
* @param expectedResult expected return value of {@link FileInformation#getFileFlags()}
* @param expectedApplied expected return value of {@link de.dentrassi.rpm.builder.EntryDetails#apply(org.eclipse.packager.rpm.build.FileInformation)}
*/
private static void doTest(FileFlags[] expectedResult, boolean expectedApplied, final EntryDetails entryDetails)
{
final FileInformation fileInformation = new FileInformation();
assertEquals(expectedApplied, entryDetails.apply(fileInformation));
final Set<FileFlags> fileFlags = fileInformation.getFileFlags();
assertArrayEquals(expectedResult, fileFlags.toArray());
}
}
Loading

0 comments on commit 6ce869e

Please sign in to comment.