View Javadoc

1   package org.apache.maven.repository;
2   
3   /* ====================================================================
4    *   Licensed to the Apache Software Foundation (ASF) under one or more
5    *   contributor license agreements.  See the NOTICE file distributed with
6    *   this work for additional information regarding copyright ownership.
7    *   The ASF licenses this file to You under the Apache License, Version 2.0
8    *   (the "License"); you may not use this file except in compliance with
9    *   the License.  You may obtain a copy of the License at
10   *
11   *       http://www.apache.org/licenses/LICENSE-2.0
12   *
13   *   Unless required by applicable law or agreed to in writing, software
14   *   distributed under the License is distributed on an "AS IS" BASIS,
15   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   *   See the License for the specific language governing permissions and
17   *   limitations under the License.
18   * ====================================================================
19   */
20  
21  import org.apache.maven.project.Dependency;
22  
23  /**
24   * Simple factory for creating Artifact implementations based on a dependency
25   * type.
26   *
27   * @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
28   * @version $Id: DefaultArtifactFactory.java 517014 2007-03-11 21:15:50Z ltheussl $
29   *
30   * @todo The factor needs to take a properties file describing the acceptable
31   *       types of artifacts. We can have a default set and also allow users
32   *       to customize the list for their own purposes.
33   */
34  public class DefaultArtifactFactory
35  {
36      /**
37       * Return an appropriate Artifact implementation based on the dependency
38       * type.
39       *
40       * @param dependency The base dependency.
41       * @todo not the intended usage of test type
42       * @return The appropriate artifact based on the dependency type.
43       */
44      public static Artifact createArtifact( Dependency dependency )
45      {
46          //!! I certainly have to revisit this. As sometimes we get
47          // any of the following conditions satisfied.
48          if ( ( dependency.getType() == null ) || ( dependency.getType().trim().length() == 0 )
49              || "jar".equals( dependency.getType() ) || "test".equals( dependency.getType() ) )
50          {
51              dependency.setType( "jar" );
52              return new GenericArtifact( dependency );
53          }
54          else
55          {
56              return new GenericArtifact( dependency );
57          }
58      }
59  }