Skip to content
This repository has been archived by the owner on Sep 14, 2021. It is now read-only.

Implement ModelResolver.addRepository(Repository, boolean) correctly. #65

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jkinkead
Copy link
Contributor

This correctly honors the replace parameter. It was ignored before, which was making it effectively be treated as false.

Per the reference implementation, the single-argument addRepository should not replace (although it wasn't before).

@bazel-io
Copy link
Member

Can one of the admins verify this patch?

}

@Override
public void addRepository(Repository repository, boolean replace) {
addRepository(repository);
if (repositories.contains(repository)) {
Copy link
Member

Choose a reason for hiding this comment

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

Thank you. The addRepositories(Repository repository, boolean replace) is never called, so we skimped out on including the replace functionality.

Assuming it's not particularly annoying, can you add a simple test case?

There isn't any DefaultModelResolverTest so you would need to create one, and mock the repositories.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

I also updated the repository store, since the previous implementation was relying on the internal implementation of Repository.equals, which is not documented as operating only on ID (even though it appears to be).

Copy link
Member

Choose a reason for hiding this comment

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

Good catch on the equals.

Refactor repository registry to not rely on .equals implmentation of Repository.
Copy link
Member

@petroseskinder petroseskinder left a comment

Choose a reason for hiding this comment

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

Thank you. It looks good overall, barring a few nits.

}
} else {
repositories.add(repository);
if (replace || !repositoriesById.containsKey(repository.getId())) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: can you add a simple comment for the boolean logic?
Although the new version is more concise, it took me a
second to remember the conditions.

mavenCentral.setName("default");
mavenCentral.setUrl(MAVEN_CENTRAL_URL);

DEFAULT_REPOSITORIES = ImmutableMap.of(mavenCentral.getId(), mavenCentral);
Copy link
Member

Choose a reason for hiding this comment

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

👍 to this change

/** Test that addRepository doesn't replace existing repositories by default. */
@Test
public void testAddRepository_defaultReplace() {
Repository repoA1 = new Repository();
Copy link
Member

Choose a reason for hiding this comment

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

First thank you for the tests. One nit

Since each test is effectively doing the same thing, can you create the following utility functions

private Repository createRepository(String id, String url) {
     Repository repo = new Repository();
     repo.setId(id);
     repo.setUrl(url);
}

private void assertThatContainsRepo(
      DefaultModelResolver resolver, Repository repo) {...} 

private void assertThatUrlNotChanged(
       DefaultModelResolver resolver, Repository repo, String expectedUrl) {...}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants