Skip to content

Commit

Permalink
SONAR-6370 remove concept of core plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Brandhof committed Jun 5, 2015
1 parent 7329c0c commit e91748e
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 158 deletions.
Expand Up @@ -135,10 +135,6 @@ public File getBundledPluginsDir() {
return new File(getHomeDir(), "lib/bundled-plugins"); return new File(getHomeDir(), "lib/bundled-plugins");
} }


public File getCorePluginsDir() {
return new File(getHomeDir(), "lib/core-plugins");
}

public File getDeprecatedPluginsDir() { public File getDeprecatedPluginsDir() {
return new File(getHomeDir(), "extensions/deprecated"); return new File(getHomeDir(), "extensions/deprecated");
} }
Expand Down
Expand Up @@ -20,16 +20,11 @@


package org.sonar.server.platform.monitoring; package org.sonar.server.platform.monitoring;


import com.google.common.base.Predicate; import java.util.LinkedHashMap;
import com.google.common.collect.Iterables;
import org.sonar.core.platform.PluginInfo; import org.sonar.core.platform.PluginInfo;
import org.sonar.core.platform.PluginRepository; import org.sonar.core.platform.PluginRepository;
import org.sonar.updatecenter.common.Version; import org.sonar.updatecenter.common.Version;


import javax.annotation.Nonnull;

import java.util.LinkedHashMap;

