Gradle任务将hg修订版写入文件

时间:2012-12-17 19:01:41

标签: version-control groovy mercurial gradle

是否有一种简单的方法可以在gradle任务中写入mercurial版本(或类似的外部命令):

我还不熟悉/熟悉,但我目前的努力看起来像这样:

task versionInfo(type:Exec){
    commandLine 'hg id -i -b -t'
    ext.versionfile = new File('bin/$baseName-buildinfo.properties')

    doLast {
        versionfile.text = 'build.revision=' + standardOutput.toString()
    }
}

2 个答案:

答案 0 :(得分:13)

此构建脚本存在两个问题:

  1. 命令行需要拆分; gradle尝试使用参数hg id -i -b thgid-i
  2. 执行名为-b而不是t的二进制文件
  3. 需要捕获标准输出;您可以将其设为ByteOutputStream以便稍后阅读
  4. 试试这个:

    task versionInfo(type:Exec){
        commandLine 'hg id -i -b -t'.split()
        ext.versionfile = new File('bin/$baseName-buildinfo.properties')
        standardOutput = new ByteArrayOutputStream()
    
        doLast {
            versionfile.text = 'build.revision=' + standardOutput.toString()
        }
    }
    

答案 1 :(得分:1)

这里我有一些不同的方法,它使用javahg来获得修订。并添加任务" writeRevisionToFile"

我在我的博客Gradle - Get Hg Mercurial revision上写了一篇简短的帖子。

enum CalendarEventError: ErrorType {
    case UnAuthorized
    case AccessDenied
    case Failed
}

func insertEventToDefaultCalendar(event :EKEvent) throws {
    let eventStore = EKEventStore()
    switch EKEventStore.authorizationStatusForEntityType(.Event) {
    case .Authorized:
        do {
            try insertEvent(eventStore, event: event)
        } catch {
            throw CalendarEventError.Failed
        }

    case .Denied:
        throw CalendarEventError.AccessDenied

    case .NotDetermined:
        eventStore.requestAccessToEntityType(EKEntityType.Event, completion: { (granted, error) -> Void in
            if granted {
                //insertEvent(eventStore)
            } else {
                //throw CalendarEventError.AccessDenied
            }
        })
    default:
    }
}
相关问题