Class: OSGi::InstallTask

Inherits:
Rake::Task
  • Object
show all
Includes:
BundleCollector
Defined in:
lib/buildr4osgi/osgi/project_extension.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Attributes included from BundleCollector

#bundles, #project_dependencies, #projects

Instance Method Summary collapse

Methods included from BundleCollector

#_collect, #collect

Constructor Details

#initialize(*args) ⇒ InstallTask

:nodoc:



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/buildr4osgi/osgi/project_extension.rb', line 99

def initialize(*args) #:nodoc:
  super

  enhance do |task|
    dependencies = []
    project.projects.each do |subp|
      collect(subp)
      dependencies |= bundles
    end
    collect(project)
    dependencies |= bundles
    dependencies.flatten.uniq.sort.each {|bundle|
      
      begin
        if File.directory?(bundle.file)
          begin
           
            tmp = File.join(Dir::tmpdir, File.basename(bundle.file))
            rm tmp if File.exists? tmp
            base = Pathname.new(bundle.file)
            Zip::ZipFile.open(tmp, Zip::ZipFile::CREATE) {|zipfile|
              Dir.glob("#{bundle.file}/**/**").each do |file|
                if(file.match(/.*\.jar/)) #unpack the jars in the directory so its contents are readable by all Java compilers.
                  Zip::ZipFile.open(file) do |source|
                    source.entries.reject { |entry| entry.directory? }.each do |entry|
                      zipfile.get_output_stream(entry.name) {|output| output.write source.read(entry.name)}
                    end
                  end
                else
                  zipfile.add(Pathname.new(file).relative_path_from(base), file)
                end
              end
            }
            bundle.file = tmp
            
          rescue Exception => e
            error e.message
            trace e.backtrace.join("\n")
          end
          
        end
        
        if local
          artifact = Buildr::artifact(bundle.to_s)
          installed = Buildr.repositories.locate(artifact)
          mkpath File.dirname(installed)
          Buildr::artifact(bundle.to_s).from(bundle.file).install
          info "Installed #{installed}"
        else
          Buildr::artifact(bundle.to_s).from(bundle.file).upload
          info "Uploaded #{bundle}"
        end
      rescue Exception => e
        error "Error installing the artifact #{bundle.to_s}"
        trace e.message
        trace e.backtrace.join("\n")
      end
    }
  end
end

Instance Attribute Details

#localObject

Returns the value of attribute local.



97
98
99
# File 'lib/buildr4osgi/osgi/project_extension.rb', line 97

def local
  @local
end

#projectObject

Returns the value of attribute project.



97
98
99
# File 'lib/buildr4osgi/osgi/project_extension.rb', line 97

def project
  @project
end