Merge pull request #39 from ThomasRubini/intellij_warnings

This commit is contained in:
Thomas Rubini 2022-12-15 20:06:47 +01:00 committed by GitHub
commit b2e82c8d7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 89 additions and 92 deletions

View File

@ -5,22 +5,22 @@
PackageViewer permer de rechercher et de visualiser un paquet et les dependances du paquet pour une distribtion donnée. PackageViewer permer de rechercher et de visualiser un paquet et les dependances du paquet pour une distribtion donnée.
## Distribution supportées ## Distributions supportées
- Arch Linux (depots officiels) - Arch Linux (depots officiels)
- Fedora - Fedora
## Utilisation ## Utilisation
Pour utiliser notre projet vous pouvez cloner et build notre projet ou bien recuperer la [derniere build](https://nightly.link/ThomasRubini/PackageViewer/workflows/ci/main/PackageViewer%20jar.zip). Pour utiliser notre projet, vous pouvez cloner et build notre projet ou bien recuperer la [derniere build](https://nightly.link/ThomasRubini/PackageViewer/workflows/ci/main/PackageViewer%20jar.zip).
### parametres ### parametres
| parametre | description | | parametre | description |
| ----------- | ------------------------------------------------ | |------------------------------|--------------------------------------------------------|
| --help, -h | Affiche laide | | --help, -h | Affiche laide |
| --distro,-d <{distribution}> | Distribution linux dans la quelle rechercher le paquet | | --distro,-d <{distribution}> | Distribution linux dans la quelle rechercher le paquet |
| --depth <{profondeur}> | Profondeur de larbre de dependance a afficher | | --depth <{profondeur}> | Profondeur de larbre de dependance a afficher |
### Exemples ### Exemples
```java -jar PackageViewer.jar -d fedora neofetch``` ```java -jar PackageViewer.jar -d fedora neofetch```

View File

@ -17,7 +17,6 @@ public class ArgParse {
* Get the command line argument given by the user, parse it with the parser and store it in the corresponding variable * Get the command line argument given by the user, parse it with the parser and store it in the corresponding variable
* @author Capelier-Marla * @author Capelier-Marla
* @param args the command line arguments given by the user * @param args the command line arguments given by the user
* @return void
*/ */
static void parseArguments(String[] args) { static void parseArguments(String[] args) {
// create JCommander and CommandLineParams objects // create JCommander and CommandLineParams objects
@ -48,7 +47,7 @@ public class ArgParse {
} }
/** /**
* Get the distribution name. If the user didn't give any or we didn't parsed, return null * Get the distribution name. If the user didn't give any or if we didn't parse it, return null
* @author Capelier-Marla * @author Capelier-Marla
* @return String: the distribution name * @return String: the distribution name
*/ */

View File

@ -19,8 +19,7 @@ public class CommandLineParams {
* Distribution the user want to search packages in * Distribution the user want to search packages in
*/ */
@Parameter(names = {"--distro", "-d"}, @Parameter(names = {"--distro", "-d"},
description = "Linux distribution to search in", description = "Linux distribution to search in")
required = false)
public String distribution; public String distribution;
/** /**
@ -28,7 +27,6 @@ public class CommandLineParams {
*/ */
@Parameter(names = {"--help", "-h"}, @Parameter(names = {"--help", "-h"},
description = "Display this help", description = "Display this help",
help = true, help = true)
required = false)
public boolean help = false; public boolean help = false;
} }

View File

@ -1,14 +1,14 @@
package fr.packageviewer; package fr.packageviewer;
import java.util.ArrayList;
import java.util.List;
import fr.packageviewer.distribution.ArchDistribution; import fr.packageviewer.distribution.ArchDistribution;
import fr.packageviewer.distribution.Distribution; import fr.packageviewer.distribution.Distribution;
import fr.packageviewer.distribution.FedoraDistribution; import fr.packageviewer.distribution.FedoraDistribution;
import java.util.ArrayList;
import java.util.List;
/** /**
* Enum containing contructors for each distribution to get them by their name * Enum containing distribution information to get them by their name
* @author Capelier-Marla * @author Capelier-Marla
*/ */
public enum DistributionEnum { public enum DistributionEnum {
@ -16,13 +16,13 @@ public enum DistributionEnum {
FEDORA("fedora", new FedoraDistribution()), FEDORA("fedora", new FedoraDistribution()),
; ;
private String name; private final String name;
private Distribution distributionConstructor; private final Distribution distributionConstructor;
/** /**
* Contructor for enums * Constructor for enums
* @param name * @param name the name of the distribution
* @param distributionConstructor * @param distributionConstructor the instance of the distribution
* @author Capelier-Marla * @author Capelier-Marla
*/ */
DistributionEnum(String name, Distribution distributionConstructor) { DistributionEnum(String name, Distribution distributionConstructor) {
@ -36,8 +36,8 @@ public enum DistributionEnum {
* @return the instance of the distribution requested * @return the instance of the distribution requested
* @author Capelier-Marla * @author Capelier-Marla
*/ */
public static Distribution getDistributionContructorByName(String name) { public static Distribution getDistributionConstructorByName(String name) {
// loop for all ditributions stored in enum // loop for all distributions stored in enum
for(var distrib : values()) { for(var distrib : values()) {
// return the instance if it's the same as enum name // return the instance if it's the same as enum name
if(distrib.name.equals(name)) { if(distrib.name.equals(name)) {
@ -49,14 +49,14 @@ public enum DistributionEnum {
/** /**
* Get all distribution instances available in this enum * Get all distribution instances available in this enum
* @return the set of distribution instances * @return the list of distribution instances
*/ */
public static List<Distribution> getAllDistributionsInstances() { public static List<Distribution> getAllDistributionsInstances() {
// create the set that will be returned // create the set that will be returned
List<Distribution> result = new ArrayList<>(); List<Distribution> result = new ArrayList<>();
// add all the distribution instances in the set // add all the distribution instances in the set
for(var ditrib : values()) { for(var distrib : values()) {
result.add(ditrib.distributionConstructor); result.add(distrib.distributionConstructor);
} }
return result; return result;
} }

View File

@ -37,7 +37,7 @@ public class LoggerManager {
Logger logger = Logger.getLogger(name); Logger logger = Logger.getLogger(name);
logger.setLevel(level); logger.setLevel(level);
// create an hanlder for standard error and add it to the logger // create a handler for standard error and add it to the logger
Handler handler = new StreamHandler(System.err, new SimpleFormatter()); Handler handler = new StreamHandler(System.err, new SimpleFormatter());
logger.addHandler(handler); logger.addHandler(handler);

View File

@ -1,12 +1,12 @@
package fr.packageviewer; package fr.packageviewer;
import java.util.List;
import fr.packageviewer.frontend.Frontend; import fr.packageviewer.frontend.Frontend;
import fr.packageviewer.frontend.FrontendFactory; import fr.packageviewer.frontend.FrontendFactory;
import fr.packageviewer.pack.Package; import fr.packageviewer.pack.Package;
import fr.packageviewer.pack.SearchedPackage; import fr.packageviewer.pack.SearchedPackage;
import java.util.List;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
@ -27,10 +27,10 @@ public class Main {
// ask the user to select the package to see in details and store its name // ask the user to select the package to see in details and store its name
SearchedPackage searchedPacketName = frontend.askUserToChoosePackage(packets); SearchedPackage searchedPacketName = frontend.askUserToChoosePackage(packets);
// get all informations about the package by searching it in details // get all information about the package by searching it in details
Package packet = searcher.getPackage(searchedPacketName); Package packet = searcher.getPackage(searchedPacketName);
// show all informations about a packet // show all information about a packet
frontend.showPackageTree(packet, 0); frontend.showPackageTree(packet, 0);
} }
} }

View File

@ -65,9 +65,9 @@ public class Pair<K, V> {
} }
/** /**
* Returns a string reprensentation of the pair * Returns a string representation of the pair
* *
* @return String, string reprensentation of the pair * @return String, string representation of the pair
*/ */
@Override @Override
public String toString() { public String toString() {

View File

@ -1,25 +1,25 @@
package fr.packageviewer; package fr.packageviewer;
import fr.packageviewer.distribution.Distribution;
import fr.packageviewer.pack.Package;
import fr.packageviewer.pack.SearchedPackage;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import fr.packageviewer.distribution.Distribution;
import fr.packageviewer.pack.SearchedPackage;
import fr.packageviewer.pack.Package;
public class Searcher { public class Searcher {
private String distributionName = null; private String distributionName;
public Searcher(String distributionName) { public Searcher(String distributionName) {
this.distributionName = distributionName; this.distributionName = distributionName;
} }
/** /**
* Get the list of all packages in the distribution setted before * Get the list of all packages in the distribution set before
* @param packageName the name of the package wanted * @param packageName the name of the package wanted
* @return the list of all packages found * @return the list of all packages found
* @author Capelier-Marla * @author Capelier-Marla
@ -31,7 +31,7 @@ public class Searcher {
if(distributionName == null) { if(distributionName == null) {
distributions = DistributionEnum.getAllDistributionsInstances(); distributions = DistributionEnum.getAllDistributionsInstances();
} else { } else {
distributions = Collections.singletonList(DistributionEnum.getDistributionContructorByName(distributionName)); distributions = Collections.singletonList(DistributionEnum.getDistributionConstructorByName(distributionName));
if(distributions.get(0) == null) { if(distributions.get(0) == null) {
System.out.println("Distribution non trouvée"); System.out.println("Distribution non trouvée");
System.exit(0); System.exit(0);
@ -65,7 +65,7 @@ public class Searcher {
distributionName = packetInput.getDistribution(); distributionName = packetInput.getDistribution();
} }
String packageName = packetInput.getName(); String packageName = packetInput.getName();
Distribution distribution = DistributionEnum.getDistributionContructorByName(distributionName); Distribution distribution = DistributionEnum.getDistributionConstructorByName(distributionName);
Future<Package> futurePacket = distribution.getPackageTree(packageName, 4); Future<Package> futurePacket = distribution.getPackageTree(packageName, 4);
Package packet = null; Package packet = null;
try { try {

View File

@ -1,19 +1,20 @@
package fr.packageviewer.distribution; package fr.packageviewer.distribution;
import java.io.IOException;
import java.net.URI;
import java.util.*;
import java.net.http.*;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Logger;
import fr.packageviewer.LoggerManager; import fr.packageviewer.LoggerManager;
import fr.packageviewer.Pair; import fr.packageviewer.Pair;
import fr.packageviewer.pack.Package; import fr.packageviewer.pack.Package;
import fr.packageviewer.pack.SearchedPackage; import fr.packageviewer.pack.SearchedPackage;
import fr.packageviewer.parser.AsyncRequestsParser; import fr.packageviewer.parser.AsyncRequestsParser;
import org.json.*; import org.json.JSONArray;
import org.json.JSONObject;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Logger;
/** /**
* This class handles package requests for Arch linux. All return objects in * This class handles package requests for Arch linux. All return objects in
@ -31,12 +32,12 @@ public class ArchDistribution extends AsyncRequestsParser implements Distributio
/** /**
* This method remove all characters in the first string passed as * This method remove all characters in the first string passed as
* parametter after one of the character in the second string if found * parameter after one of the character in the second string if found
* in the first string * in the first string
* *
* @param str String, the string to trim * @param str String, the string to trim
* @param trimAfterCharacters String, the character that delimits our string * @param trimAfterCharacters String, the character that delimits our string
* @return * @return the string after being trimmed
*/ */
private static String trimAfterCharacters(String str, String trimAfterCharacters) { private static String trimAfterCharacters(String str, String trimAfterCharacters) {
for (char c : trimAfterCharacters.toCharArray()) { for (char c : trimAfterCharacters.toCharArray()) {
@ -50,14 +51,14 @@ public class ArchDistribution extends AsyncRequestsParser implements Distributio
/** /**
* This function return a package from arch package api in the form of a Pair * This function return a package from arch package api in the form of a Pair
* Composed of a Package object, and a set of string containing the names of * Composed of a Package object, and a set of string containing the names of
* the dependecies of the package. * the dependencies of the package.
* *
* @param packageName String, The package's exact name * @param packageName String, The package's exact name
* @return Pair of Package and Set of String * @return Pair of Package and Set of String
*/ */
@Override @Override
public CompletableFuture<Pair<Package, Set<String>>> getPackageFromAPI(String packageName) { public CompletableFuture<Pair<Package, Set<String>>> getPackageFromAPI(String packageName) {
// create a new http client and he request for arch reseach api // create a new http client and make a request to the arch research api
HttpClient client = HttpClient.newHttpClient(); HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest HttpRequest request = HttpRequest
.newBuilder(URI.create("https://archlinux.org/packages/search/json/?name=" + packageName)).build(); .newBuilder(URI.create("https://archlinux.org/packages/search/json/?name=" + packageName)).build();
@ -77,7 +78,7 @@ public class ArchDistribution extends AsyncRequestsParser implements Distributio
} }
JSONObject resultJson = resultsArrayJson.getJSONObject(0); JSONObject resultJson = resultsArrayJson.getJSONObject(0);
Set<String> dependenciesNames = new HashSet<>(); Set<String> dependenciesNames = new HashSet<>();
// parse depencies without version requirements (bash >= 3.0) -> (bash) // parse dependencies without version requirements (bash >= 3.0) -> (bash)
for (Object dependency : resultJson.getJSONArray("depends")) { for (Object dependency : resultJson.getJSONArray("depends")) {
dependenciesNames.add(trimAfterCharacters((String) dependency, "<>=")); dependenciesNames.add(trimAfterCharacters((String) dependency, "<>="));
} }

View File

@ -4,11 +4,10 @@ import fr.packageviewer.pack.Package;
import fr.packageviewer.pack.SearchedPackage; import fr.packageviewer.pack.SearchedPackage;
import java.util.List; import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future; import java.util.concurrent.Future;
/** /**
* This interface specifies the methods needed by a distribtion to be parsable. * This interface specifies the methods needed by a distribution to be parsable.
* *
* @author R.Thomas * @author R.Thomas
* @version 1.0 * @version 1.0
@ -25,10 +24,10 @@ public interface Distribution {
/** /**
* This function returns a fully completed package containing all * This function returns a fully completed package containing all
* information about the package identified by it's exact name passed as * information about the package identified by its exact name passed as
* parametter, the package contains in its dependency list fully formed * parameter, the package contains in its dependency list fully formed
* packages that also contains its dependencies, the dependency depth is * packages that also contains its dependencies, the dependency depth is
* specified by the parametter with the same name. * specified by the parameter with the same name.
* *
* @param packageName String, The package's exact name * @param packageName String, The package's exact name
* @param depth int, the depth of the dependency tree * @param depth int, the depth of the dependency tree

View File

@ -1,18 +1,19 @@
package fr.packageviewer.distribution; package fr.packageviewer.distribution;
import java.net.URI; import fr.packageviewer.LoggerManager;
import java.util.*;
import java.net.http.*;
import fr.packageviewer.Pair; import fr.packageviewer.Pair;
import fr.packageviewer.parser.AsyncRequestsParser;
import org.json.*;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Logger;
import fr.packageviewer.pack.Package; import fr.packageviewer.pack.Package;
import fr.packageviewer.pack.SearchedPackage; import fr.packageviewer.pack.SearchedPackage;
import fr.packageviewer.LoggerManager; import fr.packageviewer.parser.AsyncRequestsParser;
import org.json.JSONObject;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Logger;
/** /**
* This class handles package requests for Fedora. All return objects in * This class handles package requests for Fedora. All return objects in
@ -31,7 +32,7 @@ public class FedoraDistribution extends AsyncRequestsParser implements Distribut
/** /**
* This function return a package from Fedora metadata api in the form of a * This function return a package from Fedora metadata api in the form of a
* Pair Composed of a Package object, and a set of string containing the * Pair Composed of a Package object, and a set of string containing the
* names of the dependecies of the package. * names of the dependencies of the package.
* *
* @param packageName String, The package's exact name * @param packageName String, The package's exact name
* @return Pair of Package and Set of String * @return Pair of Package and Set of String
@ -99,7 +100,7 @@ public class FedoraDistribution extends AsyncRequestsParser implements Distribut
*/ */
@Override @Override
public CompletableFuture<List<SearchedPackage>> searchPackage(String packageName) { public CompletableFuture<List<SearchedPackage>> searchPackage(String packageName) {
// create an http client and the request for fedora's reseach api // create a new http client and make a request to the fedora research api
HttpClient client = HttpClient.newHttpClient(); HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder() HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create( .uri(URI.create(

View File

@ -1,10 +1,10 @@
package fr.packageviewer.frontend; package fr.packageviewer.frontend;
import java.util.List;
import fr.packageviewer.pack.Package; import fr.packageviewer.pack.Package;
import fr.packageviewer.pack.SearchedPackage; import fr.packageviewer.pack.SearchedPackage;
import java.util.List;
public interface Frontend { public interface Frontend {
SearchedPackage askUserToChoosePackage(List<SearchedPackage> packets); SearchedPackage askUserToChoosePackage(List<SearchedPackage> packets);
void showPackageTree(Package packet, int depth); void showPackageTree(Package packet, int depth);

View File

@ -1,11 +1,11 @@
package fr.packageviewer.frontend; package fr.packageviewer.frontend;
import java.util.List;
import java.util.Scanner;
import fr.packageviewer.pack.Package; import fr.packageviewer.pack.Package;
import fr.packageviewer.pack.SearchedPackage; import fr.packageviewer.pack.SearchedPackage;
import java.util.List;
import java.util.Scanner;
public class FrontendTerminal implements Frontend{ public class FrontendTerminal implements Frontend{
/** /**

View File

@ -1,7 +1,6 @@
package fr.packageviewer.pack; package fr.packageviewer.pack;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
/** /**
@ -12,21 +11,21 @@ import java.util.List;
*/ */
public class Package extends SearchedPackage { public class Package extends SearchedPackage {
/** /**
* List of package storing all of the dependencies of the package * List of package storing all the dependencies of the package
*/ */
private final List<Package> deps; private final List<Package> deps;
/** /**
* Getter for the deps attribute * Getter for the deps attribute
* *
* @return List, List of package storing all of the dependencies of the package * @return List, List of package storing all the dependencies of the package
*/ */
public List<Package> getDeps() { public List<Package> getDeps() {
return deps; return deps;
} }
/** /**
* This method adds to the dependency list the package passed as parametter. * This method adds to the dependency list the package passed as parameter.
* *
* @param pack Package, the package to add as dependency * @param pack Package, the package to add as dependency
*/ */
@ -67,9 +66,9 @@ public class Package extends SearchedPackage {
} }
/** /**
* Returns a string reprensentation of the package * Returns a string representation of the package
* *
* @return String, string reprensentation of the package * @return String, string representation of the package
*/ */
@Override @Override
public String toString() { public String toString() {

View File

@ -93,9 +93,9 @@ public class SearchedPackage {
} }
/** /**
* Returns a string reprensentation of the package * Returns a string representation of the package
* *
* @return String, string reprensentation of the package * @return String, string representation of the package
*/ */
@Override @Override
public String toString() { public String toString() {

View File

@ -14,7 +14,7 @@ import java.util.logging.Logger;
/** /**
* This abstract class defines the method that a distribution will use * This abstract class defines the method that a distribution will use
* in order to get a package and fill its dependency list. It does all that * in order to get a package and fill its dependency list. It does all that
* in an asyncron manner * in an asynchronous manner
* *
* @author R.Thomas * @author R.Thomas
* @version 1.0 * @version 1.0
@ -29,19 +29,19 @@ public abstract class AsyncRequestsParser {
/** /**
* This function returns a package from the distribution's api in the form * This function returns a package from the distribution's api in the form
* of a Pair Composed of a Package object and a set of string containing * of a Pair Composed of a Package object and a set of string containing
* the names of the dependecies of the package. * the names of the dependencies of the package.
* *
* @param packageName String, The package's exact name * @param packageName String, The package's exact name
* @return Pair of Package and Set of String * @return Pair of Package and Set of String
*/ */
protected abstract CompletableFuture<Pair<Package, Set<String>>> getPackageFromAPI(String name); protected abstract CompletableFuture<Pair<Package, Set<String>>> getPackageFromAPI(String packageName);
/** /**
* This function returns a fully completed package containing all * This function returns a fully completed package containing all
* information about the package identified by it's exact name passed as * information about the package identified by its exact name passed as
* parametter, the package contains in its dependency list fully formed * parameter, the package contains in its dependency list fully formed
* packages that also contains its dependencies, the dependency depth is * packages that also contains its dependencies, the dependency depth is
* specified by the parametter with the same name. * specified by the parameter with the same name.
* *
* @param packageName String, The package's exact name * @param packageName String, The package's exact name
* @param depth int, the depth of the dependency tree * @param depth int, the depth of the dependency tree
@ -87,7 +87,7 @@ public abstract class AsyncRequestsParser {
futureDeps.add(getPackageTree(depPackageName, depth - 1)); futureDeps.add(getPackageTree(depPackageName, depth - 1));
} }
// for each future in the list, get the actual package and store // for each future in the list, get the actual package and store
// into the deps list of the packaqge // into the deps list of the package
for (CompletableFuture<Package> future : futureDeps) { for (CompletableFuture<Package> future : futureDeps) {
Package dep; Package dep;
try { try {