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

Commit

Permalink
updating to gradle 4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
dcendents committed Mar 20, 2018
1 parent a3ddb89 commit ad7a062
Show file tree
Hide file tree
Showing 25 changed files with 166 additions and 67 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repositories {
}

ext {
gradleVersions = '4.1'
gradleVersions = '4.2'
androidGradleBuildVersion = '3.0.0-beta3'
androidCompileSdkVersion = 'android-26'
androidBuildToolsVersion = '26.0.1'
Expand Down Expand Up @@ -229,7 +229,7 @@ jacocoTestReport.dependsOn test
check.dependsOn jacocoTestReport

task wrapper(type: Wrapper) {
gradleVersion = '4.1'
gradleVersion = '4.2'
distributionUrl = "https://services.gradle.org/distributions/gradle-${gradleVersion}-all.zip"
}

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.2-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
import org.gradle.api.tasks.util.PatternSet;
import org.gradle.api.tasks.util.internal.PatternSets;
import org.gradle.internal.Factory;
import org.gradle.internal.hash.DefaultContentHasherFactory;
import org.gradle.internal.hash.DefaultFileHasher;
import org.gradle.internal.hash.DefaultStreamHasher;
import org.gradle.internal.nativeintegration.filesystem.FileSystem;
import org.gradle.internal.reflect.DirectInstantiator;
import org.gradle.internal.resource.local.FileResourceConnector;
import org.gradle.internal.resource.local.FileResourceRepository;
import org.gradle.process.internal.DefaultExecActionFactory;
Expand Down Expand Up @@ -65,6 +69,18 @@ public static DirectoryFileTreeFactory directoryFileTreeFactory() {
return new DefaultDirectoryFileTreeFactory(getPatternSetFactory(), fileSystem());
}

public static FileOperations fileOperations(File basedDir) {
return new DefaultFileOperations(resolver(basedDir), null, null, DirectInstantiator.INSTANCE, fileLookup(), directoryFileTreeFactory(), streamHasher(), fileHasher());
}

public static DefaultStreamHasher streamHasher() {
return new DefaultStreamHasher(new DefaultContentHasherFactory());
}

public static DefaultFileHasher fileHasher() {
return new DefaultFileHasher(streamHasher());
}

public static FileCollectionFactory fileCollectionFactory() {
return new DefaultFileCollectionFactory();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public abstract class AbstractSpockTaskTest extends AbstractProjectBuilderSpec {
getTask().actions = [action2]

then:
[new AbstractTask.TaskActionWrapper(action2)] == getTask().actions
[new AbstractTask.TaskActionWrapper(action2, "doLast(Action)")] == getTask().actions
}

def testAddActionWithNull() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,30 @@ import org.gradle.api.InvalidUserDataException
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.internal.AbstractTask
import org.gradle.api.internal.DependencyInjectingInstantiator
import org.gradle.api.internal.TaskInternal
import org.gradle.api.internal.project.ProjectInternal
import org.gradle.api.internal.project.taskfactory.ITaskFactory
import org.gradle.api.internal.tasks.TaskExecuter
import org.gradle.api.internal.tasks.TaskExecutionContext
import org.gradle.api.internal.tasks.TaskStateInternal
import org.gradle.api.internal.tasks.execution.DefaultTaskExecutionContext
import org.gradle.api.model.ObjectFactory
import org.gradle.api.specs.Spec
import org.gradle.internal.Actions
import org.gradle.internal.reflect.Instantiator
import org.gradle.internal.service.DefaultServiceRegistry
import org.gradle.test.fixtures.AbstractProjectBuilderSpec
import org.gradle.util.GUtil
import org.gradle.util.TestUtil

import java.util.concurrent.atomic.AtomicBoolean

import static org.junit.Assert.*
import static org.junit.Assert.assertTrue

public abstract class AbstractTaskTest extends AbstractProjectBuilderSpec {
abstract class AbstractTaskTest extends AbstractProjectBuilderSpec {
public static final String TEST_TASK_NAME = "testTask"

protected DefaultServiceRegistry serviceRegistry = new DefaultServiceRegistry()

protected Instantiator instantiator = new DependencyInjectingInstantiator(serviceRegistry, new DependencyInjectingInstantiator.ConstructorCache())
protected ObjectFactory objectFactory = TestUtil.objectFactory()

public abstract AbstractTask getTask()

Expand All @@ -71,7 +69,7 @@ public abstract class AbstractTaskTest extends AbstractProjectBuilderSpec {
}

def setup() {
serviceRegistry.add(Instantiator.class, instantiator)
serviceRegistry.add(ObjectFactory.class, objectFactory)
}

def "test Task"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

package org.gradle.cache.internal

import org.gradle.cache.FileAccess
import org.gradle.cache.FileIntegrityViolationException
import org.gradle.cache.FileLock
import org.gradle.cache.FileLockManager
import org.gradle.cache.internal.filelock.LockOptionsBuilder
import org.gradle.cache.internal.locklistener.NoOpFileLockContentionHandler

Expand Down Expand Up @@ -56,7 +60,19 @@ abstract class DefaultFileLockManagerTestHelper {
}
}, new NoOpFileLockContentionHandler())
}


static DefaultFileLockManager createDefaultFileLockManager(int timeout) {
new DefaultFileLockManager(new ProcessMetaDataProvider() {
String getProcessIdentifier() {
return "pid"
}

String getProcessDisplayName() {
return "process"
}
}, timeout, new NoOpFileLockContentionHandler())
}

static FileLock createDefaultFileLock(File file, FileLockManager.LockMode mode = FileLockManager.LockMode.Exclusive, DefaultFileLockManager manager = createDefaultFileLockManager()) {
manager.lock(file, LockOptionsBuilder.mode(mode), "test lock")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.gradle.api.internal.cache;
package org.gradle.cache.internal;

import org.gradle.api.internal.file.TestFiles;
import org.gradle.internal.serialize.Serializer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public int reservePort() {
return -1;
}

public void pingOwner(int port, long lockId, String displayName) {
public boolean maybePingOwner(int port, long lockId, String displayName, long timeElapsed) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ class NoOpProgressLoggerFactory implements ProgressLoggerFactory {
}

ProgressLogger start(String description, String shortDescription) {
start(description, shortDescription, 0)
}

ProgressLogger start(String description, String shortDescription, int totalProgress) {
setDescription(description)
setShortDescription(shortDescription)
started()
Expand All @@ -71,8 +75,10 @@ class NoOpProgressLoggerFactory implements ProgressLoggerFactory {

void started() {}
void started(String status) {}
void started(String status, int totalProgress) {}
void progress(String status) {}
void progress(String status, boolean failing) {}
void completed() {}
void completed(String status) {}
void completed(String status, boolean failed) {}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,19 +14,17 @@
* limitations under the License.
*/

package org.gradle.util;
package org.gradle.internal.time;

import org.gradle.internal.time.TimeProvider;

public class MockTimeProvider implements TimeProvider {
public class MockClock implements Clock {

long current;

public MockTimeProvider() {
public MockClock() {
this(System.currentTimeMillis());
}

public MockTimeProvider(long startTime) {
public MockClock(long startTime) {
current = startTime;
}

Expand All @@ -41,9 +39,4 @@ public long getCurrentTime() {
return current;
}

/** Increments the time by 10ms and returns it. */
@Override
public long getCurrentTimeForDuration() {
return getCurrentTime();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void run() {
return start(task).waitFor();
}

protected ThreadHandle expectTimesOut(int value, TimeUnit units, Closure closure) {
public ThreadHandle expectTimesOut(int value, TimeUnit units, Closure closure) {
Date start = new Date();
ThreadHandle threadHandle = start(closure);
threadHandle.waitFor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ import org.gradle.api.Task
import org.gradle.api.internal.AsmBackedClassGenerator
import org.gradle.api.internal.DefaultInstantiatorFactory
import org.gradle.api.internal.InstantiatorFactory
import org.gradle.api.internal.model.DefaultObjectFactory
import org.gradle.api.internal.model.NamedObjectInstantiator
import org.gradle.api.internal.project.ProjectInternal
import org.gradle.api.internal.project.taskfactory.ITaskFactory
import org.gradle.api.model.ObjectFactory
import org.gradle.cache.internal.CrossBuildInMemoryCacheFactory
import org.gradle.groovy.scripts.DefaultScript
import org.gradle.groovy.scripts.Script
import org.gradle.groovy.scripts.ScriptSource
import org.gradle.internal.event.DefaultListenerManager
import org.gradle.test.fixtures.file.TestDirectoryProvider
import org.gradle.testfixtures.ProjectBuilder
import org.gradle.testfixtures.internal.NativeServicesTestFixture
Expand All @@ -43,7 +48,11 @@ class TestUtil {

static InstantiatorFactory instantiatorFactory() {
def generator = new AsmBackedClassGenerator()
return new DefaultInstantiatorFactory(generator)
return new DefaultInstantiatorFactory(generator, new CrossBuildInMemoryCacheFactory(new DefaultListenerManager()))
}

static ObjectFactory objectFactory() {
return new DefaultObjectFactory(instantiatorFactory().decorate(), NamedObjectInstantiator.INSTANCE)
}

static TestUtil create(File rootDir) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,20 @@ class FixedAvailablePortAllocator extends AbstractAvailablePortAllocator {
static final String WORKER_ID_SYS_PROPERTY = "org.gradle.test.worker"
static final String AGENT_NUM_SYS_PROPERTY = "org.gradle.ci.agentNum"
static final String TOTAL_AGENTS_SYS_PROPERTY = "org.gradle.ci.agentCount"
static final int DEFAULT_RANGE_SIZE = 20
static final int DEFAULT_RANGE_SIZE = 50
private static FixedAvailablePortAllocator instance
final int workerId
final int agentNum
final int totalAgents
final int bucketsPerAgent
final int rangeCount
final int rangeCountPerAgent
final int rangeSize

FixedAvailablePortAllocator(int workerId, int agentNum, int totalAgents) {
this.agentNum = agentNum
this.workerId = workerId
this.totalAgents = totalAgents
this.rangeSize = DEFAULT_RANGE_SIZE
this.bucketsPerAgent = (MAX_PRIVATE_PORT - MIN_PRIVATE_PORT) / (rangeSize * totalAgents)
this.rangeCount = bucketsPerAgent * totalAgents
this.rangeCountPerAgent = (MAX_PRIVATE_PORT - MIN_PRIVATE_PORT) / (rangeSize * totalAgents)
}

public static FixedAvailablePortAllocator getInstance() {
Expand All @@ -60,13 +58,12 @@ class FixedAvailablePortAllocator extends AbstractAvailablePortAllocator {
throw new IllegalArgumentException("Agent number was set to ${agentNum} but totalAgents was set to ${totalAgents}.")
}

int fixedRange = 0

int rangeIndex = (agentNum - 1) * rangeCountPerAgent
if (workerId != -1) {
fixedRange = ((workerId - 1) % bucketsPerAgent) + ((agentNum - 1) * bucketsPerAgent)
rangeIndex += (workerId - 1) % rangeCountPerAgent
}

int startPort = MIN_PRIVATE_PORT + (fixedRange * rangeSize)
int startPort = MIN_PRIVATE_PORT + (rangeIndex * rangeSize)
int endPort = startPort + rangeSize - 1
return Pair.of(startPort, endPort)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,9 @@ class ReservedPortRange {
result = 31 * result + endPort
return result
}

@Override
String toString() {
return "ReservedPortRange[" + startPort + ":" + endPort + "]"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -694,11 +694,17 @@ abstract class AbstractWaitAction extends AbstractAsyncAction {
class WaitForAsyncCallback extends AbstractWaitAction {
private boolean callbackCompleted
private Runnable callback
private int waitTimeMillis = 500

WaitForAsyncCallback(ConcurrentTestUtil owner) {
super(owner)
}

WaitForAsyncCallback withWaitTime(int waitTimeMillis) {
this.waitTimeMillis = waitTimeMillis
return this
}

/**
* Runs the given action. Asserts that it blocks until after asynchronous callback is made. The action must register the callback using {@link #callbackLater(Runnable)}.
*/
Expand All @@ -708,7 +714,7 @@ class WaitForAsyncCallback extends AbstractWaitAction {
startBlockingAction(action)
waitForCallbackToBeRegistered()

Thread.sleep(500)
Thread.sleep(waitTimeMillis)

assertBlocked()
runCallbackAction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class Identifier {
private static final String NON_PRECOMPOSED_NON_ASCII = "-√æ∫ʙ₦∆√∫";
private static final String FILESYSTEM_RESERVED_CHARS = "-./\\?%*:|\"<>";
private static final String XML_MARKUP_CHARS = "-<with>some<xml-markup/></with>";
private static final String GRADLE_NAME_FORBIDDEN_CHARACTERS = " /\\:<>\"?*|"; //See: NameValidator.FORBIDDEN_CHARACTERS

private final String suffix;
private final String displayName;
Expand All @@ -44,6 +45,10 @@ public Identifier safeForFileName() {
return without(getUnsupportedFileNameCharacters());
}

public Identifier safeForGradleDomainObjectName() {
return without(GRADLE_NAME_FORBIDDEN_CHARACTERS);
}

public Identifier without(String toRemove) {
String newSuffix = suffix;
for (char c : toRemove.toCharArray()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* A JUnit rule which provides a unique temporary folder for the test.
*/
abstract class AbstractTestDirectoryProvider implements TestRule, TestDirectoryProvider {
protected static TestFile root;
protected TestFile root;

private static final Random RANDOM = new Random();
private static final int ALL_DIGITS_AND_LETTERS_RADIX = 36;
Expand All @@ -60,6 +60,10 @@ public void suppressCleanup() {
cleanup = false;
}

public boolean isCleanup() {
return cleanup;
}

public Statement apply(final Statement base, Description description) {
Class<?> testClass = description.getTestClass();
init(description.getMethodName(), testClass.getSimpleName());
Expand Down
Loading

0 comments on commit ad7a062

Please sign in to comment.