IdeaModule represents an .ipr file
# File lib/buildr/ide/idea.rb, line 623 def initialize(buildr_project) super() @buildr_project = buildr_project @extra_modules = [] @artifacts = [] @data_sources = [] @configurations = [] end
# File lib/buildr/ide/idea.rb, line 640 def add_artifact(name, type, build_on_make = false) add_to_composite_component(self.artifacts) do |xml| xml.artifact(:name => name, :type => type, :"build-on-make" => build_on_make) do |xml| yield xml if block_given? end end end
# File lib/buildr/ide/idea.rb, line 648 def add_configuration(name, type, factory_name, default = false) add_to_composite_component(self.configurations) do |xml| xml.configuration(:name => name, :type => type, :factoryName => factory_name, :default => default) do |xml| yield xml if block_given? end end end
# File lib/buildr/ide/idea.rb, line 686 def add_data_source(name, options = {}) add_to_composite_component(self.data_sources) do |xml| data_source_options = { :source => "LOCAL", :name => name, :uuid => Buildr::Util.uuid } classpath = options[:classpath] || [] xml.tag!("data-source", data_source_options) do |xml| xml.tag!("synchronize", (options[:synchronize]||"true")) xml.tag!("jdbc-driver", options[:driver]) if options[:driver] xml.tag!("jdbc-url", options[:url]) if options[:url] xml.tag!("user-name", options[:username]) if options[:username] xml.tag!("user-password", encrypt(options[:password])) if options[:password] xml.tag!("default-dialect", options[:dialect]) if options[:dialect] xml.libraries do |xml| classpath.each do |classpath_element| a = Buildr.artifact(classpath_element) a.invoke xml.library do |xml| xml.tag!("url", resolve_path(a.to_s)) end end end if classpath.size > 0 end end end
# File lib/buildr/ide/idea.rb, line 754 def add_exploded_ear_artifact(project, options ={}) artifact_name = to_artifact_name(project, options) add_artifact(artifact_name, "exploded-ear", build_on_make(options)) do |xml| dependencies = (options[:dependencies] || ([project] + project.compile.dependencies)).flatten libraries, projects = partition_dependencies(dependencies) emit_output_path(xml, artifact_name, options) xml.root :id => "root" do emit_module_output(xml, projects) xml.element :id => "directory", :name => "lib" do emit_libraries(xml, libraries) end end end end
# File lib/buildr/ide/idea.rb, line 787 def add_exploded_ejb_artifact(project, options = {}) artifact_name = to_artifact_name(project, options) add_artifact(artifact_name, "exploded-ejb", build_on_make(options)) do |xml| dependencies = (options[:dependencies] || [project]).flatten libraries, projects = partition_dependencies(dependencies) raise "Unable to add non-project dependencies (#{libraries.inspect}) to ejb artifact" if libraries.size > 0 emit_output_path(xml, artifact_name, options) xml.root :id => "root" do artifact_content(xml, project, projects, options) end end end
# File lib/buildr/ide/idea.rb, line 715 def add_exploded_war_artifact(project, options = {}) artifact_name = to_artifact_name(project, options) artifacts = options[:artifacts] || [] add_artifact(artifact_name, "exploded-war", build_on_make(options)) do |xml| dependencies = (options[:dependencies] || ([project] + project.compile.dependencies)).flatten libraries, projects = partition_dependencies(dependencies) emit_output_path(xml, artifact_name, options) xml.root :id => "root" do xml.element :id => "directory", :name => "WEB-INF" do xml.element :id => "directory", :name => "classes" do artifact_content(xml, project, projects, options) end xml.element :id => "directory", :name => "lib" do emit_libraries(xml, libraries) emit_jar_artifacts(xml, artifacts) end end if options[:enable_war].nil? || options[:enable_war] || (options[:war_module_names] && options[:war_module_names].size > 0) module_names = options[:war_module_names] || [project.iml.id] module_names.each do |module_name| facet_name = options[:war_facet_name] || "Web" xml.element :id => "javaee-facet-resources", :facet => "#{module_name}/web/#{facet_name}" end end if options[:enable_gwt] || (options[:gwt_module_names] && options[:gwt_module_names].size > 0) module_names = options[:gwt_module_names] || [project.iml.id] module_names.each do |module_name| facet_name = options[:gwt_facet_name] || "GWT" xml.element :id => "gwt-compiler-output", :facet => "#{module_name}/gwt/#{facet_name}" end end end end end
# File lib/buildr/ide/idea.rb, line 802 def add_gwt_configuration(launch_page, project, options = {}) name = options[:name] || "Run #{launch_page}" shell_parameters = options[:shell_parameters] || "" vm_parameters = options[:vm_parameters] || "-Xmx512m" add_configuration(name, "GWT.ConfigurationType", "GWT Configuration") do |xml| xml.module(:name => project.iml.id) xml.option(:name => "RUN_PAGE", :value => launch_page) xml.option(:name => "SHELL_PARAMETERS", :value => shell_parameters) xml.option(:name => "VM_PARAMETERS", :value => vm_parameters) xml.RunnerSettings(:RunnerId => "Run") xml.ConfigurationWrapper(:RunnerId => "Run") xml.method() end end
# File lib/buildr/ide/idea.rb, line 771 def add_jar_artifact(project, options = {}) artifact_name = to_artifact_name(project, options) dependencies = (options[:dependencies] || [project]).flatten libraries, projects = partition_dependencies(dependencies) raise "Unable to add non-project dependencies (#{libraries.inspect}) to jar artifact" if libraries.size > 0 jar_name = "#{artifact_name}.jar" add_artifact(jar_name, "jar", build_on_make(options)) do |xml| emit_output_path(xml, artifact_name, options) xml.root(:id => "archive", :name => jar_name) do artifact_content(xml, project, projects, options) end end end
# File lib/buildr/ide/idea.rb, line 656 def add_postgres_data_source(name, options = {}) if options[:url].nil? && options[:database] default_url = "jdbc:postgresql://#{(options[:host] || "127.0.0.1")}:#{(options[:port] || "5432")}/#{options[:database]}" end params = { :driver => 'org.postgresql.Driver', :url => default_url, :username => ENV["USER"], :dialect => 'PostgreSQL', :classpath => ["org.postgresql:postgresql:jar:9.2-1003-jdbc4"] }.merge(options) add_data_source(name, params) end
# File lib/buildr/ide/idea.rb, line 671 def add_sql_server_data_source(name, options = {}) if options[:url].nil? && options[:database] default_url = "jdbc:jtds:sqlserver://#{(options[:host] || "127.0.0.1")}:#{(options[:port] || "1433")}/#{options[:database]}" end params = { :driver => 'net.sourceforge.jtds.jdbc.Driver', :url => default_url, :username => ENV["USER"], :dialect => 'TSQL', :classpath => ['net.sourceforge.jtds:jtds:jar:1.2.7'] }.merge(options) add_data_source(name, params) end
# File lib/buildr/ide/idea.rb, line 636 def jdk_version @jdk_version ||= buildr_project.compile.options.source || "1.6" end
# File lib/buildr/ide/idea.rb, line 632 def version @version || "12" end
# File lib/buildr/ide/idea.rb, line 821 def artifact_content(xml, project, projects, options) emit_module_output(xml, projects) emit_jpa_descriptors(xml, project, options) emit_ejb_descriptors(xml, project, options) end
# File lib/buildr/ide/idea.rb, line 939 def artifacts_component create_composite_component("ArtifactManager", {}, self.artifacts) end
# File lib/buildr/ide/idea.rb, line 831 def base_document target = StringIO.new Builder::XmlMarkup.new(:target => target).project(:version => "4") Buildr::IntellijIdea.new_document(target.string) end
# File lib/buildr/ide/idea.rb, line 943 def configurations_component create_composite_component("ProjectRunConfigurationManager", {}, self.configurations) end
# File lib/buildr/ide/idea.rb, line 935 def data_sources_component create_composite_component("DataSourceManagerImpl", {:format => "xml", :hash => "3208837817"}, self.data_sources) end
# File lib/buildr/ide/idea.rb, line 837 def default_components [ lambda { modules_component }, vcs_component, artifacts_component, lambda { data_sources_component }, configurations_component, lambda { framework_detection_exclusion_component } ] end
# File lib/buildr/ide/idea.rb, line 827 def extension "ipr" end
# File lib/buildr/ide/idea.rb, line 848 def framework_detection_exclusion_component create_component('FrameworkDetectionExcludesConfiguration') do |xml| xml.file :url => file_path(buildr_project._(:artifacts)) end end
# File lib/buildr/ide/idea.rb, line 854 def initial_components [ lambda { project_root_manager_component }, lambda { project_details_component } ] end
# File lib/buildr/ide/idea.rb, line 880 def modules_component create_component("ProjectModuleManager") do |xml| xml.modules do buildr_project.projects.select { |subp| subp.iml? }.each do |subproject| module_path = subproject.base_dir.gsub(/^#{buildr_project.base_dir}\//, '') path = "#{module_path}/#{subproject.iml.name}.iml" attribs = {:fileurl => "file://$PROJECT_DIR$/#{path}", :filepath => "$PROJECT_DIR$/#{path}"} if subproject.iml.group == true attribs[:group] = subproject.parent.name.gsub(':', '/') elsif !subproject.iml.group.nil? attribs[:group] = subproject.iml.group.to_s end xml.module attribs end self.extra_modules.each do |iml_file| xml.module :fileurl => "file://$PROJECT_DIR$/#{iml_file}", :filepath => "$PROJECT_DIR$/#{iml_file}" end if buildr_project.iml? xml.module :fileurl => "file://$PROJECT_DIR$/#{buildr_project.iml.name}.iml", :filepath => "$PROJECT_DIR$/#{buildr_project.iml.name}.iml" end end end end
# File lib/buildr/ide/idea.rb, line 874 def project_details_component create_component("ProjectDetails") do |xml| xml.option("name" => "projectName", "value" => self.name) end end
# File lib/buildr/ide/idea.rb, line 861 def project_root_manager_component attribs = {} attribs["version"] = "2" attribs["languageLevel"] = "JDK_#{self.jdk_version.gsub('.', '_')}" attribs["assert-keyword"] = "true" attribs["jdk-15"] = (jdk_version >= "1.5").to_s attribs["project-jdk-name"] = self.jdk_version attribs["project-jdk-type"] = "JavaSDK" create_component("ProjectRootManager", attribs) do |xml| xml.output("url" => file_path(buildr_project._(:target, :idea, :project_out))) end end
# File lib/buildr/ide/idea.rb, line 947 def resolve_path(path) resolve_path_from_base(path, "$PROJECT_DIR$") end
# File lib/buildr/ide/idea.rb, line 906 def vcs_component project_directories = buildr_project.projects.select { |p| p.iml? }.collect { |p| p.base_dir } project_directories << buildr_project.base_dir # Guess the iml file is in the same dir as base dir project_directories += self.extra_modules.collect { |p| File.dirname(p) } project_directories = project_directories.sort.uniq mappings = {} project_directories.each do |dir| if File.directory?("#{dir}/.git") mappings[dir] = "Git" elsif File.directory?("#{dir}/.svn") mappings[dir] = "svn" end end if mappings.size > 1 create_component("VcsDirectoryMappings") do |xml| mappings.each_pair do |dir, vcs_type| resolved_dir = resolve_path(dir) mapped_dir = resolved_dir == '$PROJECT_DIR$/.' ? buildr_project.base_dir : resolved_dir xml.mapping :directory => mapped_dir, :vcs => vcs_type end end end end