/** /**
* Installed plugins (excluding core plugins) * Installed plugins (excluding core plugins)
*/ */
Expand All @@ -48,7 +43,7 @@ public String name() {
@Override @Override
public LinkedHashMap<String, Object> attributes() { public LinkedHashMap<String, Object> attributes() {
LinkedHashMap<String, Object> attributes = new LinkedHashMap<>(); LinkedHashMap<String, Object> attributes = new LinkedHashMap<>();
for (PluginInfo plugin : plugins()) { for (PluginInfo plugin : repository.getPluginInfos()) {
LinkedHashMap<String, Object> pluginAttributes = new LinkedHashMap<>(); LinkedHashMap<String, Object> pluginAttributes = new LinkedHashMap<>();
pluginAttributes.put("Name", plugin.getName()); pluginAttributes.put("Name", plugin.getName());
Version version = plugin.getVersion(); Version version = plugin.getVersion();
Expand All @@ -59,13 +54,4 @@ public LinkedHashMap<String, Object> attributes() {
} }
return attributes; return attributes;
} }

private Iterable<PluginInfo> plugins() {
return Iterables.filter(repository.getPluginInfos(), new Predicate<PluginInfo>() {
@Override
public boolean apply(@Nonnull PluginInfo info) {
return !info.isCore();
}
});
}
} }
Expand Up @@ -48,9 +48,7 @@ public static PluginReferential getInstalledPluginReferential(Collection<PluginI
private static List<PluginManifest> getPluginManifestList(Collection<PluginInfo> metadata) { private static List<PluginManifest> getPluginManifestList(Collection<PluginInfo> metadata) {
List<PluginManifest> pluginManifestList = newArrayList(); List<PluginManifest> pluginManifestList = newArrayList();
for (PluginInfo plugin : metadata) { for (PluginInfo plugin : metadata) {
if (!plugin.isCore()) { pluginManifestList.add(toPluginManifest(plugin));
pluginManifestList.add(toPluginManifest(plugin));
}
} }
return pluginManifestList; return pluginManifestList;
} }
Expand Down
Expand Up @@ -25,7 +25,16 @@
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Ordering; import com.google.common.collect.Ordering;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nonnull;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.picocontainer.Startable; import org.picocontainer.Startable;
import org.sonar.api.Plugin; import org.sonar.api.Plugin;
Expand All @@ -38,17 +47,6 @@
import org.sonar.core.platform.PluginLoader; import org.sonar.core.platform.PluginLoader;
import org.sonar.core.platform.PluginRepository; import org.sonar.core.platform.PluginRepository;
import org.sonar.server.platform.DefaultServerFileSystem; import org.sonar.server.platform.DefaultServerFileSystem;

import javax.annotation.Nonnull;

import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.sonar.updatecenter.common.Version; import org.sonar.updatecenter.common.Version;


import static com.google.common.collect.Iterables.transform; import static com.google.common.collect.Iterables.transform;
Expand All @@ -73,7 +71,7 @@
public class ServerPluginRepository implements PluginRepository, Startable { public class ServerPluginRepository implements PluginRepository, Startable {


private static final Logger LOG = Loggers.get(ServerPluginRepository.class); private static final Logger LOG = Loggers.get(ServerPluginRepository.class);
private static final String[] JAR_FILE_EXTENSIONS = new String[]{"jar"}; private static final String[] JAR_FILE_EXTENSIONS = new String[] {"jar"};
private static final Set<String> DEFAULT_BLACKLISTED_PLUGINS = ImmutableSet.of("scmactivity", "issuesreport"); private static final Set<String> DEFAULT_BLACKLISTED_PLUGINS = ImmutableSet.of("scmactivity", "issuesreport");
private static final Joiner SLASH_JOINER = Joiner.on(" / ").skipNulls(); private static final Joiner SLASH_JOINER = Joiner.on(" / ").skipNulls();


Expand Down Expand Up @@ -105,7 +103,6 @@ public void start() {
loadPreInstalledPlugins(); loadPreInstalledPlugins();
copyBundledPlugins(); copyBundledPlugins();
moveDownloadedPlugins(); moveDownloadedPlugins();
loadCorePlugins();
unloadIncompatiblePlugins(); unloadIncompatiblePlugins();
logInstalledPlugins(); logInstalledPlugins();
loadInstances(); loadInstances();
Expand Down Expand Up @@ -208,13 +205,6 @@ private void overrideAndRegisterPlugin(File sourceFile, boolean deleteSource) {
} }
} }


private void loadCorePlugins() {
for (File file : listJarFiles(fs.getCorePluginsDir())) {
PluginInfo info = PluginInfo.create(file).setCore(true);
registerPluginInfo(info);
}
}

/** /**
* Removes the plugins that are not compatible with current environment. * Removes the plugins that are not compatible with current environment.
*/ */
Expand Down Expand Up @@ -294,15 +284,13 @@ public void uninstall(String pluginKey) {


for (String uninstallKey : uninstallKeys) { for (String uninstallKey : uninstallKeys) {
PluginInfo info = pluginInfosByKeys.get(uninstallKey); PluginInfo info = pluginInfosByKeys.get(uninstallKey);
if (!info.isCore()) { try {
try { LOG.info("Uninstalling plugin {} [{}]", info.getName(), info.getKey());
LOG.info("Uninstalling plugin {} [{}]", info.getName(), info.getKey()); // we don't reuse info.getFile() just to be sure that file is located in from extensions/plugins
// we don't reuse info.getFile() just to be sure that file is located in from extensions/plugins File masterFile = new File(fs.getInstalledPluginsDir(), info.getNonNullJarFile().getName());
File masterFile = new File(fs.getInstalledPluginsDir(), info.getNonNullJarFile().getName()); moveFileToDirectory(masterFile, uninstalledPluginsDir(), true);
moveFileToDirectory(masterFile, uninstalledPluginsDir(), true); } catch (IOException e) {
} catch (IOException e) { throw new IllegalStateException(format("Fail to uninstall plugin %s [%s]", info.getName(), info.getKey()), e);
throw new IllegalStateException(format("Fail to uninstall plugin %s [%s]", info.getName(), info.getKey()), e);
}
} }
} }
} }
Expand Down
Expand Up @@ -34,6 +34,7 @@
import java.util.Collection; import java.util.Collection;
import java.util.SortedSet; import java.util.SortedSet;


import static com.google.common.collect.ImmutableSortedSet.copyOf;
import static com.google.common.collect.Iterables.filter; import static com.google.common.collect.Iterables.filter;
import static org.sonar.server.plugins.ws.PluginWSCommons.NAME_KEY_PLUGIN_METADATA_COMPARATOR; import static org.sonar.server.plugins.ws.PluginWSCommons.NAME_KEY_PLUGIN_METADATA_COMPARATOR;


