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.api.services;
20  
21  import org.apache.maven.api.ArtifactCoordinates;
22  import org.apache.maven.api.DependencyCoordinates;
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  import org.apache.maven.api.model.Dependency;
28  import org.apache.maven.api.model.Plugin;
29  import org.apache.maven.api.model.ReportPlugin;
30  
31  /**
32   *
33   * @since 4.0.0
34   */
35  @Experimental
36  public interface DependencyCoordinatesFactory extends Service {
37  
38      /**
39       * Creates a new {@link DependencyCoordinates} object from the request.
40       *
41       * @param request the request containing the various data
42       * @return a new {@link DependencyCoordinates} object
43       *
44       * @throws IllegalArgumentException if {@code request} is null or
45       *         if {@code request.getSession()} is null or invalid
46       */
47      @Nonnull
48      DependencyCoordinates create(@Nonnull DependencyCoordinatesFactoryRequest request);
49  
50      @Nonnull
51      default DependencyCoordinates create(@Nonnull Session session, @Nonnull ArtifactCoordinates coordinates) {
52          return create(DependencyCoordinatesFactoryRequest.build(session, coordinates));
53      }
54  
55      @Nonnull
56      default DependencyCoordinates create(
57              @Nonnull Session session, @Nonnull org.apache.maven.api.Dependency dependency) {
58          return create(DependencyCoordinatesFactoryRequest.build(session, dependency));
59      }
60  
61      @Nonnull
62      default DependencyCoordinates create(@Nonnull Session session, Dependency dependency) {
63          return create(DependencyCoordinatesFactoryRequest.build(
64                  session,
65                  dependency.getGroupId(),
66                  dependency.getArtifactId(),
67                  dependency.getVersion(),
68                  dependency.getClassifier(),
69                  null,
70                  dependency.getType()));
71      }
72  
73      @Nonnull
74      default DependencyCoordinates create(@Nonnull Session session, Plugin plugin) {
75          // TODO: hard coded string
76          return create(DependencyCoordinatesFactoryRequest.build(
77                  session, plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion(), null, null, "maven-plugin"));
78      }
79  
80      @Nonnull
81      default DependencyCoordinates create(@Nonnull Session session, ReportPlugin reportPlugin) {
82          // TODO: hard coded string
83          return create(DependencyCoordinatesFactoryRequest.build(
84                  session,
85                  reportPlugin.getGroupId(),
86                  reportPlugin.getArtifactId(),
87                  reportPlugin.getVersion(),
88                  null,
89                  null,
90                  "maven-plugin"));
91      }
92  }