2 * Sonar, open source software quality management tool.
3 * Copyright (C) 2009 SonarSource SA
4 * mailto:contact AT sonarsource DOT com
6 * Sonar is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * Sonar is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Sonar; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
20 package org.sonar.updatecenter.server;
22 import org.apache.commons.io.FileUtils;
23 import org.apache.commons.lang.StringUtils;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
28 import java.io.IOException;
29 import java.util.Properties;
31 public class Configuration {
33 public static final String WORKING_DIR = "workingDir";
34 public static final String OUTPUT_FILE = "outputFile";
35 public static final String SOURCE_PATH = "path";
36 public static final String SOURCE_LOGIN = "login";
37 public static final String SOURCE_PASSWORD = "password";
39 private static Logger LOG = LoggerFactory.getLogger(Configuration.class);
40 private Properties props;
41 private File workingDir = null;
43 public Configuration(Properties props) {
48 LOG.info("-------------------------------");
49 LOG.info(WORKING_DIR + ": " + getWorkingDir().getPath());
50 LOG.info(OUTPUT_FILE + ": " + getOutputFile().getPath());
51 LOG.info(SOURCE_PATH + ": " + getSourcePath());
52 LOG.info(SOURCE_LOGIN + ": " + getSourceLogin());
53 LOG.info(SOURCE_PASSWORD + ": " + getSourcePassword());
54 LOG.info("-------------------------------");
57 public File getWorkingDir() {
58 if (workingDir == null) {
59 String path = props.getProperty(WORKING_DIR);
60 if (StringUtils.isBlank(path)) {
61 workingDir = new File(System.getProperty("user.home"), ".sonar-update-center");
63 workingDir = new File(path);
66 FileUtils.forceMkdir(workingDir);
68 } catch (IOException e) {
69 throw new RuntimeException("Fail to create the working directory: " + workingDir.getAbsolutePath(), e);
75 public File getOutputFile() {
76 String path = props.getProperty(OUTPUT_FILE);
77 if (StringUtils.isNotBlank(path)) {
78 return new File(path);
80 return new File(getWorkingDir(), "generated-sonar-updates.properties");
83 public String getSourcePath() {
84 return props.getProperty(SOURCE_PATH);
87 public String getSourceLogin() {
88 return props.getProperty(SOURCE_LOGIN);
91 public String getSourcePassword() {
92 return props.getProperty(SOURCE_PASSWORD);