1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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 }