Index: app/controllers/wizard_controller.rb
===================================================================
--- app/controllers/wizard_controller.rb	(revision 4822)
+++ app/controllers/wizard_controller.rb	(working copy)
@@ -1,4 +1,5 @@
 require 'wizard'
+require 'rexml/document'
 
 class WizardController < ApplicationController
 
@@ -39,11 +40,19 @@
                         "Creating package #{pkg_name} in project #{prj_name}")
       questions.each do |question|
         name = question.keys[0]
+        attrs = question[name]
+        # type "inspect_tarball" is special
+        if attrs["type"] == "inspect_tarball"
+          if ! inspect_tarball
+            return # abort the loop if the "please wait" dialog was rendered
+          else
+            next
+          end
+        end
         if params[name] && ! params[name].empty?
           @wizard[name] = params[name]
           next
         end
-        attrs = question[name]
         @wizard_form.add_entry(name, attrs["type"], attrs["label"],
                                attrs["legend"], attrs["options"], @wizard[name])
       end
@@ -80,6 +89,39 @@
     end
     render :template => "wizard", :status => 200
   end
+
+  # let the wizard host inspec the tarball
+  # returns true if the next dialog should be rendered, false if render was
+  # already called
+  def inspect_tarball
+    path = "/inspect/#{params[:project]}/#{params[:package]}/#{@wizard["tarball"]}"
+    res = Net::HTTP.start(WIZARD_HOST, WIZARD_PORT) {|http|
+      http.get(path)
+    }
+    xml = REXML::Document.new(res.body)
+    status = xml.root.elements["status"].text
+    case status
+    when "pending":
+      @wizard_form = WizardForm.new("Please wait",
+                                  "The wizard is analyzing the uploaded source.")
+      render_wizard
+      return false
+    when "error":
+      @wizard_form = WizardForm.new("Error reading #{@wizard["tarball"]}",
+                                   xml.root.elements["details"])
+      @wizard["inspect_tarball"] = "error"
+      render_wizard
+      return false
+    when "done":
+      xml.elements.each("wizard-inspect/result/data") do |element|
+        @wizard[element.attributes["name"]] = element.text
+      end
+      @wizard["inspect_tarball"] = "done"
+      return true
+    else
+      raise RuntimeError.new("WizardError: incorrect status returned by backend server")
+    end
+  end
 end
 
 # vim:et:ts=2:sw=2
Index: files/wizardtemplate.spec
===================================================================
--- files/wizardtemplate.spec	(revision 4822)
+++ files/wizardtemplate.spec	(working copy)
@@ -1,10 +1,15 @@
 Name:           <%= @name %>
 # List of additional build dependencies
-<% if @packtype == "python"
-%>BuildRequires:  python-devel<%
+<%
+  buildrequires = []
+  buildrequires << "python-devel" if @packtype == "python"
+  buildrequires << "java-devel" if @packtype == "java"
+  buildrequires << "gcc-c++" if @has_cpp_source
+  if ! buildrequires.empty?
+%>BuildRequires:  <%= buildrequires.sort.join(" ") %><%
   else
 %>#BuildRequires:  gcc-c++ libxml2-devel<%
-   end %>
+  end %>
 Version:        <%= @version %>
 Release:        1
 License:        <%= @license %>
@@ -23,48 +28,67 @@
 
 %prep
 <%=
-# FIXME: escape special characters in name and version
-if @tarball =~ /^#{@name}-#{@version}\.tar\.(gz|bz2)$/
-"%setup -q"
-elsif @tarball =~ /^(.*)-#{@version}\.tar\.(gz|bz2)$/
-"%setup -q -n #{$1}-%version"
-elsif @tarball =~ /^(.*)\.tar\.(gz|bz2)$/
-"%setup -q -n #{$1}"
-else # give up
-"%setup -q"
-end
+  if @has_toplevel_dir
+    if @toplevel_dir == "#{@name}-#{@version}"
+      "%setup -q"
+    # FIXME: special characters in @version
+    elsif @toplevel_dir =~ /^(.*)#{@version}$/
+      "%setup -q -n #{$1}%version"
+    else
+      "%setup -q -n #{@toplevel_dir}"
+    end
+  else
+    "%setup -q -c"
+  end
 %>
 
 %build
-<% if @packtype == "generic" %>
-# Assume that the package is built by plain 'make' if there's no ./configure.
-# This test is there only because the wizard doesn't know much about the
-# package, feel free to clean it up
-if test -x ./configure; then
-	%configure
-fi
+<% if @has_makefile %>
+  <% if @has_configure %>
+%configure
+  <% end %>
 make
