1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Pickle |
5
|
|
|
* |
6
|
|
|
* |
7
|
|
|
* @license |
8
|
|
|
* |
9
|
|
|
* New BSD License |
10
|
|
|
* |
11
|
|
|
* Copyright © 2015-2015, Pickle community. All rights reserved. |
12
|
|
|
* |
13
|
|
|
* Redistribution and use in source and binary forms, with or without |
14
|
|
|
* modification, are permitted provided that the following conditions are met: |
15
|
|
|
* * Redistributions of source code must retain the above copyright |
16
|
|
|
* notice, this list of conditions and the following disclaimer. |
17
|
|
|
* * Redistributions in binary form must reproduce the above copyright |
18
|
|
|
* notice, this list of conditions and the following disclaimer in the |
19
|
|
|
* documentation and/or other materials provided with the distribution. |
20
|
|
|
* * Neither the name of the Hoa nor the names of its contributors may be |
21
|
|
|
* used to endorse or promote products derived from this software without |
22
|
|
|
* specific prior written permission. |
23
|
|
|
* |
24
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
25
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
26
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
27
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE |
28
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
29
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
30
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
31
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
32
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
33
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
34
|
|
|
* POSSIBILITY OF SUCH DAMAGE. |
35
|
|
|
*/ |
36
|
|
|
|
37
|
|
|
namespace Pickle\Package\PHP\Command; |
38
|
|
|
|
39
|
|
|
use Closure; |
40
|
|
|
use Composer\Package\Version\VersionParser; |
41
|
|
|
use Phar; |
42
|
|
|
use PharData; |
43
|
|
|
use Pickle\Base\Interfaces; |
44
|
|
|
use Pickle\Package\PHP\Util\PackageJson; |
45
|
|
|
use Pickle\Package\Util\Header; |
46
|
|
|
|
47
|
|
|
class Release implements Interfaces\Package\Release |
48
|
|
|
{ |
49
|
|
|
/** |
50
|
|
|
* @var \Pickle\Base\Interfaces\Package |
51
|
|
|
*/ |
52
|
|
|
protected $pkg; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var Closure |
56
|
|
|
*/ |
57
|
|
|
protected $cb; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var bool |
61
|
|
|
*/ |
62
|
|
|
protected $noConvert = false; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Constructor. |
66
|
|
|
* |
67
|
|
|
* @param string $path |
68
|
|
|
* @param Closure $cb |
69
|
|
|
* @param bool $noConvert |
70
|
|
|
*/ |
71
|
|
|
public function __construct($path, $cb = null, $noConvert = false) |
72
|
|
|
{ |
73
|
|
|
$this->pkg = $this->readPackage($path); |
74
|
|
|
$this->cb = $cb; |
75
|
|
|
$this->noConvert = $noConvert; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Create package. |
80
|
|
|
*/ |
81
|
|
|
public function create(array $args = []) |
82
|
|
|
{ |
83
|
|
|
$archBasename = $this->pkg->getSimpleName() . '-' . $this->pkg->getPrettyVersion(); |
|
|
|
|
84
|
|
|
|
85
|
|
|
/* Work around bug #67417 [NEW]: ::compress modifies archive basename |
86
|
|
|
creates temp file and rename it */ |
87
|
|
|
$tempName = getcwd() . '/pkl-tmp.tar'; |
88
|
|
|
if (file_exists($tempName)) { |
89
|
|
|
unlink($tempName); |
90
|
|
|
} |
91
|
|
|
$arch = new PharData($tempName); |
92
|
|
|
$pkgDir = $this->pkg->getRootDir(); |
93
|
|
|
|
94
|
|
|
foreach ($this->pkg->getFiles() as $file) { |
|
|
|
|
95
|
|
|
if (is_file($file)) { |
96
|
|
|
$name = str_replace($pkgDir, '', $file); |
97
|
|
|
$arch->addFile($file, $name); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
if (file_exists($tempName)) { |
101
|
|
|
@unlink($tempName . '.gz'); |
|
|
|
|
102
|
|
|
} |
103
|
|
|
$arch->compress(Phar::GZ); |
104
|
|
|
unset($arch); |
105
|
|
|
|
106
|
|
|
rename($tempName . '.gz', $archBasename . '.tgz'); |
107
|
|
|
unlink($tempName); |
108
|
|
|
|
109
|
|
|
if ($this->cb) { |
110
|
|
|
$cb = $this->cb; |
111
|
|
|
$cb($this->pkg); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function packLog() |
116
|
|
|
{ |
117
|
|
|
/* pass, no logging seems to be happening here yet */ |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
protected function readPackage($path) |
121
|
|
|
{ |
122
|
|
|
$package = PackageJson::readPackage($path, $this->noConvert); |
123
|
|
|
$package->setRootDir(realpath($path)); |
124
|
|
|
|
125
|
|
|
/* We're not adding any versions into the composer.json for the source release. |
126
|
|
|
Instead we just set the package version and that's it. The version is to be |
127
|
|
|
contained in the extension sources, so no need to maintain it more than once. |
128
|
|
|
*/ |
129
|
|
|
$version = new Header\Version($package); |
130
|
|
|
$package->replaceVersion((new VersionParser())->normalize($version), $version); |
|
|
|
|
131
|
|
|
|
132
|
|
|
return $package; |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/* vim: set tabstop=4 shiftwidth=4 expandtab: fdm=marker */ |
137
|
|
|
|