From eb1e4b10898fb0becc7ec104cbd4f49f8f7f49c8 Mon Sep 17 00:00:00 2001 From: Martin Kellogg Date: Tue, 30 Jul 2024 12:32:35 -0400 Subject: [PATCH 1/4] add modularity model logic --- Keyvalue.py | 1 + main.py | 9 +++- resources/test_data.json | 99 ++++++++++++++++++++++++++-------------- 3 files changed, 73 insertions(+), 36 deletions(-) diff --git a/Keyvalue.py b/Keyvalue.py index 43a0801..3b9d6db 100644 --- a/Keyvalue.py +++ b/Keyvalue.py @@ -21,3 +21,4 @@ class JsonKeys(Enum): BUG_TYPE = 'bug_type' CHECKER_QUAL_REQURIED = 'checker_qual_required' BUG_PATTERN = 'bug_pattern' + MODEL = 'model' diff --git a/main.py b/main.py index a855ba1..4d109d6 100644 --- a/main.py +++ b/main.py @@ -292,7 +292,7 @@ def build_specimin_command(project_name: str, project_name (str): Name of the target project. Example: daikon target_base_dir (str): path of the target project directory. Ex: ISSUES/cf-1291 root_dir (str): A directory path relative to the project base directory where java package stored. - targets ({'method': '' or 'field': '', 'file': '', 'package': ''}) : target java file and method/field name data + targets ({'method': '' or 'field': '', 'file': '', 'package': '', 'model' : ''}) : target java file, modularity model, and method/field name data Retruns: command (str): The gradle command of SPECIMIN for the issue. @@ -335,6 +335,7 @@ def build_specimin_command(project_name: str, field_name = target.get(JsonKeys.FIELD_NAME.value) file_name = target[JsonKeys.FILE_NAME.value] package_name = target[JsonKeys.PACKAGE.value] + modularity_model = target[JsonKeys.MODEL.value] dot_replaced_package_name = package_name.replace('.', '/') @@ -380,7 +381,11 @@ def build_specimin_command(project_name: str, if jar_path: jar_path_subcommand = " --jarPath" + " " + f"\"{jar_path}\"" - command_args = root_dir_subcommand + " " + output_dir_subcommand + " " + target_file_subcommand + " " + target_method_subcommand + target_field_subcommand + jar_path_subcommand + model_subcommand = "" + if modularity_model: + model_subcommand = " --modularityModel " + f"\"{modularity_model}\"" + + command_args = root_dir_subcommand + " " + output_dir_subcommand + " " + model_subcommand + " " + target_file_subcommand + " " + target_method_subcommand + target_field_subcommand + jar_path_subcommand command = "" diff --git a/resources/test_data.json b/resources/test_data.json index 628c836..e1d06d6 100644 --- a/resources/test_data.json +++ b/resources/test_data.json @@ -11,7 +11,8 @@ { "method": "executePureMethod(Method, Object, Object[])", "file": "PureMethodInfo.java", - "package": "daikon.chicory" + "package": "daikon.chicory", + "model": "cf" } ], "version": "2.1.10", @@ -40,7 +41,8 @@ { "method": "setAccessible(AccessibleObject)", "file": "ClassUtil.java", - "package": "net.openhft.chronicle.core.internal" + "package": "net.openhft.chronicle.core.internal", + "model": "cf" } ], "version": "3.40.0", @@ -62,7 +64,8 @@ { "method": "getMode(ColumnMetadata, Map)", "file": "IndexMode.java", - "package": "org.apache.cassandra.index.sasi.conf" + "package": "org.apache.cassandra.index.sasi.conf", + "model": "cf" } ], "version": "3.36.0", @@ -90,7 +93,8 @@ { "method": "spliterator()", "file": "ResultQuery.java", - "package": "org.jooq" + "package": "org.jooq", + "model": "cf" } ], "version": "", @@ -112,7 +116,8 @@ { "method": "hasNext()", "file": "SSTableScanner.java", - "package": "org.apache.cassandra.io.sstable.format" + "package": "org.apache.cassandra.io.sstable.format", + "model": "cf" } ], "version": "3.35.0", @@ -134,7 +139,8 @@ { "method": "transform(String, byte[])", "file": "Avro2Confluent.java", - "package": "com.fillmore_labs.kafka.sensors.serde.confluent.interop" + "package": "com.fillmore_labs.kafka.sensors.serde.confluent.interop", + "model": "cf" } ], "version": "3.35.0", @@ -157,7 +163,8 @@ { "method": "method()", "file": "Version.java", - "package": "net.mtu.eggplant.checker.parser_error" + "package": "net.mtu.eggplant.checker.parser_error", + "model": "cf" } ], "version": "3.12.0", @@ -186,7 +193,8 @@ { "method": "toPos(Iterable)", "file": "SqlParserPos.java", - "package": "org.apache.calcite.sql.parser" + "package": "org.apache.calcite.sql.parser", + "model": "cf" } ], "version": "3.7.1", @@ -209,7 +217,8 @@ "method": "arrayForOne(int[], int, IntConsumer)", "file": "IncomparableTypes.java", "package": "com.example.stream", - "inner_class": "Splitr" + "inner_class": "Splitr", + "model": "cf" } ], "version": "1.9.11", @@ -243,7 +252,8 @@ "method": "expand(PCollection)", "file": "InvoicingPipeline.java", "package": "google.registry.beam.invoicing", - "inner_class": "GenerateInvoiceRows" + "inner_class": "GenerateInvoiceRows", + "model": "cf" } ], "version": "3.1.0", @@ -272,7 +282,8 @@ { "method": "equals(Object)", "file": "ImmutableIntList.java", - "package": "org.apache.calcite.util" + "package": "org.apache.calcite.util", + "model": "cf" } ], "version": "3.6.0", @@ -299,7 +310,8 @@ { "method": "checkedEntry(Entry, B>)", "file": "MutableClassToInstanceMap.java", - "package": "com.google.common.collect" + "package": "com.google.common.collect", + "model": "cf" } ], "version": "3.0.1", @@ -330,7 +342,8 @@ "method": "getBestValidator()", "file": "FuturesGetChecked.java", "package": "com.google.common.util.concurrent", - "inner_class": "GetCheckedTypeValidatorHolder" + "inner_class": "GetCheckedTypeValidatorHolder", + "model": "cf" } ], "version": "3.0.1", @@ -359,7 +372,8 @@ "method": "wrapCollection(K, Collection)", "file": "Multimaps.java", "package": "com.google.common.collect", - "inner_class": "CustomMultimap" + "inner_class": "CustomMultimap", + "model": "cf" } ], "version": "3.0.1", @@ -386,11 +400,12 @@ "root_dir": "", "targets": [ { - "method": "", + "method": "", "field": "EMPTY_NAVIGABLE_SET", "file": "Collections.java", "package": "com.example", - "inner_class": "UnmodifiableNavigableSet" + "inner_class": "UnmodifiableNavigableSet", + "model": "cf" } ], "version": "1.9.13", @@ -424,7 +439,8 @@ "file": "AbstractList.java", "package": "com.example", "inner_class": "", - "non_primary_class": "SubList" + "non_primary_class": "SubList", + "model": "cf" } ], "version": "1.9.13", @@ -457,7 +473,8 @@ "method": "via(Contextful>, Contextful>>)", "file": "FileIO.java", "package": "org.apache.beam.sdk.io", - "inner_class": "Write" + "inner_class": "Write", + "model": "cf" } ], "version": "3.40.0", @@ -481,7 +498,8 @@ "method": "difference(Map, Map, Equivalence)", "file": "Maps.java", "package": "com.google.common.collect", - "inner_class": "" + "inner_class": "", + "model": "javac" } ], "version": "3.0.1", @@ -512,7 +530,8 @@ "method": "create(Class

