All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.gradle.external.javadoc.internal.JavadocOptionFile Maven / Gradle / Ivy

/*
 * Copyright 2009 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.gradle.external.javadoc.internal;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.gradle.external.javadoc.JavadocOptionFileOption;
import org.gradle.external.javadoc.OptionLessJavadocOptionFileOption;
import org.gradle.internal.Cast;

import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class JavadocOptionFile {
    private final Map> options;

    private final OptionLessJavadocOptionFileOptionInternal> sourceNames;

    public JavadocOptionFile() {
        this(new LinkedHashMap>(), new OptionLessStringsJavadocOptionFileOption(Lists.newArrayList()));
    }

    private JavadocOptionFile(Map> options, OptionLessJavadocOptionFileOptionInternal> sourceNames) {
        this.options = options;
        this.sourceNames = sourceNames;
    }

    public JavadocOptionFile(JavadocOptionFile original) {
        this(duplicateOptions(original.options), original.sourceNames.duplicate());
    }

    private static Map> duplicateOptions(Map> original) {
        Map> duplicateOptions = Maps.newLinkedHashMap();
        for (Map.Entry> entry : original.entrySet()) {
            duplicateOptions.put(entry.getKey(), entry.getValue().duplicate());
        }
        return duplicateOptions;
    }

    public OptionLessJavadocOptionFileOption> getSourceNames() {
        return sourceNames;
    }

    Map> getOptions() {
        return Collections.unmodifiableMap(options);
    }

    public  JavadocOptionFileOption addOption(JavadocOptionFileOptionInternal option) {
        if (option == null) {
            throw new IllegalArgumentException("option == null!");
        }

        options.put(option.getOption(), option);

        return option;
    }

    public JavadocOptionFileOption addStringOption(String option) {
        return addStringOption(option, null);
    }

    public JavadocOptionFileOption addStringOption(String option, String value) {
        return addOption(new StringJavadocOptionFileOption(option, value));
    }

    public  JavadocOptionFileOption addEnumOption(String option) {
        return addEnumOption(option, null);
    }

    public  JavadocOptionFileOption addEnumOption(String option, T value) {
        return addOption(new EnumJavadocOptionFileOption(option, value));
    }

    public JavadocOptionFileOption> addPathOption(String option) {
        return addPathOption(option, System.getProperty("path.separator"));
    }

    public JavadocOptionFileOption> addPathOption(String option, String joinBy) {
        return addOption(new PathJavadocOptionFileOption(option, Lists.newArrayList(), joinBy));
    }

    public JavadocOptionFileOption> addStringsOption(String option) {
        return addStringsOption(option, System.getProperty("path.separator"));
    }

    public JavadocOptionFileOption> addStringsOption(String option, String joinBy) {
        return addOption(new StringsJavadocOptionFileOption(option, Lists.newArrayList(), joinBy));
    }

    public JavadocOptionFileOption> addMultilineStringsOption(String option) {
        return addOption(new MultilineStringsJavadocOptionFileOption(option, Lists.newArrayList()));
    }

    public JavadocOptionFileOption addBooleanOption(String option) {
        return addBooleanOption(option, false);
    }

    public JavadocOptionFileOption addBooleanOption(String option, boolean value) {
        return addOption(new BooleanJavadocOptionFileOption(option, value));
    }

    public JavadocOptionFileOption addFileOption(String option) {
        return addFileOption(option, null);
    }

    public JavadocOptionFileOption addFileOption(String option, File value) {
        return addOption(new FileJavadocOptionFileOption(option, value));
    }

    public void write(File optionFile) throws IOException {
        if (optionFile == null) {
            throw new IllegalArgumentException("optionFile == null!");
        }

        final JavadocOptionFileWriter optionFileWriter = new JavadocOptionFileWriter(this);

        optionFileWriter.write(optionFile);
    }

    public  JavadocOptionFileOption getOption(String option) {
        JavadocOptionFileOption foundOption = options.get(option);
        if (foundOption == null) {
            throw new IllegalArgumentException("Cannot find option " + option);
        }
        return Cast.uncheckedCast(foundOption);
    }

    public JavadocOptionFileOption>> addMultilineMultiValueOption(String option) {
        return addOption(new MultilineMultiValueJavadocOptionFileOption(option, Lists.>newArrayList(), " "));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy