Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<extensions>
<extension>
<groupId>me.qoomon</groupId>
<artifactId>maven-git-versioning-extension</artifactId>
<version>9.11.0</version>
</extension>
</extensions>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>git-versioning-test</artifactId>
<version>1.0.0-SNAPSHOT</version>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.IOException;
import java.util.Collection;

Expand All @@ -30,11 +31,11 @@
import org.junit.Assert;
import org.junit.Test;

public class ExtensionsTest extends AbstractMavenProjectTestCase {

Check warning on line 34 in org.eclipse.m2e.core.tests/src/org/eclipse/m2e/core/ExtensionsTest.java

View check run for this annotation

Jenkins - M2E / Compiler

Restriction

NORMAL: Discouraged access: The type 'AbstractMavenProjectTestCase' is not API (restriction on classpath entry '/home/jenkins/agent/workspace/m2e_PR-2139/org.eclipse.m2e.tests.common/target/classes')
@Test
public void testProjectExtensions() throws Exception {
IProject project = createExisting("projectExtension", "resources/projects/projectExtension/", false);
waitForJobsToComplete(monitor);

Check warning on line 38 in org.eclipse.m2e.core.tests/src/org/eclipse/m2e/core/ExtensionsTest.java

View check run for this annotation

Jenkins - M2E / Compiler

Restriction

NORMAL: Discouraged access: The field 'AbstractMavenProjectTestCase.monitor' is not API (restriction on classpath entry '/home/jenkins/agent/workspace/m2e_PR-2139/org.eclipse.m2e.tests.common/target/classes')
IMavenProjectFacade facade = Adapters.adapt(project, IMavenProjectFacade.class);
Assert.assertNotNull(facade);
IComponentLookup projectLookup = facade.getComponentLookup();
Expand All @@ -45,7 +46,7 @@
.execute((context, monitor) -> {
assertNotNull("context has no project!", context.getSession().getCurrentProject());
return context.getComponentLookup().lookupCollection(AbstractMavenLifecycleParticipant.class);
}, monitor);

Check warning on line 49 in org.eclipse.m2e.core.tests/src/org/eclipse/m2e/core/ExtensionsTest.java

View check run for this annotation

Jenkins - M2E / Compiler

Restriction

NORMAL: Discouraged access: The field 'AbstractMavenProjectTestCase.monitor' is not API (restriction on classpath entry '/home/jenkins/agent/workspace/m2e_PR-2139/org.eclipse.m2e.tests.common/target/classes')
assertTrue("the must be at laest one build participant!", buildParticipants.size() > 0);
Collection<AbstractMavenLifecycleParticipant> participantListAfterCall = projectLookup
.lookupCollection(AbstractMavenLifecycleParticipant.class);
Expand All @@ -55,7 +56,7 @@
@Test
public void testCoreExtension() throws Exception {
IProject project = importPomlessProject("pomless", "bundle/pom.xml");
waitForJobsToComplete(monitor);

Check warning on line 59 in org.eclipse.m2e.core.tests/src/org/eclipse/m2e/core/ExtensionsTest.java

View check run for this annotation

Jenkins - M2E / Compiler

Restriction

NORMAL: Discouraged access: The field 'AbstractMavenProjectTestCase.monitor' is not API (restriction on classpath entry '/home/jenkins/agent/workspace/m2e_PR-2139/org.eclipse.m2e.tests.common/target/classes')
assertEquals("my.bundle", project.getName());
assertNotNull(project.getNature("org.eclipse.m2e.core.maven2Nature"));
}
Expand All @@ -63,11 +64,11 @@
@Test
public void testLoadSameExtensionFromMultipleLocations() throws Exception {
IProject project1 = importPomlessProject("pomless", "bundle/pom.xml");
waitForJobsToComplete(monitor);

Check warning on line 67 in org.eclipse.m2e.core.tests/src/org/eclipse/m2e/core/ExtensionsTest.java

View check run for this annotation

Jenkins - M2E / Compiler

Restriction

NORMAL: Discouraged access: The field 'AbstractMavenProjectTestCase.monitor' is not API (restriction on classpath entry '/home/jenkins/agent/workspace/m2e_PR-2139/org.eclipse.m2e.tests.common/target/classes')
assertEquals("my.bundle", project1.getName());

IProject project2 = importPomlessProject("pomless2", "bundle2/pom.xml");
waitForJobsToComplete(monitor);

Check warning on line 71 in org.eclipse.m2e.core.tests/src/org/eclipse/m2e/core/ExtensionsTest.java

View check run for this annotation

Jenkins - M2E / Compiler

Restriction

NORMAL: Discouraged access: The field 'AbstractMavenProjectTestCase.monitor' is not API (restriction on classpath entry '/home/jenkins/agent/workspace/m2e_PR-2139/org.eclipse.m2e.tests.common/target/classes')
assertEquals("my.bundle2", project2.getName());
}

Expand All @@ -75,13 +76,13 @@
public void testReloadExtensionAfterDeletion() throws Exception {
IProject project = importPomlessProject("pomless", "bundle/pom.xml");

waitForJobsToComplete(monitor);

Check warning on line 79 in org.eclipse.m2e.core.tests/src/org/eclipse/m2e/core/ExtensionsTest.java

View check run for this annotation

Jenkins - M2E / Compiler

Restriction

NORMAL: Discouraged access: The field 'AbstractMavenProjectTestCase.monitor' is not API (restriction on classpath entry '/home/jenkins/agent/workspace/m2e_PR-2139/org.eclipse.m2e.tests.common/target/classes')
assertEquals("my.bundle", project.getName());

WorkspaceHelpers.cleanWorkspace();

Check warning on line 82 in org.eclipse.m2e.core.tests/src/org/eclipse/m2e/core/ExtensionsTest.java

View check run for this annotation

Jenkins - M2E / Compiler

Restriction

NORMAL: Discouraged access: The type 'WorkspaceHelpers' is not API (restriction on classpath entry '/home/jenkins/agent/workspace/m2e_PR-2139/org.eclipse.m2e.tests.common/target/classes')

Check warning on line 82 in org.eclipse.m2e.core.tests/src/org/eclipse/m2e/core/ExtensionsTest.java

View check run for this annotation

Jenkins - M2E / Compiler

Restriction

NORMAL: Discouraged access: The method 'WorkspaceHelpers.cleanWorkspace()' is not API (restriction on classpath entry '/home/jenkins/agent/workspace/m2e_PR-2139/org.eclipse.m2e.tests.common/target/classes')

project = importPomlessProject("pomless", "bundle/pom.xml");
waitForJobsToComplete(monitor);

Check warning on line 85 in org.eclipse.m2e.core.tests/src/org/eclipse/m2e/core/ExtensionsTest.java

View check run for this annotation

Jenkins - M2E / Compiler

Restriction

NORMAL: Discouraged access: The field 'AbstractMavenProjectTestCase.monitor' is not API (restriction on classpath entry '/home/jenkins/agent/workspace/m2e_PR-2139/org.eclipse.m2e.tests.common/target/classes')
assertEquals("my.bundle", project.getName());
}

Expand All @@ -97,13 +98,31 @@
@Test
public void testCopyResourcesWithMVNFolder() throws Exception {
IProject project = importProject("resources/projects/resourcesWithMVNFolder/pom.xml");
project.build(IncrementalProjectBuilder.FULL_BUILD, monitor);

Check warning on line 101 in org.eclipse.m2e.core.tests/src/org/eclipse/m2e/core/ExtensionsTest.java

View check run for this annotation

Jenkins - M2E / Compiler

Restriction

NORMAL: Discouraged access: The field 'AbstractMavenProjectTestCase.monitor' is not API (restriction on classpath entry '/home/jenkins/agent/workspace/m2e_PR-2139/org.eclipse.m2e.tests.common/target/classes')
WorkspaceHelpers.assertNoErrors(project);

Check warning on line 102 in org.eclipse.m2e.core.tests/src/org/eclipse/m2e/core/ExtensionsTest.java

View check run for this annotation

Jenkins - M2E / Compiler

Restriction

NORMAL: Discouraged access: The type 'WorkspaceHelpers' is not API (restriction on classpath entry '/home/jenkins/agent/workspace/m2e_PR-2139/org.eclipse.m2e.tests.common/target/classes')

Check warning on line 102 in org.eclipse.m2e.core.tests/src/org/eclipse/m2e/core/ExtensionsTest.java

View check run for this annotation

Jenkins - M2E / Compiler

Restriction

NORMAL: Discouraged access: The method 'WorkspaceHelpers.assertNoErrors(IProject)' is not API (restriction on classpath entry '/home/jenkins/agent/workspace/m2e_PR-2139/org.eclipse.m2e.tests.common/target/classes')
IFile file = project.getFile("target/classes/file.txt");
assertTrue(file.exists());
assertEquals("foo-bar-content", new String(file.getContents().readAllBytes()));
}

@Test
public void testGitVersioningExtension() throws Exception {
// Pre-initialize git repo in workspace (required by the extension to activate)
File projectDir = new File(workspace.getRoot().getLocation().toFile(), "gitVersioningExtension");

Check warning on line 111 in org.eclipse.m2e.core.tests/src/org/eclipse/m2e/core/ExtensionsTest.java

View check run for this annotation

Jenkins - M2E / Compiler

Restriction

NORMAL: Discouraged access: The field 'AbstractMavenProjectTestCase.workspace' is not API (restriction on classpath entry '/home/jenkins/agent/workspace/m2e_PR-2139/org.eclipse.m2e.tests.common/target/classes')
copyDir(new File("resources/projects/gitVersioningExtension"), projectDir);
assertEquals(0, new ProcessBuilder("git", "init").directory(projectDir).start().waitFor());
assertEquals(0, new ProcessBuilder("git", "add", ".").directory(projectDir).start().waitFor());
assertEquals(0,
new ProcessBuilder("git", "-c", "user.email=test@test.com", "-c", "user.name=Test", "commit", "-m",
"init").directory(projectDir).start().waitFor());
// Import project - the extension modifies the model, stripping InputLocation metadata
IProject project = importProject("resources/projects/gitVersioningExtension/pom.xml");
waitForJobsToComplete(monitor);

Check warning on line 120 in org.eclipse.m2e.core.tests/src/org/eclipse/m2e/core/ExtensionsTest.java

View check run for this annotation

Jenkins - M2E / Compiler

Restriction

NORMAL: Discouraged access: The field 'AbstractMavenProjectTestCase.monitor' is not API (restriction on classpath entry '/home/jenkins/agent/workspace/m2e_PR-2139/org.eclipse.m2e.tests.common/target/classes')
// Without the fix, Model.getLocation("") returns null causing NPE in
// AnnotationMappingMetadataSource and SourceLocationHelper
assertNoErrors(project);
}

private IProject importPomlessProject(String rootProject, String... poms) throws IOException, CoreException {
IProject[] projects = importProjects("resources/projects/" + rootProject + "/", poms,
new ResolverConfiguration(), false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ public static AnnotationMappingMetadataSource get(MavenProject project) {
private AnnotationMappingMetadataSource(MavenProject project, List<PI> pis) {
this.project = project;
this.pis = pis;
projectId = project.getModel().getLocation(SELF).getSource().getModelId();
InputLocation selfLocation = project.getModel().getLocation(SELF);
if(selfLocation != null && selfLocation.getSource() != null) {
projectId = selfLocation.getSource().getModelId();
} else {
projectId = project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion();
}
}

@Override
Expand Down Expand Up @@ -171,7 +176,14 @@ private PluginExecutionMetadata createMetadata(Xpp3Dom action) {
}

private static List<PI> parsePIs(MavenProject project) {
InputSource source = project.getModel().getLocation(SELF).getSource();
InputLocation selfLocation = project.getModel().getLocation(SELF);
if(selfLocation == null) {
return List.of();
}
InputSource source = selfLocation.getSource();
if(source == null) {
return List.of();
}
File pom = project.getFile();
if((pom == null || !pom.isFile()) && source.getLocation() != null) {
pom = new File(source.getLocation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,16 @@
}

File pomFile = mavenProject.getFile();
if(pomFile.getAbsolutePath().equals(inputLocation.getSource().getLocation())) {
if(inputLocation.getSource() != null && pomFile.getAbsolutePath().equals(inputLocation.getSource().getLocation())) {
// Plugin/execution is specified in current pom
return getSourceLocation(inputLocation, elementName);
}

// Plugin/execution is specified in some parent pom
SourceLocation causeLocation = getSourceLocation(inputLocation, elementName);
if(mavenProject.getModel().getParent() == null) {
return new SourceLocation(1, 1, 1, causeLocation);
}
inputLocation = mavenProject.getModel().getParent().getLocation(SELF);
if(inputLocation == null) {
// parent location cannot be determined for participant-added parents
Expand Down Expand Up @@ -156,10 +159,12 @@
if(found != null) {

// missing transitive managed dependency
String projectId = mavenProject.getModel().getLocation(SELF).getSource().getModelId();
String depId = found.getLocation(SELF).getSource().getModelId();
InputLocation projectSelfLoc = mavenProject.getModel().getLocation(SELF);
InputLocation depSelfLoc = found.getLocation(SELF);
String projectId = projectSelfLoc != null && projectSelfLoc.getSource() != null ? projectSelfLoc.getSource().getModelId() : null;
String depId = depSelfLoc != null && depSelfLoc.getSource() != null ? depSelfLoc.getSource().getModelId() : null;

if(!projectId.equals(depId)) {

Check warning on line 167 in org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/markers/SourceLocationHelper.java

View check run for this annotation

Jenkins - M2E / Compiler

Potential Programming Problem

NORMAL: Potential null pointer access: The variable projectId may be null at this location
// let's see if it comes from a directly imported pom
DependencyManagement origMgmt = mavenProject.getOriginalModel().getDependencyManagement();
org.apache.maven.model.Dependency importDep = findDependencyImport(origMgmt, depId);
Expand Down Expand Up @@ -224,32 +229,44 @@
if(inputLocation == null) {
// Should never happen
inputLocation = mavenProject.getModel().getLocation(SELF);
if(inputLocation == null) {
return new SourceLocation(1, 1, 1);
}
return new SourceLocation(inputLocation.getLineNumber(), 1, inputLocation.getColumnNumber() - COLUMN_END_OFFSET);
}

File pomFile = mavenProject.getFile();
if(pomFile.getAbsolutePath().equals(inputLocation.getSource().getLocation())) {
if(inputLocation.getSource() != null && pomFile.getAbsolutePath().equals(inputLocation.getSource().getLocation())) {
// Dependency is specified in current pom
return getSourceLocation(inputLocation, DEPENDENCY);
}

// Plugin/execution is specified in some parent pom
// Dependency is specified in some parent pom
SourceLocation causeLocation = getSourceLocation(inputLocation, DEPENDENCY);
if(mavenProject.getModel().getParent() == null) {
return new SourceLocation(1, 1, 1, causeLocation);
}
inputLocation = mavenProject.getModel().getParent().getLocation(SELF);
return getSourceLocation(inputLocation, PARENT, causeLocation);
}

private static SourceLocation getSourceLocation(InputLocation inputLocation, String elementName) {
if(inputLocation == null) {
return new SourceLocation(1, 1, 1);
}
InputSource source = inputLocation.getSource();
return new SourceLocation( //
source != null ? source.getLocation() : null, source != null ? source.getModelId() : null,
inputLocation.getLineNumber(), //
inputLocation.getLineNumber(), //
inputLocation.getColumnNumber() - elementName.length() - COLUMN_START_OFFSET,
inputLocation.getColumnNumber() - COLUMN_END_OFFSET);
}

private static SourceLocation getSourceLocation(InputLocation inputLocation, String elementName,
SourceLocation causeLocation) {
if(inputLocation == null) {
return new SourceLocation(1, 1, 1, causeLocation);
}
return new SourceLocation(inputLocation.getLineNumber(),
inputLocation.getColumnNumber() - elementName.length() - COLUMN_START_OFFSET,
inputLocation.getColumnNumber() - COLUMN_END_OFFSET, causeLocation);
Expand Down
Loading