apply plugin: 'base'

allprojects {
    version = '3.1.0.CI-SNAPSHOT'
    releaseBuild = version.endsWith('RELEASE')
    snapshotBuild = version.endsWith('SNAPSHOT')

    group = 'org.springframework.security'

    repositories {
        mavenRepo name:'Local', urls: "file://" + System.properties['user.home'] + "/.m2/repository"
        mavenCentral()
        mavenRepo name: 'SpringSource Milestone Repo', urls: 'http://repository.springsource.com/maven/bundles/milestone'
        mavenRepo name: 'SpringSource Maven Snapshot Repo', urls: 'http://maven.springframework.org/snapshot/'
        mavenRepo name: 'SpringSource Enterprise Release', urls: 'http://repository.springsource.com/maven/bundles/release'
        mavenRepo name: 'SpringSource Enterprise External', urls: 'http://repository.springsource.com/maven/bundles/external'
//        mavenRepo(name: 'Spock Snapshots', urls: 'http://m2repo.spockframework.org/snapshots')
    }
}

// Set up different subproject lists for individual configuration
javaProjects = subprojects.findAll { project -> project.name != 'docs' && project.name != 'faq' && project.name != 'manual' }
sampleProjects = subprojects.findAll { project -> project.name.startsWith('spring-security-samples') }
itestProjects = subprojects.findAll { project -> project.name.startsWith('itest') }
coreModuleProjects = javaProjects - sampleProjects - itestProjects
aspectjProjects = [project(':spring-security-aspects'), project(':spring-security-samples-aspectj')]

configure(javaProjects) {
    apply from: "$rootDir/gradle/javaprojects.gradle"
}

configure(coreModuleProjects) {
    apply from: "$rootDir/gradle/bundlor.gradle"
    apply from: "$rootDir/gradle/maven-deployment.gradle"
    apply from: "$rootDir/gradle/emma.gradle"
    // Gives better names in structure101 jar diagram
    sourceSets.main.classesDir = new File(buildDir, "classes/" + project.name.substring("spring-security".length() + 1))
}

task coreBuild {
    dependsOn coreModuleProjects*.tasks*.matching { task -> task.name == 'build' }
}

configure (aspectjProjects) {
    apply from: "$rootDir/gradle/aspectj.gradle"
}

apply from: "$rootDir/gradle/dist.gradle"

apply plugin: 'idea'

configure(javaProjects) {
    apply plugin: 'idea'
    apply plugin: 'eclipse'

    ideaModule {
        downloadJavadoc=false
        excludeDirs.add(buildDir)
        gradleCacheVariable = 'GRADLE_CACHE'
        outputDir = "$rootProject.projectDir/intellij/out" as File
        testOutputDir = "$rootProject.projectDir/intellij/testOut" as File
        whenConfigured { module ->
            def allClasses = module.dependencies.findAll() { dep ->
                if (dep instanceof org.gradle.plugins.idea.model.ModuleLibrary
                    && dep.classes.find { path ->
                        path.url.matches('.*jcl-over-slf4j.*') ||
                        path.url.matches('.*servlet-api.*') ||
                        path.url.matches('.*jsp-api.*')
                    }) {
                    dep.scope = 'COMPILE'
                    dep.exported = false
                }
            }
        }
    }
}

ideaModule {
    excludeDirs += file('.gradle')
    excludeDirs += file('buildSrc/build')
    excludeDirs += file('buildSrc/.gradle')
}

ideaProject {
    javaVersion = '1.6'
    subprojects = [rootProject] + javaProjects
    withXml { node ->
        // Use git
        def vcsConfig = node.component.find { it.'@name' == 'VcsDirectoryMappings' }
        vcsConfig.mapping[0].'@vcs' = 'Git'
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '0.9-rc-1'
    jarPath = 'gradle/wrapper'
}
