summaryrefslogtreecommitdiff
path: root/java/gradle/ice.gradle
blob: 1080f20e6b532bc10b761dc52a51459f302eba27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//

buildscript {
    //
    // If iceBuilderHome is set add its lib directory it to the local maven repositories
    // so we can build using a local plugin version
    //
    if (iceBuilderHome) {
        def builder  = new File([iceBuilderHome, "build", "libs"].join(File.separator))
        if(builder.exists()) {
            repositories {
                flatDir dirs: "file://${builder.getCanonicalPath()}"
            }
        }
    }

    if(new File("/usr/share/maven-repo").exists()){
        repositories {
            maven {
                url "file:///usr/share/maven-repo"
            }
        }
    }

    repositories {
        mavenCentral()

        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath group: "${iceBuilderClassPath}", name: 'slice', version: "${iceBuilderVersion}"
    }
}

//
// We do not use the new gradle Plugin DSL because on debian we want to use the plug-in
// from gradle-ice-builder-plugin package and this is not possible when using gradle 3.2
// included in stretch and the Plugin DSL.
//
project.apply(plugin: com.zeroc.gradle.icebuilder.slice.SlicePlugin)

slice {
    cppConfiguration = project.cppConfiguration
    cppPlatform = project.cppPlatform
    if(!System.env.ICE_BIN_DIST?.split(" ").find{ it == 'all' || it.contains('java')}) {
        iceHome =  project.hasProperty('iceHome') ? project.iceHome
            : System.getenv("ICE_HOME") != null ? System.env.ICE_HOME : new File(project.ext.topSrcDir).getCanonicalPath()
    }
}

// Android does not have a compileJava task
if(!(project.hasProperty('android') && project.android.sourceSets)) {
    compileJava {
        exclude 'module-info.java'
        // target Java 8 using the --release option introduced in Java 9
        if(JavaVersion.current() > JavaVersion.VERSION_1_8) {
            options.compilerArgs.addAll(['--release', "${targetJavaRelease}"])
        }
        options.debug = debug
    }

    if(JavaVersion.current() > JavaVersion.VERSION_1_8) {
        task compileModuleInfoJava(type: JavaCompile) {
            classpath = files() // empty
            source = 'src/main/java/module-info.java'
            destinationDir = compileJava.destinationDir // same dir to see classes compiled by compileJava
            doFirst {
                options.compilerArgs = [
                    '--release', '9',
                    '--module-path', compileJava.classpath.asPath,
                    '-Xlint:-module',
                ]
            }
        }

        compileModuleInfoJava.dependsOn compileJava
        classes.dependsOn compileModuleInfoJava
    }
}

// The corresponding -source and -target javac options are suppressed by gradle when
// --release is set through options.compileArgs (see above).
sourceCompatibility = "1.${targetJavaRelease}"
targetCompatibility = "1.${targetJavaRelease}"

// Determine the name of the Slice-to-Java translator
def isWindows = System.properties['os.name'].toLowerCase().contains('windows')

// If the prefix isn't set use these default locations.
if(!prefix) {
    def prefixVersion = iceVersion
    if(prefixVersion.indexOf(".0-alpha")){
        prefixVersion = prefixVersion.replace(".0-alpha", "a")
    } else if(prefixVersion.indexOf(".0-beta")){
        prefixVersion = prefixVersion.replace(".0-beta", "b")
    }
    if(isWindows) {
        prefix = "C:\\Ice-${prefixVersion}"
    } else {
        prefix = "/opt/Ice-${prefixVersion}"
    }
}

// Installation location for jar/pom & executables.
//
// Note that we exclude /usr/src/packages because it's the RPM build directory on SLES.
//
if((prefix.startsWith("/usr") || prefix.startsWith("/usr/local")) && !prefix.startsWith("/usr/src/packages")) {
    ext.jarDir = prefix + "/share/java"
    ext.binDir = prefix + "/bin"
} else {
    ext.jarDir = prefix + "/lib"
    ext.binDir = prefix + "/bin"
}

// Check is DESTDIR is set (non-Windows)
if(isWindows) {
    ext.DESTDIR = ""
}

ext.libDir = "$rootProject.projectDir/lib"

ext.searchFile = { List<Closure> places, List<String> searchPaths ->
    def dirs = []
    places.each {
        def dir = it
        if(dir != null) {
            dirs << dir + "/"
        }
    }

    def candidates = searchPaths.collect {
        def path = it
        dirs.collect {
            it.concat(path)
        }
    }.flatten()

    return candidates.find {
        new File(it).exists()
    }
}

// Used for the tests
//
ext.localDependency = { artifactId ->
    if(project.slice.srcDist || System.env.ICE_BIN_DIST == "cpp") {
        return project(":${artifactId}")
    } else {
        return "com.zeroc:${artifactId}:${project.version}"
    }
}