001    package org.kuali.common.deploy;
002    
003    import java.util.List;
004    
005    import org.kuali.common.deploy.env.model.DeployEnvironment;
006    import org.kuali.common.util.Assert;
007    import org.kuali.common.util.maven.model.Artifact;
008    import org.kuali.common.util.secure.channel.SecureChannel;
009    
010    import com.google.common.base.Optional;
011    import com.google.common.collect.ImmutableList;
012    
013    public final class DeployContext {
014    
015            private final SecureChannel channel;
016            private final DeployEnvironment environment;
017            private final Artifact application;
018            private final Optional<Artifact> jdbcDriver;
019            private final List<Deployable> configFiles;
020    
021            public DeployEnvironment getEnvironment() {
022                    return environment;
023            }
024    
025            public Artifact getApplication() {
026                    return application;
027            }
028    
029            public Optional<Artifact> getJdbcDriver() {
030                    return jdbcDriver;
031            }
032    
033            public List<Deployable> getConfigFiles() {
034                    return configFiles;
035            }
036    
037            public SecureChannel getChannel() {
038                    return channel;
039            }
040    
041            public static class Builder {
042    
043                    // Required
044                    private final SecureChannel channel;
045                    private final DeployEnvironment environment;
046                    private final Artifact application;
047    
048                    // Optional
049                    private Optional<Artifact> jdbcDriver = Optional.absent();
050                    private List<Deployable> configFiles = ImmutableList.of();
051    
052                    public Builder(DeployEnvironment environment, SecureChannel channel, Artifact application) {
053                            this.channel = channel;
054                            this.environment = environment;
055                            this.application = application;
056                    }
057    
058                    public Builder jdbcDriver(Optional<Artifact> jdbcDriver) {
059                            this.jdbcDriver = jdbcDriver;
060                            return this;
061                    }
062    
063                    public Builder jdbcDriver(Artifact jdbcDriver) {
064                            return jdbcDriver(Optional.fromNullable(jdbcDriver));
065                    }
066    
067                    public Builder configFiles(List<Deployable> configFiles) {
068                            this.configFiles = configFiles;
069                            return this;
070                    }
071    
072                    public DeployContext build() {
073                            Assert.noNulls(environment, channel, application, jdbcDriver, configFiles);
074                            this.configFiles = ImmutableList.copyOf(configFiles);
075                            return new DeployContext(this);
076                    }
077    
078            }
079    
080            private DeployContext(Builder builder) {
081                    this.environment = builder.environment;
082                    this.channel = builder.channel;
083                    this.application = builder.application;
084                    this.jdbcDriver = builder.jdbcDriver;
085                    this.configFiles = builder.configFiles;
086            }
087    
088    }