Expand Down Expand Up @@ -76,10 +77,7 @@ public void handle(Request request, Response response) throws Exception {
} }


private SortedSet<PluginInfo> retrieveAndSortPluginMetadata() { private SortedSet<PluginInfo> retrieveAndSortPluginMetadata() {
return ImmutableSortedSet.copyOf( return copyOf(NAME_KEY_PLUGIN_METADATA_COMPARATOR, pluginRepository.getPluginInfos());
NAME_KEY_PLUGIN_METADATA_COMPARATOR,
filter(pluginRepository.getPluginInfos(), NotCorePluginsPredicate.INSTANCE)
);
} }


private void writeMetadataList(JsonWriter jsonWriter, Collection<PluginInfo> pluginMetadatas) { private void writeMetadataList(JsonWriter jsonWriter, Collection<PluginInfo> pluginMetadatas) {
Expand All @@ -90,13 +88,4 @@ private void writeMetadataList(JsonWriter jsonWriter, Collection<PluginInfo> plu
} }
jsonWriter.endArray(); jsonWriter.endArray();
} }

private enum NotCorePluginsPredicate implements Predicate<PluginInfo> {
INSTANCE;

@Override
public boolean apply(@Nullable PluginInfo input) {
return input != null && !input.isCore();
}
}
} }
Expand Up @@ -38,12 +38,4 @@ public void should_convert_info_to_plugin_referential() {
assertThat(pluginReferential.getPlugins().get(0).getKey()).isEqualTo("foo"); assertThat(pluginReferential.getPlugins().get(0).getKey()).isEqualTo("foo");
} }


@Test
public void should_not_add_core_plugin() {
PluginInfo info = new PluginInfo("foo").setCore(true);

PluginReferential pluginReferential = PluginReferentialMetadataConverter.getInstalledPluginReferential(newArrayList(info));
assertThat(pluginReferential).isNotNull();
assertThat(pluginReferential.getPlugins()).hasSize(0);
}
} }
Expand Up @@ -63,7 +63,6 @@ public class ServerPluginRepositoryTest {
@Before @Before
public void setUp() throws IOException { public void setUp() throws IOException {
when(fs.getBundledPluginsDir()).thenReturn(temp.newFolder()); when(fs.getBundledPluginsDir()).thenReturn(temp.newFolder());
when(fs.getCorePluginsDir()).thenReturn(temp.newFolder());
when(fs.getDeployedPluginsDir()).thenReturn(temp.newFolder()); when(fs.getDeployedPluginsDir()).thenReturn(temp.newFolder());
when(fs.getDownloadedPluginsDir()).thenReturn(temp.newFolder()); when(fs.getDownloadedPluginsDir()).thenReturn(temp.newFolder());
when(fs.getHomeDir()).thenReturn(temp.newFolder()); when(fs.getHomeDir()).thenReturn(temp.newFolder());
Expand All @@ -78,18 +77,17 @@ public void tearDown() {
} }


/** /**
* The first server startup (fresh db) installs bundled plugins and instantiates bundled + core plugins. * The first server startup (fresh db) installs bundled plugins and instantiates bundled plugins.
*/ */
@Test @Test
public void first_startup_installs_bundled_plugins() throws Exception { public void first_startup_installs_bundled_plugins() throws Exception {
copyTestPluginTo("test-base-plugin", fs.getBundledPluginsDir()); copyTestPluginTo("test-base-plugin", fs.getBundledPluginsDir());
copyTestPluginTo("test-core-plugin", fs.getCorePluginsDir());
when(upgradeStatus.isFreshInstall()).thenReturn(true); when(upgradeStatus.isFreshInstall()).thenReturn(true);


underTest.start(); underTest.start();


// both plugins are installed // both plugins are installed
assertThat(underTest.getPluginInfosByKeys()).containsOnlyKeys("core", "testbase"); assertThat(underTest.getPluginInfosByKeys()).containsOnlyKeys("testbase");
} }


@Test @Test
Expand All @@ -103,20 +101,14 @@ public void bundled_plugins_are_not_installed_if_not_fresh_server() throws Excep
} }


