common.gradle 885 B

1234567891011121314151617181920212223242526
  1. gradle.allprojects {
  2. ext.getGitInfoSuffix = {
  3. String result = "";
  4. try {
  5. File headFile = new File('.git/HEAD');
  6. if (headFile.exists()) {
  7. String[] strings = headFile.getText('UTF-8').split(" ");
  8. if (strings.size() > 1) {
  9. String refFilePath = '.git/' + strings[1].replace("\n", "");
  10. if (refFilePath.contains("/")) {
  11. String branchName = refFilePath.substring(refFilePath.lastIndexOf("/") + 1);
  12. result += "_" + branchName;
  13. }
  14. // File refFile = new File(refFilePath);
  15. // result += "_" + refFile.getText('UTF-8').substring(0, 7);
  16. }
  17. }
  18. } catch (Exception e) {
  19. e.printStackTrace();
  20. }
  21. return result;
  22. }
  23. }