Skip to content

Commit

Permalink
[MNG-8084] New model builder and resolver provider
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Apr 5, 2024
1 parent d4bf190 commit f8d790e
Show file tree
Hide file tree
Showing 196 changed files with 18,569 additions and 1,131 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* http://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.apache.maven.api.services;

import java.util.List;

import org.apache.maven.api.Service;
import org.apache.maven.api.model.Model;

public interface ModelBuilder extends Service {

List<String> VALID_MODEL_VERSIONS = List.of("4.0.0", "4.1.0");

ModelBuilderResult build(ModelBuilderRequest request) throws ModelBuilderException;

ModelTransformerContextBuilder newTransformerContextBuilder();

Model buildRawModel(ModelBuilderRequest request);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* http://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.apache.maven.api.services;

import java.util.Collections;
import java.util.List;

import org.apache.maven.api.annotations.Experimental;

/**
* The Exception class throw by the {@link ProjectBuilder} service.
*
* @since 4.0.0
*/
@Experimental
public class ModelBuilderException extends MavenException {

private final ModelBuilderResult result;

/**
* Creates a new exception from the specified interim result and its associated problems.
*
* @param result The interim result, may be {@code null}.
*/
public ModelBuilderException(ModelBuilderResult result) {
super(result.toString());
this.result = result;
}

/**
* Gets the interim result of the model building up to the point where it failed.
*
* @return The interim model building result or {@code null} if not available.
*/
public ModelBuilderResult getResult() {
return result;
}

/**
* Gets the identifier of the POM whose effective model could not be built. The general format of the identifier is
* {@code <groupId>:<artifactId>:<version>} but some of these coordinates may still be unknown at the point the
* exception is thrown so this information is merely meant to assist the user.
*
* @return The identifier of the POM or an empty string if not known, never {@code null}.
*/
public String getModelId() {
if (result == null || result.getModelIds().isEmpty()) {
return "";
}
return result.getModelIds().get(0);
}

/**
* Gets the problems that caused this exception.
*
* @return The problems that caused this exception, never {@code null}.
*/
public List<ModelProblem> getProblems() {
if (result == null) {
return Collections.emptyList();
}
return Collections.unmodifiableList(result.getProblems());
}
}

0 comments on commit f8d790e

Please sign in to comment.