Skip to content

Commit

Permalink
jabref: switch to gradle setup hook
Browse files Browse the repository at this point in the history
  • Loading branch information
chayleaf committed Dec 6, 2023
1 parent 5aaf779 commit 735100e
Show file tree
Hide file tree
Showing 2 changed files with 3,116 additions and 77 deletions.
98 changes: 21 additions & 77 deletions pkgs/applications/office/jabref/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{ lib
, stdenv
, fetchurl
, fetchFromGitHub
, fetchpatch
, wrapGAppsHook
Expand All @@ -15,15 +14,7 @@
, python3
}:

let
versionReplace = {
easybind = {
snapshot = "2.2.1-SNAPSHOT";
pin = "2.2.1-20230117.075740-16";
};
};
in
stdenv.mkDerivation rec {
let self = stdenv.mkDerivation rec {
version = "5.11";
pname = "jabref";

Expand All @@ -35,6 +26,11 @@ stdenv.mkDerivation rec {
fetchSubmodules = true;
};

mitmCache = gradle.fetchDeps {
name = "jabref-deps";
data = ./deps.json;
};

desktopItems = [
(makeDesktopItem {
comment = meta.description;
Expand All @@ -49,30 +45,6 @@ stdenv.mkDerivation rec {
})
];

deps = stdenv.mkDerivation {
pname = "${pname}-deps";
inherit src version patches postPatch;

nativeBuildInputs = [ gradle perl ];
buildPhase = ''
export GRADLE_USER_HOME=$(mktemp -d)
gradle --no-daemon downloadDependencies -Dos.arch=amd64
gradle --no-daemon downloadDependencies -Dos.arch=aarch64
'';
# perl code mavenizes pathes (com.squareup.okio/okio/1.13.0/a9283170b7305c8d92d25aff02a6ab7e45d06cbe/okio-1.13.0.jar -> com/squareup/okio/okio/1.13.0/okio-1.13.0.jar)
installPhase = ''
find $GRADLE_USER_HOME/caches/modules-2 -type f -regex '.*\.\(jar\|pom\)' \
| perl -pe 's#(.*/([^/]+)/([^/]+)/([^/]+)/[0-9a-f]{30,40}/([^/\s]+))$# ($x = $2) =~ tr|\.|/|; "install -Dm444 $1 \$out/$x/$3/$4/''${\($5 =~ s/-jvm//r)}" #e' \
| sh
mv $out/com/tobiasdiez/easybind/${versionReplace.easybind.pin} \
$out/com/tobiasdiez/easybind/${versionReplace.easybind.snapshot}
'';
# Don't move info to share/
forceShare = [ "dummy" ];
outputHashMode = "recursive";
outputHash = "sha256-sMbAv122EcLPOqbEVKowfxp9B71iJaccLRlKS75b3Xc=";
};

patches = [
# Use JavaFX 21
(fetchpatch {
Expand All @@ -82,40 +54,10 @@ stdenv.mkDerivation rec {
];

postPatch = ''
# Pin the version
substituteInPlace build.gradle \
--replace 'com.tobiasdiez:easybind:${versionReplace.easybind.snapshot}' \
'com.tobiasdiez:easybind:${versionReplace.easybind.pin}'
# Disable update check
substituteInPlace src/main/java/org/jabref/preferences/JabRefPreferences.java \
--replace 'VERSION_CHECK_ENABLED, Boolean.TRUE' \
'VERSION_CHECK_ENABLED, Boolean.FALSE'
# Add back downloadDependencies task for deps download which is removed upstream in https://github.com/JabRef/jabref/pull/10326
cat <<EOF >> build.gradle
task downloadDependencies {
description "Pre-downloads *most* dependencies"
doLast {
configurations.getAsMap().each { name, config ->
println "Retrieving dependencies for $name"
try {
config.files
} catch (e) {
// some cannot be resolved, just log them
project.logger.info e.message
}
}
}
}
EOF
'';

preBuild = ''
# Use the local packages from -deps
sed -i -e '/repositories {/a maven { url uri("${deps}") }' \
build.gradle \
settings.gradle
'';

nativeBuildInputs = [
Expand All @@ -131,19 +73,13 @@ stdenv.mkDerivation rec {
python3
];

buildPhase = ''
runHook preBuild
export GRADLE_USER_HOME=$(mktemp -d)
gradle \
--offline \
--no-daemon \
-PprojVersion="${version}" \
-PprojVersionInfo="${version} NixOS" \
-Dorg.gradle.java.home=${jdk} \
assemble
gradleFlags = [
"-PprojVersion=${version}"
"-Dorg.gradle.java.home=${jdk}"
];

runHook postBuild
preConfigure = ''
gradleFlagsArray+=(-PprojVersionInfo="${version} NixOS")
'';

dontWrapGApps = true;
Expand Down Expand Up @@ -200,4 +136,12 @@ stdenv.mkDerivation rec {
platforms = [ "x86_64-linux" "aarch64-linux" ];
maintainers = with maintainers; [ gebner linsui ];
};
}

passthru.updateDeps = gradle.updateDeps {
inherit self;
gradleCommands = ''
gradle nixSupport_downloadDeps -Dos.arch=amd64
gradle nixSupport_downloadDeps -Dos.arch=aarch64
'';
};
}; in self
Loading

0 comments on commit 735100e

Please sign in to comment.