0

I have a java/recipes/windows recipe that uses a method called win_friendly_path and it doesn't work because win_friendly_path is not yet defined.

win_friendly_path is however defined in the ../windows/libraries/windows_helper.rb as follows:

module Windows
  module Helper
def win_friendly_path(path)
      path.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR || '\\') if path
    end

I already have my berksfile and metadata.rb setup in the java (./) recipe to depend on the windows cookbook.

I'm not sure how to include this module so right now I am trying to just use include WindowsHelper in the java/cookbook/windows recipe and receiving this error:

uninitialized constant #<Class:#<Chef::Recipe:0x00000000029a2188>>::WindowsHelper

I have tried several variations of this and now feel like I have spent way too much time troubleshooting the issue so any help is appreciated.

UPDATE: plugging in this line ::Chef::Resource.send(:include, Windows::Helper) to my java/recipes/windows recipe gives me the following error:

Chef::Exceptions::ValidationFailed
       ----------------------------------
       value is a required property
aphexlog
  • 1,503
  • 3
  • 16
  • 43

2 Answers2

1

Try this

include Windows::Helper
Ilya Konyukhov
  • 2,666
  • 1
  • 12
  • 21
  • I receive the following error when adding that line: undefined method `include' for cookbook: java, recipe: windows :Chef::Recipe – aphexlog Oct 09 '18 at 18:30
  • Interesting. How about this one: ```Chef::Resource.send(:include, Windows::Helper)``` ? – Ilya Konyukhov Oct 09 '18 at 18:47
  • I edited my question to include the following: I have tried both Chef::Resource.send(:include, Windows::Helper) and ::Chef::Resource.send(:include, Windows::Helper) resulting in the following error: value is a required property – aphexlog Oct 09 '18 at 18:54
-1

Inserting the following line resolved this issue for me:

::Chef::Recipe.send(:include, Windows::Helper)

This allows me to use the variables following module from the windows cookbook:

module Windows
  module Helper
...
{Variable}
  {Other_variable}
...
aphexlog
  • 1,503
  • 3
  • 16
  • 43