Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2009-2014, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3) Neither the name of the nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 package com.jcabi.latex.maven.plugin;
 import java.util.Map;
Source of one file.

This class is immutable and thread-safe.

Yegor Bugayenko (
 final class Source {

Name of the source (main file).
     private final transient String main;

Collection of files (this Map is updated only in ctor and never ever touched/changed again).
     private final transient Map<StringURLinputs =
         new HashMap<StringURL>(0);

Public ctor.

dir Directory with sources
name Name of source
closures List of closures
Throws: If some error inside
     Source(final File dirfinal String name,
         final Iterable<Stringclosuresthrows IOException {
         if (dir == null || name == null || closures == null) {
             throw new IllegalArgumentException(
                 "NULL is not allowed in Source"
         if (!dir.exists()) {
             throw new IllegalArgumentException(
                 String.format("Directory '%s' doesn't exist"dir)
         if (name.isEmpty()) {
             throw new IllegalArgumentException(
                 "Empty name of source is not allowed"
         this. = FilenameUtils.getBaseName(name);
         for (final String closure : closures) {

Build and return names of files and their actual locations.

Names and locations
    public Map<StringURLfiles() {
            "#files(): %d files found for '%s': %[list]s",
        return Collections.unmodifiableMap(this.);

Short name of it (without extension and path).

The name
    public String name() {
        return this.;
    public String toString() {

Append one new source to the list.

dir Directory with sources
name The name of source
Throws: If some IO problem
    private void append(final File dirfinal String namethrows IOException {
        final File file;
        final String path;
        if (name.charAt(0) == '/') {
            file = new File(this.getClass().getResource(name).getFile());
            path = FilenameUtils.getName(file.getPath());
        } else {
            file = new File(dirname);
            if (!file.exists()) {
                throw new IOException(String.format("file %s not found"file));
            path = name;
        if (file.isDirectory()) {
            for (final String sub : Source.subs(file)) {
                this..put(subnew File(filesub).toURI().toURL());
        } else {

Find all sub-files in this directory (excluding folders).

dir Directory with sources
List of files (recursively)
    private static Iterable<Stringsubs(final File dir) {
        final IOFileFilter filter = new RegexFileFilter("[^\\.].*");
        final Collection<Filefiles = FileUtils.listFiles(dirfilterfilter);
        final Collection<Stringsubs = new ArrayList<String>(files.size());
        for (final File file : files) {
            subs.add(file.getPath().substring(dir.getPath().length() + 1));
        return subs;
New to GrepCode? Check out our FAQ X