From 4aa96bd6652358e3af219b9472f012484becdc0d Mon Sep 17 00:00:00 2001 From: Mahdi Khosravi Date: Tue, 31 Oct 2023 08:17:43 +0000 Subject: [PATCH 1/3] add new parameter for affected tests in MethodMojo --- .../illinois/starts/jdeps/MethodsMojo.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/starts-plugin/src/main/java/edu/illinois/starts/jdeps/MethodsMojo.java b/starts-plugin/src/main/java/edu/illinois/starts/jdeps/MethodsMojo.java index df7b4d96..996eb49b 100644 --- a/starts-plugin/src/main/java/edu/illinois/starts/jdeps/MethodsMojo.java +++ b/starts-plugin/src/main/java/edu/illinois/starts/jdeps/MethodsMojo.java @@ -72,6 +72,12 @@ public class MethodsMojo extends DiffMojo { @Parameter(property = "debug", defaultValue = FALSE) private boolean debug; + /** + * Set this to "true" to compute affected test classes as well. + */ + @Parameter(property = "computeAffectedTests", defaultValue = FALSE) + private boolean computeAffectedTests; + public void setDebug(boolean debug) { this.debug = debug; } @@ -173,12 +179,15 @@ protected void runMethods(boolean impacted) throws MojoExecutionException { if (!Files.exists(Paths.get(getArtifactsDir() + METHODS_CHECKSUMS_SERIALIZED_FILE))) { changedMethods = new HashSet<>(); newMethods = MethodLevelStaticDepsBuilder.computeMethods(); - affectedTestClasses = MethodLevelStaticDepsBuilder.computeTestClasses(); oldClasses = new HashSet<>(); changedClasses = new HashSet<>(); newClasses = MethodLevelStaticDepsBuilder.getClasses(); nonAffectedMethods = new HashSet<>(); + if (computeAffectedTests) { + affectedTestClasses = MethodLevelStaticDepsBuilder.computeTestClasses(); + } + if (impacted) { impactedMethods = newMethods; } @@ -197,6 +206,9 @@ protected void runMethods(boolean impacted) throws MojoExecutionException { if (impacted) { computeImpactedMethods(); + + } + if (computeAffectedTests) { computeAffectedTestClasses(); } @@ -232,13 +244,18 @@ private void logInfoStatements(boolean impacted) { logger.log(Level.INFO, "NewClasses: " + newClasses.size()); logger.log(Level.INFO, "OldClasses: " + oldClasses.size()); logger.log(Level.INFO, "ChangedClasses: " + changedClasses.size()); - logger.log(Level.INFO, "AffectedTestClasses: " + affectedTestClasses.size()); + + if (computeAffectedTests) { + logger.log(Level.INFO, "AffectedTestClasses: " + affectedTestClasses.size()); + } // DEBUG PRINTS if (debug) { logger.log(Level.INFO, "ChangedMethods: " + changedMethods); logger.log(Level.INFO, "ImpactedMethods: " + impactedMethods); - logger.log(Level.INFO, "AffectedTestClasses: " + affectedTestClasses); + if (computeAffectedTests) { + logger.log(Level.INFO, "AffectedTestClasses: " + affectedTestClasses); + } } } From 010bb5ae8d4350dabf8925663c08ae68e6b88973 Mon Sep 17 00:00:00 2001 From: Mahdi Khosravi Date: Tue, 31 Oct 2023 08:25:02 +0000 Subject: [PATCH 2/3] add new parameter for affected tests in HybridMojo --- .../edu/illinois/starts/jdeps/HybridMojo.java | 73 ++++++++++++------- 1 file changed, 48 insertions(+), 25 deletions(-) diff --git a/starts-plugin/src/main/java/edu/illinois/starts/jdeps/HybridMojo.java b/starts-plugin/src/main/java/edu/illinois/starts/jdeps/HybridMojo.java index 24156f14..30876f40 100644 --- a/starts-plugin/src/main/java/edu/illinois/starts/jdeps/HybridMojo.java +++ b/starts-plugin/src/main/java/edu/illinois/starts/jdeps/HybridMojo.java @@ -63,6 +63,12 @@ public class HybridMojo extends DiffMojo { @Parameter(property = "debug", defaultValue = TRUE) private boolean debug; + /** + * Set this to "true" to compute affected test classes as well. + */ + @Parameter(property = "computeAffectedTests", defaultValue = FALSE) + private boolean computeAffectedTests; + public void setComputeImpactedMethods(boolean computeImpactedMethods) { this.computeImpactedMethods = computeImpactedMethods; } @@ -160,8 +166,11 @@ public void execute() throws MojoExecutionException { // Build method level static dependencies try { MethodLevelStaticDepsBuilder.buildMethodsGraph(includeVariables); - methodToTestClasses = MethodLevelStaticDepsBuilder.computeMethodToTestClasses(); + classesChecksum = MethodLevelStaticDepsBuilder.computeClassesChecksums(loader, cleanBytes); + if (computeAffectedTests) { + methodToTestClasses = MethodLevelStaticDepsBuilder.computeMethodToTestClasses(); + } } catch (Exception exception) { throw new RuntimeException(exception); } @@ -196,7 +205,6 @@ protected void runHybrid(boolean impacted) throws MojoExecutionException { methodsCheckSum = MethodLevelStaticDepsBuilder.getMethodsCheckSum(); changedMethods = new HashSet<>(); newMethods = MethodLevelStaticDepsBuilder.computeMethods(); - affectedTestClasses = MethodLevelStaticDepsBuilder.computeTestClasses(); newClasses = MethodLevelStaticDepsBuilder.getClasses(); oldClasses = new HashSet<>(); deletedClasses = new HashSet<>(); @@ -204,6 +212,10 @@ protected void runHybrid(boolean impacted) throws MojoExecutionException { changedClassesWithoutChangedHeaders = new HashSet<>(); nonAffectedMethods = new HashSet<>(); + if (computeAffectedTests) { + affectedTestClasses = MethodLevelStaticDepsBuilder.computeTestClasses(); + } + if (impacted) { impactedMethods = newMethods; impactedClasses = newClasses; @@ -226,9 +238,11 @@ protected void runHybrid(boolean impacted) throws MojoExecutionException { classDependencyGraph = MethodLevelStaticDepsBuilder.constructClassesDependencyGraph(); MethodLevelStaticDepsBuilder.constuctTestClassesToClassesGraph(); - classToTestClassGraph = MethodLevelStaticDepsBuilder.constructClassesToTestClassesGraph(); - methodToTestClasses = MethodLevelStaticDepsBuilder.computeMethodToTestClasses(); - affectedTestClasses = new HashSet<>(); + if (computeAffectedTests) { + classToTestClassGraph = MethodLevelStaticDepsBuilder.constructClassesToTestClassesGraph(); + methodToTestClasses = MethodLevelStaticDepsBuilder.computeMethodToTestClasses(); + affectedTestClasses = new HashSet<>(); + } setChangedAndNonaffectedMethods(); @@ -276,7 +290,9 @@ private void logInfo(boolean impacted) { logger.log(Level.INFO, "DeletedClasses: " + deletedClasses.size()); logger.log(Level.INFO, "ChangedClassesWithChangedHeaders: " + changedClassesWithChangedHeaders.size()); logger.log(Level.INFO, "ChangedClassesWithoutChangedHeaders: " + changedClassesWithoutChangedHeaders.size()); - logger.log(Level.INFO, "AffectedTestClasses: " + affectedTestClasses.size()); + if (computeAffectedTests) { + logger.log(Level.INFO, "AffectedTestClasses: " + affectedTestClasses.size()); + } if (impacted) { logger.log(Level.INFO, "ImpactedClasses: " + impactedClasses.size()); @@ -286,11 +302,13 @@ private void logInfo(boolean impacted) { if (debug) { logger.log(Level.INFO, "ImpactedMethods: " + impactedMethods); logger.log(Level.INFO, "ImpactedClasses: " + impactedClasses); - logger.log(Level.INFO, "AffectedTestClasses: " + affectedTestClasses); logger.log(Level.INFO, "ClassDependencyGraph: " + classDependencyGraph); - logger.log(Level.INFO, "ClassToTestClassGraph: " + classToTestClassGraph); logger.log(Level.INFO, "ChangedClassesWithChangedHeaders: " + changedClassesWithChangedHeaders); logger.log(Level.INFO, "ChangedClassesWithoutChangedHeaders: " + changedClassesWithoutChangedHeaders); + if (computeAffectedTests) { + logger.log(Level.INFO, "AffectedTestClasses: " + affectedTestClasses); + logger.log(Level.INFO, "ClassToTestClassGraph: " + classToTestClassGraph); + } } } @@ -320,23 +338,24 @@ protected void setChangedAndNonaffectedMethods() throws MojoExecutionException { changedMethods = methodsData == null ? new HashSet() : methodsData.get(0); newMethods = methodsData == null ? new HashSet() : methodsData.get(1); - for (String newMethod : newMethods) { - affectedTestClasses.addAll(methodToTestClasses.getOrDefault(newMethod, new HashSet<>())); - } + if (computeAffectedTests) { + for (String newMethod : newMethods) { + affectedTestClasses.addAll(methodToTestClasses.getOrDefault(newMethod, new HashSet<>())); + } - for (String changedMethod : changedMethods) { - affectedTestClasses.addAll(methodToTestClasses.getOrDefault(changedMethod, new HashSet<>())); - } + for (String changedMethod : changedMethods) { + affectedTestClasses.addAll(methodToTestClasses.getOrDefault(changedMethod, new HashSet<>())); + } - for (String addedClass : newClasses) { - affectedTestClasses.addAll(classToTestClassGraph.getOrDefault(addedClass, new HashSet<>())); - } + for (String addedClass : newClasses) { + affectedTestClasses.addAll(classToTestClassGraph.getOrDefault(addedClass, new HashSet<>())); + } - for (String changedClassesWithChangedHeader : changedClassesWithChangedHeaders) { - affectedTestClasses - .addAll(classToTestClassGraph.getOrDefault(changedClassesWithChangedHeader, new HashSet<>())); + for (String changedClassesWithChangedHeader : changedClassesWithChangedHeaders) { + affectedTestClasses + .addAll(classToTestClassGraph.getOrDefault(changedClassesWithChangedHeader, new HashSet<>())); + } } - } /** @@ -348,8 +367,10 @@ private void computeImpactedMethods() { impactedMethods = new HashSet<>(); impactedMethods.addAll(findImpactedMethods(changedMethods)); impactedMethods.addAll(findImpactedMethods(newMethods)); - for (String impactedMethod : impactedMethods) { - affectedTestClasses.addAll(methodToTestClasses.getOrDefault(impactedMethod, new HashSet())); + if (computeAffectedTests) { + for (String impactedMethod : impactedMethods) { + affectedTestClasses.addAll(methodToTestClasses.getOrDefault(impactedMethod, new HashSet())); + } } } @@ -363,8 +384,10 @@ private void computeImpactedClasses() { impactedClasses = new HashSet<>(); impactedClasses.addAll(findImpactedClasses(newClasses)); impactedClasses.addAll(findImpactedClasses(changedClassesWithChangedHeaders)); - for (String impactedClass : impactedClasses) { - affectedTestClasses.addAll(classToTestClassGraph.getOrDefault(impactedClass, new HashSet())); + if (computeAffectedTests) { + for (String impactedClass : impactedClasses) { + affectedTestClasses.addAll(classToTestClassGraph.getOrDefault(impactedClass, new HashSet())); + } } } From e6737a5567af6246e307364e9fcde152a579bd2a Mon Sep 17 00:00:00 2001 From: Mahdi Khosravi Date: Tue, 31 Oct 2023 08:43:22 +0000 Subject: [PATCH 3/3] add setters for new params --- .../src/main/java/edu/illinois/starts/jdeps/HybridMojo.java | 4 ++++ .../src/main/java/edu/illinois/starts/jdeps/MethodsMojo.java | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/starts-plugin/src/main/java/edu/illinois/starts/jdeps/HybridMojo.java b/starts-plugin/src/main/java/edu/illinois/starts/jdeps/HybridMojo.java index 30876f40..c21e9fb6 100644 --- a/starts-plugin/src/main/java/edu/illinois/starts/jdeps/HybridMojo.java +++ b/starts-plugin/src/main/java/edu/illinois/starts/jdeps/HybridMojo.java @@ -77,6 +77,10 @@ public void setUpdateMethodsChecksums(boolean updateChecksums) { this.updateMethodsChecksums = updateChecksums; } + public void setComputeAffectedTests(boolean computeAffectedTests) { + this.computeAffectedTests = computeAffectedTests; + } + public Set getAffectedMethods() { Set affectedMethods = new HashSet<>(); affectedMethods.addAll(changedMethods); diff --git a/starts-plugin/src/main/java/edu/illinois/starts/jdeps/MethodsMojo.java b/starts-plugin/src/main/java/edu/illinois/starts/jdeps/MethodsMojo.java index 996eb49b..1f800f20 100644 --- a/starts-plugin/src/main/java/edu/illinois/starts/jdeps/MethodsMojo.java +++ b/starts-plugin/src/main/java/edu/illinois/starts/jdeps/MethodsMojo.java @@ -94,6 +94,10 @@ public void setIncludeVariables(boolean includeVariables) { this.includeVariables = includeVariables; } + public void setComputeAffectedTests(boolean computeAffectedTests) { + this.computeAffectedTests = computeAffectedTests; + } + public Set getAffectedMethods() { Set affectedMethods = new HashSet<>(); affectedMethods.addAll(changedMethods);