<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.jruby</groupId>
    <artifactId>jruby-artifacts</artifactId>
    <version>1.7.14</version>
  </parent>
  <artifactId>jruby-stdlib</artifactId>
  <name>JRuby Stdlib</name>
  <properties>
    <jruby.complete.gems>${jruby.complete.home}/lib/ruby/gems/shared</jruby.complete.gems>
    <tesla.version>0.1.1</tesla.version>
    <tesla.dump.readOnly>true</tesla.dump.readOnly>
    <bundle.symbolic_name>org.jruby.jruby-stdlib</bundle.symbolic_name>
    <jruby.basedir>${basedir}/../../</jruby.basedir>
    <gem.home>${jruby.basedir}/lib/ruby/gems/shared</gem.home>
    <main.basedir>${project.parent.parent.basedir}</main.basedir>
    <jruby.complete.home>${project.build.outputDirectory}/META-INF/jruby.home</jruby.complete.home>
    <bundle.name>JRuby Stdlib</bundle.name>
    <tesla.dump.pom>pom.xml</tesla.dump.pom>
    <jruby.home>${basedir}/../../</jruby.home>
  </properties>
  <build>
    <resources>
      <resource>
        <targetPath>${jruby.complete.gems}</targetPath>
        <directory>${gem.home}</directory>
        <includes>
          <include>gems/rake-${rake.version}/bin/r*</include>
          <include>gems/rdoc-${rdoc.version}/bin/r*</include>
          <include>specifications/default/*.gemspec</include>
        </includes>
      </resource>
      <resource>
        <targetPath>${jruby.complete.home}</targetPath>
        <directory>${jruby.basedir}</directory>
        <includes>
          <include>bin/ast*</include>
          <include>bin/gem*</include>
          <include>bin/irb*</include>
          <include>bin/jgem*</include>
          <include>bin/jirb*</include>
          <include>bin/jruby*</include>
          <include>bin/rake*</include>
          <include>bin/ri*</include>
          <include>bin/rdoc*</include>
          <include>bin/testrb*</include>
          <include>lib/ruby/1.8/**</include>
          <include>lib/ruby/1.9/**</include>
          <include>lib/ruby/2.0/**</include>
          <include>lib/ruby/shared/**</include>
        </includes>
        <excludes>
          <exclude>bin/jruby</exclude>
          <exclude>bin/jruby*_*</exclude>
          <exclude>bin/jruby*-*</exclude>
          <exclude>**/.*</exclude>
          <exclude>lib/ruby/shared/rubygems/defaults/jruby_native.rb</exclude>
        </excludes>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <artifactId>maven-source-plugin</artifactId>
        <configuration>
          <skipSource>true</skipSource>
        </configuration>
      </plugin>
      <plugin>
        <groupId>de.saumya.mojo</groupId>
        <artifactId>gem-maven-plugin</artifactId>
        <version>${jruby.plugins.version}</version>
        <executions>
          <execution>
            <id>fix shebang on gem bin files and add *.bat files</id>
            <phase>initialize</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <script>puts 'fix the gem stub files'
		Dir[ '../../lib/ruby/gems/shared/bin/*' ].each do |f|
                  if File.file?( f )
		    content = File.read( f )
		    new_content = content.sub(/#!.*/, "#!/usr/bin/env jruby
")
		     File.open( f, "w" ) { |file| file.print( new_content ) }
                  end
		end
	
		puts 'generate the missing bat files'
		Dir[File.join( '${jruby.basedir}', 'bin', '*' )].each do |fn|
                  next unless File.file?(fn)
		  next if fn =~ /.bat$/
		  next if File.exist?("#{fn}.bat")
		  next unless File.open(fn, 'r', :internal_encoding => 'ASCII-8BIT') do |io|
		    line = io.readline rescue ""
		    line =~ /^#!.*ruby/
		  end
		  puts "Generating #{File.basename(fn)}.bat"
		  File.open("#{fn}.bat", "wb") do |f|
                    f.print "@ECHO OFF\r\n"
		    f.print "@\"%~dp0jruby.exe\" -S #{File.basename(fn)} %*\r\n"
                  end
		end</script>
            </configuration>
          </execution>
          <execution>
            <id>copy bin/jruby.bash to bin/jruby</id>
            <phase>process-resources</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <script>puts 'copy jruby.bash to jruby'
		require 'fileutils'
		FileUtils.cp( File.join( '${jruby.complete.home}', 'bin', 'jruby.bash' ), File.join( '${jruby.complete.home}', 'bin', 'jruby' ) )</script>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>attach-artifacts</id>
            <phase>package</phase>
            <goals>
              <goal>attach-artifact</goal>
            </goals>
            <configuration>
              <artifacts>
                <artifact>
                  <file>${basedir}/src/empty.jar</file>
                  <classifier>sources</classifier>
                </artifact>
                <artifact>
                  <file>${basedir}/src/empty.jar</file>
                  <classifier>javadoc</classifier>
                </artifact>
              </artifacts>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>io.tesla.polyglot</groupId>
        <artifactId>tesla-polyglot-maven-plugin</artifactId>
        <version>${tesla.version}</version>
        <executions>
          <execution>
            <id>jrubydir</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>execute</goal>
            </goals>
            <configuration>
              <taskId>jrubydir</taskId>
              <nativePom>pom.rb</nativePom>
            </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>io.tesla.polyglot</groupId>
            <artifactId>tesla-polyglot-ruby</artifactId>
            <version>${tesla.version}</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>
</project>
