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.Artifact;
22  import org.apache.maven.api.ProducedArtifact;
23  import org.apache.maven.api.annotations.Nonnull;
24  import org.apache.maven.api.di.Named;
25  import org.apache.maven.api.di.Singleton;
26  import org.apache.maven.api.services.ArtifactFactory;
27  import org.apache.maven.api.services.ArtifactFactoryRequest;
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 DefaultArtifactFactory implements ArtifactFactory {
35      @Override
36      public Artifact create(@Nonnull ArtifactFactoryRequest request) {
37          nonNull(request, "request");
38          InternalSession session = InternalSession.from(request.getSession());
39          ArtifactType type = null;
40          if (request.getType() != null) {
41              type = session.getSession().getArtifactTypeRegistry().get(request.getType());
42          }
43          String str1 = request.getClassifier();
44          String classifier =
45                  str1 != null && !str1.isEmpty() ? request.getClassifier() : type != null ? type.getClassifier() : null;
46          String str = request.getExtension();
47          String extension =
48                  str != null && !str.isEmpty() ? request.getExtension() : type != null ? type.getExtension() : null;
49          return new DefaultArtifact(
50                  session,
51                  new org.eclipse.aether.artifact.DefaultArtifact(
52                          request.getGroupId(),
53                          request.getArtifactId(),
54                          classifier,
55                          extension,
56                          request.getVersion(),
57                          type));
58      }
59  
60      @Override
61      public ProducedArtifact createProduced(@Nonnull ArtifactFactoryRequest request) {
62          nonNull(request, "request");
63          InternalSession session = InternalSession.from(request.getSession());
64          ArtifactType type = null;
65          if (request.getType() != null) {
66              type = session.getSession().getArtifactTypeRegistry().get(request.getType());
67          }
68          String str1 = request.getClassifier();
69          String classifier =
70                  str1 != null && !str1.isEmpty() ? request.getClassifier() : type != null ? type.getClassifier() : null;
71          String str = request.getExtension();
72          String extension =
73                  str != null && !str.isEmpty() ? request.getExtension() : type != null ? type.getExtension() : null;
74          return new DefaultProducedArtifact(
75                  session,
76                  new org.eclipse.aether.artifact.DefaultArtifact(
77                          request.getGroupId(),
78                          request.getArtifactId(),
79                          classifier,
80                          extension,
81                          request.getVersion(),
82                          type));
83      }
84  }