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