Search in sources :

Example 1 with MongoConnection

use of fr.inria.spirals.repairnator.serializer.mongodb.MongoConnection in project repairnator by Spirals-Team.

the class ScannerSerializer method main.

public static void main(String[] args) throws IOException, GeneralSecurityException {
    GoogleSpreadSheetFactory.initWithFileSecret("client_secret.json");
    GoogleSpreadSheetFactory.setSpreadsheetId(args[1]);
    Sheets sheets = GoogleSpreadSheetFactory.getSheets();
    List<List<Object>> results = sheets.spreadsheets().values().get(GoogleSpreadSheetFactory.getSpreadsheetID(), "Scanner Data!A:M").execute().getValues();
    MongoConnection mongoConnection = new MongoConnection(args[0], "repairnator");
    if (!mongoConnection.isConnected()) {
        throw new RuntimeException("Error when connection to mongodb");
    }
    MongoDBSerializerEngine serializerEngine = new MongoDBSerializerEngine(mongoConnection);
    List<SerializedData> data = new ArrayList<>();
    for (int i = 1; i < results.size(); i++) {
        List<Object> value = results.get(i);
        JsonObject result = new JsonObject();
        result.addProperty("hostname", Utils.getValue(value, 0));
        result.addProperty("dateBegin", Utils.getValue(value, 1));
        result.addProperty("dateLimit", Utils.getValue(value, 2));
        result.addProperty("totalRepoNumber", Utils.getValue(value, 3));
        result.addProperty("totalRepoUsingTravis", Utils.getValue(value, 4));
        result.addProperty("totalScannedBuilds", Utils.getValue(value, 5));
        result.addProperty("totalJavaBuilds", Utils.getValue(value, 6));
        result.addProperty("totalJavaPassingBuilds", Utils.getValue(value, 7));
        result.addProperty("totalJavaFailingBuilds", Utils.getValue(value, 8));
        result.addProperty("totalJavaFailingBuildsWithFailingTests", Utils.getValue(value, 9));
        result.addProperty("totalPRBuilds", Utils.getValue(value, 10));
        result.addProperty("dayLimit", Utils.getValue(value, 11));
        result.addProperty("duration", Utils.getValue(value, 12));
        result.addProperty("runId", Utils.getValue(value, 13));
        data.add(new SerializedData(Collections.EMPTY_LIST, result));
    }
    serializerEngine.serialize(data, SerializerType.SCANNER);
}
Also used : ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) SerializedData(fr.inria.spirals.repairnator.serializer.engines.SerializedData) MongoDBSerializerEngine(fr.inria.spirals.repairnator.serializer.engines.json.MongoDBSerializerEngine) ArrayList(java.util.ArrayList) List(java.util.List) JsonObject(com.google.gson.JsonObject) MongoConnection(fr.inria.spirals.repairnator.serializer.mongodb.MongoConnection) Sheets(com.google.api.services.sheets.v4.Sheets)

Example 2 with MongoConnection

use of fr.inria.spirals.repairnator.serializer.mongodb.MongoConnection in project repairnator by Spirals-Team.

the class ScannerSerializer4Bears method main.

