Class ExtractArchiveFilesTask

java.lang.Object
org.gradle.api.internal.AbstractTask
org.gradle.api.DefaultTask
net.fabricmc.loom.task.ExtractArchiveFilesTask
All Implemented Interfaces:
Comparable<org.gradle.api.Task>, org.gradle.api.internal.DynamicObjectAware, org.gradle.api.internal.TaskInternal, org.gradle.api.Named, org.gradle.api.plugins.ExtensionAware, org.gradle.api.Task, org.gradle.util.Configurable<org.gradle.api.Task>

@CacheableTask public abstract class ExtractArchiveFilesTask extends org.gradle.api.DefaultTask
把若干归档(jar/zip)解压到单一输出目录的声明式任务.

与手工解压相比,本任务:

  • 只声明一个 OutputDirectory,不产出与之重叠的 @OutputFile,避免任务输出重叠;
  • 使用 Gradle 的 ArchiveOperations.zipTree(java.lang.Object) 与 FileSystemOperations.sync(org.gradle.api.Action<? super org.gradle.api.file.SyncSpec>), 因此可被构建缓存与增量执行复用;
  • 归档只参与输入哈希而不参与相对路径计算(PathSensitivity.NONE), 这样同一份依赖在 Gradle 缓存目录中的绝对路径变化不会引起无谓重跑。

当所有输入归档都不含任何可选后缀文件时,会在输出目录写入一个空标记文件, 保证任务在“确实没有可解压内容”时也有稳定的输出,而不会产出空目录。

  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.gradle.api.Named

    org.gradle.api.Named.Namer
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    无匹配条目时写入的标记文件名;该文件同时作为“同步已完成”的稳定输出.
    static final String
    上述任务的输出目录(相对于构建目录).
    static final String
    展开 Forge 安装器源码包的任务名.

    Fields inherited from interface org.gradle.api.Task

    TASK_ACTION, TASK_CONSTRUCTOR_ARGS, TASK_DEPENDS_ON, TASK_DESCRIPTION, TASK_GROUP, TASK_NAME, TASK_OVERWRITE, TASK_TYPE
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    protected abstract org.gradle.api.file.ArchiveOperations
     
    protected abstract org.gradle.api.file.ConfigurableFileCollection
    待解压的归档集合.
    protected abstract org.gradle.api.provider.ListProperty<String>
    无匹配条目时写入的输出目录内标记文件名.
    protected abstract org.gradle.api.file.FileSystemOperations
     
    protected abstract org.gradle.api.provider.ListProperty<String>
    只保留这些后缀的条目.
    abstract org.gradle.api.file.DirectoryProperty
     
    void
    显式声明保留全部条目(即不做后缀过滤),与 includeSuffixes(String, String...) 互斥.
    void
    includeSuffixes(String firstSuffix, String... otherSuffixes)
    只解压这些后缀的条目.
    protected void
    run()
     

    Methods inherited from class org.gradle.api.DefaultTask

    compareTo, configure, dependsOn, doFirst, doFirst, doFirst, doLast, doLast, doLast, finalizedBy, getActions, getAnt, getDependsOn, getDescription, getDestroyables, getDidWork, getEnabled, getExtensions, getFinalizedBy, getGroup, getInputs, getLocalState, getLogger, getLogging, getMustRunAfter, getName, getOutputs, getPath, getProject, getShouldRunAfter, getState, getTaskDependencies, getTemporaryDir, getTimeout, hasProperty, mustRunAfter, onlyIf, onlyIf, onlyIf, property, setActions, setDependsOn, setDescription, setDidWork, setEnabled, setFinalizedBy, setGroup, setMustRunAfter, setOnlyIf, setOnlyIf, setOnlyIf, setProperty, setShouldRunAfter, shouldRunAfter, usesService

    Methods inherited from class org.gradle.api.internal.AbstractTask

    acceptServiceReferences, appendParallelSafeAction, doNotTrackState, doNotTrackStateIf, getAsDynamicObject, getIdentityPath, getImpliesSubProjects, getLifecycleDependencies, getOnlyIf, getReasonNotToTrackState, getReasonsNotToTrackState, getReasonTaskIsIncompatibleWithConfigurationCache, getRequiredServices, getServices, getSharedResources, getStandardOutputCapture, getTaskActions, getTaskIdentity, getTemporaryDirFactory, hasTaskActions, injectIntoNewInstance, isCompatibleWithConfigurationCache, isEnabled, isHasCustomActions, notCompatibleWithConfigurationCache, prependParallelSafeAction, restoreOnlyIf, restoreTaskActions, setImpliesSubProjects

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.gradle.api.Task

    doNotTrackState, notCompatibleWithConfigurationCache
  • Field Details

    • FORGE_SOURCES_TASK_NAME

      public static final String FORGE_SOURCES_TASK_NAME
      展开 Forge 安装器源码包的任务名.
      See Also:
    • FORGE_SOURCES_OUTPUT_DIRECTORY

      public static final String FORGE_SOURCES_OUTPUT_DIRECTORY
      上述任务的输出目录(相对于构建目录).
      See Also:
    • EMPTY_MARKER_FILE

      public static final String EMPTY_MARKER_FILE
      无匹配条目时写入的标记文件名;该文件同时作为“同步已完成”的稳定输出.
      See Also:
  • Constructor Details

    • ExtractArchiveFilesTask

      public ExtractArchiveFilesTask()
  • Method Details

    • getArchives

      @InputFiles @PathSensitive(NONE) protected abstract org.gradle.api.file.ConfigurableFileCollection getArchives()
      待解压的归档集合.
    • getIncludedSuffixes

      @Input protected abstract org.gradle.api.provider.ListProperty<String> getIncludedSuffixes()
      只保留这些后缀的条目.

      该属性必须显式赋值:空列表的语义是「保留全部条目」,与 includeSuffixes(String, String...) 的名称直觉相反,因此不提供默认值,未配置时任务会直接报错(见 run()); 确实需要全部条目时请显式调用 includeAllSuffixes()。

    • getEmptyMarkers

      @Input protected abstract org.gradle.api.provider.ListProperty<String> getEmptyMarkers()
      无匹配条目时写入的输出目录内标记文件名.
    • includeSuffixes

      public void includeSuffixes(String firstSuffix, String... otherSuffixes)
      只解压这些后缀的条目.

      至少需要一个后缀:空列表表示「保留全部条目」,为避免误用,这里把它从参数层面排除, 需要保留全部条目请调用 includeAllSuffixes()。

      Parameters:
      firstSuffix - 第一个后缀
      otherSuffixes - 其余后缀
    • includeAllSuffixes

      public void includeAllSuffixes()
      显式声明保留全部条目(即不做后缀过滤),与 includeSuffixes(String, String...) 互斥.
    • emptyMarker

      public void emptyMarker(String marker)
    • getOutputDirectory

      @OutputDirectory public abstract org.gradle.api.file.DirectoryProperty getOutputDirectory()
    • getArchiveOperations

      @Inject protected abstract org.gradle.api.file.ArchiveOperations getArchiveOperations()
    • getFileSystemOperations

      @Inject protected abstract org.gradle.api.file.FileSystemOperations getFileSystemOperations()
    • run

      protected void run() throws IOException
      Throws:
      IOException