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.lang.StringUtils;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25 import org.sonar.updatecenter.common.*;
28 import java.io.IOException;
29 import java.net.URISyntaxException;
31 public final class Server {
32 private static Logger LOG = LoggerFactory.getLogger(Server.class);
34 public void start() throws IOException, URISyntaxException {
35 Configuration conf = new Configuration(System.getProperties());
37 HttpDownloader downloader = new HttpDownloader(conf.getWorkingDir());
38 UpdateCenter center = buildFromPartialMetadata(conf, downloader);
39 downloadReleases(downloader, center);
40 generateMetadata(conf, center);
43 private UpdateCenter buildFromPartialMetadata(Configuration conf, HttpDownloader downloader) {
44 return new MetadataFile(conf, downloader).getUpdateCenter();
47 private void downloadReleases(HttpDownloader downloader, UpdateCenter center) throws IOException, URISyntaxException {
48 for (Plugin plugin : center.getPlugins()) {
49 LOG.info("Load plugin: " + plugin.getKey());
51 File masterJar = null;
52 for (Release release : plugin.getReleases()) {
53 if (StringUtils.isNotBlank(release.getDownloadUrl())) {
54 File jar = downloader.download(release.getDownloadUrl(), false);
55 if (jar!= null && jar.exists()) {
58 release.setDownloadUrl(null);
59 LOG.warn("Ignored because of wrong downloadUrl: plugin " + plugin.getKey() + ", version " + release.getVersion());
63 LOG.warn("Ignored because of missing downloadUrl: plugin " + plugin.getKey() + ", version " + release.getVersion());
67 // the last release is the master version for loading metadata included in manifest
68 if (masterJar != null) {
69 plugin.merge(new PluginManifest(masterJar));
74 private void generateMetadata(Configuration conf, UpdateCenter center) {
75 LOG.info("Generate output: " + conf.getOutputFile());
76 UpdateCenterSerializer.toProperties(center, conf.getOutputFile());
79 public static void main(String[] args) throws IOException, URISyntaxException {