Class Main

java.lang.Object
io.github.intisy.gradle.online.Main
All Implemented Interfaces:
org.gradle.api.Plugin<org.gradle.api.Project>

public class Main extends Object implements org.gradle.api.Plugin<org.gradle.api.Project>
Author:
Finn Birich
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    apply(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.
    void
    downloadFile(Logger logger, String fileURL, File file)
    Downloads a file from a specified URL and saves it to a local file.
    Generates a File object representing a unique file path for a given URL.
    void
    processPresets(Logger logger, org.gradle.api.Project project, UsesExtension extension)
    Processes the presets specified in the given extension and updates or downloads the corresponding files.
    void
    processUrls(Logger logger, org.gradle.api.Project project, UsesExtension extension)
    Processes the URLs specified in the given extension and updates or downloads the corresponding files.
    boolean
    shouldDownloadFile(File file, UsesExtension extension, Logger logger)
    Determines whether a file should be downloaded based on its existence, update delay, and auto-update settings.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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:
      apply in interface org.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

      public void processUrls(Logger logger, org.gradle.api.Project project, UsesExtension extension)
      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 process
      project - the Gradle project to which the plugin is applied
      extension - the extension containing the configuration, including the list of URLs to process
    • shouldDownloadFile

      public boolean shouldDownloadFile(File file, UsesExtension extension, Logger logger)
      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:
      true if the file should be downloaded, false otherwise. 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

      public void processPresets(Logger logger, org.gradle.api.Project project, UsesExtension extension)
      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 process
      project - the Gradle project to which the plugin is applied
      extension - the extension containing the configuration, including the list of presets to process
    • getUrlFile

      public File getUrlFile(String url)
      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

      public File downloadFile(Logger logger, String fileURL)
      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

      public void downloadFile(Logger logger, String fileURL, File file)
      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.