forked from nebula-plugins/gradle-dependency-lock-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It is now possible to update only a subset of the locked dependencies rather than updating them all at once by regenerating the lock file. nebula-plugins#42
- Loading branch information
David Cowden
committed
Feb 21, 2015
1 parent
ca96962
commit 8a8e8be
Showing
6 changed files
with
116 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
version=2.2.1-SNAPSHOT | ||
version=2.3.0-SNAPSHOT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/main/groovy/nebula/plugin/dependencylock/tasks/UpdateLockTask.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package nebula.plugin.dependencylock.tasks | ||
|
||
import groovy.json.JsonSlurper | ||
import org.apache.log4j.spi.LoggerFactory | ||
import org.gradle.api.logging.Logger | ||
import org.gradle.api.logging.Logging | ||
|
||
import java.lang.Override | ||
import org.gradle.api.GradleException | ||
import org.gradle.api.internal.tasks.options.Option | ||
|
||
/** | ||
* The update task is a generate task, it simply reads in the old locked dependencies and then overwrites the desired | ||
* dependencies per user request. | ||
*/ | ||
class UpdateLockTask extends GenerateLockTask { | ||
private static Logger logger = Logging.getLogger(UpdateLockTask) | ||
|
||
String description = 'Apply updates to a preexisting lock file and write to build/<specified name>' | ||
Set<String> dependencies | ||
|
||
@Option(option = "dependencies", description = "Specify which dependencies to update via a comma-separated list") | ||
void setDependencies(String depsFromOption) { | ||
setDependencies(depsFromOption.tokenize(',').toSet()) | ||
} | ||
|
||
void setDependencies(Set<String> dependencyList) { | ||
this.dependencies = dependencyList | ||
} | ||
|
||
@Override | ||
void lock() { | ||
// If the user specifies dependencies to update, ignore any filter specified by the build file and use our | ||
// own generated from the list of dependencies. | ||
def updates = getDependencies() | ||
|
||
if (updates) { | ||
filter = { group, artifact, version -> | ||
updates.contains("${group}:${artifact}".toString()) | ||
} | ||
} | ||
super.lock() | ||
} | ||
|
||
@Override | ||
void writeLock(updatedDeps) { | ||
File currentLock = new File(project.projectDir, dependenciesLock.name) | ||
def lockedDeps = loadLock(currentLock) | ||
super.writeLock(lockedDeps + (updatedDeps as Map)) | ||
} | ||
|
||
private static loadLock(File lock) { | ||
def lockKeyMap = [:].withDefault { [transitive: [] as Set, firstLevelTransitive: [] as Set, childrenVisited: false] } | ||
|
||
try { | ||
def json = new JsonSlurper().parseText(lock.text) | ||
json.each { key, value -> | ||
def (group, artifact) = key.tokenize(':') | ||
lockKeyMap.put(new LockKey(group: group, artifact: artifact), value) | ||
} | ||
} catch (ex) { | ||
logger.debug('Unreadable json file: ' + lock.text) | ||
logger.error('JSON unreadable') | ||
throw new GradleException("${lock.name} is unreadable or invalid json, terminating run", ex) | ||
} | ||
|
||
lockKeyMap | ||
} | ||
} |