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; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
| @ -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