001/*
002 * Copyright 2012-2018 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.time.Duration;
021import java.util.ArrayList;
022import java.util.List;
023
024import org.springframework.boot.context.properties.ConfigurationProperties;
025import org.springframework.boot.context.properties.NestedConfigurationProperty;
026import org.springframework.util.StringUtils;
027
028/**
029 * Configuration properties for developer tools.
030 *
031 * @author Phillip Webb
032 * @author Stephane Nicoll
033 * @since 1.3.0
034 */
035@ConfigurationProperties(prefix = "spring.devtools")
036public class DevToolsProperties {
037
038        private Restart restart = new Restart();
039
040        private Livereload livereload = new Livereload();
041
042        @NestedConfigurationProperty
043        private final RemoteDevToolsProperties remote = new RemoteDevToolsProperties();
044
045        public Restart getRestart() {
046                return this.restart;
047        }
048
049        public Livereload getLivereload() {
050                return this.livereload;
051        }
052
053        public RemoteDevToolsProperties getRemote() {
054                return this.remote;
055        }
056
057        /**
058         * Restart properties.
059         */
060        public static class Restart {
061
062                private static final String DEFAULT_RESTART_EXCLUDES = "META-INF/maven/**,"
063                                + "META-INF/resources/**,resources/**,static/**,public/**,templates/**,"
064                                + "**/*Test.class,**/*Tests.class,git.properties,META-INF/build-info.properties";
065
066                /**
067                 * Whether to enable automatic restart.
068                 */
069                private boolean enabled = true;
070
071                /**
072                 * Patterns that should be excluded from triggering a full restart.
073                 */
074                private String exclude = DEFAULT_RESTART_EXCLUDES;
075
076                /**
077                 * Additional patterns that should be excluded from triggering a full restart.
078                 */
079                private String additionalExclude;
080
081                /**
082                 * Amount of time to wait between polling for classpath changes.
083                 */
084                private Duration pollInterval = Duration.ofSeconds(1);
085
086                /**
087                 * Amount of quiet time required without any classpath changes before a restart is
088                 * triggered.
089                 */
090                private Duration quietPeriod = Duration.ofMillis(400);
091
092                /**
093                 * Name of a specific file that, when changed, triggers the restart check. If not
094                 * specified, any classpath file change triggers the restart.
095                 */
096                private String triggerFile;
097
098                /**
099                 * Additional paths to watch for changes.
100                 */
101                private List<File> additionalPaths = new ArrayList<>();
102
103                /**
104                 * Whether to log the condition evaluation delta upon restart.
105                 */
106                private boolean logConditionEvaluationDelta = true;
107
108                public boolean isEnabled() {
109                        return this.enabled;
110                }
111
112                public void setEnabled(boolean enabled) {
113                        this.enabled = enabled;
114                }
115
116                public String[] getAllExclude() {
117                        List<String> allExclude = new ArrayList<>();
118                        if (StringUtils.hasText(this.exclude)) {
119                                allExclude.addAll(StringUtils.commaDelimitedListToSet(this.exclude));
120                        }
121                        if (StringUtils.hasText(this.additionalExclude)) {
122                                allExclude.addAll(
123                                                StringUtils.commaDelimitedListToSet(this.additionalExclude));
124                        }
125                        return StringUtils.toStringArray(allExclude);
126                }
127
128                public String getExclude() {
129                        return this.exclude;
130                }
131
132                public void setExclude(String exclude) {
133                        this.exclude = exclude;
134                }
135
136                public String getAdditionalExclude() {
137                        return this.additionalExclude;
138                }
139
140                public void setAdditionalExclude(String additionalExclude) {
141                        this.additionalExclude = additionalExclude;
142                }
143
144                public Duration getPollInterval() {
145                        return this.pollInterval;
146                }
147
148                public void setPollInterval(Duration pollInterval) {
149                        this.pollInterval = pollInterval;
150                }
151
152                public Duration getQuietPeriod() {
153                        return this.quietPeriod;
154                }
155
156                public void setQuietPeriod(Duration quietPeriod) {
157                        this.quietPeriod = quietPeriod;
158                }
159
160                public String getTriggerFile() {
161                        return this.triggerFile;
162                }
163
164                public void setTriggerFile(String triggerFile) {
165                        this.triggerFile = triggerFile;
166                }
167
168                public List<File> getAdditionalPaths() {
169                        return this.additionalPaths;
170                }
171
172                public void setAdditionalPaths(List<File> additionalPaths) {
173                        this.additionalPaths = additionalPaths;
174                }
175
176                public boolean isLogConditionEvaluationDelta() {
177                        return this.logConditionEvaluationDelta;
178                }
179
180                public void setLogConditionEvaluationDelta(boolean logConditionEvaluationDelta) {
181                        this.logConditionEvaluationDelta = logConditionEvaluationDelta;
182                }
183
184        }
185
186        /**
187         * LiveReload properties.
188         */
189        public static class Livereload {
190
191                /**
192                 * Whether to enable a livereload.com-compatible server.
193                 */
194                private boolean enabled = true;
195
196                /**
197                 * Server port.
198                 */
199                private int port = 35729;
200
201                public boolean isEnabled() {
202                        return this.enabled;
203                }
204
205                public void setEnabled(boolean enabled) {
206                        this.enabled = enabled;
207                }
208
209                public int getPort() {
210                        return this.port;
211                }
212
213                public void setPort(int port) {
214                        this.port = port;
215                }
216
217        }
218
219}