Skip to content

Commit

Permalink
Fixes up-to-date checking for the case that a changed file changes wh…
Browse files Browse the repository at this point in the history
…at the output files are.
  • Loading branch information
nedtwigg committed Oct 1, 2017
2 parents 4a59ce4 + d4e2209 commit eac3584
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,28 @@ public void performAction(IncrementalTaskInputs inputs) throws Exception {
}
inputs.outOfDate(outOfDate -> {
logger.info("outOfDate: " + Subpath.subpath(srcDir, outOfDate.getFile()));
if (outOfDate.isModified()) {
remove(outOfDate.getFile());
}
workerExecutor.submit(ProcessFile.class, workerConfig -> {
workerConfig.setIsolationMode(IsolationMode.NONE);
workerConfig.setParams(SerializableRef.create(ImageGrinderTask.this), outOfDate.getFile());
});
});
inputs.removed(removed -> {
logger.info("removed: " + Subpath.subpath(srcDir, removed.getFile()));
synchronized (map) {
map.removeAll(removed.getFile()).forEach(getProject()::delete);
}
remove(removed.getFile());
});
workerExecutor.await();
writeToCache(cache);
}

private void remove(File srcFile) {
synchronized (map) {
map.removeAll(srcFile).forEach(getProject()::delete);
}
}

@Internal
public boolean debug = false;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2017 DiffPlug
*
* 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 com.diffplug.gradle.imagegrinder;

import org.gradle.testkit.runner.TaskOutcome;
import org.junit.Test;

public class ImageGrinderPluginSizeDependentTest extends GradleHarness {
@Test
public void testUpToDate() throws Exception {
write("build.gradle",
"plugins {",
" id 'com.diffplug.gradle.image-grinder'",
"}",
"imageGrinder {",
" eclipseSvg {",
" srcDir = file('src')",
" dstDir = file('dst')",
" bumpThisNumberWhenTheGrinderChanges = 1",
" grinder { img ->",
" if (img.size().width() <= 16) {",
" // hiDpi for small images",
" img.render('.png')",
" img.render('@2x.png', 2)",
" } else {",
" // but not for big images",
" img.render('.png')",
" }",
" }",
" }",
"}");
// this image is 16x16, so it should be rendered with HiDPI
write("src/refresh.svg", readTestResource("refresh.svg"));
runAndAssert(TaskOutcome.SUCCESS);
runAndAssert(TaskOutcome.UP_TO_DATE);
assertFolderContent("dst").containsExactly("refresh.png", "[email protected]");

// this image is large, so it should only have a 1x rendering
write("src/refresh.svg", readTestResource("refresh-large.svg"));
runAndAssert(TaskOutcome.SUCCESS);
runAndAssert(TaskOutcome.UP_TO_DATE);
assertFolderContent("dst").containsExactly("refresh.png");
}
}
68 changes: 68 additions & 0 deletions src/test/resources/refresh-large.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit eac3584

Please sign in to comment.