#!/system/bin/sh

#Contains utility methods for handling projects
#like finding the project root for a source code
#and whether a project is a gradle project or not.

#Recursively checks every parent of the passed path for a src
#folder and returns the parent that has one
#If none are found it returns an empty string
getProjectRoot() {
  cfile=$@
  while [ ! -e ${cfile}/src ]; do
    cfile={cfile%/*}
  done
  
  return cfile
}

isGradleProject() {
  if [ -f "${@}/build.gradle" ]; then
    return 0
  fi
  return 1
}

isJavaProject() {
  if [ `mfind "${@}" -name .*\.java` != "" ]; then
    return 0
  fi
  return 1
}

isAndroidProject() {
  if [ -e "${@}/src" -a -e "${@}/res" ] || [ -f "${@}/AndroidManifest.xml" ]; then
    return 0
  fi
  return 1
}