Skip to content
This repository has been archived by the owner on Apr 24, 2020. It is now read-only.

Commit

Permalink
FIXED #11. Configurable patterns for target repository
Browse files Browse the repository at this point in the history
  • Loading branch information
ysb33r committed Mar 23, 2016
1 parent 4417031 commit 6f44d1f
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand Down
14 changes: 14 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
6 changes: 2 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"() {

Expand Down Expand Up @@ -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"() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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~~~'

Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -227,7 +233,7 @@ class OfflineRepositorySync extends DefaultTask {
File cacheDir = project.gradle.startParameter.projectCacheDir ?: new File(project.buildDir,'tmp')
String xml= "<ivysettings><settings defaultResolver='${REMOTECHAINNAME}'/>"

xml+= "<caches defaultCacheDir='${repoRoot}' artifactPattern='${ARTIFACT_PATTERN}' ivyPattern='${IVY_PATTERN}' " +
xml+= "<caches defaultCacheDir='${repoRoot}' artifactPattern='${repoArtifactPattern}' ivyPattern='${repoIvyPattern}' " +
"resolutionCacheDir='${cacheDir}/ivypot/${FileUtils.toSafeFileName(name)}'/>"

this.repositories.each {
Expand All @@ -240,7 +246,7 @@ class OfflineRepositorySync extends DefaultTask {

// xml+="""<resolvers>
// <filesystem name="${LOCALREPONAME}">
// <ivy pattern="${repoRoot}/${IVY_PATTERN}"/>
// <ivy pattern="${repoRoot}/${repoIvyPattern}"/>
// <artifact pattern="${artifactPattern}"/>
// </filesystem><chain name="${REMOTECHAINNAME}" returnFirst="true">"""

Expand Down

0 comments on commit 6f44d1f

Please sign in to comment.