Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add APP, JAR packaging code #136

Merged
merged 9 commits into from Oct 24, 2012
Merged

Add APP, JAR packaging code #136

merged 9 commits into from Oct 24, 2012

Conversation

wasnotrice
Copy link
Member

This is the code from wasnotrice/shoes-warbler slurped up into Shoes 4. See the README section on packaging to get started.

Kick the tires, especially on Windows.

Thanks!

@ashbb
Copy link
Member

ashbb commented Oct 21, 2012

@wasnotrice Awesome! I did the following on my Windows 7.

  • download wasnotrice/shoes4 branch:pkg into c:\tmp
  • cd c:\tmp\shoes4
  • jruby --1.9 -S rake gem
  • jruby --1.9 -S gem install pkg\shoes-4.0.0.pre1

So far worked perfect.

I wrote my app and save as c:\tmp\test1.rb.

Shoes.app do
  para 'hello shoes 4!!'
end

Then,

  • C:\tmp\shoes4>bin\shoes -p swt:app c:\tmp\test1.rb

I got an error. So, I wrote a snippet and save as c:\tmp\shoes4\bin\shoes.bat.

call jruby --1.9 -e "$LOAD_PATH.unshift File.expand_path('../lib', __FILE__); require 'shoes/cli'; Shoes::CLI.new.run(['%0','%1', '%2', '%3'])"

Then again,

  • C:\tmp\shoes4>bin\shoes -p swt:app c:\tmp\test1.rb

Wow, my app was run! I could see hello shoes 4!! on my app window!
I closed my app window by hand and got the following console log:

C:\tmp\shoes4>call jruby --1.9 -e "$LOAD_PATH.unshift File.expand_path('../lib',
 __FILE__); require 'shoes/cli'; Shoes::CLI.new.run(['bin\shoes','-p', 'swt:app'
, 'c:\tmp\test1.rb'])"
Packaging swt:app...
Creating pkg/tmp/shoesapp.jar
D, [2012-10-21T10:47:01.627000 #11052] DEBUG -- : main_window on_close block beg
in... disposing ::Swt.display
D, [2012-10-21T10:47:01.643000 #11052] DEBUG -- : ::Swt.display disposed

But umm... where is test1.app?
I couldn't find c:\tmp\pkg\test1.app. There was no c:\tmp\pkg directory.

@ashbb
Copy link
Member

ashbb commented Oct 21, 2012

Found pkg/Shoes App.app. In my case, the full path is C:\jruby\bin\pkg\Shoes App.app.

Okay then, I think C:\jruby\bin\pkg\Shoes App.app\Contents\Java\shoesapp.jar is the packaged file. Right?

If so, how to execute the shoesapp.jar file?
I did the following. But got error messages...

C:\jruby\bin\pkg\Shoes App.app\Contents\Java>ls
shoesapp.jar

C:\jruby\bin\pkg\Shoes App.app\Contents\Java>java -Djruby.compat.version=1.9 -ja
r shoesapp.jar
NameError: cannot load Java class org.eclipse.jface.viewers.ColumnViewerToolTipS
upport
  get_proxy_or_package_under_package at org/jruby/javasupport/JavaUtilities.java
:54
                      method_missing at file:/c:/ashbb/Temp/jruby563601848452194
8458extract/jruby-core-1.6.8.jar!/builtin/javasupport/java.rb:51
                             Viewers at file:C:/jruby/bin/pkg/Shoes App.app/Cont
ents/Java/shoesapp.jar!/gems/swt-0.13/lib/swt/full.rb:107
                               JFace at file:C:/jruby/bin/pkg/Shoes App.app/Cont
ents/Java/shoesapp.jar!/gems/swt-0.13/lib/swt/full.rb:106
                              (root) at file:C:/jruby/bin/pkg/Shoes App.app/Cont
ents/Java/shoesapp.jar!/gems/swt-0.13/lib/swt/full.rb:101
                             require at org/jruby/RubyKernel.java:1071
                             require at file:C:/jruby/bin/pkg/Shoes App.app/Cont
ents/Java/shoesapp.jar!/gems/swt-0.13/lib/swt/full.rb:55
                              (root) at file:C:/jruby/bin/pkg/Shoes App.app/Cont
ents/Java/shoesapp.jar!/gems/swt-0.13/lib/swt.rb:3
                             require at org/jruby/RubyKernel.java:1071
                             require at file:C:/jruby/bin/pkg/Shoes App.app/Cont
ents/Java/shoesapp.jar!/gems/swt-0.13/lib/swt.rb:55
                              (root) at file:C:/jruby/bin/pkg/Shoes App.app/Cont
ents/Java/shoesapp.jar!/gems/shoes-4.0.0.pre1/lib/shoes/swt.rb:4
                             require at org/jruby/RubyKernel.java:1071
                             require at file:C:/jruby/bin/pkg/Shoes App.app/Cont
ents/Java/shoesapp.jar!/gems/shoes-4.0.0.pre1/lib/shoes/swt.rb:55
                            backend= at file:C:/jruby/bin/pkg/Shoes App.app/Cont
ents/Java/shoesapp.jar!/gems/shoes-4.0.0.pre1/lib/shoes/configuration.rb:24
                              (root) at file:/C:/jruby/bin/pkg/Shoes App.app/Con
tents/Java/shoesapp.jar!/META-INF/init.rb:8
                             require at org/jruby/RubyKernel.java:1071
                             require at file:/C:/jruby/bin/pkg/Shoes App.app/Con
tents/Java/shoesapp.jar!/META-INF/init.rb:36
                              (root) at <script>:2

cannot load Java class org.eclipse.jface.viewers.ColumnViewerToolTipS
upport

Umm,... need to install something?

@wasnotrice
Copy link
Member Author

@ashbb Thanks for trying out packaging on Windows!

Wow, my app was run! I could see hello shoes 4!! on my app window!

Awesome! Except -p is just supposed to package, not to run the app :P

I couldn't find c:\tmp\pkg\test1.app. There was no c:\tmp\pkg directory.

Found pkg/Shoes App.app. In my case, the full path is C:\jruby\bin\pkg\Shoes App.app.

You were right to expect the .jar and the .app to be in c:\tmp\pkg. This is the right place to look. On OS X, this is where the packages are created. The pkg dir should be relative to test1.rb, but it looks like it was created relative to jruby. This is either a problem with the packaging classes, or possibly with the snippet you are using to run the CLI. Can you run the specs and see if they also have the same problem? There should be failures in the jar and app specs if the directory is created in the wrong place.

Okay then, I think C:\jruby\bin\pkg\Shoes App.app\Contents\Java\shoesapp.jar is the packaged file. Right?

Right!

If so, how to execute the shoesapp.jar file?

Just as you did. I know this error :)

There is a bug in the Swt gem where those JFace libs will get loaded if the gem is installed normally, but will fail if the gem is bundled within a .jar. It's because jar paths contain a !, as you can see in your stacktrace. I fixed the bug on my OS X with this monkeypatch. The monkeypatch is supposed to be loaded here, but maybe it's not being loaded correctly, or maybe the monkeypatch needs to be improved ;)

