diff --git a/src/it/test19-intermediate-directories/pom.xml b/src/it/test19-intermediate-directories/pom.xml new file mode 100644 index 0000000..b2fcb50 --- /dev/null +++ b/src/it/test19-intermediate-directories/pom.xml @@ -0,0 +1,141 @@ + + + 4.0.0 + + de.dentrassi.maven.rpm.test + test19 + 1.0.0-SNAPSHOT + jar + + Test Package #19 + + Test explicitly adding and applying rules for implicitly created intermediate directories. + + + http://dentrassi.de + + + Jens Reimann + http://dentrassi.de + + + + + Eclipse Public License - v 1.0 + repo + https://www.eclipse.org/legal/epl-v10.html + + + + + UTF-8 + UTF-8 + true + + 2009-01-01T12:00:00+01:00 + + + + + + + de.dentrassi.maven + rpm + @project.version@ + + + + rpm + + + false + Application/Misc + + + ${keyId} + ${user.home}/.gnupg/secring.gpg + ${passphrase} + SHA1 + ${skipSigning} + + + + /etc/mycompany/myapp + /opt/mycompany/myapp + + + + + my-default + + + + /opt/mycompany + + mygeneraluser + mygeneralgroup + 0111 + + + + /opt/mycompany/myapp + + myuser + mygroup + 0555 + + + + /opt/mycompany/myapp + directory + + 0777 + + + + + + + + /opt/mycompany/myapp/a/b/c/foobar + ${project.basedir}/src/main/data/foobar + my-default + + + /opt/mycompany/myapp + true + my-default + + + /etc/mycompany/myapp/defaults + true + my-default + + + /opt/mycompany/otherapp/a/b/c/foobar + ${project.basedir}/src/main/data/foobar + my-default + + + + + + + + + + + + + sign + + false + + + false + + + + + \ No newline at end of file diff --git a/src/it/test19-intermediate-directories/src/main/data/foobar b/src/it/test19-intermediate-directories/src/main/data/foobar new file mode 100644 index 0000000..e69de29 diff --git a/src/it/test19-intermediate-directories/verify.groovy b/src/it/test19-intermediate-directories/verify.groovy new file mode 100644 index 0000000..37f0515 --- /dev/null +++ b/src/it/test19-intermediate-directories/verify.groovy @@ -0,0 +1,24 @@ +def dump() { + Process proc = ('rpm -q --dump -p ' + basedir + "/target/*.rpm").execute() + return proc.in.getText().trim() +} + +def actual = dump() +println "Dump:\n" + actual + +def expected = """\ + /etc/mycompany/myapp 0 1230807600 0000000000000000000000000000000000000000000000000000000000000000 040755 root root 0 0 0 X + /etc/mycompany/myapp/defaults 0 1230807600 0000000000000000000000000000000000000000000000000000000000000000 040755 root root 0 0 0 X + /opt/mycompany/myapp 0 1230807600 0000000000000000000000000000000000000000000000000000000000000000 040777 myuser mygroup 0 0 0 X + /opt/mycompany/myapp/a 0 1230807600 0000000000000000000000000000000000000000000000000000000000000000 040777 myuser mygroup 0 0 0 X + /opt/mycompany/myapp/a/b 0 1230807600 0000000000000000000000000000000000000000000000000000000000000000 040777 myuser mygroup 0 0 0 X + /opt/mycompany/myapp/a/b/c 0 1230807600 0000000000000000000000000000000000000000000000000000000000000000 040777 myuser mygroup 0 0 0 X + /opt/mycompany/myapp/a/b/c/foobar 0 1230807600 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 0100555 myuser mygroup 0 0 0 X + /opt/mycompany/otherapp/a/b/c/foobar 0 1230807600 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 0100111 mygeneraluser mygeneralgroup 0 0 0 X""".stripIndent() + +if (actual != expected) { + System.out.format("RPM dump doesn't match - actual:%n%s%nexpected:%n%s%n", actual, expected); + return false; +} + +return true; diff --git a/src/main/java/de/dentrassi/rpm/builder/MissingDirectoryTracker.java b/src/main/java/de/dentrassi/rpm/builder/MissingDirectoryTracker.java index 6c9df4c..480f994 100644 --- a/src/main/java/de/dentrassi/rpm/builder/MissingDirectoryTracker.java +++ b/src/main/java/de/dentrassi/rpm/builder/MissingDirectoryTracker.java @@ -25,14 +25,17 @@ public class MissingDirectoryTracker implements BuilderContextListener { + // keep track of explicit added directories private final Set explicitAddedDirectories; + // keep track of all missing directories which should be added after processing (without explicit added directories) private final Map> missingDirectories; - private final List ignorePrefixes; + // base directories (prefixes) for which the intermediate directories should be generated + private final List baseDirectories; - public MissingDirectoryTracker(List ignorePrefixes) { + public MissingDirectoryTracker(List baseDirectories) { this.explicitAddedDirectories = new HashSet<>(); this.missingDirectories = new HashMap<>(); - this.ignorePrefixes = ignorePrefixes; + this.baseDirectories = baseDirectories; } @Override @@ -53,23 +56,25 @@ public void notifySymbolicLinkAdded(String targetName, FileInformationProvider provider) { - for (String intermediateDirectory : getIntermediateDirectories(targetName)) { - if (!shouldDirectoryIgnored(intermediateDirectory) && !explicitAddedDirectories.contains(intermediateDirectory)) { - if (provider instanceof MojoFileInformationProvider) { - MojoFileInformationProvider mojoProvider = (MojoFileInformationProvider) provider; - missingDirectories.computeIfAbsent(intermediateDirectory, k -> new MojoFileInformationProvider(mojoProvider.getRulesetEval(), mojoProvider.getRuleId(), null, mojoProvider.getLogger(), mojoProvider.getTimestamp())); + if (provider instanceof MojoFileInformationProvider) { + MojoFileInformationProvider mojoProvider = (MojoFileInformationProvider) provider; + + for (String intermediateDirectory : getIntermediateDirectories(targetName)) { + if (startsPathWithPrefix(intermediateDirectory) && !explicitAddedDirectories.contains(intermediateDirectory)) { + missingDirectories.computeIfAbsent(intermediateDirectory, + (String directory) -> new MojoFileInformationProvider( + mojoProvider.getRulesetEval(), + mojoProvider.getRuleId(), + null, + mojoProvider.getLogger(), + mojoProvider.getTimestamp())); } } } } - private boolean shouldDirectoryIgnored(String directory) { - for (String ignorePrefix : ignorePrefixes) { - if (ignorePrefix.startsWith(directory)) { - return true; - } - } - return false; + private boolean startsPathWithPrefix(String directory) { + return baseDirectories.stream().anyMatch(directory::startsWith); } public void addMissingIntermediateDirectoriesToContext(BuilderContext ctx) throws IOException { @@ -90,5 +95,4 @@ private List getIntermediateDirectories(String targetName) { return intermediateDirectories; } - } diff --git a/src/main/java/de/dentrassi/rpm/builder/RpmMojo.java b/src/main/java/de/dentrassi/rpm/builder/RpmMojo.java index 9e3cc79..fe06d1e 100644 --- a/src/main/java/de/dentrassi/rpm/builder/RpmMojo.java +++ b/src/main/java/de/dentrassi/rpm/builder/RpmMojo.java @@ -208,28 +208,6 @@ public void setGenerateDefaultSourcePackage(final boolean generateDefaultSourceP this.generateDefaultSourcePackage = generateDefaultSourcePackage; } - /** - * Whether implicitly created intermediate directories should explicitly - * added to package. - *

