diff --git a/src/main/groovy/com/ofg/uptodate/UptodatePlugin.groovy b/src/main/groovy/com/ofg/uptodate/UptodatePlugin.groovy index 935e152..e1b18c5 100755 --- a/src/main/groovy/com/ofg/uptodate/UptodatePlugin.groovy +++ b/src/main/groovy/com/ofg/uptodate/UptodatePlugin.groovy @@ -1,6 +1,9 @@ package com.ofg.uptodate -import com.ofg.uptodate.finder.* +import com.ofg.uptodate.finder.Dependency +import com.ofg.uptodate.finder.JCenterNewVersionFinderFactory +import com.ofg.uptodate.finder.MavenNewVersionFinderFactory +import com.ofg.uptodate.finder.NewVersionFinderInAllRepositories import groovy.util.logging.Slf4j import org.gradle.api.Plugin import org.gradle.api.Project @@ -9,9 +12,6 @@ import org.gradle.api.artifacts.Configuration import javax.inject.Inject -import static com.ofg.uptodate.finder.NewVersionFinder.jCenterNewVersionFinder -import static com.ofg.uptodate.finder.NewVersionFinder.mavenNewVersionFinder - @Slf4j class UptodatePlugin implements Plugin { public static final String TASK_NAME = 'uptodate' @@ -35,8 +35,8 @@ class UptodatePlugin implements Plugin { printMissingJCenterRepoIfApplicable(uptodatePluginExtension, project) NewVersionFinderInAllRepositories newVersionFinder = new NewVersionFinderInAllRepositories(loggerProxy, [ - mavenNewVersionFinder(loggerProxy, uptodatePluginExtension), - jCenterNewVersionFinder(loggerProxy, uptodatePluginExtension) + new MavenNewVersionFinderFactory(loggerProxy).build(uptodatePluginExtension), + new JCenterNewVersionFinderFactory(loggerProxy).build(uptodatePluginExtension) ]) List dependencies = getDependencies(project) Set dependenciesWithNewVersions = newVersionFinder.findNewer(dependencies) diff --git a/src/main/groovy/com/ofg/uptodate/finder/FinderConfiguration.groovy b/src/main/groovy/com/ofg/uptodate/finder/FinderConfiguration.groovy index fe4f386..b0e2eeb 100755 --- a/src/main/groovy/com/ofg/uptodate/finder/FinderConfiguration.groovy +++ b/src/main/groovy/com/ofg/uptodate/finder/FinderConfiguration.groovy @@ -1,11 +1,28 @@ package com.ofg.uptodate.finder - +import com.ofg.uptodate.UptodatePluginExtension import groovy.transform.PackageScope @PackageScope class FinderConfiguration { - boolean ignore - HttpConnectionSettings httpConnectionSettings - List excludedVersionPatterns + final boolean ignore + final HttpConnectionSettings httpConnectionSettings + final List excludedVersionPatterns + + FinderConfiguration(RepositorySettings repositorySettings, + UptodatePluginExtension uptodatePluginExtension) { + + ignore = repositorySettings.ignoreRepo + httpConnectionSettings = new HttpConnectionSettings( + url: repositorySettings.repoUrl, + proxySettings: new ProxySettings( + hostname: uptodatePluginExtension.proxyHostname, + port: uptodatePluginExtension.proxyPort, + scheme: uptodatePluginExtension.proxyScheme + ), + poolSize: uptodatePluginExtension.simultaneousHttpConnections, + timeout: uptodatePluginExtension.connectionTimeout + ) + excludedVersionPatterns = uptodatePluginExtension.excludedVersionPatterns + } } diff --git a/src/main/groovy/com/ofg/uptodate/finder/HttpConnectionSettings.groovy b/src/main/groovy/com/ofg/uptodate/finder/HttpConnectionSettings.groovy index c1d9d2e..4e38461 100755 --- a/src/main/groovy/com/ofg/uptodate/finder/HttpConnectionSettings.groovy +++ b/src/main/groovy/com/ofg/uptodate/finder/HttpConnectionSettings.groovy @@ -1,8 +1,10 @@ package com.ofg.uptodate.finder +import groovy.transform.Immutable import groovy.transform.PackageScope @PackageScope +@Immutable class HttpConnectionSettings { String url diff --git a/src/main/groovy/com/ofg/uptodate/finder/JCenterNewVersionFinderFactory.groovy b/src/main/groovy/com/ofg/uptodate/finder/JCenterNewVersionFinderFactory.groovy new file mode 100755 index 0000000..369ff22 --- /dev/null +++ b/src/main/groovy/com/ofg/uptodate/finder/JCenterNewVersionFinderFactory.groovy @@ -0,0 +1,20 @@ +package com.ofg.uptodate.finder + +import com.ofg.uptodate.LoggerProxy +import com.ofg.uptodate.UptodatePluginExtension +import groovy.transform.PackageScope + +@PackageScope +class JCenterNewVersionFinderFactory implements NewVersionFinderFactory { + + final LoggerProxy loggerProxy + + JCenterNewVersionFinderFactory(LoggerProxy loggerProxy) { + this.loggerProxy = loggerProxy + } + + @Override + NewVersionFinder build(UptodatePluginExtension uptodatePluginExtension) { + return new NewVersionFinder(loggerProxy, new JCenterRepositorySettingsProvider(), new JCenterLatestDependenciesProvider(loggerProxy), uptodatePluginExtension); + } +} diff --git a/src/main/groovy/com/ofg/uptodate/finder/MavenNewVersionFinderFactory.groovy b/src/main/groovy/com/ofg/uptodate/finder/MavenNewVersionFinderFactory.groovy new file mode 100755 index 0000000..3cf94d7 --- /dev/null +++ b/src/main/groovy/com/ofg/uptodate/finder/MavenNewVersionFinderFactory.groovy @@ -0,0 +1,20 @@ +package com.ofg.uptodate.finder + +import com.ofg.uptodate.LoggerProxy +import com.ofg.uptodate.UptodatePluginExtension +import groovy.transform.PackageScope + +@PackageScope +class MavenNewVersionFinderFactory implements NewVersionFinderFactory { + + final LoggerProxy loggerProxy + + MavenNewVersionFinderFactory(LoggerProxy loggerProxy) { + this.loggerProxy = loggerProxy + } + + @Override + NewVersionFinder build(UptodatePluginExtension uptodatePluginExtension) { + return new NewVersionFinder(loggerProxy, new MavenRepositorySettingsProvider(), new MavenLatestDependenciesProvider(loggerProxy), uptodatePluginExtension) + } +} diff --git a/src/main/groovy/com/ofg/uptodate/finder/NewVersionFinder.groovy b/src/main/groovy/com/ofg/uptodate/finder/NewVersionFinder.groovy index ee59fc6..cc5c3ae 100755 --- a/src/main/groovy/com/ofg/uptodate/finder/NewVersionFinder.groovy +++ b/src/main/groovy/com/ofg/uptodate/finder/NewVersionFinder.groovy @@ -11,26 +11,12 @@ class NewVersionFinder { private final FinderConfiguration finderConfiguration private final LoggerProxy loggerProxy - private NewVersionFinder(LoggerProxy loggerProxy, - RepositorySettingsProvider repositorySettingsProvider, - LatestDependenciesProvider latestDependenciesProvider, - UptodatePluginExtension uptodatePluginExtension) { + NewVersionFinder(LoggerProxy loggerProxy, + RepositorySettingsProvider repositorySettingsProvider, + LatestDependenciesProvider latestDependenciesProvider, + UptodatePluginExtension uptodatePluginExtension) { - RepositorySettings repositorySettings = repositorySettingsProvider.getFrom(uptodatePluginExtension) - finderConfiguration = new FinderConfiguration( - ignore: repositorySettings.ignoreRepo, - httpConnectionSettings: new HttpConnectionSettings( - url: repositorySettings.repoUrl, - proxySettings: new ProxySettings( - hostname: uptodatePluginExtension.proxyHostname, - port: uptodatePluginExtension.proxyPort, - scheme: uptodatePluginExtension.proxyScheme - ), - poolSize: uptodatePluginExtension.simultaneousHttpConnections, - timeout: uptodatePluginExtension.connectionTimeout - ), - excludedVersionPatterns: uptodatePluginExtension.excludedVersionPatterns - ) + finderConfiguration = new FinderConfiguration(repositorySettingsProvider.getFrom(uptodatePluginExtension), uptodatePluginExtension) this.latestDependenciesProvider = latestDependenciesProvider this.loggerProxy = loggerProxy } @@ -46,12 +32,4 @@ class NewVersionFinder { loggerProxy.debug(log, "Newer dependencies found in $finderConfiguration.httpConnectionSettings.url $newerDependencies") return newerDependencies } - - static NewVersionFinder mavenNewVersionFinder(LoggerProxy loggerProxy, UptodatePluginExtension uptodatePluginExtension) { - return new NewVersionFinder(loggerProxy, new MavenRepositorySettingsProvider(), new MavenLatestDependenciesProvider(loggerProxy), uptodatePluginExtension); - } - - static NewVersionFinder jCenterNewVersionFinder(LoggerProxy loggerProxy, UptodatePluginExtension uptodatePluginExtension) { - return new NewVersionFinder(loggerProxy, new JCenterRepositorySettingsProvider(), new JCenterLatestDependenciesProvider(loggerProxy), uptodatePluginExtension); - } } diff --git a/src/main/groovy/com/ofg/uptodate/finder/NewVersionFinderFactory.groovy b/src/main/groovy/com/ofg/uptodate/finder/NewVersionFinderFactory.groovy new file mode 100755 index 0000000..1cfb2eb --- /dev/null +++ b/src/main/groovy/com/ofg/uptodate/finder/NewVersionFinderFactory.groovy @@ -0,0 +1,8 @@ +package com.ofg.uptodate.finder + +import com.ofg.uptodate.UptodatePluginExtension + +interface NewVersionFinderFactory { + + NewVersionFinder build(UptodatePluginExtension uptodatePluginExtension) +} diff --git a/src/main/groovy/com/ofg/uptodate/finder/ProxySettings.groovy b/src/main/groovy/com/ofg/uptodate/finder/ProxySettings.groovy index 3c16052..d14aec7 100755 --- a/src/main/groovy/com/ofg/uptodate/finder/ProxySettings.groovy +++ b/src/main/groovy/com/ofg/uptodate/finder/ProxySettings.groovy @@ -1,8 +1,10 @@ package com.ofg.uptodate.finder +import groovy.transform.Immutable import groovy.transform.PackageScope @PackageScope +@Immutable class ProxySettings { String hostname diff --git a/src/main/groovy/com/ofg/uptodate/finder/RepositorySettings.groovy b/src/main/groovy/com/ofg/uptodate/finder/RepositorySettings.groovy index 08fa67d..d70d7d8 100755 --- a/src/main/groovy/com/ofg/uptodate/finder/RepositorySettings.groovy +++ b/src/main/groovy/com/ofg/uptodate/finder/RepositorySettings.groovy @@ -1,8 +1,10 @@ package com.ofg.uptodate.finder +import groovy.transform.Immutable import groovy.transform.PackageScope @PackageScope +@Immutable class RepositorySettings { String repoUrl