001/**
002 * Copyright 2010-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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 */
016package org.kuali.common.util.execute;
017
018import java.io.File;
019import java.util.List;
020import java.util.Properties;
021
022import org.apache.commons.lang3.StringUtils;
023import org.kuali.common.util.PropertyUtils;
024import org.kuali.common.util.SimpleScanner;
025import org.slf4j.Logger;
026import org.slf4j.LoggerFactory;
027import org.springframework.util.Assert;
028
029public class SetNexusRepositoryIdExecutable implements Executable {
030
031        private static final Logger logger = LoggerFactory.getLogger(SetNexusRepositoryIdExecutable.class);
032
033        Properties mavenProperties;
034        File buildDirectory;
035        boolean skip;
036
037        @Override
038        public void execute() {
039                // Might be skipping execution altogether
040                if (skip) {
041                        logger.info("Skipping execution");
042                        return;
043                }
044
045                Assert.notNull(mavenProperties, "mavenProperties are null");
046                Assert.notNull(buildDirectory, "buildDirectory is null");
047                Assert.isTrue(buildDirectory.exists(), "buildDirectory does not exist");
048
049                File nexusDirectory = new File(buildDirectory, "nexus-staging");
050
051                SimpleScanner scanner = new SimpleScanner(nexusDirectory, "*.properties", null);
052                List<File> files = scanner.getFiles();
053
054                if (files.size() != 1) {
055                        throw new IllegalStateException("There can be only one!");
056                }
057
058                File nexusPropertiesFile = files.get(0);
059
060                Properties nexusProperties = PropertyUtils.load(nexusPropertiesFile);
061
062                String value = nexusProperties.getProperty("stagingRepository.id");
063
064                if (StringUtils.isBlank(value)) {
065                        throw new IllegalStateException("stagingRepository.id is blank");
066                }
067
068                mavenProperties.setProperty("nexus.stagingRepository.id", value);
069
070        }
071
072        public Properties getMavenProperties() {
073                return mavenProperties;
074        }
075
076        public void setMavenProperties(Properties mavenProperties) {
077                this.mavenProperties = mavenProperties;
078        }
079
080        public File getBuildDirectory() {
081                return buildDirectory;
082        }
083
084        public void setBuildDirectory(File buildDirectory) {
085                this.buildDirectory = buildDirectory;
086        }
087
088        public boolean isSkip() {
089                return skip;
090        }
091
092        public void setSkip(boolean skip) {
093                this.skip = skip;
094        }
095
096}