public static void main(String[] args) throws IOException, GeneralSecurityException {
    GoogleSpreadSheetFactory.initWithFileSecret("client_secret.json");
    GoogleSpreadSheetFactory.setSpreadsheetId(args[1]);
    Sheets sheets = GoogleSpreadSheetFactory.getSheets();
    List<List<Object>> results = sheets.spreadsheets().values().get(GoogleSpreadSheetFactory.getSpreadsheetID(), "Scanner Data!A:M").execute().getValues();
    MongoConnection mongoConnection = new MongoConnection(args[0], "bears");
    if (!mongoConnection.isConnected()) {
        throw new RuntimeException("Error when connection to mongodb");
    }
    MongoDBSerializerEngine serializerEngine = new MongoDBSerializerEngine(mongoConnection);
    List<SerializedData> data = new ArrayList<>();
    for (int i = 1; i < results.size(); i++) {
        List<Object> value = results.get(i);
        JsonObject result = new JsonObject();
        result.addProperty("hostname", Utils.getValue(value, 0));
        result.addProperty("dateBegin", Utils.getValue(value, 1));
        result.addProperty("dateEnd", Utils.getValue(value, 2));
        result.addProperty("duration", Utils.getValue(value, 3));
        result.addProperty("dateLookedFrom", Utils.getValue(value, 4));
        result.addProperty("dateLookedTo", Utils.getValue(value, 5));
        result.addProperty("totalRepoNumber", Utils.getValue(value, 6));
        result.addProperty("totalRepoUsingTravis", Utils.getValue(value, 7));
        result.addProperty("totalScannedBuilds", Utils.getValue(value, 8));
        result.addProperty("totalJavaBuilds", Utils.getValue(value, 9));
        result.addProperty("totalJavaPassingBuilds", Utils.getValue(value, 10));
        result.addProperty("totalJavaFailingBuilds", Utils.getValue(value, 11));
        result.addProperty("totalJavaFailingBuildsWithFailingTests", Utils.getValue(value, 12));
        result.addProperty("totalPRBuilds", Utils.getValue(value, 13));
        result.addProperty("totalFailingAndPassingBuildPairs", Utils.getValue(value, 14));
        result.addProperty("totalPassingAndPassingBuildPairs", Utils.getValue(value, 15));
        result.addProperty("totalPairOfBuilds", Utils.getValue(value, 16));
        result.addProperty("runId", Utils.getValue(value, 17));
        data.add(new SerializedData(Collections.EMPTY_LIST, result));
    }
    serializerEngine.serialize(data, SerializerType.SCANNER4BEARS);
}
Also used : ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) SerializedData(fr.inria.spirals.repairnator.serializer.engines.SerializedData) MongoDBSerializerEngine(fr.inria.spirals.repairnator.serializer.engines.json.MongoDBSerializerEngine) ArrayList(java.util.ArrayList) List(java.util.List) JsonObject(com.google.gson.JsonObject) MongoConnection(fr.inria.spirals.repairnator.serializer.mongodb.MongoConnection) Sheets(com.google.api.services.sheets.v4.Sheets)

Example 3 with MongoConnection

use of fr.inria.spirals.repairnator.serializer.mongodb.MongoConnection in project repairnator by Spirals-Team.

the class CheckIfFutureBuildIdWhereWellComputed method main.

