@@ -134,11 +134,6 @@ public class CePluginJarExploderTest { | |||
throw new UnsupportedOperationException(); | |||
} | |||
@Override | |||
public File getPluginIndex() { | |||
throw new UnsupportedOperationException(); | |||
} | |||
@Override | |||
public File getUninstalledPluginsDir() { | |||
throw new UnsupportedOperationException(); |
@@ -64,14 +64,6 @@ public interface ServerFileSystem { | |||
*/ | |||
File getInstalledBundledPluginsDir(); | |||
/** | |||
* The file listing all the installed plugins. Used by scanner only. | |||
* @return an existing file | |||
* @deprecated see {@link org.sonar.server.startup.GeneratePluginIndex} | |||
*/ | |||
@Deprecated | |||
File getPluginIndex(); | |||
/** | |||
* Directory where plugins to be uninstalled are moved to. | |||
* @return a directory which may or not exist |
@@ -22,10 +22,10 @@ package org.sonar.server.platform; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import org.apache.commons.io.FileUtils; | |||
import org.sonar.api.Startable; | |||
import org.sonar.api.config.Configuration; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.sonar.api.Startable; | |||
import org.sonar.api.config.Configuration; | |||
import static org.sonar.process.ProcessProperties.Property.PATH_DATA; | |||
import static org.sonar.process.ProcessProperties.Property.PATH_HOME; | |||
@@ -88,11 +88,6 @@ public class ServerFileSystemImpl implements ServerFileSystem, org.sonar.api.pla | |||
return new File(getHomeDir(), "lib/extensions"); | |||
} | |||
@Override | |||
public File getPluginIndex() { | |||
return new File(deployDir, "plugins/index.txt"); | |||
} | |||
@Override | |||
public File getUninstalledPluginsDir() { | |||
return uninstallDir; |
@@ -76,8 +76,6 @@ public class ServerFileSystemImplTest { | |||
assertThat(underTest.getInstalledBundledPluginsDir()).isEqualTo(new File(homeDir.getAbsolutePath() + "/lib/extensions")); | |||
assertThat(underTest.getInstalledExternalPluginsDir()).isEqualTo(new File(homeDir.getAbsolutePath() + "/extensions/plugins")); | |||
assertThat(underTest.getPluginIndex()).isEqualTo(new File(dataDir.getAbsolutePath() + "/web/deploy/plugins/index.txt")); | |||
assertThat(underTest.getUninstalledPluginsDir()).isEqualTo(new File(tempDir.getAbsolutePath() + "/uninstalled-plugins")); | |||
} | |||
@@ -1,96 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2024 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.server.startup; | |||
import java.io.File; | |||
import java.io.FileOutputStream; | |||
import java.io.IOException; | |||
import java.io.OutputStreamWriter; | |||
import java.io.Writer; | |||
import java.nio.charset.StandardCharsets; | |||
import org.apache.commons.io.FileUtils; | |||
import org.apache.commons.lang3.CharUtils; | |||
import org.sonar.api.Startable; | |||
import org.sonar.api.server.ServerSide; | |||
import org.sonar.api.utils.log.Logger; | |||
import org.sonar.api.utils.log.Loggers; | |||
import org.sonar.api.utils.log.Profiler; | |||
import org.sonar.server.platform.ServerFileSystem; | |||
import org.sonar.server.plugins.ServerPlugin; | |||
import org.sonar.server.plugins.ServerPluginRepository; | |||
/** | |||
* The file deploy/plugins/index.txt is required for old versions of SonarLint. | |||
* They don't use the web service api/plugins/installed to get the list | |||
* of installed plugins. | |||
* https://jira.sonarsource.com/browse/SLCORE-146 | |||
*/ | |||
@ServerSide | |||
public final class GeneratePluginIndex implements Startable { | |||
private static final Logger LOG = Loggers.get(GeneratePluginIndex.class); | |||
private final ServerFileSystem serverFs; | |||
private final ServerPluginRepository serverPluginRepository; | |||
public GeneratePluginIndex(ServerFileSystem serverFs, ServerPluginRepository serverPluginRepository) { | |||
this.serverFs = serverFs; | |||
this.serverPluginRepository = serverPluginRepository; | |||
} | |||
@Override | |||
public void start() { | |||
Profiler profiler = Profiler.create(LOG).startInfo("Generate scanner plugin index"); | |||
writeIndex(serverFs.getPluginIndex()); | |||
profiler.stopDebug(); | |||
} | |||
@Override | |||
public void stop() { | |||
// Nothing to do | |||
} | |||
private void writeIndex(File indexFile) { | |||
try { | |||
FileUtils.forceMkdir(indexFile.getParentFile()); | |||
try (Writer writer = new OutputStreamWriter(new FileOutputStream(indexFile), StandardCharsets.UTF_8)) { | |||
for (ServerPlugin plugin : serverPluginRepository.getPlugins()) { | |||
writer.append(toRow(plugin)); | |||
writer.append(CharUtils.LF); | |||
} | |||
writer.flush(); | |||
} | |||
} catch (IOException e) { | |||
throw new IllegalStateException("Unable to generate plugin index at " + indexFile, e); | |||
} | |||
} | |||
private static String toRow(ServerPlugin file) { | |||
return new StringBuilder().append(file.getPluginInfo().getKey()) | |||
.append(",") | |||
.append(file.getPluginInfo().isSonarLintSupported()) | |||
.append(",") | |||
.append(file.getJar().getFile().getName()) | |||
.append("|") | |||
.append(file.getJar().getMd5()) | |||
.toString(); | |||
} | |||
} |
@@ -1,91 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2024 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.server.startup; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import java.util.List; | |||
import org.apache.commons.io.FileUtils; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.TemporaryFolder; | |||
import org.sonar.core.platform.PluginInfo; | |||
import org.sonar.server.platform.ServerFileSystem; | |||
import org.sonar.server.plugins.PluginFilesAndMd5.FileAndMd5; | |||
import org.sonar.server.plugins.ServerPlugin; | |||
import org.sonar.server.plugins.ServerPluginRepository; | |||
import static java.util.Arrays.asList; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.when; | |||
import static org.sonar.core.plugin.PluginType.BUNDLED; | |||
public class GeneratePluginIndexTest { | |||
@Rule | |||
public TemporaryFolder temp = new TemporaryFolder(); | |||
private ServerFileSystem serverFileSystem = mock(ServerFileSystem.class); | |||
private ServerPluginRepository serverPluginRepository = mock(ServerPluginRepository.class); | |||
private File index; | |||
@Before | |||
public void createIndexFile() throws IOException { | |||
index = temp.newFile(); | |||
when(serverFileSystem.getPluginIndex()).thenReturn(index); | |||
} | |||
@Test | |||
public void shouldWriteIndex() throws IOException { | |||
ServerPlugin javaPlugin = newInstalledPlugin("java", true); | |||
ServerPlugin gitPlugin = newInstalledPlugin("scmgit", false); | |||
when(serverPluginRepository.getPlugins()).thenReturn(asList(javaPlugin, gitPlugin)); | |||
GeneratePluginIndex underTest = new GeneratePluginIndex(serverFileSystem, serverPluginRepository); | |||
underTest.start(); | |||
List<String> lines = FileUtils.readLines(index); | |||
assertThat(lines).containsExactly( | |||
"java,true," + javaPlugin.getJar().getFile().getName() + "|" + javaPlugin.getJar().getMd5(), | |||
"scmgit,false," + gitPlugin.getJar().getFile().getName() + "|" + gitPlugin.getJar().getMd5()); | |||
underTest.stop(); | |||
} | |||
@Test | |||
public void shouldThrowWhenUnableToWrite() throws IOException { | |||
File wrongParent = temp.newFile(); | |||
wrongParent.createNewFile(); | |||
File wrongIndex = new File(wrongParent, "index.txt"); | |||
when(serverFileSystem.getPluginIndex()).thenReturn(wrongIndex); | |||
assertThatThrownBy(() -> new GeneratePluginIndex(serverFileSystem, serverPluginRepository).start()) | |||
.isInstanceOf(IllegalStateException.class); | |||
} | |||
private ServerPlugin newInstalledPlugin(String key, boolean supportSonarLint) throws IOException { | |||
FileAndMd5 jar = new FileAndMd5(temp.newFile()); | |||
PluginInfo pluginInfo = new PluginInfo(key).setJarFile(jar.getFile()).setSonarLintSupported(supportSonarLint); | |||
return new ServerPlugin(pluginInfo, BUNDLED, null, jar, null); | |||
} | |||
} |
@@ -39,14 +39,13 @@ import org.sonar.server.qualityprofile.builtin.BuiltInQualityProfilesUpdateListe | |||
import org.sonar.server.rule.AdvancedRuleDescriptionSectionsGenerator; | |||
import org.sonar.server.rule.LegacyHotspotRuleDescriptionSectionsGenerator; | |||
import org.sonar.server.rule.LegacyIssueRuleDescriptionSectionsGenerator; | |||
import org.sonar.server.rule.RuleDescriptionSectionsGeneratorResolver; | |||
import org.sonar.server.rule.WebServerRuleFinder; | |||
import org.sonar.server.rule.registration.NewRuleCreator; | |||
import org.sonar.server.rule.registration.QualityProfileChangesUpdater; | |||
import org.sonar.server.rule.registration.RulesKeyVerifier; | |||
import org.sonar.server.rule.registration.RulesRegistrant; | |||
import org.sonar.server.rule.RuleDescriptionSectionsGeneratorResolver; | |||
import org.sonar.server.rule.WebServerRuleFinder; | |||
import org.sonar.server.rule.registration.StartupRuleUpdater; | |||
import org.sonar.server.startup.GeneratePluginIndex; | |||
import org.sonar.server.startup.RegisterMetrics; | |||
import org.sonar.server.startup.RegisterPermissionTemplates; | |||
import org.sonar.server.startup.RegisterPlugins; | |||
@@ -64,8 +63,7 @@ public class PlatformLevelStartup extends PlatformLevel { | |||
@Override | |||
protected void configureLevel() { | |||
add(GeneratePluginIndex.class, | |||
ServerLifecycleNotifier.class); | |||
add(ServerLifecycleNotifier.class); | |||
addIfStartupLeader( | |||
IndexerStartupTask.class); |