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

net.java.trueupdate.server.maven.MavenUpdateServerParameters Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (C) 2013 Schlichtherle IT Services & Stimulus Software.
 * All rights reserved. Use is subject to license terms.
 */
package net.java.trueupdate.server.maven;

import java.net.URL;
import java.util.Locale;
import java.util.ServiceConfigurationError;
import javax.annotation.*;
import javax.annotation.concurrent.Immutable;
import javax.xml.bind.JAXB;
import net.java.trueupdate.artifact.maven.*;
import net.java.trueupdate.artifact.spec.ArtifactResolver;
import net.java.trueupdate.server.maven.ci.MavenUpdateServerParametersCi;
import net.java.trueupdate.util.builder.AbstractBuilder;

/**
 * Maven update server parameters.
 *
 * @author Christian Schlichtherle
 */
@Immutable
public final class MavenUpdateServerParameters {

    private static final String CONFIGURATION = "update/server.xml";

    private final ArtifactResolver artifactResolver;

    MavenUpdateServerParameters(final Builder b) {
        this.artifactResolver = new MavenArtifactResolver(b.mavenParameters);
    }

    /**
     * Loads Maven update server parameters from the configuration resource
     * file with the name {@code update/server.xml}.
     */
    public static MavenUpdateServerParameters load() {
        return load(net.java.trueupdate.util.Resources.locate(CONFIGURATION));
    }

    static MavenUpdateServerParameters load(final URL source) {
        try {
            return parse(JAXB.unmarshal(source,
                                        MavenUpdateServerParametersCi.class));
        } catch (RuntimeException ex) {
            throw new ServiceConfigurationError(String.format(Locale.ENGLISH,
                    "Failed to load configuration from %s .", source),
                    ex);
        }
    }

    /** Parses the given configuration item. */
    public static MavenUpdateServerParameters parse(MavenUpdateServerParametersCi ci) {
        return builder().parse(ci).build();
    }

    /** Returns a new builder for maven update server parameters. */
    public static Builder builder() { return new Builder(); }

    /** Returns the artifact resolver. */
    public ArtifactResolver artifactResolver() { return artifactResolver; }

    /**
     * A builder for maven update server parameters.
     *
     * @param 

The type of the parent builder, if defined. */ @SuppressWarnings("PackageVisibleField") public static class Builder

extends AbstractBuilder

{ @CheckForNull MavenParameters mavenParameters; protected Builder() { } /** Selectively parses the given configuration item. */ public final Builder

parse(final MavenUpdateServerParametersCi ci) { return null == ci.repositories ? this : mavenParameters(MavenParameters.parse(ci.repositories)); } public final Builder

mavenParameters( final @Nullable MavenParameters mavenParameters) { this.mavenParameters = mavenParameters; return this; } @Override public final MavenUpdateServerParameters build() { return new MavenUpdateServerParameters(this); } } // Builder }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy