about summary refs log tree commit diff
path: root/pkgs/applications/editors/jedit/default.nix
blob: 8fdf8e7c8de2647a550f86f6803e15f5c4933f0c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
{
  lib,
  stdenv,
  fetchsvn,
  ant,
  jdk,
  jre,
  xmlstarlet,
  makeWrapper,
  stripJavaArchivesHook,
}:

stdenv.mkDerivation (finalAttrs: {
  pname = "jedit";
  version = "5.6.0-unstable-2023-11-19";

  src = fetchsvn {
    url = "https://svn.code.sf.net/p/jedit/svn/jEdit/trunk";
    rev = "25703";
    hash = "sha256-z1KTZqKl6Dlqayw/3h/JvHQK3kSfio02R8V6aCb4g4Q=";
  };

  ivyDeps = stdenv.mkDerivation {
    name = "${finalAttrs.pname}-${finalAttrs.version}-ivy-deps";
    inherit (finalAttrs) src;

    nativeBuildInputs = [
      ant
      jdk
      xmlstarlet
    ];

    # set defaultCacheDir to something that can exist
    # this directory won't get copied, but needs to be set properly
    configurePhase = ''
      runHook preConfigure

      xmlstarlet ed --subnode /ivysettings -t elem -n caches ivysettings.xml \
          | xmlstarlet ed --insert /ivysettings/caches -t attr -n defaultCacheDir -v "$(pwd)/ivy-cache" \
          > ivysettings.xml.tmp
      mv ivysettings.xml.tmp ivysettings.xml

      runHook postConfigure
    '';

    buildPhase = ''
      runHook preBuild
      ant retrieve
      runHook postBuild
    '';

    installPhase = ''
      runHook preInstall
      mkdir -p $out/lib
      cp -r lib/* $out/lib
      runHook postInstall
    '';

    outputHashMode = "recursive";
    outputHashAlgo = "sha256";
    outputHash = "sha256-J5i5IhXlXw84y/4K6Vt84au4eVXVLupmtfscO+y1Fi0=";
  };

  # ignore a test failing because of the build environment
  postPatch = ''
    substituteInPlace test/org/gjt/sp/jedit/MiscUtilitiesTest.java \
        --replace-fail "public class MiscUtilitiesTest" "@org.junit.Ignore public class MiscUtilitiesTest"
  '';

  nativeBuildInputs = [
    ant
    jdk
    makeWrapper
    stripJavaArchivesHook
  ];

  buildPhase = ''
    runHook preBuild
    ln -s ${finalAttrs.ivyDeps}/lib ./lib
    ant build -Divy.done=true
    runHook postBuild
  '';

  installPhase = ''
    runHook preInstall

    mkdir -p $out/share/jEdit
    cp -r build/jedit.jar doc keymaps macros modes startup $out/share/jEdit

    install -Dm644 icons/jedit-icon48.png $out/share/icons/hicolor/48x48/apps/jedit.png
    install -Dm644 package-files/linux/deb/jedit.desktop -t $out/share/applications

    sed -i $out/share/applications/jedit.desktop \
        -e "s|Icon=.*|Icon=jedit|g" \
        -e "s|Exec=.*|Exec=jedit|g"

    install -Dm755 package-files/linux/jedit -t $out/bin
    substituteInPlace $out/bin/jedit \
        --replace-fail "/usr/share/jEdit/@jar.filename@" "$out/share/jEdit/jedit.jar"

    wrapProgram $out/bin/jedit --set JAVA_HOME ${jre}

    runHook postInstall
  '';

  meta = {
    description = "A programmer's text editor written in Java";
    homepage = "http://www.jedit.org";
    license = lib.licenses.gpl2Only;
    mainProgram = "jedit";
    maintainers = with lib.maintainers; [ tomasajt ];
    platforms = lib.platforms.unix;
    sourceProvenance = with lib.sourceTypes; [
      fromSource
      binaryBytecode # ivyDeps contains .jar dependencies
    ];
  };
})