Skip to content

Commit

Permalink
Adapt MavenConsoleLineTracker to changed project description printout
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesWell authored and Eskibear committed Mar 27, 2023
1 parent 0e823bb commit e38f38f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<trimStackTrace>true</trimStackTrace>
<forkNode implementation="org.apache.maven.plugin.surefire.extensions.SurefireForkNodeFactory"/>
</configuration>
</plugin>
</plugins>
</pluginManagement>
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.m2e.launching/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.eclipse.m2e.launching;singleton:=true
Bundle-Version: 2.0.400.qualifier
Bundle-Version: 2.0.500.qualifier
Bundle-Localization: plugin
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.core.variables,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.eclipse.m2e.internal.launch;

import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayDeque;
Expand Down Expand Up @@ -109,7 +110,7 @@ private static record ProjectReference(IProject project, MavenProjectBuildData b

private ProjectReference mavenProject;

private final Deque<IRegion> projectDefinitionLines = new ArrayDeque<>(2);
private final Deque<IRegion> projectDefinitionLines = new ArrayDeque<>(3);

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

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

private static final int VERSION = 1;

private static final Pattern FROM_FILE_LINE = Pattern.compile("^\\[INFO\\] +from ");

private static final Pattern PACKAGING_TYPE_LINE = Pattern.compile("^\\[INFO\\] -+\\[ [\\w\\-\\. ]+ \\]-+$");

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

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

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

IRegion line1Region = previousLines.next();
String line1 = getLineText(line1Region, null);

Matcher vMatcher = VERSION_LINE.matcher(line1);
if(vMatcher.matches()) {
String version = vMatcher.group(VERSION);

IRegion line2Region = previousLines.next();
List<int[]> removedLine2Locations = new ArrayList<>();
String line2 = getLineText(line2Region, removedLine2Locations);
Matcher gaMatcher = GROUP_ARTIFACT_LINE.matcher(line2);
if(gaMatcher.matches()) {
String groupId = gaMatcher.group(GROUP_ID);
String artifactId = gaMatcher.group(ARTIFACT_ID);

mavenProject = getProject(groupId, artifactId, version);
if(mavenProject != null) {
addProjectLink(line2Region, gaMatcher, GROUP_ID, ARTIFACT_ID, removedLine2Locations);
String line1 = getLineText(previousLines.next(), null);
if(FROM_FILE_LINE.matcher(line1).find()) {

String line2 = getLineText(previousLines.next(), null);
Matcher vMatcher = VERSION_LINE.matcher(line2);
if(vMatcher.matches()) {
String version = vMatcher.group(VERSION);

IRegion line3Region = previousLines.next();
List<int[]> removedLine3Locations = new ArrayList<>();
String line3 = getLineText(line3Region, removedLine3Locations);
Matcher gaMatcher = GROUP_ARTIFACT_LINE.matcher(line3);
if(gaMatcher.matches()) {
String groupId = gaMatcher.group(GROUP_ID);
String artifactId = gaMatcher.group(ARTIFACT_ID);

mavenProject = getProject(groupId, artifactId, version);
if(mavenProject != null) {
addProjectLink(line3Region, gaMatcher, GROUP_ID, ARTIFACT_ID, removedLine3Locations);
}
}
}
}
Expand Down Expand Up @@ -265,9 +271,9 @@ private ProjectReference getProject(String groupId, String artifactId, String ve
if(buildProject == null) {
return null;
}
Optional<IProject> project = Arrays
.stream(
ResourcesPlugin.getWorkspace().getRoot().findContainersForLocationURI(buildProject.projectBasedir.toUri()))
IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
URI basedirURI = buildProject.projectBasedir.toUri();
Optional<IProject> project = Arrays.stream(wsRoot.findContainersForLocationURI(basedirURI))
.filter(IProject.class::isInstance).map(IProject.class::cast).findFirst();
//if project is absent, the project build in Maven is not in the workspace
return project.isPresent() ? new ProjectReference(project.get(), buildProject) : null;
Expand Down

0 comments on commit e38f38f

Please sign in to comment.