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:



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/buildr4osgi/osgi/project_extension.rb', line 143

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)
          rm_rf installed
          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.



141
142
143
# File 'lib/buildr4osgi/osgi/project_extension.rb', line 141

def local
  @local
end

#projectObject

Returns the value of attribute project.



141
142
143
# File 'lib/buildr4osgi/osgi/project_extension.rb', line 141

def project
  @project
end