@ashbb
Copy link
Member

ashbb commented Oct 23, 2012

I tried from scratch. :)

  • cd c:\tmp
  • git clone git://github.com/wasnotrice/shoes4.git
  • cd shoes4
  • git checkout -b pkg remotes/origin/pkg
  • Save this snippet as c:\tmp\shoes4\bin\shoes.bat
call jruby --1.9 -e "$LOAD_PATH.unshift File.expand_path('../lib', __FILE__); require 'shoes/cli'; Shoes::CLI.new.run(['%3', '%1', '%2', '%3'])"
  • Replace the code in c:\tmp\shoes4\lib\swt\full-monkeypatch.rb
module JFace
  path = case Config::CONFIG["host_os"]
    when /windows|mswin/i
      "../../../../swt-*/vendor/jface/*.jar"
    else
      "../../../vendor/jface/*.jar"
    end

  Dir[File.expand_path path, __FILE__].each do |jar_fn|
    require jar_fn
  end
end
  • Comment out line 16 in c:\tmp\shoes4\lib\shoes\swt\app.rb
#shell.set_image ::Swt::Graphics::Image.new(::Swt.display, SHOES_ICON)
  • jruby --1.9 -S rake gem
  • jruby --1.9 -S gem install pkg\shoes-4.0.0.pre1
  • cd c:\tmp
  • mkdir hello
  • Save my app snippet as c:\tmp\hello\hello.rb
Shoes.app do
  para 'hello shoes 4!!'
end
  • cd c:\jruby\lib\ruby\gems\1.8\gems\shoes-4.0.0.pre1
  • bin\shoes.bat -p swt:app c:\tmp\hello\hello.rb
  • Close my app window by hand. I got c:\tmp\hello\pkg directory. Yay!
  • cd "c:\tmp\hello\pkg\Shoes App.app\Contents\Java"
  • java -Djruby.compat.version=1.9 -jar shoesapp.jar

Finaly, my app was launched from in the shoesapp.jar. :)

But there is still one problem. In the above steps, I commented out line 16 in c:\tmp\shoes4\lib\shoes\swt\app.rb. So, SHOES_ICON isn't set on my app window. :(

If I didn't comment out the line 16, I got the following error messages when I run the shoesapp.jar.

