Skip to content

Commit ab7d766

Browse files
authored
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.
1 parent c4834ef commit ab7d766

File tree

8 files changed

+30
-25
lines changed

8 files changed

+30
-25
lines changed

api/maven-api-core/src/main/java/org/apache/maven/api/Session.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.apache.maven.api.model.Repository;
3434
import org.apache.maven.api.services.ArtifactCoordinatesFactory;
3535
import org.apache.maven.api.services.DependencyCoordinatesFactory;
36+
import org.apache.maven.api.services.VersionResolverException;
3637
import org.apache.maven.api.settings.Settings;
3738

3839
/**
@@ -742,7 +743,7 @@ Map<PathType, List<Path>> resolveDependencies(
742743
* @see org.apache.maven.api.services.VersionResolver#resolve(Session, ArtifactCoordinates) (String)
743744
*/
744745
@Nonnull
745-
Version resolveVersion(@Nonnull ArtifactCoordinates artifact);
746+
Version resolveVersion(@Nonnull ArtifactCoordinates artifact) throws VersionResolverException;
746747

747748
/**
748749
* Expands a version range to a list of matching versions, in ascending order.
@@ -758,7 +759,7 @@ Map<PathType, List<Path>> resolveDependencies(
758759
* @see org.apache.maven.api.services.VersionRangeResolver#resolve(Session, ArtifactCoordinates) (String)
759760
*/
760761
@Nonnull
761-
List<Version> resolveVersionRange(@Nonnull ArtifactCoordinates artifact);
762+
List<Version> resolveVersionRange(@Nonnull ArtifactCoordinates artifact) throws VersionResolverException;
762763

763764
/**
764765
* Expands a version range to a list of matching versions, in ascending order.
@@ -775,7 +776,8 @@ Map<PathType, List<Path>> resolveDependencies(
775776
* @see org.apache.maven.api.services.VersionRangeResolver#resolve(Session, ArtifactCoordinates) (String)
776777
*/
777778
@Nonnull
778-
List<Version> resolveVersionRange(@Nonnull ArtifactCoordinates artifact, List<RemoteRepository> repositories);
779+
List<Version> resolveVersionRange(@Nonnull ArtifactCoordinates artifact, List<RemoteRepository> repositories)
780+
throws VersionResolverException;
779781

780782
/**
781783
* Parses the specified version string, for example "1.0".

api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ interface ModelBuilderSession {
3838
ModelBuilderResult build(ModelBuilderRequest request) throws ModelBuilderException;
3939
}
4040

41-
Model buildRawModel(ModelBuilderRequest request);
41+
Model buildRawModel(ModelBuilderRequest request) throws ModelBuilderException;
4242
}

api/maven-api-core/src/main/java/org/apache/maven/api/services/ProjectBuilder.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public interface ProjectBuilder extends Service {
4040
* @throws IllegalArgumentException if an argument is {@code null} or invalid
4141
*/
4242
@Nonnull
43-
ProjectBuilderResult build(ProjectBuilderRequest request);
43+
ProjectBuilderResult build(ProjectBuilderRequest request) throws ProjectBuilderException;
4444

