Subject: [bug#63145] [PATCH 3/3] gnu: maven-*-*: DRY generate-sisu-named.

From: Rostislav Svoboda <[email-masked]>
Date: Fri, 28 Apr 2023 15:13:12 +0200

* gnu/packages/maven.scm
  - maven-settings-builder
  - maven-model-builder
  - maven-resolver-provider
  - maven-core-bootstrap
  - maven-embedder
  Implement common functionality just once in the `generate-sisu-named`.
---
 gnu/packages/maven.scm | 41 +++++++++++++----------------------------
 1 file changed, 13 insertions(+), 28 deletions(-)

diff --git a/gnu/packages/maven.scm b/gnu/packages/maven.scm
index 6990d091cf..34a1fae4b5 100644
--- a/gnu/packages/maven.scm
+++ b/gnu/packages/maven.scm
@@ -1359,6 +1359,14 @@ (define add-missing-shebang
      ;; -i, --in-place   edit files in place
      (invoke "sed" "-i" "1s;^;#!/bin/sh\\n\\n;" "./sisu.sh")))
 
+(define* (generate-sisu-named sisu-path #:optional (src-path ""))
+  (let ((sisu-sh (string-append sisu-path "sisu.sh")))
+    `(lambda _
+       (mkdir-p "build/classes/META-INF/sisu")
+       (chmod  ,sisu-sh #o755)
+       (invoke ,sisu-sh ,(string-append src-path "src/main/java")
+               "build/classes/META-INF/sisu/javax.inject.Named"))))
+
 (define-public maven-settings-builder
   (package
     (inherit maven-artifact)
@@ -1373,11 +1381,7 @@ (define-public maven-settings-builder
          (add-before 'patch-source-shebangs 'add-missing-shebang
            ,add-missing-shebang)
          (add-before 'build 'generate-sisu-named
-           (lambda _
-             (mkdir-p "build/classes/META-INF/sisu")
-             (chmod "sisu.sh" #o755)
-             (invoke "./sisu.sh" "maven-settings-builder/src/main/java"
-                     "build/classes/META-INF/sisu/javax.inject.Named")))
+           ,(generate-sisu-named "./" "maven-settings-builder/"))
          (replace 'install (install-from-pom "maven-settings-builder/pom.xml")))))
     (propagated-inputs
      (list java-plexus-utils
@@ -1416,11 +1420,7 @@ (define-public maven-model-builder
                                "build/classes")
              #t))
          (add-before 'build 'generate-sisu-named
-           (lambda _
-             (mkdir-p "build/classes/META-INF/sisu")
-             (chmod "../sisu.sh" #o755)
-             (invoke "../sisu.sh" "src/main/java"
-                     "build/classes/META-INF/sisu/javax.inject.Named")))
+           ,(generate-sisu-named "../"))
          (replace 'install
            (install-from-pom "pom.xml")))))
     (propagated-inputs
@@ -1513,12 +1513,7 @@ (define-public maven-resolver-provider
          (add-before 'patch-source-shebangs 'add-missing-shebang
            ,add-missing-shebang)
          (add-before 'build 'generate-sisu-named
-           (lambda _
-             (mkdir-p "build/classes/META-INF/sisu")
-             (chmod "./sisu.sh" #o755)
-             (invoke "./sisu.sh" "maven-resolver-provider/src/main/java"
-                     "build/classes/META-INF/sisu/javax.inject.Named")
-             #t))
+           ,(generate-sisu-named "./" "maven-resolver-provider/"))
          (replace 'install
            (install-from-pom "maven-resolver-provider/pom.xml")))))
     (propagated-inputs
@@ -1627,12 +1622,7 @@ (define-public maven-core-bootstrap
                  (("\\$\\{distributionName\\}") "Apache Maven"))
                #t))
            (add-before 'build 'generate-sisu-named
-             (lambda _
-               (mkdir-p "build/classes/META-INF/sisu")
-               (chmod "../sisu.sh" #o755)
-               (invoke "../sisu.sh" "src/main/java"
-                       "build/classes/META-INF/sisu/javax.inject.Named")
-               #t))
+             ,(generate-sisu-named "../"))
            (add-before 'build 'generate-models
              (lambda* (#:key inputs #:allow-other-keys)
                (define (modello-single-mode file version mode)
@@ -1838,12 +1828,7 @@ (define-public maven-embedder
          (add-before 'patch-source-shebangs 'add-missing-shebang
            ,add-missing-shebang)
          (add-before 'build 'generate-sisu-named
-           (lambda _
-             (mkdir-p "build/classes/META-INF/sisu")
-             (chmod "sisu.sh" #o755)
-             (invoke "./sisu.sh" "maven-embedder/src/main/java"
-                     "build/classes/META-INF/sisu/javax.inject.Named")
-             #t))
+           ,(generate-sisu-named "./" "maven-embeder/"))
          (add-before 'build 'copy-resources
            (lambda _
              (mkdir-p "build/classes/")
-- 
2.39.2