reformat code (mostly switch spaces to tabs)
This commit is contained in:
parent
b2e82c8d7c
commit
277e836e71
@ -5,6 +5,7 @@ import com.beust.jcommander.JCommander;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to parse the command line arguments given by the user
|
* Class to parse the command line arguments given by the user
|
||||||
|
*
|
||||||
* @author Capelier-Marla
|
* @author Capelier-Marla
|
||||||
*/
|
*/
|
||||||
public class ArgParse {
|
public class ArgParse {
|
||||||
@ -15,8 +16,9 @@ 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
|
*
|
||||||
* @param args the command line arguments given by the user
|
* @param args the command line arguments given by the user
|
||||||
|
* @author Capelier-Marla
|
||||||
*/
|
*/
|
||||||
static void parseArguments(String[] args) {
|
static void parseArguments(String[] args) {
|
||||||
// create JCommander and CommandLineParams objects
|
// create JCommander and CommandLineParams objects
|
||||||
@ -27,7 +29,7 @@ public class ArgParse {
|
|||||||
try {
|
try {
|
||||||
// parse the argument from list of String
|
// parse the argument from list of String
|
||||||
jCommander.parse(args);
|
jCommander.parse(args);
|
||||||
if(params.help) {
|
if (params.help) {
|
||||||
jCommander.setProgramName("PackageViewer");
|
jCommander.setProgramName("PackageViewer");
|
||||||
jCommander.usage();
|
jCommander.usage();
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
@ -48,8 +50,9 @@ public class ArgParse {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the distribution name. If the user didn't give any or if we didn't parse it, 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
|
* @return String: the distribution name
|
||||||
|
* @author Capelier-Marla
|
||||||
*/
|
*/
|
||||||
public static String getDistribution() {
|
public static String getDistribution() {
|
||||||
return distribution;
|
return distribution;
|
||||||
@ -57,8 +60,9 @@ public class ArgParse {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the packet name, this one isn't optional
|
* Get the packet name, this one isn't optional
|
||||||
* @author Capelier-Marla
|
*
|
||||||
* @return String: the packet name
|
* @return String: the packet name
|
||||||
|
* @author Capelier-Marla
|
||||||
*/
|
*/
|
||||||
public static String getPacket() {
|
public static String getPacket() {
|
||||||
return packet;
|
return packet;
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import com.beust.jcommander.Parameter;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to store and get the command line arguments given by the user
|
* Class to store and get the command line arguments given by the user
|
||||||
|
*
|
||||||
* @author Capelier-Marla
|
* @author Capelier-Marla
|
||||||
*/
|
*/
|
||||||
public class CommandLineParams {
|
public class CommandLineParams {
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import java.util.List;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Enum containing distribution information 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 {
|
||||||
@ -21,6 +22,7 @@ public enum DistributionEnum {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for enums
|
* Constructor for enums
|
||||||
|
*
|
||||||
* @param name the name of the distribution
|
* @param name the name of the distribution
|
||||||
* @param distributionConstructor the instance of the distribution
|
* @param distributionConstructor the instance of the distribution
|
||||||
* @author Capelier-Marla
|
* @author Capelier-Marla
|
||||||
@ -32,15 +34,16 @@ public enum DistributionEnum {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the distribution instance for the distribution requested in String
|
* Get the distribution instance for the distribution requested in String
|
||||||
|
*
|
||||||
* @param name name of the distribution requested
|
* @param name name of the distribution requested
|
||||||
* @return the instance of the distribution requested
|
* @return the instance of the distribution requested
|
||||||
* @author Capelier-Marla
|
* @author Capelier-Marla
|
||||||
*/
|
*/
|
||||||
public static Distribution getDistributionConstructorByName(String name) {
|
public static Distribution getDistributionConstructorByName(String name) {
|
||||||
// loop for all distributions 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)) {
|
||||||
return distrib.distributionConstructor;
|
return distrib.distributionConstructor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -49,13 +52,14 @@ public enum DistributionEnum {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all distribution instances available in this enum
|
* Get all distribution instances available in this enum
|
||||||
|
*
|
||||||
* @return the list 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 distrib : values()) {
|
for (var distrib : values()) {
|
||||||
result.add(distrib.distributionConstructor);
|
result.add(distrib.distributionConstructor);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@ -20,6 +20,7 @@ public class Searcher {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the list of all packages in the distribution set 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
|
||||||
@ -28,11 +29,11 @@ public class Searcher {
|
|||||||
|
|
||||||
// we add all instanced constructors in a list, only one if defined at creation of the object
|
// we add all instanced constructors in a list, only one if defined at creation of the object
|
||||||
List<Distribution> distributions;
|
List<Distribution> distributions;
|
||||||
if(distributionName == null) {
|
if (distributionName == null) {
|
||||||
distributions = DistributionEnum.getAllDistributionsInstances();
|
distributions = DistributionEnum.getAllDistributionsInstances();
|
||||||
} else {
|
} else {
|
||||||
distributions = Collections.singletonList(DistributionEnum.getDistributionConstructorByName(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);
|
||||||
}
|
}
|
||||||
@ -48,7 +49,7 @@ public class Searcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// we get all packages waiting for them to be received
|
// we get all packages waiting for them to be received
|
||||||
for(Future<List<SearchedPackage>> futurePackageList : listFuturePackagesList ) {
|
for (Future<List<SearchedPackage>> futurePackageList : listFuturePackagesList) {
|
||||||
try {
|
try {
|
||||||
List<SearchedPackage> tempList = futurePackageList.get();
|
List<SearchedPackage> tempList = futurePackageList.get();
|
||||||
allPackages.addAll(tempList);
|
allPackages.addAll(tempList);
|
||||||
@ -61,7 +62,7 @@ public class Searcher {
|
|||||||
|
|
||||||
|
|
||||||
public Package getPackage(SearchedPackage packetInput) {
|
public Package getPackage(SearchedPackage packetInput) {
|
||||||
if(distributionName == null) {
|
if (distributionName == null) {
|
||||||
distributionName = packetInput.getDistribution();
|
distributionName = packetInput.getDistribution();
|
||||||
}
|
}
|
||||||
String packageName = packetInput.getName();
|
String packageName = packetInput.getName();
|
||||||
|
|||||||
@ -81,7 +81,7 @@ public class FedoraDistribution extends AsyncRequestsParser implements Distribut
|
|||||||
),
|
),
|
||||||
dependenciesNames
|
dependenciesNames
|
||||||
));
|
));
|
||||||
}).exceptionally(error->{
|
}).exceptionally(error -> {
|
||||||
error.printStackTrace();
|
error.printStackTrace();
|
||||||
logger.warning("Error while fetching package %s from the API : \n%s".formatted(packageName, error));
|
logger.warning("Error while fetching package %s from the API : \n%s".formatted(packageName, error));
|
||||||
futureResult.complete(null);
|
futureResult.complete(null);
|
||||||
@ -126,7 +126,7 @@ public class FedoraDistribution extends AsyncRequestsParser implements Distribut
|
|||||||
String name = searchResultJson.getString("name");
|
String name = searchResultJson.getString("name");
|
||||||
|
|
||||||
// do not include fork projects in the list
|
// do not include fork projects in the list
|
||||||
if(!name.startsWith("fork/")){
|
if (!name.startsWith("fork/")) {
|
||||||
|
|
||||||
// add package into to list
|
// add package into to list
|
||||||
searchedPackagesList.add(new SearchedPackage(
|
searchedPackagesList.add(new SearchedPackage(
|
||||||
|
|||||||
@ -7,5 +7,6 @@ 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);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,15 +2,11 @@ package fr.packageviewer.frontend;
|
|||||||
|
|
||||||
public class FrontendFactory {
|
public class FrontendFactory {
|
||||||
|
|
||||||
public static Frontend get(String name){
|
public static Frontend get(String name) {
|
||||||
switch(name){
|
if (name.equals("terminal")) {
|
||||||
case "terminal":{
|
|
||||||
return new FrontendTerminal();
|
return new FrontendTerminal();
|
||||||
}
|
}
|
||||||
default:{
|
|
||||||
throw new IllegalArgumentException("Invalid frontend");
|
throw new IllegalArgumentException("Invalid frontend");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,10 +6,11 @@ import fr.packageviewer.pack.SearchedPackage;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class FrontendTerminal implements Frontend{
|
public class FrontendTerminal implements Frontend {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the String given is a number
|
* Check if the String given is a number
|
||||||
|
*
|
||||||
* @param i the String given
|
* @param i the String given
|
||||||
* @return true if the String is a number
|
* @return true if the String is a number
|
||||||
* @author Capelier-Marla
|
* @author Capelier-Marla
|
||||||
@ -33,11 +34,11 @@ public class FrontendTerminal implements Frontend{
|
|||||||
searchedPacket.getDistribution(),
|
searchedPacket.getDistribution(),
|
||||||
searchedPacket.getRepo(),
|
searchedPacket.getRepo(),
|
||||||
searchedPacket.getName(),
|
searchedPacket.getName(),
|
||||||
searchedPacket.getVersion()==null?"":searchedPacket.getVersion(),
|
searchedPacket.getVersion() == null ? "" : searchedPacket.getVersion(),
|
||||||
searchedPacket.getDescription());
|
searchedPacket.getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.printf("Pick a package to see in details (0-%s) : ", packets.size()-1);
|
System.out.printf("Pick a package to see in details (0-%s) : ", packets.size() - 1);
|
||||||
Scanner input = new Scanner(System.in);
|
Scanner input = new Scanner(System.in);
|
||||||
|
|
||||||
// we create vars for the loop
|
// we create vars for the loop
|
||||||
@ -49,9 +50,9 @@ public class FrontendTerminal implements Frontend{
|
|||||||
packetNumberString = input.nextLine();
|
packetNumberString = input.nextLine();
|
||||||
// reset notValid to false, we set it in true only if something is wrong
|
// reset notValid to false, we set it in true only if something is wrong
|
||||||
notValid = false;
|
notValid = false;
|
||||||
if(isNumeric(packetNumberString)) {
|
if (isNumeric(packetNumberString)) {
|
||||||
packetNumber = Integer.parseInt(packetNumberString);
|
packetNumber = Integer.parseInt(packetNumberString);
|
||||||
if(packetNumber < 0 || packetNumber >= packets.size()) {
|
if (packetNumber < 0 || packetNumber >= packets.size()) {
|
||||||
// this number is too big or too small
|
// this number is too big or too small
|
||||||
System.out.println("Enter a valid number");
|
System.out.println("Enter a valid number");
|
||||||
notValid = true;
|
notValid = true;
|
||||||
@ -61,7 +62,7 @@ public class FrontendTerminal implements Frontend{
|
|||||||
System.out.println("Enter a valid number");
|
System.out.println("Enter a valid number");
|
||||||
notValid = true;
|
notValid = true;
|
||||||
}
|
}
|
||||||
} while(notValid);
|
} while (notValid);
|
||||||
|
|
||||||
input.close();
|
input.close();
|
||||||
return packets.get(packetNumber);
|
return packets.get(packetNumber);
|
||||||
@ -75,7 +76,7 @@ public class FrontendTerminal implements Frontend{
|
|||||||
packet.getVersion(),
|
packet.getVersion(),
|
||||||
packet.getDescription());
|
packet.getDescription());
|
||||||
for (Package dep : packet.getDeps()) {
|
for (Package dep : packet.getDeps()) {
|
||||||
showPackageTree(dep, depth+1);
|
showPackageTree(dep, depth + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,6 @@ import java.util.logging.Logger;
|
|||||||
*
|
*
|
||||||
* @author R.Thomas
|
* @author R.Thomas
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public abstract class AsyncRequestsParser {
|
public abstract class AsyncRequestsParser {
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -14,19 +14,21 @@ import java.util.concurrent.Future;
|
|||||||
public abstract class DistroTest<T extends Distribution> {
|
public abstract class DistroTest<T extends Distribution> {
|
||||||
|
|
||||||
protected abstract T createInstance();
|
protected abstract T createInstance();
|
||||||
protected List<SearchedPackage> helperSearchPackage(String packageName){
|
|
||||||
|
protected List<SearchedPackage> helperSearchPackage(String packageName) {
|
||||||
Distribution distribution = createInstance();
|
Distribution distribution = createInstance();
|
||||||
Future<List<SearchedPackage>> future = distribution.searchPackage(packageName);
|
Future<List<SearchedPackage>> future = distribution.searchPackage(packageName);
|
||||||
try{
|
try {
|
||||||
return future.get();
|
return future.get();
|
||||||
} catch (ExecutionException | InterruptedException e) {
|
} catch (ExecutionException | InterruptedException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected Package helperGetPackageTree(String packageName, int depth){
|
|
||||||
|
protected Package helperGetPackageTree(String packageName, int depth) {
|
||||||
Distribution distribution = createInstance();
|
Distribution distribution = createInstance();
|
||||||
Future<Package> future = distribution.getPackageTree(packageName, depth);
|
Future<Package> future = distribution.getPackageTree(packageName, depth);
|
||||||
try{
|
try {
|
||||||
return future.get();
|
return future.get();
|
||||||
} catch (ExecutionException | InterruptedException e) {
|
} catch (ExecutionException | InterruptedException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@ -34,7 +36,7 @@ public abstract class DistroTest<T extends Distribution> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicQueryDoNotFail(){
|
public void testBasicQueryDoNotFail() {
|
||||||
helperGetPackageTree("bash", 0);
|
helperGetPackageTree("bash", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +58,7 @@ public abstract class DistroTest<T extends Distribution> {
|
|||||||
public void testQueryWithDepth1hasOneLevelOfDeps() {
|
public void testQueryWithDepth1hasOneLevelOfDeps() {
|
||||||
Package pack = helperGetPackageTree("bash", 1);
|
Package pack = helperGetPackageTree("bash", 1);
|
||||||
Assertions.assertNotEquals(pack.getDeps().size(), 0);
|
Assertions.assertNotEquals(pack.getDeps().size(), 0);
|
||||||
for(Package dep : pack.getDeps()){
|
for (Package dep : pack.getDeps()) {
|
||||||
Assertions.assertEquals(dep.getDeps().size(), 0);
|
Assertions.assertEquals(dep.getDeps().size(), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -83,10 +85,11 @@ public abstract class DistroTest<T extends Distribution> {
|
|||||||
public void testThatBashSearchReturnsResults() {
|
public void testThatBashSearchReturnsResults() {
|
||||||
Assertions.assertNotEquals(helperSearchPackage("bash").size(), 0);
|
Assertions.assertNotEquals(helperSearchPackage("bash").size(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testThatBashSearchContainsBash() {
|
public void testThatBashSearchContainsBash() {
|
||||||
for(SearchedPackage pack : helperSearchPackage("bash")){
|
for (SearchedPackage pack : helperSearchPackage("bash")) {
|
||||||
if(pack.getName().equals("bash")){
|
if (pack.getName().equals("bash")) {
|
||||||
Assertions.assertTrue(true);
|
Assertions.assertTrue(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user