~deltahex-team/deltahex/master

« back to all changes in this revision

Viewing changes to modules/deps_processing.gradle

  • Committer: hajdam
  • Date: 2022-01-06 19:37:26 UTC
  • Revision ID: git-v1:97921d93e0e70a2c671187af2443d69dfe46a8e8
Framework refactored

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Downloadable dependencies processing
2
 
 
3
 
buildscript {
4
 
    repositories {
5
 
        maven {
6
 
            url "https://plugins.gradle.org/m2/"
7
 
        }
8
 
    }
9
 
    dependencies {
10
 
        classpath "at.bxm.gradleplugins:gradle-svntools-plugin:2.2"
11
 
        classpath "org.tmatesoft.svnkit:svnkit:1.10.1"
12
 
    }
13
 
}
14
 
 
15
 
import at.bxm.gradleplugins.svntools.tasks.SvnExport
16
 
import at.bxm.gradleplugins.svntools.internal.SvnSupport
17
 
import at.bxm.gradleplugins.svntools.internal.SvnProxy
18
 
import at.bxm.gradleplugins.svntools.SvnToolsPluginExtension
19
 
import org.gradle.api.InvalidUserDataException
20
 
import org.tmatesoft.svn.core.SVNDepth
21
 
import org.tmatesoft.svn.core.SVNException
22
 
import org.tmatesoft.svn.core.SVNURL
23
 
import org.tmatesoft.svn.core.wc.SVNRevision
24
 
 
25
 
def fetchModule(String svnUrl, targetDir, Long revision) {
26
 
    def svnClient = SvnSupport.createSvnClientManager(null, null, new SvnProxy())
27
 
    def rev = SvnSupport.revisionFrom(revision)
28
 
    def repoUrl
29
 
    try {
30
 
      repoUrl = SVNURL.parseURIEncoded(svnUrl)
31
 
    } catch (SVNException e) {
32
 
      throw new InvalidUserDataException("Invalid svnUrl value: $svnUrl", e)
33
 
    }
34
 
    if (!targetDir) {
35
 
      throw new InvalidUserDataException("targetDir must be specified")
36
 
    }
37
 
    def dir = targetDir instanceof File ? targetDir : targetDir.toString() as File
38
 
    if (dir.exists()) {
39
 
      if (!dir.isDirectory()) {
40
 
        throw new InvalidUserDataException("targetDir $dir.absolutePath must be a directory")
41
 
      }
42
 
      if (dir.list()) {
43
 
        throw new InvalidUserDataException("targetDir $dir.absolutePath must be an empty directory")
44
 
      }
45
 
    }
46
 
    try {
47
 
      svnClient.updateClient.doExport(repoUrl, dir, SVNRevision.UNDEFINED, rev, null, true, SVNDepth.INFINITY)
48
 
    } catch (SVNException e) {
49
 
      throw new InvalidUserDataException("svn-export failed for $svnUrl\n" + e.message, e)
50
 
    }
51
 
}
52
 
 
53
 
// - local maven repository module will be used if available
54
 
// - otherwise module will be download to deps directory
55
 
project.dependencies.ext.moduleDep = { depsName, packageName, moduleName ->
56
 
    if (ext.has('depsRoot') && depsName == ext.depsRoot) {
57
 
        return project(':modules:' + moduleName)
58
 
    }
59
 
 
60
 
    def depVersion = ext['deps' + depsName].version
61
 
    def depGithubProfile = ext['deps' + depsName].githubProfile
62
 
    def depGithubRepo = ext['deps' + depsName].githubRepo
63
 
 
64
 
    def mavenModuleDir = repositories.mavenLocal().url.path + packageName.replace('.', '/') + '/' + moduleName + '/' + depVersion
65
 
    if (new File(mavenModuleDir).isDirectory()) {
66
 
        // Use maven package if available
67
 
        return packageName + ':' + moduleName + ':' + depVersion
68
 
    }
69
 
 
70
 
    def depsDir = rootProject.buildDir.parent + '/deps/'
71
 
    if (gradle.startParameter.taskNames == ['clean']) {
72
 
        return project(':deps')
73
 
    }
74
 
 
75
 
    def depModuleDir = depsDir + moduleName
76
 
    if (!new File(depModuleDir).isDirectory()) {
77
 
        // Download module
78
 
        def githubModulePath = 'https://github.com/' + depGithubProfile + '/' + depGithubRepo + '/trunk/modules/' + moduleName
79
 
        println 'Downloading ' + githubModulePath
80
 
 
81
 
        fetchModule(githubModulePath, depModuleDir, null)
82
 
        
83
 
        // Reports new module was downloaded -> need another sweep of dependency resolution
84
 
        if (!new File(depsDir + ".downloaded").exists()) {
85
 
            new File(depsDir + ".downloaded").createNewFile()
86
 
        }
87
 
        return project(':deps')
88
 
    }
89
 
 
90
 
    if (new File(depsDir + ".downloaded").exists()) {
91
 
        return project(':deps')
92
 
    }
93
 
 
94
 
    return project(':deps:' + moduleName)
95
 
}
96
 
 
97
 
project.dependencies.ext.moduleDepPath = { depsName, moduleName ->
98
 
    if (!ext.has('depsRoot') || depsName == ext.depsRoot) {
99
 
        return ":modules:${moduleName}"
100
 
    }
101
 
 
102
 
    return ":deps:${moduleName}"
103
 
}