Skip to content

Support relative paths for legacy tag importer#123

Merged
kaklakariada merged 3 commits intodevelopfrom
support_relative_path_configs
Apr 4, 2018
Merged

Support relative paths for legacy tag importer#123
kaklakariada merged 3 commits intodevelopfrom
support_relative_path_configs

Conversation

@kaklakariada
Copy link
Copy Markdown
Contributor

This is required for gradle plugin configuration

Copy link
Copy Markdown
Collaborator

@redcatbear redcatbear left a comment

Choose a reason for hiding this comment

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

Findings in PR.

public LegacyTagImporterConfig()
{
this(emptyList());
this(null, emptyList());
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Using "null" this way always makes my danger sense tingle. How about an "Optional".
Alternatively a extra method to see if the path is set so that you can avoid the null checks in the calling code?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

👍 Using Optional.

import java.nio.file.Path;
import java.util.List;

public class LegacyTagImporterConfig
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Add Java doc to all public classes and methods please.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

✔️

}

public LegacyTagImporterFactory(final List<PathConfig> pathConfigs)
public LegacyTagImporterFactory(final LegacyTagImporterConfig config)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why support two types of constructors that are so similar in effect but use different paradigms?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

✔️

return findConfig(path).isPresent();
}

private Optional<PathConfig> findConfig(final Path file)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You changed the parameter to "path" in the calling function but kept is as "file" here.
Suggest using "path" uniformly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

✔️

final Path relativePath = makeRelative(file);
return this.config.get().getPathConfigs().stream() //
.filter(config -> config.matches(relativePath)) //
.findFirst();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What happens if multiple match?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Wouldn't a hash map be more efficient here than iterating all path configs with each find?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

  • For multiple matches we take the first matching path.
  • We can't use a map because the matching logic is based on Java's path matcher.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Okay.

private Path makeRelative(final Path path)
{
final Path basePath = this.config.get().getBasePath();
if (basePath == null)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please add method to check if path is set instead of null check.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

✔️

{
return path;
}
return basePath.relativize(path);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does the match still work if the paths in the path config are provided absolute?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No. I created #127 to check for absolute paths.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Perfect. Thanks.

}

private Importer createImporter(final List<PathConfig> pathConfigs, final Path path)
private LegacyTagImporterConfig config(final PathConfig... pathConfigs)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please rename to "configure" to be in line with the Java naming standards.

Also to avoid mix-up of this method with variables of the same name.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

✔️


private LegacyTagImporterConfig config(final String basePath, final PathConfig... pathConfigs)
{
return new LegacyTagImporterConfig(basePath == null ? null : Paths.get(basePath),
Copy link
Copy Markdown
Collaborator

@redcatbear redcatbear Apr 1, 2018

Choose a reason for hiding this comment

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

The null values make this piece of code really hard to read. Especially without context.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

✔️

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 3, 2018

Codecov Report

Merging #123 into develop will increase coverage by 0.03%.
The diff coverage is 100%.

Impacted file tree graph

@@              Coverage Diff              @@
##             develop     #123      +/-   ##
=============================================
+ Coverage       92.6%   92.63%   +0.03%     
- Complexity       811      816       +5     
=============================================
  Files             81       81              
  Lines           2203     2214      +11     
  Branches         196      197       +1     
=============================================
+ Hits            2040     2051      +11     
  Misses           121      121              
  Partials          42       42
Impacted Files Coverage Δ Complexity Δ
...e/importer/legacytag/LegacyTagImporterFactory.java 72.22% <100%> (+9.25%) 11 <10> (+4) ⬆️
...ce/importer/legacytag/LegacyTagImporterConfig.java 100% <100%> (ø) 4 <2> (+1) ⬆️

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 7a7533d...92b02d1. Read the comment docs.

@kaklakariada kaklakariada dismissed redcatbear’s stale review April 4, 2018 17:43

@redcatbear approved the changes on the phone

@kaklakariada kaklakariada merged commit 8f72cc3 into develop Apr 4, 2018
@kaklakariada kaklakariada deleted the support_relative_path_configs branch April 4, 2018 17:44
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.

2 participants