Search in sources :

Example 1 with Diff

use of gumtree.spoon.diff.Diff in project dspot by STAMP-project.

the class SelectorOnDiff method pathToModifiedJavaFile.

private static Set<String> pathToModifiedJavaFile(String baseSha, String pathToChangedVersion) {
    Process p;
    try {
        p = Runtime.getRuntime().exec("git diff " + baseSha, new String[] {}, new File(pathToChangedVersion));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    final Set<String> modifiedJavaFiles = new BufferedReader(new InputStreamReader(p.getInputStream())).lines().filter(line -> line.startsWith("diff") && line.endsWith(".java")).map(line -> line.split(" ")[2]).collect(Collectors.toSet());
    try {
        p.waitFor();
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
    if (Main.verbose) {
        LOGGER.info("Modified files:{}{}", AmplificationHelper.LINE_SEPARATOR, modifiedJavaFiles.stream().collect(Collectors.joining(AmplificationHelper.LINE_SEPARATOR)));
    }
    return modifiedJavaFiles;
}
Also used : Diff(gumtree.spoon.diff.Diff) TypeFilter(spoon.reflect.visitor.filter.TypeFilter) AmplificationHelper(fr.inria.diversify.utils.AmplificationHelper) Logger(org.slf4j.Logger) InputConfiguration(fr.inria.diversify.utils.sosiefier.InputConfiguration) Main(fr.inria.stamp.Main) AstComparator(gumtree.spoon.AstComparator) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) IOException(java.io.IOException) Factory(spoon.reflect.factory.Factory) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) Collections(edu.emory.mathcs.backport.java.util.Collections) File(java.io.File) CtExecutableReference(spoon.reflect.reference.CtExecutableReference) List(java.util.List) CtType(spoon.reflect.declaration.CtType) AmplificationChecker(fr.inria.diversify.utils.AmplificationChecker) BufferedReader(java.io.BufferedReader) CtMethod(spoon.reflect.declaration.CtMethod) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) File(java.io.File)

Example 2 with Diff

use of gumtree.spoon.diff.Diff in project dspot by STAMP-project.

the class SelectorOnDiff method getModifiedMethod.

@SuppressWarnings("unchecked")
private static Set<CtMethod> getModifiedMethod(String pathFile1, String pathFile2) {
    try {
        final File file1 = new File(pathFile1);
        final File file2 = new File(pathFile2);
        if (!file1.exists() || !file2.exists()) {
            return Collections.emptySet();
        }
        Diff result = (new AstComparator()).compare(file1, file2);
        return result.getRootOperations().stream().map(operation -> operation.getSrcNode().getParent(CtMethod.class)).collect(Collectors.toSet());
    } catch (Exception ignored) {
        // if something bad happen, we do not care, we go for next file
        return Collections.emptySet();
    }
}
Also used : Diff(gumtree.spoon.diff.Diff) TypeFilter(spoon.reflect.visitor.filter.TypeFilter) AmplificationHelper(fr.inria.diversify.utils.AmplificationHelper) Logger(org.slf4j.Logger) InputConfiguration(fr.inria.diversify.utils.sosiefier.InputConfiguration) Main(fr.inria.stamp.Main) AstComparator(gumtree.spoon.AstComparator) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) IOException(java.io.IOException) Factory(spoon.reflect.factory.Factory) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) Collections(edu.emory.mathcs.backport.java.util.Collections) File(java.io.File) CtExecutableReference(spoon.reflect.reference.CtExecutableReference) List(java.util.List) CtType(spoon.reflect.declaration.CtType) AmplificationChecker(fr.inria.diversify.utils.AmplificationChecker) BufferedReader(java.io.BufferedReader) CtMethod(spoon.reflect.declaration.CtMethod) AstComparator(gumtree.spoon.AstComparator) Diff(gumtree.spoon.diff.Diff) File(java.io.File) IOException(java.io.IOException)

Aggregations

Collections (edu.emory.mathcs.backport.java.util.Collections)2 AmplificationChecker (fr.inria.diversify.utils.AmplificationChecker)2 AmplificationHelper (fr.inria.diversify.utils.AmplificationHelper)2 InputConfiguration (fr.inria.diversify.utils.sosiefier.InputConfiguration)2 Main (fr.inria.stamp.Main)2 AstComparator (gumtree.spoon.AstComparator)2 Diff (gumtree.spoon.diff.Diff)2 BufferedReader (java.io.BufferedReader)2 File (java.io.File)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 List (java.util.List)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 CtMethod (spoon.reflect.declaration.CtMethod)2 CtType (spoon.reflect.declaration.CtType)2 Factory (spoon.reflect.factory.Factory)2 CtExecutableReference (spoon.reflect.reference.CtExecutableReference)2