c:\tmp\hello\pkg\Shoes App.app\Contents\Java>java -Djruby.compat.version=1.9 -ja
r shoesapp.jar
NativeException: org.eclipse.swt.SWTException: i/o error (java.io.FileNotFoundEx
ception: file:C:\tmp\hello\pkg\Shoes App.app\Contents\Java\shoesapp.jar!\gems\sh
oes-4.0.0.pre1\lib\shoes\..\..\static\shoes-icon.png (Syntax error: file name or 
directory name or volume lavel))
  initialize at file:C:/tmp/hello/pkg/Shoes App.app/Contents/Java/shoesapp.jar!/
gems/shoes-4.0.0.pre1/lib/shoes/swt/app.rb:16
         tap at org/jruby/RubyKernel.java:1816
  initialize at file:C:/tmp/hello/pkg/Shoes App.app/Contents/Java/shoesapp.jar!/
gems/shoes-4.0.0.pre1/lib/shoes/swt/app.rb:15
  initialize at file:C:/tmp/hello/pkg/Shoes App.app/Contents/Java/shoesapp.jar!/
gems/shoes-4.0.0.pre1/lib/shoes/app.rb:43
         app at file:C:/tmp/hello/pkg/Shoes App.app/Contents/Java/shoesapp.jar!/
gems/shoes-4.0.0.pre1/lib/shoes/app.rb:13
      (root) at file:/C:/tmp/hello/pkg/Shoes App.app/Contents/Java/shoesapp.jar!
/shoes-app/hello.rb:1
        load at org/jruby/RubyKernel.java:1097
      (root) at file:/C:/tmp/hello/pkg/Shoes App.app/Contents/Java/shoesapp.jar!
/shoes-app/hello.rb:1
     require at org/jruby/RubyKernel.java:1071
     require at file:/C:/tmp/hello/pkg/Shoes App.app/Contents/Java/shoesapp.jar!
/META-INF/main.rb:55
      (root) at <script>:3

@wasnotrice
Copy link
Member Author

@ashbb Thanks for working on this! Would you please give me a link to your Shoes App.app so I can see if it runs on OS X?

Finaly, my app was launched from in the shoesapp.jar. :)

Awesome!

But there is still one problem. In the above steps, I commented out line 16 in c:\tmp\shoes4\lib\shoes\swt\app.rb. So, SHOES_ICON isn't set on my app window. :(

OK. This looks like a problem with ".." in .jar paths on Windows, maybe. I wonder if Pathname#cleanpath would fix that?

But there is another problem with this line. The app.yaml lets you add a custom icon (see spec/test_app/img). In the .app, this gets set as the application icon. Great. But when you launch the app, this line that you commented out _overwrites the icon_, changing it back to the Shoes icon. This line works well for running an app that doesn't have its own icon, but not well for running a packaged app that does have its own icon :( So we need to change this line somehow anyway.

@ashbb ashbb merged commit 5f578d3 into shoes:master Oct 24, 2012
@ashbb
Copy link
Member

ashbb commented Oct 24, 2012

@wasnotrice

Would you please give me a link to your Shoes App.app so I can see if it runs on OS X?

Download from here, please. :)

@wasnotrice
Copy link
Member Author

@ashbb it works! Hooray! I have now run Shoes App.apps created on OS X, Windows, and Linux!

![](https://dl.dropbox.com/u/610739/Screenshots/Screen Shot 2012-10-24 at 11.31.14 AM.png)

there is a small problem with the new application security features in OS X 10.8. By default, applications only run if they have been signed by a developer's key. Otherwise, you get this:

This is fine, of course, because you can change that preference, but it's a hassle. I'll have to see if we can allow developers to sign their apps if they have a key from Apple. Then at least some apps wouldn't raise that warning.

@pjfitzgibbons
Copy link
Member

Can we possibly get a developer key as "Shoes Project" or something? The
app can use it in the self-publishing mode?

Peter Fitzgibbons
(847) 859-9550
Email: peter.fitzgibbons@gmail.com
IM GTalk: peter.fitzgibbons
IM AOL: peter.fitzgibbons@gmail.com

On Wed, Oct 24, 2012 at 11:53 AM, Eric Watson notifications@github.comwrote:

@ashbb https://github.com/ashbb it works! Hooray! I have now run Shoes
App.apps created on OS X, Windows, and Linux!

https://dl.dropbox.com/u/610739/Screenshots/Screen%20Shot%202012-10-24%20at%2011.31.14%20AM.png

there is a small problem with the new application security features in OS
X 10.8. By default, applications only run if they have been signed by a
developer's key. Otherwise, you get this:

https://dl.dropbox.com/u/610739/Screenshots/Screen%20Shot%202012-10-24%20at%2011.28.28%20AM.png

This is fine, of course, because you can change that preference, but it's
a hassle. I'll have to see if we can allow developers to sign their apps if
they have a key from Apple. Then at least some apps wouldn't raise that
warning.


Reply to this email directly or view it on GitHubhttps://github.com//pull/136#issuecomment-9746974.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants