Skip to content
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

Merged
merged 3 commits into from
Jul 21, 2018

Conversation

Menardi
Copy link
Contributor

@Menardi Menardi commented Jun 29, 2018

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 to ProjectBuilder as several people suggested in #458. GenericBuilder has also been merged into this file. I have kept builder.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 in ProjectBuilder.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 use class instead of prototype 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 shows ProjectBuilder.js as a new file rather than a renamed StudioBuilder.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.

  • Created a project using ./bin/create
  • Built this project using ./cordova/build and successfully ran on an emulator
  • Ran JS and Java unit tests

Checklist

  • Reported an issue in the JIRA database
  • Commit message follows the format: "CB-3232: (android) Fix bug with resolving file paths", where CB-xxxx is the JIRA ID & "android" is the platform affected.
  • Added automated test coverage as appropriate for this change.

@codecov-io
Copy link

codecov-io commented Jun 29, 2018

Codecov Report

Merging #461 into master will increase coverage by 2.34%.
The diff coverage is 40.7%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
bin/templates/cordova/lib/builders/builders.js 100% <ø> (+62.5%) ⬆️
bin/templates/cordova/lib/AndroidProject.js 40% <100%> (-2.61%) ⬇️
bin/templates/cordova/Api.js 41.58% <100%> (-7.99%) ⬇️
...n/templates/cordova/lib/builders/ProjectBuilder.js 39.79% <39.79%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b6e4598...4b0725d. Read the comment docs.

@Menardi Menardi changed the title Refactor builders (with unit tests) Remove old builders code Jun 29, 2018
@@ -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';
Copy link
Member

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?

Copy link
Contributor Author

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.

@apache apache deleted a comment from asilkarbeyaz Jun 29, 2018
Copy link
Member

@dpogue dpogue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

@raphinesse raphinesse left a 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 */
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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');
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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')
Copy link
Contributor

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?

Copy link
Contributor Author

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', () => {
Copy link
Contributor

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', () => {
Copy link
Contributor

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);
Copy link
Contributor

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?

Copy link
Contributor Author

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.

it('should return an instance of ProjectBuilder', () => {
const newBuilder = builder.getBuilder('studio');
expect(newBuilder).toEqual(jasmine.any(ProjectBuilder));
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated test

Copy link
Contributor Author

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.

const ProjectBuilder = require('../../../bin/templates/cordova/lib/builders/ProjectBuilder');

describe('builders', () => {
let builder;
Copy link
Contributor

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?

@Menardi Menardi force-pushed the refactor_builders_with_tests branch from 02a9f43 to 1e012ec Compare July 10, 2018 00:05
@Menardi Menardi force-pushed the refactor_builders_with_tests branch from 1e012ec to 4b0725d Compare July 10, 2018 02:54
@raphinesse
Copy link
Contributor

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!

@Menardi
Copy link
Contributor Author

Menardi commented Jul 11, 2018

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.

@raphinesse raphinesse merged commit ebbd91f into apache:master Jul 21, 2018
@Menardi Menardi deleted the refactor_builders_with_tests branch July 23, 2018 11:36
erisu added a commit to erisu/cordova-android that referenced this pull request Sep 4, 2018
- 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.
erisu added a commit to erisu/cordova-android that referenced this pull request Sep 4, 2018
- 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.
erisu added a commit to erisu/cordova-android that referenced this pull request Sep 4, 2018
- 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.
erisu added a commit to erisu/cordova-android that referenced this pull request Sep 5, 2018
- 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.
erisu added a commit to erisu/cordova-android that referenced this pull request Sep 5, 2018
- 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.
erisu added a commit that referenced this pull request Sep 6, 2018
- 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants