Skip to content

Commit 38adad1

Browse files
committedMar 23, 2023
Adapt MavenConsoleLineTracker to changed project description printout
1 parent d73697c commit 38adad1

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed
 

‎org.eclipse.m2e.core.ui.tests/resources/projects/simple.projectWithJUnit-5_Test/pom.xml

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
<plugin>
2525
<artifactId>maven-surefire-plugin</artifactId>
2626
<version>3.0.0</version>
27+
<configuration>
28+
<trimStackTrace>true</trimStackTrace>
29+
<forkNode implementation="org.apache.maven.plugin.surefire.extensions.SurefireForkNodeFactory"/>
30+
</configuration>
2731
</plugin>
2832
</plugins>
2933
</pluginManagement>

‎org.eclipse.m2e.launching/META-INF/MANIFEST.MF

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %Bundle-Name
44
Bundle-SymbolicName: org.eclipse.m2e.launching;singleton:=true
5-
Bundle-Version: 2.0.400.qualifier
5+
Bundle-Version: 2.0.500.qualifier
66
Bundle-Localization: plugin
77
Require-Bundle: org.eclipse.core.runtime,
88
org.eclipse.core.variables,

‎org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenConsoleLineTracker.java

+29-23
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package org.eclipse.m2e.internal.launch;
1616

1717
import java.io.IOException;
18+
import java.net.URI;
1819
import java.nio.file.Files;
1920
import java.nio.file.Path;
2021
import java.util.ArrayDeque;
@@ -109,7 +110,7 @@ private static record ProjectReference(IProject project, MavenProjectBuildData b
109110

110111
private ProjectReference mavenProject;
111112

112-
private final Deque<IRegion> projectDefinitionLines = new ArrayDeque<>(2);
113+
private final Deque<IRegion> projectDefinitionLines = new ArrayDeque<>(3);
113114

114115
private final List<int[]> removedLineLocations = new ArrayList<>();
115116

@@ -190,42 +191,47 @@ private boolean isMavenProcess(ILaunchConfiguration launchConfiguration) {
190191

191192
private static final int VERSION = 1;
192193

194+
private static final Pattern FROM_FILE_LINE = Pattern.compile("^\\[INFO\\] +from ");
195+
193196
private static final Pattern PACKAGING_TYPE_LINE = Pattern.compile("^\\[INFO\\] -+\\[ [\\w\\-\\. ]+ \\]-+$");
194197

195198
private String getText(IRegion lineRegion) throws BadLocationException {
196199
removedLineLocations.clear();
197200
String line0 = getLineText(lineRegion, removedLineLocations);
198201

199-
if(projectDefinitionLines.size() < 2) {
202+
if(projectDefinitionLines.size() < 3) {
200203
projectDefinitionLines.add(lineRegion);
201204
return line0;
202205
}
203206
// Read groupId, artifactId and version from a sequence like the following lines:
204207
// [INFO] -----------< org.eclipse.m2e:org.eclipse.m2e.maven.runtime >------------
205208
// [INFO] Building M2E Embedded Maven Runtime (includes Incubating components) 1.18.2-SNAPSHOT [4/5]
209+
// [INFO] from pom.xml
206210
// [INFO] ---------------------------[ eclipse-plugin ]---------------------------
207211

208212
if(PACKAGING_TYPE_LINE.matcher(line0).matches()) {
209213
Iterator<IRegion> previousLines = projectDefinitionLines.descendingIterator();
210214

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+
}
229235
}
230236
}
231237
}
@@ -265,9 +271,9 @@ private ProjectReference getProject(String groupId, String artifactId, String ve
265271
if(buildProject == null) {
266272
return null;
267273
}
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))
271277
.filter(IProject.class::isInstance).map(IProject.class::cast).findFirst();
272278
//if project is absent, the project build in Maven is not in the workspace
273279
return project.isPresent() ? new ProjectReference(project.get(), buildProject) : null;

0 commit comments

Comments
 (0)