From 4bd1929514cb2f14010055950882788bc2103d0c Mon Sep 17 00:00:00 2001 From: Mark Derricutt Date: Tue, 14 Nov 2017 15:27:57 +1300 Subject: [PATCH] Replace configuration with RPM FileFlags. This change replaces the existing means of setting a file as being a configuration file, by exposing FileFlags modification to SimpleFileInformationCustomizer. As part of this we also define the full set of RPM file flags, using the naming from the upstream RPM sources at https://github.com/rpm-software-management/rpm/blob/master/lib/rpmfiles.h Existing behaviour is (currently) deprecated and adapted to use the newer code. Fixes #113 Signed-off-by: Mark Derricutt --- .../packagedrone/utils/rpm/FileFlags.java | 32 ++++++++++++++++++- .../utils/rpm/build/FileInformation.java | 30 ++++++++++++++--- .../utils/rpm/build/RpmBuilder.java | 8 +++-- 3 files changed, 63 insertions(+), 7 deletions(-) diff --git a/bundles/org.eclipse.packagedrone.utils.rpm/src/org/eclipse/packagedrone/utils/rpm/FileFlags.java b/bundles/org.eclipse.packagedrone.utils.rpm/src/org/eclipse/packagedrone/utils/rpm/FileFlags.java index f225acc2..ca89ef9d 100644 --- a/bundles/org.eclipse.packagedrone.utils.rpm/src/org/eclipse/packagedrone/utils/rpm/FileFlags.java +++ b/bundles/org.eclipse.packagedrone.utils.rpm/src/org/eclipse/packagedrone/utils/rpm/FileFlags.java @@ -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; @@ -25,4 +38,21 @@ public int getValue () { return this.value; } + + public static EnumSet decode( int flagValue ) + { + EnumSet fileFlags = EnumSet.noneOf( FileFlags.class ); + if ( flagValue != 0 ) + { + for ( FileFlags fileFlag : FileFlags.values() ) + { + if ( ( fileFlag.getValue() & flagValue ) == fileFlag.getValue() ) + { + fileFlags.add(fileFlag); + } + } + } + return fileFlags; + } + } diff --git a/bundles/org.eclipse.packagedrone.utils.rpm/src/org/eclipse/packagedrone/utils/rpm/build/FileInformation.java b/bundles/org.eclipse.packagedrone.utils.rpm/src/org/eclipse/packagedrone/utils/rpm/build/FileInformation.java index bb7322b9..0c3dc455 100644 --- a/bundles/org.eclipse.packagedrone.utils.rpm/src/org/eclipse/packagedrone/utils/rpm/build/FileInformation.java +++ b/bundles/org.eclipse.packagedrone.utils.rpm/src/org/eclipse/packagedrone/utils/rpm/build/FileInformation.java @@ -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 @@ -20,7 +23,7 @@ public class FileInformation private String group = BuilderContext.DEFAULT_GROUP; - private boolean configuration = false; + private EnumSet fileFlags = EnumSet.noneOf(FileFlags.class); private short mode = 0644; @@ -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 ) + { + this.fileFlags = fileFlags; + } + + public EnumSet getFileFlags() + { + return this.fileFlags; } public void setUser ( final String user ) @@ -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 ); } } diff --git a/bundles/org.eclipse.packagedrone.utils.rpm/src/org/eclipse/packagedrone/utils/rpm/build/RpmBuilder.java b/bundles/org.eclipse.packagedrone.utils.rpm/src/org/eclipse/packagedrone/utils/rpm/build/RpmBuilder.java index 1181767f..d867c5d7 100644 --- a/bundles/org.eclipse.packagedrone.utils.rpm/src/org/eclipse/packagedrone/utils/rpm/build/RpmBuilder.java +++ b/bundles/org.eclipse.packagedrone.utils.rpm/src/org/eclipse/packagedrone/utils/rpm/build/RpmBuilder.java @@ -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; @@ -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 () ); + } } }