├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── src ├── main │ ├── resources │ │ └── META-INF │ │ │ └── gradle-plugins │ │ │ └── imagemagick.properties │ └── groovy │ │ └── com │ │ └── eowise │ │ └── imagemagick │ │ ├── params │ │ ├── Param.groovy │ │ ├── SimpleFileParam.groovy │ │ ├── FormattedParam.groovy │ │ ├── SimpleParam.groovy │ │ ├── FormattingParam.groovy │ │ ├── ConditionParam.groovy │ │ └── ComputedFileParam.groovy │ │ ├── ImageMagickPlugin.groovy │ │ ├── tasks │ │ ├── ImageInfo.groovy │ │ ├── SvgToPng.groovy │ │ └── Magick.groovy │ │ └── specs │ │ ├── FormattingSpec.groovy │ │ └── DefaultMagickSpec.groovy └── test │ ├── resources │ ├── images │ │ └── gradle.png │ └── build.gradle │ └── groovy │ └── com │ └── eowise │ └── imagemagick │ ├── specs │ └── DefaultMagickSpecTest.groovy │ └── tasks │ ├── MagickTest.groovy │ └── ConvertTest.groovy ├── .gitignore ├── README.md ├── LICENSE ├── gradlew.bat └── gradlew /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eowise/gradle-imagemagick/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /src/main/resources/META-INF/gradle-plugins/imagemagick.properties: -------------------------------------------------------------------------------- 1 | implementation-class=com.eowise.imagemagick.ImageMagickPlugin -------------------------------------------------------------------------------- /src/test/resources/images/gradle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eowise/gradle-imagemagick/HEAD/src/test/resources/images/gradle.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | .idea/ 3 | .gradle/ 4 | gradle-imagemagick.iml 5 | gradle-imagemagick.ipr 6 | gradle-imagemagick.iws 7 | gradle.properties 8 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /src/main/groovy/com/eowise/imagemagick/params/Param.groovy: -------------------------------------------------------------------------------- 1 | package com.eowise.imagemagick.params 2 | 3 | import org.gradle.api.file.FileVisitDetails 4 | 5 | /** 6 | * Created by aurel on 14/12/13. 7 | */ 8 | interface Param extends Serializable { 9 | LinkedList toParams(FileVisitDetails details) 10 | } 11 | -------------------------------------------------------------------------------- /src/main/groovy/com/eowise/imagemagick/ImageMagickPlugin.groovy: -------------------------------------------------------------------------------- 1 | package com.eowise.imagemagick 2 | 3 | import org.gradle.api.Plugin 4 | import org.gradle.api.Project 5 | 6 | /** 7 | * Created by aurel on 21/01/14. 8 | */ 9 | class ImageMagickPlugin implements Plugin { 10 | 11 | @Override 12 | void apply(Project project) { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | gradle-imagemagick 2 | ================== 3 | 4 | Gradle tasks to easy integrate ImageMagick 5 | 6 | ## Install 7 | 8 | ```groovy 9 | buildscript { 10 | repositories { 11 | jCenter() 12 | } 13 | 14 | dependencies { 15 | classpath 'com.eowise:gradle-imagemagick:0.5.2' 16 | } 17 | } 18 | ``` 19 | 20 | ## Usage 21 | 22 | Have a look at the [wiki](https://github.com/eowise/gradle-imagemagick/wiki) 23 | -------------------------------------------------------------------------------- /src/main/groovy/com/eowise/imagemagick/params/SimpleFileParam.groovy: -------------------------------------------------------------------------------- 1 | package com.eowise.imagemagick.params 2 | 3 | import org.gradle.api.file.FileVisitDetails 4 | 5 | /** 6 | * Created by aurel on 11/06/14. 7 | */ 8 | class SimpleFileParam implements Param { 9 | 10 | File file 11 | 12 | public SimpleFileParam(File file) { 13 | this.file = file 14 | } 15 | 16 | @Override 17 | LinkedList toParams(FileVisitDetails details) { 18 | return [file] 19 | } 20 | 21 | @Override 22 | String toString() { 23 | return file.toString() 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/groovy/com/eowise/imagemagick/params/FormattedParam.groovy: -------------------------------------------------------------------------------- 1 | package com.eowise.imagemagick.params 2 | 3 | import org.gradle.api.Task 4 | import org.gradle.api.file.FileVisitDetails 5 | 6 | /** 7 | * Created by aurel on 11/03/15. 8 | */ 9 | class FormattedParam implements Param { 10 | 11 | String id 12 | Task task 13 | 14 | FormattedParam(String id, Task task) { 15 | this.id = id 16 | this.task = task 17 | } 18 | 19 | @Override 20 | LinkedList toParams(FileVisitDetails details) { 21 | return [ "@${task.temporaryDir}/${details.getRelativePath()}.${id}.mvg" ] 22 | } 23 | 24 | @Override 25 | String toString() { 26 | return id 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/groovy/com/eowise/imagemagick/params/SimpleParam.groovy: -------------------------------------------------------------------------------- 1 | package com.eowise.imagemagick.params 2 | 3 | import org.gradle.api.file.FileVisitDetails 4 | 5 | /** 6 | * Created by aurel on 14/12/13. 7 | */ 8 | class SimpleParam implements Param { 9 | 10 | String value 11 | String sign 12 | 13 | SimpleParam(String value) { 14 | this.value = value 15 | this.sign = '' 16 | } 17 | 18 | @Override 19 | LinkedList toParams(FileVisitDetails details) { 20 | return [sign + value] 21 | } 22 | 23 | String toString() { 24 | return sign + value 25 | } 26 | 27 | def positive() { 28 | sign = '+'; 29 | } 30 | 31 | def negative() { 32 | sign = '-'; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/resources/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenLocal() 4 | } 5 | dependencies { 6 | classpath 'com.eowise:gradle-imagemagick:0.5.2' 7 | } 8 | } 9 | 10 | task basicTest(type: com.eowise.imagemagick.tasks.Magick) { 11 | convert 'images', {include '*.png'} 12 | into 'out' 13 | outputFileFromInputFile { File inputFile 14 | -> file("out/${inputFile.name}") 15 | } 16 | 17 | actions { 18 | inputFile() 19 | -background('black') 20 | outputFile() 21 | } 22 | } 23 | 24 | task testWithClosureOutputDir(type: com.eowise.imagemagick.tasks.Magick) { 25 | convert 'images', {include '*.png'} 26 | into { relativePath -> "out/${relativePath}"} 27 | actions { 28 | inputFile() 29 | -background('black') 30 | outputFile() 31 | } 32 | } 33 | 34 | task clean { 35 | delete 'out' 36 | } 37 | -------------------------------------------------------------------------------- /src/main/groovy/com/eowise/imagemagick/params/FormattingParam.groovy: -------------------------------------------------------------------------------- 1 | package com.eowise.imagemagick.params 2 | 3 | import org.gradle.api.file.FileVisitDetails 4 | 5 | /** 6 | * Created by aurel on 11/03/15. 7 | */ 8 | class FormattingParam implements Param { 9 | 10 | String format 11 | ComputedFileParam inputFile 12 | 13 | FormattingParam(String format, ComputedFileParam inputFile) { 14 | this.format = format 15 | this.inputFile = inputFile 16 | } 17 | 18 | @Override 19 | LinkedList toParams(FileVisitDetails details) { 20 | def toReturn = [] 21 | 22 | toReturn.addAll(inputFile.toParams(details)) 23 | toReturn.add('-format') 24 | toReturn.add(format) 25 | toReturn.add('info:') 26 | 27 | 28 | return toReturn 29 | } 30 | 31 | @Override 32 | String toString() { 33 | return inputFile.toString() + ':' + format 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/groovy/com/eowise/imagemagick/tasks/ImageInfo.groovy: -------------------------------------------------------------------------------- 1 | package com.eowise.imagemagick.tasks 2 | 3 | import org.gradle.api.DefaultTask 4 | 5 | /** 6 | * Created by aurel on 14/12/13. 7 | */ 8 | class ImageInfo extends DefaultTask { 9 | def size(File file) { 10 | new ByteArrayOutputStream().withStream { os -> 11 | project.exec { 12 | commandLine 'convert', file, '-format', '"%w"', 'info:' 13 | standardOutput = os 14 | } 15 | ext.width = Integer.parseInt((os.toString() =~ /"([0-9]+)"/)[0][1]) 16 | 17 | } 18 | 19 | new ByteArrayOutputStream().withStream { os -> 20 | project.exec { 21 | commandLine 'convert', file, '-format', '"%h"', 'info:' 22 | standardOutput = os 23 | } 24 | ext.height = Integer.parseInt((os.toString() =~ /"([0-9]+)"/)[0][1]) 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/groovy/com/eowise/imagemagick/params/ConditionParam.groovy: -------------------------------------------------------------------------------- 1 | package com.eowise.imagemagick.params 2 | 3 | import org.gradle.api.file.FileCollection 4 | import org.gradle.api.file.FileTree 5 | import org.gradle.api.file.FileVisitDetails 6 | import org.gradle.api.tasks.util.PatternSet 7 | 8 | /** 9 | * Created by aurel on 14/12/13. 10 | */ 11 | class ConditionParam implements Param { 12 | 13 | FileTree matchingFiles 14 | LinkedList params 15 | 16 | ConditionParam(FileCollection original, PatternSet pattern, LinkedList params) { 17 | this.matchingFiles = original.asFileTree.matching(pattern) 18 | this.params = params 19 | } 20 | 21 | @Override 22 | LinkedList toParams(FileVisitDetails details) { 23 | 24 | LinkedList toReturn = [] 25 | 26 | if (matchingFiles.contains(details.getFile())) 27 | params.each { p -> toReturn.addAll(p.toParams(details)) } 28 | 29 | 30 | return toReturn 31 | } 32 | 33 | String toString() { 34 | return params.join(' ') 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 eowise 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /src/main/groovy/com/eowise/imagemagick/specs/FormattingSpec.groovy: -------------------------------------------------------------------------------- 1 | package com.eowise.imagemagick.specs 2 | 3 | import com.eowise.imagemagick.params.ComputedFileParam 4 | import com.eowise.imagemagick.params.FormattingParam 5 | import org.gradle.api.Task 6 | 7 | /** 8 | * Created by aurel on 11/03/15. 9 | */ 10 | class FormattingSpec { 11 | 12 | Task task 13 | Map formats 14 | String inputBasePath 15 | ComputedFileParam inputFile 16 | 17 | FormattingSpec(Task task) { 18 | this.task = task 19 | this.formats = [:] 20 | } 21 | 22 | def include(String id, String format) { 23 | if (inputFile == null) { 24 | inputFile = new ComputedFileParam( 25 | task.getProject(), 26 | { relativePath -> "${inputBasePath}/${relativePath}" }, 27 | { fileName, extension -> "${fileName}.${extension}" } 28 | ) 29 | } 30 | formats[id] = new FormattingParam(format, inputFile) 31 | } 32 | 33 | def setInputBasePath(String inputBasePath) { 34 | this.inputBasePath = inputBasePath 35 | } 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/groovy/com/eowise/imagemagick/params/ComputedFileParam.groovy: -------------------------------------------------------------------------------- 1 | package com.eowise.imagemagick.params 2 | 3 | import org.gradle.api.Project 4 | import org.gradle.api.file.FileVisitDetails 5 | 6 | /** 7 | * Created by aurel on 14/12/13. 8 | */ 9 | class ComputedFileParam implements Param { 10 | 11 | Project project 12 | Closure output 13 | Closure rename 14 | 15 | 16 | ComputedFileParam(Project project, Closure output) { 17 | this(project, output, { name, extension -> "${name}.${extension}"}); 18 | } 19 | 20 | ComputedFileParam(Project project, Closure output, Closure rename) { 21 | this.project = project; 22 | this.output = output; 23 | this.rename = rename; 24 | } 25 | 26 | @Override 27 | String toString() { 28 | return output("path") + '/' + (rename != null ? rename('file', 'ext') : '') 29 | } 30 | 31 | @Override 32 | LinkedList toParams(FileVisitDetails details) { 33 | 34 | String name = details.getName()[0.. 34 | outputFile = outputDir.toString() + '/' + change.file.name.replace(".svg", ".png") 35 | project.exec { 36 | commandLine 'inkscape', '--export-png=' + outputFile, '--export-background-opacity=0', '--without-gui', change.file 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/groovy/com/eowise/imagemagick/specs/DefaultMagickSpecTest.groovy: -------------------------------------------------------------------------------- 1 | package com.eowise.imagemagick.specs 2 | 3 | import org.gradle.api.Task 4 | import org.gradle.api.tasks.util.PatternSet 5 | import spock.lang.Specification 6 | 7 | /** 8 | * Created by aurel on 11/04/14. 9 | */ 10 | class DefaultMagickSpecTest extends Specification { 11 | 12 | 13 | def "methodMissing is called"() { 14 | DefaultMagickSpec spec = new DefaultMagickSpec(Mock(Task)) 15 | 16 | spec.setOutput { relativePath -> "path/${relativePath}" } 17 | 18 | Closure closure = { 19 | -background('black') 20 | } 21 | 22 | closure.delegate = spec 23 | 24 | when: 25 | closure() 26 | then: 27 | spec.toString() == '-background black' 28 | } 29 | 30 | def "propertyMissing is called"() { 31 | DefaultMagickSpec spec = new DefaultMagickSpec(Mock(Task)) 32 | 33 | spec.setOutput { relativePath -> "path/${relativePath}" } 34 | 35 | Closure closure = { 36 | -clone 37 | } 38 | 39 | closure.delegate = spec 40 | 41 | when: 42 | closure() 43 | then: 44 | spec.toString() == '-clone' 45 | } 46 | 47 | 48 | def "- is added"() { 49 | DefaultMagickSpec spec = new DefaultMagickSpec(Mock(Task)) 50 | 51 | spec.setOutput { relativePath -> "path/${relativePath}" } 52 | 53 | Closure closure = { 54 | -width('1') 55 | } 56 | 57 | closure.delegate = spec 58 | closure.resolveStrategy = Closure.DELEGATE_ONLY 59 | 60 | when: 61 | closure() 62 | then: 63 | spec.toString() == '-width 1' 64 | } 65 | 66 | def "+ is added"() { 67 | DefaultMagickSpec spec = new DefaultMagickSpec(Mock(Task)) 68 | 69 | spec.setOutput { relativePath -> "path/${relativePath}" } 70 | 71 | Closure closure = { 72 | +repage 73 | } 74 | 75 | closure.delegate = spec 76 | closure.resolveStrategy = Closure.DELEGATE_ONLY 77 | 78 | when: 79 | closure() 80 | then: 81 | spec.toString() == '+repage' 82 | } 83 | 84 | def "stack add parenthesis"() { 85 | DefaultMagickSpec spec = new DefaultMagickSpec(Mock(Task)) 86 | 87 | spec.setOutput { relativePath -> "path/${relativePath}" } 88 | 89 | Closure closure = { 90 | -clone 91 | stack { 92 | -width('1') 93 | } 94 | +repage 95 | } 96 | 97 | closure.delegate = spec 98 | closure.resolveStrategy = Closure.DELEGATE_ONLY 99 | 100 | when: 101 | closure() 102 | then: 103 | spec.toString() == '-clone ( -width 1 ) +repage' 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /src/main/groovy/com/eowise/imagemagick/specs/DefaultMagickSpec.groovy: -------------------------------------------------------------------------------- 1 | package com.eowise.imagemagick.specs 2 | 3 | import com.eowise.imagemagick.params.* 4 | import org.gradle.api.Task 5 | import org.gradle.api.tasks.util.PatternSet 6 | 7 | /** 8 | * Created by aurel on 14/12/13. 9 | */ 10 | class DefaultMagickSpec implements Serializable { 11 | 12 | LinkedList params 13 | Task task 14 | Closure output 15 | String inputBasePath 16 | 17 | public DefaultMagickSpec(Task task) { 18 | this.task = task 19 | this.params = [] 20 | } 21 | 22 | def setOutput(Closure output) { 23 | this.output = output 24 | } 25 | 26 | def setInputBasePath(String inputBasePath) { 27 | this.inputBasePath = inputBasePath 28 | } 29 | 30 | 31 | def methodMissing(String name, args) { 32 | SimpleParam nameParam = new SimpleParam(name) 33 | params.add(nameParam) 34 | 35 | args.each { 36 | arg -> 37 | String argValue = arg.toString(); 38 | if ( argValue.startsWith('@')) { 39 | params.add(new FormattedParam(argValue[1.. "${inputBasePath}/${relativePath}" }, 66 | { fileName, extension -> "${fileName}.${extension}" } 67 | ) 68 | ) 69 | } 70 | 71 | def outputFile() { 72 | params.add( 73 | new ComputedFileParam( 74 | task.getProject(), 75 | output, 76 | { fileName, extension -> "${fileName}.${extension}" } 77 | ) 78 | ) 79 | } 80 | 81 | def outputFile(String file) { 82 | params.add( 83 | new ComputedFileParam( 84 | task.getProject(), 85 | output, 86 | { fileName, extension -> "${file}" } 87 | ) 88 | ) 89 | } 90 | 91 | def outputFile(Closure rename) { 92 | params.add( 93 | new ComputedFileParam( 94 | task.getProject(), 95 | output, 96 | rename 97 | ) 98 | ) 99 | } 100 | 101 | def file(File f) { 102 | params.add(new SimpleFileParam(f)) 103 | } 104 | 105 | def file(Closure path, Closure rename) { 106 | params.add(new ComputedFileParam(task.getProject(), path, rename)) 107 | } 108 | 109 | def xc(String color) { 110 | params.add(new SimpleParam("xc:${color}")) 111 | } 112 | 113 | // Memory program register: See http://www.imagemagick.org/Usage/files/#mpr 114 | def mpr(String label) { 115 | params.add(new SimpleParam("mpr:${label}")) 116 | } 117 | 118 | def stack(Closure closure) { 119 | params.add(new SimpleParam('(')) 120 | closure.delegate = this 121 | closure.resolveStrategy = Closure.DELEGATE_FIRST 122 | closure() 123 | params.add(new SimpleParam(')')) 124 | } 125 | 126 | def condition(PatternSet pattern, Closure closure) { 127 | DefaultMagickSpec spec = new DefaultMagickSpec(task) 128 | closure.delegate = spec 129 | closure.resolveStrategy = Closure.DELEGATE_FIRST 130 | closure() 131 | params.add(new ConditionParam(task.getInputs().getFiles(), pattern, spec.params)) 132 | println(toString()) 133 | } 134 | 135 | 136 | String toString() { 137 | return params.join(' ') 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/main/groovy/com/eowise/imagemagick/tasks/Magick.groovy: -------------------------------------------------------------------------------- 1 | package com.eowise.imagemagick.tasks 2 | 3 | import com.eowise.imagemagick.specs.FormattingSpec 4 | import com.eowise.imagemagick.specs.DefaultMagickSpec 5 | import org.gradle.api.DefaultTask 6 | import org.gradle.api.file.FileCollection 7 | import org.gradle.api.file.FileTree 8 | import org.gradle.api.file.FileVisitDetails 9 | import org.gradle.api.tasks.Input 10 | import org.gradle.api.tasks.InputFiles 11 | import org.gradle.api.tasks.Internal 12 | import org.gradle.api.tasks.Optional 13 | import org.gradle.api.tasks.OutputDirectory 14 | import org.gradle.api.tasks.TaskAction 15 | import org.gradle.api.tasks.incremental.IncrementalTaskInputs 16 | import org.gradle.api.tasks.util.PatternSet 17 | 18 | /** 19 | * Created by aurel on 14/12/13. 20 | */ 21 | class Magick extends DefaultTask { 22 | 23 | 24 | @InputFiles 25 | FileTree inputFiles 26 | @OutputDirectory 27 | File outputDir 28 | @Input 29 | String inputSpec 30 | @Input 31 | String command 32 | @Input 33 | Closure output 34 | 35 | @Internal 36 | DefaultMagickSpec spec 37 | @Internal 38 | FormattingSpec formattingSpec 39 | // @Input 40 | // @Optional 41 | Closure outputFileFromInputFileClosure 42 | 43 | Magick() { 44 | this.spec = new DefaultMagickSpec(this) 45 | this.formattingSpec = new FormattingSpec(this) 46 | } 47 | 48 | def verb(String baseDir, PatternSet pattern, String command) { 49 | this.inputFiles = project.fileTree(baseDir).matching(pattern) 50 | this.output = { relativePath -> "${baseDir}/${relativePath}" } 51 | this.outputDir = project.file(output('')) 52 | this.spec.setInputBasePath(baseDir) 53 | this.formattingSpec.setInputBasePath(baseDir) 54 | this.command = command 55 | } 56 | def convert(String baseDir, PatternSet pattern) { 57 | verb(baseDir, pattern, 'convert') 58 | } 59 | 60 | def convert(String baseDir, Closure closure) { 61 | convert(baseDir, project.configure(new PatternSet(), closure) as PatternSet) 62 | } 63 | 64 | def magick(String baseDir, PatternSet pattern) { 65 | verb(baseDir, pattern, 'magick') 66 | } 67 | 68 | def magick(String baseDir, Closure closure) { 69 | magick(baseDir, project.configure(new PatternSet(), closure) as PatternSet) 70 | } 71 | 72 | def into(Closure outputClosure) { 73 | this.output = outputClosure 74 | this.outputDir = project.file(output('')) 75 | this.spec.setOutput(outputClosure) 76 | } 77 | 78 | def into(String path) { 79 | into({ relativePath -> "${path}/${relativePath}" }) 80 | } 81 | 82 | def formatting(Closure closure) { 83 | project.configure(formattingSpec, closure) 84 | } 85 | 86 | def actions(Closure closure) { 87 | project.configure(spec, closure) 88 | inputSpec = spec.toString() 89 | } 90 | 91 | def outputFileFromInputFile(Closure outputFileFromInputFile) { 92 | this.outputFileFromInputFileClosure = outputFileFromInputFile 93 | } 94 | 95 | LinkedList buildArgs(FileVisitDetails file) { 96 | 97 | LinkedList execArgs = [] 98 | 99 | spec.params.each { 100 | p -> 101 | execArgs.addAll(p.toParams(file)) 102 | } 103 | 104 | return execArgs 105 | } 106 | 107 | @TaskAction 108 | void execute(IncrementalTaskInputs incrementalInputs) { 109 | LinkedList execArgs 110 | FileCollection changedFiles = project.files() 111 | 112 | incrementalInputs.outOfDate { 113 | change -> 114 | changedFiles.from(change.file) 115 | } 116 | 117 | 118 | inputFiles.visit { 119 | FileVisitDetails f -> 120 | 121 | if (changedFiles.contains(f.getFile())) { 122 | 123 | if (!f.getFile().isDirectory()) { 124 | 125 | formattingSpec.formats.each { 126 | id, param -> 127 | project.exec { 128 | commandLine command 129 | args param.toParams(f) 130 | standardOutput new FileOutputStream("${temporaryDir}/${f.getRelativePath()}.${id}.mvg") 131 | } 132 | } 133 | 134 | execArgs = buildArgs(f) 135 | 136 | project.exec { 137 | commandLine command 138 | args execArgs 139 | } 140 | } 141 | 142 | } 143 | } 144 | 145 | if (incrementalInputs.isIncremental() && outputFileFormInputFileClosure != null) { 146 | incrementalInputs.removed { 147 | remove -> 148 | println "Applying outPutFileFromInputClosure to ${remove.file}" 149 | File outputFileToRemove = outputFileFromInputFileClosure(remove.file) 150 | outputFileToRemove.delete() 151 | } 152 | } 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /src/test/groovy/com/eowise/imagemagick/tasks/MagickTest.groovy: -------------------------------------------------------------------------------- 1 | package com.eowise.imagemagick.tasks 2 | 3 | import org.apache.commons.io.FileUtils 4 | import org.gradle.api.Project 5 | import org.gradle.api.file.FileTree 6 | import org.gradle.api.file.FileVisitDetails 7 | import org.gradle.testfixtures.ProjectBuilder 8 | import org.gradle.testkit.runner.GradleRunner 9 | import spock.lang.Specification 10 | 11 | class MagickTest extends Specification { 12 | 13 | def "Test string output file"() { 14 | Project project = ProjectBuilder.builder().withProjectDir(new File('src/test/resources')).build() 15 | Magick task = (Magick)project.task('magick', type: Magick) 16 | FileTree inputFiles = project.fileTree('images', {include: '*.png'; exclude: '*2.png'}) 17 | 18 | when: 19 | task.magick('images', {include: '*.png'; exclude: '*2.png'}) 20 | task.into('out') 21 | task.actions { 22 | inputFile() 23 | -background('black') 24 | outputFile() 25 | } 26 | then: 27 | inputFiles.visit { FileVisitDetails f -> assert task.buildArgs(f).join(' ') == project.file('images/gradle.png').toString() + " -background black " + project.file('out/gradle.png').toString() } 28 | task.outputDir == project.file('out') 29 | } 30 | 31 | def "Test string output file with rename"() { 32 | Project project = ProjectBuilder.builder().withProjectDir(new File('src/test/resources')).build() 33 | Magick task = (Magick)project.task('magick', type: Magick) 34 | FileTree inputFiles = project.fileTree('images', {include: '*.png'; exclude: '*2.png'}) 35 | 36 | when: 37 | task.magick('images', {include: '*.png'; exclude: '*2.png'}) 38 | task.into('out') 39 | task.actions { 40 | inputFile() 41 | -background('black') 42 | outputFile { fileName, extension -> "computed-${fileName}.${extension}" } 43 | } 44 | then: 45 | inputFiles.visit { FileVisitDetails f -> assert task.buildArgs(f).join(' ') == project.file('images/gradle.png').toString() + " -background black " + project.file('out/computed-gradle.png').toString() } 46 | task.outputDir == project.file('out') 47 | } 48 | 49 | def "Test closure output dir"() { 50 | when: 51 | GradleRunner.create() 52 | .withProjectDir(new File("src/test/resources")) 53 | .withArguments("testWithClosureOutputDir", "--rerun-tasks") 54 | .build() 55 | 56 | then: 57 | new File("src/test/resources/out/gradle.png").exists() 58 | } 59 | 60 | def "Test closure output file with rename"() { 61 | Project project = ProjectBuilder.builder().withProjectDir(new File('src/test/resources')).build() 62 | Magick task = (Magick)project.task('magick', type: Magick) 63 | FileTree inputFiles = project.fileTree('images', {include: '*.png'; exclude: '*2.png'}) 64 | 65 | when: 66 | task.magick('images', {include: '*.png'; exclude: '*2.png'}) 67 | task.into { relativePath -> "out/${relativePath}"} 68 | task.actions { 69 | inputFile() 70 | -background('black') 71 | outputFile { fileName, extension -> "computed-${fileName}.${extension}" } 72 | } 73 | 74 | then: 75 | inputFiles.visit { FileVisitDetails f -> assert task.buildArgs(f).join(' ') == project.file('images/gradle.png').toString() + " -background black " + project.file('out/computed-gradle.png').toString() } 76 | task.outputDir == project.file('out') 77 | } 78 | 79 | def "Test without output dir"() { 80 | Project project = ProjectBuilder.builder().withProjectDir(new File('src/test/resources')).build() 81 | Magick task = (Magick)project.task('magick', type: Magick) 82 | FileTree inputFiles = project.fileTree('images', {include: '*.png'; exclude: '*2.png'}) 83 | 84 | when: 85 | task.magick('images', {include: '*.png'; exclude: '*2.png'}) 86 | task.actions { 87 | inputFile() 88 | -background('black') 89 | inputFile() 90 | } 91 | 92 | then: 93 | inputFiles.visit { FileVisitDetails f -> assert task.buildArgs(f).join(' ') == project.file('images/gradle.png').toString() + " -background black " + project.file('images/gradle.png').toString() } 94 | task.outputDir == project.file('images') 95 | } 96 | 97 | def "Test removing input file remove also output file"() { 98 | FileUtils.copyFile(new File('src/test/resources/images/gradle.png'), new File('src/test/resources/images/gradle2.png')) 99 | 100 | when: 101 | GradleRunner.create() 102 | .withProjectDir(new File("src/test/resources")) 103 | .withArguments("basicTest", "--rerun-tasks") 104 | .build() 105 | 106 | FileUtils.deleteQuietly(new File('src/test/resources/images/gradle2.png')) 107 | 108 | GradleRunner.create() 109 | .withProjectDir(new File("src/test/resources")) 110 | .withArguments("basicTest") 111 | .build() 112 | 113 | then: 114 | new File("src/test/resources/out/gradle.png").exists() 115 | !new File("src/test/resources/out/gradle2.png").exists() 116 | 117 | cleanup: 118 | FileUtils.deleteQuietly(new File('src/test/resources/images/gradle2.png')) 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/test/groovy/com/eowise/imagemagick/tasks/ConvertTest.groovy: -------------------------------------------------------------------------------- 1 | package com.eowise.imagemagick.tasks 2 | 3 | import org.apache.commons.io.FileUtils 4 | import org.gradle.api.Project 5 | import org.gradle.api.file.FileTree 6 | import org.gradle.api.file.FileVisitDetails 7 | import org.gradle.testfixtures.ProjectBuilder 8 | import org.gradle.testkit.runner.GradleRunner 9 | import spock.lang.Specification 10 | 11 | class ConvertTest extends Specification { 12 | 13 | def "Test string output file"() { 14 | Project project = ProjectBuilder.builder().withProjectDir(new File('src/test/resources')).build() 15 | Magick task = (Magick)project.task('magick', type: Magick) 16 | FileTree inputFiles = project.fileTree('images', {include: '*.png'; exclude: '*2.png'}) 17 | 18 | when: 19 | task.convert('images', {include: '*.png'; exclude: '*2.png'}) 20 | task.into('out') 21 | task.actions { 22 | inputFile() 23 | -background('black') 24 | outputFile() 25 | } 26 | then: 27 | inputFiles.visit { FileVisitDetails f -> assert task.buildArgs(f).join(' ') == project.file('images/gradle.png').toString() + " -background black " + project.file('out/gradle.png').toString() } 28 | task.outputDir == project.file('out') 29 | } 30 | 31 | def "Test string output file with rename"() { 32 | Project project = ProjectBuilder.builder().withProjectDir(new File('src/test/resources')).build() 33 | Magick task = (Magick)project.task('magick', type: Magick) 34 | FileTree inputFiles = project.fileTree('images', {include: '*.png'; exclude: '*2.png'}) 35 | 36 | when: 37 | task.convert('images', {include: '*.png'; exclude: '*2.png'}) 38 | task.into('out') 39 | task.actions { 40 | inputFile() 41 | -background('black') 42 | outputFile { fileName, extension -> "computed-${fileName}.${extension}" } 43 | } 44 | then: 45 | inputFiles.visit { FileVisitDetails f -> assert task.buildArgs(f).join(' ') == project.file('images/gradle.png').toString() + " -background black " + project.file('out/computed-gradle.png').toString() } 46 | task.outputDir == project.file('out') 47 | } 48 | 49 | def "Test closure output dir"() { 50 | when: 51 | GradleRunner.create() 52 | .withProjectDir(new File("src/test/resources")) 53 | .withArguments("testWithClosureOutputDir", "--rerun-tasks") 54 | .build() 55 | 56 | then: 57 | new File("src/test/resources/out/gradle.png").exists() 58 | } 59 | 60 | def "Test closure output file with rename"() { 61 | Project project = ProjectBuilder.builder().withProjectDir(new File('src/test/resources')).build() 62 | Magick task = (Magick)project.task('magick', type: Magick) 63 | FileTree inputFiles = project.fileTree('images', {include: '*.png'; exclude: '*2.png'}) 64 | 65 | when: 66 | task.convert('images', {include: '*.png'; exclude: '*2.png'}) 67 | task.into { relativePath -> "out/${relativePath}"} 68 | task.actions { 69 | inputFile() 70 | -background('black') 71 | outputFile { fileName, extension -> "computed-${fileName}.${extension}" } 72 | } 73 | 74 | then: 75 | inputFiles.visit { FileVisitDetails f -> assert task.buildArgs(f).join(' ') == project.file('images/gradle.png').toString() + " -background black " + project.file('out/computed-gradle.png').toString() } 76 | task.outputDir == project.file('out') 77 | } 78 | 79 | def "Test without output dir"() { 80 | Project project = ProjectBuilder.builder().withProjectDir(new File('src/test/resources')).build() 81 | Magick task = (Magick)project.task('magick', type: Magick) 82 | FileTree inputFiles = project.fileTree('images', {include: '*.png'; exclude: '*2.png'}) 83 | 84 | when: 85 | task.convert('images', {include: '*.png'; exclude: '*2.png'}) 86 | task.actions { 87 | inputFile() 88 | -background('black') 89 | inputFile() 90 | } 91 | 92 | then: 93 | inputFiles.visit { FileVisitDetails f -> assert task.buildArgs(f).join(' ') == project.file('images/gradle.png').toString() + " -background black " + project.file('images/gradle.png').toString() } 94 | task.outputDir == project.file('images') 95 | } 96 | 97 | def "Test removing input file remove also output file"() { 98 | FileUtils.copyFile(new File('src/test/resources/images/gradle.png'), new File('src/test/resources/images/gradle2.png')) 99 | 100 | when: 101 | GradleRunner.create() 102 | .withProjectDir(new File("src/test/resources")) 103 | .withArguments("basicTest", "--rerun-tasks") 104 | .build() 105 | 106 | FileUtils.deleteQuietly(new File('src/test/resources/images/gradle2.png')) 107 | 108 | GradleRunner.create() 109 | .withProjectDir(new File("src/test/resources")) 110 | .withArguments("basicTest") 111 | .build() 112 | 113 | then: 114 | new File("src/test/resources/out/gradle.png").exists() 115 | !new File("src/test/resources/out/gradle2.png").exists() 116 | 117 | cleanup: 118 | FileUtils.deleteQuietly(new File('src/test/resources/images/gradle2.png')) 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | --------------------------------------------------------------------------------