finished tree view of package and slight modification in the FedoraDistribution class
This commit is contained in:
parent
cdc4a98b73
commit
4e59b17b7c
@ -4,6 +4,7 @@ import java.util.List;
|
||||
|
||||
import fr.packageviewer.frontend.Frontend;
|
||||
import fr.packageviewer.frontend.FrontendFactory;
|
||||
import fr.packageviewer.pack.Package;
|
||||
import fr.packageviewer.pack.SearchedPackage;
|
||||
|
||||
public class Main {
|
||||
@ -14,18 +15,22 @@ public class Main {
|
||||
|
||||
// send the command line arguments to the parser
|
||||
ArgParse.parseArguments(args);
|
||||
String packet = ArgParse.getPacket();
|
||||
String packetName = ArgParse.getPacket();
|
||||
String distribution = ArgParse.getDistribution();
|
||||
|
||||
// we create an object to search the packages in the distribution
|
||||
Searcher searcher = new Searcher(distribution);
|
||||
|
||||
// we get the packages list
|
||||
List<SearchedPackage> packets = searcher.searchPackages(packet);
|
||||
List<SearchedPackage> packets = searcher.searchPackages(packetName);
|
||||
|
||||
// ask the user to select the package to see in details
|
||||
SearchedPackage searchedPacket = frontend.askUserToChoosePackage(packets);
|
||||
// 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
|
||||
Package packet = searcher.getPackage(searchedPacketName);
|
||||
|
||||
// show all informations about a packet
|
||||
frontend.showPackageTree(packet, 0);
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import java.util.concurrent.Future;
|
||||
|
||||
import fr.packageviewer.distribution.Distribution;
|
||||
import fr.packageviewer.pack.SearchedPackage;
|
||||
import fr.packageviewer.pack.Package;
|
||||
|
||||
public class Searcher {
|
||||
|
||||
@ -57,4 +58,21 @@ public class Searcher {
|
||||
}
|
||||
return allPackages;
|
||||
}
|
||||
|
||||
|
||||
public Package getPackage(SearchedPackage packetInput) {
|
||||
if(distributionName == null) {
|
||||
distributionName = packetInput.getDistribution();
|
||||
}
|
||||
String packageName = packetInput.getName();
|
||||
Distribution distribution = DistributionEnum.getDistributionContructorByName(distributionName);
|
||||
Future<Package> futurePacket = distribution.getPackageTree(packageName, 4);
|
||||
Package packet = null;
|
||||
try {
|
||||
packet = futurePacket.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return packet;
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ import fr.packageviewer.LoggerManager;
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@ -32,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.
|
||||
*
|
||||
*
|
||||
* @param packageName String, The package's exact name
|
||||
* @return Pair of Package and Set of String
|
||||
*/
|
||||
@ -75,7 +75,7 @@ public class FedoraDistribution extends AsyncRequestsParser implements Distribut
|
||||
json.getString("basename"),
|
||||
json.getString("version"),
|
||||
"rawhide",
|
||||
json.getString("description"),
|
||||
json.getString("summary"),
|
||||
"fedora"
|
||||
),
|
||||
dependenciesNames
|
||||
@ -93,7 +93,7 @@ public class FedoraDistribution extends AsyncRequestsParser implements Distribut
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@ -111,7 +111,7 @@ public class FedoraDistribution extends AsyncRequestsParser implements Distribut
|
||||
|
||||
// send the request and when there's a response
|
||||
client.sendAsync(request, HttpResponse.BodyHandlers.ofString()).thenAccept(result -> {
|
||||
//parse the json response
|
||||
//parse the json response
|
||||
JSONObject json = new JSONObject(result.body());
|
||||
|
||||
List<SearchedPackage> searchedPackagesList = new ArrayList<>();
|
||||
|
@ -7,5 +7,5 @@ import fr.packageviewer.pack.SearchedPackage;
|
||||
|
||||
public interface Frontend {
|
||||
SearchedPackage askUserToChoosePackage(List<SearchedPackage> packets);
|
||||
void showPackageTree(Package packet);
|
||||
void showPackageTree(Package packet, int depth);
|
||||
}
|
||||
|
@ -68,9 +68,15 @@ public class FrontendTerminal implements Frontend{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showPackageTree(Package packet) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
public void showPackageTree(Package packet, int depth) {
|
||||
System.out.printf("%s%s / %s : %s%n",
|
||||
" ".repeat(depth),
|
||||
packet.getName(),
|
||||
packet.getVersion(),
|
||||
packet.getDescription());
|
||||
for (Package dep : packet.getDeps()) {
|
||||
showPackageTree(dep, depth+1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user