-<% elsif @packtype == "perl" %>
+<% elsif @has_cmakelists_txt %>
+mkdir _build
+cd _build
+cmake -DCMAKE_INSTALL_PREFIX=%{prefix} \
+      -DSYSCONFDIR=%{_sysconfdir} \
+      -DMANDIR=%{_mandir} \
+      -DCMAKE_VERBOSE_MAKEFILE=TRUE \
+      -DCMAKE_C_FLAGS_RELEASE:STRING="%{optflags}" \
+      -DCMAKE_CXX_FLAGS_RELEASE:STRING="%{optflags}" \
+      -DCMAKE_BUILD_TYPE=Release \
+      ..
+make
+<% elsif @has_makefile_pl %>
 perl Makefile.PL
 make
-<% elsif @packtype == "python" %>
+<% elsif @has_setup_py == "python" %>
 python setup.py build
-<% else raise RuntimeError.new("WizardError: unknown packtype #{@packtype}") %>
+<% elsif @has_build_xml %>
+ant
+<% else %>
+echo "Replace me with a command to compile the package" >&2; exit 1
 <% end %>
     
 
 %install
-<% if @packtype == "generic" %>
+<% if @has_makefile %>
 make DESTDIR=%buildroot install
-<% elsif @packtype == "perl" %>
+<% elsif @has_cmakelists_txt %>
+cd _build
+make DESTDIR=%buildroot install
+<% elsif @has_makefile_pl %>
 make DESTDIR=%buildroot install_vendor
 %perl_process_packlist
-<% elsif @packtype == "python" %>
+<% elsif @has_setup_py == "python" %>
 python setup.py install --prefix=%_prefix --root=%buildroot --record-rpm=filelist
-<% else raise RuntimeError.new("WizardError: unknown packtype #{@packtype}") %>
+<% else %>
+echo "Replace me with a command to install the build files to \$RPM_BUILD_ROOT" >&2; exit 1
 <% end %>
 
-<% if @packtype != "python" %>
+
+<% if @has_makefile || @has_cmakelists_txt || @has_makefile_pl %>
 # Write a proper %%files section and remove these two commands and
 # the '-f filelist' option to %%files
 echo '%%defattr(-,root,root)' >filelist
Index: lib/wizard.rb
===================================================================
--- lib/wizard.rb	(revision 4822)
+++ lib/wizard.rb	(working copy)
@@ -7,6 +7,9 @@
       @guess = DirtyHash.new
       @version = 1
       @dirty = false
+      # set some default guesses
+      @guess["license"] = "GPL v2 or later"
+      @guess["group"] = "Productivity/Other"
       return
     end
 
@@ -51,36 +54,34 @@
     return @dirty || @data.dirty || @guess.dirty
   end
 
-  def [](name)
-    return @data[name] || @guess[name]
+  def [](key)
+    return @data[key] || @guess[key]
   end
 
-  def []=(name, value)
-    @data[name] = value
-    case name
-    when "name":
-      if value =~ /^perl-/i
-        @guess["packtype"] = "perl"
-      elsif value =~ /^python-/i
-        @guess["packtype"] = "python"
-      end
+  def []=(key, value)
+    @data[key] = value
+    case key
     when "tarball":
       version = Wizard.guess_version(@data["name"], value)
       if version
         @guess["version"] = version
       end
-    when "packtype":
-      case value
-      when "perl"
-        @guess["license"] = "Artistic license"
-        @guess["group"] = "Development/Libraries/Perl"
-      when "python"
-        @guess["license"] = "GPL v2 or later"
-        @guess["group"] = "Development/Libraries/Python"
-      else
-        @guess["license"] = "GPL v2 or later"
-        @guess["group"] = "Productivity/Other"
+    when "has_makefile_pl":
+      @guess["packtype"] = "perl"
+      @guess["license"] = "Artistic license"
+      @guess["group"] = "Development/Libraries/Perl"
+      if @data["tarball"] =~ /^(.*)-[0-9][0-9\.]+\.tar\.(gz|bz2)$/
+        name = $1
+        name.sub!(/-/, "::")
+        @guess["summary"] = "#{name} Perl module"
+        @guess["description"] = "The #{name} Perl module is essential when doing foo or bar."
       end
+    when "has_setup_py":
+      @guess["packtype"] = "python"
+      @guess["group"] = "Development/Libraries/Python"
+    when "has_build_xml":
+      @guess["packtype"] = "java"
+      @guess["group"] = "Development/Libraries/Java"
     end
   end
 
@@ -89,8 +90,10 @@
     ask "name"
     return @questions if @questions
     ask "tarball"
-    ask "packtype"
+    #ask "packtype"
     return @questions if @questions
+    ask "inspect_tarball"
+    return @questions if @questions
     ask "summary"
     ask "description"
     ask "version"
@@ -164,6 +167,10 @@
       'type'    => "text",
       'label'   => "Your email",
     },
+    # special
+    "inspect_tarball" => {
+      'type'    => "inspect_tarball"
+    }
   }
 
   public
