Skip to content

Commit

Permalink
fix: Explicitly set remote repositories before resolving poms
Browse files Browse the repository at this point in the history
Fixes #22
  • Loading branch information
gastaldi authored Aug 30, 2024
1 parent f2c3ac1 commit 87c5a68
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 4 deletions.
6 changes: 6 additions & 0 deletions pomchecker-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@
<artifactId>slf4j-simple</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.11.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import eu.maveniverse.maven.mima.context.Context;
import eu.maveniverse.maven.mima.context.ContextOverrides;
import eu.maveniverse.maven.mima.context.Runtimes;
import org.apache.maven.artifact.repository.MavenArtifactRepository;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.project.MavenProject;
Expand All @@ -37,12 +39,12 @@
import org.codehaus.plexus.PlexusContainerException;
import org.codehaus.plexus.classworlds.ClassWorld;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.eclipse.aether.repository.RemoteRepository;

import java.io.File;
import java.util.Locale;
import java.util.Properties;

import static java.util.Objects.requireNonNull;
import java.util.stream.Collectors;

/**
* @author Andres Almiray
Expand Down Expand Up @@ -83,7 +85,8 @@ private static MavenProject createMavenProject(File pomFile, Context context, Pl
mavenExecutionRequest.getProjectBuildingRequest();

projectBuildingRequest.setRepositorySession(context.repositorySystemSession());

projectBuildingRequest.setRemoteRepositories(context.remoteRepositories()
.stream().map(PomParser::toArtifactRepository).collect(Collectors.toList()));
// Profile activation needs properties such as JDK version
Properties properties = new Properties(); // allowing duplicate entries
properties.putAll(projectBuildingRequest.getSystemProperties());
Expand Down Expand Up @@ -138,4 +141,12 @@ private static String osDetectedArch() {
return "x86_32";
}
}
}

private static MavenArtifactRepository toArtifactRepository(RemoteRepository remoteRepository) {
MavenArtifactRepository mavenArtifactRepository = new MavenArtifactRepository();
mavenArtifactRepository.setId(remoteRepository.getId());
mavenArtifactRepository.setUrl(remoteRepository.getUrl());
mavenArtifactRepository.setLayout(new DefaultRepositoryLayout());
return mavenArtifactRepository;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2024 Andres Almiray.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.kordamp.maven.checker.cli.internal;

import org.apache.maven.project.MavenProject;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.net.URL;

import static org.junit.jupiter.api.Assertions.assertEquals;

class PomParserTest {

@Test
void parse() throws Exception {
URL resource = getClass().getClassLoader().getResource("test-pom.xml");
MavenProject mavenProject = PomParser.createMavenProject(new File(resource.toURI()));
assertEquals("quarkus-slack-parent",mavenProject.getArtifactId());
}
}
34 changes: 34 additions & 0 deletions pomchecker-cli/src/test/resources/test-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
SPDX-License-Identifier: Apache-2.0
Copyright 2020-2024 Andres Almiray.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<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>

<parent>
<groupId>io.quarkiverse</groupId>
<artifactId>quarkiverse-parent</artifactId>
<version>17</version>
</parent>
<groupId>io.quarkiverse.slack</groupId>
<artifactId>quarkus-slack-parent</artifactId>
<version>0.0.2</version>
<packaging>pom</packaging>
</project>

0 comments on commit 87c5a68

Please sign in to comment.