crotwell / gradle-macappbundle

A Gradle Plugin to create a Mac OSX .app application and dmg based on the project.
Apache License 2.0
94 stars 33 forks source link

There doesn't seem to be a way to create a /Applications alias in a dmg without a background image #58

Closed hepcat72 closed 5 years ago

hepcat72 commented 6 years ago

There's potentially 2 issues here. I tried creating my own /Applications alias using this code in macAppBundle:

    exec {
      commandLine 'ln', '-s', '/Applications', "${buildDir}/macApp/Applications"
      standardOutput = new ByteArrayOutputStream()
    }

but that leads to the error:

Could not list contents of '/Users/rleach/git/treeview3/build/macApp/Applications/Disk Inventory X.app/Contents/Frameworks/CocoaTechStrings.framework/Headers'. Couldn't follow symbolic link.

because it appears to be following the symbolic link when it creates the dmg.

So I was searching the code and discovered that macAppBundle will create a /Applications alias if I just set a background image.

I'm going to work around this by creating a single white pixel background image, but it seems that:

  1. The creation of the dmg shouldn't follow symlinks
  2. The creation of the default /Applications alias shouldn't depend on defining a background image.
crotwell commented 6 years ago

For 1), the dmg creation is done by hdiutil, and it has no options for not following symlinks. Sorry, but that is not something I have the ability to fix. The correct way to do the linking is to create it inside the dmg after it has been created. Then it will function as you want.

For 2) it would be nice to allow this, but using a "blank" background image seems a good workaround. I'll leave this issue open and try to add an option if I make another release, but not sure if or when that would happen.

hepcat72 commented 6 years ago

So for 1), would it be a command-line call to hdiutil to add the alias to the dmg created by running the createDmg task? So, I would run gradle createDmg, then run the new task you're proposing to add the alias? I'm not very familiar with hdiutil. This is the first mac app I've ever built. If this is how that would be handled, could I also define window locations for the README and sample data file I added? Because their default locations appear to be filling the window from top-left to right, above the .app and apps alias...

macAppBundle {
  ...
  copyMacPkgFiles()
}

def copyMacPkgFiles() {
  copy {
    from file("${projectDir}/")
    into file("${buildDir}/macApp")
    include 'README.md'
    rename('README.md','README.txt')
  }
  mkdir file("${buildDir}/macApp/Sample")
  copy {
    from file("${projectDir}/src/main/resources")
    into file("${buildDir}/macApp/Sample")
    include 'spellman.cdt'
  }
}
crotwell commented 6 years ago

You have to first create the dmg, then mount it, then do whatever extra stuff you want, then unmount it.

See https://github.com/crotwell/gradle-macappbundle/blob/master/src/main/groovy/edu/sc/seis/macAppBundle/MacAppBundlePlugin.groovy about line 296 for the dmg creation and about line 383 for how the linking it is done internally.

This page although old, maybe useful.

victorkifer commented 6 years ago

@hepcat72 opened a pull request which should add this functionality https://github.com/crotwell/gradle-macappbundle/pull/62

crotwell commented 5 years ago

In v2.2.3