From 6f44d1fd381c75b9948931ed23e2302f000c121f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Schalk=20W=2E=20Cronj=C3=A9?= Date: Wed, 23 Mar 2016 17:52:58 +0000 Subject: [PATCH] FIXED #11. Configurable patterns for target repository --- CHANGELOG.adoc | 4 ++ README.adoc | 14 +++++++ build.gradle | 6 +-- ...fflineRepositorySyncIntegrationSpec.groovy | 37 +++++++++++++++++++ .../ivypot/OfflineRepositorySync.groovy | 24 +++++++----- 5 files changed, 72 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index f8d74cb..168be8e 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -4,6 +4,10 @@ * https://github.com/ysb33r/ivypot-gradle-plugin/issues/2[Issue #2] - Add support for `repositories.flatDir`. +== 0.3.7 + +* https://github.com/ysb33r/ivypot-gradle-plugin/issues/10[Issue #11] - Patterns for writing artifacts is now configurable. + == 0.3.6 * https://github.com/ysb33r/ivypot-gradle-plugin/issues/10[Issue #10] - Fixes issues that was suppose to be fixed by https://github.com/ysb33r/ivypot-gradle-plugin/issues/8[Issue #9]. diff --git a/README.adoc b/README.adoc index 6e54582..d9addd7 100644 --- a/README.adoc +++ b/README.adoc @@ -136,6 +136,20 @@ buildscript { By default buildscript dependencies will not be added to the synchronisation list. By setting `includeBuildScriptDependencies = true` in the configuration closure of the task these will be added. +== Patterns + +By default the pattern used for writing artifacts is the standard +https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/repositories/IvyArtifactRepository.html[Ivy Pattern]. +This can be changed by setting + +[source,groovy] +---- +syncRemoteRepositories { + repoArtifactPattern = '[organisation]/[module]/[revision]/[type]s/[artifact]-[revision](.[ext])' + repoIvyPattern = '[organisation]/[module]/[revision]/[type]s/[artifact]-[revision](.[ext])' +} +---- + == Limitations The resolution process cannot be fine-tuned at present - not to the level at least which is described in http://gradle.org/docs/current//userguide/dependency_management.html#sec:ivy_repositories. \ No newline at end of file diff --git a/build.gradle b/build.gradle index 3c1710c..49f30db 100644 --- a/build.gradle +++ b/build.gradle @@ -37,7 +37,7 @@ apply plugin : 'org.ysb33r.gradletest' apply from: 'gradle/integration-tests.gradle' -version = '0.3.7-SNAPSHOT' +version = '0.3.7' group = 'org.ysb33r.gradle' sourceCompatibility = 1.6 targetCompatibility = 1.6 @@ -122,11 +122,9 @@ gradleTest { versions '2.2' versions '2.3' versions '2.4' - versions '2.7' versions '2.8' - versions '2.9' versions '2.10' - versions '2.11' + versions '2.12' inputs.files jar inputs.dir file('gradleTest') diff --git a/src/integrationTest/groovy/org/ysb33r/gradle/ivypot/OfflineRepositorySyncIntegrationSpec.groovy b/src/integrationTest/groovy/org/ysb33r/gradle/ivypot/OfflineRepositorySyncIntegrationSpec.groovy index df3be7b..143a529 100644 --- a/src/integrationTest/groovy/org/ysb33r/gradle/ivypot/OfflineRepositorySyncIntegrationSpec.groovy +++ b/src/integrationTest/groovy/org/ysb33r/gradle/ivypot/OfflineRepositorySyncIntegrationSpec.groovy @@ -97,6 +97,42 @@ class OfflineRepositorySyncIntegrationSpec extends Specification { new File(LOCALREPO, 'commons-io/commons-io/2.4/jars/commons-io.jar').exists() } + @IgnoreIf({ OFFLINE }) + def "Can we sync from mavenCentral using a different local artifactPattern?"() { + + given: + def pathToLocalRepo = LOCALREPO + + project.allprojects { + + configurations { + compile + } + + dependencies { + compile 'commons-io:commons-io:2.4' + } + + syncRemoteRepositories { + repositories { + mavenCentral() + } + + repoRoot "${pathToLocalRepo}" + + repoArtifactPattern = '[organisation]/[module]/[revision]/[type]s/[artifact]-[revision](.[ext])' + } + } + + project.evaluate() + project.tasks.syncRemoteRepositories.execute() + + expect: + LOCALREPO.exists() + new File(LOCALREPO, 'commons-io/commons-io/2.4/ivys/ivy.xml').exists() + new File(LOCALREPO, 'commons-io/commons-io/2.4/jars/commons-io-2.4.jar').exists() + } + @IgnoreIf({ OFFLINE }) def "Two syncs to same folder should not cause an overwrite exceptions"() { @@ -132,6 +168,7 @@ class OfflineRepositorySyncIntegrationSpec extends Specification { new File(LOCALREPO, 'commons-io/commons-io/2.4/jars/commons-io.jar').exists() } + @IgnoreIf({ OFFLINE }) def "Seting includeBuildScriptDependencies means that buildscript configuration will be added"() { diff --git a/src/main/groovy/org/ysb33r/gradle/ivypot/OfflineRepositorySync.groovy b/src/main/groovy/org/ysb33r/gradle/ivypot/OfflineRepositorySync.groovy index 197878b..3ee5c51 100644 --- a/src/main/groovy/org/ysb33r/gradle/ivypot/OfflineRepositorySync.groovy +++ b/src/main/groovy/org/ysb33r/gradle/ivypot/OfflineRepositorySync.groovy @@ -17,16 +17,12 @@ package org.ysb33r.gradle.ivypot import groovy.transform.CompileDynamic import groovy.transform.CompileStatic import groovy.transform.PackageScope -import org.apache.ivy.Ivy -import org.apache.ivy.core.module.descriptor.ModuleDescriptor import org.gradle.api.DefaultTask import org.gradle.api.GradleException import org.gradle.api.Project -import org.gradle.api.Task import org.gradle.api.artifacts.Configuration import org.gradle.api.artifacts.ConfigurationContainer import org.gradle.api.artifacts.Dependency -import groovy.xml.NamespaceBuilder import org.gradle.api.artifacts.dsl.RepositoryHandler import org.gradle.api.artifacts.repositories.IvyArtifactRepository import org.gradle.api.internal.artifacts.dsl.DefaultRepositoryHandler @@ -44,8 +40,6 @@ import org.ysb33r.gradle.ivypot.internal.BaseRepositoryFactory class OfflineRepositorySync extends DefaultTask { - static final String ARTIFACT_PATTERN = IvyArtifactRepository.IVY_ARTIFACT_PATTERN - static final String IVY_PATTERN = IvyArtifactRepository.IVY_ARTIFACT_PATTERN private static final String LOCALREPONAME = '~~~local~~~repo~~~' private static final String REMOTECHAINNAME = '~~~remote~~~resolvers~~~' @@ -65,6 +59,18 @@ class OfflineRepositorySync extends DefaultTask { repositories = createRepositoryHandler(project.gradle) } + /** The pattern that will be used to write artifacts into the target repository + * + */ + @Input + String repoArtifactPattern = IvyArtifactRepository.IVY_ARTIFACT_PATTERN + + /** The pattern that will be used to write Ivy metafiles into the target repository + * + */ + @Input + String repoIvyPattern = IvyArtifactRepository.IVY_ARTIFACT_PATTERN + @Input boolean includeBuildScriptDependencies = false @@ -168,7 +174,7 @@ class OfflineRepositorySync extends DefaultTask { * @return Artifact pattern or null in case repoRoot has not been set. */ String getArtifactPattern() { - repoRoot ? "${repoRoot}/${ARTIFACT_PATTERN}" : null + repoRoot ? "${repoRoot}/${repoArtifactPattern}" : null } @TaskAction @@ -227,7 +233,7 @@ class OfflineRepositorySync extends DefaultTask { File cacheDir = project.gradle.startParameter.projectCacheDir ?: new File(project.buildDir,'tmp') String xml= "" - xml+= "" this.repositories.each { @@ -240,7 +246,7 @@ class OfflineRepositorySync extends DefaultTask { // xml+=""" // -// +// // // """