, Class, String, PropertyMetadata)", "file": "PropertyFactoryManager.java", "package": "io.github.mmm.property.factory", - "inner_class": "" + "inner_class": "", + "model": "javac" } ], "version": "", @@ -541,7 +560,8 @@ "method": "simpleFieldValues(String, Class, Iterable)", "file": "FieldSupport.java", "package": "org.assertj.core.util.introspection", - "inner_class": "" + "inner_class": "", + "model": "javac" } ], "version": "", @@ -572,7 +592,8 @@ "method": "toArray()", "file": "ForwardingCollection.java", "package": "com.google.common.collect", - "inner_class": "" + "inner_class": "", + "model": "nullaway" } ], "version": "0.2.2", @@ -598,7 +619,8 @@ "method": "longAccumulate(long, LongBinaryOperator, boolean)", "file": "Striped64.java", "package": "java.util.concurrent.atomic", - "inner_class": "" + "inner_class": "", + "model": "nullaway" } ], "bug_pattern": { @@ -628,7 +650,8 @@ "method": "iterator()", "file": "AbstractLinkedDeque.java", "package": "com.github.benmanes.caffeine.cache", - "inner_class": "" + "inner_class": "", + "model": "nullaway" } ], "bug_pattern": { @@ -659,7 +682,8 @@ "method": "evictFromMain(int)", "file": "BoundedLocalCache.java", "package": "com.github.benmanes.caffeine.cache", - "inner_class": "" + "inner_class": "", + "model": "nullaway" } ], "bug_pattern": { @@ -690,7 +714,8 @@ "method": "setUp()", "file": "UnitOfWorkAwareProxyFactoryTest.java", "package": "io.dropwizard.hibernate", - "inner_class": "" + "inner_class": "", + "model": "nullaway" } ], "bug_pattern": { @@ -719,12 +744,13 @@ "method": "MutableClock(Instant, ZoneId)", "file": "MutableClock.java", "package": "com.cogvio.time", - "inner_class": "" + "inner_class": "", + "model": "nullaway" } ], "bug_pattern": { "file_pattern": "(\\w+\\.java)", - "error_pattern": "[NullAway] (.*)" + "error_pattern": "\\[NullAway\\] initializer (.*)" }, "version": "0.7.3", "java_version": "", @@ -749,12 +775,13 @@ "method": "SignatureX(DSAPublicKey, int, byte[])", "file": "SignatureX.java", "package": "net.java.otr4j.messages", - "inner_class": "" + "inner_class": "", + "model": "nullaway" } ], "bug_pattern": { "file_pattern": "(\\w+\\.java)", - "error_pattern": "[NullAway] (.*)" + "error_pattern": "\\[NullAway\\] (.*)" }, "version": "0.7.5", "java_version": "", @@ -779,7 +806,8 @@ "method": "getStatistics()", "file": "ActionManagerFactoryImpl.java", "package": "com.adobe.acs.commons.fam.impl", - "inner_class": "" + "inner_class": "", + "model": "nullaway" } ], "bug_pattern": { @@ -811,7 +839,8 @@ "field": "entrySet", "file": "CaffeinatedGuavaCache.java", "package": "com.github.benmanes.caffeine.guava", - "inner_class": "AsMapView" + "inner_class": "AsMapView", + "model": "nullaway" } ], "bug_pattern": { @@ -841,7 +870,8 @@ "method": "getEvictionListener(boolean)", "file": "Caffeine.java", "package": "com.github.benmanes.caffeine.cache", - "inner_class": "" + "inner_class": "", + "model": "nullaway" } ], "bug_pattern": { @@ -872,7 +902,8 @@ "method": "getFeatures(List)", "file": "NodeFactoryGenerator.java", "package": "com.github.benmanes.caffeine.cache", - "inner_class": "" + "inner_class": "", + "model": "nullaway" } ], "bug_pattern": { From 5d0d644d925d610db92d9d73ee85844f4e562d75 Mon Sep 17 00:00:00 2001 From: Martin Kellogg Date: Tue, 30 Jul 2024 12:38:54 -0400 Subject: [PATCH 2/4] also add model to test --- TestMain.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/TestMain.py b/TestMain.py index 72af55c..e06555c 100644 --- a/TestMain.py +++ b/TestMain.py @@ -61,7 +61,8 @@ def test_build_specimin_command(self): targets = [{ "method": "getMode(ColumnMetadata, Map)", "file": "IndexMode.java", - "package": 'org.apache.cassandra.index.sasi.conf' + "package": 'org.apache.cassandra.index.sasi.conf', + "model": "cf" }] target_dir = '/user/ISSUES/cf-6077' @@ -76,7 +77,8 @@ def test_build_specimin_command(self): targets = [{ "method": "transform(String, byte[])", "file": "Avro2Confluent.java", - "package": 'com.fillmore_labs.kafka.sensors.serde.confluent.interop' + "package": 'com.fillmore_labs.kafka.sensors.serde.confluent.interop', + "model" : "cf" }] target_dir = '/user/ISSUES/cf-6019' @@ -109,7 +111,8 @@ def test_run_specimin(self): targets = [{ "method": "bar()", "file": "Simple.java", - "package": "com.example" + "package": "com.example", + "model" : "cf" }] target_dir = 'resources/onefilesimple' @@ -121,4 +124,4 @@ def test_run_specimin(self): if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main() From c0efcf282966b362791e53ba682e970d8930466e Mon Sep 17 00:00:00 2001 From: Martin Kellogg Date: Tue, 30 Jul 2024 12:45:28 -0400 Subject: [PATCH 3/4] adjust expected specimin commands for tests --- resources/specimin_command_cf-6019.txt | 2 +- resources/specimin_command_cf-6077.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/specimin_command_cf-6019.txt b/resources/specimin_command_cf-6019.txt index 9c2ca18..3525974 100644 --- a/resources/specimin_command_cf-6019.txt +++ b/resources/specimin_command_cf-6019.txt @@ -1 +1 @@ -./gradlew run --args='--root "/user/ISSUES/cf-6019/input/kafka-sensors/src/main/java/" --outputDirectory "/user/ISSUES/cf-6019/output/kafka-sensors/src/main/java" --targetFile "com/fillmore_labs/kafka/sensors/serde/confluent/interop/Avro2Confluent.java" --targetMethod "com.fillmore_labs.kafka.sensors.serde.confluent.interop.Avro2Confluent#transform(String, byte[])"' \ No newline at end of file +./gradlew run --args='--root "/user/ISSUES/cf-6019/input/kafka-sensors/src/main/java/" --outputDirectory "/user/ISSUES/cf-6019/output/kafka-sensors/src/main/java" --modularityModel "cf" --targetFile "com/fillmore_labs/kafka/sensors/serde/confluent/interop/Avro2Confluent.java" --targetMethod "com.fillmore_labs.kafka.sensors.serde.confluent.interop.Avro2Confluent#transform(String, byte[])"' diff --git a/resources/specimin_command_cf-6077.txt b/resources/specimin_command_cf-6077.txt index dc066d1..2e108c7 100644 --- a/resources/specimin_command_cf-6077.txt +++ b/resources/specimin_command_cf-6077.txt @@ -1 +1 @@ -./gradlew run --args='--root "/user/ISSUES/cf-6077/input/cassandra/src/java/" --outputDirectory "/user/ISSUES/cf-6077/output/cassandra/src/main/java" --targetFile "org/apache/cassandra/index/sasi/conf/IndexMode.java" --targetMethod "org.apache.cassandra.index.sasi.conf.IndexMode#getMode(ColumnMetadata, Map)"' \ No newline at end of file +./gradlew run --args='--root "/user/ISSUES/cf-6077/input/cassandra/src/java/" --outputDirectory "/user/ISSUES/cf-6077/output/cassandra/src/main/java" --modularityModel "cf" --targetFile "org/apache/cassandra/index/sasi/conf/IndexMode.java" --targetMethod "org.apache.cassandra.index.sasi.conf.IndexMode#getMode(ColumnMetadata, Map)"' From c4c97f909f952d00f91dd706f5aed65cfe04eb15 Mon Sep 17 00:00:00 2001 From: Martin Kellogg Date: Tue, 30 Jul 2024 12:58:46 -0400 Subject: [PATCH 4/4] make the test more robust, and don't add an extra space --- TestMain.py | 2 ++ main.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/TestMain.py b/TestMain.py index e06555c..0a46803 100644 --- a/TestMain.py +++ b/TestMain.py @@ -70,6 +70,7 @@ def test_build_specimin_command(self): target_command = '' with open('resources/specimin_command_cf-6077.txt','r') as file: target_command = file.read() + target_command = target_command.strip() self.assertEqual(command, target_command) # not executing since this crashes specimin proj_name = 'kafka-sensors' @@ -85,6 +86,7 @@ def test_build_specimin_command(self): command = main.build_specimin_command(proj_name, target_dir, root, targets) with open('resources/specimin_command_cf-6019.txt','r') as file: target_command = file.read() + target_command = target_command.strip() self.assertEqual(command, target_command) #not executing since it crashes specimin. diff --git a/main.py b/main.py index 4d109d6..fa9918b 100644 --- a/main.py +++ b/main.py @@ -385,7 +385,7 @@ def build_specimin_command(project_name: str, if modularity_model: model_subcommand = " --modularityModel " + f"\"{modularity_model}\"" - command_args = root_dir_subcommand + " " + output_dir_subcommand + " " + model_subcommand + " " + target_file_subcommand + " " + target_method_subcommand + target_field_subcommand + jar_path_subcommand + command_args = root_dir_subcommand + " " + output_dir_subcommand + model_subcommand + " " + target_file_subcommand + " " + target_method_subcommand + target_field_subcommand + jar_path_subcommand command = ""