diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..5afaade --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,83 @@ +version: 2.1 +anchors: + env_gradle: &env_gradle + environment: + # we're only allowed to use 2 vCPUs + GRADLE_OPTS: "-Dorg.gradle.workers.max=2" + docker: + - image: cimg/openjdk:8.0 + + restore_cache_wrapper: &restore_cache_wrapper + restore_cache: + key: gradle-wrapper-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }} + restore_cache_deps: &restore_cache_deps + restore_cache: + keys: + - gradle-deps-{{ checksum "build.gradle" }}-{{ checksum "gradle.properties" }} + - gradle-deps- + set_git_origin_to_https: &set_git_origin_to_https + run: + name: set git origin to https + command: git remote set-url --push origin https://github.com/diffplug/image-grinder + +jobs: + assemble_and_check: + <<: *env_gradle + steps: + - checkout + - *restore_cache_wrapper + - *restore_cache_deps + - run: + name: gradlew spotlessCheck assemble testClasses + command: ./gradlew spotlessCheck assemble testClasses --build-cache + - run: + name: gradlew check + command: ./gradlew check --build-cache + - save_cache: + paths: + - ~/.gradle/wrapper + key: gradle-wrapper-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }} + - save_cache: + paths: + - ~/.gradle/caches + key: gradle-deps-{{ checksum "build.gradle" }}-{{ checksum "gradle.properties" }} + changelog_print: + << : *env_gradle + steps: + - checkout + - *restore_cache_wrapper + - *restore_cache_deps + - run: + name: gradlew changelogPrint + command: ./gradlew changelogPrint + do_release: + << : *env_gradle + steps: + - checkout + - *restore_cache_wrapper + - *restore_cache_deps + - *set_git_origin_to_https + - run: + name: changelogPush + command: ./gradlew changelogPush -Penable_publishing=true -Pgradle.publish.key=${gradle_key} -Pgradle.publish.secret=${gradle_secret} --stacktrace --warning-mode all + +workflows: + version: 2 + assemble_and_check: + jobs: + - assemble_and_check + deploy: + jobs: + - changelog_print: + filters: + branches: + only: main + - release: + type: approval + requires: + - changelog_print + - do_release: + requires: + - release + context: + - SonatypeDeploy diff --git a/CHANGES.md b/CHANGES.md index 41ddc38..32183ab 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,7 +2,25 @@ ## [Unreleased] +## [2.2.2] - 2021-09-04 +### Fixed +- Skip directories (DOH!). + +## [2.2.1] - 2021-09-04 +### Fixed +- Now supports the Gradle Configuration Cache, but we had to lose support for incremental build ([#9](https://github.com/diffplug/image-grinder/pull/9)). + +## [2.2.0] - 2021-09-04 [YANKED] +### Added +- Now supports the Gradle Configuration Cache ([#8](https://github.com/diffplug/image-grinder/pull/8)). + - This required bumping our minimum required Gradle from `5.6` to `6.0`. + +## [2.1.3] - 2021-06-12 +### Fixed +- Bumped batik from 1.12 to 1.14 + ## [2.1.2] - 2020-01-26 +### Fixed - Fixed deprecation warning for multi-project parallel builds. ## [2.1.1] - 2020-01-25 diff --git a/README.md b/README.md index c47f0e0..b6c45e2 100644 --- a/README.md +++ b/README.md @@ -6,24 +6,24 @@ output = [ link(shield('Maven central', 'mavencentral', 'available', 'blue'), 'https://search.maven.org/artifact/com.diffplug.gradle/image-grinder'), link(shield('Apache 2.0', 'license', 'apache-2.0', 'blue'), 'https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)'), '', - link(shield('Changelog', 'changelog', versionLast, 'brightgreen'), 'CHANGELOG.md'), + link(shield('Changelog', 'changelog', versionLast, 'brightgreen'), 'CHANGES.md'), link(shield('Javadoc', 'javadoc', 'yes', 'brightgreen'), 'https://javadoc.io/doc/com.diffplug.gradle/image-grinder/{{versionLast}}/index.html'), link(shield('Live chat', 'gitter', 'chat', 'brightgreen'), 'https://gitter.im/diffplug/image-grinder'), - link(image('JitCI', 'https://jitci.com/gh/diffplug/image-grinder/svg'), 'https://jitci.com/gh/diffplug/image-grinder') + link(image('CircleCI', 'https://circleci.com/gh/diffplug/image-grinder.svg?style=shield'), 'https://circleci.com/gh/diffplug/image-grinder') ].join('\n'); --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.image--grinder-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.image-grinder) [![Maven central](https://img.shields.io/badge/mavencentral-available-blue.svg)](https://search.maven.org/artifact/com.diffplug.gradle/image-grinder) [![Apache 2.0](https://img.shields.io/badge/license-apache--2.0-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) -[![Changelog](https://img.shields.io/badge/changelog-2.1.2-brightgreen.svg)](CHANGELOG.md) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-brightgreen.svg)](https://javadoc.io/doc/com.diffplug.gradle/image-grinder/2.1.2/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.2.2-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-brightgreen.svg)](https://javadoc.io/doc/com.diffplug.gradle/image-grinder/2.2.2/index.html) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/image-grinder) -[![JitCI](https://jitci.com/gh/diffplug/image-grinder/svg)](https://jitci.com/gh/diffplug/image-grinder) +[![CircleCI](https://circleci.com/gh/diffplug/image-grinder.svg?style=shield)](https://circleci.com/gh/diffplug/image-grinder) ## Simple image processing @@ -47,15 +47,36 @@ imageGrinder { } ``` -Every single file in `srcDir` needs to be an image that ImageGrinder can parse. Each image will be parsed, and wrapped into an [`Img`](https://javadoc.io/static/com.diffplug.gradle/image-grinder/2.1.2/com/diffplug/gradle/imagegrinder/Img.html). Call its methods to grind it into whatever you need in the `dstDir`. +Every single file in `srcDir` needs to be an image that ImageGrinder can parse. Each image will be parsed, and wrapped into an [`Img`](https://javadoc.io/doc/com.diffplug.gradle/image-grinder/2.2.2/com/diffplug/gradle/imagegrinder/Img.html). Call its methods to grind it into whatever you need in the `dstDir`. -ImageGrinder uses the gradle [Worker API](https://docs.gradle.org/5.6/userguide/custom_tasks.html#worker_api) introduced in Gradle 5.6 to use all your CPU cores for grinding. It also uses gradle's [incremental task](https://docs.gradle.org/5.6/userguide/custom_tasks.html#incremental_tasks) support to do the minimum amount of grinding required. +ImageGrinder uses the gradle [Worker API](https://docs.gradle.org/6.6/userguide/custom_tasks.html#worker_api) to use all your CPU cores for grinding, the [buildcache](https://docs.gradle.org/6.6/userguide/build_cache.html) to minimize the necessary work, and it also supports the [configuration cache](https://docs.gradle.org/6.6/userguide/configuration_cache.html) for near-instant startup times. It does not currently support [incremental update](https://docs.gradle.org/6.0/userguide/custom_tasks.html#incremental_tasks), but if you go back to `2.1.3` you can get that back in return for losing the configuration cache (see [#9](https://github.com/diffplug/image-grinder/pull/9) for details). + + +## Configuration avoidance + +The plugin creates tasks eagerly. If you wish to avoid this, you can rewrite the example above like this: + +```gradle +def processEclipseSvg = tasks.register('processEclipseSvg', com.diffplug.gradle.imagegrinder.ImageGrinderTask) { + srcDir = file('src') + dstDir = file('dst') + grinder { img -> + img.render('.png') + img.render('@2x.png', 2) + } + // used for up-to-date checking, bump this if the function above changes + bumpThisNumberWhenTheGrinderChanges = 1 +} +tasks.named(JavaPlugin.PROCESS_RESOURCES_TASK_NAME) { + dependsOn processSvg +} +``` ## Limitations - ImageGrinder can only read SVG images. - ImageGrinder can only write PNG images. -- ImageGrinder needs Gradle 5.6 or higher. +- ImageGrinder needs Gradle 6.0 or higher. Not much of a grinder, but it does everything we needed. If you need more, we're [happy to take PR's](CONTRIBUTING.md)! diff --git a/build.gradle b/build.gradle index d6edfb8..dffa9a5 100644 --- a/build.gradle +++ b/build.gradle @@ -9,14 +9,12 @@ spotlessChangelog { ifFoundBumpAdded '### Added', '### Changed' } apply from: 干.file('base/changelog.gradle') -apply from: 干.file('spotless/freshmark.gradle') - apply from: 干.file('base/java8.gradle') -apply from: 干.file('spotless/java.gradle') - apply from: 干.file('base/gradle-plugin.gradle') apply from: 干.file('base/maven.gradle') -apply from: 干.file('base/bintray.gradle') +apply from: 干.file('base/sonatype.gradle') +apply from: 干.file('spotless/freshmark.gradle') +apply from: 干.file('spotless/java.gradle') test.testLogging.exceptionFormat = 'full' @@ -26,12 +24,12 @@ dependencies { implementation 'com.diffplug.durian:durian-collect:1.2.0' implementation 'com.diffplug.durian:durian-io:1.2.0' // svg - implementation 'org.apache.xmlgraphics:batik-rasterizer:1.12' - implementation 'org.apache.xmlgraphics:batik-codec:1.12' + implementation 'org.apache.xmlgraphics:batik-rasterizer:1.14' + implementation 'org.apache.xmlgraphics:batik-codec:1.14' // testing - testImplementation 'junit:junit:4.13' - testImplementation 'org.assertj:assertj-core:3.14.0' - testImplementation 'org.assertj:assertj-swing-junit:3.9.2' + testImplementation 'junit:junit:4.13.2' + testImplementation 'org.assertj:assertj-core:3.19.0' + testImplementation 'org.assertj:assertj-swing-junit:3.17.1' // we'll want the findbugs annotations (they don't have a 3.0.1 version) compileOnly 'com.google.code.findbugs:annotations:3.0.1' compileOnly 'com.google.code.findbugs:jsr305:3.0.2' diff --git a/settings.gradle b/settings.gradle index af7a4d8..4ac5e80 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,24 +1,26 @@ pluginManagement { plugins { - id 'com.diffplug.blowdryer' version '1.0.0' - id 'com.diffplug.blowdryerSetup' version '1.0.0' - id 'com.diffplug.eclipse.mavencentral' version '3.21.0' - id 'com.diffplug.gradle.spotless' version '3.27.1' - id 'com.diffplug.spotless-changelog' version '1.0.0' - id 'com.gradle.plugin-publish' version '0.10.1' - id 'com.jfrog.bintray' version '1.8.4' + id 'com.diffplug.blowdryer' version '1.1.1' + id 'com.diffplug.blowdryerSetup' version '1.1.1' + id 'com.diffplug.osgi.bndmanifest' version '3.29.1' + id 'com.diffplug.spotless-changelog' version '2.2.0' + id 'com.diffplug.spotless' version '5.13.0' + id 'com.gradle.plugin-publish' version '0.15.0' + id 'io.github.gradle-nexus.publish-plugin' version '1.1.0' + id 'org.jdrupes.mdoclet' version '1.0.10' } } plugins { id 'com.diffplug.blowdryerSetup' - id 'com.diffplug.eclipse.mavencentral' apply false - id 'com.diffplug.gradle.spotless' apply false - id 'com.diffplug.spotless-changelog' apply false - id 'com.gradle.plugin-publish' apply false - id 'com.jfrog.bintray' apply false + id 'com.diffplug.osgi.bndmanifest' apply false + id 'com.diffplug.spotless-changelog' apply false + id 'com.diffplug.spotless' apply false + id 'com.gradle.plugin-publish' apply false + id 'io.github.gradle-nexus.publish-plugin' apply false + id 'org.jdrupes.mdoclet' apply false } blowdryerSetup { - github 'diffplug/blowdryer-diffplug', 'tag', '3.1.0' + github 'diffplug/blowdryer-diffplug', 'tag', '5.1.3' //devLocal '../blowdryer-diffplug' } rootProject.name = 'image-grinder' diff --git a/src/main/java/com/diffplug/gradle/imagegrinder/ImageGrinderPlugin.java b/src/main/java/com/diffplug/gradle/imagegrinder/ImageGrinderPlugin.java index d0ab680..2a08dd2 100644 --- a/src/main/java/com/diffplug/gradle/imagegrinder/ImageGrinderPlugin.java +++ b/src/main/java/com/diffplug/gradle/imagegrinder/ImageGrinderPlugin.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 DiffPlug + * Copyright (C) 2020-2021 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/main/java/com/diffplug/gradle/imagegrinder/ImageGrinderTask.java b/src/main/java/com/diffplug/gradle/imagegrinder/ImageGrinderTask.java index 31630fe..5d4b117 100644 --- a/src/main/java/com/diffplug/gradle/imagegrinder/ImageGrinderTask.java +++ b/src/main/java/com/diffplug/gradle/imagegrinder/ImageGrinderTask.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 DiffPlug + * Copyright (C) 2020-2021 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package com.diffplug.gradle.imagegrinder; -import com.diffplug.common.collect.HashMultimap; import java.io.File; import java.io.Serializable; import java.util.Objects; @@ -25,7 +24,7 @@ import org.gradle.api.Action; import org.gradle.api.DefaultTask; import org.gradle.api.file.DirectoryProperty; -import org.gradle.api.file.FileType; +import org.gradle.api.file.FileSystemOperations; import org.gradle.api.file.RegularFileProperty; import org.gradle.api.provider.Property; import org.gradle.api.tasks.CacheableTask; @@ -35,10 +34,6 @@ import org.gradle.api.tasks.PathSensitive; import org.gradle.api.tasks.PathSensitivity; import org.gradle.api.tasks.TaskAction; -import org.gradle.work.ChangeType; -import org.gradle.work.FileChange; -import org.gradle.work.Incremental; -import org.gradle.work.InputChanges; import org.gradle.workers.WorkAction; import org.gradle.workers.WorkParameters; import org.gradle.workers.WorkQueue; @@ -54,19 +49,6 @@ * Worker requires that all arguments to its worker runnables ({@link ImageGrinderTask} * in this case) be Serializable. There's no way to serialize our {@link #grinder(Action)}, so we had * to use {@link SerializableRef} to sneakily pass our task to the worker. - * - * ## Tedious thing #2: Removal handling - * - * Tedious thing #2: .java to .class has a 1:1 mapping. But that is not true for these images - a pipeline - * might create two images from one source, and the number of outputs might even change based on the content - * of the input (e.g. skip hi-res versions of very large images). - * - * That means that when the user removes or changes an image, we need to remember exactly which files it - * created last time, or else we might end up with stale results lying around. So, this task has the - * {@link #map} field which is a multimap from source file to the dst files it created. When the task starts, - * it reads this map from disk, and when the task finishes, it writes it to disk. Whenever an {@link Img} is - * rendered, the filename that was written is saved to this map via the {@link Img#registerDstFile(String)} - * method. */ @CacheableTask public abstract class ImageGrinderTask extends DefaultTask { @@ -77,7 +59,6 @@ public ImageGrinderTask(WorkerExecutor workerExecutor) { this.workerExecutor = workerExecutor; } - @Incremental @PathSensitive(PathSensitivity.RELATIVE) @InputDirectory public abstract DirectoryProperty getSrcDir(); @@ -104,63 +85,26 @@ public void grinder(Action> grinder) { this.grinder = grinder; } + @Inject + public abstract FileSystemOperations getFs(); + @TaskAction - public void performAction(InputChanges inputChanges) throws Exception { + public void performAction() throws Exception { Objects.requireNonNull(grinder, "grinder"); + getFs().delete(deleteSpec -> deleteSpec.delete(getDstDir())); - File cache = new File(getProject().getBuildDir(), "cache" + getName()); - if (!inputChanges.isIncremental()) { - getProject().delete(getDstDir().getAsFile().get()); - map = HashMultimap.create(); - } else { - readFromCache(cache); - } WorkQueue queue = workerExecutor.noIsolation(); - for (FileChange fileChange : inputChanges.getFileChanges(getSrcDir())) { - if (fileChange.getFileType() == FileType.DIRECTORY) { - continue; - } - boolean modifiedOrRemoved = fileChange.getChangeType() == ChangeType.MODIFIED || fileChange.getChangeType() == ChangeType.REMOVED; - boolean modifiedOrAdded = fileChange.getChangeType() == ChangeType.MODIFIED || fileChange.getChangeType() == ChangeType.ADDED; - if (modifiedOrRemoved) { - logger.info("clean: " + fileChange.getNormalizedPath()); - remove(fileChange.getFile()); - } - if (modifiedOrAdded) { - logger.info("render: " + fileChange.getNormalizedPath()); - queue.submit(RenderSvg.class, params -> { - params.getSourceFile().set(fileChange.getFile()); - params.getTaskRef().set(SerializableRef.create(ImageGrinderTask.this)); - }); + getSrcDir().get().getAsFileTree().visit(fileVisit -> { + if (fileVisit.isDirectory()) { + return; } - } + logger.info("render: " + fileVisit.getRelativePath()); + queue.submit(RenderSvg.class, params -> { + params.getSourceFile().set(fileVisit.getFile()); + params.getTaskRef().set(SerializableRef.create(ImageGrinderTask.this)); + }); + }); queue.await(); - writeToCache(cache); - } - - private void remove(File srcFile) { - synchronized (map) { - map.removeAll(srcFile).forEach(getProject()::delete); - } - } - - public boolean debug = false; - - HashMultimap map; - - @SuppressWarnings("unchecked") - private void readFromCache(File file) { - if (file.exists()) { - map = SerializableMisc.fromFile(HashMultimap.class, file); - } else { - map = HashMultimap.create(); - } - } - - private void writeToCache(File file) { - synchronized (map) { - SerializableMisc.toFile(map, file); - } } public interface RenderSvgParams extends WorkParameters { diff --git a/src/main/java/com/diffplug/gradle/imagegrinder/Img.java b/src/main/java/com/diffplug/gradle/imagegrinder/Img.java index 587326f..2af2b42 100644 --- a/src/main/java/com/diffplug/gradle/imagegrinder/Img.java +++ b/src/main/java/com/diffplug/gradle/imagegrinder/Img.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 DiffPlug + * Copyright (C) 2020-2021 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -83,9 +83,10 @@ public void renderFull(String fullPath, Size size) { File registerDstFile(String fullPath) { File file = new File(task.getDstDir().getAsFile().get(), fullPath); FileMisc.mkdirs(file.getParentFile()); - synchronized (task.map) { - task.map.put(new File(task.getSrcDir().getAsFile().get(), subpath.full()), file); - } + // TODO: useful for incremental build in the future, perhaps + // synchronized (task.map) { + // task.map.put(new File(task.getSrcDir().getAsFile().get(), subpath.full()), file); + // } return file; } diff --git a/src/main/java/com/diffplug/gradle/imagegrinder/LegacyPlugin.java b/src/main/java/com/diffplug/gradle/imagegrinder/LegacyPlugin.java index f5e40e1..2d26d82 100644 --- a/src/main/java/com/diffplug/gradle/imagegrinder/LegacyPlugin.java +++ b/src/main/java/com/diffplug/gradle/imagegrinder/LegacyPlugin.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 DiffPlug + * Copyright (C) 2020-2021 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,6 @@ import java.util.Map; import org.gradle.api.Plugin; import org.gradle.api.Project; -import org.gradle.util.SingleMessageLogger; public class LegacyPlugin implements Plugin { private final Class> newPlugin; @@ -40,7 +39,10 @@ public void apply(Project proj) { } proj.getPlugins().apply(newPlugin); String oldId = newId.replace("com.diffplug.", "com.diffplug.gradle."); - SingleMessageLogger.nagUserOfReplacedPlugin(oldId, newId); + System.err.println("Plugin '" + oldId + "' has been replaced by '" + newId + "'"); + System.err.println(" This is just a name change, there is no behavior change."); + System.err.println(" The old id will keep working, but it will print this warning message."); + System.err.println(" See here for reason: https://dev.to/nedtwigg/names-in-java-maven-and-gradle-2fm2"); } public static void applyForCompat(Project proj, Class clazz) { diff --git a/src/main/java/com/diffplug/gradle/imagegrinder/Subpath.java b/src/main/java/com/diffplug/gradle/imagegrinder/Subpath.java index 08763d3..a223768 100644 --- a/src/main/java/com/diffplug/gradle/imagegrinder/Subpath.java +++ b/src/main/java/com/diffplug/gradle/imagegrinder/Subpath.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 DiffPlug + * Copyright (C) 2020-2021 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,12 +18,21 @@ import com.diffplug.common.base.Preconditions; import java.io.File; +import org.gradle.api.file.FileSystemLocationProperty; public class Subpath { private final String full; private final String extension; private final String withoutExtension; + public static Subpath from(FileSystemLocationProperty root, FileSystemLocationProperty child) { + return from(root.getAsFile().get(), child.getAsFile().get()); + } + + public static Subpath from(FileSystemLocationProperty root, File child) { + return from(root.getAsFile().get(), child); + } + public static Subpath from(File root, File child) { String rootPath = root.getAbsolutePath().replace('\\', '/') + '/'; String childPath = child.getAbsolutePath().replace('\\', '/'); @@ -31,6 +40,14 @@ public static Subpath from(File root, File child) { return new Subpath(childPath.substring(rootPath.length())); } + public File resolve(File root) { + return new File(root, full); + } + + public File resolve(FileSystemLocationProperty root) { + return resolve(root.getAsFile().get()); + } + public String full() { return full; } @@ -62,4 +79,21 @@ static String extension(String subpath) { Preconditions.checkArgument(idx < subpath.length() - 1, "'%s' can't end in '.'", subpath); return subpath.substring(idx + 1); } + + @Override + public int hashCode() { + return full.hashCode(); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } else if (other instanceof Subpath) { + Subpath sub = (Subpath) other; + return sub.full.equals(full); + } else { + return false; + } + } } diff --git a/src/test/java/com/diffplug/gradle/imagegrinder/GradleHarness.java b/src/test/java/com/diffplug/gradle/imagegrinder/GradleHarness.java index 2e1fa74..ac155f5 100644 --- a/src/test/java/com/diffplug/gradle/imagegrinder/GradleHarness.java +++ b/src/test/java/com/diffplug/gradle/imagegrinder/GradleHarness.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 DiffPlug + * Copyright (C) 2020-2021 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,7 +29,7 @@ public class GradleHarness extends ResourceHarness { /** A gradleRunner(). */ protected GradleRunner gradleRunner() throws IOException { - return GradleRunner.create().withGradleVersion("5.6").withProjectDir(rootFolder()).withPluginClasspath(); + return GradleRunner.create().withGradleVersion("6.0").withProjectDir(rootFolder()).withPluginClasspath(); } /** Runs the eclipseSvg task and asserts that the given result is applied to the given files. */ diff --git a/src/test/java/com/diffplug/gradle/imagegrinder/ImageGrinderPluginTest.java b/src/test/java/com/diffplug/gradle/imagegrinder/ImageGrinderPluginTest.java index f0731fa..be354ee 100644 --- a/src/test/java/com/diffplug/gradle/imagegrinder/ImageGrinderPluginTest.java +++ b/src/test/java/com/diffplug/gradle/imagegrinder/ImageGrinderPluginTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 DiffPlug + * Copyright (C) 2020-2021 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,7 +45,7 @@ public void testDeprecated() throws Exception { BuildResult result = gradleRunner().withArguments("eclipseSvg", "--warning-mode", "all").build(); System.out.println(result.getOutput().replace("\r", "")); Assertions.assertThat(result.getOutput().replace("\r", "")) - .contains("The com.diffplug.gradle.image-grinder plugin has been deprecated. This is scheduled to be removed in Gradle 6.0. Please use the com.diffplug.image-grinder plugin instead."); + .contains("Plugin 'com.diffplug.gradle.image-grinder' has been replaced by 'com.diffplug.image-grinder'"); ParsedSVGTest.assertEqual(file("dst/refresh@2x.png"), "refresh32.png"); } @@ -81,6 +81,15 @@ public void testOnce() throws Exception { ParsedSVGTest.assertEqual(file("dst/refresh@2x.png"), "refresh32.png"); } + @Test + public void testOnceConfigurationCache() throws Exception { + writeBuild(); + write("src/refresh.svg", readTestResource("refresh.svg")); + gradleRunner().withGradleVersion("6.6").withArguments("--configuration-cache", "eclipseSvg").build(); + ParsedSVGTest.assertEqual(file("dst/refresh.png"), "refresh16.png"); + ParsedSVGTest.assertEqual(file("dst/refresh@2x.png"), "refresh32.png"); + } + @Test public void testUpToDate() throws Exception { writeBuild(); @@ -108,35 +117,4 @@ public void testUpToDate() throws Exception { runAndAssert(TaskOutcome.SUCCESS); runAndAssert(TaskOutcome.UP_TO_DATE); } - - @Test - public void testIncremental() throws Exception { - writeBuild(); - - // one file - write("src/refresh.svg", readTestResource("refresh.svg")); - runAndAssert(TaskOutcome.SUCCESS).containsExactly("render: refresh.svg"); - assertFolderContent("dst").containsExactly("refresh.png", "refresh@2x.png"); - - // add a file, and only it changes - write("src/diffpluglogo.svg", readTestResource("diffpluglogo.svg")); - runAndAssert(TaskOutcome.SUCCESS).containsExactly("render: diffpluglogo.svg"); - assertFolderContent("dst").containsExactly("diffpluglogo.png", "diffpluglogo@2x.png", "refresh.png", "refresh@2x.png"); - - // remove a file, and only it is removed - delete("src/refresh.svg"); - runAndAssert(TaskOutcome.SUCCESS).containsExactly("clean: refresh.svg"); - assertFolderContent("dst").containsExactly("diffpluglogo.png", "diffpluglogo@2x.png"); - - // remove another file, and we end up with an empty directory - delete("src/diffpluglogo.svg"); - runAndAssert(TaskOutcome.SUCCESS).containsExactly("clean: diffpluglogo.svg"); - assertFolderContent("dst").isEmpty(); - - // add them both, and they're both rendered - write("src/refresh.svg", readTestResource("refresh.svg")); - write("src/diffpluglogo.svg", readTestResource("diffpluglogo.svg")); - runAndAssert(TaskOutcome.SUCCESS).containsExactlyInAnyOrder("render: refresh.svg", "render: diffpluglogo.svg"); - assertFolderContent("dst").containsExactly("diffpluglogo.png", "diffpluglogo@2x.png", "refresh.png", "refresh@2x.png"); - } }