@Test @Test
public void standard_startup_loads_core_and_installed_plugins() throws Exception { public void standard_startup_loads_installed_plugins() throws Exception {
copyTestPluginTo("test-base-plugin", fs.getInstalledPluginsDir()); copyTestPluginTo("test-base-plugin", fs.getInstalledPluginsDir());
copyTestPluginTo("test-core-plugin", fs.getCorePluginsDir());


underTest.start(); underTest.start();


// both plugins are installed assertThat(underTest.getPluginInfosByKeys()).containsOnlyKeys("testbase");
assertThat(underTest.getPluginInfosByKeys()).containsOnlyKeys("core", "testbase");
} }


/**
* That sounds impossible, there are still core plugins for now, but it's still valuable
* to test sensibility to null values.
*/
@Test @Test
public void no_plugins_at_all_on_startup() { public void no_plugins_at_all_on_startup() {
underTest.start(); underTest.start();
Expand Down
Expand Up @@ -19,6 +19,7 @@
*/ */
package org.sonar.server.plugins.ws; package org.sonar.server.plugins.ws;


import java.io.File;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;
Expand All @@ -29,8 +30,6 @@
import org.sonar.server.ws.WsTester; import org.sonar.server.ws.WsTester;
import org.sonar.updatecenter.common.Version; import org.sonar.updatecenter.common.Version;


import java.io.File;

import static com.google.common.collect.ImmutableList.of; import static com.google.common.collect.ImmutableList.of;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -77,20 +76,11 @@ public void empty_array_is_returned_when_there_is_not_plugin_installed() throws
assertJson(response.outputAsString()).setStrictArrayOrder(true).isSimilarTo(JSON_EMPTY_PLUGIN_LIST); assertJson(response.outputAsString()).setStrictArrayOrder(true).isSimilarTo(JSON_EMPTY_PLUGIN_LIST);
} }


@Test
public void core_plugin_are_not_returned() throws Exception {
when(pluginRepository.getPluginInfos()).thenReturn(of(corePlugin("core1", "1.0")));

underTest.handle(request, response);

assertJson(response.outputAsString()).setStrictArrayOrder(true).isSimilarTo(JSON_EMPTY_PLUGIN_LIST);
}