public static void main(String[] args) throws IOException {
    List<String> allIds = Files.readAllLines(new File(args[0]).toPath());
    String dbCollectionUrl = args[1];
    String dbName = args[2];
    String collectionName = args[3];
    final List<String> projectsNames = Files.readAllLines(new File(args[4]).toPath());
    String githubLogin = args[5];
    String githubToken = args[6];
    RepairnatorConfig.getInstance().setGithubLogin(githubLogin);
    RepairnatorConfig.getInstance().setGithubToken(githubToken);
    MongoConnection mongoConnection = new MongoConnection(dbCollectionUrl, dbName);
    MongoDatabase database = mongoConnection.getMongoDatabase();
    MongoCollection collection = database.getCollection(collectionName);
    Calendar limitDateMay = Calendar.getInstance();
    limitDateMay.set(2017, Calendar.MAY, 10);
    HashMap<String, List<Integer>> results = new HashMap<>();
    Block<Document> block = new Block<Document>() {

        @Override
        public void apply(Document document) {
            Object pBuildId = document.get("previousBuildId");
            if (pBuildId instanceof Integer) {
                int previousBuildId = document.getInteger("previousBuildId", -1);
                int nextBuildId = document.getInteger("buildId", -1);
                if (previousBuildId != -1 && nextBuildId != -1) {
                    Build previousBuild = BuildHelper.getBuildFromId(previousBuildId, null);
                    Build nextBuild = BuildHelper.getNextBuildOfSameBranchOfStatusAfterBuild(previousBuild, null);
                    if (nextBuild.getId() != nextBuildId) {
                        String projectName = previousBuild.getRepository().getSlug();
                        if (projectsNames == null || projectsNames.contains(projectName)) {
                            if (!results.containsKey(projectName)) {
                                results.put(projectName, new ArrayList<>());
                            }
                            results.get(projectName).add(previousBuildId);
                            i++;
                        }
                    }
                }
            }
        }
    };
    for (String s : allIds) {
        int buildId = Integer.parseInt(s);
        collection.find(and(gt("buildReproductionDate", limitDateMay.getTime()), eq("previousBuildId", buildId), eq("lastReproducedBuggyBuild", true))).forEach(block);
    }
    System.out.println(allIds.size() + " ids read, and got: " + i);
    System.out.println(results.keySet().size() + " detected projects: (" + StringUtils.join(results.keySet(), ",") + ")");
    System.out.println("Results:");
    for (String s : results.keySet()) {
        System.out.println("Project " + s + " : ");
        System.out.println(StringUtils.join(results.get(s), "\n"));
        System.out.println("\n");
    }
}
Also used : HashMap(java.util.HashMap) Calendar(java.util.Calendar) Document(org.bson.Document) MongoCollection(com.mongodb.client.MongoCollection) Build(fr.inria.spirals.jtravis.entities.Build) Block(com.mongodb.Block) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) MongoConnection(fr.inria.spirals.repairnator.serializer.mongodb.MongoConnection) MongoDatabase(com.mongodb.client.MongoDatabase)

Example 4 with MongoConnection

use of fr.inria.spirals.repairnator.serializer.mongodb.MongoConnection in project repairnator by Spirals-Team.

the class CheckIfIdsAreInDatabase method main.

public static void main(String[] args) throws IOException {
    List<String> allIds = Files.readAllLines(new File(args[0]).toPath());
    String dbCollectionUrl = args[1];
    String dbName = args[2];
    String collectionName = args[3];
    List<String> projectsNames = null;
    if (args.length > 4) {
        projectsNames = Files.readAllLines(new File(args[4]).toPath());
        String githubLogin = args[5];
        String githubToken = args[6];
        RepairnatorConfig.getInstance().setGithubLogin(githubLogin);
        RepairnatorConfig.getInstance().setGithubToken(githubToken);
    }
    MongoConnection mongoConnection = new MongoConnection(dbCollectionUrl, dbName);
    MongoDatabase database = mongoConnection.getMongoDatabase();
    MongoCollection collection = database.getCollection(collectionName);
    Calendar limitDateMay = Calendar.getInstance();
    // limitDateMay.set(2017, Calendar.MAY, 10);
    limitDateMay.set(2017, Calendar.SEPTEMBER, 8);
    Calendar limitDateNow = Calendar.getInstance();
    HashMap<String, List<Integer>> results = new HashMap<>();
    int i = 0;
    for (String s : allIds) {
        int buildId = Integer.parseInt(s);
        long total = collection.count(and(gt("buildReproductionDate", limitDateMay.getTime()), eq("previousBuildId", buildId)));
        if (total == 0) {
            Build build = BuildHelper.getBuildFromId(buildId, null);
            String projectName = build.getRepository().getSlug();
            if (projectsNames == null || projectsNames.contains(projectName)) {
                if (!results.containsKey(projectName)) {
                    results.put(projectName, new ArrayList<>());
                }
                results.get(projectName).add(buildId);
                i++;
            }
        }
    }
    System.out.println(allIds.size() + " ids read, and got: " + i);
    System.out.println(results.keySet().size() + " detected projects: (" + StringUtils.join(results.keySet(), ",") + ")");
    System.out.println("Results:");
    for (String s : results.keySet()) {
        System.out.println("Project " + s + " : ");
        System.out.println(StringUtils.join(results.get(s), "\n"));
        System.out.println("\n");
    }
}
Also used : HashMap(java.util.HashMap) Calendar(java.util.Calendar) MongoCollection(com.mongodb.client.MongoCollection) Build(fr.inria.spirals.jtravis.entities.Build) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) MongoConnection(fr.inria.spirals.repairnator.serializer.mongodb.MongoConnection) MongoDatabase(com.mongodb.client.MongoDatabase)

