diff --git a/src/main/groovy/nebula/plugin/dependencylock/DependencyLockTaskConfigurer.groovy b/src/main/groovy/nebula/plugin/dependencylock/DependencyLockTaskConfigurer.groovy index af109944..21fbea65 100644 --- a/src/main/groovy/nebula/plugin/dependencylock/DependencyLockTaskConfigurer.groovy +++ b/src/main/groovy/nebula/plugin/dependencylock/DependencyLockTaskConfigurer.groovy @@ -39,10 +39,6 @@ import static nebula.plugin.dependencylock.tasks.GenerateLockTask.lockableConfig class DependencyLockTaskConfigurer { private static final Logger LOGGER = Logging.getLogger(DependencyLockTaskConfigurer) - private static final String LOCK_FILE = 'dependencyLock.lockFile' - private static final String USE_GENERATED_LOCK = 'dependencyLock.useGeneratedLock' - private static final String USE_GENERATED_GLOBAL_LOCK = 'dependencyLock.useGeneratedGlobalLock' - public static final String OVERRIDE_FILE = 'dependencyLock.overrideFile' public static final String GLOBAL_LOCK_CONFIG = '_global_' @@ -65,21 +61,14 @@ class DependencyLockTaskConfigurer { this.project = project } - String configureTasks(String globalLockFilename, DependencyLockExtension extension, DependencyLockCommitExtension commitExtension, Map overrides) { - String lockFilename = project.hasProperty(LOCK_FILE) ? project[LOCK_FILE] : null - File lockFileInBuildDir = new File(project.buildDir, lockFilename ?: extension.lockFile) - if (project.hasProperty(USE_GENERATED_LOCK)) { - lockFilename = lockFileInBuildDir.path - } - File lockFileInProjectDir = new File(project.projectDir, lockFilename ?: extension.lockFile) - + String configureTasks(String globalLockFilename, String lockFilename, DependencyLockExtension extension, DependencyLockCommitExtension commitExtension, Map overrides) { TaskProvider genLockTask = project.tasks.register(GENERATE_LOCK_TASK_NAME, GenerateLockTask) - configureGenerateLockTask(genLockTask, lockFileInBuildDir, extension, overrides) + configureGenerateLockTask(genLockTask, lockFilename, extension, overrides) TaskProvider updateLockTask = project.tasks.register(UPDATE_LOCK_TASK_NAME, UpdateLockTask) - configureGenerateLockTask(updateLockTask, lockFileInBuildDir, extension, overrides) + configureGenerateLockTask(updateLockTask, lockFilename, extension, overrides) - TaskProvider saveTask = configureSaveTask(lockFileInBuildDir, lockFileInProjectDir, genLockTask, updateLockTask, extension) + TaskProvider saveTask = configureSaveTask(lockFilename, genLockTask, updateLockTask, extension) createDeleteLock(saveTask) configureMigrateToCoreLocksTask(extension) @@ -91,19 +80,13 @@ class DependencyLockTaskConfigurer { TaskProvider globalLockTask TaskProvider globalUpdateLock if (project == project.rootProject) { - if (project.hasProperty(USE_GENERATED_GLOBAL_LOCK)) { - globalLockFilename = lockFileInBuildDir.path - } - File globalLockFileInBuildDir = new File(project.buildDir, globalLockFilename ?: extension.globalLockFile) - File globalLockFileInProjectDir = new File(project.projectDir, globalLockFilename ?: extension.globalLockFile) - globalLockTask = project.tasks.register(GENERATE_GLOBAL_LOCK_TASK_NAME, GenerateLockTask) - configureGlobalLockTask(globalLockTask, globalLockFileInBuildDir, extension, overrides) + configureGlobalLockTask(globalLockTask, globalLockFilename, extension, overrides) globalUpdateLock = project.tasks.register(UPDATE_GLOBAL_LOCK_TASK_NAME, UpdateLockTask) - configureGlobalLockTask(globalUpdateLock, globalLockFileInBuildDir, extension, overrides) + configureGlobalLockTask(globalUpdateLock, globalLockFilename, extension, overrides) - globalSave = configureGlobalSaveTask(globalLockFileInBuildDir, globalLockFileInProjectDir, globalLockTask, globalUpdateLock, extension) + globalSave = configureGlobalSaveTask(globalLockFilename, globalLockTask, globalUpdateLock, extension) createDeleteGlobalLock(globalSave) } @@ -113,6 +96,22 @@ class DependencyLockTaskConfigurer { lockFilename } + private File getProjectDirLockFile(String lockFilename, DependencyLockExtension extension) { + new File(project.projectDir, lockFilename ?: extension.lockFile) + } + + private File getBuildDirLockFile(String lockFilename, DependencyLockExtension extension) { + new File(project.buildDir, lockFilename ?: extension.lockFile) + } + + private File getProjectDirGlobalLockFile(String lockFilename, DependencyLockExtension extension) { + new File(project.projectDir, lockFilename ?: extension.globalLockFile) + } + + private File getBuildDirGlobalLockFile(String lockFilename, DependencyLockExtension extension) { + new File(project.buildDir, lockFilename ?: extension.globalLockFile) + } + private void configureCommitTask(String clLockFileName, String globalLockFileName, TaskProvider saveTask, DependencyLockExtension lockExtension, DependencyLockCommitExtension commitExtension, TaskProvider globalSaveTask = null) { project.plugins.withType(ScmPlugin) { @@ -171,7 +170,7 @@ class DependencyLockTaskConfigurer { } } - private TaskProvider configureSaveTask(File lockfileInBuildDir, File lockfileInProjectDir, TaskProvider lockTask, + private TaskProvider configureSaveTask(String lockFilename, TaskProvider lockTask, TaskProvider updateTask, DependencyLockExtension extension) { TaskProvider saveLockTask = project.tasks.register(SAVE_LOCK_TASK_NAME, SaveLockTask) @@ -183,8 +182,8 @@ class DependencyLockTaskConfigurer { } } saveTask.conventionMapping.with { - generatedLock = { lockfileInBuildDir } - outputLock = { lockfileInProjectDir } + generatedLock = { getBuildDirLockFile(lockFilename, extension) } + outputLock = { getProjectDirLockFile(lockFilename, extension) } } } configureCommonSaveTask(saveLockTask, lockTask, updateTask) @@ -206,7 +205,7 @@ class DependencyLockTaskConfigurer { } } - private TaskProvider configureGlobalSaveTask(File globalLockFileInBuildDir, File globalLockFileInProjectDir, TaskProvider globalLockTask, + private TaskProvider configureGlobalSaveTask(String lockFilename, TaskProvider globalLockTask, TaskProvider globalUpdateLockTask, DependencyLockExtension extension) { TaskProvider globalSaveLockTask = project.tasks.register(SAVE_GLOBAL_LOCK_TASK_NAME, SaveLockTask) @@ -220,8 +219,8 @@ class DependencyLockTaskConfigurer { } } globalSaveTask.conventionMapping.with { - generatedLock = { globalLockFileInBuildDir } - outputLock = { globalLockFileInProjectDir } + generatedLock = { getBuildDirGlobalLockFile(lockFilename, extension) } + outputLock = { getProjectDirGlobalLockFile(lockFilename, extension) } } } configureCommonSaveTask(globalSaveLockTask, globalLockTask, globalUpdateLockTask) @@ -229,11 +228,11 @@ class DependencyLockTaskConfigurer { globalSaveLockTask } - private TaskProvider configureGenerateLockTask(TaskProvider lockTask, File dependenciesLockFile, DependencyLockExtension extension, Map overrides) { + private TaskProvider configureGenerateLockTask(TaskProvider lockTask, String lockFilename, DependencyLockExtension extension, Map overrides) { setupLockConventionMapping(lockTask, extension, overrides) lockTask.configure { it.conventionMapping.with { - dependenciesLock = { dependenciesLockFile } + dependenciesLock = { getBuildDirLockFile(lockFilename, extension) } configurationNames = { extension.configurationNames } skippedConfigurationNames = { extension.skippedConfigurationNamesPrefixes } } @@ -255,7 +254,7 @@ class DependencyLockTaskConfigurer { } } - private TaskProvider configureGlobalLockTask(TaskProvider globalLockTask, File globalLockFileInBuildDir, + private TaskProvider configureGlobalLockTask(TaskProvider globalLockTask, String lockFilename, DependencyLockExtension extension, Map overrides) { setupLockConventionMapping(globalLockTask, extension, overrides) globalLockTask.configure { globalGenerateTask -> @@ -263,7 +262,7 @@ class DependencyLockTaskConfigurer { project.subprojects.each { sub -> sub.repositories.each { repo -> project.repositories.add(repo) } } } globalGenerateTask.conventionMapping.with { - dependenciesLock = { globalLockFileInBuildDir } + dependenciesLock = { getBuildDirGlobalLockFile(lockFilename, extension) } configurations = { def subprojects = project.subprojects.collect { subproject -> def ext = subproject.getExtensions().findByType(DependencyLockExtension) diff --git a/src/main/kotlin/nebula/plugin/dependencylock/DependencyLockPlugin.kt b/src/main/kotlin/nebula/plugin/dependencylock/DependencyLockPlugin.kt index ccc5bcaf..affffde6 100644 --- a/src/main/kotlin/nebula/plugin/dependencylock/DependencyLockPlugin.kt +++ b/src/main/kotlin/nebula/plugin/dependencylock/DependencyLockPlugin.kt @@ -38,6 +38,7 @@ class DependencyLockPlugin : Plugin { const val EXTENSION_NAME = "dependencyLock" const val COMMIT_EXTENSION_NAME = "commitDependencyLock" const val DEPENDENCY_RESOLTION_VERIFIER_EXTENSION = "dependencyResolutionVerifierExtension" + const val LOCK_FILE = "dependencyLock.lockFile" const val GLOBAL_LOCK_FILE = "dependencyLock.globalLockFile" const val LOCK_AFTER_EVALUATING = "dependencyLock.lockAfterEvaluating" const val UPDATE_DEPENDENCIES = "dependencyLock.updateDependencies" @@ -85,7 +86,8 @@ class DependencyLockPlugin : Plugin { } val overrides = lockReader.readOverrides() val globalLockFilename = project.findStringProperty(GLOBAL_LOCK_FILE) - val lockFilename = DependencyLockTaskConfigurer(project).configureTasks(globalLockFilename, extension, commitExtension, overrides) + val lockFilename = project.findStringProperty(LOCK_FILE) + DependencyLockTaskConfigurer(project).configureTasks(globalLockFilename, lockFilename, extension, commitExtension, overrides) if (CoreLocking.isCoreLockingEnabled()) { LOGGER.warn("${project.name}: coreLockingSupport feature enabled") val coreLockingHelper = CoreLockingHelper(project) diff --git a/src/test/groovy/nebula/plugin/dependencylock/DependencyLockLauncherSpec.groovy b/src/test/groovy/nebula/plugin/dependencylock/DependencyLockLauncherSpec.groovy index e9887749..4e9b857f 100644 --- a/src/test/groovy/nebula/plugin/dependencylock/DependencyLockLauncherSpec.groovy +++ b/src/test/groovy/nebula/plugin/dependencylock/DependencyLockLauncherSpec.groovy @@ -315,6 +315,22 @@ class DependencyLockLauncherSpec extends IntegrationSpec { !result.standardOutput.contains('test.example:foo:2.0.0 -> 1.0.0') } + def 'lock file name can be customized'() { + buildFile << BUILD_GRADLE + buildFile << """ + dependencyLock { + lockFile = "custom.lock" + } + """ + + when: + def result = runTasksSuccessfully('generateLock', 'saveLock') + + then: + def dependenciesLock = new File(projectDir, 'custom.lock') + dependenciesLock.exists() + } + def 'override lock file is applied'() { def dependenciesLock = new File(projectDir, 'dependencies.lock') dependenciesLock << OLD_FOO_LOCK @@ -420,78 +436,6 @@ class DependencyLockLauncherSpec extends IntegrationSpec { new File(projectDir, 'build/dependency-lock/lockdiff.txt').text == MY_DIFF } - def 'run with generated lock'() { - def dependenciesLock = new File(projectDir, 'dependencies.lock') - dependenciesLock << OLD_FOO_LOCK - buildFile << BUILD_GRADLE - - when: - runTasksSuccessfully('generateLock') - - then: - new File(projectDir, 'build/dependencies.lock').text == FOO_LOCK - - when: - def result0 = runTasksSuccessfully('dependencies') - - then: - result0.standardOutput.contains 'test.example:foo:1.+ -> 1.0.0' - - when: - def result1 = runTasksSuccessfully('-PdependencyLock.useGeneratedLock=true', 'dependencies') - - then: - result1.standardOutput.contains 'test.example:foo:1.+ -> 1.0.1' - } - - def 'run with generated global lock'() { - def globalLock = new File(projectDir, 'global.lock') - globalLock << OLD_FOO_LOCK - buildFile << BUILD_GRADLE - - when: - runTasksSuccessfully('generateGlobalLock') - - then: - new File(projectDir, 'build/global.lock').text == FOO_LOCK - - when: - def result0 = runTasksSuccessfully('dependencies') - - then: - result0.standardOutput.contains 'test.example:foo:1.+ -> 1.0.0' - - when: - def result1 = runTasksSuccessfully('-PdependencyLock.useGeneratedGlobalLock=true', 'dependencies') - - then: - result1.standardOutput.contains 'test.example:foo:1.+ -> 1.0.1' - } - - def 'generateLock with deprecated format existing causes no issues'() { - def dependenciesLock = new File(projectDir, 'dependencies.lock') - dependenciesLock << DEPRECATED_LOCK_FORMAT - buildFile << BUILD_GRADLE - - when: - runTasksSuccessfully('generateLock') - - then: - new File(projectDir, 'build/dependencies.lock').text == FOO_LOCK - - when: - def result0 = runTasksSuccessfully('dependencies') - - then: - result0.standardOutput.contains 'test.example:foo:1.+ -> 1.0.0' - - when: - def result1 = runTasksSuccessfully('-PdependencyLock.useGeneratedLock=true', 'dependencies') - - then: - result1.standardOutput.contains 'test.example:foo:1.+ -> 1.0.1' - } - def 'generateLock fails if dependency locks are ignored'() { buildFile << BUILD_GRADLE