-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Config to only add j2objc_shared method to Podfile #565
Changes from 1 commit
86004d5
8afd2b6
4f8d7ed
1aa92c7
605b623
555bfad
36e8d3c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,9 @@ class XcodeTask extends DefaultTask { | |
@Input @Optional | ||
String getXcodeProjectDir() { return J2objcConfig.from(project).xcodeProjectDir } | ||
|
||
@Input | ||
boolean isOnlyAddJ2ObjcToPodfile() { return J2objcConfig.from(project).onlyAddJ2ObjcToPodfile } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Follow the existing convention and use a "get" prefix on the existing name, with first letter capitalized:
|
||
|
||
boolean isTaskActive() { return getXcodeProjectDir() != null } | ||
|
||
@Input | ||
|
@@ -200,7 +203,7 @@ class XcodeTask extends DefaultTask { | |
getXcodeTargetsIos(), getXcodeTargetsOsx(), getXcodeTargetsWatchos(), | ||
getMinVersionIos(), getMinVersionOsx(), getMinVersionWatchos()) | ||
|
||
writeUpdatedPodfileIfNeeded(podspecDetailsList, xcodeTargetDetails, podfile) | ||
writeUpdatedPodfileIfNeeded(podspecDetailsList, xcodeTargetDetails,!isOnlyAddJ2ObjcToPodfile(), podfile) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By using a similar variable name (and meaning) throughout the code, you should avoid things like negation. When you make a change like this, a developer has to think "it's X over here" then "it's not-X over here". That's a significant addition in mental complexity for someone else reading the code that you should avoid. |
||
|
||
// install the pod | ||
ByteArrayOutputStream stdout = new ByteArrayOutputStream() | ||
|
@@ -374,14 +377,14 @@ class XcodeTask extends DefaultTask { | |
@VisibleForTesting | ||
static void writeUpdatedPodfileIfNeeded( | ||
List<PodspecDetails> podspecDetailsList, | ||
XcodeTargetDetails xcodeTargetDetails, | ||
XcodeTargetDetails xcodeTargetDetails, boolean updateTargets, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Follow existing conventions and put new parameter on separate line. Also, rename to |
||
File podfile) { | ||
|
||
List<String> oldPodfileLines = podfile.readLines() | ||
List<String> newPodfileLines = new ArrayList<String>(oldPodfileLines) | ||
|
||
newPodfileLines = updatePodfile( | ||
newPodfileLines, podspecDetailsList, xcodeTargetDetails, podfile) | ||
newPodfileLines, podspecDetailsList, xcodeTargetDetails,updateTargets, podfile) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need space after comma. |
||
|
||
// Write file only if it's changed | ||
if (!oldPodfileLines.equals(newPodfileLines)) { | ||
|
@@ -393,34 +396,38 @@ class XcodeTask extends DefaultTask { | |
static List<String> updatePodfile( | ||
List<String> podfileLines, | ||
List<PodspecDetails> podspecDetailsList, | ||
XcodeTargetDetails xcodeTargetDetails, | ||
XcodeTargetDetails xcodeTargetDetails,boolean updateTargets, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Parameter on new line. Rename to |
||
File podfile) { | ||
|
||
List<String> podfileTargets = extractXcodeTargets(podfileLines) | ||
verifyTargets(xcodeTargetDetails.xcodeTargetsIos, podfileTargets, 'xcodeTargetsIos') | ||
verifyTargets(xcodeTargetDetails.xcodeTargetsOsx, podfileTargets, 'xcodeTargetsOsx') | ||
verifyTargets(xcodeTargetDetails.xcodeTargetsWatchos, podfileTargets, 'xcodeTargetsWatchos') | ||
if(updateTargets){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need space between |
||
List<String> podfileTargets = extractXcodeTargets(podfileLines) | ||
verifyTargets(xcodeTargetDetails.xcodeTargetsIos, podfileTargets, 'xcodeTargetsIos') | ||
verifyTargets(xcodeTargetDetails.xcodeTargetsOsx, podfileTargets, 'xcodeTargetsOsx') | ||
verifyTargets(xcodeTargetDetails.xcodeTargetsWatchos, podfileTargets, 'xcodeTargetsWatchos') | ||
|
||
if (xcodeTargetDetails.xcodeTargetsIos.isEmpty() && | ||
xcodeTargetDetails.xcodeTargetsOsx.isEmpty() && | ||
xcodeTargetDetails.xcodeTargetsWatchos.isEmpty()) { | ||
// Give example for configuring iOS as that's the common case | ||
throw new InvalidUserDataException( | ||
"You must configure the xcode targets for the J2ObjC Gradle Plugin.\n" + | ||
"It must be a subset of the valid targets: '${podfileTargets.join("', '")}'\n" + | ||
"\n" + | ||
"j2objcConfig {\n" + | ||
" xcodeTargetsIos 'IOS-APP', 'IOS-APPTests' // example\n" + | ||
"}\n" + | ||
"\n" + | ||
"Can be optionally configured for xcodeTargetsOsx and xcodeTargetsWatchos\n") | ||
if (xcodeTargetDetails.xcodeTargetsIos.isEmpty() && | ||
xcodeTargetDetails.xcodeTargetsOsx.isEmpty() && | ||
xcodeTargetDetails.xcodeTargetsWatchos.isEmpty()) { | ||
// Give example for configuring iOS as that's the common case | ||
throw new InvalidUserDataException( | ||
"You must configure the xcode targets for the J2ObjC Gradle Plugin.\n" + | ||
"It must be a subset of the valid targets: '${podfileTargets.join("', '")}'\n" + | ||
"\n" + | ||
"j2objcConfig {\n" + | ||
" xcodeTargetsIos 'IOS-APP', 'IOS-APPTests' // example\n" + | ||
"}\n" + | ||
"\n" + | ||
"Can be optionally configured for xcodeTargetsOsx and xcodeTargetsWatchos\n") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add additional line:
|
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rewrite logic so that it forces xcode targets to be empty when doing manual config. It should be either or when configuring this.
|
||
} | ||
|
||
// update pod methods | ||
List<String> newPodfileLines = updatePodMethods(podfileLines, podspecDetailsList, podfile) | ||
|
||
// update pod targets | ||
newPodfileLines = updatePodfileTargets(newPodfileLines, podspecDetailsList, xcodeTargetDetails) | ||
if(updateTargets){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Combine this section with the previous This is how it is currently:
See how much simpler it is to understand this instead:
|
||
newPodfileLines = updatePodfileTargets(newPodfileLines, podspecDetailsList, xcodeTargetDetails) | ||
} | ||
|
||
return newPodfileLines | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -430,7 +430,7 @@ class XcodeTaskTest { | |
new File(podspecBuildDir + '/j2objc-PROJ-debug.podspec'), | ||
new File(podspecBuildDir + '/j2objc-PROJ-release.podspec'))) | ||
XcodeTask.writeUpdatedPodfileIfNeeded( | ||
podspecDetailsList, xcodeTargetDetailsIosAppOnly, podfile) | ||
podspecDetailsList, xcodeTargetDetailsIosAppOnly, true, podfile) | ||
|
||
// Verify modified Podfile | ||
List<String> expectedLines = [ | ||
|
@@ -451,7 +451,7 @@ class XcodeTaskTest { | |
// Verify unmodified on second call | ||
// TODO: verify that file wasn't written a second time | ||
XcodeTask.writeUpdatedPodfileIfNeeded( | ||
podspecDetailsList, xcodeTargetDetailsIosAppOnly, podfile) | ||
podspecDetailsList, xcodeTargetDetailsIosAppOnly, true, podfile) | ||
readPodfileLines = podfile.readLines() | ||
assert expectedLines == readPodfileLines | ||
} | ||
|
@@ -465,7 +465,7 @@ class XcodeTaskTest { | |
List<String> newPodfileLines = XcodeTask.updatePodfile( | ||
podfileLines, | ||
podspecDetailsProj, | ||
xcodeTargetDetailsIosAppOnly, | ||
xcodeTargetDetailsIosAppOnly, true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there's already a convention of putting each parameter on a new line, then do it. It's confusing to mix styles, you should adopt the same local style that already exists. |
||
new File('/SRC/ios/Podfile')) | ||
|
||
List<String> expectedPodfileLines = [ | ||
|
@@ -485,7 +485,39 @@ class XcodeTaskTest { | |
newPodfileLines = XcodeTask.updatePodfile( | ||
newPodfileLines, | ||
podspecDetailsProj, | ||
xcodeTargetDetailsIosAppOnly, | ||
xcodeTargetDetailsIosAppOnly, true, | ||
new File('/SRC/ios/Podfile')) | ||
assert expectedPodfileLines == newPodfileLines | ||
} | ||
|
||
@Test | ||
void testUpdatePodfile_onlyAddMethod() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename to: |
||
List<String> podfileLines = [ | ||
"target 'IOS-APP' do", | ||
"end"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is better demonstrated with a more complex Podfile example. Where there loops or other strange ruby logic that is impossible to update normally. That's the important example to have here. |
||
|
||
List<String> newPodfileLines = XcodeTask.updatePodfile( | ||
podfileLines, | ||
podspecDetailsProj, | ||
xcodeTargetDetailsIosAppOnly, false, | ||
new File('/SRC/ios/Podfile')) | ||
|
||
List<String> expectedPodfileLines = [ | ||
"# J2ObjC Gradle Plugin - DO NOT MODIFY from here to the first target", | ||
"def j2objc_PROJ", | ||
" pod 'j2objc-PROJ-debug', :configuration => ['Debug'], :path => '../PROJ/BUILD'", | ||
" pod 'j2objc-PROJ-release', :configuration => ['Release'], :path => '../PROJ/BUILD'", | ||
"end", | ||
"", | ||
"target 'IOS-APP' do", | ||
"end"] | ||
assert expectedPodfileLines == newPodfileLines | ||
|
||
// Second time around is a no-op | ||
newPodfileLines = XcodeTask.updatePodfile( | ||
newPodfileLines, | ||
podspecDetailsProj, | ||
xcodeTargetDetailsIosAppOnly, false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New line for new parameter |
||
new File('/SRC/ios/Podfile')) | ||
assert expectedPodfileLines == newPodfileLines | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add another test where it guides the user on how to handle a complex, non-standard Podfile:
|
||
|
@@ -509,7 +541,7 @@ class XcodeTaskTest { | |
List<String> newPodfileLines = XcodeTask.updatePodfile( | ||
podfileLines, | ||
podspecDetailsProj, | ||
xcodeTargetDetails, | ||
xcodeTargetDetails, true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adopt local style of new line for each parameter |
||
new File('/SRC/ios/Podfile')) | ||
|
||
List<String> expectedPodfileLines = [ | ||
|
@@ -539,7 +571,7 @@ class XcodeTaskTest { | |
newPodfileLines = XcodeTask.updatePodfile( | ||
newPodfileLines, | ||
podspecDetailsProj, | ||
xcodeTargetDetails, | ||
xcodeTargetDetails, true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adopt local style of new line for each parameter |
||
new File('/SRC/ios/Podfile')) | ||
assert expectedPodfileLines == newPodfileLines | ||
} | ||
|
@@ -562,7 +594,7 @@ class XcodeTaskTest { | |
[], | ||
new XcodeTask.XcodeTargetDetails( | ||
[], [], [], | ||
'6.0.0', '10.6.0', '1.0.0'), | ||
'6.0.0', '10.6.0', '1.0.0'), true, | ||
null) | ||
} | ||
|
||
|
@@ -583,10 +615,29 @@ class XcodeTaskTest { | |
[], | ||
new XcodeTask.XcodeTargetDetails( | ||
['TARGET-DOES-NOT-EXIST'], [], [], | ||
'6.0.0', '10.6.0', '1.0.0'), | ||
'6.0.0', '10.6.0', '1.0.0'), true, | ||
null) | ||
} | ||
|
||
@Test | ||
void testUpdatePodfileNoTargets_onlyAddMethod() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The first part of the test name is the method under test, so the "NoTargets" part should not be there. This doesn't seem to add much value compared to the existing A better test would be a more complex but still valid Podfile. Perhaps based on your own which I presume meant that you came across this problem. In any case, if you add that, then it should likely be next to the |
||
List<String> podfileLines = [] | ||
|
||
List<String> newPodfileLines = XcodeTask.updatePodfile( | ||
podfileLines, podspecDetailsProj, | ||
xcodeTargetDetailsIosAppOnly, false, | ||
new File('/SRC/ios/Podfile')) | ||
|
||
List<String> expectedLines = [ | ||
"# J2ObjC Gradle Plugin - DO NOT MODIFY from here to the first target", | ||
"def j2objc_PROJ", | ||
" pod 'j2objc-PROJ-debug', :configuration => ['Debug'], :path => '../PROJ/BUILD'", | ||
" pod 'j2objc-PROJ-release', :configuration => ['Release'], :path => '../PROJ/BUILD'", | ||
"end"] | ||
|
||
assert expectedLines == newPodfileLines | ||
} | ||
|
||
@Test | ||
void testUpdatePodMethods_basic() { | ||
List<String> podfileLines = [ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.