Skip to content

Commit

Permalink
Merge pull request #83 from brunobowden/fix
Browse files Browse the repository at this point in the history
J2objcPodTask fixes and error message improvements
  • Loading branch information
brunobowden committed Jun 2, 2015
2 parents bd7a885 + 734b902 commit 644e3de
Showing 1 changed file with 36 additions and 19 deletions.
55 changes: 36 additions & 19 deletions j2objc.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -1078,13 +1078,16 @@ class J2objcPodTask extends DefaultTask {
@TaskAction
def pod(IncrementalTaskInputs inputs) {

if (project.j2objcConfig.xcodeProjectDir == null) {
def message = "You must specify the xcodeProjectDir"
throw new InvalidUserDataException(message)
}
if (project.j2objcConfig.xcodeProjectDir == null ||
project.j2objcConfig.xcodeTarget == null) {

if (project.j2objcConfig.xcodeTarget == null) {
def message = "You must specify the xcodeTarget"
def message =
"Xcode settings needs to be configured in the build.gradle file:\n" +
"\n" +
"j2objcConfig {\n" +
" xcodeProjectDir \"\${projectDir}/../Xcode\"\n" +
" xcodeTarget \"<TARGET_NAME>\"\n" +
"}\n"
throw new InvalidUserDataException(message)
}

Expand All @@ -1093,41 +1096,47 @@ class J2objcPodTask extends DefaultTask {
def lineSeparator = System.getProperty("line.separator")

// Resource Folder is copied to buildDir where it's accessed by the pod later
def j2objcHome = J2objcUtils.j2objcHome(getProject())
String j2objcResourceDirName = "j2objcResources"
String j2objcResourceDirPath = "${project.buildDir}/${j2objcResourceDirName}"
project.delete j2objcResourceDirPath
project.copy {
from J2objcUtils.srcDirs(depProj, 'main', 'resources')
from J2objcUtils.srcDirs(project, 'main', 'resources')
into j2objcResourceDirPath
}

// create the podspec
def podName = project.name
def podspecName = podName + ".podspec"
def podVersion = project.version
File podspecFile = new File(project.buildDir, podspecName)
podspecFile.write("")
// TODO s.libraries: this will not function for anyone who has their own list of linked libraries in the compileFlags
podspecFile.append(
"Pod::Spec.new do |s|" + lineSeparator +
"s.name = '${podName}'" + lineSeparator +
"s.version = '${podVersion}'" + lineSeparator +
"s.version = '1.0'" + lineSeparator +
"s.summary = 'Generated by the j2objc.gradle plugin.'" + lineSeparator +
"s.source_files = 'j2objc/**/*.{h,m}'" + lineSeparator +
"s.public_header_files = 'j2objc/**/*.h'" + lineSeparator +
"s.resources = '${j2objcResourceDirName}/**/*'" + lineSeparator +
"s.requires_arc = true" + lineSeparator +
"s.libraries = 'ObjC', 'guava', 'javax_inject', 'jre_emul', 'jsr305', 'z', 'icucore'" + lineSeparator +
"s.xcconfig = { 'HEADER_SEARCH_PATHS' => '${J2objcUtils.j2objcHome(project)}/include', 'LIBRARY_SEARCH_PATHS' => '${j2objcHome}/lib' }" + lineSeparator +
"s.xcconfig = { 'HEADER_SEARCH_PATHS' => '${j2objcHome}/include', 'LIBRARY_SEARCH_PATHS' => '${j2objcHome}/lib' }" + lineSeparator +
"end")

// link the podspec in pod file
File podFile = new File(xcodeProjectDir, "Podfile")
if (!podFile.exists()) {
def message = "No podfile exists at path ${xcodeProjectDir} execute 'pod init' first in your project directory"
// TODO: offer to run the setup commands
def message =
"No podfile exists in the directory: ${xcodeProjectDir}\n" +
"Within that directory, create the podfile with this command:\n" +
" pod init\n" +
"\n" +
"If the pod command isn't found, then install CocoaPods:\n" +
" sudo gem install cocoapods"
throw new InvalidUserDataException(message)
}
else {
} else {
logger.debug "Pod exists at path: ${xcodeProjectDir}"
// check if this podspec has been included before
def result = J2objcUtils.checkPodDefExistence(podFile, xcodeTarget, podName)
Expand Down Expand Up @@ -1155,17 +1164,25 @@ class J2objcPodTask extends DefaultTask {
errorOutput output
}
} catch (Exception exception) {
logger.debug output.toString()
logger.error 'Error during pod install:'
logger.error output.toString()

// unrecognized errors are rethrown:
if (exception.getMessage().find("A problem occurred starting process 'command 'pod install''")) {
// TODO: fix this installation description
def message =
"To install pod: sudo gem install cocoapods \n" +
"See: https://cocoapods.org/"
"Fix this by installing CocoaPods:\n" +
" sudo gem install cocoapods \n" +
"\n" +
"See: https://cocoapods.org/"
throw new InvalidUserDataException(message)
}
if (output.toString().find("ArgumentError - Malformed version number string unspecified")) {
// TODO: Add instructions on how to configure project.version
def message =
"Fix this by specifying a project version:\n" +
"<ADD INSTRUCTIONS>"
throw new InvalidUserDataException(message)
}

// unrecognized errors are rethrown:
throw exception
}
logger.debug 'Pod install output:'
Expand Down

0 comments on commit 644e3de

Please sign in to comment.