Skip to content

Commit

Permalink
Avoid use of deprecated directoryProperty() method
Browse files Browse the repository at this point in the history
Gradle 5 deprecates the one on ProjectLayout in favor of ObjectFactory.

This resolves #64 and supersedes #71.
  • Loading branch information
ajoberstar committed Mar 23, 2019
1 parent 121d46d commit 739e3e6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
31 changes: 17 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,17 @@ apply plugin: 'org.ajoberstar.git-publish'

### Configuration

**NOTE:** In general, there are no default values here. The main exception is that the `repoUri` will be automatically set if you use the `org.ajoberstar.grgit` plugin to your project's origin repo URI.
**NOTE:** In general, there are no default values here. The main exception is that the `repoUri` and `referenceRepoUri` will be automatically set if you use the `org.ajoberstar.grgit` plugin to your project's origin repo URI.

```groovy
gitPublish {
// where to publish to (repo must exist)
repoUri = '[email protected]:ajoberstar/test-repo.git'
// (or 'https://github.com/ajoberstar/test-repo.git', depending on authentication)
// where to fetch from prior to fetching from the remote (i.e. a local repo to save time)
referenceRepoUri = 'file:///home/human/projects/test-repo/'
// branch will be created if it doesn't exist
branch = 'gh-pages'
Expand Down Expand Up @@ -84,10 +87,10 @@ gitPublish {

Generally, you'll just run `gitPublishPush`, but there is a series of four tasks that happen in order.

* `gitPublishReset` - Clones/updates the working repo to the latest commit on the `repoUri` `branch` head. All files not included by the `preserve` filters will be deleted and staged.
* `gitPublishCopy` - Copies any files defined in the `contents` CopySpec into the working repo.
* `gitPublishCommit` - Commits all changes to the working repo.
* `gitPublishPush` - If changes were committed, pushed them to the `repoUri`.
- `gitPublishReset` - Clones/updates the working repo to the latest commit on the `repoUri` `branch` head. All files not included by the `preserve` filters will be deleted and staged.
- `gitPublishCopy` - Copies any files defined in the `contents` CopySpec into the working repo.
- `gitPublishCommit` - Commits all changes to the working repo.
- `gitPublishPush` - If changes were committed, pushed them to the `repoUri`.

### Avoiding Extra Copy

Expand All @@ -106,15 +109,15 @@ gitPublishCommit.dependsOn jbakeTask

The following table should help translate settings you used in `org.ajoberstar.github-pages` to this plugin's format. Additionally reference the Configuration section above for more information on the current feature set.

| org.ajoberstar.github-pages | org.ajoberstar.git-publish | Comment |
|-----------------------------|-----------------------------|---------|
| `repoUri` | `repoUri` | Used to allow any Object (which would be lazily unpacked to a String). Now requires a String. |
| `targetBranch` | `branch` | The old plugin defaulted to `gh-pages`, the new one has no default. This must be a String. |
| `workingPath` | `repoDir` | Used to allow any Object and called `file()` on it for you. Now expects a File. |
| `pages` | `contents` | Just a name change. |
| `deleteExistingFiles` | `preserve` | If previously `true` (the default), do nothing. If previously `false`, `preserve { include '**/*' }`
| `commitMessage` | `commitMessage` | Just copy from the old value. |
| `credentials` | env variable or system prop | `GRGIT_USER` environment variable or `org.ajoberstar.grgit.auth.username` system property. |
| org.ajoberstar.github-pages | org.ajoberstar.git-publish | Comment |
| --------------------------- | --------------------------- | ---------------------------------------------------------------------------------------------------- |
| `repoUri` | `repoUri` | Used to allow any Object (which would be lazily unpacked to a String). Now requires a String. |
| `targetBranch` | `branch` | The old plugin defaulted to `gh-pages`, the new one has no default. This must be a String. |
| `workingPath` | `repoDir` | Used to allow any Object and called `file()` on it for you. Now expects a File. |
| `pages` | `contents` | Just a name change. |
| `deleteExistingFiles` | `preserve` | If previously `true` (the default), do nothing. If previously `false`, `preserve { include '**/*' }` |
| `commitMessage` | `commitMessage` | Just copy from the old value. |
| `credentials` | env variable or system prop | `GRGIT_USER` environment variable or `org.ajoberstar.grgit.auth.username` system property. |

Use the `gitPublishPush` task as replacement for the `publishGhPages` task.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.util.PatternFilterable;
import org.gradle.api.tasks.util.PatternSet;
import org.gradle.util.GradleVersion;

public class GitPublishExtension {
private final DirectoryProperty repoDir;
Expand All @@ -19,7 +20,11 @@ public class GitPublishExtension {
private final PatternFilterable preserve;

public GitPublishExtension(Project project) {
this.repoDir = project.getLayout().directoryProperty();
if (GradleVersion.current().compareTo(GradleVersion.version("5.0")) >= 0) {
this.repoDir = project.getObjects().directoryProperty();
} else {
this.repoDir = project.getLayout().directoryProperty();
}
this.repoUri = project.getObjects().property(String.class);
this.referenceRepoUri = project.getObjects().property(String.class);
this.branch = project.getObjects().property(String.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.provider.Provider;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Copy;

public class GitPublishPlugin implements Plugin<Project> {
Expand Down

0 comments on commit 739e3e6

Please sign in to comment.