@@ -55,20 +55,23 @@ public class TestRepository {
55
55
private static final char JAR_PATH_DELIMITER = '!' ;
56
56
57
57
private static final Map <Path , Path > renameMappings = new LinkedHashMap <>(Map .of (
58
- Path .of ("bazaar" , "bzr" ), Path .of ("bazaar" , ".bzr" ),
59
-
60
- Path .of ("bitkeeper" , "bk" , "BitKeeper" , "etc" , "SCCS_dir" ),
61
- Path .of ("bitkeeper" , ".bk" , "BitKeeper" , "etc" , "SCCS" ),
62
- Path .of ("bitkeeper" , "bk" , "SCCS_dir" ),
63
- Path .of ("bitkeeper" , ".bk" , "SCCS" ),
64
-
65
- Path .of ("bitkeeper" , "bk" ), Path .of ("bitkeeper" , ".bk" ),
66
- Path .of ("mercurial" , "hg" ), Path .of ("mercurial" , ".hg" ),
67
- Path .of ("mercurial" , "hgignore" ), Path .of ("mercurial" , ".hgignore" ),
68
- Path .of ("git" , "git" ), Path .of ("git" , ".git" ),
69
- Path .of ("cvs_test" , "cvsrepo" , "CVS_dir" ), Path .of ("cvs_test" , "cvsrepo" , "CVS" ),
70
- Path .of ("rcs_test" , "RCS_dir" ), Path .of ("rcs_test" , "RCS" ),
71
- Path .of ("teamware" , "SCCS_dir" ), Path .of ("teamware" , "SCCS" )
58
+ Path .of ("bazaar" , "bzr" ),
59
+ Path .of ("bazaar" , ".bzr" ),
60
+
61
+ Path .of ("bitkeeper" , "bk" ),
62
+ Path .of ("bitkeeper" , ".bk" ),
63
+
64
+ Path .of ("mercurial" , "hg" ),
65
+ Path .of ("mercurial" , ".hg" ),
66
+
67
+ Path .of ("mercurial" , "hgignore" ),
68
+ Path .of ("mercurial" , ".hgignore" ),
69
+
70
+ Path .of ("git" , "git" ),
71
+ Path .of ("git" , ".git" ),
72
+
73
+ Path .of ("cvs_test" , "cvsrepo" , "CVS_dir" ),
74
+ Path .of ("cvs_test" , "cvsrepo" , "CVS" )
72
75
));
73
76
74
77
private final RuntimeEnvironment env ;
@@ -102,32 +105,37 @@ public void create(@NotNull final URL url) throws IOException, URISyntaxExceptio
102
105
103
106
private void copyDirectory (Path src , Path dest ) throws IOException {
104
107
try (Stream <Path > stream = Files .walk (src )) {
105
- stream .forEach (source -> {
106
- if (source .equals (src )) {
108
+ stream .forEach (sourceFile -> {
109
+ if (sourceFile .equals (src )) {
107
110
return ;
108
111
}
109
112
try {
110
- // possibly strip zip filesystem for the startsWith method to work
111
- var relativePath = Path .of (src .relativize (source ).toString ());
112
- for (var e : renameMappings .entrySet ()) {
113
- if (relativePath .startsWith (e .getKey ())) {
114
- if (relativePath .getNameCount () > e .getKey ().getNameCount ()) {
115
- relativePath = relativePath .subpath (e .getKey ().getNameCount (), relativePath .getNameCount ());
116
- } else {
117
- relativePath = Path .of ("" );
118
- }
119
- relativePath = e .getValue ().resolve (relativePath );
120
- break ;
121
- }
122
- }
123
- Files .copy (source , dest .resolve (relativePath .toString ()), REPLACE_EXISTING );
113
+ Path destRelativePath = getDestinationRelativePath (src , sourceFile );
114
+ Files .copy (sourceFile , dest .resolve (destRelativePath .toString ()), REPLACE_EXISTING );
124
115
} catch (Exception e ) {
125
116
throw new RuntimeException (e );
126
117
}
127
118
});
128
119
}
129
120
}
130
121
122
+ private Path getDestinationRelativePath (Path sourceDirectory , Path sourceFile ) {
123
+ // possibly strip zip filesystem for the startsWith method to work
124
+ var relativePath = Path .of (sourceDirectory .relativize (sourceFile ).toString ());
125
+ for (var e : renameMappings .entrySet ()) {
126
+ if (relativePath .startsWith (e .getKey ())) {
127
+ if (relativePath .getNameCount () > e .getKey ().getNameCount ()) {
128
+ relativePath = relativePath .subpath (e .getKey ().getNameCount (), relativePath .getNameCount ());
129
+ } else {
130
+ relativePath = Path .of ("" );
131
+ }
132
+ relativePath = e .getValue ().resolve (relativePath );
133
+ break ;
134
+ }
135
+ }
136
+ return relativePath ;
137
+ }
138
+
131
139
public void create (InputStream inputBundle ) throws IOException {
132
140
createEmpty ();
133
141
extractBundle (sourceRoot , inputBundle );
0 commit comments