|
7 | 7 |
|
8 | 8 | import java.io.File; |
9 | 9 | import java.io.IOException; |
| 10 | +import java.util.List; |
10 | 11 | import java.util.Locale; |
| 12 | +import net.sf.json.JSONArray; |
11 | 13 |
|
12 | 14 | import hudson.FilePath; |
13 | 15 | import hudson.model.FreeStyleProject; |
|
16 | 18 |
|
17 | 19 | import io.jenkins.plugins.analysis.core.testutil.IntegrationTestWithJenkinsPerSuite; |
18 | 20 | import io.jenkins.plugins.analysis.warnings.Java; |
| 21 | +import io.jenkins.plugins.prism.SourceCodeDirectory; |
19 | 22 |
|
20 | 23 | import static io.jenkins.plugins.analysis.core.assertions.Assertions.*; |
| 24 | +import static net.javacrumbs.jsonunit.assertj.JsonAssertions.*; |
21 | 25 | import static org.assertj.core.api.Assumptions.*; |
22 | 26 |
|
23 | 27 | /** |
|
27 | 31 | */ |
28 | 32 | class AbsolutePathGeneratorITest extends IntegrationTestWithJenkinsPerSuite { |
29 | 33 | private static final String SOURCE_CODE = "public class Test {}"; |
| 34 | + private static final String FILE_NAME = "Test.java"; |
30 | 35 |
|
31 | 36 | /** Temporary workspace for the agent. */ |
32 | 37 | @TempDir |
33 | 38 | private File agentWorkspace; |
34 | 39 |
|
| 40 | + /** |
| 41 | + * Verifies that the Remote API returns file paths relative to the configured source directory. |
| 42 | + * This test addresses JENKINS-68856 where file paths should be relative to the sourceDirectory |
| 43 | + * when specified, rather than showing the full workspace path. |
| 44 | + */ |
| 45 | + @Test |
| 46 | + @Issue("JENKINS-68856") |
| 47 | + void shouldStripSourcePathPrefixFromFileNamesInRemoteApi() { |
| 48 | + var agent = createAgentWithWrongWorkspaceFolder(); |
| 49 | + var project = createJobForAgent(agent); |
| 50 | + |
| 51 | + createFileInAgentWorkspace(agent, project, "Folder/Test.java", SOURCE_CODE); |
| 52 | + createFileInAgentWorkspace(agent, project, "warnings.txt", |
| 53 | + "[javac] Test.java:1: warning: Test Warning for Jenkins"); |
| 54 | + |
| 55 | + var javaJob = new Java(); |
| 56 | + javaJob.setPattern("warnings.txt"); |
| 57 | + var recorder = enableWarnings(project, javaJob); |
| 58 | + recorder.setSourceDirectories(List.of(new SourceCodeDirectory("Folder"))); |
| 59 | + |
| 60 | + var result = scheduleSuccessfulBuild(project); |
| 61 | + assertThat(result).hasTotalSize(1); |
| 62 | + assertThat(result.getIssues().get(0)).hasFileName(FILE_NAME); |
| 63 | + |
| 64 | + assertThat(result).hasInfoMessages("-> resolved paths in source directory (1 found, 0 not found)"); |
| 65 | + assertThat(result).doesNotHaveInfoMessages("-> 0 copied, 1 not in workspace, 0 not-found, 0 with I/O error"); |
| 66 | + |
| 67 | + var json = callJsonRemoteApi(result.getOwner().getUrl() + "java/all/api/json"); |
| 68 | + var object = json.getJSONObject(); |
| 69 | + |
| 70 | + assertThatJson(object).node("issues").isArray(); |
| 71 | + JSONArray issues = object.getJSONArray("issues"); |
| 72 | + assertThat(issues.size()).as("Should have issues").isGreaterThan(0); |
| 73 | + |
| 74 | + assertThatJson(issues.getJSONObject(0)).node("fileName").isEqualTo(FILE_NAME); |
| 75 | + } |
| 76 | + |
35 | 77 | /** |
36 | 78 | * Verifies that the affected files will be copied even if the file name uses the wrong case (Windows only). |
37 | 79 | */ |
|
0 commit comments