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.model.building;
20  
21  import java.io.File;
22  import java.net.URI;
23  import java.nio.file.Path;
24  
25  import org.apache.maven.building.FileSource;
26  import org.apache.maven.model.locator.ModelLocator;
27  
28  /**
29   * Wraps an ordinary {@link File} as a model source.
30   *
31   * @deprecated use {@link org.apache.maven.api.services.ModelBuilder} instead
32   */
33  @Deprecated(since = "4.0.0")
34  public class FileModelSource extends FileSource implements ModelSource3 {
35  
36      /**
37       * Creates a new model source backed by the specified file.
38       *
39       * @param pomFile The POM file, must not be {@code null}.
40       * @deprecated Use {@link #FileModelSource(Path)} instead.
41       */
42      @Deprecated
43      public FileModelSource(File pomFile) {
44          super(pomFile);
45      }
46  
47      /**
48       * Creates a new model source backed by the specified file.
49       *
50       * @param pomPath The POM file, must not be {@code null}.
51       * @since 4.0.0
52       */
53      public FileModelSource(Path pomPath) {
54          super(pomPath);
55      }
56  
57      /**
58       *
59       * @return the file of this source
60       *
61       * @deprecated instead use {@link #getFile()}
62       */
63      @Deprecated
64      public File getPomFile() {
65          return getFile();
66      }
67  
68      @Override
69      public ModelSource3 getRelatedSource(ModelLocator locator, String relPath) {
70          relPath = relPath.replace('\\', File.separatorChar).replace('/', File.separatorChar);
71  
72          Path path = getPath().getParent().resolve(relPath);
73  
74          Path relatedPom = locator.locateExistingPom(path);
75  
76          if (relatedPom != null) {
77              return new FileModelSource(relatedPom.normalize());
78          }
79  
80          return null;
81      }
82  
83      @Override
84      public URI getLocationURI() {
85          return getPath().toUri();
86      }
87  
88      @Override
89      public boolean equals(Object obj) {
90          if (this == obj) {
91              return true;
92          }
93  
94          if (obj == null) {
95              return false;
96          }
97  
98          if (!FileModelSource.class.equals(obj.getClass())) {
99              return false;
100         }
101         FileModelSource other = (FileModelSource) obj;
102         return getPath().equals(other.getPath());
103     }
104 
105     @Override
106     public int hashCode() {
107         return getPath().hashCode();
108     }
109 }