Skip to content

Commit

Permalink
Core locking: verify offline resolution behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
OdysseusLives committed Nov 12, 2019
1 parent d926292 commit e42a7a3
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class CoreLockingHelper {

boolean migrationTaskWasRequested = project.gradle.startParameter.taskNames.contains(DependencyLockTaskConfigurer.MIGRATE_TO_CORE_LOCKS_TASK_NAME)
boolean hasWriteLocksFlag = project.gradle.startParameter.isWriteDependencyLocks()
boolean projectIsOffline = project.gradle.startParameter.isOffline()
boolean hasDependenciesToUpdate = !project.gradle.startParameter.getLockedDependenciesToUpdate().isEmpty()
boolean isUpdatingDependencies = hasWriteLocksFlag || hasDependenciesToUpdate

Expand Down Expand Up @@ -186,4 +187,10 @@ class CoreLockingHelper {
})
}
}

void notifyWhenUsingOfflineMode() {
if (projectIsOffline) {
LOGGER.lifecycle("${project.name}: offline mode enabled. Using cached dependencies")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class DependencyLockPlugin : Plugin<Project> {
DependencyResolutionVerifier.verifySuccessfulResolution(project)
}
coreLockingHelper.disableCachingWhenUpdatingDependencies()
coreLockingHelper.notifyWhenUsingOfflineMode()

val lockFile = File(project.projectDir, extension.lockFile)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
*
* Copyright 2019 Netflix, Inc.
*
* 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 nebula.plugin.dependencylock.caching

import com.github.tomakehurst.wiremock.client.WireMock
import com.github.tomakehurst.wiremock.stubbing.ServeEvent

class OfflineModeSpec extends AbstractCachingAndCoreLockingSpec {
private static final String OFFLINE_MODE_NOTIFICATION = 'offline mode enabled. Using cached dependencies'

def setup() {
buildFile << """
dependencies {
implementation 'test.offlineMode:z-$uniqueId:latest.release'
}
""".stripIndent()
}

def 'offline mode with core locking uses cached dependencies'() {
given:
setupBaseDependencyAndMockedResponses(uniqueId, "offlineMode")

when:
def result = runTasks('dependencies', '--write-locks', '--configuration', 'compileClasspath')

then:
result.output.contains("test.offlineMode:z-$uniqueId:latest.release -> 1.0.0")
result.output.contains("\\--- test.nebula:a-$uniqueId:1.0.0")
!result.output.contains(OFFLINE_MODE_NOTIFICATION)

def lockFile = new File(projectDir, 'gradle/dependency-locks/compileClasspath.lockfile')
lockFile.exists()

List<ServeEvent> allServeEvents = WireMock.getAllServeEvents()
WireMock.verify(WireMock.exactly(1), WireMock.getRequestedFor(WireMock.urlEqualTo("/${parseGroup('test.offlineMode')}/z-${uniqueId}/maven-metadata.xml")))
WireMock.verify(WireMock.exactly(1), WireMock.getRequestedFor(WireMock.urlEqualTo('/' + filePathFor('test.offlineMode', "z-$uniqueId", '1.0.0', 'pom'))))
WireMock.verify(WireMock.exactly(1), WireMock.getRequestedFor(WireMock.urlEqualTo('/' + filePathFor('test.nebula', "a-$uniqueId", '1.0.0', 'pom'))))
assert allServeEvents.size() == 3

when:
def offlineResults = runTasks('dependencies', '--configuration', 'compileClasspath', '--offline')

then:
offlineResults.output.contains("test.offlineMode:z-$uniqueId:latest.release -> 1.0.0")
offlineResults.output.contains("\\--- test.nebula:a-$uniqueId:1.0.0")
offlineResults.output.contains(OFFLINE_MODE_NOTIFICATION)

List<ServeEvent> allServeEventsUpdated = WireMock.getAllServeEvents()
assert allServeEventsUpdated.size() == 3 // there are no new events because offline mode used the cache
}
}

0 comments on commit e42a7a3

Please sign in to comment.