@@ -7,29 +7,40 @@ import os
7
7
import shutil , errno
8
8
import argparse
9
9
import sys
10
+ from pathlib import Path
10
11
11
12
RESOURCE_DIR = os .path .join (os .path .dirname (os .path .dirname (os .path .abspath (__file__ ))), "resources" )
12
13
BEFORE_DIR = os .path .join (RESOURCE_DIR , "before" )
13
14
AFTER_DIR = os .path .join (RESOURCE_DIR , "after" )
14
15
TARGET_DIR = os .path .join (os .path .dirname (os .path .dirname (os .path .abspath (os .path .join (__file__ , "../../" )))), "target/generated-test-sources/project" )
16
+ TARGET_AFTER_DIR = os .path .join (os .path .dirname (os .path .dirname (os .path .abspath (os .path .join (__file__ , "../../" )))), "target/generated-test-sources/after" )
17
+ AFTER_POM = os .path .join (TARGET_AFTER_DIR , "pom.xml" )
18
+
15
19
def main ():
16
20
parser = argparse .ArgumentParser ()
17
21
parser .add_argument ('-v' , '--version' , dest = 'version' ,
18
22
default = '' )
19
23
args = parser .parse_args ()
20
24
run_test (args .version .strip ())
21
25
26
+ # It copies "src/test/resources/before" and "src/test/resources/after" directory to "target/generated-test-sources/project"
27
+ # and "target/generated-test-sources/after" respectively and then execute rewrite command in "target/generated-test-sources/project".
28
+ # It verifies the correctness of the transformation by comparing the directory to "target/generated-test-sources/after" and ensuring it compiles.
22
29
def run_test (version ):
23
30
if os .path .exists (TARGET_DIR ) and os .path .isdir (TARGET_DIR ):
24
31
shutil .rmtree (TARGET_DIR )
25
32
copy_directory (BEFORE_DIR , TARGET_DIR )
33
+ copy_directory (AFTER_DIR , TARGET_AFTER_DIR )
26
34
27
35
subprocess .run (["mvn" , "org.openrewrite.maven:rewrite-maven-plugin:5.21.0:run" ,
28
36
"-Drewrite.recipeArtifactCoordinates=software.amazon.awssdk:migration-tool:" + version ,
29
37
"-Drewrite.activeRecipes=software.amazon.awssdk.UpgradeJavaSdk2" ], cwd = TARGET_DIR , check = True )
30
38
shutil .rmtree (os .path .join (TARGET_DIR , "target" ))
31
- comparison = filecmp .dircmp (TARGET_DIR , AFTER_DIR )
32
- is_same = compare_directory (filecmp .dircmp (TARGET_DIR , AFTER_DIR ))
39
+
40
+ pom_file = Path (AFTER_POM )
41
+ pom_file .write_text (pom_file .read_text ().replace ('V2_VERSION' , version ))
42
+
43
+ is_same = compare_directory (filecmp .dircmp (TARGET_DIR , TARGET_AFTER_DIR ))
33
44
if not is_same :
34
45
raise Exception ("The transformed directory('target/generated-test-sources/project') does not match with the expected one('src/test/resources/after')" )
35
46
result = subprocess .run (["mvn" , "package" ], cwd = TARGET_DIR , capture_output = True , check = True )
0 commit comments