1 package org.codehaus.plexus.languages.java.jpms;
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 java.io.File;
23 import java.nio.file.Path;
24 import java.nio.file.Paths;
25
26 /**
27 *
28 * @author Robert Scholte
29 * @since 1.0.0
30 */
31 public abstract class ResolvePathRequest<T> {
32 private Path jdkHome;
33
34 private T path;
35
36 private ResolvePathRequest() {}
37
38 public static ResolvePathRequest<File> ofFile(File file) {
39 ResolvePathRequest<File> request = new ResolvePathRequest<File>() {
40 @Override
41 protected Path toPath(File f) {
42 return f.toPath();
43 }
44 };
45 request.path = file;
46 return request;
47 }
48
49 public static ResolvePathRequest<Path> ofPath(Path path) {
50 ResolvePathRequest<Path> request = new ResolvePathRequest<Path>() {
51 @Override
52 protected Path toPath(Path p) {
53 return p;
54 }
55 };
56 request.path = path;
57 return request;
58 }
59
60 public static ResolvePathRequest<String> ofString(String string) {
61 ResolvePathRequest<String> request = new ResolvePathRequest<String>() {
62 @Override
63 protected Path toPath(String s) {
64 return Paths.get(s);
65 }
66 };
67 request.path = string;
68 return request;
69 }
70
71 protected abstract Path toPath(T t);
72
73 public T getPathElement() {
74 return path;
75 }
76
77 /**
78 * In case the JRE is Java 8 or before, this jdkHome is used to extract the module name.
79 *
80 * @param jdkHome
81 * @return this request
82 */
83 public ResolvePathRequest<T> setJdkHome(T jdkHome) {
84 this.jdkHome = toPath(jdkHome);
85 return this;
86 }
87
88 public Path getJdkHome() {
89 return jdkHome;
90 }
91 }