Class: BuildTool::VCS::Archive

Inherits:
Base
  • Object
show all
Defined in:
lib/build-tool/vcs/archive.rb

Overview

class ArchiveConfiguration

Defined Under Namespace

Classes: ArchiveError, FileNotFoundError

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#configure, #gc, #initialize, #local_path, #local_path_exist?, #prepare_for_vcs_access, #recipe

Constructor Details

This class inherits a constructor from BuildTool::VCS::Base

Instance Method Details

#apply_patches(patches) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
# File 'lib/build-tool/vcs/archive.rb', line 93

def apply_patches( patches )
    patches.each do |patch|
        full_path = self.recipe.find_first_config_file( "custom/#{config.module.name}/patches/#{patch}.patch" )
        if full_path.nil?
            raise FileNotFoundError, "Patch '#{patch}' not found from module #{config.module.name}."
        end
        logger.info "Applying patch #{patch}"
        self.class.execute( "patch -p1 -i #{full_path}", local_path )
    end

end

#apply_patches_after_rebase?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/build-tool/vcs/archive.rb', line 69

def apply_patches_after_rebase?
    true
end

#archive_local_pathObject



73
74
75
# File 'lib/build-tool/vcs/archive.rb', line 73

def archive_local_path
    "#{File.dirname( local_path )}/#{archive_name}"
end

#archive_nameObject



77
78
79
# File 'lib/build-tool/vcs/archive.rb', line 77

def archive_name
    File.basename( archive_url )
end

#archive_urlObject



81
82
83
# File 'lib/build-tool/vcs/archive.rb', line 81

def archive_url
    "#{config.repository.url}/#{config.remote_path}"
end

#checkedout?Boolean

METHODS

Returns:

  • (Boolean)


89
90
91
# File 'lib/build-tool/vcs/archive.rb', line 89

def checkedout?
    File.exist? archive_local_path
end

#cloneObject



105
106
107
108
109
# File 'lib/build-tool/vcs/archive.rb', line 105

def clone
    fetch()
    rebase()
    0
end

#fetchObject



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
# File 'lib/build-tool/vcs/archive.rb', line 111

def fetch()
    # Check if the archive is already downloaded
    if File.exist? archive_local_path
        logger.trace "Archive already fetched. Skipping."
        return 0
    end

    # If the archive doesn't exist we assume the unpacked archive
    # should not exist too.
    if local_path_exist?
        logger.trace "We fetch a new archive. Remove the old sources."
        FileUtils.rm_rf local_path if !$noop
    end

    # Create the directories parent dir.
    FileUtils.mkdir_p( File.dirname( local_path ) ) if !$noop

    # Download the archive
    logger.trace "get #{archive_name} from #{archive_url} to #{archive_local_path}"
    if !$noop
        target = open( archive_local_path, "wb" )
        open( archive_url ) { |file|
            while c = file.getc
                target.putc c
            end
        }
        target.close()
    end
    return 0
end

#fetching_supported?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/build-tool/vcs/archive.rb', line 61

def fetching_supported?
    true
end

#guess_top_level_directoryObject



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/build-tool/vcs/archive.rb', line 142

def guess_top_level_directory
    return "<topdir>" if $noop
    topdir = nil
    if archive_name =~ /(\.tgz|\.tar\.gz)$/
        if self.class.execute( "gunzip -c #{archive_local_path} | tar tf -" ) { |line| 
            rc = /^([^\/]*)\//.match( line )
            if topdir and topdir != rc[1]
                raise StandardError, "Unable to determine toplevel directory for archive #{archive_name}!"
            end
            topdir = rc[1]
        } != 0 
            # No topdir
            return nil
        end
    else
        raise NotImplementedError, "No idea how to unpack the archive '#{archive_name}'."
    end
    return topdir
end

#nameObject

Attributes



57
58
59
# File 'lib/build-tool/vcs/archive.rb', line 57

def name
    "archive"
end

#patches_supported?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/build-tool/vcs/archive.rb', line 65

def patches_supported?
    true
end

#prepare_for_accessObject



193
194
195
196
197
198
199
200
201
202
# File 'lib/build-tool/vcs/archive.rb', line 193

def prepare_for_access
    # If our server has an associated ssh-key, add it to the ssh-agent.
    if config.repository.sshkey
        key = config.repository.sshkey
        logger.info ""
        logger.info "#### Adding required ssh-key #{key.file} to ssh-agent."
        MJ::Tools::SSH::add_key key.file
    end
    true
end

#rebaseObject



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
# File 'lib/build-tool/vcs/archive.rb', line 162

def rebase

    # Check if the archive is already downloaded
    if !File.exist? archive_local_path
        logger.debug "Archive not fetched. Skipping."
        return 0
    end

    if local_path_exist?
        return 0
    end

    # Create the directory we want to use to checkout
    FileUtils.mkdir_p local_path if !$noop

    if archive_name =~ /(\.tgz|\.tar\.gz)$/
        if guess_top_level_directory()
            cmd = "gunzip -c #{archive_local_path} | tar --strip-components=1 --extract --file=- --directory=#{local_path}"
        else
            cmd = "gunzip -c #{archive_local_path} | tar --strip-components=0 --extract --file=- --directory=#{local_path}"
        end
        if self.class.execute( cmd ) != 0
            raise StandardError, "Failed to unpack the archive: $?"
        end
    else
        raise NotImplementedError, "No idea how to unpack the archive"
    end

    0
end