Search in sources :

Example 36 with ChangedEntity

use of de.dagere.peass.dependency.analysis.data.ChangedEntity in project peass by DaGeRe.

the class GitUtils method getChangedLines.

public static int getChangedLines(final File projectFolder, final String version, final List<ChangedEntity> entities, ExecutionConfig config) {
    try {
        final File folderTemp = new File(FilenameUtils.normalize(projectFolder.getAbsolutePath()));
        final String command = "git diff --stat=250 " + version + ".." + version + "~1";
        final Process process = Runtime.getRuntime().exec(command, new String[0], folderTemp);
        final String output = StreamGobbler.getFullProcess(process, false);
        int size = 0;
        final String[] lines = output.split("\n");
        // Skip last line - therefore - 1
        for (int index = 0; index < lines.length - 1; index++) {
            final String line = lines[index].trim().replaceAll("\\s{2,}", " ");
            System.out.println(line);
            final String[] parts = line.split("\\|");
            final String clazz = parts[0].replaceAll(" ", "");
            final String number = parts[1];
            final String countString = number.split(" ")[1];
            if (!countString.equals("Bin")) {
                final int count = Integer.parseInt(countString);
                String clazzName = getClazz(clazz, config);
                if (clazzName != null) {
                    final ChangedEntity changedEntity = new ChangedEntity(clazzName, "");
                    if (entities.contains(changedEntity)) {
                        size += count;
                    }
                }
            }
        }
        return size;
    } catch (final IOException e) {
        e.printStackTrace();
    }
    return -1;
}
Also used : ChangedEntity(de.dagere.peass.dependency.analysis.data.ChangedEntity) IOException(java.io.IOException) File(java.io.File)

Example 37 with ChangedEntity

use of de.dagere.peass.dependency.analysis.data.ChangedEntity in project peass by DaGeRe.

the class DependencyReaderUtil method addNewTestcases.

static void addNewTestcases(final VersionStaticSelection newVersionInfo, final Map<ChangedEntity, Set<TestCase>> newTestcases) {
    for (final Map.Entry<ChangedEntity, Set<TestCase>> newTestcase : newTestcases.entrySet()) {
        final ChangedEntity changedClazz = newTestcase.getKey();
        TestSet testsetForChange = null;
        for (final Entry<ChangedEntity, TestSet> dependency : newVersionInfo.getChangedClazzes().entrySet()) {
            ChangedEntity dependencyChangedClazz = dependency.getKey();
            if (dependencyChangedClazz.equals(changedClazz)) {
                testsetForChange = dependency.getValue();
            }
        }
        if (testsetForChange == null) {
            testsetForChange = new TestSet();
            newVersionInfo.getChangedClazzes().put(changedClazz, testsetForChange);
        }
        for (final TestCase testcase : newTestcase.getValue()) {
            testsetForChange.addTest(testcase.onlyClazz(), testcase.getMethod());
        }
    }
}
Also used : Set(java.util.Set) TestSet(de.dagere.peass.dependency.analysis.data.TestSet) TestCase(de.dagere.peass.dependency.analysis.data.TestCase) ChangedEntity(de.dagere.peass.dependency.analysis.data.ChangedEntity) Map(java.util.Map) TestSet(de.dagere.peass.dependency.analysis.data.TestSet)

Example 38 with ChangedEntity

use of de.dagere.peass.dependency.analysis.data.ChangedEntity in project peass by DaGeRe.

the class InitialVersionReader method addVersionTestDependencies.

