-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: replace deprecated archivePath with archiveFile in a backwards c…
…ompatible way (#451)
- Loading branch information
1 parent
5d39c93
commit ffd72d7
Showing
6 changed files
with
69 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...lugin/src/main/java/com/google/cloud/tools/gradle/appengine/util/GradleCompatibility.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.google.cloud.tools.gradle.appengine.util; | ||
|
||
import java.io.File; | ||
import org.gradle.api.tasks.bundling.AbstractArchiveTask; | ||
import org.gradle.util.GradleVersion; | ||
|
||
/** Utility class for Gradle compatibility related functions. As an end user, do not use. */ | ||
public class GradleCompatibility { | ||
|
||
private GradleCompatibility() { | ||
// Prevent instantiation and extension. | ||
} | ||
|
||
/** | ||
* Compatibility method for getting the archive location. | ||
* | ||
* @param task the task whose archive location we're interested in. | ||
* @return the archive location as a {@link File} for compatibility with older Gradle versions. | ||
*/ | ||
@SuppressWarnings("deprecation") | ||
public static File getArchiveFile(AbstractArchiveTask task) { | ||
// getArchiveFile and getArchivePath history: | ||
// - Gradle 5.1.0-M1 added `getArchiveFile` | ||
// - Gradle 5.1.0-M1 deprecated `getArchivePath` | ||
// - Gradle 6.0.0-RC1 added nagging to `getArchivePath` | ||
// - Gradle 6.0.0-RC1 removed nagging of `getArchivePath` | ||
// - Gradle 7.1.0-RC1 re-enabled nagging of `getArchivePath` for Gradle 8 | ||
// - Gradle 7.1.0-RC1 removed nagging of `getArchivePath` | ||
// - Gradle 8.0-M2 removed `getArchivePath` | ||
// - Gradle 8.0-M2 re-added `getArchivePath` with nagging for Gradle 9 | ||
// For full history with references see: | ||
// https://github.com/GoogleCloudPlatform/app-gradle-plugin/pull/451 | ||
|
||
if (GradleVersion.current().getBaseVersion().compareTo(GradleVersion.version("5.1")) >= 0) { | ||
return task.getArchiveFile().get().getAsFile(); | ||
} else { | ||
// Note: in case this fails to compile, because Gradle have succeeded with the removal, | ||
// this needs to be replaced with a reflective call to getArchivePath() | ||
// or the minimum Gradle version for GCP Gradle Plugin bumped up to 5.1+. | ||
return task.getArchivePath(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters