| 1 | #! /bin/false | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # Copyright (C) 2016-2018 Guido Flohr <guido.flohr@cantanea.com>, | ||||||||||||||||||||||||||||
| 4 | # all rights reserved. | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | # This program is free software: you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 7 | # it under the terms of the GNU General Public License as published by | ||||||||||||||||||||||||||||
| 8 | # the Free Software Foundation; either version 3 of the License, or | ||||||||||||||||||||||||||||
| 9 | # (at your option) any later version. | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | # This program is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||||||||||||||||||
| 14 | # GNU General Public License for more details. | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | # You should have received a copy of the GNU General Public License | ||||||||||||||||||||||||||||
| 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | package Qgoda::Repository; | ||||||||||||||||||||||||||||
| 20 | 1 | $Qgoda::Repository::VERSION = 'v0.9.2'; | |||||||||||||||||||||||||||
| 21 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | ▶ | use Locale::TextDomain qw(qgoda); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 1 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | use File::HomeDir; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 1 | ▶ | use File::Temp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 1 | ▶ | use Qgoda; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 1 | ▶ | use Qgoda::Util qw(read_file write_file is_archive); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 1 | ▶ | use URI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | sub new { | ||||||||||||||||||||||||||||
| 35 | 8 | ▶ | my ($class, $uri) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=20 SCAR=36.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 8 | $uri = URI->new($uri); | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | # This is a mess! Re-write it from scratch ... | ||||||||||||||||||||||||||||
| 40 | 8 | ▶ | if ($uri =~ m{^\.\.?\\/}) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 41 | 0 | $uri = 'file://' . File::Spec->rel2abs($uri); | |||||||||||||||||||||||||||
| 42 | 0 | $uri =~ s{\\}{/}g; | |||||||||||||||||||||||||||
| 43 | 0 | $uri = URI->new($uri); | |||||||||||||||||||||||||||
| 44 | } elsif ($uri =~ s{^~([^/\\]*)}{}) { | ||||||||||||||||||||||||||||
| 45 | 0 | my $user = $1; | |||||||||||||||||||||||||||
| 46 | 0 | my $home; | |||||||||||||||||||||||||||
| 47 | 0 | ▶ | if (length $user) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 0 | $home = File::HomeDir->user_home($user); | |||||||||||||||||||||||||||
| 49 | } else { | ||||||||||||||||||||||||||||
| 50 | 0 | $home = File::HomeDir->my_home; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | 0 | $uri = 'file://' . $home . '/' . $uri; | |||||||||||||||||||||||||||
| 53 | 0 | $uri =~ s{\\}{/}g; | |||||||||||||||||||||||||||
| 54 | 0 | $uri = URI->new($uri); | |||||||||||||||||||||||||||
| 55 | } elsif (File::Spec->file_name_is_absolute($uri)) { | ||||||||||||||||||||||||||||
| 56 | 0 | $uri = URI->new('file://' . $uri); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 8 | ▶ | if (undef eq $uri->scheme) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 1 | my $file = "$uri"; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 1 | ▶ | if (File::Spec->file_name_is_absolute($file)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 0 | $uri = URI->new($file, 'file'); | |||||||||||||||||||||||||||
| 64 | } else { | ||||||||||||||||||||||||||||
| 65 | 1 | ▶ | if ($file =~ /^[_a-zA-Z][_a-zA-Z0-9]*\@/) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 66 | # Replace the first colon with a slash. | ||||||||||||||||||||||||||||
| 67 | 0 | $uri =~ s{:}{/}; | |||||||||||||||||||||||||||
| 68 | 0 | $uri = URI->new('git+ssh://' . $uri); | |||||||||||||||||||||||||||
| 69 | ▶ | } elsif (!-e $file && $file =~ m{/}) { | |||||||||||||||||||||||||||
|
Condition33%1/3
not -e $file and $file =~ m[/]
MC/DC0%0/2
not -e $file and $file =~ m[/]
not -e $file
$file =~ m[/]
Truth table33%1/3
not(A) and B
A= not -e $fileB= $file =~ m[/]
| |||||||||||||||||||||||||||||
| 70 | 1 | $uri = URI->new('git://github.com/' . $file); | |||||||||||||||||||||||||||
| 71 | } else { | ||||||||||||||||||||||||||||
| 72 | 0 | $uri = URI::file->new_abs($file); | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 8 | my $self = { | |||||||||||||||||||||||||||
| 78 | __uri => $uri | ||||||||||||||||||||||||||||
| 79 | }; | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 8 | my $protocol = $uri->scheme; | |||||||||||||||||||||||||||
| 82 | 8 | my %known = ( | |||||||||||||||||||||||||||
| 83 | 'git' => 'Git', | ||||||||||||||||||||||||||||
| 84 | 'git+ssh' => 'Git', | ||||||||||||||||||||||||||||
| 85 | 'git+http' => 'Git', | ||||||||||||||||||||||||||||
| 86 | 'git+https' => 'Git', | ||||||||||||||||||||||||||||
| 87 | 'git+file' => 'Git', | ||||||||||||||||||||||||||||
| 88 | 'file' => 'File' | ||||||||||||||||||||||||||||
| 89 | ); | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 8 | ▶ | $self->{__type} = $known{$protocol} || 'LWP'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$known{$protocol} || 'LWP'
MC/DC100%1/1
$known{$protocol} || 'LWP'
$known{$protocol}
Truth table100%2/2
A
A= $known{$protocol}
| |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 8 | ▶ | if ('Git' eq $self->{__type}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 6 | my $scheme = $self->{__uri}->scheme; | |||||||||||||||||||||||||||
| 95 | 6 | ▶ | if ($scheme =~ /\+(.*)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 4 | $self->{__uri}->scheme($1); | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | # If an http/https URI does not look like an archive, assume that it is | ||||||||||||||||||||||||||||
| 101 | # also a git URI. | ||||||||||||||||||||||||||||
| 102 | 8 | ▶ | if ('http' eq $uri->scheme || 'https' eq $uri->scheme) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
"http" eq $uri->scheme or "https" eq $uri->scheme
MC/DC100%2/2
"http" eq $uri->scheme or "https" eq $uri->scheme
"http" eq $uri->scheme
"https" eq $uri->scheme
Truth table100%3/3
A or B
A= "http" eq $uri->schemeB= "https" eq $uri->scheme
| |||||||||||||||||||||||||||||
| 103 | # These are file name extenders likely to contain an archive. | ||||||||||||||||||||||||||||
| 104 | 3 | ▶ | if (!is_archive $uri->path) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 2 | $self->{__type} = 'Git'; | |||||||||||||||||||||||||||
| 106 | $self->{__source} = 'Github' | ||||||||||||||||||||||||||||
| 107 | 2 | ▶ | if 'github.com' eq $self->{__uri}->host; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 8 | ▶ | if ($self->{__type}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 8 | ▶ | if ('Git' eq $self->{__type}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 6 | ▶ | if ('github.com' eq $self->{__uri}->host) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 4 | $self->{__source} = 'Github'; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 8 | bless $self, $class; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 8 | ▶ | sub type { shift->{__type} } | ||||||||||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 123 | 8 | ▶ | sub source { shift->{__source} } | ||||||||||||||||||||||||||
|
Subroutine
source: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 124 | 0 | ▶ | sub uri { shift->{__uri} } | ||||||||||||||||||||||||||
|
Subroutine
uri: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | sub fetch { | ||||||||||||||||||||||||||||
| 127 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
fetch: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 0 | my $logger = Qgoda->new->logger; | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | my $fetcher_class = 'Qgoda::Repository::Fetcher::' . $self->{__type}; | |||||||||||||||||||||||||||
| 132 | 0 | my $fetcher_module = $fetcher_class; | |||||||||||||||||||||||||||
| 133 | 0 | $fetcher_module =~ s{::}{/}g; | |||||||||||||||||||||||||||
| 134 | 0 | $fetcher_module .= '.pm'; | |||||||||||||||||||||||||||
| 135 | 0 | require $fetcher_module; | |||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 0 | $logger->info(__x("fetching '{uri}'", uri => $self->{__uri})); | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 0 | my $tmp = File::Temp->newdir; | |||||||||||||||||||||||||||
| 140 | 0 | $logger->debug(__x("created temporary directory '{dir}'", | |||||||||||||||||||||||||||
| 141 | dir => $tmp)); | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 0 | my $fetcher = $fetcher_class->new; | |||||||||||||||||||||||||||
| 144 | 0 | my $dir = $fetcher->fetch($self->{__uri}, $tmp->dirname); | |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | # Return the object as well, so that it doesn't go out of scope here. | ||||||||||||||||||||||||||||
| 147 | 0 | return ($dir, $tmp); | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | package URI::git; | ||||||||||||||||||||||||||||
| 151 | 1 | $URI::git::VERSION = 'v0.9.2'; | |||||||||||||||||||||||||||
| 152 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 1 | ▶ | use base qw(URI::http); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | package URI::git_Phttp; | ||||||||||||||||||||||||||||
| 157 | 1 | $URI::git_Phttp::VERSION = 'v0.9.2'; | |||||||||||||||||||||||||||
| 158 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 1 | ▶ | use base qw(URI::git); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | package URI::git_Phttps; | ||||||||||||||||||||||||||||
| 163 | 1 | $URI::git_Phttps::VERSION = 'v0.9.2'; | |||||||||||||||||||||||||||
| 164 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 1 | ▶ | use base qw(URI::git); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | package URI::git_Pssh; | ||||||||||||||||||||||||||||
| 169 | 1 | $URI::git_Pssh::VERSION = 'v0.9.2'; | |||||||||||||||||||||||||||
| 170 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 1 | ▶ | use base qw(URI::git); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | package URI::git_Pfile; | ||||||||||||||||||||||||||||
| 175 | 1 | $URI::git_Pfile::VERSION = 'v0.9.2'; | |||||||||||||||||||||||||||
| 176 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 1 | ▶ | use base qw(URI::file); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 1 | 1; | |||||||||||||||||||||||||||