-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #118 from nebula-plugins/wayback
Add dependency wayback machine
- Loading branch information
Showing
20 changed files
with
834 additions
and
226 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
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
87 changes: 87 additions & 0 deletions
87
src/main/groovy/nebula/plugin/dependencylock/DependencyLockReader.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,87 @@ | ||
package nebula.plugin.dependencylock | ||
|
||
import groovy.json.JsonSlurper | ||
import groovy.transform.TupleConstructor | ||
import org.gradle.api.GradleException | ||
import org.gradle.api.Project | ||
import org.gradle.api.artifacts.Configuration | ||
import org.gradle.api.logging.Logger | ||
import org.gradle.api.logging.Logging | ||
import static nebula.plugin.dependencylock.DependencyLockPlugin.OVERRIDE_FILE | ||
import static nebula.plugin.dependencylock.DependencyLockPlugin.GLOBAL_LOCK_CONFIG | ||
|
||
@TupleConstructor | ||
class DependencyLockReader { | ||
private static final Logger logger = Logging.getLogger(DependencyLockPlugin) | ||
|
||
Project project | ||
|
||
Map readLocks(Configuration conf, File dependenciesLock, Collection<String> updates = []) { | ||
logger.info("Using ${dependenciesLock.name} to lock dependencies in $conf") | ||
if(!dependenciesLock.exists()) | ||
return null | ||
|
||
Map locks = parseLockFile(dependenciesLock) | ||
|
||
if (updates) { | ||
locks = locks.collectEntries { configurationName, deps -> | ||
[(configurationName): deps.findAll { coord, info -> | ||
def notUpdate = !updates.contains(coord) | ||
def notTransitive = info.transitive == null | ||
def hasRequestedVersion = info.requested != null | ||
notUpdate && notTransitive && hasRequestedVersion | ||
}] | ||
} | ||
} | ||
|
||
// in the old format, all first level props were groupId:artifactId | ||
def isDeprecatedFormat = !locks.isEmpty() && locks.every { it.key ==~ /[^:]+:.+/ } | ||
// in the old format, all first level props were groupId:artifactId | ||
if (isDeprecatedFormat) { | ||
logger.warn("${dependenciesLock.name} is using a deprecated lock format. Support for this format may be removed in future versions.") | ||
} | ||
|
||
// In the old format of the lock file, there was only one locked setting. In that case, apply it on all configurations. | ||
// In the new format, apply _global_ to all configurations or use the config name | ||
return isDeprecatedFormat ? locks : locks[GLOBAL_LOCK_CONFIG] ?: locks[conf.name] | ||
} | ||
|
||
Map readOverrides() { | ||
// Overrides are dependencies that trump the lock file. | ||
Map overrides = [:] | ||
|
||
// Load overrides from a file if the user has specified one via a property. | ||
if (project.hasProperty(OVERRIDE_FILE)) { | ||
File dependenciesLock = new File(project.rootDir, project[OVERRIDE_FILE] as String) | ||
def lockOverride = parseLockFile(dependenciesLock) | ||
def isDeprecatedFormat = lockOverride.any { it.value.getClass() != String && it.value.locked } | ||
// the old lock override files specified the version to override under the "locked" property | ||
if (isDeprecatedFormat) { | ||
logger.warn("The override file ${dependenciesLock.name} is using a deprecated format. Support for this format may be removed in future versions.") | ||
} | ||
lockOverride.each { overrides[it.key] = isDeprecatedFormat ? it.value.locked : it.value } | ||
logger.debug "Override file loaded: ${project[OVERRIDE_FILE]}" | ||
} | ||
|
||
// Allow the user to specify overrides via a property as well. | ||
if (project.hasProperty('dependencyLock.override')) { | ||
project['dependencyLock.override'].tokenize(',').each { | ||
def (group, artifact, version) = it.tokenize(':') | ||
overrides["${group}:${artifact}".toString()] = version | ||
logger.debug "Override added for: ${it}" | ||
} | ||
} | ||
|
||
return overrides | ||
} | ||
|
||
private static Map parseLockFile(File lock) { | ||
try { | ||
return new JsonSlurper().parseText(lock.text) as Map | ||
} 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) | ||
} | ||
} | ||
} |
Oops, something went wrong.