name: jabref
adopt-info: jabref
icon: snap/gui/jabref.png
license: MIT
summary: Bibliography manager
description: |
  JabRef is an open source bibliography reference manager.
  The native file format used by JabRef is BibTeX, the standard LaTeX bibliography format.
  To access files in external media (i.e., USB drives) you must run:
  `snap connect jabref:removable-media`
grade: stable
confinement: strict
base: core22
compression: lzo
architectures:
 - build-on: [amd64, arm64]
   build-for: [amd64]

plugs:
  home:
  unity7:
  opengl:
  network-bind:
  removable-media:
  hostfs-mozilla-native-messaging-jabref:
    interface: system-files
    write:
    - /var/lib/snapd/hostfs/usr/lib/mozilla/native-messaging-hosts/org.jabref.jabref.json
  etc-opt-chrome-native-messaging-jabref:
    interface: system-files
    write:
    - /etc/opt/chrome/native-messaging-hosts/org.jabref.jabref.json
  etc-opt-edge-native-messaging-jabref:
    interface: system-files
    write:
      - /etc/opt/edge/native-messaging-hosts/org.jabref.jabref.json
  etc-chromium-native-messaging-jabref:
    interface: system-files
    write:
    - /etc/chromium/native-messaging-hosts/org.jabref.jabref.json

layout:
  /usr/share/libdrm:
    bind: $SNAP/gnome-platform/usr/share/libdrm

apps:
  jabref:
    command: bin/JabRef
    extensions: [gnome]
  browser-proxy:
    command: lib/jabrefHost.py
    extensions: [gnome]

environment:
  _JAVA_OPTIONS: "-Duser.home=$SNAP_USER_DATA"
  GTK_USE_PORTAL: "1"

parts:
  jabref:
    plugin: dump
    source: https://builds.jabref.org/main/JabRef-5.16-portable_linux.tar.gz
    stage-packages:
      - x11-utils
    override-build: |
      snapcraftctl build
      snapcraftctl set-version "$(cat $SNAPCRAFT_PART_INSTALL/lib/app/.jpackage.xml | grep "app-version" | cut -d">" -f2 | cut -d"<" -f1)"
      sed -i 's|/opt/jabref/lib/jabrefHost.py|/snap/bin/jabref.browser-proxy|g' $SNAPCRAFT_PART_INSTALL/lib/native-messaging-host/*/org.jabref.jabref.json
      sed -i 's/usr\/bin\/env python3/usr\/bin\/python3/g' $SNAPCRAFT_PART_INSTALL/lib/jabrefHost.py
      rm $SNAPCRAFT_PART_INSTALL/bin/JabRef
  jabref-launcher:
    after:
      - jabref
    source: snap/local
    source-type: local
    plugin: dump
    organize:
      JabRef-launcher: bin/JabRef
  cleanup:
    after:
      - jabref
      - jabref-launcher
    plugin: nil
    build-snaps:
      - gnome-42-2204
    override-prime: |
      set -eux
      for snap in "gnome-42-2204"; do  # List all content-snaps you're using here
          cd "/snap/$snap/current" && find . -type f,l -exec rm -f "$SNAPCRAFT_PRIME/{}" "$SNAPCRAFT_PRIME/usr/{}" \;
      done
      for CRUFT in bug lintian man; do
          rm -rf $SNAPCRAFT_PRIME/usr/share/$CRUFT
      done
      find $SNAPCRAFT_PRIME/usr/share/doc/ -type f -not -name 'copyright' -delete
      find $SNAPCRAFT_PRIME/usr/share -type d -empty -delete