Fixed publishing debug symbols artifact
Fixed publishing debug symbols artifact

package au.org.trogdor.xamarin.plugins

import au.org.trogdor.xamarin.lib.XamarinProject
import org.gradle.api.Project
import org.gradle.api.Plugin
import org.gradle.api.publish.maven.MavenPublication

class XamarinPublishPlugin implements Plugin<Project> {
	void apply(Project project) {
        project.extensions.create("xamarinPublish", XamarinPublishExtension, project)
    }
}

class XamarinPublishExtension {
    final def Project project
    private def String mArtifactId
    private def String mRepository

    XamarinPublishExtension(Project project) {
        this.project = project
    }

    void artifactId(String artifactId) {
        mArtifactId = artifactId
    }

    String getArtifactId() {
        mArtifactId
    }

    void repository(String repo) {
        mRepository = repo
    }

    String getRepository() {
        mRepository
    }

    void mavenTask(String configuration) {

        project.configure(project) {
            XamarinProject xamarinProject = project.xamarin.xamarinProject
            def configurations = xamarinProject.configurationContainer
            def resolvedArtifactId = project.xamarinPublish.artifactId ?: xamarinProject.projectName
            def buildOutput = configurations.getByName(configuration).buildOutput

            apply plugin: 'maven-publish'

            def debugSymbolsPath = configurations.getByName(configuration).buildOutput + ".mdb"
            def debugFile = project.file(debugSymbolsPath)
            if (debugFile.exists()) {
                project.publishing {
                    publications {
                        xamarinComponent(MavenPublication) {
                            artifactId resolvedArtifactId
                            artifact(buildOutput) {
                                extension "dll"
                            }
                            artifact(debugSymbolsPath) {
                                classifier "debug-symbols"
                                extension "dll.mdb"
                            }
                        }
                    }
                }
            } else {
                project.publishing {
                    publications {
                        xamarinComponent(MavenPublication) {
                            artifactId resolvedArtifactId
                            artifact(buildOutput) {
                                extension "dll"
                            }
                        }
                    }
                }
            }

        }
        /*
        def taskName = configuration.replaceAll(~/\|/, "")
        def buildTaskName = "xamarinBuild-$taskName"
        def buildTask = project.tasks.findByName(buildTaskName)

        project.tasks.findByName('publishToMavenLocal').mustRunAfter(buildTask)
        project.tasks.findByName('publish').mustRunAfter(buildTask)
        project.task('xamarinPublishMavenLocal', description: "Publish the Xamarin component using configuration $configuration to the local Maven repository", group: 'Xamarin', dependsOn: [buildTaskName, 'publishToMavenLocal'])
        project.task('xamarinPublishMaven', description: "Publish the Xamarin component using configuration $configuration to Maven", group: 'Xamarin', dependsOn: [buildTaskName, 'publish'])
        */
    }
}

package au.org.trogdor.xamarin.plugins

import au.org.trogdor.xamarin.lib.XamarinProject
import org.gradle.api.Project
import org.gradle.api.Plugin
import org.gradle.api.publish.maven.MavenPublication

class XamarinPublishPlugin implements Plugin<Project> {
	void apply(Project project) {
        project.extensions.create("xamarinPublish", XamarinPublishExtension, project)
    }
}

class XamarinPublishExtension {
    final def Project project
    private def String mArtifactId
    private def String mRepository

    XamarinPublishExtension(Project project) {
        this.project = project
    }

    void artifactId(String artifactId) {
        mArtifactId = artifactId
    }

    String getArtifactId() {
        mArtifactId
    }

    void repository(String repo) {
        mRepository = repo
    }

    String getRepository() {
        mRepository
    }

    void mavenTask(String configuration) {

        project.configure(project) {
            XamarinProject xamarinProject = project.xamarin.xamarinProject
            def configurations = xamarinProject.configurationContainer
            def resolvedArtifactId = project.xamarinPublish.artifactId ?: xamarinProject.projectName
            def buildOutput = configurations.getByName(configuration).buildOutput

            apply plugin: 'maven-publish'

            project.publishing {
                publications {
                    xamarinComponent(MavenPublication) {
                        artifactId resolvedArtifactId
                        artifact(buildOutput) {
                            extension "dll"
                        }
                    }
                }
            }

            def debugSymbolsPath = configurations.getByName(configuration).buildOutput + ".mdb"
            def debugFile = project.file(debugSymbolsPath)
            if (debugFile.exists()) {
                project.publishing {
                    publications {
                        xamarinComponentDebugSymbols(MavenPublication) {
                            artifactId resolvedArtifactId
                            artifact(debugSymbolsPath) {
                                classifier "debug-symbols"
                                extension "dll.mdb"
                            }
                        }
                    }
                }
            }

        }
        /*
        def taskName = configuration.replaceAll(~/\|/, "")
        def buildTaskName = "xamarinBuild-$taskName"
        def buildTask = project.tasks.findByName(buildTaskName)

        project.tasks.findByName('publishToMavenLocal').mustRunAfter(buildTask)
        project.tasks.findByName('publish').mustRunAfter(buildTask)
        project.task('xamarinPublishMavenLocal', description: "Publish the Xamarin component using configuration $configuration to the local Maven repository", group: 'Xamarin', dependsOn: [buildTaskName, 'publishToMavenLocal'])
        project.task('xamarinPublishMaven', description: "Publish the Xamarin component using configuration $configuration to Maven", group: 'Xamarin', dependsOn: [buildTaskName, 'publish'])
        */
    }
}
