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 java.io.File;
19  import java.util.List;
20  import java.util.Properties;
21  
22  import org.apache.commons.lang3.StringUtils;
23  import org.kuali.common.util.PropertyUtils;
24  import org.kuali.common.util.SimpleScanner;
25  import org.slf4j.Logger;
26  import org.slf4j.LoggerFactory;
27  import org.springframework.util.Assert;
28  
29  public class SetNexusRepositoryIdExecutable implements Executable {
30  
31  	private static final Logger logger = LoggerFactory.getLogger(SetNexusRepositoryIdExecutable.class);
32  
33  	Properties mavenProperties;
34  	File buildDirectory;
35  	boolean skip;
36  
37  	@Override
38  	public void execute() {
39  		// Might be skipping execution altogether
40  		if (skip) {
41  			logger.info("Skipping execution");
42  			return;
43  		}
44  
45  		Assert.notNull(mavenProperties, "mavenProperties are null");
46  		Assert.notNull(buildDirectory, "buildDirectory is null");
47  		Assert.isTrue(buildDirectory.exists(), "buildDirectory does not exist");
48  
49  		File nexusDirectory = new File(buildDirectory, "nexus-staging");
50  
51  		SimpleScanner scanner = new SimpleScanner(nexusDirectory, "*.properties", null);
52  		List<File> files = scanner.getFiles();
53  
54  		if (files.size() != 1) {
55  			throw new IllegalStateException("There can be only one!");
56  		}
57  
58  		File nexusPropertiesFile = files.get(0);
59  
60  		Properties nexusProperties = PropertyUtils.load(nexusPropertiesFile);
61  
62  		String value = nexusProperties.getProperty("stagingRepository.id");
63  
64  		if (StringUtils.isBlank(value)) {
65  			throw new IllegalStateException("stagingRepository.id is blank");
66  		}
67  
68  		mavenProperties.setProperty("nexus.stagingRepository.id", value);
69  
70  	}
71  
72  	public Properties getMavenProperties() {
73  		return mavenProperties;
74  	}
75  
76  	public void setMavenProperties(Properties mavenProperties) {
77  		this.mavenProperties = mavenProperties;
78  	}
79  
80  	public File getBuildDirectory() {
81  		return buildDirectory;
82  	}
83  
84  	public void setBuildDirectory(File buildDirectory) {
85  		this.buildDirectory = buildDirectory;
86  	}
87  
88  	public boolean isSkip() {
89  		return skip;
90  	}
91  
92  	public void setSkip(boolean skip) {
93  		this.skip = skip;
94  	}
95  
96  }