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
24 import org.apache.maven.building.FileSource;
25
26 /**
27 * Wraps an ordinary {@link File} as a model source.
28 *
29 * @deprecated use {@code org.apache.maven.api.services.ModelBuilder} instead
30 */
31 @Deprecated(since = "4.0.0")
32 public class FileModelSource extends FileSource implements ModelSource2 {
33
34 /**
35 * Creates a new model source backed by the specified file.
36 *
37 * @param pomFile The POM file, must not be {@code null}.
38 */
39 public FileModelSource(File pomFile) {
40 super(pomFile);
41 }
42
43 /**
44 *
45 * @return the file of this source
46 *
47 * @deprecated instead use {@link #getFile()}
48 */
49 @Deprecated
50 public File getPomFile() {
51 return getFile();
52 }
53
54 @Override
55 public ModelSource2 getRelatedSource(String relPath) {
56 relPath = relPath.replace('\\', File.separatorChar).replace('/', File.separatorChar);
57
58 File relatedPom = new File(getFile().getParentFile(), relPath);
59
60 if (relatedPom.isDirectory()) {
61 // TODO figure out how to reuse ModelLocator.locatePom(File) here
62 relatedPom = new File(relatedPom, "pom.xml");
63 }
64
65 if (relatedPom.isFile() && relatedPom.canRead()) {
66 return new FileModelSource(new File(relatedPom.toURI().normalize()));
67 }
68
69 return null;
70 }
71
72 @Override
73 public URI getLocationURI() {
74 return getFile().toURI();
75 }
76
77 @Override
78 public boolean equals(Object obj) {
79 if (this == obj) {
80 return true;
81 }
82
83 if (!(obj instanceof FileModelSource)) {
84 return false;
85 }
86 FileModelSource other = (FileModelSource) obj;
87 return getFile().equals(other.getFile());
88 }
89
90 @Override
91 public int hashCode() {
92 return getFile().hashCode();
93 }
94 }