# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: @SNAP_NAME@

summary: @SNAP_SUMMARY@ 
description: |@SNAP_DISCLAIMER@
  Apache NetBeans IDE lets you quickly and easily develop Java
  desktop, enterprise, and  web applications, as well as HTML5 applications
  with HTML, JavaScript, and CSS. The IDE also provides a great set of tools for
  PHP and C/C++ developers.
  It is free and open source and has a large community of users and developers
  around the world.
  
  It requires Java 17 or later Java Development Kit installed.

icon: snap/gui/frame512.png
confinement: classic
grade: @SNAP_GRADE@
base: core22
architectures: 
  - build-on: [ amd64 ]
    build-for: [ amd64 ]
  - build-on: [ amd64 ]
    build-for: [ arm64 ]
compression: lzo

version: "@SNAP_VERSION@"

parts:
      
  build:
    build-attributes: [ no-patchelf ]
    plugin: dump
    source: @SNAP_SOURCE@
    override-build: |
        mv netbeans $SNAPCRAFT_PART_INSTALL/netbeans
        # Make the default cache and data directory relative to Snap user directory
        sed -i 's/${HOME}\/.netbeans/${SNAP_USER_DATA}/' $SNAPCRAFT_PART_INSTALL/netbeans/bin/netbeans
        sed -i 's/${HOME}\/.cache\/netbeans/${SNAP_USER_COMMON}\/${SNAP_REVISION}/' $SNAPCRAFT_PART_INSTALL/netbeans/bin/netbeans
        sed -i 's/"${DEFAULT_USERDIR_ROOT}\/.*"/"${DEFAULT_USERDIR_ROOT}"/g' $SNAPCRAFT_PART_INSTALL/netbeans/etc/netbeans.conf
        sed -i 's/"${DEFAULT_CACHEDIR_ROOT}\/.*"/"${DEFAULT_CACHEDIR_ROOT}"/g' $SNAPCRAFT_PART_INSTALL/netbeans/etc/netbeans.conf        
        sed -i 's/-J-Dapple.laf.useScreenMenuBar=true/-J-Dplugin.manager.install.global=false/' $SNAPCRAFT_PART_INSTALL/netbeans/etc/netbeans.conf
        chmod a+r $SNAPCRAFT_PART_INSTALL/netbeans/etc/netbeans.conf
        find $SNAPCRAFT_PART_INSTALL/netbeans -type f -name *.sh -exec chmod a+rx {} \;
    stage:
        - netbeans/*
        - -netbeans/*.built
        - -netbeans/extra

  launchers:
    source: snap/local/launchers
    plugin: dump
    organize:
      '*': launchers/

apps:
  netbeans:
    command-chain:
      - launchers/userdir-cleanup
      - launchers/patch-netbeans-conf
    command: netbeans/bin/netbeans

