DepConfig.groovy 2.0 KB
Newer Older
B
Blankj 已提交
1 2 3 4 5 6 7 8
/**
 * <pre>
 *     author: blankj
 *     blog  : http://blankj.com
 *     time  : 2019/07/13
 *     desc  :
 * </pre>
 */
B
Blankj 已提交
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
class DepConfig {
    boolean useLocal // 是否使用本地的
    String localPath // 本地路径
    String remotePath// 远程路径
    boolean isApply  // 是否应用
    String path      // 最后的路径
    def dep          // 根据条件生成项目最终的依赖项

    DepConfig(String path) {
        this(path, true)
    }

    DepConfig(String path, boolean isApply) {
        if (path.startsWith(":")) {
            this.useLocal = true
            this.localPath = path
            this.isApply = isApply
        } else {
            this.useLocal = false
            this.remotePath = path
            this.isApply = isApply
        }
        this.path = path
    }

B
Blankj 已提交
34
    DepConfig(boolean useLocal, String path, boolean isApply) { // 自定义插件的构造函数
B
Blankj 已提交
35
        this(useLocal, "", path, isApply)
B
Blankj 已提交
36 37
    }

B
Blankj 已提交
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
    DepConfig(boolean useLocal, String localPath, String remotePath) {
        this(useLocal, localPath, remotePath, true)
    }

    DepConfig(boolean useLocal, String localPath, String remotePath, boolean isApply) {
        this.useLocal = useLocal
        this.localPath = localPath
        this.remotePath = remotePath
        this.isApply = isApply
        this.path = useLocal ? localPath : remotePath
    }

    String getGroupId() {
        String[] splits = remotePath.split(":")
        return splits.length == 3 ? splits[0] : null
    }

    String getArtifactId() {
        String[] splits = remotePath.split(":")
        return splits.length == 3 ? splits[1] : null
    }

    String getVersion() {
        String[] splits = remotePath.split(":")
        return splits.length == 3 ? splits[2] : null
    }


    @Override
    String toString() {
        return "DepConfig { " +
B
Blankj 已提交
69 70 71
                "useLocal = " + useLocal +
                (dep == null ? ", path = " + path : (", dep = " + dep)) +
                ", isApply = " + isApply +
B
Blankj 已提交
72 73 74
                " }"
    }
}