001/*
002 * Copyright 2013 Atteo.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.atteo.moonshine.directories;
017
018import java.io.IOException;
019import java.nio.file.Files;
020import java.nio.file.Path;
021import java.util.Collections;
022
023/**
024 * Subdirectory layout.
025 *
026 * <p>
027 * Registers ${root}/config as config home and ${root}/data as data home.
028 * </p>
029 */
030public class SubdirectoryLayout implements WriteableDirectoryLayout {
031    private final Path configHome;
032    private final Path dataHome;
033    private final Path cacheHome;
034    private final Path logHome;
035
036    /**
037     * Creates subdirectory layout.
038     * @param root root directory of this layout
039     */
040    public SubdirectoryLayout(Path root) throws IOException {
041        Files.createDirectories(root);
042        configHome = root.resolve("config");
043        dataHome = root.resolve("data");
044        cacheHome = root.resolve("cache");
045        logHome = root.resolve("logs");
046    }
047
048    @Override
049    public Path getConfigHome() {
050        return configHome;
051    }
052
053    @Override
054    public Path getDataHome() {
055        return dataHome;
056    }
057
058    @Override
059    public Path getCacheHome() {
060        return cacheHome;
061    }
062
063    @Override
064    public Path getLogHome() {
065        return logHome;
066    }
067
068    @Override
069    public Iterable<Path> getConfigDirs() {
070        return Collections.emptyList();
071    }
072
073    @Override
074    public Iterable<Path> getDataDirs() {
075        return Collections.emptyList();
076    }
077
078}