View Javadoc
1   package org.eclipse.aether.transport.classpath;
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 javax.inject.Named;
23  
24  import org.eclipse.aether.RepositorySystemSession;
25  import org.eclipse.aether.repository.RemoteRepository;
26  import org.eclipse.aether.spi.connector.transport.Transporter;
27  import org.eclipse.aether.spi.connector.transport.TransporterFactory;
28  import org.eclipse.aether.transfer.NoTransporterException;
29  
30  /**
31   * A transporter factory for repositories using the {@code classpath:} protocol. As example, getting an item named
32   * {@code some/file.txt} from a repository with the URL {@code classpath:/base/dir} results in retrieving the resource
33   * {@code base/dir/some/file.txt} from the classpath. The classpath to load the resources from is given via a
34   * {@link ClassLoader} that can be configured via the configuration property {@link #CONFIG_PROP_CLASS_LOADER}.
35   * <p>
36   * <em>Note:</em> Such repositories are read-only and uploads to them are generally not supported.
37   */
38  @Named( "classpath" )
39  public final class ClasspathTransporterFactory
40      implements TransporterFactory
41  {
42  
43      /**
44       * The key in the repository session's {@link RepositorySystemSession#getConfigProperties() configuration
45       * properties} used to store a {@link ClassLoader} from which resources should be retrieved. If unspecified, the
46       * {@link Thread#getContextClassLoader() context class loader} of the current thread will be used.
47       */
48      public static final String CONFIG_PROP_CLASS_LOADER = "aether.connector.classpath.loader";
49  
50      private float priority;
51  
52      /**
53       * Creates an (uninitialized) instance of this transporter factory. <em>Note:</em> In case of manual instantiation
54       * by clients, the new factory needs to be configured via its various mutators before first use or runtime errors
55       * will occur.
56       */
57      public ClasspathTransporterFactory()
58      {
59          // enables default constructor
60      }
61  
62  
63      public float getPriority()
64      {
65          return priority;
66      }
67  
68      /**
69       * Sets the priority of this component.
70       * 
71       * @param priority The priority.
72       * @return This component for chaining, never {@code null}.
73       */
74      public ClasspathTransporterFactory setPriority( float priority )
75      {
76          this.priority = priority;
77          return this;
78      }
79  
80      public Transporter newInstance( RepositorySystemSession session, RemoteRepository repository )
81          throws NoTransporterException
82      {
83          return new ClasspathTransporter( session, repository );
84      }
85  
86  }