make install depend on jar task
make install depend on jar task

package com.github.dynamicextensionsalfresco.gradle

import com.github.dynamicextensionsalfresco.gradle.configuration.BaseConfig
import com.github.dynamicextensionsalfresco.gradle.tasks.InstallBundle
import org.gradle.api.Plugin
import org.gradle.api.Project

/**
 * Gradle plugin that configures build settings for an Alfresco Dynamic Extension.
 * 
 * @author Laurens Fridael
 * @author Laurent Van der Linden
 */
class DynamicExtensionPlugin implements Plugin<Project> {

	@Override
	void apply(Project project) {
		configurePlugins(project)
		configureExtensions(project)
		configureTasks(project)
		project.afterEvaluate {
			configureDependencies(project)
			configureRepositories(project)
			configureJarManifest(project)
		}
	}

    static void configurePlugins(Project project) {
		project.apply plugin: "java"
		project.apply plugin: "osgi"
	}

    static void configureExtensions(Project project) {
		project.extensions.create("alfrescoDynamicExtensions", BaseConfig.class, project)
	}

    static void configureTasks(Project project) {
		project.tasks.create("installBundle", InstallBundle.class).dependsOn('jar')
	}

	void configureDependencies(Project project) {
		def alfresco = [
			version: project.alfrescoDynamicExtensions.versions.alfresco
		]
		def surf = [
			version: project.alfrescoDynamicExtensions.versions.surf
		]
		def dynamicExtensions = [
			version: project.alfrescoDynamicExtensions.versions.dynamicExtensions
		]
		def spring = [
			version: project.alfrescoDynamicExtensions.versions.spring
		]
		project.dependencies {
			compile ("org.alfresco:alfresco-core:${alfresco.version}") { transitive = false }
			compile ("org.alfresco:alfresco-repository:${alfresco.version}") { transitive = false }
			compile ("org.alfresco:alfresco-data-model:${alfresco.version}") { transitive = false }
			compile ("org.springframework.extensions.surf:spring-webscripts:${surf.version}") { transitive = false }
			compile ("org.springframework.extensions.surf:spring-surf-core:${surf.version}") { transitive = false }
			compile ("com.github.dynamicextensionsalfresco:annotations:${dynamicExtensions.version}") { transitive = false }
            compile ("com.github.dynamicextensionsalfresco:webscripts:${dynamicExtensions.version}") { transitive = false }
			// Since Spring is so fundamental, this is the one dependency we leave as transitive.
			compile ("org.springframework:spring-context:${spring.version}")
			// JSR-250 API contains the @Resource annotation for referencing dependencies by name.
			compile ('javax.annotation:jsr250-api:1.0') { transitive = false }
		}
	}

	void configureJarManifest(Project project) {
        project.jar {
            manifest {
                instruction "Alfresco-Dynamic-Extension", "true"
            }
        }
        /*
         * These packages must be imported for code that uses CGLIB or Spring AOP. For the sake of convenience, this
         * plugin preemptively adds these imports.
         *
         * Without these imports, you will get ClassNotFoundExceptions when using CGLIB proxies (generated by Spring)
         * for classes that are loaded within the OSGi container.
         *
         * BND will not be able to detect the use of CGLIB and Spring AOP classes at build-time, hence these packages
         * must be specified manually.
         *
         * If the task has already set the "Import-Package", we leave it as is.
         * Double import issue when writing an extension that explicitly references AOP classes.
         */
        if (!project.jar.manifest.instructionValue("Import-Package")) {
            def additionalPackages = [
                    "net.sf.cglib.core",
                    "net.sf.cglib.proxy",
                    "net.sf.cglib.reflect",
                    "org.aopalliance.aop",
                    "org.aopalliance.intercept",
                    "org.springframework.aop",
                    "org.springframework.aop.framework"
            ]
            project.jar {
                manifest {
                    instruction "Import-Package", "*," + additionalPackages.join(",")
                }
            }
        }
    }

	void configureRepositories(Project project) {
		project.repositories {
			jcenter()
			maven { url "https://artifacts.alfresco.com/nexus/content/groups/public" }
			maven { url "http://repo.springsource.org/release" }
			maven { url "https://raw.github.com/laurentvdl/dynamic-extensions-for-alfresco/mvn-repo/" }
		}
	}
}



