PageRenderTime 53ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/bin/release-tool.php

http://github.com/WindowsAzure/azure-sdk-for-php
PHP | 107 lines | 66 code | 10 blank | 31 comment | 19 complexity | deda044ebed03c1888e7f32f6a44c35b MD5 | raw file
  1. #!/usr/bin/env php
  2. <?php
  3. /**
  4. * LICENSE: Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. * http://www.apache.org/licenses/LICENSE-2.0.
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. *
  15. * PHP version 5
  16. *
  17. * @category Microsoft
  18. *
  19. * @author Azure PHP SDK <azurephpsdk@microsoft.com>
  20. * @copyright Microsoft Corporation
  21. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  22. *
  23. * @link https://github.com/windowsazure/azure-sdk-for-php
  24. */
  25. /**
  26. * Update the version number of PHP files, and generate class list.
  27. *
  28. * 1. change the NEW_VER const to the correct new version string
  29. * 2. run php .\bin\release-tool.php in the root directory
  30. */
  31. const VER_TOKEN = ' * @version';
  32. const NEW_VER = ' Release: 0.5.0_2016-11';
  33. $startDir = __DIR__.'/../'; //this will update SDK sources, test sources and examples.
  34. $updateVersion = true;
  35. $listClass = false;
  36. $files_changed = 0;
  37. $output = '';
  38. foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($startDir)) as $filename => $cur) {
  39. if (is_dir($filename) || strpos($filename, 'release-tool.php') !== false) {
  40. continue;
  41. }
  42. if ($updateVersion) {
  43. $tempfile = $filename.'.tmp';
  44. $rhandle = fopen($filename, 'r');
  45. $whandle = fopen($tempfile, 'w');
  46. $replaced = false;
  47. while (($buffer = fgets($rhandle, 4096)) !== false) {
  48. if (strpos($buffer, VER_TOKEN) !== false) {
  49. $buffer = VER_TOKEN.NEW_VER."\n";
  50. $replaced = true;
  51. }
  52. fputs($whandle, $buffer);
  53. }
  54. fclose($rhandle);
  55. fclose($whandle);
  56. if ($replaced) {
  57. rename($tempfile, $filename);
  58. ++$files_changed;
  59. } else {
  60. unlink($tempfile);
  61. }
  62. }
  63. if ($listClass) {
  64. $path_parts = pathinfo($filename);
  65. if (array_key_exists('extension', $path_parts) && $path_parts['extension'] == 'php') {
  66. //remove leading . or ..
  67. if (strpos($filename, '.') !== false && strpos($filename, '.') == 0) {
  68. $filename = substr($filename, 1);
  69. }
  70. if (strpos($filename, '..') !== false && strpos($filename, '..') == 0) {
  71. $filename = substr($filename, 2);
  72. }
  73. $filename = str_replace('/', '\\', $filename);
  74. // remove leading \
  75. if (strpos($filename, '\\') !== false && strpos($filename, '\\') == 0) {
  76. $filename = substr($filename, 1);
  77. }
  78. $path_parts = pathinfo($filename);
  79. $classname = $path_parts['dirname'].'\\'.$path_parts['filename'];
  80. $classname = strtolower(str_replace('\\', '\\\\', $classname));
  81. // remove the top directory from file name
  82. if (strpos($filename, '\\') !== false) {
  83. $filename = substr($filename, strpos($filename, '\\'));
  84. }
  85. $filename = str_replace('\\', '/', $filename);
  86. //'src\\table\\tablerestproxy' => '/Table/TableRestProxy.php'
  87. $output = $output." '$classname' => '$filename',\n";
  88. }
  89. }
  90. }
  91. if ($listClass) {
  92. file_put_contents('output.txt', $output);
  93. }
  94. echo sprintf("\nNumber of files updated: %d.\n", $files_changed);