Skip to content

Commit 8af9ee2

Browse files
author
Gianluca Arbezzano
committed
Merge branch 'release/0.6.0'
2 parents 58ed3e2 + 948e6ad commit 8af9ee2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2610
-799
lines changed

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
tests/*.expect
2-
tests/*.result
1+
.test_fs
32
build/
43
vendor/
5-
phpctags

.travis.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
language: php
2+
3+
php:
4+
- 5.3
5+
- 5.4
6+
- 5.5
7+
- 5.6
8+
- 7
9+
- hhvm
10+
11+
before_script:
12+
- composer self-update
13+
- composer install
14+
- if [ "$TRAVIS_PHP_VERSION" = 'hhvm' ]; then export COMPOSER_PROCESS_TIMEOUT=900; fi
15+
16+
script:
17+
- vendor/bin/phpunit
18+
19+
matrix:
20+
fast_finish: true
21+
allow_failures:
22+
- php: 7

ChangeLog.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
Version 0.6.0
2+
* Exclude phpctags when re-building phar
3+
* Fix typo in README.md
4+
* Fixed PHPUnit.xml.dist
5+
* Refactoring codebase
6+
* Refactroing testsuite
7+
* Now composer support an entry point to install in globally
8+
* Define new build flow
9+
110
Version 0.5.1
211
-------------
312

Makefile

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ source := README.md \
66
PHPCtags.class.php
77

88
.PHONY: all
9-
all: phpctags
9+
all: build/phpctags.phar
1010

1111
.PHONY: clean
1212
clean:
1313
@echo "Cleaning executables ..."
14-
@rm -f ./phpctags
1514
@rm -f ./build/phpctags.phar
1615
@echo "Done!"
1716

@@ -20,7 +19,6 @@ dist-clean:
2019
@echo "Cleaning old build files and vendor libraries ..."
2120
@rm -rf ./build
2221
@rm -rf ./vendor
23-
@rm -f ./phpctags
2422
@echo "Done!"
2523

2624
.PHONY: install
@@ -45,8 +43,3 @@ vendor: composer.lock build/composer.phar
4543
build/phpctags.phar: vendor $(source) | build
4644
@php -dphar.readonly=0 buildPHAR.php
4745
@chmod +x build/phpctags.phar
48-
49-
phpctags: build/phpctags.phar
50-
@echo "Building phpctags ..."
51-
@cp build/phpctags.phar phpctags
52-
@echo "Done!"

PHPCtags.class.php

Lines changed: 104 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,18 @@ class PHPCtags
2020
);
2121

2222
private $mParser;
23-
24-
private $mStructs;
25-
23+
private $mLines;
2624
private $mOptions;
25+
private $tagdata;
26+
private $cachefile;
27+
private $filecount;
2728

2829
public function __construct($options)
2930
{
3031
$this->mParser = new PHPParser_Parser(new PHPParser_Lexer);
31-
$this->mStructs = array();
32+
$this->mLines = array();
3233
$this->mOptions = $options;
34+
$this->filecount = 0;
3335
}
3436

3537
public function setMFile($file)
@@ -59,6 +61,10 @@ public function addFile($file)
5961
$this->mFiles[realpath($file)] = 1;
6062
}
6163

64+
public function setCacheFile($file) {
65+
$this->cachefile = $file;
66+
}
67+
6268
public function addFiles($files)
6369
{
6470
foreach ($files as $file) {
@@ -250,12 +256,16 @@ private function struct($node, $reset=FALSE, $parent=array())
250256
return $structs;
251257
}
252258

253-
private function render()
259+
private function render($structure)
254260
{
255261
$str = '';
256-
foreach ($this->mStructs as $struct) {
262+
foreach ($structure as $struct) {
257263
$file = $struct['file'];
258264

265+
if (!in_array($struct['kind'], $this->mOptions['kinds'])) {
266+
continue;
267+
}
268+
259269
if (!isset($files[$file]))
260270
$files[$file] = file($file);
261271

@@ -357,19 +367,42 @@ private function render()
357367
$str .= "\n";
358368
}
359369

360-
// remove the last line ending
361-
$str = trim($str);
370+
// remove the last line ending and carriage return
371+
$str = trim(str_replace("\x0D", "", $str));
372+
373+
return $str;
374+
}
375+
376+
private function full_render() {
377+
// Files will have been rendered already, just join and export.
378+
379+
$str = '';
380+
foreach($this->mLines as $file => $data) {
381+
$str .= $data.PHP_EOL;
382+
}
362383

363384
// sort the result as instructed
364385
if (isset($this->mOptions['sort']) && ($this->mOptions['sort'] == 'yes' || $this->mOptions['sort'] == 'foldcase')) {
365386
$str = self::stringSortByLine($str, $this->mOptions['sort'] == 'foldcase');
366387
}
367388

389+
// Save all tag information to a file for faster updates if a cache file was specified.
390+
if (isset($this->cachefile)) {
391+
file_put_contents($this->cachefile, serialize($this->tagdata));
392+
if ($this->mOptions['v']) {
393+
echo "Saved cache file.".PHP_EOL;
394+
}
395+
}
396+
397+
$str = trim($str);
398+
368399
return $str;
369400
}
370401

371402
public function export()
372403
{
404+
$start = microtime(true);
405+
373406
if (empty($this->mFiles)) {
374407
throw new PHPCtagsException('No File specified.');
375408
}
@@ -378,14 +411,30 @@ public function export()
378411
$this->process($file);
379412
}
380413

381-
return $this->render();
414+
$content = $this->full_render();
415+
416+
$end = microtime(true);
417+
418+
if ($this->mOptions['V']) {
419+
echo "It tooks ".($end-$start)." seconds.".PHP_EOL;
420+
}
421+
422+
return $content;
382423
}
383424

384425
private function process($file)
385426
{
427+
// Load the tag md5 data to skip unchanged files.
428+
if (!isset($this->tagdata) && isset($this->cachefile) && file_exists(realpath($this->cachefile))) {
429+
if ($this->mOptions['v']) {
430+
echo "Loaded cache file.".PHP_EOL;
431+
}
432+
$this->tagdata = unserialize(file_get_contents(realpath($this->cachefile)));
433+
}
434+
386435
if (is_dir($file) && isset($this->mOptions['R'])) {
387436
$iterator = new RecursiveIteratorIterator(
388-
new RecursiveDirectoryIterator(
437+
new ReadableRecursiveDirectoryIterator(
389438
$file,
390439
FilesystemIterator::SKIP_DOTS |
391440
FilesystemIterator::FOLLOW_SYMLINKS
@@ -404,31 +453,64 @@ private function process($file)
404453
}
405454

406455
try {
407-
$this->setMFile((string) $filename);
408-
$this->mStructs = array_merge(
409-
$this->mStructs,
410-
$this->struct($this->mParser->parse(file_get_contents($this->mFile)), TRUE)
411-
);
456+
$this->process_single_file($filename);
412457
} catch(Exception $e) {
413458
echo "PHPParser: {$e->getMessage()} - {$filename}".PHP_EOL;
414459
}
415460
}
416461
} else {
417462
try {
418-
$this->setMFile($file);
419-
$this->mStructs = array_merge(
420-
$this->mStructs,
421-
$this->struct($this->mParser->parse(file_get_contents($this->mFile)), TRUE)
422-
);
463+
$this->process_single_file($file);
423464
} catch(Exception $e) {
424-
echo "PHPParser: {$e->getMessage()} - {$filename}".PHP_EOL;
465+
echo "PHPParser: {$e->getMessage()} - {$file}".PHP_EOL;
466+
}
467+
}
468+
}
469+
470+
private function process_single_file($filename)
471+
{
472+
if ($this->mOptions['v'] && $this->filecount > 1 && $this->filecount % 64 == 0) {
473+
echo " ".$this->filecount." files".PHP_EOL;
474+
}
475+
$this->filecount++;
476+
477+
$this->setMFile((string) $filename);
478+
$file = file_get_contents($this->mFile);
479+
$md5 = md5($file);
480+
if (isset($this->tagdata[$this->mFile][$md5])) {
481+
// The file is the same as the previous time we analyzed and saved.
482+
$this->mLines[$this->mFile] = $this->tagdata[$this->mFile][$md5];
483+
if ($this->mOptions['V']) {
484+
echo ".";
425485
}
486+
return;
487+
}
488+
489+
$struct = $this->struct($this->mParser->parse($file), TRUE);
490+
$this->mLines[$this->mFile] = $this->render($struct);
491+
$this->tagdata[$this->mFile][$md5] = $this->mLines[$this->mFile];
492+
if ($this->mOptions['debug']) {
493+
echo "Parse: ".($finishfile - $startfile).", Merge: ".($finishmerge-$finishfile)."; (".$this->filecount.")".$this->mFile.PHP_EOL;
494+
} else if ($this->mOptions['v']) {
495+
echo "U";
426496
}
427497
}
498+
428499
}
429500

430501
class PHPCtagsException extends Exception {
431502
public function __toString() {
432-
return "PHPCtags: {$this->message}\n";
503+
return "\nPHPCtags: {$this->message}\n";
504+
}
505+
}
506+
507+
class ReadableRecursiveDirectoryIterator extends RecursiveDirectoryIterator {
508+
function getChildren() {
509+
try {
510+
return new ReadableRecursiveDirectoryIterator($this->getPathname());
511+
} catch(UnexpectedValueException $e) {
512+
file_put_contents('php://stderr', "\nPHPPCtags: {$e->getMessage()} - {$this->getPathname()}\n");
513+
return new RecursiveArrayIterator(array());
514+
}
433515
}
434516
}

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
phpctags
22
========
3+
Master [![Build Status](https://travis-ci.org/vim-php/phpctags.svg)](https://travis-ci.org/vim-php/phpctags?branch=master)
4+
Develop [![Build Status](https://travis-ci.org/vim-php/phpctags.svg)](https://travis-ci.org/vim-php/phpctags?branch=develop)
35

46
An enhanced php [ctags](http://ctags.sourceforge.net/) index file generator
57
compatible with http://ctags.sourceforge.net/FORMAT.
@@ -18,6 +20,14 @@ Enjoy!
1820
Installation
1921
------------
2022

23+
## Download
24+
25+
```
26+
curl -Ss http://vim-php.com/phpctags/install/phpctags.phar > phpctags
27+
php ./phpctags
28+
```
29+
30+
## Build
2131
> We currently only support building PHAR executable for \*nix like platform
2232
which provides `make` utility. If you are interested in building an executable
2333
for other platform, especially for Windows, please help yourself out. It
@@ -27,7 +37,7 @@ provide a patch for this.
2737

2838
Installation is simple, make sure you have PHP's PHAR extension enabled, then
2939
just run `make` in the root directory of the source, you will get a `phpctags`
30-
PHAR executable, add it to your `$PATH`, then you can invoke `phpcatgs`
40+
PHAR executable, add it to your `$PATH`, then you can invoke `phpctags`
3141
directly from anywhere.
3242

3343
See [phpctags on packagist](http://packagist.org/packages/techlivezheng/phpctags)

bin/phpctags

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env php
2+
3+
<?php
4+
include(__DIR__."/../bootstrap.php");

0 commit comments

Comments
 (0)