View Javadoc
1   package org.apache.maven.api.services;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.api.ArtifactCoordinate;
23  import org.apache.maven.api.DependencyCoordinate;
24  import org.apache.maven.api.Service;
25  import org.apache.maven.api.Session;
26  import org.apache.maven.api.annotations.Experimental;
27  import org.apache.maven.api.annotations.Nonnull;
28  import org.apache.maven.api.model.Dependency;
29  import org.apache.maven.api.model.Plugin;
30  import org.apache.maven.api.model.ReportPlugin;
31  
32  /**
33   *
34   * @since 4.0
35   */
36  @Experimental
37  public interface DependencyCoordinateFactory extends Service
38  {
39  
40      /**
41       * Creates a new {@link DependencyCoordinate} object from the request.
42       *
43       * @param request the request containing the various data
44       * @return a new {@link DependencyCoordinate} object.
45       *
46       * @throws IllegalArgumentException if {@code request} is null or
47       *         if {@code request.getSession()} is null or invalid
48       */
49      @Nonnull
50      DependencyCoordinate create( @Nonnull DependencyCoordinateFactoryRequest request );
51  
52      @Nonnull
53      default DependencyCoordinate create( @Nonnull Session session, @Nonnull ArtifactCoordinate coordinate )
54      {
55          return create( DependencyCoordinateFactoryRequest.build( session, coordinate ) );
56      }
57  
58      @Nonnull
59      default DependencyCoordinate create( @Nonnull Session session, @Nonnull org.apache.maven.api.Dependency dependency )
60      {
61          return create( DependencyCoordinateFactoryRequest.build( session, dependency ) );
62      }
63  
64      @Nonnull
65      default DependencyCoordinate create( @Nonnull Session session, Dependency dependency )
66      {
67          return create( DependencyCoordinateFactoryRequest.build( session,
68                  dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(),
69                  dependency.getClassifier(), null, dependency.getType() ) );
70      }
71  
72      @Nonnull
73      default DependencyCoordinate create( @Nonnull Session session, Plugin plugin )
74      {
75          // TODO: hard coded string
76          return create( DependencyCoordinateFactoryRequest.build( session,
77                  plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion(),
78                  null, null, "maven-plugin" ) );
79      }
80  
81      @Nonnull
82      default DependencyCoordinate create( @Nonnull Session session, ReportPlugin reportPlugin )
83      {
84          // TODO: hard coded string
85          return create( DependencyCoordinateFactoryRequest.build( session,
86                  reportPlugin.getGroupId(), reportPlugin.getArtifactId(), reportPlugin.getVersion(),
87                  null, null, "maven-plugin" ) );
88      }
89  }