Skip to content

Commit 052a229

Browse files
committed
Add ant build for executables
1 parent 9ac9bc0 commit 052a229

10 files changed

+282
-46
lines changed

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/.idea/
22

33
# IntelliJ
4-
/out/
5-
/build/
4+
/build/coverage
5+
/build/logs
6+
/build/phar
7+
/build/*.phar
68

79
# JIRA plugin
810
atlassian-ide-plugin.xml

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ This is a parser for API Blueprint files in PHP.
44
## Usage
55
For direct usage you can run:
66
```bash
7-
$ ./phpdraft.phar blueprint-file.apib > blueprint-webpage.html
7+
$ ./phpdraft.phar -f blueprint-file.apib > blueprint-webpage.html
88
```
99
You can also install it first:
1010
```bash
1111
$ cp phpdraft.phar /usr/bin/phpdraft
1212
$ chmod +x /usr/bin/phpdraft
13-
$ phpdraft blueprint-file.apib > blueprint-webpage.html
13+
$ phpdraft -f blueprint-file.apib > blueprint-webpage.html
1414
```
1515

1616
## Including Files

build.xml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project name="phpdrafter" default="setup">
3+
<target name="setup" depends="clean"/>
4+
5+
<target name="clean" unless="clean.done" description="Cleanup build artifacts">
6+
<delete dir="${basedir}/bin"/>
7+
<delete dir="${basedir}/build/documentation"/>
8+
<delete dir="${basedir}/build/logfiles"/>
9+
<delete dir="${basedir}/build/phar"/>
10+
<delete>
11+
<fileset dir="${basedir}/build">
12+
<include name="**/phpdraft*.phar"/>
13+
<include name="**/phpdraft*.phar.asc"/>
14+
</fileset>
15+
</delete>
16+
17+
<property name="clean.done" value="true"/>
18+
</target>
19+
20+
<target name="signed-phar" depends="phar"
21+
description="Create signed PHAR archive of PHPDraft and all its dependencies">
22+
<exec executable="gpg" failonerror="true">
23+
<arg value="--armor"/>
24+
<arg value="--detach-sign"/>
25+
<arg path="${basedir}/build/phpdraft-library-${version}.phar"/>
26+
</exec>
27+
28+
<exec executable="gpg" failonerror="true">
29+
<arg value="--armor"/>
30+
<arg value="--detach-sign"/>
31+
<arg path="${basedir}/build/phpdraft-${version}.phar"/>
32+
</exec>
33+
</target>
34+
35+
<target name="phar" depends="-phar-determine-version,-phar-prepare"
36+
description="Create PHAR archive of PHPDraft and all its dependencies">
37+
<antcall target="-phar-build">
38+
<param name="type" value="release"/>
39+
</antcall>
40+
</target>
41+
42+
<target name="phar-nightly" depends="-phar-prepare"
43+
description="Create PHAR archive of PHPDraft and all its dependencies (nightly)">
44+
<antcall target="-phar-build">
45+
<param name="type" value="nightly"/>
46+
</antcall>
47+
</target>
48+
49+
<target name="-phar-prepare" depends="clean">
50+
<mkdir dir="${basedir}/build/phar"/>
51+
<copy file="${basedir}/LICENSE" tofile="${basedir}/build/phar/LICENSE"/>
52+
<exec executable="${basedir}/build/phar-manifest.php" output="${basedir}/build/phar/manifest.txt"/>
53+
</target>
54+
55+
<target name="-phar-build" depends="-phar-determine-version">
56+
<copy todir="${basedir}/build/phar/phpdraft/src">
57+
<fileset dir="${basedir}/src/">
58+
<exclude name="**/*Test.php*"/>
59+
<include name="**/*.php"/>
60+
<include name="**/*.js*"/>
61+
<include name="**/*.css*"/>
62+
</fileset>
63+
</copy>
64+
<copy todir="${basedir}/build/phar/phpdraft">
65+
<fileset dir="${basedir}">
66+
<include name="**/*.json*"/>
67+
<include name="**/index.php"/>
68+
</fileset>
69+
</copy>
70+
71+
<exec executable="${basedir}/build/phar-version.php" outputproperty="_version">
72+
<arg value="${version}"/>
73+
<arg value="${type}"/>
74+
</exec>
75+
76+
<exec executable="phpab" taskname="phpab">
77+
<arg value="--all"/>
78+
<arg value="--static"/>
79+
<arg value="--once"/>
80+
<arg value="--phar"/>
81+
<arg value="--hash"/>
82+
<arg value="SHA-1"/>
83+
<arg value="--output"/>
84+
<arg path="${basedir}/build/phpdraft-library-${_version}.phar"/>
85+
<arg value="--template"/>
86+
<arg path="${basedir}/build/library-phar-autoload.php.in"/>
87+
<arg path="${basedir}/build/phar"/>
88+
</exec>
89+
90+
<exec executable="phpab" taskname="phpab">
91+
<arg value="--all"/>
92+
<arg value="--nolower"/>
93+
<arg value="--static"/>
94+
<arg value="--phar"/>
95+
<arg value="--hash"/>
96+
<arg value="SHA-1"/>
97+
<arg value="--output"/>
98+
<arg path="${basedir}/build/phpdraft-${_version}.phar"/>
99+
<arg value="--template"/>
100+
<arg path="${basedir}/build/binary-phar-autoload.php.in"/>
101+
<arg path="${basedir}/build/phar"/>
102+
</exec>
103+
104+
<chmod file="${basedir}/build/phpdraft-${_version}.phar" perm="ugo+rx"/>
105+
</target>
106+
107+
<target name="-phar-determine-version">
108+
<exec executable="bash" outputproperty="version">
109+
<arg value="-c"/>
110+
<arg value="php ${basedir}/index.php -v | grep -ohE '([0-9]{1,}\.)+[0-9]{1,}'"/>
111+
</exec>
112+
</target>
113+
</project>

