This repository has been archived by the owner on Feb 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#21] Introduced some abstractions and did some refactoring in the at…
…tempt to reduce code duplication
- Loading branch information
Catalin Buleandra
committed
Feb 28, 2015
1 parent
4f9038d
commit df7b739
Showing
16 changed files
with
334 additions
and
217 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
11 changes: 11 additions & 0 deletions
11
src/main/groovy/com/ofg/uptodate/finder/FinderConfiguration.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,11 @@ | ||
package com.ofg.uptodate.finder | ||
|
||
import groovy.transform.PackageScope | ||
|
||
@PackageScope | ||
class FinderConfiguration { | ||
|
||
boolean ignore | ||
HttpConnectionSettings httpConnectionSettings | ||
List<String> excludedVersionPatterns | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/groovy/com/ofg/uptodate/finder/HTTPBuilderProvider.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,37 @@ | ||
package com.ofg.uptodate.finder | ||
|
||
import groovyx.net.http.AsyncHTTPBuilder | ||
import groovyx.net.http.HTTPBuilder | ||
|
||
class HTTPBuilderProvider { | ||
|
||
private final HttpConnectionSettings httpConnectionSettings | ||
private int poolSize | ||
|
||
HTTPBuilderProvider(HttpConnectionSettings httpConnectionSettings) { | ||
this.httpConnectionSettings = httpConnectionSettings | ||
} | ||
|
||
HTTPBuilderProvider withPoolSize(int poolSize) { | ||
this.poolSize = poolSize | ||
return this | ||
} | ||
|
||
HTTPBuilder get() { | ||
HTTPBuilder httpBuilder = new AsyncHTTPBuilder( | ||
uri: httpConnectionSettings.url, | ||
timeout: httpConnectionSettings.timeout, | ||
poolSize: poolSize | ||
) | ||
return configureProxySettingsIfApplicable(httpBuilder) | ||
} | ||
|
||
private HTTPBuilder configureProxySettingsIfApplicable(HTTPBuilder httpBuilder) { | ||
httpConnectionSettings.proxySettings.with { | ||
if (hostname) { | ||
httpBuilder.setProxy(hostname, port, scheme) | ||
} | ||
} | ||
return httpBuilder | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/groovy/com/ofg/uptodate/finder/HttpConnectionSettings.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,12 @@ | ||
package com.ofg.uptodate.finder | ||
|
||
import groovy.transform.PackageScope | ||
|
||
@PackageScope | ||
class HttpConnectionSettings { | ||
|
||
String url | ||
ProxySettings proxySettings | ||
int poolSize | ||
int timeout | ||
} |
69 changes: 69 additions & 0 deletions
69
src/main/groovy/com/ofg/uptodate/finder/JCenterLatestDependenciesProvider.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 com.ofg.uptodate.finder | ||
import com.ofg.uptodate.LoggerProxy | ||
import groovy.transform.PackageScope | ||
import groovy.util.logging.Slf4j | ||
import groovy.util.slurpersupport.NodeChild | ||
import groovyx.net.http.HTTPBuilder | ||
|
||
import java.util.concurrent.Future | ||
|
||
@Slf4j | ||
@PackageScope | ||
class JCenterLatestDependenciesProvider implements LatestDependenciesProvider { | ||
|
||
private final LoggerProxy loggerProxy | ||
|
||
JCenterLatestDependenciesProvider(LoggerProxy loggerProxy) { | ||
this.loggerProxy = loggerProxy | ||
} | ||
|
||
@Override | ||
List<Dependency> findLatest(List<Dependency> dependencies, FinderConfiguration finderConfiguration) { | ||
int httpPoolSize = Math.min(dependencies.size(), finderConfiguration.httpConnectionSettings.poolSize) | ||
HTTPBuilder httpBuilder = new HTTPBuilderProvider(finderConfiguration.httpConnectionSettings).withPoolSize(httpPoolSize).get() | ||
Closure latestFromJCenterGetter = getLatestFromJCenterRepo.curry(httpBuilder, finderConfiguration.excludedVersionPatterns) | ||
return dependencies.collect(latestFromJCenterGetter).collect{it.get()}.grep(getOnlyNewer).collect {it[1]} | ||
} | ||
|
||
public Closure<Future> getLatestFromJCenterRepo = {HTTPBuilder httpBuilder, List<String> versionToExcludePatterns, Dependency dependency -> | ||
appendFailureHandling(httpBuilder, dependency.name) | ||
httpBuilder.get(path: "/${dependency.group.split('\\.').join('/')}/${dependency.name}/maven-metadata.xml") { resp, xml -> | ||
if(!xml) { | ||
return [] | ||
} | ||
def releaseVersionNode = xml.versioning.release | ||
String releaseVersion = releaseVersionNode.text() | ||
DependencyVersion getFirstNonExcludedVersion = getLatestDependencyVersion(releaseVersion, xml, versionToExcludePatterns) | ||
return [dependency, new Dependency(dependency, getFirstNonExcludedVersion)] | ||
} as Future | ||
} | ||
|
||
private void appendFailureHandling(HTTPBuilder httpBuilder, String dependencyName) { | ||
httpBuilder.handler.failure = { resp -> | ||
loggerProxy.debug(log, "Error with status [$resp.status] occurred while trying to download dependency [$dependencyName]") | ||
return [] | ||
} | ||
} | ||
|
||
private DependencyVersion getLatestDependencyVersion(String releaseVersion, NodeChild xml, List<String> versionToExcludePatterns) { | ||
if (versionNotMatchesExcludes(versionToExcludePatterns, releaseVersion)) { | ||
return new DependencyVersion(releaseVersion) | ||
} | ||
return xml.versioning.versions.version.findAll { NodeChild version -> | ||
versionNotMatchesExcludes(versionToExcludePatterns, version.text()) | ||
}.collect { | ||
NodeChild version -> new DependencyVersion(version.text()) | ||
}.max() | ||
|
||
} | ||
|
||
private boolean versionNotMatchesExcludes(List<String> versionToExcludePatterns, String version) { | ||
return versionToExcludePatterns.every { | ||
!version.matches(it) | ||
} | ||
} | ||
|
||
private final Closure<Boolean> getOnlyNewer = { List<Dependency> dependenciesToCompare -> | ||
!dependenciesToCompare.empty && dependenciesToCompare[1].version != null && dependenciesToCompare[1].version > dependenciesToCompare[0].version | ||
} | ||
} |
105 changes: 0 additions & 105 deletions
105
src/main/groovy/com/ofg/uptodate/finder/JCenterNewVersionFinder.groovy
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
src/main/groovy/com/ofg/uptodate/finder/JCenterRepositorySettingsProvider.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,17 @@ | ||
package com.ofg.uptodate.finder | ||
import com.ofg.uptodate.UptodatePluginExtension | ||
import groovy.transform.PackageScope | ||
|
||
@PackageScope | ||
class JCenterRepositorySettingsProvider implements RepositorySettingsProvider { | ||
|
||
public static final String JCENTER_REPO_URL = "http://jcenter.bintray.com/" | ||
|
||
@Override | ||
RepositorySettings getFrom(UptodatePluginExtension uptodatePluginExtension) { | ||
return new RepositorySettings( | ||
repoUrl: uptodatePluginExtension.jCenterRepo, | ||
ignoreRepo: uptodatePluginExtension.ignoreJCenter | ||
) | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/groovy/com/ofg/uptodate/finder/LatestDependenciesProvider.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,6 @@ | ||
package com.ofg.uptodate.finder | ||
|
||
interface LatestDependenciesProvider { | ||
|
||
List<Dependency> findLatest(List<Dependency> dependencies, FinderConfiguration finderConfiguration) | ||
} |
Oops, something went wrong.