|
15 | 15 | */
|
16 | 16 | package org.springframework.sbm;
|
17 | 17 |
|
18 |
| -import net.sf.saxon.trans.SymbolicName; |
19 | 18 | import org.apache.commons.io.FileUtils;
|
20 | 19 | import org.apache.maven.shared.invoker.*;
|
21 | 20 | import org.junit.jupiter.api.*;
|
22 | 21 | import org.junit.jupiter.api.io.TempDir;
|
23 |
| -import org.openrewrite.SourceFile; |
24 |
| -import org.openrewrite.java.JavaParser; |
25 |
| -import org.openrewrite.java.internal.JavaTypeCache; |
26 | 22 | import org.openrewrite.java.marker.JavaSourceSet;
|
27 | 23 | import org.openrewrite.java.tree.J;
|
28 | 24 | import org.openrewrite.java.tree.JavaType;
|
|
44 | 40 | import java.net.URL;
|
45 | 41 | import java.nio.file.Files;
|
46 | 42 | import java.nio.file.Path;
|
47 |
| -import java.nio.file.attribute.PosixFilePermission; |
48 |
| -import java.nio.file.attribute.PosixFilePermissions; |
49 | 43 | import java.util.Arrays;
|
50 | 44 | import java.util.List;
|
51 |
| -import java.util.Set; |
52 | 45 | import java.util.regex.Matcher;
|
53 | 46 | import java.util.regex.Pattern;
|
54 | 47 | import java.util.zip.ZipEntry;
|
@@ -95,79 +88,7 @@ static void beforeAll(@TempDir Path tempDir) {
|
95 | 88 | originalUserHome = System.getProperty("user.home");
|
96 | 89 | newUserHome = Path.of(".").resolve(TESTCODE_DIR + "/user.home").toAbsolutePath().normalize().toString();
|
97 | 90 | System.setProperty("user.home", newUserHome);
|
98 |
| - |
99 |
| - // download Maven |
100 |
| - if (!Path.of("./testcode/reposilite-test/user.home/apache-maven-3.9.5/bin/mvn").toFile().exists()) { |
101 |
| - String mavenDownloadUrl = "https://dlcdn.apache.org/maven/maven-3/3.9.5/binaries/apache-maven-3.9.5-bin.zip"; |
102 |
| - try { |
103 |
| - Path mavenInstallDir = Path.of(TESTCODE_DIR + "/user.home"); |
104 |
| - File downloadedMavenZipFile = tempDir.resolve("apache-maven-3.9.5-bin.zip").toFile(); |
105 |
| - FileUtils.copyURLToFile( |
106 |
| - new URL(mavenDownloadUrl), |
107 |
| - downloadedMavenZipFile, |
108 |
| - 10000, |
109 |
| - 30000); |
110 |
| - unzip(downloadedMavenZipFile, mavenInstallDir); |
111 |
| - File file = mavenInstallDir.resolve("apache-maven-3.9.5/bin/mvn").toFile(); |
112 |
| - file.setExecutable(true, false); |
113 |
| - assertThat(file.canExecute()).isTrue(); |
114 |
| - } catch (IOException e) { |
115 |
| - throw new RuntimeException(e); |
116 |
| - } |
117 |
| - } |
118 |
| - } |
119 |
| - |
120 |
| - private static void unzip(File downloadedMavenZipFile, Path mavenInstallDir) { |
121 |
| - try { |
122 |
| - byte[] buffer = new byte[1024]; |
123 |
| - ZipInputStream zis = null; |
124 |
| - |
125 |
| - zis = new ZipInputStream(new FileInputStream(downloadedMavenZipFile)); |
126 |
| - |
127 |
| - ZipEntry zipEntry = zis.getNextEntry(); |
128 |
| - while (zipEntry != null) { |
129 |
| - File newFile = newFile(mavenInstallDir.toFile(), zipEntry); |
130 |
| - if (zipEntry.isDirectory()) { |
131 |
| - if (!newFile.isDirectory() && !newFile.mkdirs()) { |
132 |
| - throw new IOException("Failed to create directory " + newFile); |
133 |
| - } |
134 |
| - } else { |
135 |
| - // fix for Windows-created archives |
136 |
| - File parent = newFile.getParentFile(); |
137 |
| - if (!parent.isDirectory() && !parent.mkdirs()) { |
138 |
| - throw new IOException("Failed to create directory " + parent); |
139 |
| - } |
140 |
| - |
141 |
| - // write file content |
142 |
| - FileOutputStream fos = new FileOutputStream(newFile); |
143 |
| - int len; |
144 |
| - while ((len = zis.read(buffer)) > 0) { |
145 |
| - fos.write(buffer, 0, len); |
146 |
| - } |
147 |
| - fos.close(); |
148 |
| - } |
149 |
| - zipEntry = zis.getNextEntry(); |
150 |
| - } |
151 |
| - zis.closeEntry(); |
152 |
| - zis.close(); |
153 |
| - } catch (FileNotFoundException e) { |
154 |
| - throw new RuntimeException(e); |
155 |
| - } catch (IOException e) { |
156 |
| - throw new RuntimeException(e); |
157 |
| - } |
158 |
| - } |
159 |
| - |
160 |
| - public static File newFile(File destinationDir, ZipEntry zipEntry) throws IOException { |
161 |
| - File destFile = new File(destinationDir, zipEntry.getName()); |
162 |
| - |
163 |
| - String destDirPath = destinationDir.getCanonicalPath(); |
164 |
| - String destFilePath = destFile.getCanonicalPath(); |
165 |
| - |
166 |
| - if (!destFilePath.startsWith(destDirPath + File.separator)) { |
167 |
| - throw new IOException("Entry is outside of the target dir: " + zipEntry.getName()); |
168 |
| - } |
169 |
| - |
170 |
| - return destFile; |
| 91 | + installMavenForTestIfNotExists(tempDir); |
171 | 92 | }
|
172 | 93 |
|
173 | 94 | @AfterAll
|
@@ -222,6 +143,7 @@ void mavenSettingsShouldBeRead() throws IOException, MavenInvocationException, I
|
222 | 143 |
|
223 | 144 | // @Test
|
224 | 145 | // @Order(2)
|
| 146 | + |
225 | 147 | @DisplayName("verify dependencies from private repo were resolved")
|
226 | 148 | void verifyDependenciesFromPrivateRepoWereResolved() {
|
227 | 149 | // verify dependency does not exist in local Maven repo
|
@@ -255,6 +177,80 @@ void verifyDependenciesFromPrivateRepoWereResolved() {
|
255 | 177 | assertThat(type.getFullyQualifiedName()).isEqualTo(DEPENDENCY_CLASS_FQNAME);
|
256 | 178 | }
|
257 | 179 |
|
| 180 | + private static void installMavenForTestIfNotExists(Path tempDir) { |
| 181 | + if (!Path.of("./testcode/reposilite-test/user.home/apache-maven-3.9.5/bin/mvn").toFile().exists()) { |
| 182 | + String mavenDownloadUrl = "https://dlcdn.apache.org/maven/maven-3/3.9.5/binaries/apache-maven-3.9.5-bin.zip"; |
| 183 | + try { |
| 184 | + Path mavenInstallDir = Path.of(TESTCODE_DIR + "/user.home"); |
| 185 | + File downloadedMavenZipFile = tempDir.resolve("apache-maven-3.9.5-bin.zip").toFile(); |
| 186 | + FileUtils.copyURLToFile( |
| 187 | + new URL(mavenDownloadUrl), |
| 188 | + downloadedMavenZipFile, |
| 189 | + 10000, |
| 190 | + 30000); |
| 191 | + unzip(downloadedMavenZipFile, mavenInstallDir); |
| 192 | + File file = mavenInstallDir.resolve("apache-maven-3.9.5/bin/mvn").toFile(); |
| 193 | + file.setExecutable(true, false); |
| 194 | + assertThat(file.canExecute()).isTrue(); |
| 195 | + } catch (IOException e) { |
| 196 | + throw new RuntimeException(e); |
| 197 | + } |
| 198 | + } |
| 199 | + } |
| 200 | + |
| 201 | + private static void unzip(File downloadedMavenZipFile, Path mavenInstallDir) { |
| 202 | + try { |
| 203 | + byte[] buffer = new byte[1024]; |
| 204 | + ZipInputStream zis = null; |
| 205 | + |
| 206 | + zis = new ZipInputStream(new FileInputStream(downloadedMavenZipFile)); |
| 207 | + |
| 208 | + ZipEntry zipEntry = zis.getNextEntry(); |
| 209 | + while (zipEntry != null) { |
| 210 | + File newFile = newFile(mavenInstallDir.toFile(), zipEntry); |
| 211 | + if (zipEntry.isDirectory()) { |
| 212 | + if (!newFile.isDirectory() && !newFile.mkdirs()) { |
| 213 | + throw new IOException("Failed to create directory " + newFile); |
| 214 | + } |
| 215 | + } else { |
| 216 | + // fix for Windows-created archives |
| 217 | + File parent = newFile.getParentFile(); |
| 218 | + if (!parent.isDirectory() && !parent.mkdirs()) { |
| 219 | + throw new IOException("Failed to create directory " + parent); |
| 220 | + } |
| 221 | + |
| 222 | + // write file content |
| 223 | + FileOutputStream fos = new FileOutputStream(newFile); |
| 224 | + int len; |
| 225 | + while ((len = zis.read(buffer)) > 0) { |
| 226 | + fos.write(buffer, 0, len); |
| 227 | + } |
| 228 | + fos.close(); |
| 229 | + } |
| 230 | + zipEntry = zis.getNextEntry(); |
| 231 | + } |
| 232 | + zis.closeEntry(); |
| 233 | + zis.close(); |
| 234 | + } catch (FileNotFoundException e) { |
| 235 | + throw new RuntimeException(e); |
| 236 | + } catch (IOException e) { |
| 237 | + throw new RuntimeException(e); |
| 238 | + } |
| 239 | + } |
| 240 | + |
| 241 | + public static File newFile(File destinationDir, ZipEntry zipEntry) throws IOException { |
| 242 | + File destFile = new File(destinationDir, zipEntry.getName()); |
| 243 | + |
| 244 | + String destDirPath = destinationDir.getCanonicalPath(); |
| 245 | + String destFilePath = destFile.getCanonicalPath(); |
| 246 | + |
| 247 | + if (!destFilePath.startsWith(destDirPath + File.separator)) { |
| 248 | + throw new IOException("Entry is outside of the target dir: " + zipEntry.getName()); |
| 249 | + } |
| 250 | + |
| 251 | + return destFile; |
| 252 | + } |
| 253 | + |
258 | 254 |
|
259 | 255 | private Path renderSettingsXml(String testcodeDir, Path settingsXmlTmplPath) throws IOException {
|
260 | 256 | String settingsXmlContent = Files.readString(settingsXmlTmplPath);
|
|
0 commit comments