@Test @Test
public void empty_fields_are_not_serialized_to_json() throws Exception { public void empty_fields_are_not_serialized_to_json() throws Exception {
when(pluginRepository.getPluginInfos()).thenReturn( when(pluginRepository.getPluginInfos()).thenReturn(
of( of(
new PluginInfo("").setName("").setCore(false) new PluginInfo("").setName("")
) )
); );


Expand All @@ -105,7 +95,6 @@ public void verify_properties_displayed_in_json_per_plugin() throws Exception {
when(pluginRepository.getPluginInfos()).thenReturn(of( when(pluginRepository.getPluginInfos()).thenReturn(of(
new PluginInfo("plugKey") new PluginInfo("plugKey")
.setName("plugName") .setName("plugName")
.setCore(false)
.setDescription("desc_it") .setDescription("desc_it")
.setVersion(Version.create("1.0")) .setVersion(Version.create("1.0"))
.setLicense("license_hey") .setLicense("license_hey")
Expand Down Expand Up @@ -189,11 +178,7 @@ public void only_one_plugin_can_have_a_specific_name_and_key() throws Exception
assertThat(response.outputAsString()).containsOnlyOnce("name2"); assertThat(response.outputAsString()).containsOnlyOnce("name2");
} }


private PluginInfo corePlugin(String key, String version) {
return new PluginInfo(key).setName(key).setCore(true).setVersion(Version.create(version));
}

private PluginInfo plugin(String key, String name) { private PluginInfo plugin(String key, String name) {
return new PluginInfo(key).setName(name).setCore(false).setVersion(Version.create("1.0")); return new PluginInfo(key).setName(name).setVersion(Version.create("1.0"));
} }
} }
8 changes: 0 additions & 8 deletions sonar-application/assembly.xml
Expand Up @@ -78,14 +78,6 @@
<scope>provided</scope> <scope>provided</scope>
</dependencySet> </dependencySet>
<!-- Plugins --> <!-- Plugins -->
<dependencySet>
<outputDirectory>lib/core-plugins</outputDirectory>
<useTransitiveDependencies>false</useTransitiveDependencies>
<includes>
<include>org.codehaus.sonar.plugins:*</include>
</includes>
<scope>provided</scope>
</dependencySet>
<dependencySet> <dependencySet>
<outputDirectory>lib/bundled-plugins</outputDirectory> <outputDirectory>lib/bundled-plugins</outputDirectory>
<useTransitiveDependencies>false</useTransitiveDependencies> <useTransitiveDependencies>false</useTransitiveDependencies>
Expand Down
Expand Up @@ -51,7 +51,7 @@ public class BatchPluginInstallerTest {
public void listRemotePlugins() { public void listRemotePlugins() {


ServerClient server = mock(ServerClient.class); ServerClient server = mock(ServerClient.class);
when(server.request("/deploy/plugins/index.txt")).thenReturn("checkstyle,false\nsqale,false"); when(server.request("/deploy/plugins/index.txt")).thenReturn("checkstyle\nsqale");
BatchPluginInstaller installer = new BatchPluginInstaller(server, fileCache, pluginPredicate); BatchPluginInstaller installer = new BatchPluginInstaller(server, fileCache, pluginPredicate);


List<RemotePlugin> remotePlugins = installer.listRemotePlugins(); List<RemotePlugin> remotePlugins = installer.listRemotePlugins();
Expand All @@ -66,7 +66,7 @@ public void should_download_plugin() throws Exception {
ServerClient server = mock(ServerClient.class); ServerClient server = mock(ServerClient.class);
BatchPluginInstaller installer = new BatchPluginInstaller(server, fileCache, pluginPredicate); BatchPluginInstaller installer = new BatchPluginInstaller(server, fileCache, pluginPredicate);


RemotePlugin remote = new RemotePlugin("checkstyle", true).setFile("checkstyle-plugin.jar", "fakemd5_1"); RemotePlugin remote = new RemotePlugin("checkstyle").setFile("checkstyle-plugin.jar", "fakemd5_1");
File file = installer.download(remote); File file = installer.download(remote);


assertThat(file).isEqualTo(pluginJar); assertThat(file).isEqualTo(pluginJar);
Expand Down
11 changes: 0 additions & 11 deletions sonar-core/src/main/java/org/sonar/core/platform/PluginInfo.java
Expand Up @@ -133,8 +133,6 @@ public String toString() {
@CheckForNull @CheckForNull
private String basePlugin; private String basePlugin;


private boolean core = false;

@CheckForNull @CheckForNull
private String implementationBuild; private String implementationBuild;


Expand Down Expand Up @@ -223,10 +221,6 @@ public String getBasePlugin() {
return basePlugin; return basePlugin;
} }


public boolean isCore() {
return core;
}

@CheckForNull @CheckForNull
public String getImplementationBuild() { public String getImplementationBuild() {
return implementationBuild; return implementationBuild;
Expand Down Expand Up @@ -305,11 +299,6 @@ public PluginInfo setBasePlugin(@Nullable String s) {
return this; return this;
} }


public PluginInfo setCore(boolean b) {
this.core = b;
return this;
}

public PluginInfo setImplementationBuild(@Nullable String implementationBuild) { public PluginInfo setImplementationBuild(@Nullable String implementationBuild) {
this.implementationBuild = implementationBuild; this.implementationBuild = implementationBuild;
return this; return this;
Expand Down

0 comments on commit e91748e

Please sign in to comment.