aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src/main/webapp/WEB-INF/app/controllers/updatecenter_controller.rb
blob: be17f0b9b4c63ead5fcf3b74a12116f669e5a71a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#
# Sonar, entreprise quality control tool.
# Copyright (C) 2009 SonarSource SA
# mailto:contact AT sonarsource DOT com
#
# Sonar 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.
#
# Sonar 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 Sonar; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
#
class UpdatecenterController < ApplicationController

  SECTION=Navigation::SECTION_CONFIGURATION
  before_filter :admin_required
  before_filter :updatecenter_activated

  verify :method => :post, :only => [:cancel, :install], :redirect_to => {:action => :index}

  def index
    @uninstalls=java_facade.getPluginUninstalls()
    @downloads=java_facade.getPluginDownloads()

    @user_plugins=Plugin.user_plugins
    @core_plugins=Plugin.core_plugins
  end

  def updates
    @uninstalls=java_facade.getPluginUninstalls()
    @downloads=java_facade.getPluginDownloads()

    @center=nil
    @sonar_updates=[]
    @updates_by_plugin={}
    @user_plugins={}
    @last_compatible={}

    Plugin.user_plugins.each do |plugin|
      @user_plugins[plugin.plugin_key]=plugin.version
    end

    finder=load_update_finder()
    if finder
      @center=finder.getCenter()
      @sonar_updates=finder.findSonarUpdates()

      @finder.findPluginUpdates().each do |update|
        plugin=update.getPlugin()
        @updates_by_plugin[plugin]||=[]
        @updates_by_plugin[plugin]<<update
        if update.isCompatible
          @last_compatible[plugin.getKey()]=update.getRelease().getVersion()
        end
      end
    end
  end

  def available
    @uninstalls=java_facade.getPluginUninstalls()
    @downloads=java_facade.getPluginDownloads()

    @center=nil
    @updates_by_category={}

    finder=load_update_finder()
    if finder
      @center=finder.getCenter()
      finder.findAvailablePlugins().each do |update|
        category=update.getPlugin().getCategory()||''
        @updates_by_category[category]||=[]
        @updates_by_category[category]<<update
      end
    end
  end

  def cancel_downloads
    java_facade.cancelPluginDownloads()
    flash[:notice]="Plugin downloads are canceled."
    redirect_to :action => 'index'
  end

  def install
    key=params[:key]
    version=params[:version]
    if key && version
      begin
        java_facade.downloadPlugin(key, version)
      rescue Exception => e
        flash[:error]=e.message
      end
    end
    redirect_to :action => (params[:from] || 'index')
  end
  
  def uninstall
    key=params[:key]
    if key
      begin
        java_facade.uninstallPlugin(key)
      rescue Exception => e
        flash[:error]=e.message
      end
    end
    redirect_to :action => 'index'
  end
  
  def cancel_uninstalls
    java_facade.cancelPluginUninstalls()
    flash[:notice]="Plugin uninstalls are canceled."
    redirect_to :action => 'index'
  end
  
  private
  def load_update_finder
    @finder=java_facade.getUpdateFinder(params[:reload]=='true')
  end
  
  def updatecenter_activated
    update_center_activated = java_facade.getConfigurationValue('sonar.updatecenter') || 'true';
    if update_center_activated!='true'
      redirect_to home_url
    end
  end
end
        if update.isCompatible
          @last_compatible[plugin.getKey()]=update.getRelease().getVersion()
        end
      end
    end
  end

  def available
    @uninstalls=java_facade.getPluginUninstalls()
    @downloads=java_facade.getPluginDownloads()

    @center=nil
    @updates_by_category={}

    finder=load_update_finder()
    if finder
      @center=finder.getCenter()
      finder.findAvailablePlugins().each do |update|
        category=update.getPlugin().getCategory()||''
        @updates_by_category[category]||=[]
        @updates_by_category[category]<<update
      end
    end
  end

  def cancel_downloads
    java_facade.cancelPluginDownloads()
    flash[:notice]="Plugin downloads are canceled."
    redirect_to :action => 'index'
  end

  def install
    key=params[:key]
    version=params[:version]
    if key && version
      begin
        java_facade.downloadPlugin(key, version)
      rescue Exception => e
        flash[:error]=e.message
      end
    end
    redirect_to :action => (params[:from] || 'index')
  end
  
  def uninstall
    key=params[:key]
    if key
      begin
        java_facade.uninstallPlugin(key)
      rescue Exception => e
        flash[:error]=e.message
      end
    end
    redirect_to :action => 'index'
  end
  
  def cancel_uninstalls
    java_facade.cancelPluginUninstalls()
    flash[:notice]="Plugin uninstalls are canceled."
    redirect_to :action => 'index'
  end
  
  private
  def load_update_finder
    @finder=java_facade.getUpdateFinder(params[:reload]=='true')
  end
  
  def updatecenter_activated
    update_center_activated = java_facade.getConfigurationValue('sonar.updatecenter') || 'true';
    if update_center_activated!='true'
      redirect_to home_url
    end
  end
end
      end
    end
  end

  def cancel_downloads
    java_facade.cancelPluginDownloads()
    flash[:notice]="Plugin downloads are canceled."
    redirect_to :action => 'index'
  end

  def install
    key=params[:key]
    version=params[:version]
    if key && version
      begin
        java_facade.downloadPlugin(key, version)
      rescue Exception => e
        flash[:error]=e.message
      end
    end
    redirect_to :action => (params[:from] || 'index')
  end
  
  def uninstall
    key=params[:key]
    if key
      begin
        java_facade.uninstallPlugin(key)
      rescue Exception => e
        flash[:error]=e.message
      end
    end
    redirect_to :action => 'index'
  end
  
  def cancel_uninstalls
    java_facade.cancelPluginUninstalls()
    flash[:notice]="Plugin uninstalls are canceled."
    redirect_to :action => 'index'
  end
  
  private
  def load_update_finder
    @finder=java_facade.getUpdateFinder(params[:reload]=='true')
  end
  
  def updatecenter_activated
    update_center_activated = java_facade.getConfigurationValue('sonar.updatecenter') || 'true';
    if update_center_activated!='true'
      redirect_to home_url
    end
  end
end