001 /*
002 * Sonar, open source software quality management tool.
003 * Copyright (C) 2008-2011 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * Sonar is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * Sonar is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public
017 * License along with Sonar; if not, write to the Free Software
018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
019 */
020 package org.sonar.server.mavendeployer;
021
022 import org.apache.commons.io.FileUtils;
023 import org.sonar.api.config.Settings;
024 import org.sonar.api.platform.Server;
025 import org.sonar.server.platform.DefaultServerFileSystem;
026 import org.sonar.server.platform.ServerSettings;
027
028 import java.io.File;
029 import java.io.IOException;
030
031 public class MavenRepository {
032
033 private final DefaultServerFileSystem installation;
034 private final String serverId;
035 private File rootDir;
036
037 public MavenRepository(Settings settings, DefaultServerFileSystem fileSystem, Server server) throws IOException {
038 this.installation = fileSystem;
039 this.serverId = server.getId();
040 initRootDir(settings);
041 }
042
043 /**
044 * for unit tests
045 */
046 protected MavenRepository(DefaultServerFileSystem installation, String serverId, File rootDir) {
047 this.installation = installation;
048 this.serverId = serverId;
049 this.rootDir = rootDir;
050 }
051
052 public void start() {
053 try {
054 Artifact maven2Plugin = Mojo.createMaven2Plugin(serverId, installation.getMaven2Plugin());
055 maven2Plugin.deployTo(rootDir);
056
057 } catch (Exception e) {
058 throw new IllegalStateException("Fail to deploy Maven 2 plugin to: " + rootDir, e);
059 }
060 }
061
062
063 private void initRootDir(Settings settings) throws IOException {
064 this.rootDir = new File(settings.getString(ServerSettings.DEPLOY_DIR), "maven");
065 File orgDir = new File(rootDir, "/org/");
066 if (orgDir.exists()) {
067 FileUtils.forceDelete(orgDir);
068 }
069 }
070 }