- * If enabled, all from entries implicitly created intermediate directories - * are added as explicit entries to package. Also the rules with file - * information are applied to these directories. - *

- *

- * To exclude directories like {@code /usr} from being added, you have - * to add these as prefix property (see {@code prefixes}). Directories - * that match a whole prefix or a sub path of it, are not added. - *

- */ - @Parameter(property = "rpm.generateIntermediateDirectories", defaultValue = "true") - boolean generateIntermediateDirectories = true; - - public void setGenerateIntermediateDirectories(final boolean generateIntermediateDirectories) { - this.generateIntermediateDirectories = generateIntermediateDirectories; - } - - /** * The prefix of the release if this is a snapshot build, will be suffixed * with the snapshot build id @@ -388,6 +366,31 @@ public void setGenerateIntermediateDirectories(final boolean generateIntermediat @Parameter(property = "rpm.prefixes") List prefixes; + /** + * Base paths for which implicitly created intermediate directories should + * explicitly added to package. + * + *
+     *       <generateIntermediateDirectories>
+     *           <baseDirectory>/opt/mycompany/myapp</baseDirectory>
+     *           <baseDirectory>/etc/mycompany</baseDirectory>
+     *       </generateIntermediateDirectories>
+     * 
+ * + *

+ * For given base directories, all from entries implicitly created + * intermediate directories are added as explicit entries to package. + * Also the rules with file information are applied to these added directories. + *

+ *

+ * To exclude directories like {@code /usr} from being added, you have + * to add these as prefix property (see {@code prefixes}). Directories + * that match a whole prefix or a sub path of it, are not added. + *

+ */ + @Parameter(property = "rpm.generateIntermediateDirectories") + List generateIntermediateDirectories; + /** * The actual payload/file entries *

@@ -1100,7 +1103,7 @@ protected void fillPayload(final RpmBuilder builder) throws MojoFailureException } final ListenableBuilderContext ctx = new ListenableBuilderContext(builder.newContext()); - final MissingDirectoryTracker missingDirectoryTracker = new MissingDirectoryTracker(this.prefixes); + final MissingDirectoryTracker missingDirectoryTracker = new MissingDirectoryTracker(this.generateIntermediateDirectories); ctx.registerListener(missingDirectoryTracker); this.logger.debug("Building payload:"); @@ -1118,7 +1121,7 @@ protected void fillPayload(final RpmBuilder builder) throws MojoFailureException } ctx.removeListener(missingDirectoryTracker); - if (generateIntermediateDirectories) { + if (!generateIntermediateDirectories.isEmpty()) { missingDirectoryTracker.addMissingIntermediateDirectoriesToContext(ctx); } }