001/**
002 * Copyright 2010-2014 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
029/**
030 * @deprecated
031 */
032@Deprecated
033public class SetNexusRepositoryIdExecutable implements Executable {
034
035        private static final Logger logger = LoggerFactory.getLogger(SetNexusRepositoryIdExecutable.class);
036
037        Properties mavenProperties;
038        File buildDirectory;
039        boolean skip;
040
041        @Override
042        public void execute() {
043                // Might be skipping execution altogether
044                if (skip) {
045                        logger.info("Skipping execution");
046                        return;
047                }
048
049                Assert.notNull(mavenProperties, "mavenProperties are null");
050                Assert.notNull(buildDirectory, "buildDirectory is null");
051                Assert.isTrue(buildDirectory.exists(), "buildDirectory does not exist");
052
053                File nexusDirectory = new File(buildDirectory, "nexus-staging");
054
055                SimpleScanner scanner = new SimpleScanner(nexusDirectory, "*.properties", null);
056                List<File> files = scanner.getFiles();
057
058                if (files.size() != 1) {
059                        throw new IllegalStateException("There can be only one!");
060                }
061
062                File nexusPropertiesFile = files.get(0);
063
064                Properties nexusProperties = PropertyUtils.load(nexusPropertiesFile);
065
066                String value = nexusProperties.getProperty("stagingRepository.id");
067
068                if (StringUtils.isBlank(value)) {
069                        throw new IllegalStateException("stagingRepository.id is blank");
070                }
071
072                mavenProperties.setProperty("nexus.stagingRepository.id", value);
073
074        }
075
076        public Properties getMavenProperties() {
077                return mavenProperties;
078        }
079
080        public void setMavenProperties(Properties mavenProperties) {
081                this.mavenProperties = mavenProperties;
082        }
083
084        public File getBuildDirectory() {
085                return buildDirectory;
086        }
087
088        public void setBuildDirectory(File buildDirectory) {
089                this.buildDirectory = buildDirectory;
090        }
091
092        public boolean isSkip() {
093                return skip;
094        }
095
096        public void setSkip(boolean skip) {
097                this.skip = skip;
098        }
099
100}