if (metadata.getPathsToInternalDeps().length > 0) {
// needs to unzip the jar
- ZipUtils.unzip(pluginFile, pluginBasedir, new ZipUtils.ZipEntryFilter() {
- public boolean accept(ZipEntry entry) {
- return entry.getName().startsWith("META-INF/lib");
- }
- });
+ ZipUtils.unzip(pluginFile, pluginBasedir, new LibFilter());
for (String depPath : metadata.getPathsToInternalDeps()) {
File dependency = new File(pluginBasedir, depPath);
if (!dependency.isFile() || !dependency.exists()) {
}
}
+ private static class LibFilter implements ZipUtils.ZipEntryFilter {
+ public boolean accept(ZipEntry entry) {
+ return entry.getName().startsWith("META-INF/lib");
+ }
+ }
+
public DefaultPluginMetadata extractMetadata(File file, boolean isCore) {
try {
PluginManifest manifest = new PluginManifest(file);
metadata.setName(pluginInstance.getName());
} catch (Exception e) {
- throw new RuntimeException("The metadata main class can not be created. Plugin file=" + pluginFile.getName() + ", class=" + mainClass, e);
+ throw new IllegalStateException("The metadata main class can not be created. Plugin file=" + pluginFile.getName() + ", class=" + mainClass, e);
}
}
}
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
+import org.sonar.api.platform.PluginMetadata;
import org.sonar.api.platform.PluginRepository;
import org.sonar.api.platform.ServerFileSystem;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
+import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
assertThat(new File(appDir, "app/views/fake/index.html.erb").exists(), is(true));
}
+ @Test
+ public void deployRubyRailsApps_no_apps() throws Exception {
+ ServerFileSystem fileSystem = mock(ServerFileSystem.class);
+ File tempDir = this.temp.getRoot();
+ when(fileSystem.getTempDir()).thenReturn(tempDir);
+
+ PluginRepository pluginRepository = mock(PluginRepository.class);
+ when(pluginRepository.getMetadata()).thenReturn(Collections.<PluginMetadata>emptyList());
+ new ApplicationDeployer(fileSystem, pluginRepository).start();
+
+ File appDir = new File(tempDir, "ror");
+ assertThat(appDir.isDirectory(), is(true));
+ assertThat(appDir.exists(), is(true));
+ assertThat(FileUtils.listFiles(appDir, null, true).size(), is(0));
+ }
+
@Test
public void prepareRubyRailsRootDirectory() throws Exception {
ServerFileSystem fileSystem = mock(ServerFileSystem.class);
assertThat(dir.exists(), is(true));
assertThat(dir.getCanonicalPath(), is(new File(tempDir, "ror").getCanonicalPath()));
}
+
+ @Test
+ public void prepareRubyRailsRootDirectory_delete_existing_dir() throws Exception {
+ ServerFileSystem fileSystem = mock(ServerFileSystem.class);
+ File tempDir = this.temp.getRoot();
+ when(fileSystem.getTempDir()).thenReturn(tempDir);
+
+ File file = new File(tempDir, "ror/foo/bar.txt");
+ FileUtils.writeStringToFile(file, "foooo");
+
+ File dir = new ApplicationDeployer(fileSystem, mock(PluginRepository.class)).prepareRubyRailsRootDirectory();
+
+ assertThat(dir.isDirectory(), is(true));
+ assertThat(dir.exists(), is(true));
+ assertThat(dir.getCanonicalPath(), is(new File(tempDir, "ror").getCanonicalPath()));
+ assertThat(FileUtils.listFiles(new File(tempDir, "ror"), null, true).size(), is(0));
+ }
}