|
15 | 15 | package org.eclipse.m2e.internal.launch; |
16 | 16 |
|
17 | 17 | import java.io.IOException; |
| 18 | +import java.net.URI; |
18 | 19 | import java.nio.file.Files; |
19 | 20 | import java.nio.file.Path; |
20 | 21 | import java.util.ArrayDeque; |
@@ -109,7 +110,7 @@ private static record ProjectReference(IProject project, MavenProjectBuildData b |
109 | 110 |
|
110 | 111 | private ProjectReference mavenProject; |
111 | 112 |
|
112 | | - private final Deque<IRegion> projectDefinitionLines = new ArrayDeque<>(2); |
| 113 | + private final Deque<IRegion> projectDefinitionLines = new ArrayDeque<>(3); |
113 | 114 |
|
114 | 115 | private final List<int[]> removedLineLocations = new ArrayList<>(); |
115 | 116 |
|
@@ -190,42 +191,47 @@ private boolean isMavenProcess(ILaunchConfiguration launchConfiguration) { |
190 | 191 |
|
191 | 192 | private static final int VERSION = 1; |
192 | 193 |
|
| 194 | + private static final Pattern FROM_FILE_LINE = Pattern.compile("^\\[INFO\\] +from "); |
| 195 | + |
193 | 196 | private static final Pattern PACKAGING_TYPE_LINE = Pattern.compile("^\\[INFO\\] -+\\[ [\\w\\-\\. ]+ \\]-+$"); |
194 | 197 |
|
195 | 198 | private String getText(IRegion lineRegion) throws BadLocationException { |
196 | 199 | removedLineLocations.clear(); |
197 | 200 | String line0 = getLineText(lineRegion, removedLineLocations); |
198 | 201 |
|
199 | | - if(projectDefinitionLines.size() < 2) { |
| 202 | + if(projectDefinitionLines.size() < 3) { |
200 | 203 | projectDefinitionLines.add(lineRegion); |
201 | 204 | return line0; |
202 | 205 | } |
203 | 206 | // Read groupId, artifactId and version from a sequence like the following lines: |
204 | 207 | // [INFO] -----------< org.eclipse.m2e:org.eclipse.m2e.maven.runtime >------------ |
205 | 208 | // [INFO] Building M2E Embedded Maven Runtime (includes Incubating components) 1.18.2-SNAPSHOT [4/5] |
| 209 | + // [INFO] from pom.xml |
206 | 210 | // [INFO] ---------------------------[ eclipse-plugin ]--------------------------- |
207 | 211 |
|
208 | 212 | if(PACKAGING_TYPE_LINE.matcher(line0).matches()) { |
209 | 213 | Iterator<IRegion> previousLines = projectDefinitionLines.descendingIterator(); |
210 | 214 |
|
211 | | - IRegion line1Region = previousLines.next(); |
212 | | - String line1 = getLineText(line1Region, null); |
213 | | - |
214 | | - Matcher vMatcher = VERSION_LINE.matcher(line1); |
215 | | - if(vMatcher.matches()) { |
216 | | - String version = vMatcher.group(VERSION); |
217 | | - |
218 | | - IRegion line2Region = previousLines.next(); |
219 | | - List<int[]> removedLine2Locations = new ArrayList<>(); |
220 | | - String line2 = getLineText(line2Region, removedLine2Locations); |
221 | | - Matcher gaMatcher = GROUP_ARTIFACT_LINE.matcher(line2); |
222 | | - if(gaMatcher.matches()) { |
223 | | - String groupId = gaMatcher.group(GROUP_ID); |
224 | | - String artifactId = gaMatcher.group(ARTIFACT_ID); |
225 | | - |
226 | | - mavenProject = getProject(groupId, artifactId, version); |
227 | | - if(mavenProject != null) { |
228 | | - addProjectLink(line2Region, gaMatcher, GROUP_ID, ARTIFACT_ID, removedLine2Locations); |
| 215 | + String line1 = getLineText(previousLines.next(), null); |
| 216 | + if(FROM_FILE_LINE.matcher(line1).find()) { |
| 217 | + |
| 218 | + String line2 = getLineText(previousLines.next(), null); |
| 219 | + Matcher vMatcher = VERSION_LINE.matcher(line2); |
| 220 | + if(vMatcher.matches()) { |
| 221 | + String version = vMatcher.group(VERSION); |
| 222 | + |
| 223 | + IRegion line3Region = previousLines.next(); |
| 224 | + List<int[]> removedLine3Locations = new ArrayList<>(); |
| 225 | + String line3 = getLineText(line3Region, removedLine3Locations); |
| 226 | + Matcher gaMatcher = GROUP_ARTIFACT_LINE.matcher(line3); |
| 227 | + if(gaMatcher.matches()) { |
| 228 | + String groupId = gaMatcher.group(GROUP_ID); |
| 229 | + String artifactId = gaMatcher.group(ARTIFACT_ID); |
| 230 | + |
| 231 | + mavenProject = getProject(groupId, artifactId, version); |
| 232 | + if(mavenProject != null) { |
| 233 | + addProjectLink(line3Region, gaMatcher, GROUP_ID, ARTIFACT_ID, removedLine3Locations); |
| 234 | + } |
229 | 235 | } |
230 | 236 | } |
231 | 237 | } |
@@ -265,9 +271,9 @@ private ProjectReference getProject(String groupId, String artifactId, String ve |
265 | 271 | if(buildProject == null) { |
266 | 272 | return null; |
267 | 273 | } |
268 | | - Optional<IProject> project = Arrays |
269 | | - .stream( |
270 | | - ResourcesPlugin.getWorkspace().getRoot().findContainersForLocationURI(buildProject.projectBasedir.toUri())) |
| 274 | + IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); |
| 275 | + URI basedirURI = buildProject.projectBasedir.toUri(); |
| 276 | + Optional<IProject> project = Arrays.stream(wsRoot.findContainersForLocationURI(basedirURI)) |
271 | 277 | .filter(IProject.class::isInstance).map(IProject.class::cast).findFirst(); |
272 | 278 | //if project is absent, the project build in Maven is not in the workspace |
273 | 279 | return project.isPresent() ? new ProjectReference(project.get(), buildProject) : null; |
|
0 commit comments