Skip to content
This repository was archived by the owner on Jan 25, 2021. It is now read-only.

Commit 761af07

Browse files
committed
testing against gradle 3.3
1 parent a6fae45 commit 761af07

File tree

19 files changed

+407
-62
lines changed

19 files changed

+407
-62
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ repositories {
1616
}
1717

1818
ext {
19-
gradleVersions = '3.0,3.1,3.2,3.2.1'
19+
gradleVersions = '3.0,3.1,3.2,3.2.1,3.3'
2020
androidGradleBuildVersion = '2.2.0-beta1'
2121
androidCompileSdkVersion = 'android-24'
2222
androidBuildToolsVersion = '24.0.0'
@@ -223,7 +223,7 @@ jacocoTestReport.dependsOn test
223223
check.dependsOn jacocoTestReport
224224

225225
task wrapper(type: Wrapper) {
226-
gradleVersion = '3.2.1'
226+
gradleVersion = '3.3'
227227
distributionUrl = "https://services.gradle.org/distributions/gradle-${gradleVersion}-all.zip"
228228
}
229229

gradle/wrapper/gradle-wrapper.jar

-19 Bytes
Binary file not shown.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Tue Nov 22 21:11:44 EST 2016
1+
#Tue Jan 03 21:54:54 EST 2017
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-3.2.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

src/test/core/src/testFixtures/groovy/org/gradle/api/internal/file/TestFiles.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static FileResolver resolver(File baseDir) {
5656
}
5757

5858
public static DirectoryFileTreeFactory directoryFileTreeFactory() {
59-
return new DefaultDirectoryFileTreeFactory();
59+
return new DefaultDirectoryFileTreeFactory(getPatternSetFactory(), fileSystem());
6060
}
6161

6262
public static FileCollectionFactory fileCollectionFactory() {

src/test/core/src/testFixtures/groovy/org/gradle/api/tasks/AbstractSpockTaskTest.groovy

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import org.gradle.api.internal.AsmBackedClassGenerator
2525
import org.gradle.api.internal.project.ProjectInternal
2626
import org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory
2727
import org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore
28+
import org.gradle.api.internal.project.taskfactory.DefaultTaskClassValidatorExtractor
2829
import org.gradle.api.internal.project.taskfactory.ITaskFactory
2930
import org.gradle.api.internal.project.taskfactory.TaskFactory
3031
import org.gradle.api.internal.tasks.TaskExecuter
@@ -44,7 +45,8 @@ import static org.junit.Assert.assertFalse
4445
public abstract class AbstractSpockTaskTest extends AbstractProjectBuilderSpec {
4546
public static final String TEST_TASK_NAME = "taskname"
4647

47-
private static final ITaskFactory TASK_FACTORY = new AnnotationProcessingTaskFactory(new DefaultTaskClassInfoStore(), new TaskFactory(new AsmBackedClassGenerator()))
48+
def taskClassInfoStore = new DefaultTaskClassInfoStore(new DefaultTaskClassValidatorExtractor())
49+
private final ITaskFactory taskFactory = new AnnotationProcessingTaskFactory(taskClassInfoStore, new TaskFactory(new AsmBackedClassGenerator()))
4850

4951
public abstract AbstractTask getTask();
5052

@@ -57,7 +59,7 @@ public abstract class AbstractSpockTaskTest extends AbstractProjectBuilderSpec {
5759
}
5860

5961
public <T extends AbstractTask> T createTask(Class<T> type, Project project, String name) {
60-
Task task = TASK_FACTORY.createChild(project, DirectInstantiator.INSTANCE).createTask(
62+
Task task = taskFactory.createChild(project, DirectInstantiator.INSTANCE).createTask(
6163
GUtil.map(Task.TASK_TYPE, type,
6264
Task.TASK_NAME, name))
6365
assert type.isAssignableFrom(task.getClass())
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright 2016 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.gradle.internal.progress;
18+
19+
import org.gradle.api.Action;
20+
import org.gradle.api.Nullable;
21+
import org.gradle.api.Transformer;
22+
import org.gradle.internal.operations.BuildOperationContext;
23+
24+
import java.util.List;
25+
import java.util.concurrent.CopyOnWriteArrayList;
26+
27+
/**
28+
* A BuildOperationExecutor for tests.
29+
* Simply execute given operations, does not support current/parent operations.
30+
*/
31+
public class TestBuildOperationExecutor implements BuildOperationExecutor {
32+
public final List<BuildOperationDetails> operations = new CopyOnWriteArrayList<BuildOperationDetails>();
33+
34+
@Override
35+
public Operation getCurrentOperation() {
36+
return new Operation() {
37+
@Override
38+
public Object getId() {
39+
return "current";
40+
}
41+
};
42+
}
43+
44+
@Override
45+
public <T> T run(String displayName, Transformer<T, ? super BuildOperationContext> factory) {
46+
operations.add(BuildOperationDetails.displayName(displayName).build());
47+
return factory.transform(new TestBuildOperationContext());
48+
}
49+
50+
@Override
51+
public <T> T run(BuildOperationDetails operationDetails, Transformer<T, ? super BuildOperationContext> factory) {
52+
operations.add(operationDetails);
53+
return factory.transform(new TestBuildOperationContext());
54+
}
55+
56+
@Override
57+
public void run(String displayName, Action<? super BuildOperationContext> action) {
58+
operations.add(BuildOperationDetails.displayName(displayName).build());
59+
action.execute(new TestBuildOperationContext());
60+
}
61+
62+
@Override
63+
public void run(BuildOperationDetails operationDetails, Action<? super BuildOperationContext> action) {
64+
operations.add(operationDetails);
65+
action.execute(new TestBuildOperationContext());
66+
}
67+
68+
private static class TestBuildOperationContext implements BuildOperationContext {
69+
@Override
70+
public void failed(@Nullable Throwable failure) {
71+
}
72+
}
73+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright 2016 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.gradle.util
18+
19+
import com.google.common.base.Splitter
20+
21+
class BinaryDiffUtils {
22+
public static List<String> toHexStrings(byte[] bytes, int bytesPerLine = 16) {
23+
def sw = new StringWriter()
24+
bytes.encodeHex().writeTo(sw)
25+
return Splitter.fixedLength(bytesPerLine * 2).split(sw.toString()).collect { line ->
26+
Splitter.fixedLength(2).split(line).join(" ")
27+
}
28+
}
29+
30+
public static int levenshteinDistance(byte[] lhs, byte[] rhs) {
31+
int len0 = lhs.length + 1;
32+
int len1 = rhs.length + 1;
33+
34+
// the array of distances
35+
int[] cost = new int[len0];
36+
int[] newcost = new int[len0];
37+
38+
// initial cost of skipping prefix in byte[] s0
39+
for (int i = 0; i < len0; i++) {
40+
cost[i] = i
41+
}
42+
43+
// dynamically computing the array of distances
44+
45+
// transformation cost for each letter in s1
46+
for (int j = 1; j < len1; j++) {
47+
// initial cost of skipping prefix in byte[] s1
48+
newcost[0] = j;
49+
50+
// transformation cost for each letter in s0
51+
for (int i = 1; i < len0; i++) {
52+
// matching current letters in both strings
53+
int match = (lhs[i - 1] == rhs[j - 1]) ? 0 : 1;
54+
55+
// computing cost for each transformation
56+
int costReplace = cost[i - 1] + match;
57+
int costInsert = cost[i] + 1;
58+
int costDelete = newcost[i - 1] + 1;
59+
60+
// keep minimum cost
61+
newcost[i] = Math.min(Math.min(costInsert, costDelete), costReplace);
62+
}
63+
64+
// swap cost/newcost arrays
65+
int[] swap = cost; cost = newcost; newcost = swap;
66+
}
67+
68+
// the distance is the cost for transforming all letters in both strings
69+
return cost[len0 - 1];
70+
}
71+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2016 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.gradle.util
18+
19+
import java.util.jar.JarOutputStream
20+
import java.util.zip.ZipEntry
21+
22+
class JarUtils {
23+
static def jarWithContents(Map<String, String> contents) {
24+
def out = new ByteArrayOutputStream()
25+
def jarOut = new JarOutputStream(out)
26+
try {
27+
contents.each { file, fileContents ->
28+
def zipEntry = new ZipEntry(file)
29+
zipEntry.setTime(0)
30+
jarOut.putNextEntry(zipEntry)
31+
jarOut << fileContents
32+
}
33+
} finally {
34+
jarOut.close()
35+
}
36+
return out.toByteArray()
37+
}
38+
}

src/test/core/src/testFixtures/groovy/org/gradle/util/MockTimeProvider.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package org.gradle.util;
1818

19-
import org.gradle.internal.TimeProvider;
19+
import org.gradle.internal.time.TimeProvider;
2020

2121
public class MockTimeProvider implements TimeProvider {
2222

@@ -40,4 +40,10 @@ public long getCurrentTime() {
4040
current += 10L;
4141
return current;
4242
}
43+
44+
/** Increments the time by 10ms and returns it. */
45+
@Override
46+
public long getCurrentTimeForDuration() {
47+
return getCurrentTime();
48+
}
4349
}

src/test/core/src/testFixtures/groovy/org/gradle/util/MultithreadedTestCase.java renamed to src/test/core/src/testFixtures/groovy/org/gradle/util/MultithreadedTestRule.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,20 @@
2424
import org.gradle.internal.concurrent.ExecutorFactory;
2525
import org.hamcrest.Matcher;
2626
import org.junit.After;
27+
import org.junit.rules.ExternalResource;
2728
import org.slf4j.Logger;
2829
import org.slf4j.LoggerFactory;
2930

30-
import java.util.*;
31+
import java.util.ArrayList;
32+
import java.util.Arrays;
33+
import java.util.Collection;
34+
import java.util.Date;
35+
import java.util.EnumSet;
36+
import java.util.HashMap;
37+
import java.util.HashSet;
38+
import java.util.List;
39+
import java.util.Map;
40+
import java.util.Set;
3141
import java.util.concurrent.AbstractExecutorService;
3242
import java.util.concurrent.CopyOnWriteArraySet;
3343
import java.util.concurrent.ExecutorService;
@@ -37,7 +47,7 @@
3747
import java.util.concurrent.locks.ReentrantLock;
3848

3949
/**
40-
* <p>A base class for testing concurrent code.</p>
50+
* <p>A rule for testing concurrent code.</p>
4151
*
4252
* <p>Provides several ways to start and manage threads. You can use the {@link #start(groovy.lang.Closure)} or {@link
4353
* #run(groovy.lang.Closure)} methods to execute test code in other threads. You can use {@link #waitForAll()} to wait
@@ -50,8 +60,8 @@
5060
* <p>You can use {@link #syncAt(int)} and {@link #expectBlocksUntil(int, groovy.lang.Closure)} to synchronise between
5161
* test threads.</p>
5262
*/
53-
public class MultithreadedTestCase {
54-
private static final Logger LOGGER = LoggerFactory.getLogger(MultithreadedTestCase.class);
63+
public class MultithreadedTestRule extends ExternalResource {
64+
private static final Logger LOGGER = LoggerFactory.getLogger(MultithreadedTestRule.class);
5565
private static final int MAX_WAIT_TIME = 5000;
5666
private ExecutorImpl executor;
5767
private final Lock lock = new ReentrantLock();
@@ -257,6 +267,11 @@ public void waitForStop() {
257267
waitForAll();
258268
}
259269

270+
@Override
271+
protected void after() {
272+
waitForStop();
273+
}
274+
260275
/**
261276
* Returns the meta-info for the given clock tick.
262277
*/

0 commit comments

Comments
 (0)