Skip to content
This repository has been archived by the owner on Oct 5, 2018. It is now read-only.

Commit

Permalink
gh-pages only cleans up target
Browse files Browse the repository at this point in the history
The pages CopySpec defaults to targeting the root of the repo,
but in cases like documentation, you may want to target a subfolder
such as one using the version in the name. This can already be done
with the into method on the CopySpec. With this change the into
setting of the pages CopySpec is also what controls which directory
is cleaned up before the copy. This allows multiple versions of doc
to exist in the repo without having the be kept in source or generated
each time. This fixes #94.
  • Loading branch information
ajoberstar committed May 24, 2016
1 parent ce80baf commit 77bd53d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class GithubPagesPlugin implements Plugin<Project> {
Task task = project.tasks.create(PREPARE_TASK_NAME, Copy)
task.with {
description = 'Prepare the gh-pages changes locally'
with extension.pages
with extension.pages.realSpec
into { extension.workingDir }
doFirst {
extension.workingDir.deleteDir()
Expand All @@ -71,7 +71,8 @@ class GithubPagesPlugin implements Plugin<Project> {
extension.deleteExistingFiles = true
}

def filesList = extension.workingDir.list({ dir, name ->
def targetDir = project.file("${extension.workingDir}/${extension.pages.relativeDestinationDir}")
def filesList = targetDir.list({ dir, name ->
return !name.equals('.git')
})
if (filesList && extension.deleteExistingFiles) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.ajoberstar.gradle.git.ghpages

import groovy.transform.PackageScope

import org.ajoberstar.grgit.Grgit
import org.ajoberstar.grgit.exception.GrgitException

Expand Down Expand Up @@ -76,10 +78,9 @@ class GithubPagesPluginExtension implements AuthenticationSupported {
* the extension for
*/
GithubPagesPluginExtension(Project project) {
this.project = project;
this.pages = project.copySpec {
from 'src/main/ghpages'
}
this.project = project
this.pages = new DestinationCopySpec(project)
pages.from 'src/main/ghpages'

// defaulting the repoUri to the project repo's origin
try {
Expand Down Expand Up @@ -126,4 +127,28 @@ class GithubPagesPluginExtension implements AuthenticationSupported {
void credentials(Closure closure) {
ConfigureUtil.configure(closure, credentials)
}

static class DestinationCopySpec implements CopySpec {
private Project project
private Object destPath

@Delegate
CopySpec realSpec

public DestinationCopySpec(Project project) {
this.project = project
this.realSpec = project.copySpec {}
}

public File getRelativeDestinationDir() {
return destPath ? project.file(destPath) : new File('.')
}

@Override
public CopySpec into(Object destPath) {
this.destPath = destPath
realSpec.into(destPath)
return this
}
}
}

0 comments on commit 77bd53d

Please sign in to comment.