sonatype-lift[bot] commented on code in PR #1600:
URL: https://github.com/apache/solr/pull/1600#discussion_r1181233661
##########
solr/core/src/java/org/apache/solr/cli/PackageTool.java:
##########
@@ -86,204 +93,153 @@ public void runImpl(CommandLine cli) throws Exception {
}
log.info("ZK: {}", zkHost);
- String cmd = cli.getArgList().size() == 0 ? "help" : cli.getArgs()[0];
try (SolrClient solrClient = new
Http2SolrClient.Builder(solrBaseUrl).build()) {
- if (cmd != null) {
- packageManager = new PackageManager(solrClient, solrBaseUrl, zkHost);
- try {
- repositoryManager = new RepositoryManager(solrClient,
packageManager);
+ packageManager = new PackageManager(solrClient, solrBaseUrl, zkHost);
+ try {
+ repositoryManager = new RepositoryManager(solrClient,
packageManager);
- switch (cmd) {
- case "add-repo":
- String repoName = cli.getArgs()[1];
- String repoUrl = cli.getArgs()[2];
- repositoryManager.addRepository(repoName, repoUrl);
- PackageUtils.printGreen("Added repository: " + repoName);
- break;
- case "add-key":
- String keyFilename = cli.getArgs()[1];
- Path path = Path.of(keyFilename);
- repositoryManager.addKey(Files.readAllBytes(path),
path.getFileName().toString());
- break;
- case "list-installed":
- PackageUtils.printGreen("Installed packages:\n-----");
- for (SolrPackageInstance pkg :
packageManager.fetchInstalledPackageInstances()) {
- PackageUtils.printGreen(pkg);
+ switch (cmd) {
+ case "add-repo":
+ String repoName = cli.getArgs()[1];
+ String repoUrl = cli.getArgs()[2];
+ repositoryManager.addRepository(repoName, repoUrl);
+ PackageUtils.printGreen("Added repository: " + repoName);
+ break;
+ case "add-key":
+ String keyFilename = cli.getArgs()[1];
+ Path path = Path.of(keyFilename);
+ repositoryManager.addKey(Files.readAllBytes(path),
path.getFileName().toString());
+ break;
+ case "list-installed":
+ PackageUtils.printGreen("Installed packages:\n-----");
+ for (SolrPackageInstance pkg :
packageManager.fetchInstalledPackageInstances()) {
+ PackageUtils.printGreen(pkg);
+ }
+ break;
+ case "list-available":
+ PackageUtils.printGreen("Available packages:\n-----");
+ for (SolrPackage pkg : repositoryManager.getPackages()) {
+ PackageUtils.printGreen(pkg.name + " \t\t" + pkg.description);
+ for (SolrPackageRelease version : pkg.versions) {
+ PackageUtils.printGreen("\tVersion: " + version.version);
}
- break;
- case "list-available":
- PackageUtils.printGreen("Available packages:\n-----");
- for (SolrPackage pkg : repositoryManager.getPackages()) {
- PackageUtils.printGreen(pkg.name + " \t\t" +
pkg.description);
- for (SolrPackageRelease version : pkg.versions) {
- PackageUtils.printGreen("\tVersion: " + version.version);
- }
+ }
+ break;
+ case "list-deployed":
+ if (cli.hasOption('c')) {
+ String collection = cli.getArgs()[1];
+ Map<String, SolrPackageInstance> packages =
+ packageManager.getPackagesDeployed(collection);
+ PackageUtils.printGreen("Packages deployed on " + collection +
":");
+ for (String packageName : packages.keySet()) {
+ PackageUtils.printGreen("\t" + packages.get(packageName));
}
- break;
- case "list-deployed":
- if (cli.hasOption('c')) {
- String collection = cli.getArgs()[1];
- Map<String, SolrPackageInstance> packages =
- packageManager.getPackagesDeployed(collection);
- PackageUtils.printGreen("Packages deployed on " + collection
+ ":");
- for (String packageName : packages.keySet()) {
- PackageUtils.printGreen("\t" + packages.get(packageName));
- }
- } else {
- String packageName = cli.getArgs()[1];
- Map<String, String> deployedCollections =
- packageManager.getDeployedCollections(packageName);
- if (deployedCollections.isEmpty() == false) {
+ } else {
+ String packageName = cli.getArgs()[1];
+ Map<String, String> deployedCollections =
+ packageManager.getDeployedCollections(packageName);
+ if (!deployedCollections.isEmpty()) {
+ PackageUtils.printGreen(
+ "Collections on which package " + packageName + " was
deployed:");
+ for (String collection : deployedCollections.keySet()) {
PackageUtils.printGreen(
- "Collections on which package " + packageName + " was
deployed:");
- for (String collection : deployedCollections.keySet()) {
- PackageUtils.printGreen(
- "\t"
- + collection
- + "("
- + packageName
- + ":"
- + deployedCollections.get(collection)
- + ")");
- }
- } else {
- PackageUtils.printGreen(
- "Package " + packageName + " not deployed on any
collection.");
+ "\t"
+ + collection
+ + "("
+ + packageName
+ + ":"
+ + deployedCollections.get(collection)
Review Comment:
<picture><img alt="13% of developers fix this issue"
src="https://lift.sonatype.com/api/commentimage/fixrate/13/display.svg"></picture>
<b>*INEFFICIENT_KEYSET_ITERATOR:</b>* Accessing a value using a key that
was retrieved from a `keySet` iterator. It is more efficient to use an iterator
on the `entrySet` of the map, avoiding the extra `HashMap.get(key)` lookup.
---
<details><summary>ℹ️ Expand to see all <b>@sonatype-lift</b>
commands</summary>
You can reply with the following commands. For example, reply with
***@sonatype-lift ignoreall*** to leave out all findings.
| **Command** | **Usage** |
| ------------- | ------------- |
| `@sonatype-lift ignore` | Leave out the above finding from this PR |
| `@sonatype-lift ignoreall` | Leave out all the existing findings from this
PR |
| `@sonatype-lift exclude <file\|issue\|path\|tool>` | Exclude specified
`file\|issue\|path\|tool` from Lift findings by updating your config.toml file |
**Note:** When talking to LiftBot, you need to **refresh** the page to see
its response.
<sub>[Click here](https://github.com/apps/sonatype-lift/installations/new)
to add LiftBot to another repo.</sub></details>
##########
solr/core/src/java/org/apache/solr/cli/PackageTool.java:
##########
@@ -86,204 +93,153 @@ public void runImpl(CommandLine cli) throws Exception {
}
log.info("ZK: {}", zkHost);
- String cmd = cli.getArgList().size() == 0 ? "help" : cli.getArgs()[0];
try (SolrClient solrClient = new
Http2SolrClient.Builder(solrBaseUrl).build()) {
- if (cmd != null) {
- packageManager = new PackageManager(solrClient, solrBaseUrl, zkHost);
- try {
- repositoryManager = new RepositoryManager(solrClient,
packageManager);
+ packageManager = new PackageManager(solrClient, solrBaseUrl, zkHost);
+ try {
+ repositoryManager = new RepositoryManager(solrClient,
packageManager);
- switch (cmd) {
- case "add-repo":
- String repoName = cli.getArgs()[1];
- String repoUrl = cli.getArgs()[2];
- repositoryManager.addRepository(repoName, repoUrl);
- PackageUtils.printGreen("Added repository: " + repoName);
- break;
- case "add-key":
- String keyFilename = cli.getArgs()[1];
- Path path = Path.of(keyFilename);
- repositoryManager.addKey(Files.readAllBytes(path),
path.getFileName().toString());
- break;
- case "list-installed":
- PackageUtils.printGreen("Installed packages:\n-----");
- for (SolrPackageInstance pkg :
packageManager.fetchInstalledPackageInstances()) {
- PackageUtils.printGreen(pkg);
+ switch (cmd) {
+ case "add-repo":
+ String repoName = cli.getArgs()[1];
+ String repoUrl = cli.getArgs()[2];
+ repositoryManager.addRepository(repoName, repoUrl);
+ PackageUtils.printGreen("Added repository: " + repoName);
+ break;
+ case "add-key":
+ String keyFilename = cli.getArgs()[1];
+ Path path = Path.of(keyFilename);
+ repositoryManager.addKey(Files.readAllBytes(path),
path.getFileName().toString());
+ break;
+ case "list-installed":
+ PackageUtils.printGreen("Installed packages:\n-----");
+ for (SolrPackageInstance pkg :
packageManager.fetchInstalledPackageInstances()) {
+ PackageUtils.printGreen(pkg);
+ }
+ break;
+ case "list-available":
+ PackageUtils.printGreen("Available packages:\n-----");
+ for (SolrPackage pkg : repositoryManager.getPackages()) {
+ PackageUtils.printGreen(pkg.name + " \t\t" + pkg.description);
+ for (SolrPackageRelease version : pkg.versions) {
+ PackageUtils.printGreen("\tVersion: " + version.version);
}
- break;
- case "list-available":
- PackageUtils.printGreen("Available packages:\n-----");
- for (SolrPackage pkg : repositoryManager.getPackages()) {
- PackageUtils.printGreen(pkg.name + " \t\t" +
pkg.description);
- for (SolrPackageRelease version : pkg.versions) {
- PackageUtils.printGreen("\tVersion: " + version.version);
- }
+ }
+ break;
+ case "list-deployed":
+ if (cli.hasOption('c')) {
+ String collection = cli.getArgs()[1];
+ Map<String, SolrPackageInstance> packages =
+ packageManager.getPackagesDeployed(collection);
+ PackageUtils.printGreen("Packages deployed on " + collection +
":");
+ for (String packageName : packages.keySet()) {
+ PackageUtils.printGreen("\t" + packages.get(packageName));
Review Comment:
<picture><img alt="13% of developers fix this issue"
src="https://lift.sonatype.com/api/commentimage/fixrate/13/display.svg"></picture>
<b>*INEFFICIENT_KEYSET_ITERATOR:</b>* Accessing a value using a key that
was retrieved from a `keySet` iterator. It is more efficient to use an iterator
on the `entrySet` of the map, avoiding the extra `HashMap.get(key)` lookup.
---
<details><summary>ℹ️ Expand to see all <b>@sonatype-lift</b>
commands</summary>
You can reply with the following commands. For example, reply with
***@sonatype-lift ignoreall*** to leave out all findings.
| **Command** | **Usage** |
| ------------- | ------------- |
| `@sonatype-lift ignore` | Leave out the above finding from this PR |
| `@sonatype-lift ignoreall` | Leave out all the existing findings from this
PR |
| `@sonatype-lift exclude <file\|issue\|path\|tool>` | Exclude specified
`file\|issue\|path\|tool` from Lift findings by updating your config.toml file |
**Note:** When talking to LiftBot, you need to **refresh** the page to see
its response.
<sub>[Click here](https://github.com/apps/sonatype-lift/installations/new)
to add LiftBot to another repo.</sub></details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]