build/binary-phar-autoload.php.in

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env php
2+
<?php
3+
if (version_compare('5.6.0', PHP_VERSION, '>')) {
4+
fwrite(
5+
STDERR,
6+
'This version of PHPDraft requires PHP 5.6; using the latest version of PHP is highly recommended.' . PHP_EOL
7+
);
8+
9+
die(1);
10+
}
11+
12+
if (__FILE__ == realpath($GLOBALS['_SERVER']['SCRIPT_NAME'])) {
13+
$execute = true;
14+
} else {
15+
$execute = false;
16+
}
17+
18+
define('__PHPDRAFT_PHAR__', str_replace(DIRECTORY_SEPARATOR, '/', __FILE__));
19+
define('__PHPDRAFT_PHAR_ROOT__', 'phar://___PHAR___');
20+
21+
Phar::mapPhar('___PHAR___');
22+
23+
___FILELIST___
24+
25+
if ($execute) {
26+
if (isset($_SERVER['argv'][1]) && $_SERVER['argv'][1] == '--manifest') {
27+
print file_get_contents(__PHPDRAFT_PHAR_ROOT__ . '/manifest.txt');
28+
exit;
29+
}
30+
31+
require_once __PHPDRAFT_PHAR_ROOT__.DIRECTORY_SEPARATOR.'phpdraft'.DIRECTORY_SEPARATOR.'index.php';
32+
}
33+
34+
__HALT_COMPILER();

build/library-phar-autoload.php.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
define('__PHPDRAFT_PHAR__', str_replace(DIRECTORY_SEPARATOR, '/', __FILE__));
3+
define('__PHPDRAFT_PHAR_ROOT__', 'phar://___PHAR___');
4+
5+
Phar::mapPhar('___PHAR___');
6+
7+
___FILELIST___
8+
9+
__HALT_COMPILER();

build/phar-manifest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env php
2+
<?php
3+
print 'phpdraft/phpdraft: ';
4+
5+
$tag = @exec('git describe --tags 2>&1');
6+
7+
if (strpos($tag, '-') === false && strpos($tag, 'No names found') === false) {
8+
print $tag;
9+
} else {
10+
$branch = @exec('git rev-parse --abbrev-ref HEAD');
11+
$hash = @exec('git log -1 --format="%H"');
12+
print $branch . '@' . $hash;
13+
}
14+
15+
print "\n";

build/phar-version.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env php
2+
<?php
3+
if (!isset($argv[1]) || !isset($argv[2])) {
4+
exit(1);
5+
}
6+
7+
file_put_contents(
8+
__DIR__ . '/phar/phpdraft/index.php',
9+
str_replace(
10+
"define('VERSION', '');",
11+
"define('VERSION', '" . $argv[1] . "');",
12+
file_get_contents(__DIR__ . '/phar/phpdraft/index.php')
13+
)
14+
);
15+
16+
if ($argv[2] == 'release') {
17+
print $argv[1];
18+
} else {
19+
print $argv[2];
20+
}

