All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ullink.ProjectFileParser.groovy Maven / Gradle / Ivy

There is a newer version: 2.22
Show newest version
package com.ullink

import org.apache.commons.io.FilenameUtils
import org.gradle.api.Project
import org.gradle.api.file.FileCollection
import org.gradle.internal.os.OperatingSystem

// http://msdn.microsoft.com/en-us/library/5dy88c2e.aspx
class ProjectFileParser {
    Msbuild msbuild
    Map eval

    Object getProp(String key) {
        return properties[key]
    }

    def getProjectFile() {
        properties.MSBuildProjectFullPath
    }

    def getProjectName() {
        properties.MSBuildProjectName
    }

    def getProperties() {
        eval.Properties
    }

    def getReferences() {
        eval.Reference
    }

    Project getProject() {
        msbuild?.project
    }

    Collection getItems(def section) {
        eval[section].collect {
            findProjectFile(it.Include)
        }
    }

    def renameExtension(def file, def newExtension) {
        FilenameUtils.removeExtension(file) + newExtension
    }

    File getDotnetAssemblyFile() {
        project.file(properties.TargetPath)
    }

    File getDotnetDebugFile() {
        File target = project.file(properties.TargetPath)
        new File(renameExtension(target.path, OperatingSystem.current().windows ? '.pdb' : '.mdb'))
    }

     FileCollection getDotnetArtifacts() {
        project.files({
            def ret = [dotnetAssemblyFile];
            if (dotnetDebugFile?.exists()) ret += dotnetDebugFile;
            File doc = getProjectPropertyPath('DocumentationFile')
            if (doc?.exists()) ret += doc;
            ret
        }) {
            builtBy msbuild
        }
    }

    File findProjectFile(String str) {
        findImportFile(project.file(projectFile).parentFile, str)
    }

    File getProjectPropertyPath(String path) {
        if (getProp(path)) {
            findProjectFile(getProp(path))
        }
    }

    static String ospath(String path) {
        path.replaceAll("\\\\|/", "\\" + System.getProperty("file.separator"))
    }

    static File findImportFile(File baseDir, String s) {
        def path = ospath(s)
        def file = new File(path)
        if (!file.isAbsolute()) {
            file = new File(baseDir, path)
        }
        file.canonicalFile
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy