View Javadoc

1   /**
2    * Copyright 2010-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.common.util.execute;
17  
18  import org.kuali.common.util.Assert;
19  import org.kuali.common.util.CollectionUtils;
20  import org.kuali.common.util.FormatUtils;
21  import org.kuali.common.util.scm.ScmRequest;
22  import org.slf4j.Logger;
23  import org.slf4j.LoggerFactory;
24  
25  /**
26   * @deprecated
27   */
28  @Deprecated
29  public class ScmExecutable implements Executable {
30  
31  	private static final Logger logger = LoggerFactory.getLogger(ScmExecutable.class);
32  
33  	boolean skip;
34  	boolean logConfiguration;
35  	org.kuali.common.util.service.ScmService service;
36  	ScmRequest request;
37  
38  	@Override
39  	public void execute() {
40  
41  		// Show our current configuration
42  		if (logConfiguration) {
43  			log(this);
44  		}
45  
46  		// They have explicitly asked that execution be skipped
47  		if (skip) {
48  			logger.info("Skipping execution");
49  			return;
50  		}
51  
52  		// The SCM request is not allowed to be null here
53  		Assert.notNull(request);
54  
55  		// There are no files to add/delete/commit, no point in going further.
56  		if (isEmpty(request)) {
57  			logger.info("Skipping execution.  Nothing to do!");
58  			return;
59  		}
60  
61  		// Make sure we are configured correctly
62  		validateConfiguration(service, request);
63  
64  		// Add files as needed
65  		if (!CollectionUtils.isEmpty(request.getAdds())) {
66  			service.add(request.getAdds());
67  		}
68  
69  		// Delete files as needed
70  		if (!CollectionUtils.isEmpty(request.getDeletes())) {
71  			service.delete(request.getDeletes());
72  		}
73  
74  		// Commit files as needed
75  		if (!CollectionUtils.isEmpty(request.getCommits())) {
76  			service.commit(request.getCommits(), request.getCommitMessage());
77  		}
78  	}
79  
80  	protected void validateConfiguration(org.kuali.common.util.service.ScmService service, ScmRequest request) {
81  		// Make sure we are configured correctly
82  		Assert.notNull(service, "service is null");
83  		if (!CollectionUtils.isEmpty(request.getCommits())) {
84  			Assert.hasText(request.getCommitMessage(), "commitMessage has no text");
85  		}
86  	}
87  
88  	protected void log(ScmExecutable exec) {
89  		ScmRequest request = org.kuali.common.util.ScmUtils.cloneOrNew(exec.getRequest());
90  		String adds = FormatUtils.getCount(CollectionUtils.toEmptyList(request.getAdds()).size());
91  		String deletes = FormatUtils.getCount(CollectionUtils.toEmptyList(request.getDeletes()).size());
92  		String commits = FormatUtils.getCount(CollectionUtils.toEmptyList(request.getCommits()).size());
93  
94  		logger.info(" -- SCM --");
95  		logger.info("Adds: {}", adds);
96  		logger.info("Deletes: {}", deletes);
97  		logger.info("Commits: {}", commits);
98  		logger.info("Skip: {}", skip);
99  	}
100 
101 	public boolean isEmpty(ScmRequest request) {
102 		if (!CollectionUtils.isEmpty(request.getAdds())) {
103 			return false;
104 		}
105 		if (!CollectionUtils.isEmpty(request.getDeletes())) {
106 			return false;
107 		}
108 		if (!CollectionUtils.isEmpty(request.getCommits())) {
109 			return false;
110 		}
111 		return true;
112 	}
113 
114 	public org.kuali.common.util.service.ScmService getService() {
115 		return service;
116 	}
117 
118 	public void setService(org.kuali.common.util.service.ScmService service) {
119 		this.service = service;
120 	}
121 
122 	public boolean isSkip() {
123 		return skip;
124 	}
125 
126 	public void setSkip(boolean skip) {
127 		this.skip = skip;
128 	}
129 
130 	public ScmRequest getRequest() {
131 		return request;
132 	}
133 
134 	public void setRequest(ScmRequest request) {
135 		this.request = request;
136 	}
137 
138 	public boolean isLogConfiguration() {
139 		return logConfiguration;
140 	}
141 
142 	public void setLogConfiguration(boolean logConfiguration) {
143 		this.logConfiguration = logConfiguration;
144 	}
145 
146 }