View Javadoc
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.internal.impl;
20  
21  import org.apache.maven.api.ArtifactCoordinates;
22  import org.apache.maven.api.annotations.Nonnull;
23  import org.apache.maven.api.di.Named;
24  import org.apache.maven.api.di.Singleton;
25  import org.apache.maven.api.services.ArtifactCoordinatesFactory;
26  import org.apache.maven.api.services.ArtifactCoordinatesFactoryRequest;
27  import org.eclipse.aether.artifact.ArtifactType;
28  
29  import static org.apache.maven.internal.impl.Utils.nonNull;
30  
31  @Named
32  @Singleton
33  public class DefaultArtifactCoordinatesFactory implements ArtifactCoordinatesFactory {
34      @Override
35      public ArtifactCoordinates create(@Nonnull ArtifactCoordinatesFactoryRequest request) {
36          nonNull(request, "request");
37          InternalSession session = InternalSession.from(request.getSession());
38          if (request.getCoordinatesString() != null) {
39              return new DefaultArtifactCoordinates(
40                      session, new org.eclipse.aether.artifact.DefaultArtifact(request.getCoordinatesString()));
41          } else {
42              ArtifactType type = null;
43              if (request.getType() != null) {
44                  type = session.getSession().getArtifactTypeRegistry().get(request.getType());
45              }
46              String str1 = request.getClassifier();
47              String classifier = str1 != null && !str1.isEmpty()
48                      ? request.getClassifier()
49                      : type != null ? type.getClassifier() : "";
50              String str = request.getExtension();
51              String extension =
52                      str != null && !str.isEmpty() ? request.getExtension() : type != null ? type.getExtension() : "";
53              return new DefaultArtifactCoordinates(
54                      session,
55                      new org.eclipse.aether.artifact.DefaultArtifact(
56                              request.getGroupId(),
57                              request.getArtifactId(),
58                              classifier,
59                              extension,
60                              request.getVersion(),
61                              type));
62          }
63      }
64  }