Package io.github.intisy.gradle.online
Class Main
java.lang.Object
io.github.intisy.gradle.online.Main
- All Implemented Interfaces:
org.gradle.api.Plugin<org.gradle.api.Project>
- Author:
- Finn Birich
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidapply(org.gradle.api.Project project) Applies the plugin to the given Gradle project.downloadFile(Logger logger, String fileURL) Downloads a file from the specified URL and saves it to a unique file location.voiddownloadFile(Logger logger, String fileURL, File file) Downloads a file from a specified URL and saves it to a local file.getUrlFile(String url) Generates a File object representing a unique file path for a given URL.voidprocessPresets(Logger logger, org.gradle.api.Project project, UsesExtension extension) Processes the presets specified in the given extension and updates or downloads the corresponding files.voidprocessUrls(Logger logger, org.gradle.api.Project project, UsesExtension extension) Processes the URLs specified in the given extension and updates or downloads the corresponding files.booleanshouldDownloadFile(File file, UsesExtension extension, Logger logger) Determines whether a file should be downloaded based on its existence, update delay, and auto-update settings.
-
Constructor Details
-
Main
public Main()
-
-
Method Details
-
apply
public void apply(org.gradle.api.Project project) Applies the plugin to the given Gradle project. This method sets up the necessary tasks and configurations for processing online Gradle files and presets.- Specified by:
applyin interfaceorg.gradle.api.Plugin<org.gradle.api.Project>- Parameters:
project- the Gradle project to which the plugin is applied. This project will be configured with tasks to list and process online Gradle files.
-
processUrls
Processes the URLs specified in the given extension and updates or downloads the corresponding files.- Parameters:
logger- the logger used to log messages during the processproject- the Gradle project to which the plugin is appliedextension- the extension containing the configuration, including the list of URLs to process
-
shouldDownloadFile
Determines whether a file should be downloaded based on its existence, update delay, and auto-update settings.- Parameters:
file- The file to be checked for download.extension- The extension containing the configuration, including auto-update settings and update delay.logger- The logger used to log messages during the process.- Returns:
trueif the file should be downloaded,falseotherwise. If the file does not exist, it will be downloaded. If auto-update is enabled and the update delay is greater than 0, the file will be downloaded if the difference between its creation time and the current time is greater than or equal to the update delay. If auto-update is enabled and the update delay is 0, the file will always be downloaded. If auto-update is disabled, the file will always be downloaded.
-
processPresets
Processes the presets specified in the given extension and updates or downloads the corresponding files.- Parameters:
logger- the logger used to log messages during the processproject- the Gradle project to which the plugin is appliedextension- the extension containing the configuration, including the list of presets to process
-
getUrlFile
Generates a File object representing a unique file path for a given URL. This method creates a file in the Gradle home directory with a unique name based on the provided URL.- Parameters:
url- The URL string for which to generate a unique file path.- Returns:
- A File object representing the unique file path for the given URL.
- Throws:
RuntimeException- If the Gradle home directory cannot be created.
-
downloadFile
Downloads a file from the specified URL and saves it to a unique file location.- Parameters:
logger- The Logger object used for logging messages during the download process.fileURL- The URL of the file to be downloaded.- Returns:
- A File object representing the downloaded file on the local file system.
- Throws:
RuntimeException- If there's an error during the download process.
-
downloadFile
Downloads a file from a specified URL and saves it to a local file. If the target file already exists, it attempts to delete it before downloading. The method uses a buffered input stream to read the file content and writes it to the local file system.- Parameters:
logger- The Logger object used for logging the download status.fileURL- The URL of the file to be downloaded as a String.file- The File object representing the local file where the downloaded content will be saved.- Throws:
RuntimeException- If the existing file cannot be deleted, if there's an IO error during download, or if the file cannot be downloaded and doesn't exist locally.
-