package com.github.dynamicextensionsalfresco.gradle

import com.github.dynamicextensionsalfresco.gradle.configuration.BaseConfig
import com.github.dynamicextensionsalfresco.gradle.tasks.InstallBundle
import org.gradle.api.Plugin
import org.gradle.api.Project

/**
 * Gradle plugin that configures build settings for an Alfresco Dynamic Extension.
 * 
 * @author Laurens Fridael
 * @author Laurent Van der Linden
 */
class DynamicExtensionPlugin implements Plugin<Project> {

	@Override
	void apply(Project project) {
		configurePlugins(project)
		configureExtensions(project)
		configureTasks(project)
		project.afterEvaluate {
			configureDependencies(project)
			configureRepositories(project)
			configureJarManifest(project)
		}
	}

    static void configurePlugins(Project project) {
		project.apply plugin: "java"
		project.apply plugin: "osgi"
	}

    static void configureExtensions(Project project) {
		project.extensions.create("alfrescoDynamicExtensions", BaseConfig.class, project)
	}

    static void configureTasks(Project project) {
		project.tasks.create("installBundle", InstallBundle.class)
	}

	void configureDependencies(Project project) {
		def alfresco = [
			version: project.alfrescoDynamicExtensions.versions.alfresco
		]
		def surf = [
			version: project.alfrescoDynamicExtensions.versions.surf
		]
		def dynamicExtensions = [
			version: project.alfrescoDynamicExtensions.versions.dynamicExtensions
		]
		def spring = [
			version: project.alfrescoDynamicExtensions.versions.spring
		]
		project.dependencies {
			compile ("org.alfresco:alfresco-core:${alfresco.version}") { transitive = false }
			compile ("org.alfresco:alfresco-repository:${alfresco.version}") { transitive = false }
			compile ("org.alfresco:alfresco-data-model:${alfresco.version}") { transitive = false }
			compile ("org.springframework.extensions.surf:spring-webscripts:${surf.version}") { transitive = false }
			compile ("org.springframework.extensions.surf:spring-surf-core:${surf.version}") { transitive = false }
			compile ("com.github.dynamicextensionsalfresco:annotations:${dynamicExtensions.version}") { transitive = false }
            compile ("com.github.dynamicextensionsalfresco:webscripts:${dynamicExtensions.version}") { transitive = false }
			// Since Spring is so fundamental, this is the one dependency we leave as transitive.
			compile ("org.springframework:spring-context:${spring.version}")
			// JSR-250 API contains the @Resource annotation for referencing dependencies by name.
			compile ('javax.annotation:jsr250-api:1.0') { transitive = false }
		}
	}

	void configureJarManifest(Project project) {
        project.jar {
            manifest {
                instruction "Alfresco-Dynamic-Extension", "true"
            }
        }
        /*
         * These packages must be imported for code that uses CGLIB or Spring AOP. For the sake of convenience, this
         * plugin preemptively adds these imports.
         *
         * Without these imports, you will get ClassNotFoundExceptions when using CGLIB proxies (generated by Spring)
         * for classes that are loaded within the OSGi container.
         *
         * BND will not be able to detect the use of CGLIB and Spring AOP classes at build-time, hence these packages
         * must be specified manually.
         *
         * If the task has already set the "Import-Package", we leave it as is.
         * Double import issue when writing an extension that explicitly references AOP classes.
         */
        if (!project.jar.manifest.instructionValue("Import-Package")) {
            def additionalPackages = [
                    "net.sf.cglib.core",
                    "net.sf.cglib.proxy",
                    "net.sf.cglib.reflect",
                    "org.aopalliance.aop",
                    "org.aopalliance.intercept",
                    "org.springframework.aop",
                    "org.springframework.aop.framework"
            ]
            project.jar {
                manifest {
                    instruction "Import-Package", "*," + additionalPackages.join(",")
                }
            }
        }
    }

	void configureRepositories(Project project) {
		project.repositories {
			jcenter()
			maven { url "https://artifacts.alfresco.com/nexus/content/groups/public" }
			maven { url "http://repo.springsource.org/release" }
			maven { url "https://raw.github.com/laurentvdl/dynamic-extensions-for-alfresco/mvn-repo/" }
		}
	}
}


