예제 #1
0
  @VisibleForTesting
  static PluginInfo create(File jarFile, PluginManifest manifest) {
    PluginInfo info = new PluginInfo(manifest.getKey());

    info.setJarFile(jarFile);
    info.setName(manifest.getName());
    info.setMainClass(manifest.getMainClass());
    info.setVersion(Version.create(manifest.getVersion()));

    // optional fields
    info.setDescription(manifest.getDescription());
    info.setLicense(manifest.getLicense());
    info.setOrganizationName(manifest.getOrganization());
    info.setOrganizationUrl(manifest.getOrganizationUrl());
    String minSqVersion = manifest.getSonarVersion();
    if (minSqVersion != null) {
      info.setMinimalSqVersion(Version.create(minSqVersion));
    }
    info.setHomepageUrl(manifest.getHomepage());
    info.setIssueTrackerUrl(manifest.getIssueTrackerUrl());
    info.setUseChildFirstClassLoader(manifest.isUseChildFirstClassLoader());
    info.setBasePlugin(manifest.getBasePlugin());
    info.setImplementationBuild(manifest.getImplementationBuild());
    String[] requiredPlugins = manifest.getRequirePlugins();
    if (requiredPlugins != null) {
      for (String s : requiredPlugins) {
        info.addRequiredPlugin(RequiredPlugin.parse(s));
      }
    }
    return info;
  }
예제 #2
0
  /**
   * Find out if this plugin is compatible with a given version of Sonar. The version of sonar must
   * be greater than or equal to the minimal version needed by the plugin.
   *
   * @param sonarVersion
   * @return <code>true</code> if the plugin is compatible
   */
  public boolean isCompatibleWith(String sonarVersion) {
    if (null == this.sonarVersion) {
      return true; // Plugins without sonar version are so old, they are compatible with a version
                   // containing this code
    }

    Version minimumVersion = Version.createRelease(this.sonarVersion);
    Version actualVersion = Version.createRelease(sonarVersion);
    return actualVersion.compareTo(minimumVersion) >= 0;
  }
예제 #3
0
  /**
   * Find out if this plugin is compatible with a given version of SonarQube. The version of SQ must
   * be greater than or equal to the minimal version needed by the plugin.
   */
  public boolean isCompatibleWith(String sqVersion) {
    if (null == this.minimalSqVersion) {
      // no constraint defined on the plugin
      return true;
    }

    Version effectiveMin = Version.create(minimalSqVersion.getName()).removeQualifier();
    Version actualVersion = Version.create(sqVersion).removeQualifier();
    return actualVersion.compareTo(effectiveMin) >= 0;
  }
public class PluginUpdateAggregateBuilderTest {

  private static final Plugin PLUGIN_1 = new Plugin("key1");
  private static final Plugin PLUGIN_2 = new Plugin("key2");
  private static final Version SOME_VERSION = Version.create("1.0");
  private static final PluginUpdate.Status SOME_STATUS = PluginUpdate.Status.COMPATIBLE;

  @Test(expected = NullPointerException.class)
  public void plugin_can_not_be_null_and_builderFor_enforces_it_with_NPE() {
    PluginUpdateAggregateBuilder.builderFor(null);
  }

  @Test(expected = IllegalArgumentException.class)
  public void add_throws_IAE_when_plugin_is_not_equal_to_the_one_of_the_builder() {
    PluginUpdateAggregateBuilder builder = PluginUpdateAggregateBuilder.builderFor(PLUGIN_1);

    builder.add(createPluginUpdate(PLUGIN_2));
  }

  @Test
  public void add_uses_equals_which_takes_only_key_into_account() {
    PluginUpdateAggregateBuilder builder = PluginUpdateAggregateBuilder.builderFor(PLUGIN_1);

    builder.add(createPluginUpdate(new Plugin(PLUGIN_1.getKey())));
  }

  private static PluginUpdate createPluginUpdate(Plugin plugin) {
    return PluginUpdate.createWithStatus(new Release(plugin, SOME_VERSION), SOME_STATUS);
  }
}
예제 #5
0
 public static RequiredPlugin parse(String s) {
   if (!PARSER.matcher(s).matches()) {
     throw new IllegalArgumentException("Manifest field does not have correct format: " + s);
   }
   String[] fields = StringUtils.split(s, ':');
   return new RequiredPlugin(fields[0], Version.create(fields[1]).removeQualifier());
 }
예제 #6
0
 @Override
 public String toString() {
   return new StringBuilder()
       .append(key)
       .append(':')
       .append(minimalVersion.getName())
       .toString();
 }
예제 #7
0
 public PluginInfo gitPluginInfo() {
   return new PluginInfo("scmgit")
       .setName("Git")
       .setDescription("Git SCM Provider.")
       .setVersion(Version.create("1.0"))
       .setLicense("GNU LGPL 3")
       .setOrganizationName("SonarSource")
       .setOrganizationUrl("http://www.sonarsource.com")
       .setHomepageUrl("http://redirect.sonarsource.com/plugins/scmgit.html")
       .setIssueTrackerUrl("http://jira.sonarsource.com/browse/SONARSCGIT")
       .setImplementationBuild("9ce9d330c313c296fab051317cc5ad4b26319e07");
 }
예제 #8
0
 @Override
 public boolean equals(@Nullable Object o) {
   if (this == o) {
     return true;
   }
   if (o == null || getClass() != o.getClass()) {
     return false;
   }
   PluginInfo info = (PluginInfo) o;
   if (!key.equals(info.key)) {
     return false;
   }
   return !(version != null ? !version.equals(info.version) : info.version != null);
 }
예제 #9
0
  @Test
  public void if_plugin_has_an_update_download_is_triggered_with_latest_version_from_updatecenter()
      throws Exception {
    Version version = Version.create("1.0");
    when(updateCenter.findPluginUpdates())
        .thenReturn(
            ImmutableList.of(
                PluginUpdate.createWithStatus(
                    new Release(new Plugin(PLUGIN_KEY), version), Status.COMPATIBLE)));

    underTest.handle(validRequest, response);

    verify(pluginDownloader).download(PLUGIN_KEY, version);
    assertThat(response.outputAsString()).isEmpty();
  }
예제 #10
0
 public void downloadPlugin(String pluginKey, String pluginVersion) {
   getContainer()
       .getComponent(PluginDownloader.class)
       .download(pluginKey, Version.create(pluginVersion));
 }
예제 #11
0
 @Override
 public int hashCode() {
   int result = key.hashCode();
   result = 31 * result + (version != null ? version.hashCode() : 0);
   return result;
 }