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