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.
## Distribution supportées
## Distributions supportées
- Arch Linux (depots officiels)
- Fedora
## 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
| parametre | description |
| ----------- | ------------------------------------------------ |
| --help, -h | Affiche laide |
| parametre | description |
|------------------------------|--------------------------------------------------------|
| --help, -h | Affiche laide |
| --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
```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
* @author Capelier-Marla
* @param args the command line arguments given by the user
* @return void
*/
static void parseArguments(String[] args) {
// 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
* @return String: the distribution name
*/

View File

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

View File

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

View File

@ -37,7 +37,7 @@ public class LoggerManager {
Logger logger = Logger.getLogger(name);
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());
logger.addHandler(handler);

View File

@ -1,12 +1,12 @@
package fr.packageviewer;
import java.util.List;
import fr.packageviewer.frontend.Frontend;
import fr.packageviewer.frontend.FrontendFactory;
import fr.packageviewer.pack.Package;
import fr.packageviewer.pack.SearchedPackage;
import java.util.List;
public class Main {
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
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);
// show all informations about a packet
// show all information about a packet
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
public String toString() {

View File

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

View File

@ -1,19 +1,20 @@
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.Pair;
import fr.packageviewer.pack.Package;
import fr.packageviewer.pack.SearchedPackage;
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
@ -31,12 +32,12 @@ public class ArchDistribution extends AsyncRequestsParser implements Distributio
/**
* 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
*
* @param str String, the string to trim
* @param trimAfterCharacters String, the character that delimits our string
* @return
* @return the string after being trimmed
*/
private static String trimAfterCharacters(String str, String trimAfterCharacters) {
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
* 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
* @return Pair of Package and Set of String
*/
@Override
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();
HttpRequest request = HttpRequest
.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);
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")) {
dependenciesNames.add(trimAfterCharacters((String) dependency, "<>="));
}

View File

@ -4,11 +4,10 @@ import fr.packageviewer.pack.Package;
import fr.packageviewer.pack.SearchedPackage;
import java.util.List;
import java.util.concurrent.CompletableFuture;
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
* @version 1.0
@ -25,10 +24,10 @@ public interface Distribution {
/**
* This function returns a fully completed package containing all
* information about the package identified by it's exact name passed as
* parametter, the package contains in its dependency list fully formed
* information about the package identified by its exact name passed as
* parameter, the package contains in its dependency list fully formed
* 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 depth int, the depth of the dependency tree

View File

@ -1,18 +1,19 @@
package fr.packageviewer.distribution;
import java.net.URI;
import java.util.*;
import java.net.http.*;
import fr.packageviewer.LoggerManager;
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.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
@ -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
* 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
* @return Pair of Package and Set of String
@ -99,7 +100,7 @@ public class FedoraDistribution extends AsyncRequestsParser implements Distribut
*/
@Override
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();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(

View File

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

View File

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

View File

@ -1,7 +1,6 @@
package fr.packageviewer.pack;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
@ -12,21 +11,21 @@ import java.util.List;
*/
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;
/**
* 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() {
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
*/
@ -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
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
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
* 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
* @version 1.0
@ -29,19 +29,19 @@ public abstract class AsyncRequestsParser {
/**
* 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
* the names of the dependecies of the package.
* the names of the dependencies of the package.
*
* @param packageName String, The package's exact name
* @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
* information about the package identified by it's exact name passed as
* parametter, the package contains in its dependency list fully formed
* information about the package identified by its exact name passed as
* parameter, the package contains in its dependency list fully formed
* 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 depth int, the depth of the dependency tree
@ -87,7 +87,7 @@ public abstract class AsyncRequestsParser {
futureDeps.add(getPackageTree(depPackageName, depth - 1));
}
// 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) {
Package dep;
try {