SourceLocation.java revision 3195:88a874f33d6d
1/*
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package com.sun.tools.sjavac.options;
27
28import java.io.IOException;
29import java.nio.file.Path;
30import java.util.List;
31import java.util.Map;
32import java.util.Set;
33
34import com.sun.tools.sjavac.Log;
35import com.sun.tools.sjavac.Module;
36import com.sun.tools.sjavac.ProblemException;
37import com.sun.tools.sjavac.Source;
38
39/**
40 * Represents a directory to be used for input to sjavac. (For instance a
41 * sourcepath or classpath.)
42 *
43 *  <p><b>This is NOT part of any supported API.
44 *  If you write code that depends on this, you do so at your own risk.
45 *  This code and its internal interfaces are subject to change or
46 *  deletion without notice.</b>
47 */
48public class SourceLocation {
49
50    // Path to the root directory
51    private Path path;
52
53    // Package include / exclude patterns and file includes / excludes.
54    List<String> includes, excludes;
55
56    public SourceLocation(Path path,
57                          List<String> includes,
58                          List<String> excludes) {
59        this.path = path;
60        this.includes = includes;
61        this.excludes = excludes;
62    }
63
64
65    /**
66     * Finds all files with the given suffix that pass the include / exclude
67     * filters in this source location.
68     *
69     * @param suffixes The set of suffixes to search for
70     * @param foundFiles The map in which to store the found files
71     * @param foundModules The map in which to store the found modules
72     * @param currentModule The current module
73     * @param permitSourcesInDefaultPackage true if sources in default package
74     *                                      are to be permitted
75     * @param inLinksrc true if in link source
76     */
77    public void findSourceFiles(Set<String> suffixes,
78                                Map<String, Source> foundFiles,
79                                Map<String, Module> foundModules,
80                                Module currentModule,
81                                boolean permitSourcesInDefaultPackage,
82                                boolean inLinksrc)
83                                        throws IOException {
84        try {
85            Source.scanRoot(path.toFile(),
86                            suffixes,
87                            excludes,
88                            includes,
89                            foundFiles,
90                            foundModules,
91                            currentModule,
92                            permitSourcesInDefaultPackage,
93                            false,
94                            inLinksrc);
95        } catch (ProblemException e) {
96            e.printStackTrace();
97        }
98    }
99    /** Get the root directory of this source location */
100    public Path getPath() {
101        return path;
102    }
103
104    /** Get the package include patterns */
105    public List<String> getIncludes() {
106        return includes;
107    }
108
109    /** Get the package exclude patterns */
110    public List<String> getExcludes() {
111        return excludes;
112    }
113
114    @Override
115    public String toString() {
116        return String.format("%s[\"%s\", includes: %s, excludes: %s]",
117                             getClass().getSimpleName(), path, includes, excludes);
118    }
119}
120