001package org.kuali.common.devops.aws.sysadmin.model;
002
003import java.io.File;
004
005import org.kuali.common.devops.model.ZipPackage;
006import org.kuali.common.util.Assert;
007import org.kuali.common.util.channel.api.ChannelService;
008import org.kuali.common.util.channel.model.ChannelContext;
009import org.kuali.common.util.maven.RepositoryUtils;
010
011public final class InstallZipContext {
012
013        private final ChannelService service;
014        private final ChannelContext context;
015        private final ZipPackage zip;
016        private final File localRepositoryDir;
017        private final String remotePackageDir;
018        private final String installDir;
019        private final boolean skipIfInstalled;
020
021        public static class Builder {
022
023                // Required
024                private final ChannelService service;
025                private final ChannelContext context;
026                private final ZipPackage zip;
027
028                // Optional
029                private File localRepositoryDir = RepositoryUtils.getDefaultLocalRepository();
030                private String remotePackageDir = "/usr/local";
031                private boolean skipIfInstalled = true;
032
033                // Filled in automatically, based off of remotePackageDir + package name
034                private String installDir;
035
036                public Builder(ChannelService service, ChannelContext context, ZipPackage zip) {
037                        this.zip = zip;
038                        this.service = service;
039                        this.context = context;
040                }
041
042                public Builder localRepositoryDir(File localRepositoryDir) {
043                        this.localRepositoryDir = localRepositoryDir;
044                        return this;
045                }
046
047                public Builder remotePackageDir(String remotePackageDir) {
048                        this.remotePackageDir = remotePackageDir;
049                        return this;
050                }
051
052                public Builder skipIfInstalled(boolean skipIfInstalled) {
053                        this.skipIfInstalled = skipIfInstalled;
054                        return this;
055                }
056
057                public InstallZipContext build() {
058                        Assert.noNulls(service, context, zip, localRepositoryDir);
059                        Assert.noBlanks(remotePackageDir);
060                        Assert.exists(RepositoryUtils.getFile(localRepositoryDir, zip.getArtifact()));
061                        this.installDir = remotePackageDir + "/" + zip.getName();
062                        return new InstallZipContext(this);
063                }
064        }
065
066        private InstallZipContext(Builder builder) {
067                this.zip = builder.zip;
068                this.service = builder.service;
069                this.context = builder.context;
070                this.localRepositoryDir = builder.localRepositoryDir;
071                this.remotePackageDir = builder.remotePackageDir;
072                this.installDir = builder.installDir;
073                this.skipIfInstalled = builder.skipIfInstalled;
074        }
075
076        public ChannelService getService() {
077                return service;
078        }
079
080        public ChannelContext getContext() {
081                return context;
082        }
083
084        public ZipPackage getZip() {
085                return zip;
086        }
087
088        public File getLocalRepositoryDir() {
089                return localRepositoryDir;
090        }
091
092        public String getRemotePackageDir() {
093                return remotePackageDir;
094        }
095
096        public String getInstallDir() {
097                return installDir;
098        }
099
100        public boolean isSkipIfInstalled() {
101                return skipIfInstalled;
102        }
103
104}