started fedora parser
This commit is contained in:
parent
a8658f77bc
commit
6454fd9d66
@ -4,24 +4,52 @@ import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
import java.net.http.*;
|
||||
import org.json.*;
|
||||
|
||||
public class FedoraParser {
|
||||
|
||||
public List<SearchedPackage> searchPackage(String packageName){
|
||||
|
||||
private String getPackageFromAPI(String packageName) {
|
||||
/* TODO
|
||||
*
|
||||
* Ok, to retrieve all the data we need about a package we get the
|
||||
* .spec file at the repo's root. The thing is that for pacakges
|
||||
* that didn't had an update for a long time, the branch "main" doesn't
|
||||
* exist, it's "master", so in the future we'll need to address this
|
||||
* case
|
||||
*
|
||||
*/
|
||||
// create a new http client
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
// and create its url
|
||||
HttpRequest request = HttpRequest.newBuilder(URI.create("https://src.fedoraproject.org/rpms/"+packageName+"/raw/main/f/"+packageName+".spec")).build();
|
||||
// send its url and return the string given
|
||||
try {
|
||||
return client.send(request, HttpResponse.BodyHandlers.ofString()).body();
|
||||
} catch (IOException|InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// if there's an error, return an empty string
|
||||
return "";
|
||||
}
|
||||
|
||||
public List<SearchedPackage> searchPackage(String packageName) {
|
||||
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://src.fedoraproject.org/api/0/projects?namepace=rpms&per_page=100&short=true&pattern="+packageName))
|
||||
.uri(URI.create(
|
||||
"https://src.fedoraproject.org/api/0/projects?namepace=rpms&per_page=100&short=true&pattern="
|
||||
+ packageName))
|
||||
.build();
|
||||
|
||||
HttpResponse<String> response;
|
||||
try{
|
||||
try {
|
||||
response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
}catch(IOException|InterruptedException e){
|
||||
} catch (IOException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
@ -36,11 +64,26 @@ public class FedoraParser {
|
||||
JSONObject searchResultJson = (JSONObject) searchResultObj;
|
||||
// add package into to list
|
||||
searchedPackagesList.add(new SearchedPackage(
|
||||
searchResultJson.getString("neofetch"),
|
||||
searchResultJson.getString("fullname"),
|
||||
searchResultJson.getString("description")
|
||||
));
|
||||
searchResultJson.getString("neofetch"),
|
||||
searchResultJson.getString("fullname"),
|
||||
searchResultJson.getString("description")));
|
||||
}
|
||||
return searchedPackagesList;
|
||||
}
|
||||
|
||||
private Map<String,String> parseSpecFile(String spec){
|
||||
Map<String,String> results = new HashMap<>();
|
||||
spec.indexOf("%description");
|
||||
return results;
|
||||
}
|
||||
|
||||
public Package getPackageTree(String packageName, int depth) {
|
||||
String name, version, repo, description;
|
||||
List<Package> deps = new ArrayList<>();
|
||||
|
||||
// parse the json
|
||||
String spec = getPackageFromAPI(packageName);
|
||||
return new Package("name", "version", "repo", "description", deps);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user