org.gradle.api.file.CopySpec Maven / Gradle / Ivy
Show all versions of gradle-api Show documentation
/*
* Copyright 2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradle.api.file;
import groovy.lang.Closure;
import groovy.lang.DelegatesTo;
import org.gradle.api.Action;
import org.gradle.api.Transformer;
import org.gradle.api.specs.Spec;
import org.gradle.api.tasks.util.PatternFilterable;
import org.gradle.internal.HasInternalProtocol;
import org.gradle.internal.instrumentation.api.annotations.ToBeReplacedByLazyProperty;
import java.io.FilterReader;
import java.util.Map;
import java.util.regex.Pattern;
/**
* A set of specifications for copying files. This includes:
*
*
*
* - source directories (multiples allowed)
*
*
- destination directory
*
*
- ANT like include patterns
*
*
- ANT like exclude patterns
*
*
- File relocating rules
*
*
- renaming rules
*
*
- content filters
*
*
*
* CopySpecs may be nested by passing a closure to one of the from methods. The closure creates a child CopySpec and
* delegates methods in the closure to the child. Child CopySpecs inherit any values specified in the parent. This
* allows constructs like:
*
* def myCopySpec = project.copySpec {
* into('webroot')
* exclude('**/.data/**')
* from('src/main/webapp') {
* include '**/*.jsp'
* }
* from('src/main/js') {
* include '**/*.js'
* }
* }
*
*
* In this example, the into
and exclude
specifications at the root level are inherited by the
* two child CopySpecs.
*
* Copy specs can be reused in other copy specs via {@link #with(CopySpec...)} method. This enables reuse of the copy spec instances.
*
*
* def contentSpec = copySpec {
* from("content") {
* include "**/*.txt"
* }
* }
*
* task copy(type: Copy) {
* into "$buildDir/copy"
* with contentSpec
* }
*
*
* @see org.gradle.api.tasks.Copy Copy Task
* @see org.gradle.api.Project#copy(groovy.lang.Closure) Project.copy()
*/
@HasInternalProtocol
public interface CopySpec extends CopySourceSpec, CopyProcessingSpec, PatternFilterable {
/**
* Specifies whether case-sensitive pattern matching should be used.
*
* @return true for case-sensitive matching.
*/
@ToBeReplacedByLazyProperty
boolean isCaseSensitive();
/**
* Specifies whether case-sensitive pattern matching should be used for this CopySpec.
*
* @param caseSensitive true for case-sensitive matching.
*/
void setCaseSensitive(boolean caseSensitive);
/**
* Tells if empty target directories will be included in the copy.
*
* @return true
if empty target directories will be included in the copy, false
otherwise
*/
@ToBeReplacedByLazyProperty
boolean getIncludeEmptyDirs();
/**
* Controls if empty target directories should be included in the copy.
*
* @param includeEmptyDirs true
if empty target directories should be included in the copy, false
otherwise
*/
void setIncludeEmptyDirs(boolean includeEmptyDirs);
/**
* Returns the strategy to use when trying to copy more than one file to the same destination.
*
* The value can be set with a case insensitive string of the enum value (e.g. {@code 'exclude'} for {@link DuplicatesStrategy#EXCLUDE}).
*
* This strategy can be overridden for individual files by using {@link #eachFile(org.gradle.api.Action)} or {@link #filesMatching(String, org.gradle.api.Action)}.
*
* @return the strategy to use for files included by this copy spec.
* @see DuplicatesStrategy
*/
@ToBeReplacedByLazyProperty
DuplicatesStrategy getDuplicatesStrategy();
/**
* The strategy to use when trying to copy more than one file to the same destination. Set to {@link DuplicatesStrategy#INHERIT}, the default strategy, to use
* the strategy inherited from the parent copy spec, if any, or {@link DuplicatesStrategy#INCLUDE} if this copy spec has no parent.
*/
void setDuplicatesStrategy(DuplicatesStrategy strategy);
/**
* Configure the {@link org.gradle.api.file.FileCopyDetails} for each file whose path matches the specified Ant-style pattern.
* This is equivalent to using eachFile() and selectively applying a configuration based on the file's path.
*
* @param pattern Ant-style pattern used to match against files' relative paths
* @param action action called for the FileCopyDetails of each file matching pattern
* @return this
*/
CopySpec filesMatching(String pattern, Action super FileCopyDetails> action);
/**
* Configure the {@link org.gradle.api.file.FileCopyDetails} for each file whose path matches any of the specified Ant-style patterns.
* This is equivalent to using eachFile() and selectively applying a configuration based on the file's path.
*
* @param patterns Ant-style patterns used to match against files' relative paths
* @param action action called for the FileCopyDetails of each file matching pattern
* @return this
*/
CopySpec filesMatching(Iterable patterns, Action super FileCopyDetails> action);
/**
* Configure the {@link org.gradle.api.file.FileCopyDetails} for each file whose path does not match the specified
* Ant-style pattern. This is equivalent to using eachFile() and selectively applying a configuration based on the
* file's path.
*
* @param pattern Ant-style pattern used to match against files' relative paths
* @param action action called for the FileCopyDetails of each file that does not match pattern
* @return this
*/
CopySpec filesNotMatching(String pattern, Action super FileCopyDetails> action);
/**
* Configure the {@link org.gradle.api.file.FileCopyDetails} for each file whose path does not match any of the specified
* Ant-style patterns. This is equivalent to using eachFile() and selectively applying a configuration based on the
* file's path.
*
* @param patterns Ant-style patterns used to match against files' relative paths
* @param action action called for the FileCopyDetails of each file that does not match any pattern
* @return this
*/
CopySpec filesNotMatching(Iterable patterns, Action super FileCopyDetails> action);
/**
* Adds the given specs as a child of this spec.
*
*
* def contentSpec = copySpec {
* from("content") {
* include "**/*.txt"
* }
* }
*
* task copy(type: Copy) {
* into "$buildDir/copy"
* with contentSpec
* }
*
*
* @param sourceSpecs The specs to add
* @return this
*/
CopySpec with(CopySpec... sourceSpecs);
// CopySourceSpec overrides to broaden return type
/**
* {@inheritDoc}
*/
@Override
CopySpec from(Object... sourcePaths);
/**
* {@inheritDoc}
*/
@Override
CopySpec from(Object sourcePath, @DelegatesTo(CopySpec.class) Closure c);
/**
* {@inheritDoc}
*/
@Override
CopySpec from(Object sourcePath, Action super CopySpec> configureAction);
// PatternFilterable overrides to broaden return type
/**
* {@inheritDoc}
*
* @see org.gradle.api.tasks.util.PatternFilterable Pattern Format
*/
@Override
CopySpec setIncludes(Iterable includes);
/**
* {@inheritDoc}
*
* @see org.gradle.api.tasks.util.PatternFilterable Pattern Format
*/
@Override
CopySpec setExcludes(Iterable excludes);
/**
* {@inheritDoc}
*
* @see org.gradle.api.tasks.util.PatternFilterable Pattern Format
*/
@Override
CopySpec include(String... includes);
/**
* {@inheritDoc}
*
* @see org.gradle.api.tasks.util.PatternFilterable Pattern Format
*/
@Override
CopySpec include(Iterable includes);
/**
* {@inheritDoc}
*
* @see org.gradle.api.tasks.util.PatternFilterable Pattern Format
*/
@Override
CopySpec include(Spec includeSpec);
/**
* {@inheritDoc}
*
* @see org.gradle.api.tasks.util.PatternFilterable Pattern Format
*/
@Override
CopySpec include(Closure includeSpec);
/**
* {@inheritDoc}
*
* @see org.gradle.api.tasks.util.PatternFilterable Pattern Format
*/
@Override
CopySpec exclude(String... excludes);
/**
* {@inheritDoc}
*
* @see org.gradle.api.tasks.util.PatternFilterable Pattern Format
*/
@Override
CopySpec exclude(Iterable excludes);
/**
* {@inheritDoc}
*
* @see org.gradle.api.tasks.util.PatternFilterable Pattern Format
*/
@Override
CopySpec exclude(Spec excludeSpec);
/**
* {@inheritDoc}
*
* @see org.gradle.api.tasks.util.PatternFilterable Pattern Format
*/
@Override
CopySpec exclude(Closure excludeSpec);
// CopyProcessingSpec overrides to broaden return type
/**
* {@inheritDoc}
*/
@Override
CopySpec into(Object destPath);
/**
* Creates and configures a child {@code CopySpec} with the given destination path.
* The destination is evaluated as per {@link org.gradle.api.Project#file(Object)}.
*
* @param destPath Path to the destination directory for a Copy
* @param configureClosure The closure to use to configure the child {@code CopySpec}.
* @return this
*/
CopySpec into(Object destPath, @DelegatesTo(CopySpec.class) Closure configureClosure);
/**
* Creates and configures a child {@code CopySpec} with the given destination path.
* The destination is evaluated as per {@link org.gradle.api.Project#file(Object)}.
*
* @param destPath Path to the destination directory for a Copy
* @param copySpec The action to use to configure the child {@code CopySpec}.
* @return this
*/
CopySpec into(Object destPath, Action super CopySpec> copySpec);
/**
* {@inheritDoc}
*/
@Override
CopySpec rename(Closure closure);
/**
* {@inheritDoc}
*/
@Override
CopySpec rename(Transformer<@org.jetbrains.annotations.Nullable String, String> renamer);
/**
* {@inheritDoc}
*/
@Override
CopySpec rename(String sourceRegEx, String replaceWith);
/**
* {@inheritDoc}
*/
@Override
CopyProcessingSpec rename(Pattern sourceRegEx, String replaceWith);
/**
* {@inheritDoc}
*/
@Override
CopySpec filter(Map properties, Class extends FilterReader> filterType);
/**
* {@inheritDoc}
*/
@Override
CopySpec filter(Class extends FilterReader> filterType);
/**
* {@inheritDoc}
*/
@Override
CopySpec filter(Closure closure);
/**
* {@inheritDoc}
*/
@Override
CopySpec filter(Transformer<@org.jetbrains.annotations.Nullable String, String> transformer);
/**
* {@inheritDoc}
*/
@Override
CopySpec expand(Map properties);
/**
* {@inheritDoc}
*/
@Override
CopySpec expand(Map properties, Action super ExpandDetails> action);
/**
* {@inheritDoc}
*/
@Override
CopySpec eachFile(Action super FileCopyDetails> action);
/**
* {@inheritDoc}
*/
@Override
CopySpec eachFile(@DelegatesTo(FileCopyDetails.class) Closure closure);
/**
* Gets the charset used to read and write files when filtering.
* By default, the JVM default charset is used.
*
* @return the charset used to read and write files when filtering
* @since 2.14
*/
@ToBeReplacedByLazyProperty
String getFilteringCharset();
/**
* Specifies the charset used to read and write files when filtering.
*
* @param charset the name of the charset to use when filtering files
* @since 2.14
*/
void setFilteringCharset(String charset);
}