config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"tmpdir": "/tmp/drafter",
3-
"logo": "/home/smillernl/Documents/5acf473a9e6a3deb8e98a2b6373d0a83.png"
3+
"logo": "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"
44
}

index.php

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,53 +10,18 @@
1010
*/
1111
require_once 'PHPDraft/Core/Autoloader.php';
1212
use PHPDraft\In\ApibFileParser;
13+
use PHPDraft\Out\UI;
1314
use PHPDraft\Parse\ApibToJson;
1415
use PHPDraft\Parse\JsonToHTML;
1516

16-
$options = getopt("f:t::i::h");
17-
if(!isset($argv[1]))
18-
{
19-
file_put_contents('php://stderr', 'Not enough arguments'.PHP_EOL);
20-
help();
21-
exit(1);
22-
}
17+
define('VERSION', '0');
2318

24-
if (boolval(preg_match('/^\-/',$argv[1])))
25-
{
26-
if (isset($options['h']))
27-
{
28-
help();
29-
exit(0);
30-
}
31-
elseif (isset($options['f']))
32-
{
33-
$file = $options['f'];
34-
}
35-
else
36-
{
37-
file_put_contents('php://stderr', 'No file to parse'.PHP_EOL);
38-
exit(1);
39-
}
40-
}
41-
else
42-
{
43-
$file = $argv[1];
44-
}
19+
$values = UI::main($argv);
4520

46-
$template = (isset($options['t']) && $options['t']) ? $options['t']: 'default';
47-
$image = (isset($options['i']) && $options['i']) ? $options['i']: NULL;
48-
49-
$apib = new ApibFileParser($file);
21+
$apib = new ApibFileParser($values['file']);
5022
$json = new ApibToJson($apib);
5123
$html = new JsonToHTML($json->parseToJson());
52-
$html->get_html($template, $image);
24+
$html->get_html($values['template'], $values['image']);
25+
5326

54-
function help()
55-
{
56-
echo 'This is a parser for API Blueprint files in PHP.'.PHP_EOL.PHP_EOL;
57-
echo "The following options can be used:.\n";
58-
echo "\t-f\tSpecifies the file to parse.\n";
59-
echo "\t-t\tSpecifies the template to use. (defaults to 'default')\n";
60-
echo "\t-h\tDisplays this text.\n";
61-
}
6227
?>

src/PHPDraft/Out/UI.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
/**
3+
* This file contains the UI.php
4+
*
5+
* @package php-drafter\SOMETHING
6+
* @author Sean Molenaar<sean@seanmolenaar.eu>
7+
*/
8+
9+
namespace PHPDraft\Out;
10+
11+
12+
class UI
13+
{
14+
static function main($argv = [])
15+
{
16+
$options = getopt("f:t::i::hv");
17+
if(!isset($argv[1]))
18+
{
19+
file_put_contents('php://stderr', 'Not enough arguments'.PHP_EOL);
20+
self::help();
21+
exit(1);
22+
}
23+
24+
if (boolval(preg_match('/^\-/',$argv[1])))
25+
{
26+
if (isset($options['h']))
27+
{
28+
self::help();
29+
exit(0);
30+
}
31+
32+
if (isset($options['v']))
33+
{
34+
self::version();
35+
exit(0);
36+
}
37+
38+
elseif (isset($options['f']))
39+
{
40+
$file = $options['f'];
41+
}
42+
else
43+
{
44+
file_put_contents('php://stderr', 'No file to parse'.PHP_EOL);
45+
exit(1);
46+
}
47+
}
48+
else
49+
{
50+
$file = $argv[1];
51+
}
52+
53+
$template = (isset($options['t']) && $options['t']) ? $options['t']: 'default';
54+
$image = (isset($options['i']) && $options['i']) ? $options['i']: NULL;
55+
56+
return [
57+
'file' => $file,
58+
'template' => $template,
59+
'image' => $image
60+
];
61+
}
62+
63+
static function help()
64+
{
65+
echo 'This is a parser for API Blueprint files in PHP.'.PHP_EOL.PHP_EOL;
66+
echo "The following options can be used:.\n";
67+
echo "\t-f\tSpecifies the file to parse.\n";
68+
echo "\t-t\tSpecifies the template to use. (defaults to 'default')\n";
69+
echo "\t-h\tDisplays this text.\n";
70+
}
71+
72+
static function version()
73+
{
74+
$version = (VERSION === '0') ? @exec('git describe --tags 2>&1') : VERSION;
75+
echo 'PHPDraft: '.$version;
76+
}
77+
78+
}

0 commit comments

Comments
 (0)