/*
 * Copyright (C) 2014 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

/*
 * *************************** ABORTED ***************************
 * 
 * See discussion in https://github.com/rosjava/rosjava_bootstrap/issues/41
 * 
 * I've left this lying around as a useful reference.
 * ***************************************************************
/*
 * ABOUT:
 * 
 * Configures a single gradle project (or subproject) to utilise ros-java settings.
 * 
 * USAGE:
 * 
 * Generally:
 * 
 *   apply from: "https://github.com/rosjava/rosjava_bootstrap/raw/indigo/ros-java.gradle"
 * 
 * In the root build.gradle file of a multiproject build:
 * 
 * subprojects {
 *   apply from: "https://github.com/rosjava/rosjava_bootstrap/raw/indigo/ros-java.gradle"
 *   ...
 * }
 */

/* 
 * Some notes: don't force the user to apply this to every subproject...let them choose
 * when and where it gets applied. This usually means applying this script redundantly
 * for every subproject. To be smarter (but force the user to do it this way) would
 * be to separate the components in this script to put subproject specific commands in a
 *        rootProject.subprojects {}
 * closure and general ones in no closure...then call it from the root.gradle (not inside
 * any allprojects/subprojects closures.
 */
/***********************
 * Plugins
 ***********************/
if (!plugins.findPlugin('maven')) {
  apply(plugin: 'maven')
}
if (!plugins.findPlugin('java')) {
  apply(plugin: 'java')
}
if (!plugins.findPlugin('maven-publish')) {
  apply(plugin: 'maven-publish')
}

/***********************
 * Environment Settings
 ***********************/
ext {
  rosMavenRepository = System.getenv("ROS_MAVEN_REPOSITORY")
  rosMavenDeploymentRepository = System.getenv("ROS_MAVEN_DEPLOYMENT_REPOSITORY")
  rosMavenPath = System.getenv("ROS_MAVEN_PATH")
}

/***********************
 * Maven Repos
 ***********************/
repositories {
  if (rosMavenPath != null) {
    rosMavenPath.tokenize(":").each { path ->
      maven {
	url uri(path)
      }
    }
  }
  if (rosMavenRepository != null) {
    maven {
      url rosMavenRepository
    }
  }
  mavenLocal()
  maven {
    url "http://repository.springsource.com/maven/bundles/release"
  }
  maven {
    url "http://repository.springsource.com/maven/bundles/external"
  }
  mavenCentral()
}

/***********************
 * Java
 ***********************/
sourceCompatibility = 1.7
targetCompatibility = 1.7

/***********************
 * Maven Deployment
 ***********************/
if ( rosMavenDeploymentRepository != 'null' && rosMavenDeploymentRepository != '' ) {
  publishing {
    publications {
      mavenJava(MavenPublication) {
	from components.java
      }
    }
    repositories {
      maven {
	url 'file://' + rosMavenDeploymentRepository
      }
    }
  }
} 
