001/*
002 * Copyright 2012-2016 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.boot.devtools.autoconfigure;
018
019import java.io.File;
020import java.util.ArrayList;
021import java.util.List;
022
023import org.springframework.boot.context.properties.ConfigurationProperties;
024import org.springframework.boot.context.properties.NestedConfigurationProperty;
025import org.springframework.util.StringUtils;
026
027/**
028 * Configuration properties for developer tools.
029 *
030 * @author Phillip Webb
031 * @author Stephane Nicoll
032 * @since 1.3.0
033 */
034@ConfigurationProperties(prefix = "spring.devtools")
035public class DevToolsProperties {
036
037        private Restart restart = new Restart();
038
039        private Livereload livereload = new Livereload();
040
041        @NestedConfigurationProperty
042        private RemoteDevToolsProperties remote = new RemoteDevToolsProperties();
043
044        public Restart getRestart() {
045                return this.restart;
046        }
047
048        public Livereload getLivereload() {
049                return this.livereload;
050        }
051
052        public RemoteDevToolsProperties getRemote() {
053                return this.remote;
054        }
055
056        /**
057         * Restart properties.
058         */
059        public static class Restart {
060
061                private static final String DEFAULT_RESTART_EXCLUDES = "META-INF/maven/**,"
062                                + "META-INF/resources/**,resources/**,static/**,public/**,templates/**,"
063                                + "**/*Test.class,**/*Tests.class,git.properties,META-INF/build-info.properties";
064
065                private static final long DEFAULT_RESTART_POLL_INTERVAL = 1000;
066
067                private static final long DEFAULT_RESTART_QUIET_PERIOD = 400;
068
069                /**
070                 * Enable automatic restart.
071                 */
072                private boolean enabled = true;
073
074                /**
075                 * Patterns that should be excluded from triggering a full restart.
076                 */
077                private String exclude = DEFAULT_RESTART_EXCLUDES;
078
079                /**
080                 * Additional patterns that should be excluded from triggering a full restart.
081                 */
082                private String additionalExclude;
083
084                /**
085                 * Amount of time (in milliseconds) to wait between polling for classpath changes.
086                 */
087                private long pollInterval = DEFAULT_RESTART_POLL_INTERVAL;
088
089                /**
090                 * Amount of quiet time (in milliseconds) required without any classpath changes
091                 * before a restart is triggered.
092                 */
093                private long quietPeriod = DEFAULT_RESTART_QUIET_PERIOD;
094
095                /**
096                 * Name of a specific file that when changed will trigger the restart check. If
097                 * not specified any classpath file change will trigger the restart.
098                 */
099                private String triggerFile;
100
101                /**
102                 * Additional paths to watch for changes.
103                 */
104                private List<File> additionalPaths = new ArrayList<File>();
105
106                public boolean isEnabled() {
107                        return this.enabled;
108                }
109
110                public void setEnabled(boolean enabled) {
111                        this.enabled = enabled;
112                }
113
114                public String[] getAllExclude() {
115                        List<String> allExclude = new ArrayList<String>();
116                        if (StringUtils.hasText(this.exclude)) {
117                                allExclude.addAll(StringUtils.commaDelimitedListToSet(this.exclude));
118                        }
119                        if (StringUtils.hasText(this.additionalExclude)) {
120                                allExclude.addAll(
121                                                StringUtils.commaDelimitedListToSet(this.additionalExclude));
122                        }
123                        return allExclude.toArray(new String[allExclude.size()]);
124                }
125
126                public String getExclude() {
127                        return this.exclude;
128                }
129
130                public void setExclude(String exclude) {
131                        this.exclude = exclude;
132                }
133
134                public String getAdditionalExclude() {
135                        return this.additionalExclude;
136                }
137
138                public void setAdditionalExclude(String additionalExclude) {
139                        this.additionalExclude = additionalExclude;
140                }
141
142                public long getPollInterval() {
143                        return this.pollInterval;
144                }
145
146                public void setPollInterval(long pollInterval) {
147                        this.pollInterval = pollInterval;
148                }
149
150                public long getQuietPeriod() {
151                        return this.quietPeriod;
152                }
153
154                public void setQuietPeriod(long quietPeriod) {
155                        this.quietPeriod = quietPeriod;
156                }
157
158                public String getTriggerFile() {
159                        return this.triggerFile;
160                }
161
162                public void setTriggerFile(String triggerFile) {
163                        this.triggerFile = triggerFile;
164                }
165
166                public List<File> getAdditionalPaths() {
167                        return this.additionalPaths;
168                }
169
170                public void setAdditionalPaths(List<File> additionalPaths) {
171                        this.additionalPaths = additionalPaths;
172                }
173
174        }
175
176        /**
177         * LiveReload properties.
178         */
179        public static class Livereload {
180
181                /**
182                 * Enable a livereload.com compatible server.
183                 */
184                private boolean enabled = true;
185
186                /**
187                 * Server port.
188                 */
189                private int port = 35729;
190
191                public boolean isEnabled() {
192                        return this.enabled;
193                }
194
195                public void setEnabled(boolean enabled) {
196                        this.enabled = enabled;
197                }
198
199                public int getPort() {
200                        return this.port;
201                }
202
203                public void setPort(int port) {
204                        this.port = port;
205                }
206
207        }
208
209}