aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src/main/java/org/sonar/batch/bootstrap
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2011-06-10 14:06:37 +0200
committersimonbrandhof <simon.brandhof@gmail.com>2011-06-10 14:06:37 +0200
commit23d30654116e9088b92cbbe8ed70fc71e5598854 (patch)
tree0cc65d0a54f11a98510b87ca57c3303b440f4f06 /sonar-batch/src/main/java/org/sonar/batch/bootstrap
parente9957c5d4049a2f8f39c83a6ff6a09e5fa333f7f (diff)
downloadsonarqube-23d30654116e9088b92cbbe8ed70fc71e5598854.tar.gz
sonarqube-23d30654116e9088b92cbbe8ed70fc71e5598854.zip
SONAR-2507 support deprecated directory /extensions/rules/
Diffstat (limited to 'sonar-batch/src/main/java/org/sonar/batch/bootstrap')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/ArtifactDownloader.java84
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java12
2 files changed, 27 insertions, 69 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ArtifactDownloader.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ArtifactDownloader.java
index b8ae7330848..946df51833e 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ArtifactDownloader.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ArtifactDownloader.java
@@ -29,6 +29,7 @@ import org.sonar.api.BatchComponent;
import org.sonar.api.utils.HttpDownloader;
import org.sonar.api.utils.SonarException;
import org.sonar.batch.ServerMetadata;
+import org.sonar.core.plugins.RemotePlugin;
import java.io.File;
import java.net.URI;
@@ -62,28 +63,36 @@ public class ArtifactDownloader implements BatchComponent {
}
}
- public File downloadPlugin(RemotePluginLocation remote) {
- File targetFile = new File(workingDirectories.getDir("plugins/" + remote.getPluginKey()), remote.getFilename());
- String url = baseUrl + "/deploy/plugins/" + remote.getRemotePath();
+ public List<File> downloadPlugin(RemotePlugin remote) {
try {
- FileUtils.forceMkdir(targetFile.getParentFile());
- LOG.info("Download plugin to " + targetFile);
- httpDownloader.download(new URI(url), targetFile);
- return targetFile;
+ File targetDir = workingDirectories.getDir("plugins/" + remote.getKey());
+ FileUtils.forceMkdir(targetDir);
+ LOG.info("Downloading plugin " + remote.getKey() + " into " + targetDir);
+
+ List<File> files = Lists.newArrayList();
+ for (String filename : remote.getFilenames()) {
+ String url = baseUrl + "/deploy/plugins/" + remote.getKey() + "/" + filename;
+ File toFile = new File(targetDir, filename);
+ httpDownloader.download(new URI(url), toFile);
+ files.add(toFile);
+ }
+
+
+ return files;
} catch (Exception e) {
- throw new SonarException("Fail to download extension: " + url, e);
+ throw new SonarException("Fail to download plugin: " + remote.getKey(), e);
}
}
- public List<RemotePluginLocation> downloadPluginIndex() {
+ public List<RemotePlugin> downloadPluginIndex() {
String url = baseUrl + "/deploy/plugins/index.txt";
try {
String indexContent = httpDownloader.downloadPlainText(new URI(url), "UTF-8");
String[] rows = StringUtils.split(indexContent, CharUtils.LF);
- List<RemotePluginLocation> remoteLocations = Lists.newArrayList();
+ List<RemotePlugin> remoteLocations = Lists.newArrayList();
for (String row : rows) {
- remoteLocations.add(RemotePluginLocation.createFromRow(row));
+ remoteLocations.add(RemotePlugin.unmarshal(row));
}
return remoteLocations;
@@ -92,57 +101,4 @@ public class ArtifactDownloader implements BatchComponent {
}
}
- public static final class RemotePluginLocation {
- private String pluginKey;
- private String remotePath;
- private boolean core;
-
- private RemotePluginLocation(String pluginKey, String remotePath, boolean core) {
- this.pluginKey = pluginKey;
- this.remotePath = remotePath;
- this.core = core;
- }
-
- static RemotePluginLocation create(String key) {
- return new RemotePluginLocation(key, null, false);
- }
-
- static RemotePluginLocation createFromRow(String row) {
- String[] fields = StringUtils.split(row, ",");
- return new RemotePluginLocation(fields[0], fields[1], Boolean.parseBoolean(fields[2]));
- }
-
- public String getPluginKey() {
- return pluginKey;
- }
-
- public String getRemotePath() {
- return remotePath;
- }
-
- public String getFilename() {
- return StringUtils.substringAfterLast(remotePath, "/");
- }
-
- public boolean isCore() {
- return core;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- RemotePluginLocation that = (RemotePluginLocation) o;
- return pluginKey.equals(that.pluginKey);
- }
-
- @Override
- public int hashCode() {
- return pluginKey.hashCode();
- }
- }
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java
index 2452983bd11..e8d698d2959 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java
@@ -34,6 +34,7 @@ import org.sonar.api.platform.PluginMetadata;
import org.sonar.api.platform.PluginRepository;
import org.sonar.core.plugins.PluginClassloaders;
import org.sonar.core.plugins.PluginFileExtractor;
+import org.sonar.core.plugins.RemotePlugin;
import java.io.File;
import java.util.*;
@@ -66,13 +67,14 @@ public class BatchPluginRepository implements PluginRepository {
doStart(artifactDownloader.downloadPluginIndex());
}
- void doStart(List<ArtifactDownloader.RemotePluginLocation> remoteLocations) {
+ void doStart(List<RemotePlugin> remotePlugins) {
PluginFileExtractor extractor = new PluginFileExtractor();
metadataByKey = Maps.newHashMap();
- for (ArtifactDownloader.RemotePluginLocation remoteLocation : remoteLocations) {
- if (isAccepted(remoteLocation.getPluginKey())) {
- File pluginFile = artifactDownloader.downloadPlugin(remoteLocation);
- PluginMetadata metadata = extractor.installInSameLocation(pluginFile, remoteLocation.isCore());
+ for (RemotePlugin remote : remotePlugins) {
+ if (isAccepted(remote.getKey())) {
+ List<File> pluginFiles = artifactDownloader.downloadPlugin(remote);
+ List<File> extensionFiles = pluginFiles.subList(1, pluginFiles.size());
+ PluginMetadata metadata = extractor.installInSameLocation(pluginFiles.get(0), remote.isCore(), extensionFiles);
if (StringUtils.isBlank(metadata.getBasePlugin()) || isAccepted(metadata.getBasePlugin())) {
// TODO log when excluding plugin
metadataByKey.put(metadata.getKey(), metadata);