Skip to content

Commit 95275c9

Browse files
author
Tim Sheppard
committed
Initial commit of basic copy functionality
0 parents  commit 95275c9

File tree

8 files changed

+783
-0
lines changed

8 files changed

+783
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea/
2+
target/
3+

.travis.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
language: scala
2+
scala:
3+
- 2.12.3
4+
jdk:
5+
- oraclejdk8
6+
notifications:
7+
email:
8+
recipients:
9+
10+
sudo: false

LICENCE.txt

Lines changed: 661 additions & 0 deletions
Large diffs are not rendered by default.

Readme.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# SBT Git Hooks
2+
3+
[![Build Status](https://travis-ci.org/randomcoder/sbt-git-hooks.svg?branch=master)](https://travis-ci.org/randomcoder/sbt-git-hooks)
4+
5+
SBT auto plugin to use [Gherkin Converter](https://github.com/randomcoder/git-hooks) to generate html from
6+
`.feature` files.
7+
8+
### How to use
9+
10+
`sbt-git-hooks` is an auto plugin for SBT 1.0.
11+
12+
Add the plugin to your build with the following in `project/plugins.sbt`:
13+
14+
```
15+
addSbtPlugin("uk.co.randomcoding" % "sbt-git-hooks" % "0.1.0")
16+
```
17+
18+
### Licence
19+
20+
This plugin is licenced under the [AGPL v3](https://www.gnu.org/licenses/agpl-3.0.en.html)
21+
22+
### Contributions
23+
24+
Contributions are welcome. Please create a fork and submit pull requests.

build.sbt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name := "sbt-git-hooks"
2+
3+
version := "0.1.0"
4+
5+
scalaVersion := "2.12.3"
6+
7+
organization := "uk.co.randomcoding"
8+
9+
sbtPlugin := true
10+
11+
resolvers += Resolver.sonatypeRepo("snapshots")
12+
13+
licenses += ("AGPLv3", url("https://www.gnu.org/licenses/agpl-3.0.en.html"))
14+
15+
publishMavenStyle := false
16+
17+
bintrayRepository := "sbt-plugins"
18+
19+
bintrayOrganization in bintray := None
20+
21+
bintrayVcsUrl := Some("[email protected]:randomcoder/sbt-git-hooks.git")

project/bintray.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.1")

project/build.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version = 1.0.1
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (C) 2017. RandomCoder <[email protected]>
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Affero General Public License as
6+
* published by the Free Software Foundation, either version 3 of the
7+
* License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Affero General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Affero General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
package uk.co.randomcoding.sbt
18+
19+
import java.nio.file.attribute.PosixFilePermissions
20+
import java.nio.file.{Files, StandardCopyOption}
21+
22+
import sbt.Keys._
23+
import sbt._
24+
25+
import scala.util.Properties
26+
27+
object GitHooks extends AutoPlugin {
28+
override def trigger = allRequirements
29+
30+
object autoImport {
31+
32+
val writeHooks = taskKey[Unit]("Write Git Hooks")
33+
val hooksSourceDir = settingKey[Option[File]]("Directory containing pre written git hooks")
34+
val gitHooksDir = settingKey[Option[File]]("Directory to write the git hooks to")
35+
36+
lazy val gitHooksSettings: Seq[Def.Setting[_]] = Seq(
37+
hooksSourceDir in writeHooks := None,
38+
writeHooks := {
39+
val hooksSource = (hooksSourceDir in writeHooks).value.getOrElse(baseDirectory.value / "hooks")
40+
val targetDirectory = (gitHooksDir in writeHooks).value.getOrElse(baseDirectory.value / ".git" / "hooks")
41+
42+
streams.value.log.info(s"Writing hooks from $hooksSource to $targetDirectory")
43+
WriteGitHooks(hooksSource, targetDirectory)
44+
streams.value.log.info(s"Successfully written hooks from $hooksSource to $targetDirectory")
45+
}
46+
)
47+
}
48+
49+
import autoImport._
50+
override val projectSettings: Seq[Setting[_]] = inConfig(Compile)(gitHooksSettings)
51+
}
52+
53+
object WriteGitHooks {
54+
55+
def apply(hooksSourceDir: File, hooksTargetDir: File): Unit = {
56+
hooksSourceDir.listFiles.foreach { hook =>
57+
val hookTarget = hooksTargetDir.toPath.resolve(hook.getName)
58+
Files.copy(hook.toPath, hookTarget, StandardCopyOption.REPLACE_EXISTING)
59+
if (!Properties.isWin) Files.setPosixFilePermissions(hookTarget, PosixFilePermissions.fromString("rwxr-xr-x"))
60+
}
61+
}
62+
}

0 commit comments

Comments
 (0)