Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Maven 4 extensions #1601

Merged
merged 3 commits into from
Jul 9, 2024
Merged
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
Expand Up @@ -41,6 +41,9 @@ public interface XmlReaderRequest {
@Nullable
Path getPath();

@Nullable
Path getRootDirectory();

@Nullable
URL getURL();

Expand Down Expand Up @@ -83,6 +86,7 @@ static XmlReaderRequestBuilder builder() {
@NotThreadSafe
class XmlReaderRequestBuilder {
Path path;
Path rootDirectory;
URL url;
InputStream inputStream;
Reader reader;
Expand All @@ -97,6 +101,11 @@ public XmlReaderRequestBuilder path(Path path) {
return this;
}

public XmlReaderRequestBuilder rootDirectory(Path rootDirectory) {
this.rootDirectory = rootDirectory;
return this;
}

public XmlReaderRequestBuilder url(URL url) {
this.url = url;
return this;
Expand Down Expand Up @@ -139,11 +148,21 @@ public XmlReaderRequestBuilder addDefaultEntities(boolean addDefaultEntities) {

public XmlReaderRequest build() {
return new DefaultXmlReaderRequest(
path, url, inputStream, reader, transformer, strict, modelId, location, addDefaultEntities);
path,
rootDirectory,
url,
inputStream,
reader,
transformer,
strict,
modelId,
location,
addDefaultEntities);
}

private static class DefaultXmlReaderRequest implements XmlReaderRequest {
final Path path;
final Path rootDirectory;
final URL url;
final InputStream inputStream;
final Reader reader;
Expand All @@ -156,6 +175,7 @@ private static class DefaultXmlReaderRequest implements XmlReaderRequest {
@SuppressWarnings("checkstyle:ParameterNumber")
DefaultXmlReaderRequest(
Path path,
Path rootDirectory,
URL url,
InputStream inputStream,
Reader reader,
Expand All @@ -165,6 +185,7 @@ private static class DefaultXmlReaderRequest implements XmlReaderRequest {
String location,
boolean addDefaultEntities) {
this.path = path;
this.rootDirectory = rootDirectory;
this.url = url;
this.inputStream = inputStream;
this.reader = reader;
Expand All @@ -180,6 +201,11 @@ public Path getPath() {
return path;
}

@Override
public Path getRootDirectory() {
return rootDirectory;
}

@Override
public URL getURL() {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,11 +640,18 @@ private Model doReadFileModel(
try {
boolean strict = request.getValidationLevel() >= ModelBuilderRequest.VALIDATION_LEVEL_MAVEN_2_0;

Path rootDirectory;
try {
rootDirectory = request.getSession().getRootDirectory();
} catch (IllegalStateException ignore) {
rootDirectory = modelSource.getPath();
}
try (InputStream is = modelSource.openStream()) {
model = modelProcessor.read(XmlReaderRequest.builder()
.strict(strict)
.location(modelSource.getLocation())
.path(modelSource.getPath())
.rootDirectory(rootDirectory)
.inputStream(is)
.build());
} catch (XmlReaderException e) {
Expand All @@ -656,6 +663,7 @@ private Model doReadFileModel(
.strict(false)
.location(modelSource.getLocation())
.path(modelSource.getPath())
.rootDirectory(rootDirectory)
.inputStream(is)
.build());
} catch (XmlReaderException ne) {
Expand Down
4 changes: 4 additions & 0 deletions maven-core/src/main/resources/META-INF/maven/extension.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,13 @@ under the License.
<exportedArtifacts>
<!-- maven 4 api -->
<exportedArtifact>org.apache.maven:maven-api-core</exportedArtifact>
<exportedArtifact>org.apache.maven:maven-api-di</exportedArtifact>
<exportedArtifact>org.apache.maven:maven-api-meta</exportedArtifact>
<exportedArtifact>org.apache.maven:maven-api-metadata</exportedArtifact>
<exportedArtifact>org.apache.maven:maven-api-model</exportedArtifact>
<exportedArtifact>org.apache.maven:maven-api-plugin</exportedArtifact>
<exportedArtifact>org.apache.maven:maven-api-settings</exportedArtifact>
<exportedArtifact>org.apache.maven:maven-api-spi</exportedArtifact>
<exportedArtifact>org.apache.maven:maven-api-toolchain</exportedArtifact>
<exportedArtifact>org.apache.maven:maven-api-xml</exportedArtifact>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,8 @@ PlexusContainer container(CliRequest cliRequest) throws Exception {

final CoreExports exports = new CoreExports(containerRealm, exportedArtifacts, exportedPackages);

Thread.currentThread().setContextClassLoader(containerRealm);

DefaultPlexusContainer container = new DefaultPlexusContainer(cc, new AbstractModule() {
@Override
protected void configure() {
Expand Down