From 279ad638917b00eef4715344ebe31527b2122471 Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Wed, 14 Dec 2022 12:01:29 +0100 Subject: [PATCH 01/12] added correct documentation for the ArchDistribution class --- .../distribution/ArchDistribution.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/java/fr/packageviewer/distribution/ArchDistribution.java b/src/main/java/fr/packageviewer/distribution/ArchDistribution.java index d3a6725..7f560e8 100644 --- a/src/main/java/fr/packageviewer/distribution/ArchDistribution.java +++ b/src/main/java/fr/packageviewer/distribution/ArchDistribution.java @@ -15,14 +15,24 @@ import fr.packageviewer.pack.SearchedPackage; import fr.packageviewer.parser.AsyncRequestsParser; import org.json.*; +/** + * This class handles package requests for Arch linux. All return objects in + * this class are wrapped by a CompletableFuture to ensure async workload. + * + * @author C.Marla, R.Thomas + * @version 1.0 + */ public class ArchDistribution extends AsyncRequestsParser implements Distribution { private static final Logger logger = LoggerManager.getLogger("ArchDistribution"); /** - * Will return the String json of the package from the Arch Linux API - * @param packageName the package name to get the json from - * @return json of the package + * 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. + * + * @param packageName String, The package's exact name + * @return Pair of Package and Set of String */ @Override @@ -72,9 +82,11 @@ public CompletableFuture>> getPackageFromAPI(String pa } /** - * Search for a package and return a list of packages - * @param packageName the package name to search - * @return + * Search for a package matching a pattern and return a list of packages and + * return a list of string matching this pattern. + * + * @param packageName String, the pattern to search in the repositories + * @return List of SearchedPackage objects */ public CompletableFuture> searchPackage(String packageName){ HttpClient client = HttpClient.newHttpClient(); From a97aa19fef227b39e8dccb6d408ea6347b8734c6 Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Wed, 14 Dec 2022 12:05:00 +0100 Subject: [PATCH 02/12] fixed indentation --- .../distribution/ArchDistribution.java | 132 +++++++++--------- 1 file changed, 64 insertions(+), 68 deletions(-) diff --git a/src/main/java/fr/packageviewer/distribution/ArchDistribution.java b/src/main/java/fr/packageviewer/distribution/ArchDistribution.java index 7f560e8..4d8585b 100644 --- a/src/main/java/fr/packageviewer/distribution/ArchDistribution.java +++ b/src/main/java/fr/packageviewer/distribution/ArchDistribution.java @@ -19,84 +19,83 @@ import org.json.*; * This class handles package requests for Arch linux. All return objects in * this class are wrapped by a CompletableFuture to ensure async workload. * - * @author C.Marla, R.Thomas - * @version 1.0 + * @author C.Marla, R.Thomas + * @version 1.0 */ public class ArchDistribution extends AsyncRequestsParser implements Distribution { private static final Logger logger = LoggerManager.getLogger("ArchDistribution"); -/** - * 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. - * - * @param packageName String, The package's exact name - * @return Pair of Package and Set of String - */ + /** + * 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. + * + * @param packageName String, The package's exact name + * @return Pair of Package and Set of String + */ -@Override -public CompletableFuture>> getPackageFromAPI(String packageName) { - // create a new http client - HttpClient client = HttpClient.newHttpClient(); - // and create its url - HttpRequest request = HttpRequest.newBuilder(URI.create("https://archlinux.org/packages/search/json/?name="+packageName)).build(); + @Override + public CompletableFuture>> getPackageFromAPI(String packageName) { + // create a new http client + HttpClient client = HttpClient.newHttpClient(); + // and create its url + HttpRequest request = HttpRequest + .newBuilder(URI.create("https://archlinux.org/packages/search/json/?name=" + packageName)).build(); - CompletableFuture>> futureResult = new CompletableFuture<>(); - client.sendAsync(request, HttpResponse.BodyHandlers.ofString()).thenAccept(result ->{ + CompletableFuture>> futureResult = new CompletableFuture<>(); + client.sendAsync(request, HttpResponse.BodyHandlers.ofString()).thenAccept(result -> { - JSONObject json = new JSONObject(result.body()); + JSONObject json = new JSONObject(result.body()); - JSONArray resultsArrayJson = json.getJSONArray("results"); - if(resultsArrayJson.length()==0){ - // unknown package, probably an abstract dependency + JSONArray resultsArrayJson = json.getJSONArray("results"); + if (resultsArrayJson.length() == 0) { + // unknown package, probably an abstract dependency + futureResult.complete(null); + return; + } + JSONObject resultJson = resultsArrayJson.getJSONObject(0); + + // get infos + + Set dependenciesNames = new HashSet<>(); + for (Object dependency : resultJson.getJSONArray("depends")) { + dependenciesNames.add((String) dependency); + } + futureResult.complete(new Pair<>( + new Package( + resultJson.getString("pkgname"), + resultJson.getString("pkgver"), + resultJson.getString("repo"), + resultJson.getString("pkgdesc")), + dependenciesNames)); + }).exceptionally(error -> { + error.printStackTrace(); + logger.warning("Error while fetching package %s from the API : \n%s".formatted(packageName, error)); futureResult.complete(null); - return; - } - JSONObject resultJson = resultsArrayJson.getJSONObject(0); + return null; + }); - // get infos + return futureResult; - Set dependenciesNames = new HashSet<>(); - for(Object dependency : resultJson.getJSONArray("depends")){ - dependenciesNames.add((String)dependency); - } - futureResult.complete(new Pair<>( - new Package( - resultJson.getString("pkgname"), - resultJson.getString("pkgver"), - resultJson.getString("repo"), - resultJson.getString("pkgdesc") - ), - dependenciesNames - )); - }).exceptionally(error ->{ - error.printStackTrace(); - logger.warning("Error while fetching package %s from the API : \n%s".formatted(packageName, error)); - futureResult.complete(null); - return null; - }); + } - return futureResult; - -} - -/** - * Search for a package matching a pattern and return a list of packages and - * return a list of string matching this pattern. - * - * @param packageName String, the pattern to search in the repositories - * @return List of SearchedPackage objects - */ - public CompletableFuture> searchPackage(String packageName){ + /** + * Search for a package matching a pattern and return a list of packages and + * return a list of string matching this pattern. + * + * @param packageName String, the pattern to search in the repositories + * @return List of SearchedPackage objects + */ + public CompletableFuture> searchPackage(String packageName) { HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder() - .uri(URI.create("https://archlinux.org/packages/search/json/?q="+packageName)) + .uri(URI.create("https://archlinux.org/packages/search/json/?q=" + packageName)) .build(); CompletableFuture> futureSearchedPackages = new CompletableFuture<>(); - client.sendAsync(request, HttpResponse.BodyHandlers.ofString()).thenAccept(result->{ + client.sendAsync(request, HttpResponse.BodyHandlers.ofString()).thenAccept(result -> { List searchedPackagesList = new ArrayList<>(); JSONObject json = new JSONObject(result.body()); @@ -107,21 +106,18 @@ public CompletableFuture>> getPackageFromAPI(String pa JSONObject searchResultJson = (JSONObject) searchResultObj; // add package into to list searchedPackagesList.add(new SearchedPackage( - searchResultJson.getString("pkgname"), - searchResultJson.getString("pkgver"), - searchResultJson.getString("repo"), - searchResultJson.getString("pkgdesc") - )); + searchResultJson.getString("pkgname"), + searchResultJson.getString("pkgver"), + searchResultJson.getString("repo"), + searchResultJson.getString("pkgdesc"))); } - futureSearchedPackages.complete(searchedPackagesList); - }).exceptionally(error->{ + futureSearchedPackages.complete(searchedPackagesList); + }).exceptionally(error -> { error.printStackTrace(); futureSearchedPackages.complete(Collections.emptyList()); return null; }); - - return futureSearchedPackages; } From 44ac927f6eea9ed4f87d73fdfac7dd460910b1ae Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Wed, 14 Dec 2022 14:01:16 +0100 Subject: [PATCH 03/12] added attribute's description --- .../distribution/ArchDistribution.java | 4 +++- .../distribution/Distribution.java | 14 +++++++++++ .../parser/AsyncRequestsParser.java | 24 ++++++++++++++++++- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/packageviewer/distribution/ArchDistribution.java b/src/main/java/fr/packageviewer/distribution/ArchDistribution.java index 4d8585b..d42a1d0 100644 --- a/src/main/java/fr/packageviewer/distribution/ArchDistribution.java +++ b/src/main/java/fr/packageviewer/distribution/ArchDistribution.java @@ -24,6 +24,9 @@ import org.json.*; */ public class ArchDistribution extends AsyncRequestsParser implements Distribution { + /** + * Logger object used to split debug output and the application output + */ private static final Logger logger = LoggerManager.getLogger("ArchDistribution"); /** @@ -34,7 +37,6 @@ public class ArchDistribution extends AsyncRequestsParser implements Distributio * @param packageName String, The package's exact name * @return Pair of Package and Set of String */ - @Override public CompletableFuture>> getPackageFromAPI(String packageName) { // create a new http client diff --git a/src/main/java/fr/packageviewer/distribution/Distribution.java b/src/main/java/fr/packageviewer/distribution/Distribution.java index 7e8cb6d..1850afb 100644 --- a/src/main/java/fr/packageviewer/distribution/Distribution.java +++ b/src/main/java/fr/packageviewer/distribution/Distribution.java @@ -7,7 +7,21 @@ 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. + * + * @author R.Thomas + * @version 1.0 + */ public interface Distribution { + /** + * Search for a package matching a pattern and return a list of packages and + * return a list of string matching this pattern. + * + * @param packageName String, the pattern to search in the repositories + * @return List of SearchedPackage objects + */ Future> searchPackage(String packageName); + Future getPackageTree(String packageName, int depth); } diff --git a/src/main/java/fr/packageviewer/parser/AsyncRequestsParser.java b/src/main/java/fr/packageviewer/parser/AsyncRequestsParser.java index 9156c55..722d973 100644 --- a/src/main/java/fr/packageviewer/parser/AsyncRequestsParser.java +++ b/src/main/java/fr/packageviewer/parser/AsyncRequestsParser.java @@ -11,12 +11,34 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; 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 + * + * @author R.Thomas + * @version 1.0 + * + */ public abstract class AsyncRequestsParser { - + /** + * Logger object used to split debug output and the application output + */ private static final Logger logger = LoggerManager.getLogger("AsyncRequestsParser"); + /** + * This function return 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. + * + * @param packageName String, The package's exact name + * @return Pair of Package and Set of String + */ protected abstract CompletableFuture>> getPackageFromAPI(String name); + /** + * + */ public CompletableFuture getPackageTree(String packageName, int depth) { // parse the json var futurePackage = new CompletableFuture(); From 052ba408006efa55225a06b05facba3f3137ffae Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Wed, 14 Dec 2022 14:17:51 +0100 Subject: [PATCH 04/12] finished documentation for classes ArchDistribution, Distribution and AsyncRequestParse --- .../distribution/ArchDistribution.java | 4 +-- .../distribution/Distribution.java | 29 +++++++++++------ .../parser/AsyncRequestsParser.java | 32 ++++++++++++------- 3 files changed, 42 insertions(+), 23 deletions(-) diff --git a/src/main/java/fr/packageviewer/distribution/ArchDistribution.java b/src/main/java/fr/packageviewer/distribution/ArchDistribution.java index d42a1d0..118367d 100644 --- a/src/main/java/fr/packageviewer/distribution/ArchDistribution.java +++ b/src/main/java/fr/packageviewer/distribution/ArchDistribution.java @@ -25,8 +25,8 @@ import org.json.*; public class ArchDistribution extends AsyncRequestsParser implements Distribution { /** - * Logger object used to split debug output and the application output - */ + * Logger object used to split debug output and the application output + */ private static final Logger logger = LoggerManager.getLogger("ArchDistribution"); /** diff --git a/src/main/java/fr/packageviewer/distribution/Distribution.java b/src/main/java/fr/packageviewer/distribution/Distribution.java index 1850afb..255f000 100644 --- a/src/main/java/fr/packageviewer/distribution/Distribution.java +++ b/src/main/java/fr/packageviewer/distribution/Distribution.java @@ -10,18 +10,29 @@ import java.util.concurrent.Future; /** * This interface specifies the methods needed by a distribtion to be parsable. * - * @author R.Thomas - * @version 1.0 + * @author R.Thomas + * @version 1.0 */ public interface Distribution { /** - * Search for a package matching a pattern and return a list of packages and - * return a list of string matching this pattern. - * - * @param packageName String, the pattern to search in the repositories - * @return List of SearchedPackage objects - */ + * Search for a package matching a pattern and return a list of packages and + * return a list of string matching this pattern. + * + * @param packageName String, the pattern to search in the repositories + * @return List of SearchedPackage objects + */ Future> searchPackage(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 + * packages that also contains its dependencies, the dependency depth is + * specified by the parametter with the same name. + * + * @param packageName String, The package's exact name + * @param depth int, the depth of the dependency tree + * @return Package, the fully completed package + */ Future getPackageTree(String packageName, int depth); } diff --git a/src/main/java/fr/packageviewer/parser/AsyncRequestsParser.java b/src/main/java/fr/packageviewer/parser/AsyncRequestsParser.java index 722d973..de4defe 100644 --- a/src/main/java/fr/packageviewer/parser/AsyncRequestsParser.java +++ b/src/main/java/fr/packageviewer/parser/AsyncRequestsParser.java @@ -13,7 +13,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 order to get a package and fill its dependency list. It does all that * in an asyncron manner * * @author R.Thomas @@ -22,22 +22,30 @@ import java.util.logging.Logger; */ public abstract class AsyncRequestsParser { /** - * Logger object used to split debug output and the application output - */ + * Logger object used to split debug output and the application output + */ private static final Logger logger = LoggerManager.getLogger("AsyncRequestsParser"); /** - * This function return a package from the distribution's api in the form - * of a Pair Composed of a Package object, and a set of string containing + * 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. - * - * @param packageName String, The package's exact name - * @return Pair of Package and Set of String - */ + * + * @param packageName String, The package's exact name + * @return Pair of Package and Set of String + */ protected abstract CompletableFuture>> getPackageFromAPI(String name); /** + * 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 + * packages that also contains its dependencies, the dependency depth is + * specified by the parametter with the same name. * + * @param packageName String, The package's exact name + * @param depth int, the depth of the dependency tree + * @return Package, the fully completed package */ public CompletableFuture getPackageTree(String packageName, int depth) { // parse the json @@ -53,7 +61,7 @@ public abstract class AsyncRequestsParser { return CompletableFuture.completedFuture(null); } futureRequest.thenAccept(result -> { - if(result==null){ + if (result == null) { logger.fine("Completing callback INVALID for package %s (depth=%s)".formatted(packageName, depth)); futurePackage.complete(null); return; @@ -61,7 +69,6 @@ public abstract class AsyncRequestsParser { Package pack = result.getFirst(); Set dependenciesNames = result.getSecond(); - // if we're at the maximum depth, return the package without its dependencies if (depth == 0) { logger.fine("Completing callback NODEP for package %s (depth=%s)".formatted(packageName, depth)); @@ -93,7 +100,8 @@ public abstract class AsyncRequestsParser { futurePackage.complete(pack); }).exceptionally(error -> { error.printStackTrace(); - logger.warning("Error while manipulating package %s (depth=%s) : \n%s".formatted(packageName, depth, error)); + logger.warning( + "Error while manipulating package %s (depth=%s) : \n%s".formatted(packageName, depth, error)); futurePackage.complete(null); return null; }); From 6db7bc4b31d757edebe106fd6f54a023b31af91e Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Wed, 14 Dec 2022 14:22:33 +0100 Subject: [PATCH 05/12] finished documentation for class FedoraDistribution and fixed formating --- .../distribution/FedoraDistribution.java | 45 ++++++++++++++----- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/src/main/java/fr/packageviewer/distribution/FedoraDistribution.java b/src/main/java/fr/packageviewer/distribution/FedoraDistribution.java index 5fe0dc4..36ec91f 100644 --- a/src/main/java/fr/packageviewer/distribution/FedoraDistribution.java +++ b/src/main/java/fr/packageviewer/distribution/FedoraDistribution.java @@ -17,23 +17,41 @@ import fr.packageviewer.LoggerManager; import fr.packageviewer.pack.Package; import fr.packageviewer.pack.SearchedPackage; +/** + * This class handles package requests for Fedora. All return objects in + * this class are wrapped by a CompletableFuture to ensure async workload. + * + * @author S.Djalim, R.Thomas + * @version 1.0 + */ public class FedoraDistribution extends AsyncRequestsParser implements Distribution { + /** + * Logger object used to split debug output and the application output + */ private static final Logger logger = LoggerManager.getLogger("FedoraDistribution"); + /** + * 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. + * + * @param packageName String, The package's exact name + * @return Pair of Package and Set of String + */ protected CompletableFuture>> getPackageFromAPI(String packageName) { // create a new http client HttpClient client = HttpClient.newHttpClient(); // and create its url - String url = "https://mdapi.fedoraproject.org/rawhide/pkg/"+packageName+""; + String url = "https://mdapi.fedoraproject.org/rawhide/pkg/" + packageName + ""; HttpRequest request = HttpRequest.newBuilder(URI.create(url)).build(); CompletableFuture>> futureResult = new CompletableFuture<>(); - client.sendAsync(request, HttpResponse.BodyHandlers.ofString()).thenAccept(result->{ + client.sendAsync(request, HttpResponse.BodyHandlers.ofString()).thenAccept(result -> { String body = result.body(); - if(body.contains("404: Not Found")) { + if (body.contains("404: Not Found")) { futureResult.complete(null); return; } @@ -60,11 +78,9 @@ public class FedoraDistribution extends AsyncRequestsParser implements Distribut json.getString("basename"), json.getString("version"), json.getString("repo"), - json.getString("description") - ), - dependenciesNames - )); - }).exceptionally(error->{ + json.getString("description")), + dependenciesNames)); + }).exceptionally(error -> { error.printStackTrace(); logger.warning("Error while fetching package %s from the API : \n%s".formatted(packageName, error)); futureResult.complete(null); @@ -73,7 +89,14 @@ public class FedoraDistribution extends AsyncRequestsParser implements Distribut // if there's an error, return an empty string return futureResult; } - + + /** + * Search for a package matching a pattern and return a list of packages and + * return a list of string matching this pattern. + * + * @param packageName String, the pattern to search in the repositories + * @return List of SearchedPackage objects + */ @Override public CompletableFuture> searchPackage(String packageName) { @@ -86,7 +109,7 @@ public class FedoraDistribution extends AsyncRequestsParser implements Distribut CompletableFuture> futureSearchedPackages = new CompletableFuture<>(); - client.sendAsync(request, HttpResponse.BodyHandlers.ofString()).thenAccept(result->{ + client.sendAsync(request, HttpResponse.BodyHandlers.ofString()).thenAccept(result -> { JSONObject json = new JSONObject(result.body()); List searchedPackagesList = new ArrayList<>(); @@ -103,7 +126,7 @@ public class FedoraDistribution extends AsyncRequestsParser implements Distribut searchResultJson.getString("description"))); } futureSearchedPackages.complete(searchedPackagesList); - }).exceptionally(error->{ + }).exceptionally(error -> { error.printStackTrace(); futureSearchedPackages.complete(Collections.emptyList()); return null; From 49eddb60991fb916c747c74f738128cb17ea1d84 Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Wed, 14 Dec 2022 14:35:10 +0100 Subject: [PATCH 06/12] finished documentation for class SearchedPackage --- .../packageviewer/pack/SearchedPackage.java | 54 ++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/src/main/java/fr/packageviewer/pack/SearchedPackage.java b/src/main/java/fr/packageviewer/pack/SearchedPackage.java index 868801e..5ede26f 100644 --- a/src/main/java/fr/packageviewer/pack/SearchedPackage.java +++ b/src/main/java/fr/packageviewer/pack/SearchedPackage.java @@ -1,27 +1,74 @@ package fr.packageviewer.pack; +/** + * The SearchedPackage class stores metadata found when searching for a + * package. + * + * @author C.Marla, R.Thomas, S.Djalim + * @version 1.0 + */ public class SearchedPackage { + /** + * Name of the package + */ private final String name; + /** + * Version of the package + */ private final String version; + /** + * Repository where the package is located + */ private final String repo; + /** + * Description of the package + */ private final String description; + /** + * Getter for the name attribute + * + * @return String, the name of the package + */ public String getName() { return name; } + /** + * Getter for the version attribute + * + * @return String, the version of the package + */ public String getVersion() { return version; } + /** + * Getter for the repo attribute + * + * @return String, repository where the package is located + */ public String getRepo() { return repo; } + /** + * Getter for the description attribute + * + * @return String, Description of the package + */ public String getDescription() { return description; } - + /** + * Constructor for the SearchedPackage class + * + * @param name String, name of the package + * @param version String, version of the package + * @param repo String, repository where the package is located + * @param description String, description of the package + * + */ public SearchedPackage(String name, String version, String repo, String desciption) { this.name = name; this.version = version; @@ -29,6 +76,11 @@ public class SearchedPackage { this.description = desciption; } + /** + * Returns a string reprensentation of the package + * + * @return String, Description of the package + */ @Override public String toString() { return "SearchedPackage{name=%s,version=%s,repo=%s,description=%s}".formatted(name, version, repo, description); From a24489e70c3d95d4d68ea3e2abaada74051e9539 Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Wed, 14 Dec 2022 14:35:34 +0100 Subject: [PATCH 07/12] fixed formating for class SearchedPackage --- src/main/java/fr/packageviewer/pack/SearchedPackage.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/fr/packageviewer/pack/SearchedPackage.java b/src/main/java/fr/packageviewer/pack/SearchedPackage.java index 5ede26f..cf90cc1 100644 --- a/src/main/java/fr/packageviewer/pack/SearchedPackage.java +++ b/src/main/java/fr/packageviewer/pack/SearchedPackage.java @@ -60,12 +60,13 @@ public class SearchedPackage { public String getDescription() { return description; } + /** * Constructor for the SearchedPackage class * - * @param name String, name of the package - * @param version String, version of the package - * @param repo String, repository where the package is located + * @param name String, name of the package + * @param version String, version of the package + * @param repo String, repository where the package is located * @param description String, description of the package * */ From 0cdc9d9ca4b64c774515d00f7a8df357c3347171 Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Wed, 14 Dec 2022 14:43:55 +0100 Subject: [PATCH 08/12] finished documentation for class Package --- .../java/fr/packageviewer/pack/Package.java | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/main/java/fr/packageviewer/pack/Package.java b/src/main/java/fr/packageviewer/pack/Package.java index 0371559..db3a126 100644 --- a/src/main/java/fr/packageviewer/pack/Package.java +++ b/src/main/java/fr/packageviewer/pack/Package.java @@ -4,25 +4,67 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +/** + * The Package class stores all metadata needed for a fully completed package. + * + * @author C.Marla, R.Thomas, S.Djalim + * @version 1.0 + */ public class Package extends SearchedPackage { + /** + * List of package storing all of the dependencies of the package + */ private final List deps; + /** + * Getter for the deps attribute + * + * @return List, List of package storing all of the dependencies of the package + */ public List getDeps() { return deps; } + /** + * This method adds to the dependency list the package passed as parametter. + * + * @param pack Package, the package to add as dependency + */ public void addDep(Package pack) { deps.add(pack); } + /** + * Second constructor for the Package class, allows to create a package + * without supplying a list of dependencies. + * + * @param name String, name of the package + * @param version String, version of the package + * @param repo String, repository where the package is located + * @param description String, description of the package + */ public Package(String name, String version, String repo, String description) { this(name, version, repo, description, new ArrayList<>()); } + + /** + * Main constructor for the Package class + * + * @param name String, name of the package + * @param version String, version of the package + * @param repo String, repository where the package is located + * @param description String, description of the package + * @param deps List of Package, dependencies of the package + */ public Package(String name, String version, String repo, String description, List deps) { super(name, version, repo, description); this.deps = deps; } - + /** + * Returns a string reprensentation of the package + * + * @return String, Description of the package + */ @Override public String toString() { return "Package{%s,deps=%s}".formatted(super.toString(), deps); From 8aed4bbd3b28d3694c00c760fab2913a22ed724f Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Wed, 14 Dec 2022 14:50:27 +0100 Subject: [PATCH 09/12] fixed wrong description for toStrings returns --- src/main/java/fr/packageviewer/Pair.java | 26 ++++++++++++++++--- .../java/fr/packageviewer/pack/Package.java | 2 +- .../packageviewer/pack/SearchedPackage.java | 2 +- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/main/java/fr/packageviewer/Pair.java b/src/main/java/fr/packageviewer/Pair.java index 1a5763d..625e133 100644 --- a/src/main/java/fr/packageviewer/Pair.java +++ b/src/main/java/fr/packageviewer/Pair.java @@ -1,18 +1,34 @@ package fr.packageviewer; +/** + * The Pair class stores two objects of distinct type + * + * @author C.Marla, R.Thomas, S.Djalim + * @version 1.0 + */ public class Pair { private K first; private V second; - + /** + * + */ public Pair() { } + /** + * + * @param first + * @param second + */ public Pair(K first, V second) { this.first = first; this.second = second; } - + /** + * + * @return + */ public K getFirst() { return first; } @@ -20,7 +36,11 @@ public class Pair { public void setFirst(K first) { this.first = first; } - + + /** + * + * @return + */ public V getSecond() { return second; } diff --git a/src/main/java/fr/packageviewer/pack/Package.java b/src/main/java/fr/packageviewer/pack/Package.java index db3a126..0b1addb 100644 --- a/src/main/java/fr/packageviewer/pack/Package.java +++ b/src/main/java/fr/packageviewer/pack/Package.java @@ -63,7 +63,7 @@ public class Package extends SearchedPackage { /** * Returns a string reprensentation of the package * - * @return String, Description of the package + * @return String, string reprensentation of the package */ @Override public String toString() { diff --git a/src/main/java/fr/packageviewer/pack/SearchedPackage.java b/src/main/java/fr/packageviewer/pack/SearchedPackage.java index cf90cc1..2ad692f 100644 --- a/src/main/java/fr/packageviewer/pack/SearchedPackage.java +++ b/src/main/java/fr/packageviewer/pack/SearchedPackage.java @@ -80,7 +80,7 @@ public class SearchedPackage { /** * Returns a string reprensentation of the package * - * @return String, Description of the package + * @return String, string reprensentation of the package */ @Override public String toString() { From 98f4bb6e1a63dab5d3e880e43895a2c44da45266 Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Wed, 14 Dec 2022 14:58:08 +0100 Subject: [PATCH 10/12] finished documentation for class Pair --- src/main/java/fr/packageviewer/Pair.java | 36 ++++++++++++++++++------ 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/src/main/java/fr/packageviewer/Pair.java b/src/main/java/fr/packageviewer/Pair.java index 625e133..75db71f 100644 --- a/src/main/java/fr/packageviewer/Pair.java +++ b/src/main/java/fr/packageviewer/Pair.java @@ -3,52 +3,72 @@ package fr.packageviewer; /** * The Pair class stores two objects of distinct type * - * @author C.Marla, R.Thomas, S.Djalim + * @author R.Thomas * @version 1.0 */ -public class Pair { +public class Pair { private K first; private V second; + /** - * + * Empty Constructor for the Pair class */ public Pair() { } /** + * Main Constructor for the Pair class * - * @param first - * @param second + * @param first, the first object to be stored + * @param second the second object to be stored */ public Pair(K first, V second) { this.first = first; this.second = second; } + /** + * Getter for the attribute first * - * @return + * @return the object stored in the attribute first */ public K getFirst() { return first; } + /** + * Setter for the attribute first + * + * @param first Store the given object in the attribute first + */ public void setFirst(K first) { this.first = first; } - + /** + * Getter for the attribute second * - * @return + * @return the object stored in the attribute second */ public V getSecond() { return second; } + /** + * Setter for the attribute second + * + * @param second Store the given object in the attribute second + */ public void setSecond(V second) { this.second = second; } + /** + * Returns a string reprensentation of the pair + * + * @return String, string reprensentation of the pair + */ @Override public String toString() { return "Pair{key=%s,value=%s}".formatted(first, second); From 4d2c67c1c247dfaec4e41d8276afc915009e50ae Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Wed, 14 Dec 2022 15:15:55 +0100 Subject: [PATCH 11/12] finished documentation for class Logger --- .../java/fr/packageviewer/LoggerManager.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/main/java/fr/packageviewer/LoggerManager.java b/src/main/java/fr/packageviewer/LoggerManager.java index c7b17e6..18240a3 100644 --- a/src/main/java/fr/packageviewer/LoggerManager.java +++ b/src/main/java/fr/packageviewer/LoggerManager.java @@ -2,15 +2,37 @@ package fr.packageviewer; import java.util.logging.*; +/** + * The LoggerManager class allows for basic debug output management using + * Java's default logging class. + * + * @author R.Thomas + * @version 1.0 + */ public class LoggerManager { - + /** + * Default log level, should be INFO + */ private static final Level DEFAULT_LOG_LEVEL = Level.INFO; - public static Logger getLogger(String name){ + /** + * Static factory for the Logger class + * + * @param name String, of the logger to create + * @return Logger, a new logger + */ + public static Logger getLogger(String name) { return getLogger(name, DEFAULT_LOG_LEVEL); } - public static Logger getLogger(String name, Level level){ + /** + * Main static factory for the Logger class + * + * @param name String, name of the logger to create + * @param level Level, the level of severity of the logger + * @return Logger, a new logger + */ + public static Logger getLogger(String name, Level level) { Logger logger = Logger.getLogger(name); logger.setLevel(level); From d31969b8d0722876d3f5447d3fe2cabb5312c42b Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Wed, 14 Dec 2022 16:00:53 +0100 Subject: [PATCH 12/12] added documentation for the newly added elements --- .../distribution/ArchDistribution.java | 40 +++++++++++-------- .../java/fr/packageviewer/pack/Package.java | 28 ++++++++----- .../packageviewer/pack/SearchedPackage.java | 23 +++++++---- 3 files changed, 56 insertions(+), 35 deletions(-) diff --git a/src/main/java/fr/packageviewer/distribution/ArchDistribution.java b/src/main/java/fr/packageviewer/distribution/ArchDistribution.java index 86f8670..1737f00 100644 --- a/src/main/java/fr/packageviewer/distribution/ArchDistribution.java +++ b/src/main/java/fr/packageviewer/distribution/ArchDistribution.java @@ -29,10 +29,20 @@ public class ArchDistribution extends AsyncRequestsParser implements Distributio */ private static final Logger logger = LoggerManager.getLogger("ArchDistribution"); - private static String trimAfterCharacters(String str, String trimAfterCharacters){ - for(char c : trimAfterCharacters.toCharArray()){ + /** + * This method remove all characters in the first string passed as + * parametter 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 + */ + private static String trimAfterCharacters(String str, String trimAfterCharacters) { + for (char c : trimAfterCharacters.toCharArray()) { int index = str.indexOf(c); - if(index>0)str = str.substring(index); + if (index > 0) + str = str.substring(index); } return str; } @@ -69,8 +79,8 @@ public class ArchDistribution extends AsyncRequestsParser implements Distributio // get infos Set dependenciesNames = new HashSet<>(); - for(Object dependency : resultJson.getJSONArray("depends")){ - dependenciesNames.add(trimAfterCharacters((String)dependency, "<>=")); + for (Object dependency : resultJson.getJSONArray("depends")) { + dependenciesNames.add(trimAfterCharacters((String) dependency, "<>=")); } futureResult.complete(new Pair<>( new Package( @@ -78,11 +88,9 @@ public class ArchDistribution extends AsyncRequestsParser implements Distributio resultJson.getString("pkgver"), resultJson.getString("repo"), resultJson.getString("pkgdesc"), - "arch" - ), - dependenciesNames - )); - }).exceptionally(error ->{ + "arch"), + dependenciesNames)); + }).exceptionally(error -> { error.printStackTrace(); logger.warning("Error while fetching package %s from the API : \n%s".formatted(packageName, error)); futureResult.complete(null); @@ -93,7 +101,6 @@ public class ArchDistribution extends AsyncRequestsParser implements Distributio } - /** * Search for a package matching a pattern and return a list of packages and * return a list of string matching this pattern. @@ -120,12 +127,11 @@ public class ArchDistribution extends AsyncRequestsParser implements Distributio JSONObject searchResultJson = (JSONObject) searchResultObj; // add package into to list searchedPackagesList.add(new SearchedPackage( - searchResultJson.getString("pkgname"), - searchResultJson.getString("pkgver"), - searchResultJson.getString("repo"), - searchResultJson.getString("pkgdesc"), - "arch" - )); + searchResultJson.getString("pkgname"), + searchResultJson.getString("pkgver"), + searchResultJson.getString("repo"), + searchResultJson.getString("pkgdesc"), + "arch")); } futureSearchedPackages.complete(searchedPackagesList); }).exceptionally(error -> { diff --git a/src/main/java/fr/packageviewer/pack/Package.java b/src/main/java/fr/packageviewer/pack/Package.java index a782a48..34a23a1 100644 --- a/src/main/java/fr/packageviewer/pack/Package.java +++ b/src/main/java/fr/packageviewer/pack/Package.java @@ -38,28 +38,34 @@ public class Package extends SearchedPackage { * Second constructor for the Package class, allows to create a package * without supplying a list of dependencies. * - * @param name String, name of the package - * @param version String, version of the package - * @param repo String, repository where the package is located - * @param description String, description of the package + * @param name String, name of the package + * @param version String, version of the package + * @param repo String, repository where the package is located + * @param description String, description of the package + * @param distribution String, the distribution where this specific package + * belongs */ - public Package(String name, String version, String repo, String description,String distribution) { + public Package(String name, String version, String repo, String description, String distribution) { this(name, version, repo, description, distribution, new ArrayList<>()); } /** * Main constructor for the Package class * - * @param name String, name of the package - * @param version String, version of the package - * @param repo String, repository where the package is located - * @param description String, description of the package - * @param deps List of Package, dependencies of the package + * @param name String, name of the package + * @param version String, version of the package + * @param repo String, repository where the package is located + * @param description String, description of the package + * @param distribution String, the distribution where this specific package + * belongs + * @param deps List of Package, dependencies of the package */ - public Package(String name, String version, String repo, String description,String distribution, List deps) { + public Package(String name, String version, String repo, String description, String distribution, + List deps) { super(name, version, repo, description, distribution); this.deps = deps; } + /** * Returns a string reprensentation of the package * diff --git a/src/main/java/fr/packageviewer/pack/SearchedPackage.java b/src/main/java/fr/packageviewer/pack/SearchedPackage.java index 50f3e7d..3ec3f45 100644 --- a/src/main/java/fr/packageviewer/pack/SearchedPackage.java +++ b/src/main/java/fr/packageviewer/pack/SearchedPackage.java @@ -24,6 +24,9 @@ public class SearchedPackage { * Description of the package */ private final String description; + /** + * Distribution where this specific package belongs + */ private final String distribution; /** @@ -62,7 +65,11 @@ public class SearchedPackage { return description; } - + /** + * Getter for the distribution attribute + * + * @return String, distribution where this specific package belongs + */ public String getDistribution() { return distribution; } @@ -70,11 +77,12 @@ public class SearchedPackage { /** * Constructor for the SearchedPackage class * - * @param name String, name of the package - * @param version String, version of the package - * @param repo String, repository where the package is located - * @param description String, description of the package - * + * @param name String, name of the package + * @param version String, version of the package + * @param repo String, repository where the package is located + * @param description String, description of the package + * @param distribution String, the distribution where this specific package + * belongs */ public SearchedPackage(String name, String version, String repo, String description, String distribution) { this.name = name; @@ -91,6 +99,7 @@ public class SearchedPackage { */ @Override public String toString() { - return "SearchedPackage{name=%s,version=%s,repo=%s,description=%s,distribution=%s}".formatted(name, version, repo, description, distribution); + return "SearchedPackage{name=%s,version=%s,repo=%s,description=%s,distribution=%s}".formatted(name, version, + repo, description, distribution); } }