-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Remove old builders code #461
Remove old builders code #461
Conversation
Codecov Report
@@ Coverage Diff @@
## master #461 +/- ##
=========================================
+ Coverage 60.56% 62.9% +2.34%
=========================================
Files 17 15 -2
Lines 1694 1650 -44
Branches 312 308 -4
=========================================
+ Hits 1026 1038 +12
+ Misses 668 612 -56
Continue to review full report at Codecov.
|
@@ -56,41 +55,27 @@ function setupEvents (externalEventEmitter) { | |||
function Api (platform, platformRootDir, events) { | |||
this.platform = PLATFORM; | |||
this.root = path.resolve(__dirname, '..'); | |||
this.builder = 'gradle'; | |||
this.builder = 'studio'; |
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.
if there is only one builder, then this could probably be removed?
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.
I wasn't sure if other things relied on Api.builder
so I left it alone. The refactor could do a lot more, but I was reluctant to change too much given that I am still relatively unfamiliar with the codebase.
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.
👍
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.
Left a few comments. Thanks for your work!
var SIGNING_PROPERTIES = '-signing.properties'; | ||
var TEMPLATE = | ||
/* eslint no-self-assign: 0 */ | ||
/* eslint no-unused-vars: 0 */ |
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.
I don't like introducing these comments, especially file global. Why do we need these?
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.
I didn't actually introduce these, they are originally from GenericBuilder. They cover this line. It makes no sense to me, but I left it as is for now.
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.
WTF?!
let spawn = require('cordova-common').superspawn.spawn; | ||
let events = require('cordova-common').events; | ||
let CordovaError = require('cordova-common').CordovaError; | ||
let check_reqs = require('../check_reqs'); |
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.
Why can't we use const here too? Or at least leave them using var for now.
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.
Using const
means that we can't spy on them unfortunately. I can revert them to var
if you think that would be better.
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.
Using const means that we can't spy on them unfortunately.
I don't get why that would be the case : thinking:
I can revert them to var if you think that would be better.
I'd prefer that, since it reduces the amount of unrelated changes.
this.root = projectRoot || path.resolve(__dirname, '../../..'); | ||
this.binDirs = { | ||
studio: path.join(this.root, 'app', 'build', 'outputs', 'apk'), | ||
gradle: path.join(this.root, 'app', 'build', 'outputs', 'apk') |
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.
Why do we need both of these?
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.
I was attempting to keep potential breaking changes to a minimum. It is unlikely that binDirs.gradle
is being used, but I was unsure about removing it.
expect(builder.root).toBe(rootDir); | ||
}); | ||
|
||
it('should set the project directory to three folders back', () => { |
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.
"… three folders up"?
spyOn(builder, 'getArgs'); | ||
}); | ||
|
||
it('should set to build type to debug', () => { |
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.
One "to" too many
let spawnSpy; | ||
|
||
beforeEach(() => { | ||
spawnSpy = jasmine.createSpy('spawn').and.returnValue(Q.defer().promise); |
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.
Does the calling code expect spawn to return a Q instance?
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.
Yes, it uses .progress
, which is not part of the Promise spec. It is only used as a workaround for CB-9971, so it should be possible to remove it at some point.
spec/unit/builders/builders.spec.js
Outdated
it('should return an instance of ProjectBuilder', () => { | ||
const newBuilder = builder.getBuilder('studio'); | ||
expect(newBuilder).toEqual(jasmine.any(ProjectBuilder)); | ||
}); |
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.
Duplicated test
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.
The first tests when gradle
is requested, and the second when studio
is requested. I will rename the tests to make the difference more obvious.
spec/unit/builders/builders.spec.js
Outdated
const ProjectBuilder = require('../../../bin/templates/cordova/lib/builders/ProjectBuilder'); | ||
|
||
describe('builders', () => { | ||
let builder; |
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.
Wouldn't builders
be a more appropriate name?
02a9f43
to
1e012ec
Compare
1e012ec
to
4b0725d
Compare
Thanks for addressing my comments @Menardi. I think we can merge this. Agreed, @dpogue? It would be great if you could somehow document all the strange stuff you came about that should be addressed but was outside the scope of this PR or potentially unsafe. Either as an issue or by creating another PR that errs on the unsafe side. Thanks again for the good work! |
Once this is merged, I am happy to take another look through the code to see how much more refactoring I can do relating to the builders. I think there is a lot of improvement to be had. |
- General Code Refactor - Removed builder type argument from getBuilder API - Removed any reference of conditional statements around builder type - Remove plugin handler install and uninstall option flag android_studio - Remove --gradle flag references - Fixed plugin handler install and uninstall pathing issues - Removed the second build process. The build before launching emulator has been removed. Only run the build once and after the emulator start process is triggered. - Added parseBuildOptions export so run can get build related options. - Use the nobuild flag option to control the run build. - Updated test spec to reflect the changes.
- General Code Refactor - Removed builder type argument from getBuilder API - Removed any reference of conditional statements around builder type - Remove plugin handler install and uninstall option flag android_studio - Remove --gradle flag references - Fixed plugin handler install and uninstall pathing issues - Removed the second build process. The build before launching emulator has been removed. Only run the build once and after the emulator start process is triggered. - Added parseBuildOptions export so run can get build related options. - Use the nobuild flag option to control the run build. - Updated test spec to reflect the changes.
- General Code Refactor - Removed builder type argument from getBuilder API - Removed any reference of conditional statements around builder type - Remove plugin handler install and uninstall option flag android_studio - Remove --gradle flag references - Fixed plugin handler install and uninstall pathing issues - Added parseBuildOptions export so run can get build related options. - Use the nobuild flag option to control the run build. - Updated test spec to reflect the changes.
- General Code Refactor - Removed builder type argument from getBuilder API - Removed any reference of conditional statements around builder type - Remove plugin handler install and uninstall option flag android_studio - Remove --gradle flag references - Fixed plugin handler install and uninstall pathing issues - Added parseBuildOptions export so run can get build related options. - Use the nobuild flag option to control the run build. - Updated test spec to reflect the changes.
- General Code Refactor - Removed builder type argument from getBuilder API - Removed any reference of conditional statements around builder type - Remove plugin handler install and uninstall option flag android_studio - Remove --gradle flag references - Fixed plugin handler install and uninstall pathing issues - Added parseBuildOptions export so run can get build related options. - Use the nobuild flag option to control the run build. - Updated test spec to reflect the changes.
- General Code Refactor - Removed builder type argument from getBuilder API - Removed any reference of conditional statements around builder type - Remove plugin handler install and uninstall option flag android_studio - Remove --gradle flag references - Fixed plugin handler install and uninstall pathing issues - Added parseBuildOptions export so run can get build related options. - Use the nobuild flag option to control the run build. - Updated test spec to reflect the changes.
Platforms affected
Android
What does this PR do?
This refactors the builders to remove legacy code, as per discussions in #458 and #437.
GradleBuilder
has been removed as it was not being used.StudioBuilder
has been renamed toProjectBuilder
as several people suggested in #458.GenericBuilder
has also been merged into this file. I have keptbuilder.js
, which is used to access the builder from other files. Since there is now only one builder, we probably don't need to keep this, but it minimises external changes. The tests which were originally part of #458 are now in here inProjectBuilder.spec.js
.I have removed
AndroidStudio.js
since it only had one function, which always returned true.In the last commit, I refactored
ProjectBuilder.js
to useclass
instead ofprototype
since the minimum Node version is now 6. Functionally it makes no difference, but I find it easier to read. Maybe not everyone will agree, which is why I put it in a separate commit which can be removed if anyone strongly objects.Due to the change to class, there are a lot of whitespace changes. For reviewing, I recommend adding
?w=1
to the end of the GitHub URL to ignore whitespace changes. It should make things a bit easier. Also, it's probably best to go commit-by-commit, as reviewing both commits together for some reason showsProjectBuilder.js
as a new file rather than a renamedStudioBuilder.js
.What testing has been done on this change?
I think the testing below is sufficient, but please let me know if there is more I should do.
./bin/create
./cordova/build
and successfully ran on an emulatorChecklist