4545
/**
4646
* Creates a {@link org.apache.maven.api.Project} from a POM file.
@@ -52,7 +52,8 @@ public interface ProjectBuilder extends Service {
5252
* @see #build(ProjectBuilderRequest)
5353
*/
5454
@Nonnull
55-
default ProjectBuilderResult build(@Nonnull Session session, @Nonnull Source source) {
55+
default ProjectBuilderResult build(@Nonnull Session session, @Nonnull Source source)
56+
throws ProjectBuilderException {
5657
return build(ProjectBuilderRequest.build(session, source));
5758
}
5859

@@ -66,7 +67,7 @@ default ProjectBuilderResult build(@Nonnull Session session, @Nonnull Source sou
6667
* @see #build(ProjectBuilderRequest)
6768
*/
6869
@Nonnull
69-
default ProjectBuilderResult build(@Nonnull Session session, @Nonnull Path path) {
70+
default ProjectBuilderResult build(@Nonnull Session session, @Nonnull Path path) throws ProjectBuilderException {
7071
return build(ProjectBuilderRequest.build(session, path));
7172
}
7273
}

impl/maven-core/src/main/java/org/apache/maven/internal/transformation/impl/ConsumerPomBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import java.nio.file.Path;
2525

2626
import org.apache.maven.api.model.Model;
27-
import org.apache.maven.model.building.ModelBuildingException;
27+
import org.apache.maven.api.services.ModelBuilderException;
2828
import org.apache.maven.project.MavenProject;
2929
import org.eclipse.aether.RepositorySystemSession;
3030

@@ -35,5 +35,5 @@
3535
interface ConsumerPomBuilder {
3636

3737
Model build(RepositorySystemSession session, MavenProject project, Path src)
38-
throws ModelBuildingException, IOException, XMLStreamException;
38+
throws ModelBuilderException, IOException, XMLStreamException;
3939
}

impl/maven-core/src/main/java/org/apache/maven/internal/transformation/impl/DefaultConsumerPomArtifactTransformer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636

3737
import org.apache.maven.api.feature.Features;
3838
import org.apache.maven.api.model.Model;
39+
import org.apache.maven.api.services.ModelBuilderException;
3940
import org.apache.maven.internal.transformation.ConsumerPomArtifactTransformer;
40-
import org.apache.maven.model.building.ModelBuildingException;
4141
import org.apache.maven.model.v4.MavenStaxWriter;
4242
import org.apache.maven.project.MavenProject;
4343
import org.apache.maven.project.artifact.ProjectArtifact;
@@ -112,7 +112,7 @@ TransformedArtifact createConsumerPomArtifact(
112112
}
113113

114114
void transform(MavenProject project, RepositorySystemSession session, Path src, Path tgt)
115-
throws ModelBuildingException, XMLStreamException, IOException {
115+
throws ModelBuilderException, XMLStreamException, IOException {
116116
Model model = builder.build(session, project, src);
117117
write(model, tgt);
118118
}

impl/maven-core/src/main/java/org/apache/maven/internal/transformation/impl/TransformedArtifact.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
import java.util.concurrent.atomic.AtomicReference;
3232
import java.util.function.Supplier;
3333

34+
import org.apache.maven.api.services.ModelBuilderException;
3435
import org.apache.maven.artifact.DefaultArtifact;
3536
import org.apache.maven.internal.transformation.TransformationFailedException;
36-
import org.apache.maven.model.building.ModelBuildingException;
3737
import org.apache.maven.project.MavenProject;
3838
import org.eclipse.aether.RepositorySystemSession;
3939

@@ -97,13 +97,12 @@ public synchronized File getFile() {
9797
return null;
9898
}
9999
return target.toFile();
100-
} catch (IOException | NoSuchAlgorithmException | XMLStreamException | ModelBuildingException e) {
100+
} catch (IOException | NoSuchAlgorithmException | XMLStreamException | ModelBuilderException e) {
101101
throw new TransformationFailedException(e);
102102
}
103103
}
104104

105-
private String mayUpdate()
106-
throws IOException, NoSuchAlgorithmException, XMLStreamException, ModelBuildingException {
105+
private String mayUpdate() throws IOException, NoSuchAlgorithmException, XMLStreamException, ModelBuilderException {
107106
String result;
108107
Path src = sourcePathProvider.get();
109108
if (src == null) {

impl/maven-impl/src/main/java/org/apache/maven/internal/impl/AbstractSession.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
import org.apache.maven.api.services.VersionParser;
8888
import org.apache.maven.api.services.VersionRangeResolver;
8989
import org.apache.maven.api.services.VersionResolver;
90+
import org.apache.maven.api.services.VersionResolverException;
9091
import org.eclipse.aether.DefaultRepositorySystemSession;
9192
import org.eclipse.aether.RepositorySystem;
9293
import org.eclipse.aether.RepositorySystemSession;
@@ -839,17 +840,18 @@ public VersionConstraint parseVersionConstraint(String versionConstraint) {
839840
}
840841

841842
@Override
842-
public Version resolveVersion(ArtifactCoordinates artifact) {
843+
public Version resolveVersion(ArtifactCoordinates artifact) throws VersionResolverException {
843844
return getService(VersionResolver.class).resolve(this, artifact).getVersion();
844845
}
845846

846847
@Override
847-
public List<Version> resolveVersionRange(ArtifactCoordinates artifact) {
848+
public List<Version> resolveVersionRange(ArtifactCoordinates artifact) throws VersionResolverException {
848849
return getService(VersionRangeResolver.class).resolve(this, artifact).getVersions();
849850
}
850851

851852
@Override
852-
public List<Version> resolveVersionRange(ArtifactCoordinates artifact, List<RemoteRepository> repositories) {
853+
public List<Version> resolveVersionRange(ArtifactCoordinates artifact, List<RemoteRepository> repositories)
854+
throws VersionResolverException {
853855
return getService(VersionRangeResolver.class)
854856
.resolve(this, artifact, repositories)
855857
.getVersions();

impl/maven-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelBuilder.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ Model readParent(Model childModel) throws ModelBuilderException {
894894
return parentModel;
895895
}
896896

897-
private Model resolveParent(Model childModel) {
897+
private Model resolveParent(Model childModel) throws ModelBuilderException {
898898
Model parentModel = null;
899899
if (isBuildRequest()) {
900900
parentModel = readParentLocally(childModel);
@@ -906,7 +906,7 @@ private Model resolveParent(Model childModel) {
906906
}
907907

908908
private Model readParentLocally(Model childModel) throws ModelBuilderException {
909-
ModelSource candidateSource = null;
909+
ModelSource candidateSource;
910910

911911
Parent parent = childModel.getParent();
912912
String parentPath = parent.getRelativePath();
@@ -1493,7 +1493,7 @@ private Model doReadRawModel() throws ModelBuilderException {
14931493
/**
14941494
* Reads the request source's parent.
14951495
*/
1496-
Model readAsParentModel() {
1496+
Model readAsParentModel() throws ModelBuilderException {
14971497
return cache(request.getSource(), PARENT, this::doReadAsParentModel);
14981498
}
14991499

@@ -1664,7 +1664,7 @@ private Model doLoadDependencyManagement(
16641664
importSource = modelResolver.resolveModel(
16651665
request.getSession(), repositories, dependency, new AtomicReference<>());
16661666
}
1667-
} catch (ModelBuilderException e) {
1667+
} catch (ModelBuilderException | ModelResolverException e) {
16681668
StringBuilder buffer = new StringBuilder(256);
16691669
buffer.append("Non-resolvable import POM");
16701670
if (!containsCoordinates(e.getMessage(), groupId, artifactId, version)) {
@@ -1719,7 +1719,8 @@ private Model doLoadDependencyManagement(
17191719
return importModel;
17201720
}
17211721

1722-
ModelSource resolveReactorModel(String groupId, String artifactId, String version) {
1722+
ModelSource resolveReactorModel(String groupId, String artifactId, String version)
1723+
throws ModelBuilderException {
17231724
Set<ModelSource> sources = mappedSources.get(new GAKey(groupId, artifactId));
17241725
if (sources != null) {
17251726
for (ModelSource source : sources) {
@@ -1737,7 +1738,7 @@ private <T> T cache(String groupId, String artifactId, String version, String ta
17371738
return cache.computeIfAbsent(groupId, artifactId, version, tag, supplier);
17381739
}
17391740

1740-
private <T> T cache(Source source, String tag, Supplier<T> supplier) {
1741+
private <T> T cache(Source source, String tag, Supplier<T> supplier) throws ModelBuilderException {
17411742
return cache.computeIfAbsent(source, tag, supplier);
17421743
}
17431744

@@ -1831,7 +1832,7 @@ private static List<String> getSubprojects(Model activated) {
18311832
public Model buildRawModel(ModelBuilderRequest request) throws ModelBuilderException {
18321833
ModelBuilderSessionState build = new ModelBuilderSessionState(request);
18331834
Model model = build.readRawModel();
1834-
if (((ModelProblemCollector) build).hasErrors()) {
1835+
if (build.hasErrors()) {
18351836
throw build.newModelBuilderException();
18361837
}
18371838
return model;

0 commit comments

Comments
 (0)