Example 5 with MongoConnection

use of fr.inria.spirals.repairnator.serializer.mongodb.MongoConnection in project repairnator by Spirals-Team.

the class UpdateDataForSpecifyingLastReproduction method main.

public static void main(String[] args) {
    String dbConnectionUrl = args[0];
    String dbName = args[1];
    String collectionName = args[2];
    MongoConnection mongoConnection = new MongoConnection(dbConnectionUrl, dbName);
    MongoDatabase database = mongoConnection.getMongoDatabase();
    MongoCollection collection = database.getCollection(collectionName);
    Calendar limitDateMay = Calendar.getInstance();
    limitDateMay.set(2017, Calendar.MAY, 10);
    final List<ObjectId> updatedDocs = new ArrayList<>();
    Set<Integer> ids = new HashSet<>();
    Block<Document> block = new Block<Document>() {

        @Override
        public void apply(Document document) {
            ObjectId documentId = document.getObjectId("_id");
            Object pBuildId = document.get("previousBuildId");
            if (pBuildId instanceof Integer) {
                int previousBuildId = document.getInteger("previousBuildId", -1);
                if (previousBuildId != -1) {
                    boolean lastReproducedBuggyBuild = !ids.contains(previousBuildId);
                    ids.add(previousBuildId);
                    document.append("lastReproducedBuggyBuild", lastReproducedBuggyBuild);
                    collection.replaceOne(eq("_id", documentId), document, new UpdateOptions().upsert(true));
                    updatedDocs.add(documentId);
                }
            }
        }
    };
    collection.find().sort(orderBy(descending("buildReproductionDate"))).forEach(block);
    System.out.println("Updated docs: " + updatedDocs.size());
}
Also used : ObjectId(org.bson.types.ObjectId) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) Document(org.bson.Document) UpdateOptions(com.mongodb.client.model.UpdateOptions) MongoCollection(com.mongodb.client.MongoCollection) Block(com.mongodb.Block) MongoConnection(fr.inria.spirals.repairnator.serializer.mongodb.MongoConnection) MongoDatabase(com.mongodb.client.MongoDatabase) HashSet(java.util.HashSet)

Aggregations

MongoConnection (fr.inria.spirals.repairnator.serializer.mongodb.MongoConnection)14 ArrayList (java.util.ArrayList)10 List (java.util.List)8 MongoDatabase (com.mongodb.client.MongoDatabase)7 MongoDBSerializerEngine (fr.inria.spirals.repairnator.serializer.engines.json.MongoDBSerializerEngine)7 Sheets (com.google.api.services.sheets.v4.Sheets)6 JsonObject (com.google.gson.JsonObject)6 MongoCollection (com.mongodb.client.MongoCollection)6 SerializedData (fr.inria.spirals.repairnator.serializer.engines.SerializedData)6 Block (com.mongodb.Block)5 Document (org.bson.Document)5 File (java.io.File)4 Calendar (java.util.Calendar)4 HashMap (java.util.HashMap)4 Build (fr.inria.spirals.jtravis.entities.Build)3 HashSet (java.util.HashSet)3 ObjectId (org.bson.types.ObjectId)3 BufferedWriter (java.io.BufferedWriter)2 FileWriter (java.io.FileWriter)2 UpdateOptions (com.mongodb.client.model.UpdateOptions)1