Skip to content

Commit

Permalink
Use ObjectFactory.directoryProperty() if possible
Browse files Browse the repository at this point in the history
ProjectLayout.directoryProperty() was deprecated in Gradle 5.0 and
replaced with ObjectFactory.directoryProperty(). In order to stay
backward compatible with Gradle 4.x, the latter is now called first and
the former is used as a fallback.

Resolves ajoberstar#64.
  • Loading branch information
marcphilipp committed Mar 21, 2019
1 parent 1c2ea1f commit 5706d17
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.ajoberstar.gradle.git.publish;


import org.ajoberstar.gradle.git.publish.tasks.DirectoryPropertyFactory;
import org.gradle.api.Action;
import org.gradle.api.Project;
import org.gradle.api.file.CopySpec;
Expand All @@ -18,7 +19,7 @@ public class GitPublishExtension {
private final PatternFilterable preserve;

public GitPublishExtension(Project project) {
this.repoDir = project.getLayout().directoryProperty();
this.repoDir = DirectoryPropertyFactory.create(project);
this.repoUri = project.getObjects().property(String.class);
this.branch = project.getObjects().property(String.class);
this.commitMessage = project.getObjects().property(String.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.ajoberstar.gradle.git.publish.tasks;

import org.gradle.api.Project;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.file.ProjectLayout;
import org.gradle.api.model.ObjectFactory;

/**
* For backward compatibility with Gradle 4.x
*/
public class DirectoryPropertyFactory {

private DirectoryPropertyFactory() {
}

public static DirectoryProperty create(Project project) {
return create(project.getLayout(), project.getObjects());
}

public static DirectoryProperty create(ProjectLayout layout, ObjectFactory objectFactory) {
try {
return objectFactory.directoryProperty();
} catch (NoSuchMethodError e) {
return layout.directoryProperty();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class GitPublishReset extends DefaultTask {
@Inject
public GitPublishReset(ProjectLayout layout, ObjectFactory objectFactory) {
this.grgit = objectFactory.property(Grgit.class);
this.repoDirectory = layout.directoryProperty();
this.repoDirectory = DirectoryPropertyFactory.create(layout, objectFactory);
this.repoUri = objectFactory.property(String.class);
this.branch = objectFactory.property(String.class);

Expand Down

0 comments on commit 5706d17

Please sign in to comment.