mirror of https://github.com/apache/maven.git
Exception usage cleanup (#1910)
This is just a cleanup of exception usage (by making them checked, fixing compiler issues, and undoing the change). There are at least two bugs (runtime escapes) fixed in this PR.
This commit is contained in:
parent
c4834efdba
commit
ab7d766c72
|
@ -33,6 +33,7 @@ import org.apache.maven.api.annotations.ThreadSafe;
|
|||
import org.apache.maven.api.model.Repository;
|
||||
import org.apache.maven.api.services.ArtifactCoordinatesFactory;
|
||||
import org.apache.maven.api.services.DependencyCoordinatesFactory;
|
||||
import org.apache.maven.api.services.VersionResolverException;
|
||||
import org.apache.maven.api.settings.Settings;
|
||||
|
||||
/**
|
||||
|
@ -742,7 +743,7 @@ public interface Session {
|
|||
* @see org.apache.maven.api.services.VersionResolver#resolve(Session, ArtifactCoordinates) (String)
|
||||
*/
|
||||
@Nonnull
|
||||
Version resolveVersion(@Nonnull ArtifactCoordinates artifact);
|
||||
Version resolveVersion(@Nonnull ArtifactCoordinates artifact) throws VersionResolverException;
|
||||
|
||||
/**
|
||||
* Expands a version range to a list of matching versions, in ascending order.
|
||||
|
@ -758,7 +759,7 @@ public interface Session {
|
|||
* @see org.apache.maven.api.services.VersionRangeResolver#resolve(Session, ArtifactCoordinates) (String)
|
||||
*/
|
||||
@Nonnull
|
||||
List<Version> resolveVersionRange(@Nonnull ArtifactCoordinates artifact);
|
||||
List<Version> resolveVersionRange(@Nonnull ArtifactCoordinates artifact) throws VersionResolverException;
|
||||
|
||||
/**
|
||||
* Expands a version range to a list of matching versions, in ascending order.
|
||||
|
@ -775,7 +776,8 @@ public interface Session {
|
|||
* @see org.apache.maven.api.services.VersionRangeResolver#resolve(Session, ArtifactCoordinates) (String)
|
||||
*/
|
||||
@Nonnull
|
||||
List<Version> resolveVersionRange(@Nonnull ArtifactCoordinates artifact, List<RemoteRepository> repositories);
|
||||
List<Version> resolveVersionRange(@Nonnull ArtifactCoordinates artifact, List<RemoteRepository> repositories)
|
||||
throws VersionResolverException;
|
||||
|
||||
/**
|
||||
* Parses the specified version string, for example "1.0".
|
||||
|
|
|
@ -38,5 +38,5 @@ public interface ModelBuilder extends Service {
|
|||
ModelBuilderResult build(ModelBuilderRequest request) throws ModelBuilderException;
|
||||
}
|
||||
|
||||
Model buildRawModel(ModelBuilderRequest request);
|
||||
Model buildRawModel(ModelBuilderRequest request) throws ModelBuilderException;
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ public interface ProjectBuilder extends Service {
|
|||
* @throws IllegalArgumentException if an argument is {@code null} or invalid
|
||||
*/
|
||||
@Nonnull
|
||||
ProjectBuilderResult build(ProjectBuilderRequest request);
|
||||
ProjectBuilderResult build(ProjectBuilderRequest request) throws ProjectBuilderException;
|
||||
|
||||
/**
|
||||
* Creates a {@link org.apache.maven.api.Project} from a POM file.
|
||||
|
@ -52,7 +52,8 @@ public interface ProjectBuilder extends Service {
|
|||
* @see #build(ProjectBuilderRequest)
|
||||
*/
|
||||
@Nonnull
|
||||
default ProjectBuilderResult build(@Nonnull Session session, @Nonnull Source source) {
|
||||
default ProjectBuilderResult build(@Nonnull Session session, @Nonnull Source source)
|
||||
throws ProjectBuilderException {
|
||||
return build(ProjectBuilderRequest.build(session, source));
|
||||
}
|
||||
|
||||
|
@ -66,7 +67,7 @@ public interface ProjectBuilder extends Service {
|
|||
* @see #build(ProjectBuilderRequest)
|
||||
*/
|
||||
@Nonnull
|
||||
default ProjectBuilderResult build(@Nonnull Session session, @Nonnull Path path) {
|
||||
default ProjectBuilderResult build(@Nonnull Session session, @Nonnull Path path) throws ProjectBuilderException {
|
||||
return build(ProjectBuilderRequest.build(session, path));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ import java.io.IOException;
|
|||
import java.nio.file.Path;
|
||||
|
||||
import org.apache.maven.api.model.Model;
|
||||
import org.apache.maven.model.building.ModelBuildingException;
|
||||
import org.apache.maven.api.services.ModelBuilderException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.eclipse.aether.RepositorySystemSession;
|
||||
|
||||
|
@ -35,5 +35,5 @@ import org.eclipse.aether.RepositorySystemSession;
|
|||
interface ConsumerPomBuilder {
|
||||
|
||||
Model build(RepositorySystemSession session, MavenProject project, Path src)
|
||||
throws ModelBuildingException, IOException, XMLStreamException;
|
||||
throws ModelBuilderException, IOException, XMLStreamException;
|
||||
}
|
||||
|
|
|
@ -36,8 +36,8 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||
|
||||
import org.apache.maven.api.feature.Features;
|
||||
import org.apache.maven.api.model.Model;
|
||||
import org.apache.maven.api.services.ModelBuilderException;
|
||||
import org.apache.maven.internal.transformation.ConsumerPomArtifactTransformer;
|
||||
import org.apache.maven.model.building.ModelBuildingException;
|
||||
import org.apache.maven.model.v4.MavenStaxWriter;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.artifact.ProjectArtifact;
|
||||
|
@ -112,7 +112,7 @@ class DefaultConsumerPomArtifactTransformer implements ConsumerPomArtifactTransf
|
|||
}
|
||||
|
||||
void transform(MavenProject project, RepositorySystemSession session, Path src, Path tgt)
|
||||
throws ModelBuildingException, XMLStreamException, IOException {
|
||||
throws ModelBuilderException, XMLStreamException, IOException {
|
||||
Model model = builder.build(session, project, src);
|
||||
write(model, tgt);
|
||||
}
|
||||
|
|
|
@ -31,9 +31,9 @@ import java.util.Objects;
|
|||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.apache.maven.api.services.ModelBuilderException;
|
||||
import org.apache.maven.artifact.DefaultArtifact;
|
||||
import org.apache.maven.internal.transformation.TransformationFailedException;
|
||||
import org.apache.maven.model.building.ModelBuildingException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.eclipse.aether.RepositorySystemSession;
|
||||
|
||||
|
@ -97,13 +97,12 @@ class TransformedArtifact extends DefaultArtifact {
|
|||
return null;
|
||||
}
|
||||
return target.toFile();
|
||||
} catch (IOException | NoSuchAlgorithmException | XMLStreamException | ModelBuildingException e) {
|
||||
} catch (IOException | NoSuchAlgorithmException | XMLStreamException | ModelBuilderException e) {
|
||||
throw new TransformationFailedException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private String mayUpdate()
|
||||
throws IOException, NoSuchAlgorithmException, XMLStreamException, ModelBuildingException {
|
||||
private String mayUpdate() throws IOException, NoSuchAlgorithmException, XMLStreamException, ModelBuilderException {
|
||||
String result;
|
||||
Path src = sourcePathProvider.get();
|
||||
if (src == null) {
|
||||
|
|
|
@ -87,6 +87,7 @@ import org.apache.maven.api.services.TypeRegistry;
|
|||
import org.apache.maven.api.services.VersionParser;
|
||||
import org.apache.maven.api.services.VersionRangeResolver;
|
||||
import org.apache.maven.api.services.VersionResolver;
|
||||
import org.apache.maven.api.services.VersionResolverException;
|
||||
import org.eclipse.aether.DefaultRepositorySystemSession;
|
||||
import org.eclipse.aether.RepositorySystem;
|
||||
import org.eclipse.aether.RepositorySystemSession;
|
||||
|
@ -839,17 +840,18 @@ public abstract class AbstractSession implements InternalSession {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Version resolveVersion(ArtifactCoordinates artifact) {
|
||||
public Version resolveVersion(ArtifactCoordinates artifact) throws VersionResolverException {
|
||||
return getService(VersionResolver.class).resolve(this, artifact).getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Version> resolveVersionRange(ArtifactCoordinates artifact) {
|
||||
public List<Version> resolveVersionRange(ArtifactCoordinates artifact) throws VersionResolverException {
|
||||
return getService(VersionRangeResolver.class).resolve(this, artifact).getVersions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Version> resolveVersionRange(ArtifactCoordinates artifact, List<RemoteRepository> repositories) {
|
||||
public List<Version> resolveVersionRange(ArtifactCoordinates artifact, List<RemoteRepository> repositories)
|
||||
throws VersionResolverException {
|
||||
return getService(VersionRangeResolver.class)
|
||||
.resolve(this, artifact, repositories)
|
||||
.getVersions();
|
||||
|
|
|
@ -894,7 +894,7 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
return parentModel;
|
||||
}
|
||||
|
||||
private Model resolveParent(Model childModel) {
|
||||
private Model resolveParent(Model childModel) throws ModelBuilderException {
|
||||
Model parentModel = null;
|
||||
if (isBuildRequest()) {
|
||||
parentModel = readParentLocally(childModel);
|
||||
|
@ -906,7 +906,7 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
}
|
||||
|
||||
private Model readParentLocally(Model childModel) throws ModelBuilderException {
|
||||
ModelSource candidateSource = null;
|
||||
ModelSource candidateSource;
|
||||
|
||||
Parent parent = childModel.getParent();
|
||||
String parentPath = parent.getRelativePath();
|
||||
|
@ -1493,7 +1493,7 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
/**
|
||||
* Reads the request source's parent.
|
||||
*/
|
||||
Model readAsParentModel() {
|
||||
Model readAsParentModel() throws ModelBuilderException {
|
||||
return cache(request.getSource(), PARENT, this::doReadAsParentModel);
|
||||
}
|
||||
|
||||
|
@ -1664,7 +1664,7 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
importSource = modelResolver.resolveModel(
|
||||
request.getSession(), repositories, dependency, new AtomicReference<>());
|
||||
}
|
||||
} catch (ModelBuilderException e) {
|
||||
} catch (ModelBuilderException | ModelResolverException e) {
|
||||
StringBuilder buffer = new StringBuilder(256);
|
||||
buffer.append("Non-resolvable import POM");
|
||||
if (!containsCoordinates(e.getMessage(), groupId, artifactId, version)) {
|
||||
|
@ -1719,7 +1719,8 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
return importModel;
|
||||
}
|
||||
|
||||
ModelSource resolveReactorModel(String groupId, String artifactId, String version) {
|
||||
ModelSource resolveReactorModel(String groupId, String artifactId, String version)
|
||||
throws ModelBuilderException {
|
||||
Set<ModelSource> sources = mappedSources.get(new GAKey(groupId, artifactId));
|
||||
if (sources != null) {
|
||||
for (ModelSource source : sources) {
|
||||
|
@ -1737,7 +1738,7 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
return cache.computeIfAbsent(groupId, artifactId, version, tag, supplier);
|
||||
}
|
||||
|
||||
private <T> T cache(Source source, String tag, Supplier<T> supplier) {
|
||||
private <T> T cache(Source source, String tag, Supplier<T> supplier) throws ModelBuilderException {
|
||||
return cache.computeIfAbsent(source, tag, supplier);
|
||||
}
|
||||
|
||||
|
@ -1831,7 +1832,7 @@ public class DefaultModelBuilder implements ModelBuilder {
|
|||
public Model buildRawModel(ModelBuilderRequest request) throws ModelBuilderException {
|
||||
ModelBuilderSessionState build = new ModelBuilderSessionState(request);
|
||||
Model model = build.readRawModel();
|
||||
if (((ModelProblemCollector) build).hasErrors()) {
|
||||
if (build.hasErrors()) {
|
||||
throw build.newModelBuilderException();
|
||||
}
|
||||
return model;
|
||||
|
|
Loading…
Reference in New Issue