001    package org.kuali.common.deploy.appserver.tomcat;
002    
003    import java.util.List;
004    
005    import org.kuali.common.deploy.Deployable;
006    import org.kuali.common.util.Assert;
007    
008    import com.google.common.collect.ImmutableList;
009    
010    public final class TomcatFiles {
011    
012            private final TomcatDirs dirs;
013            private final String rootWar;
014            private final String serverXml;
015            private final String webXml;
016            private final List<Deployable> logsDirJsps;
017    
018            public static class Builder {
019    
020                    // Required
021                    private final TomcatDirs dirs;
022    
023                    // Optional
024                    private String rootWar;
025                    private String serverXml;
026                    private String webXml;
027                    private List<Deployable> logsDirJsps = ImmutableList.of();
028    
029                    public Builder(TomcatDirs dirs) {
030                            this.dirs = dirs;
031                            this.rootWar = dirs.getWebapps() + "/ROOT.war";
032                            this.serverXml = dirs.getConf() + "/server.xml";
033                            this.webXml = dirs.getConf() + "/web.xml";
034                            this.logsDirJsps = getLogsDirJsps(dirs);
035                    }
036    
037                    private List<Deployable> getLogsDirJsps(TomcatDirs dirs) {
038                            Deployable env = new Deployable.Builder("classpath:org/kuali/common/deploy/jsp/env.jsp", dirs.getLib() + "/env.jsp").build();
039                            Deployable tail = new Deployable.Builder("classpath:org/kuali/common/deploy/jsp/tail.jsp", dirs.getLib() + "/tail.jsp").build();
040                            return ImmutableList.of(env, tail);
041                    }
042    
043                    public Builder rootWar(String rootWar) {
044                            this.rootWar = rootWar;
045                            return this;
046                    }
047    
048                    public Builder serverXml(String serverXml) {
049                            this.serverXml = serverXml;
050                            return this;
051                    }
052    
053                    public Builder webXml(String webXml) {
054                            this.webXml = webXml;
055                            return this;
056                    }
057    
058                    public Builder logsDirJsps(List<Deployable> logsDirJsps) {
059                            this.logsDirJsps = logsDirJsps;
060                            return this;
061                    }
062    
063                    public TomcatFiles build() {
064                            Assert.noBlanks(rootWar, serverXml, webXml);
065                            Assert.notNull(logsDirJsps);
066                            this.logsDirJsps = ImmutableList.copyOf(logsDirJsps);
067                            return new TomcatFiles(this);
068                    }
069    
070            }
071    
072            private TomcatFiles(Builder builder) {
073                    this.dirs = builder.dirs;
074                    this.rootWar = builder.rootWar;
075                    this.serverXml = builder.serverXml;
076                    this.webXml = builder.webXml;
077                    this.logsDirJsps = builder.logsDirJsps;
078            }
079    
080            public String getRootWar() {
081                    return rootWar;
082            }
083    
084            public String getServerXml() {
085                    return serverXml;
086            }
087    
088            public String getWebXml() {
089                    return webXml;
090            }
091    
092            public List<Deployable> getLogsDirJsps() {
093                    return logsDirJsps;
094            }
095    
096            public TomcatDirs getDirs() {
097                    return dirs;
098            }
099    
100    }