Skip to content
This repository has been archived by the owner on Mar 5, 2021. It is now read-only.

Replace configuration with RPM FileFlags. #115

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,25 @@
*
* Contributors:
* IBH SYSTEMS GmbH - initial API and implementation
* SMX Ltd. - support for additional RPM file flags
*******************************************************************************/
package org.eclipse.packagedrone.utils.rpm;

import java.util.EnumSet;

public enum FileFlags
{
CONFIGURATION ( 1 );
CONFIGURATION ( 1 << 0 ), /*!< from %%config */
DOC ( 1 << 1 ), /*!< from %%doc */
ICON ( 1 << 2 ), /*!< from %%donotuse. */
MISSINGOK ( 1 << 3 ), /*!< from %%config(missingok) */
NOREPLACE ( 1 << 4 ), /*!< from %%config(noreplace) */
GHOST ( 1 << 6 ), /*!< from %%ghost */
LICENSE ( 1 << 7 ), /*!< from %%license */
README ( 1 << 8 ), /*!< from %%readme */
/* bits 9-10 unused */
PUBKEY ( 1 << 11 ), /*!< from %%pubkey */
ARTIFACT ( 1 << 12 ); /*!< from %%artifact */

private int value;

Expand All @@ -25,4 +38,21 @@ public int getValue ()
{
return this.value;
}

public static EnumSet<FileFlags> decode( int flagValue )
{
EnumSet<FileFlags> fileFlags = EnumSet.noneOf( FileFlags.class );
if ( flagValue != 0 )
{
for ( FileFlags fileFlag : FileFlags.values() )
{
if ( ( fileFlag.getValue() & flagValue ) == fileFlag.getValue() )
{
fileFlags.add(fileFlag);
}
}
}
return fileFlags;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
*******************************************************************************/
package org.eclipse.packagedrone.utils.rpm.build;

import org.eclipse.packagedrone.utils.rpm.FileFlags;

import java.util.EnumSet;
import java.time.Instant;

public class FileInformation
Expand All @@ -20,7 +23,7 @@ public class FileInformation

private String group = BuilderContext.DEFAULT_GROUP;

private boolean configuration = false;
private EnumSet<FileFlags> fileFlags = EnumSet.noneOf(FileFlags.class);

private short mode = 0644;

Expand All @@ -34,14 +37,33 @@ public Instant getTimestamp ()
return this.timestamp;
}

@Deprecated
public void setConfiguration ( final boolean configuration )
{
this.configuration = configuration;
if ( configuration == true)
{
this.fileFlags.add(FileFlags.CONFIGURATION);
}
else
{
this.fileFlags.remove(FileFlags.CONFIGURATION);
}
}

@Deprecated
public boolean isConfiguration ()
{
return this.configuration;
return this.fileFlags.contains(FileFlags.CONFIGURATION);
}

public void setFileFlags ( final EnumSet<FileFlags> fileFlags )
{
this.fileFlags = fileFlags;
}

public EnumSet<FileFlags> getFileFlags()
{
return this.fileFlags;
}

public void setUser ( final String user )
Expand Down Expand Up @@ -77,6 +99,6 @@ public short getMode ()
@Override
public String toString ()
{
return String.format ( "[FileInformation - user: %s, group: %s, mode: 0%04o, cfg: %s]", this.user, this.group, this.mode, this.configuration );
return String.format ( "[FileInformation - user: %s, group: %s, mode: 0%04o, flags: %s]", this.user, this.group, this.mode, this.fileFlags );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
Expand Down Expand Up @@ -450,9 +451,12 @@ protected void customizeDirectory ( final FileEntry entry, final FileInformation
protected void customizeFile ( final FileEntry entry, final FileInformation information )
{
customizeCommon ( entry, information );
if ( information.isConfiguration () )
if ( !information.getFileFlags().isEmpty() )
{
entry.setFlags ( entry.getFlags () | FileFlags.CONFIGURATION.getValue () );
for ( FileFlags fileFlag : information.getFileFlags() )
{
entry.setFlags ( entry.getFlags () | fileFlag.getValue () );
}
}
}

Expand Down