private void addVersionTestDependencies(final VersionStaticSelection version) {
    for (final Entry<ChangedEntity, TestSet> dependency : version.getChangedClazzes().entrySet()) {
        final ChangedEntity callee = dependency.getKey();
        for (final Entry<TestCase, Set<String>> testcase : dependency.getValue().getTestcases().entrySet()) {
            for (final String testMethod : testcase.getValue()) {
                final Map<ChangedEntity, Set<String>> calledClasses = new HashMap<>();
                final Set<String> methods = new HashSet<>();
                methods.add(callee.getMethod());
                calledClasses.put(new ChangedEntity(callee.getClazz(), callee.getModule()), methods);
                final TestCase testClazz = testcase.getKey();
                TestCase test = new TestCase(testClazz.getClazz(), testMethod, testClazz.getModule());
                dependencyManager.addDependencies(test, calledClasses);
            }
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) TestSet(de.dagere.peass.dependency.analysis.data.TestSet) TestCase(de.dagere.peass.dependency.analysis.data.TestCase) HashMap(java.util.HashMap) ChangedEntity(de.dagere.peass.dependency.analysis.data.ChangedEntity) TestSet(de.dagere.peass.dependency.analysis.data.TestSet) HashSet(java.util.HashSet)

Example 39 with ChangedEntity

use of de.dagere.peass.dependency.analysis.data.ChangedEntity in project peass by DaGeRe.

the class InitialVersionReader method addDependencies.

private void addDependencies(final TestCase testClassName, final ChangedEntity dependentClass) {
    final Map<ChangedEntity, Set<String>> testDependencies = dependencyMap.getOrAddDependenciesForTest(testClassName);
    final ChangedEntity dependencyEntity = new ChangedEntity(dependentClass.getClazz(), dependentClass.getModule());
    Set<String> methods = testDependencies.get(dependencyEntity);
    if (methods == null) {
        methods = new HashSet<>();
        testDependencies.put(dependencyEntity, methods);
    }
    String method = dependentClass.getMethod() + dependentClass.getParameterString();
    methods.add(method);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) TestSet(de.dagere.peass.dependency.analysis.data.TestSet) ChangedEntity(de.dagere.peass.dependency.analysis.data.ChangedEntity)

Example 40 with ChangedEntity

use of de.dagere.peass.dependency.analysis.data.ChangedEntity in project peass by DaGeRe.

the class InitialVersionReader method fillInitialTestDependencies.

private void fillInitialTestDependencies() {
    for (final Entry<TestCase, InitialDependency> dependency : dependencyResult.getInitialversion().getInitialDependencies().entrySet()) {
        for (final ChangedEntity dependentClass : dependency.getValue().getEntities()) {
            TestCase testClassName = dependency.getKey();
            addDependencies(testClassName, dependentClass);
        }
    }
}
Also used : TestCase(de.dagere.peass.dependency.analysis.data.TestCase) InitialDependency(de.dagere.peass.dependency.persistence.InitialDependency) ChangedEntity(de.dagere.peass.dependency.analysis.data.ChangedEntity)

Aggregations

ChangedEntity (de.dagere.peass.dependency.analysis.data.ChangedEntity)138 Test (org.junit.jupiter.api.Test)58 File (java.io.File)57 ClazzChangeData (de.dagere.peass.dependency.changesreading.ClazzChangeData)41 TestCase (de.dagere.peass.dependency.analysis.data.TestCase)25 TestSet (de.dagere.peass.dependency.analysis.data.TestSet)21 ChangeManager (de.dagere.peass.dependency.ChangeManager)18 Set (java.util.Set)17 HashSet (java.util.HashSet)16 ExecutionConfig (de.dagere.peass.config.ExecutionConfig)14 HashMap (java.util.HashMap)14 Map (java.util.Map)13 DependencyReader (de.dagere.peass.dependency.reader.DependencyReader)11 FakeFileIterator (de.dagere.peass.dependencytests.helper.FakeFileIterator)11 VersionIterator (de.dagere.peass.vcs.VersionIterator)10 TreeMap (java.util.TreeMap)9 VersionStaticSelection (de.dagere.peass.dependency.persistence.VersionStaticSelection)8 StaticTestSelection (de.dagere.peass.dependency.persistence.StaticTestSelection)6 EnvironmentVariables (de.dagere.peass.execution.utils.EnvironmentVariables)6 LinkedList (java.util.LinkedList)6