Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package de.saumya.mojo.gem;
  
  import java.io.File;
  
 
 
 public abstract class AbstractGemMojo extends AbstractJRubyMojo {

    

Component:
role-hint="zip"
 
     protected UnArchiver unzip;
    
    

Parameter:
expression="${plugin}" @readonly
 
     protected PluginDescriptor  plugin;

    
flag whether to include open-ssl gem or not
Command line -Dgem.includeOpenSSL=...

Parameter:
expression="${gem.includeOpenSSL}" default-value="true"
 
     protected boolean       includeOpenSSL;

    
flag whether to include all gems to test-resources, i.e. to test-classpath or not
Command line -Dgem.includeRubygemsInTestResources=...

Parameter:
expression="${gem.includeRubygemsInTestResources}" default-value="true"
 
     protected boolean       includeRubygemsInTestResources;

    
    
flag whether to install rdocs of the used gems or not
Command line -Dgem.installRDoc=...

Parameter:
expression="${gem.installRDoc}" default-value="false"
 
     protected boolean         installRDoc;

    
flag whether to install ri of the used gems or not
Command line -Dgem.installRDoc=...

Parameter:
expression="${gem.installRI}" default-value="false"
 
     protected boolean         installRI;

    
directory of gem home to use when forking JRuby.
Command line -Dgem.home=...

Parameter:
expression="${gem.home}" default-value="${project.build.directory}/rubygems"
 
     protected File          gemHome;

    
directory of JRuby path to use when forking JRuby.
Command line -Dgem.path=...

Parameter:
expression="${gem.path}" default-value="${project.build.directory}/rubygems"
 
     protected File          gemPath;

    
directory of JRuby bin path to use when forking JRuby.
Command line -Dgem.binDirectory=...

Parameter:
expression="${gem.binDirectory}"
 
     protected File          binDirectory;

    
flag to indicate to setup jruby's native support for C-extensions
Command line -Dgem.supportNative=...

Parameter:
expression="${gem.supportNative}" default-value="false"
    protected boolean        supportNative;
    
    

Component:
    protected GemManager    manager;
    protected GemsConfig    gemsConfig;
    protected GemsInstaller gemsInstaller;
    @Override
    protected ScriptFactory newScriptFactory(Artifact artifactthrows MojoExecutionException {
        if (this..getBasedir() == null) {
            this. = new File(this..getAbsolutePath()
                    .replace("/${project.basedir}/""/"));
            this. = new File(this..getAbsolutePath()
                    .replace("/${project.basedir}/""/"));
        }
        this. = new GemsConfig();
        this..setGemHome(this.);
        this..addGemPath(this.);
        this..addGemPath(new File(this..getParentFile(), 
                                            this..getName() + "-bundler-maven-plugin"));
        try {
            final GemScriptFactory factory = new GemScriptFactory(this.,
                    this.,
                    artifact.getArtifactId().equals()? nullartifact.getFile(),
                    artifact.getArtifactId().equals()? retrieveStdlibArtifact().getFile(): artifact.getFile(),
                    this..getTestClasspathElements(),
                    this.
                    this.);
            if(){
                factory.addJvmArgs("-Djruby.home=" + setupNativeSupport().getAbsolutePath());
            }
            return factory;
        }
        catch (final DependencyResolutionRequiredException e) {
            throw new MojoExecutionException("could not resolve jruby"e);
        }
        catch (final ScriptException e) {
            throw new MojoExecutionException("could not initialize script factory",
                    e);
        }
        catch (final IOException e) {
            throw new MojoExecutionException("could not initialize script factory",
                    e);
        }
    }
    private File setupNativeSupport() throws MojoExecutionException {
        File target = new File(this..getBuild().getDirectory());
        File jrubyDir = new File(target"jruby-" + );
        if (!jrubyDir.exists()){
            Artifact dist = .createArtifact("org.jruby",
                                                   "jruby-dist",
                                                   ,
                                                   "bin",
                                                   "zip");
            try {
                .resolve(dist,
                                ,
                                .getRemoteArtifactRepositories());
            }
            catch (final GemException e) {
                throw new MojoExecutionException("could not setup jruby distribution for native support",
                        e);
            }
            if () {
                getLog().info("unzip " + dist.getFile());
            }
            target.mkdirs();
            .setSourceFile(dist.getFile());
            .setDestDirectory(target);
            File f = null;
            try {
                .extract();
                f = new File(target"jruby-" +  + "/bin/jruby");
                // use reflection so it compiles with java1.5 as well but does not set executable
                Method m = f.getClass().getMethod("setExecutable"boolean.class);
                m.invoke(fnew Boolean(true));
            }
            catch (ArchiverException e) {
                throw new MojoExecutionException("could unzip jruby distribution for native support",
                        e);
            }
            catch (Exception e) {
                getLog().warn("can not set executable flag: " + f.getAbsolutePath() + " (" + e.getMessage() + ")");
            }
        }
        return jrubyDir;
    }
    @Override
    protected void executeJRuby() throws MojoExecutionException,
            MojoFailureExceptionIOExceptionScriptException {
                this..setAddRdoc(this.);
        this..setAddRI(this.);
        this..setBinDirectory(this.);
        // this.gemsConfig.setUserInstall(userInstall);
        // this.gemsConfig.setSystemInstall(systemInstall);
        this..setSkipJRubyOpenSSL(!this.);
        this. = new GemsInstaller(this.,
                this.,
                this.);
        try {
            // install the gem dependencies from the pom
            this..installPom(this.this.);
            // has the plugin gem dependencies ?
            boolean hasGems = false;
            for(Artifact artifact.getArtifacts()){
                if (artifact.getType().contains("gem")){
                    hasGems = true;
                    break;
                }
            }
            // install the gems for the plugin
            File pluginGemHome = new File(this..getGemHome().getAbsolutePath() + "-" + .getArtifactId());
            pluginGemHome.mkdirs();
            if (hasGems){
                // use a common bindir, i.e. the one from the configured gemHome
                // remove default by setting it explicitly
                this..setBinDirectory(this..getBinDirectory());
                File home = this..getGemHome();
                this..setGemHome(pluginGemHome);
                this..addGemPath(this..getGemHome());
                this..installGems(this.,
                                               this..getArtifacts(), 
                                               this.
                                               this..getPluginArtifactRepositories());
                this..setGemHome(home);
            }
        }
        catch (final GemException e) {
            throw new MojoExecutionException("error in installing gems"e);
        }
        if (this.) {
            for (File path : this..getGemPath()) {
                if () {
                    getLog().info("add to rubygems to test-classpath from: "
                            + path.getAbsolutePath());
                }
                // add it to the classpath so java classes can find the ruby
                // files
                Resource resource = new Resource();
                resource.setDirectory(path.getAbsolutePath());
                resource.addInclude("gems/**");
                resource.addInclude("specifications/**");
                .getBuild().getTestResources().add(resource);
            }
        }
        try {
            executeWithGems();
        }
        catch (final GemException e) {
            throw new MojoExecutionException("error in executing with gems"e);
        }
    }
    abstract protected void executeWithGems() throws MojoExecutionException,
New to GrepCode? Check out our FAQ X