Skip to content

Commit

Permalink
Update all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed Feb 6, 2024
1 parent 68abf98 commit 4622500
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,26 @@
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectHelper;
import org.apache.maven.project.artifact.ProjectArtifact;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.artifact.ArtifactProperties;
import org.eclipse.aether.artifact.ArtifactType;
import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.artifact.DefaultArtifactType;
import org.eclipse.aether.util.artifact.ArtifactIdUtils;
import org.eclipse.aether.collection.CollectRequest;
import org.eclipse.aether.graph.DefaultDependencyNode;
import org.eclipse.aether.graph.DependencyFilter;
import org.eclipse.aether.resolution.ArtifactResult;
import org.eclipse.aether.resolution.DependencyRequest;
import org.eclipse.aether.resolution.DependencyResolutionException;
import org.eclipse.aether.resolution.DependencyResult;
import org.eclipse.aether.util.filter.ScopeDependencyFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -96,13 +97,12 @@ protected ProvisioArtifact projectArtifact() {
// is no real protocol for knowing what something like, say, the JAR plugin did to drop off a file somewhere. We
// need to improve this but for now we'll look.
// ===
// This above is not quite true: check below reuses main artifact if it was built (backing file exists) unrelated
// where it was created, but have been attached.
// While this above is still true, this check below is better, in a sense it allows JAR plugin to drop off file
// anywhere.
//
Artifact pomArtifact = RepositoryUtils.toArtifact(new ProjectArtifact(project));
Artifact projectArtifact = RepositoryUtils.toArtifact(project.getArtifact());
if (!ArtifactIdUtils.equalsId(pomArtifact, projectArtifact)
&& projectArtifact.getFile() != null
if (projectArtifact.getFile() != null
&& projectArtifact.getFile().getName().endsWith(".jar")
&& projectArtifact.getFile().exists()) {
jarArtifact = new ProvisioArtifact(project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion());
jarArtifact.setFile(projectArtifact.getFile());
Expand All @@ -122,14 +122,44 @@ protected ArtifactSet getRuntimeClasspathAsArtifactSet() {
// for this Mojo. I think this will be sufficient for anything related to creating a runtime.
//
ArtifactSet artifactSet = new ArtifactSet();
for (org.apache.maven.artifact.Artifact mavenArtifact : project.getArtifacts()) {
if (!mavenArtifact.getScope().equals("system") && !mavenArtifact.getScope().equals("provided")) {
artifactSet.addArtifact(new ProvisioArtifact(toArtifact(mavenArtifact)));
}
for (Artifact mavenArtifact : resolveRuntimeScopeTransitively()) {
artifactSet.addArtifact(new ProvisioArtifact(mavenArtifact));
}
return artifactSet;
}


/**
* This method is in use instead of project offering mojo asked resolution scope due presence of:
* <a href="https://issues.apache.org/jira/browse/MNG-8041">MNG-8041</a>
*/
private List<Artifact> resolveRuntimeScopeTransitively() {
DependencyFilter scoopeDependencyFilter = new ScopeDependencyFilter("provided", "test");
List<org.eclipse.aether.graph.Dependency> dependencies = project.getDependencies().stream()
.map(d -> RepositoryUtils.toDependency(d, repositorySystemSession.getArtifactTypeRegistry()))
.filter(d -> scoopeDependencyFilter.accept(new DefaultDependencyNode(d), Collections.emptyList()))
.collect(Collectors.toList());
List<org.eclipse.aether.graph.Dependency> managedDependencies = Collections.emptyList();
if (project.getDependencyManagement() != null) {
managedDependencies = project.getDependencyManagement().getDependencies().stream()
.map(d -> RepositoryUtils.toDependency(d, repositorySystemSession.getArtifactTypeRegistry()))
.collect(Collectors.toList());
}

CollectRequest collectRequest = new CollectRequest();
collectRequest.setManagedDependencies(managedDependencies);
collectRequest.setRepositories(project.getRemoteProjectRepositories());
collectRequest.setDependencies(dependencies);
collectRequest.setRootArtifact(RepositoryUtils.toArtifact(project.getArtifact()));
DependencyRequest request = new DependencyRequest(collectRequest, scoopeDependencyFilter);
try {
DependencyResult dependencyResult = repositorySystem.resolveDependencies(repositorySystemSession, request);
return dependencyResult.getArtifactResults().stream().map(ArtifactResult::getArtifact).collect(Collectors.toList());
} catch (DependencyResolutionException e) {
throw new RuntimeException(e);
}
}

private static Artifact toArtifact(org.apache.maven.artifact.Artifact artifact) {
if (artifact == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import static org.junit.Assert.assertArrayEquals;

@RunWith(MavenJUnitTestRunner.class)
@MavenVersions({"3.6.3", "3.8.4"})
@MavenVersions({"3.6.3", "3.8.8", "3.9.6"})
@SuppressWarnings({"JUnitTestNG", "PublicField"})
public class GeneratorIntegrationTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import static org.junit.Assert.assertTrue;

@RunWith(MavenJUnitTestRunner.class)
@MavenVersions({"3.6.3", "3.8.4", "3.9.6"})
@MavenVersions({"3.6.3", "3.8.8", "3.9.6"})
@SuppressWarnings({"JUnitTestNG", "PublicField"})
public class ProvisioningIntegrationTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.io.File;

@RunWith(MavenJUnitTestRunner.class)
@MavenVersions({"3.6.3", "3.8.4"})
@MavenVersions({"3.6.3", "3.8.8", "3.9.6"})
@SuppressWarnings({"JUnitTestNG", "PublicField"})
public class ValidatorIntegrationTest
{
Expand Down

0 comments on commit 4622500

Please sign in to comment.