1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.maven.api.services;
20
21 import org.apache.maven.api.Artifact;
22 import org.apache.maven.api.ArtifactCoordinates;
23 import org.apache.maven.api.Service;
24 import org.apache.maven.api.Session;
25 import org.apache.maven.api.annotations.Experimental;
26 import org.apache.maven.api.annotations.Nonnull;
27
28 /**
29 * Service used to create {@link ArtifactCoordinates} objects.
30 *
31 * @since 4.0.0
32 */
33 @Experimental
34 public interface ArtifactCoordinatesFactory extends Service {
35
36 /**
37 * Creates artifact coordinates.
38 *
39 * @param request the request holding coordinates creation parameters
40 * @return an {@code ArtifactCoordinates}, never {@code null}
41 * @throws IllegalArgumentException if {@code request} is null or {@code request.session} is null or invalid
42 */
43 @Nonnull
44 ArtifactCoordinates create(@Nonnull ArtifactCoordinatesFactoryRequest request);
45
46 /**
47 * Creates coordinates out of string that is formatted like:
48 * {@code <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>}
49 *
50 * @param session the session.
51 * @param coordinatesString the string having "standard" coordinates.
52 * @return an {@code ArtifactCoordinates}, never {@code null}
53 * @throws IllegalArgumentException if {@code session} is null or invalid
54 */
55 @Nonnull
56 default ArtifactCoordinates create(@Nonnull Session session, @Nonnull String coordinatesString) {
57 return create(ArtifactCoordinatesFactoryRequest.build(session, coordinatesString));
58 }
59
60 @Nonnull
61 default ArtifactCoordinates create(
62 @Nonnull Session session, String groupId, String artifactId, String version, String extension) {
63 return create(ArtifactCoordinatesFactoryRequest.build(session, groupId, artifactId, version, extension));
64 }
65
66 @Nonnull
67 default ArtifactCoordinates create(
68 @Nonnull Session session,
69 String groupId,
70 String artifactId,
71 String version,
72 String classifier,
73 String extension,
74 String type) {
75 return create(ArtifactCoordinatesFactoryRequest.build(
76 session, groupId, artifactId, version, classifier, extension, type));
77 }
78
79 @Nonnull
80 default ArtifactCoordinates create(@Nonnull Session session, Artifact artifact) {
81 return create(ArtifactCoordinatesFactoryRequest.build(
82 session,
83 artifact.getGroupId(),
84 artifact.getArtifactId(),
85 artifact.getVersion().asString(),
86 artifact.getClassifier(),
87 artifact.getExtension(),
88 null));
89 }
90 }