All Downloads are FREE. Search and download functionalities are using the official Maven repository.

flair.gradle.tasks.process.ProcessAssets.groovy Maven / Gradle / Ivy

package flair.gradle.tasks.process

import flair.gradle.dependencies.Config
import flair.gradle.tasks.AbstractVariantTask
import flair.gradle.tasks.TaskGroup
import flair.gradle.variants.Variant
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.OutputDirectories
import org.gradle.api.tasks.OutputFiles
import org.gradle.api.tasks.TaskAction

/**
 * @author SamYStudiO ( [email protected] )
 */
class ProcessAssets extends AbstractVariantTask
{
	@InputFiles
	def Set inputFiles

	@OutputFiles
	def Set outputFiles

	@OutputDirectories
	def Set outputDirs

	@Override
	public void setVariant( Variant variant )
	{
		super.variant = variant

		inputFiles = findInputFiles( )
		outputFiles = new ArrayList( )
		outputDirs = new ArrayList( )

		inputFiles.each {

			File file = project.file( "${ outputVariantDir }/package/${ it.name }" )

			if( file.isDirectory( ) ) outputDirs.add( file ) else outputFiles.add( file )
		}
	}

	public ProcessAssets()
	{
		group = TaskGroup.DEFAULT.name
		description = ""
	}

	@TaskAction
	public void processAssets()
	{
		outputFiles.each { it.delete( ) }
		outputDirs.each { it.deleteDir( ) }

		inputFiles.each { file ->

			if( file.exists( ) )
			{
				if( file.isDirectory( ) )
				{
					project.copy {
						from file
						into "${ outputVariantDir }/package/${ file.name }"

						includeEmptyDirs = false
					}
				}
				else
				{
					project.copy {
						from file
						into "${ outputVariantDir }/package"
					}
				}
			}
		}
	}

	private Set findInputFiles()
	{
		List list = new ArrayList( )

		variant.directoriesCapitalized.each {

			String s = it == "main" ? Config.PACKAGE.name : it + Config.PACKAGE.name.capitalize( )

			list.addAll( project.configurations.getByName( s ).files )
		}

		return list
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy