From 734b902d1277f2eb9eadfe2a266ef32e88c2e47c Mon Sep 17 00:00:00 2001 From: Bruno Bowden Date: Mon, 1 Jun 2015 22:53:23 -0700 Subject: [PATCH] J2objcPodTask fixes and error message improvements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fixed depProj => project which didn’t run before - Fixed j2objcHome which didn’t run before - Hard code podVersion as '1.0' Error Message Improvements: - Missing podfile - Missing pod command --- j2objc.gradle | 55 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/j2objc.gradle b/j2objc.gradle index 3ffda690..b0220a36 100644 --- a/j2objc.gradle +++ b/j2objc.gradle @@ -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 \"\"\n" + + "}\n" throw new InvalidUserDataException(message) } @@ -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) @@ -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" + + "" + throw new InvalidUserDataException(message) + } + + // unrecognized errors are rethrown: throw exception } logger.debug 'Pod install output:'