apply plugin: 'maven'

group = "org.springframework"
jar.baseName = 'springloaded'

sourceCompatibility = 1.6
targetCompatibility = 1.6

task writeNewPom {
  doLast {
     def pompom = pom {
      project  {
        inceptionYear '2013'
        licenses {
          license {
            name 'The Apache Software License, Version 2.0'
        url 'https://www.apache.org/licenses/LICENSE-2.0.txt'
            distribution 'repo'
          }
        }
      }
    };
    // Remove junit and asm jar references
    pompom.whenConfigured { p ->
      p.dependencies.clear()
    }
    pompom.writeTo("$buildDir/springloaded.pom");
  }
 
}

compileJava {
	options.debug = true
}

configurations {
	testCompileOnly
}

task wrapper(type: Wrapper) {
	gradleVersion = '3.4.1'
}

dependencies {
	tools 'com.googlecode.jarjar:jarjar:1.3'

	compile 'org.ow2.asm:asm:5.2'
	compile 'org.ow2.asm:asm-tree:5.2'

	testImplementation 'junit:junit:4.11'
	
	testImplementation files("../testdata-groovy/groovy-all-1.8.6.jar")
	testImplementation(project(':testdata'))
	testImplementation(project(':testdata-aspectj')) 
	testImplementation(project(':testdata-groovy')) 
	// testImplementation(project(':testdata-java8'))
	testImplementation(project(':testdata-plugin'))
	testImplementation(project(':testdata-subloader'))
	testImplementation(project(':testdata-superloader'))
}

sourceSets {  
    test {  
        compileClasspath += configurations.testCompileOnly  
    }  
}  

test {
	jvmArgs "-noverify"
	ignoreFailures true
	systemProperties["springloaded.tests.useGradleBuildDir"] = true
	systemProperties["springloaded.tests.generatedTests"] = System.getProperty("generatedTests", "false")
}

// org.springsource.loaded-VERSION.jar
jar {
    from 'LICENSES/LICENSE'
    baseName = 'org.springsource.loaded'
}

// org.springsource.loaded-VERSION-sources.jar
task sourcesJar(type: Jar, dependsOn:classes) {     
    baseName = 'org.springsource.loaded'
	classifier = 'sources'     
	from sourceSets.main.allSource 
}

task agentSourcesJar(type: Jar, dependsOn:classes) {
    baseName = 'springloaded'
    classifier = 'sources'
    from sourceSets.main.allSource
}

//task agentjar(type: Jar, dependsOn: [jar,writeNewPom]) {
task agentjar(type: Jar, dependsOn: jar) {
    manifest {
        from('src/main/java/META-INF/MANIFEST.MF') {
            eachEntry { details ->
		        if (details.key == 'Specification-Version' ||
                    details.key == 'Implementation-Version') {
                    details.value = version;
                }
            }
        }
    }

    inputs.files jar.archivePath
    baseName = 'springloaded'
	
    doLast {
        project.ant {
            taskdef name: "jarjar", classname: "com.tonicsystems.jarjar.JarJarTask", classpath: configurations.tools.asPath
            jarjar(jarfile: archivePath, manifest: "$temporaryDir/MANIFEST.MF") {
                zipfileset(src: jar.archivePath)
                configurations.compile.files.each { jarjarFile ->
                    zipfileset(src: jarjarFile)
                }
                rule pattern: "org.objectweb.asm.**", result: "sl.org.objectweb.asm.@1"
            }
        }
    }
}

task javadocJar(type: Jar) {
    classifier="javadoc"
    from javadoc
}

// add the jars as artifacts
artifacts {      
	archives sourcesJar      
	archives agentjar
	archives javadocJar
	archives agentSourcesJar      
}

configurations.archives.artifacts.removeAll(
  configurations.archives.allArtifacts.findAll { it.file.toString().indexOf("org.springsource.loaded")!=-1}
)
