|
38 | 38 | import java.nio.file.Path;
|
39 | 39 | import java.nio.file.StandardOpenOption;
|
40 | 40 | import java.util.Comparator;
|
| 41 | +import java.util.HashMap; |
41 | 42 | import java.util.List;
|
42 | 43 | import java.util.Map;
|
43 | 44 | import java.util.stream.Collectors;
|
@@ -88,6 +89,17 @@ private void testCommonConfiguration(String profile) throws Exception {
|
88 | 89 | assertEquals("joda", configOptions.get("dateLibrary"));
|
89 | 90 | }
|
90 | 91 |
|
| 92 | + public void testMinimalUpdateConfiguration() throws Exception { |
| 93 | + // GIVEN |
| 94 | + CodeGenMojo mojo = loadMojo(newTempFolder(), "src/test/resources/minimal-update", null); |
| 95 | + |
| 96 | + // WHEN |
| 97 | + mojo.execute(); |
| 98 | + |
| 99 | + // THEN |
| 100 | + assertEquals(Boolean.TRUE, getVariableValueFromObject(mojo, "minimalUpdate")); |
| 101 | + } |
| 102 | + |
91 | 103 | public void testHashGenerationFileContainsExecutionId() throws Exception {
|
92 | 104 | // GIVEN
|
93 | 105 | final Path tempDir = newTempFolder();
|
@@ -136,6 +148,50 @@ public void testSkipRegenerationForClasspathSpecFileNoChange() throws Exception
|
136 | 148 | assertFalse("src directory should not have been regenerated", Files.exists(generatedDir.resolve("src")));
|
137 | 149 | }
|
138 | 150 |
|
| 151 | + public void testMinimalUpdate() throws Exception { |
| 152 | + //GIVEN |
| 153 | + /* Set up the mojo */ |
| 154 | + final Path tempDir = newTempFolder(); |
| 155 | + final CodeGenMojo mojo = loadMojo(tempDir, "src/test/resources/minimal-update", null, "executionId"); |
| 156 | + |
| 157 | + /* Perform an initial generation */ |
| 158 | + mojo.execute(); |
| 159 | + |
| 160 | + /* Collect last modified times of generated files */ |
| 161 | + final Path generatedDir = tempDir.resolve("target/generated-sources/minimal-update"); |
| 162 | + assertTrue("Generated directory should exist", Files.exists(generatedDir)); |
| 163 | + |
| 164 | + Map<Path, Long> lastModifiedTimes = new HashMap<>(); |
| 165 | + try (Stream<Path> files = Files.walk(generatedDir)) { |
| 166 | + files |
| 167 | + .filter(Files::isRegularFile) |
| 168 | + .filter(path -> !path.getFileName().toString().endsWith(".sha256")) |
| 169 | + .filter(path -> !path.getFileName().toString().equals("FILES")) |
| 170 | + .forEach(file -> { |
| 171 | + try { |
| 172 | + lastModifiedTimes.put(file, Files.getLastModifiedTime(file).toMillis()); |
| 173 | + } catch (IOException e) { |
| 174 | + throw new RuntimeException(e); |
| 175 | + } |
| 176 | + }); |
| 177 | + } |
| 178 | + assertTrue("Should have recorded last modified times for more than 3 files", lastModifiedTimes.size() > 3); |
| 179 | + |
| 180 | + // WHEN |
| 181 | + /* Execute the mojo again */ |
| 182 | + mojo.execute(); |
| 183 | + |
| 184 | + // THEN |
| 185 | + /* Verify that file modification times haven't changed (files weren't touched) */ |
| 186 | + for (Map.Entry<Path, Long> entry : lastModifiedTimes.entrySet()) { |
| 187 | + Path file = entry.getKey(); |
| 188 | + Long originalTime = entry.getValue(); |
| 189 | + Long currentTime = Files.getLastModifiedTime(file).toMillis(); |
| 190 | + assertEquals("File " + file + " should not have been modified (minimal update should skip unchanged files)", |
| 191 | + originalTime, currentTime); |
| 192 | + } |
| 193 | + } |
| 194 | + |
139 | 195 | /**
|
140 | 196 | * For a Pom file which refers to an input file which will be on the classpath, as opposed to a file path,
|
141 | 197 | * test that the generated source is regenerated when the hash has changed.
|
@@ -242,7 +298,7 @@ public void test_skipIfSpecIsUnchanged_recognizesUpdatesInExternalReferencedFile
|
242 | 298 | final Path generatedDir = tempDir.resolve("target/generated-sources/issue-16489");
|
243 | 299 | final Path hashFile = generatedDir.resolve(".openapi-generator/petstore.yaml-default.sha256");
|
244 | 300 | final CodeGenMojo mojo = loadMojo(tempDir, "src/test/resources/issue-16489", null);
|
245 |
| - mojo.execute(); // Perform an initial generation |
| 301 | + mojo.execute(); // Perform an initial generation |
246 | 302 | var currentHash = Files.readString(hashFile); // read hash
|
247 | 303 | FileUtils.deleteDirectory(generatedDir.resolve("src").toFile()); // Remove the generated source
|
248 | 304 | Files.writeString( // change schema definition in external file
|
|
0 commit comments