Skip to content

Commit 644e3de

Browse files
committed
Merge pull request #83 from brunobowden/fix
J2objcPodTask fixes and error message improvements
2 parents bd7a885 + 734b902 commit 644e3de

File tree

1 file changed

+36
-19
lines changed

1 file changed

+36
-19
lines changed

j2objc.gradle

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,13 +1078,16 @@ class J2objcPodTask extends DefaultTask {
10781078
@TaskAction
10791079
def pod(IncrementalTaskInputs inputs) {
10801080

1081-
if (project.j2objcConfig.xcodeProjectDir == null) {
1082-
def message = "You must specify the xcodeProjectDir"
1083-
throw new InvalidUserDataException(message)
1084-
}
1081+
if (project.j2objcConfig.xcodeProjectDir == null ||
1082+
project.j2objcConfig.xcodeTarget == null) {
10851083

1086-
if (project.j2objcConfig.xcodeTarget == null) {
1087-
def message = "You must specify the xcodeTarget"
1084+
def message =
1085+
"Xcode settings needs to be configured in the build.gradle file:\n" +
1086+
"\n" +
1087+
"j2objcConfig {\n" +
1088+
" xcodeProjectDir \"\${projectDir}/../Xcode\"\n" +
1089+
" xcodeTarget \"<TARGET_NAME>\"\n" +
1090+
"}\n"
10881091
throw new InvalidUserDataException(message)
10891092
}
10901093

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

10951098
// Resource Folder is copied to buildDir where it's accessed by the pod later
1099+
def j2objcHome = J2objcUtils.j2objcHome(getProject())
10961100
String j2objcResourceDirName = "j2objcResources"
10971101
String j2objcResourceDirPath = "${project.buildDir}/${j2objcResourceDirName}"
10981102
project.delete j2objcResourceDirPath
10991103
project.copy {
1100-
from J2objcUtils.srcDirs(depProj, 'main', 'resources')
1104+
from J2objcUtils.srcDirs(project, 'main', 'resources')
11011105
into j2objcResourceDirPath
11021106
}
11031107

11041108
// create the podspec
11051109
def podName = project.name
11061110
def podspecName = podName + ".podspec"
1107-
def podVersion = project.version
11081111
File podspecFile = new File(project.buildDir, podspecName)
11091112
podspecFile.write("")
11101113
// TODO s.libraries: this will not function for anyone who has their own list of linked libraries in the compileFlags
11111114
podspecFile.append(
11121115
"Pod::Spec.new do |s|" + lineSeparator +
11131116
"s.name = '${podName}'" + lineSeparator +
1114-
"s.version = '${podVersion}'" + lineSeparator +
1117+
"s.version = '1.0'" + lineSeparator +
11151118
"s.summary = 'Generated by the j2objc.gradle plugin.'" + lineSeparator +
11161119
"s.source_files = 'j2objc/**/*.{h,m}'" + lineSeparator +
11171120
"s.public_header_files = 'j2objc/**/*.h'" + lineSeparator +
11181121
"s.resources = '${j2objcResourceDirName}/**/*'" + lineSeparator +
11191122
"s.requires_arc = true" + lineSeparator +
11201123
"s.libraries = 'ObjC', 'guava', 'javax_inject', 'jre_emul', 'jsr305', 'z', 'icucore'" + lineSeparator +
1121-
"s.xcconfig = { 'HEADER_SEARCH_PATHS' => '${J2objcUtils.j2objcHome(project)}/include', 'LIBRARY_SEARCH_PATHS' => '${j2objcHome}/lib' }" + lineSeparator +
1124+
"s.xcconfig = { 'HEADER_SEARCH_PATHS' => '${j2objcHome}/include', 'LIBRARY_SEARCH_PATHS' => '${j2objcHome}/lib' }" + lineSeparator +
11221125
"end")
11231126

11241127
// link the podspec in pod file
11251128
File podFile = new File(xcodeProjectDir, "Podfile")
11261129
if (!podFile.exists()) {
1127-
def message = "No podfile exists at path ${xcodeProjectDir} execute 'pod init' first in your project directory"
1130+
// TODO: offer to run the setup commands
1131+
def message =
1132+
"No podfile exists in the directory: ${xcodeProjectDir}\n" +
1133+
"Within that directory, create the podfile with this command:\n" +
1134+
" pod init\n" +
1135+
"\n" +
1136+
"If the pod command isn't found, then install CocoaPods:\n" +
1137+
" sudo gem install cocoapods"
11281138
throw new InvalidUserDataException(message)
1129-
}
1130-
else {
1139+
} else {
11311140
logger.debug "Pod exists at path: ${xcodeProjectDir}"
11321141
// check if this podspec has been included before
11331142
def result = J2objcUtils.checkPodDefExistence(podFile, xcodeTarget, podName)
@@ -1155,17 +1164,25 @@ class J2objcPodTask extends DefaultTask {
11551164
errorOutput output
11561165
}
11571166
} catch (Exception exception) {
1158-
logger.debug output.toString()
1159-
logger.error 'Error during pod install:'
1167+
logger.error output.toString()
11601168

1161-
// unrecognized errors are rethrown:
11621169
if (exception.getMessage().find("A problem occurred starting process 'command 'pod install''")) {
1163-
// TODO: fix this installation description
11641170
def message =
1165-
"To install pod: sudo gem install cocoapods \n" +
1166-
"See: https://cocoapods.org/"
1171+
"Fix this by installing CocoaPods:\n" +
1172+
" sudo gem install cocoapods \n" +
1173+
"\n" +
1174+
"See: https://cocoapods.org/"
11671175
throw new InvalidUserDataException(message)
11681176
}
1177+
if (output.toString().find("ArgumentError - Malformed version number string unspecified")) {
1178+
// TODO: Add instructions on how to configure project.version
1179+
def message =
1180+
"Fix this by specifying a project version:\n" +
1181+
"<ADD INSTRUCTIONS>"
1182+
throw new InvalidUserDataException(message)
1183+
}
1184+
1185+
// unrecognized errors are rethrown:
11691186
throw exception
11701187
}
11711188
logger.debug 'Pod install output:'

0 commit comments

Comments
 (0)