-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Apply dependency injection
* chore: Add Dagger to dependencies and build * refactor: Split Cli class * feat: Rewrite custom command class factory to Dagger implementation * feat: Setup Dagger modules and components * feat: Boot app with Dagger * refactor: Extract state from command handler * refactor: Add convenience constructor * refactor: Follow-up * test: Rewrite tests * test: Make test independent of user timezone * chore: Formatting Closes #498, #192.
- Loading branch information
1 parent
4bab717
commit 390bf3d
Showing
31 changed files
with
873 additions
and
424 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package it.mulders.mcs.cli; | ||
|
||
import it.mulders.mcs.search.SearchCommandHandler; | ||
import it.mulders.mcs.search.SearchQuery; | ||
import jakarta.inject.Inject; | ||
import java.util.concurrent.Callable; | ||
import picocli.CommandLine; | ||
|
||
@CommandLine.Command( | ||
name = "class-search", | ||
description = "Search artifacts in Maven Central by class name", | ||
usageHelpAutoWidth = true) | ||
public class ClassSearchCommand implements Callable<Integer> { | ||
@CommandLine.Parameters( | ||
arity = "1", | ||
description = { | ||
"The class name to search for.", | ||
}) | ||
private String query; | ||
|
||
@CommandLine.Option( | ||
names = {"-f", "--full-name"}, | ||
negatable = true, | ||
arity = "0", | ||
description = "Class name includes package") | ||
private boolean fullName; | ||
|
||
@CommandLine.Option( | ||
names = {"-l", "--limit"}, | ||
description = "Show <count> results", | ||
paramLabel = "<count>") | ||
private Integer limit; | ||
|
||
private final SearchCommandHandler searchCommandHandler; | ||
|
||
@Inject | ||
public ClassSearchCommand(final SearchCommandHandler searchCommandHandler) { | ||
this.searchCommandHandler = searchCommandHandler; | ||
} | ||
|
||
// Visible for testing | ||
ClassSearchCommand(final SearchCommandHandler searchCommandHandler, String query, Integer limit, boolean fullName) { | ||
this(searchCommandHandler); | ||
this.fullName = fullName; | ||
this.limit = limit; | ||
this.query = query; | ||
} | ||
|
||
@Override | ||
public Integer call() { | ||
System.out.printf("Searching for artifacts containing %s...%n", query); | ||
var searchQuery = SearchQuery.classSearch(this.query) | ||
.isFullyQualified(this.fullName) | ||
.withLimit(limit) | ||
.build(); | ||
searchCommandHandler.search(searchQuery, "maven", false); | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package it.mulders.mcs.cli; | ||
|
||
import it.mulders.mcs.search.SearchCommandHandler; | ||
import it.mulders.mcs.search.SearchQuery; | ||
import jakarta.inject.Inject; | ||
import java.util.concurrent.Callable; | ||
import picocli.CommandLine; | ||
|
||
@CommandLine.Command( | ||
name = "search", | ||
description = "Search artifacts in Maven Central by coordinates", | ||
usageHelpAutoWidth = true) | ||
public class SearchCommand implements Callable<Integer> { | ||
@CommandLine.Parameters( | ||
arity = "1..n", | ||
description = { | ||
"What to search for.", | ||
"If the search term contains a colon ( : ), it is considered a literal groupId and artifactId", | ||
"Otherwise, the search term is considered a wildcard search" | ||
}) | ||
private String[] query; | ||
|
||
@CommandLine.Option( | ||
names = {"-l", "--limit"}, | ||
description = "Show <count> results", | ||
paramLabel = "<count>") | ||
private Integer limit; | ||
|
||
@CommandLine.Option( | ||
names = {"-f", "--format"}, | ||
description = | ||
""" | ||
Show result in <type> format | ||
Supported types are: | ||
maven, gradle, gradle-short, gradle-kotlin, sbt, ivy, grape, leiningen, buildr, jbang, gav | ||
""", | ||
paramLabel = "<type>") | ||
private String responseFormat; | ||
|
||
@CommandLine.Option( | ||
names = {"-s", "--show-vulnerabilities"}, | ||
description = "Show reported security vulnerabilities", | ||
paramLabel = "<vulnerabilities>") | ||
private boolean showVulnerabilities; | ||
|
||
private final SearchCommandHandler searchCommandHandler; | ||
|
||
@Inject | ||
public SearchCommand(final SearchCommandHandler searchCommandHandler) { | ||
this.searchCommandHandler = searchCommandHandler; | ||
} | ||
|
||
// Visible for testing | ||
SearchCommand( | ||
SearchCommandHandler searchCommandHandler, | ||
String[] query, | ||
Integer limit, | ||
String responseFormat, | ||
boolean showVulnerabilities) { | ||
this(searchCommandHandler); | ||
this.limit = limit; | ||
this.query = query; | ||
this.responseFormat = responseFormat; | ||
this.showVulnerabilities = showVulnerabilities; | ||
} | ||
|
||
@Override | ||
public Integer call() { | ||
var combinedQuery = String.join(" ", query); | ||
System.out.printf("Searching for %s...%n", combinedQuery); | ||
var searchQuery = | ||
SearchQuery.search(combinedQuery).withLimit(this.limit).build(); | ||
|
||
searchCommandHandler.search(searchQuery, responseFormat, showVulnerabilities); | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/main/java/it/mulders/mcs/common/McsExecutionExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.