Projects >> jruby-maven-plugins >>7a0802f1b20422d6c9c40801921d1934b889697a

Chunk
Conflicting content
    /**
     * @parameter expression="${gem.includeOpenSSL}" default-value="true"
     */
<<<<<<< HEAD
    protected boolean            includeOpenSSL;
=======
    protected boolean           includeOpenSSL;
    
    
    /**
     * @parameter expression="${gem.installRDoc}" default-value="false"
     */
    protected boolean installRDoc;
    
    /**
     * @parameter expression="${gem.installRI}" default-value="false"
     */
    protected boolean installRI;
>>>>>>> 49138a643914f6d1dc61084e9fedf0915bf3069a

    /**
     * allow to overwrite the version by explicitly declaring a dependency in
Solution content
    /**
     * @parameter expression="${gem.includeOpenSSL}" default-value="true"
     */
    protected boolean           includeOpenSSL;
    
    
    /**
     * @parameter expression="${gem.installRDoc}" default-value="false"
     */
    protected boolean installRDoc;
    
    /**
     * @parameter expression="${gem.installRI}" default-value="false"
     */
    protected boolean installRI;

    /**
     * allow to overwrite the version by explicitly declaring a dependency in
File
AbstractGemMojo.java
Developer's decision
Version 2
Kind of conflict
Attribute
Comment
Chunk
Conflicting content
                    .addArg("--no-ri")
                    .addArg("--no-rdoc")
            }
        }
        if (gems.length() > 0) {
<<<<<<< HEAD
            this.factory.newScriptFromResource(GEM_RUBY_COMMAND)
                    .addArg("install")
                    .addArg("--no-user-install")
                    .addArg("-l")
                    .addArg(extraFlag)
                    .addArgs(gems.toString())
                    .execute();
            // execute("-S gem install --no-ri --no-rdoc --no-user-install "
            // + " -l " + gems, false);
=======
        	StringBuilder command = new StringBuilder();
        	command.append( "-S gem install -l " );
        	command.append( extraFlag );
        	if ( this.installRDoc ) {
        		command.append( "--rdoc " );
        	} else {
        		command.append( "--no-rdoc " );
        	}
        	if ( this.installRI ) {
        		command.append( "--ri " );
        	} else {
        		command.append( "--no-ri " );
        	}
        	command.append( gems );
            execute(command.toString(), false );
>>>>>>> 49138a643914f6d1dc61084e9fedf0915bf3069a
        }
        else {
            getLog().debug("no gems found to install");
Solution content
            }
        }
        if (gems.length() > 0) {
            Script script = this.factory.newScriptFromResource(GEM_RUBY_COMMAND)
		.addArg("install");
        	if ( this.installRDoc ) {
        		script.addArg( "--rdoc " );
        	} else {
        		script.addArg( "--no-rdoc " );
        	}
        	if ( this.installRI ) {
        		script.addArg( "--ri " );
        	} else {
        		script.addArg( "--no-ri " );
        	}
                    script.addArg("--no-user-install")
                    .addArg("-l")
                    .addArg(extraFlag)
                    .addArgs(gems.toString())
                    .execute();
            // execute("-S gem install --no-ri --no-rdoc --no-user-install "
            // + " -l " + gems, false);
        }
        else {
            getLog().debug("no gems found to install");
File
AbstractGemMojo.java
Developer's decision
Manual
Kind of conflict
Comment
If statement
Method invocation
Variable
Chunk
Conflicting content
                    // commandString += " -l " + this.gem.getAbsolutePath();
                }
            }
<<<<<<< HEAD
            script.addArgs(this.installArgs);
            script.addArgs(this.args);
            script.execute();
        }
=======
            if (this.args != null) {
                commandString += " " + this.args;
            }
        }
	execute(commandString, false);
>>>>>>> 49138a643914f6d1dc61084e9fedf0915bf3069a
    }
}
Solution content
                    // commandString += " -l " + this.gem.getAbsolutePath();
                }
            }
            script.addArgs(this.installArgs);
            script.addArgs(this.args);
            script.execute();
        }
    }
}
File
InstallMojo.java
Developer's decision
Version 1
Kind of conflict
If statement
Method invocation
Chunk
Conflicting content
 */
public class PackageMojo extends AbstractGemMojo {

<<<<<<< HEAD
    /**
     * @parameter expression="${project.build.directory}"
     */
    File                              buildDirectory;

    /**
     * @parameter default-value="${gemspec}"
     */
    File                              gemSpec;

    /**
     * @parameter default-value="${gemspec.overwrite}"
     */
    boolean                           gemspecOverwrite = false;

    /** @parameter */
    private String                    date;

    /** @parameter */
    private String                    extraRdocFiles;

    /** @parameter */
    private String                    extraFiles;

    /** @parameter */
    private String                    rdocOptions;

    /** @parameter */
    private String                    requirePaths;

    /** @parameter */
    private String                    rubyforgeProject;

    /** @parameter */
    private String                    rubygemsVersion;

    /** @parameter */
    private String                    requiredRubygemsVersion;

    /** @parameter */
    /** @parameter */
    private String                    bindir;

     * @parameter expression="false"
    private String                    requiredRubyVersion;

    /** @parameter */
    private String                    postInstallMessage;

    /** @parameter */
    private String                    executables;

    /** @parameter */
    private String                    extensions;

    /** @parameter */
    private String                    platform;

    private final Map relocationMap    = new HashMap();

    /**
     */
    boolean                           includeDependencies;

    @Override
    public void executeJRuby() throws MojoExecutionException,
            RubyScriptException, MojoFailureException {
        final MavenProject project = this.project;
        final GemArtifact artifact = new GemArtifact(project);
        try {
            if (this.gemSpec == null && project.getBasedir() != null
                    && project.getBasedir().exists()) {
                // TODO generate the gemspec in the prepare-package phase so we
                // can use it separately
                build(project, artifact);
            }
            else {
                if (this.project.getBasedir() == null) {
                    // TODO use AbstactGemMojo
                    this.gemHome = new File(this.gemHome.getAbsolutePath()
                            .replace("/${project.basedir}/", "/"));
                    this.gemPath = new File(this.gemPath.getAbsolutePath()
                            .replace("/${project.basedir}/", "/"));
                }
                if (this.gemSpec == null) {
                    for (final File f : this.launchDirectory().listFiles()) {
                        if (f.getName().endsWith(".gemspec")) {
                            if (this.gemSpec == null) {
                                this.gemSpec = f;
                            }
                            else {
                                throw new MojoFailureException("more than one gemspec file found, use -Dgemspec=... to specifiy one");
                            }
                        }
                    }
                    if (this.gemSpec == null) {
                        throw new MojoFailureException("no gemspec file or pom found, use -Dgemspec=... to specifiy a gemspec file or '-f ...' to use a pom file");
                    }
                    else {
                        getLog().info("use gemspec: " + this.gemSpec);
                    }
                }

                this.factory.newScriptFromResource(GEM_RUBY_COMMAND)
                        .addArg("build", this.gemSpec)
                        .executeIn(launchDirectory());
                // execute("-S gem build " + this.gemSpec.getAbsolutePath(),
                // false);

                File gem = null;
                for (final File f : launchDirectory().listFiles()) {
                    if (f.getName().endsWith(".gem")) {
                        gem = f;
                        break;
                    }
                }
                if (project.getFile() != null && artifact.isGem()) {
                    // only when the pom exist there will be an artifact
                    FileUtils.copyFileIfModified(gem, artifact.getFile());
                    gem.deleteOnExit();
                }
                else {
                    // keep the gem where it when there is no buildDirectory
                    if (this.buildDirectory.exists()) {
                        FileUtils.copyFileIfModified(gem,
                                                     new File(this.buildDirectory,
                                                             gem.getName()));
                        gem.deleteOnExit();
                    }
                }
            }
        }
        catch (final IOException e) {
            throw new MojoExecutionException("error gemifing pom", e);
        }
    }

    private MavenProject projectFromArtifact(final Artifact artifact)
            throws ProjectBuildingException {
        final MavenProject project = this.builder.buildFromRepository(artifact,
                                                                      this.project.getRemoteArtifactRepositories(),
                                                                      this.localRepository);
        if (project.getDistributionManagement() != null
                && project.getDistributionManagement().getRelocation() != null) {
            final Relocation reloc = project.getDistributionManagement()
                    .getRelocation();
            final String key = artifact.getGroupId() + ":"
                    + artifact.getArtifactId() + ":" + artifact.getType() + ":"
                    + artifact.getVersion();
            artifact.setArtifactId(reloc.getArtifactId());
            artifact.setGroupId(reloc.getGroupId());
            if (reloc.getVersion() != null) {
                artifact.setVersion(reloc.getVersion());
            }
            this.relocationMap.put(key, artifact.getGroupId() + ":"
                    + artifact.getArtifactId() + ":" + artifact.getType() + ":"
                    + artifact.getVersion());
            return projectFromArtifact(artifact);
        }
        else {
            return project;
        }
    }

    private void build(final MavenProject project, final GemArtifact artifact)
            throws MojoExecutionException, IOException, RubyScriptException {

        getLog().info("building gem for " + artifact + " . . .");
        getLog().info("include dependencies? " + this.includeDependencies);
        final File gemDir = new File(this.buildDirectory, artifact.getGemName());
        final File gemSpec = new File(gemDir, artifact.getGemName()
                + ".gemspec");
        final GemspecWriter gemSpecWriter = new GemspecWriter(gemSpec,
                project,
                artifact);

        if (this.date != null) {
            gemSpecWriter.append("date", Date.valueOf(this.date).toString());
        }
        gemSpecWriter.append("rubygems_version", this.rubygemsVersion);
        gemSpecWriter.append("required_rubygems_version",
                             this.requiredRubygemsVersion);
        gemSpecWriter.append("required_ruby_version", this.requiredRubyVersion);
        gemSpecWriter.append("bindir", this.bindir);
        gemSpecWriter.append("post_install_message", this.postInstallMessage);

        gemSpecWriter.append("rubyforge_project", this.rubyforgeProject);
        gemSpecWriter.appendRdocFiles(this.extraRdocFiles);
        gemSpecWriter.appendFiles(this.extraFiles);
        gemSpecWriter.appendList("executables", this.executables);
        gemSpecWriter.appendList("extensions", this.extensions);
        gemSpecWriter.appendList("rdoc_options", this.rdocOptions);
        gemSpecWriter.appendList("require_paths", this.requirePaths);
        final File rubyFile;
        if (artifact.hasJarFile()) {
            gemSpecWriter.appendPlatform(this.platform == null
                    ? "java"
                    : this.platform);
            gemSpecWriter.appendJarfile(artifact.getJarFile(),
                                        artifact.getJarFile().getName());
            final File lib = new File(gemDir, "lib");
            lib.mkdirs();
            // need relative filename here
            rubyFile = new File(lib.getName(), artifact.getGemName() + ".rb");
            gemSpecWriter.appendFile(rubyFile);
        }
        else {
            rubyFile = null;
            gemSpecWriter.appendPlatform(this.platform);
        }

        ArtifactResolutionResult jarDependencyArtifacts = null;
        if (this.includeDependencies) {
            try {
                jarDependencyArtifacts = this.resolver.resolveTransitively(project.getArtifacts(),
                                                                           project.getArtifact(),
                    }
                }
                                                                           this.project.getManagedVersionMap(),
                                                                           this.localRepository,
                                                                           this.project.getRemoteArtifactRepositories(),
                                                                           this.metadata,
                                                                           new ArtifactFilter() {
                                                                               public boolean include(
                                                                                       final Artifact candidate) {
                                                                                   if (candidate == artifact) {
                                                                                       return true;
                                                                                   }
                                                                                   final boolean result = (candidate.getType()
                                                                                           .equals("jar") && ("compile".equals(candidate.getScope()) || "runtime".equals(candidate.getScope())));
                                                                                   return result;
                                                                               }

                                                                           });
                for (final Object element : jarDependencyArtifacts.getArtifacts()) {
                    final Artifact dependency = (Artifact) element;
                    getLog().info(" -- include -- " + dependency);
                    gemSpecWriter.appendJarfile(dependency.getFile(),
                                                dependency.getFile().getName());
                }
            }
            catch (final ArtifactResolutionException e) {
                e.printStackTrace();
            }
            catch (final ArtifactNotFoundException e) {
                e.printStackTrace();
            }
        }

        // TODO make it the maven way (src/main/ruby + src/test/ruby) or the
        // ruby way (lib + spec + test)
        // TODO make a loop or so ;-)
        final File libDir = new File(project.getBasedir(), "lib");
        final File generatorsDir = new File(project.getBasedir(), "generators");
        final File specDir = new File(project.getBasedir(), "spec");
        final File testDir = new File(project.getBasedir(), "test");

        if (libDir.exists()) {
            gemSpecWriter.appendPath("lib");
        }
        if (generatorsDir.exists()) {
            gemSpecWriter.appendPath("generators");
        }
        if (specDir.exists()) {
            gemSpecWriter.appendPath("spec");
            gemSpecWriter.appendTestPath("spec");
        }
        if (testDir.exists()) {
            gemSpecWriter.appendPath("test");
            gemSpecWriter.appendTestPath("test");
        }

        for (final Dependency dependency : project.getDependencies()) {
            if (!dependency.isOptional()
                    && dependency.getType().contains("gem")) {
                if (!dependency.getVersion().matches(".*[\\)\\]]$")) {
                    // it will adjust the artifact as well (in case of
                    // relocation)

                    Artifact arti = null;
                    try {
                        arti = this.artifactFactory.createArtifactWithClassifier(dependency.getGroupId(),
                                                                                 dependency.getArtifactId(),
                                                                                 dependency.getVersion(),
                                                                                 dependency.getScope(),
                                                                                 dependency.getClassifier());
                        projectFromArtifact(arti);
                        dependency.setGroupId(arti.getGroupId());
                        dependency.setArtifactId(arti.getArtifactId());
                    }
                    catch (final ProjectBuildingException e) {
                        throw new MojoExecutionException("error building project for "
                                + arti,
                                e);

                final String prefix = dependency.getGroupId()
                        .equals("rubygems") ? "" : dependency.getGroupId()
                        + ".";
                if ((Artifact.SCOPE_COMPILE + Artifact.SCOPE_RUNTIME).contains(dependency.getScope())) {
                    gemSpecWriter.appendDependency(prefix
                                                           + dependency.getArtifactId(),
                                                   dependency.getVersion());
                }
                else if ((Artifact.SCOPE_PROVIDED + Artifact.SCOPE_TEST).contains(dependency.getScope())) {
                    gemSpecWriter.appendDevelopmentDependency(prefix
                                                                      + dependency.getArtifactId(),
                                                              dependency.getVersion());
                }
                else {
                    // TODO put things into "requirements"
                }
            }
        }

        gemSpecWriter.close();

        gemSpecWriter.copy(gemDir);

        if (artifact.hasJarFile() && !rubyFile.exists()) {
            FileWriter writer = null;
            try {
                // need absolute filename here
                writer = new FileWriter(new File(gemDir, rubyFile.getPath()));

                writer.append("module ")
                        .append(titleizedClassname(project.getArtifactId()))
                        .append("\n");
                writer.append("  VERSION = '")
                        .append(artifact.getGemVersion())
                        .append("'\n");
                writer.append("  MAVEN_VERSION = '")
                        .append(project.getVersion())
                        .append("'\n");
                writer.append("end\n");
                writer.append("begin\n");
                writer.append("  require 'java'\n");
                writer.append("  require File.dirname(__FILE__) + '/")
                        .append(artifact.getJarFile().getName())
                        .append("'\n");
                if (jarDependencyArtifacts != null) {
                    for (final Object element : jarDependencyArtifacts.getArtifacts()) {
                        final Artifact dependency = (Artifact) element;
                        writer.append("  require File.dirname(__FILE__) + '/")
                                .append(dependency.getFile().getName())
                                .append("'\n");
                    }

                }
                writer.append("rescue LoadError\n");
                writer.append("  puts 'JAR-based gems require JRuby to load. Please visit www.jruby.org.'\n");
                writer.append("  raise\n");
                writer.append("end\n");
            }
            catch (final IOException e) {
                throw new MojoExecutionException("error writing ruby file", e);
            }
            finally {
                if (writer != null) {
                    try {
                        writer.close();
                    }
                    catch (final IOException ignore) {
                    }
                }
            }
        }

        final File localGemspec = new File(launchDirectory(), gemSpec.getName());

        // this.launchDirectory = gemDir;
        this.factory.newScriptFromResource(GEM_RUBY_COMMAND)
                .addArg("build", gemSpec)
                .executeIn(gemDir);
        // ("-S gem build " + gemSpec.getAbsolutePath());

        if ((!localGemspec.exists() || !FileUtils.contentEquals(localGemspec,
                                                                gemSpec))
                && this.gemspecOverwrite) {
            getLog().info("overwrite gemspec '" + localGemspec.getName() + "'");
            FileUtils.copyFile(gemSpec, localGemspec);
        }

        final StringBuilder gemFilename = new StringBuilder("rubygems".equals(artifact.getGroupId())
                ? ""
                : artifact.getGroupId() + ".").append(artifact.getArtifactId())
                .append("-")
                .append(artifact.getGemVersion())
                .append("java-gem".equals(artifact.getType()) ? "-java" : "")
                .append(".gem");

        FileUtils.copyFile(new File(gemDir, gemFilename.toString()),
                           artifact.getFile());
    }

    private String titleizedClassname(final String artifactId) {
        final StringBuilder name = new StringBuilder();
        for (final String part : artifactId.split("-")) {
            name.append(StringUtils.capitalise(part));
        }
        return name.toString();
    }

    @Override
    protected void executeWithGems() throws MojoExecutionException,
            RubyScriptException, IOException {
        // TODO Auto-generated method stub

    }
=======
	/**
	 * @parameter expression="${project.build.directory}"
	 */
	File buildDirectory;

	/**
	 * @parameter default-value="${gemspec}"
	 */
	File gemSpec;

	/**
	 * @parameter default-value="${gemspec.overwrite}"
	 */
	boolean gemspecOverwrite = false;

	/** @parameter */
	private String date;

	/** @parameter */
	private String extraRdocFiles;

	/** @parameter */
	private String extraFiles;

	/** @parameter */
	private String rdocOptions;

	/** @parameter */
	private String requirePaths;

	/** @parameter */
	private String rubyforgeProject;

	/** @parameter */
	private String rubygemsVersion;

	/** @parameter */
	private String requiredRubygemsVersion;

	/** @parameter */
	private String bindir;

	/** @parameter */
	private String requiredRubyVersion;

	/** @parameter */
	private String postInstallMessage;

	/** @parameter */
	private String executables;

	/** @parameter */
	private String extensions;

	/** @parameter */
	private String platform;

	/** @parameter default-value="gem_hook.rb"*/
	private String gemHook;

	private final Map relocationMap = new HashMap();

	/**
	 * @parameter expression="false"
	 */
	boolean includeDependencies;

	public void execute() throws MojoExecutionException, MojoFailureException {
		final MavenProject project = this.project;
		final GemArtifact artifact = new GemArtifact(project);
		try {
			if (this.gemSpec == null && project.getBasedir() != null && project.getBasedir().exists()) {
				// TODO generate the gemspec in the prepare-package phase so we
				// can use it separately
				build(project, artifact);
			} else {
				if (this.project.getBasedir() == null) {
					this.gemHome = new File(this.gemHome.getAbsolutePath().replace("/${project.basedir}/", "/"));
					this.gemPath = new File(this.gemPath.getAbsolutePath().replace("/${project.basedir}/", "/"));
				}
				if (this.gemSpec == null) {
				}
					for (final File f : this.launchDirectory().listFiles()) {
						if (f.getName().endsWith(".gemspec")) {
							if (this.gemSpec == null) {
								this.gemSpec = f;
							} else {
								throw new MojoFailureException("more than one gemspec file found, use -Dgemspec=... to specifiy one");
							}
						}
					}
					if (this.gemSpec == null) {
						throw new MojoFailureException("no gemspec file or pom found, use -Dgemspec=... to specifiy a gemspec file or '-f ...' to use a pom file");
					} else {
						getLog().info("use gemspec: " + this.gemSpec);
					}

				execute("-S gem build " + this.gemSpec.getAbsolutePath(), false);

				File gem = null;
				for (final File f : launchDirectory().listFiles()) {
					if (f.getName().endsWith(".gem")) {
						gem = f;
						break;
					}
				}
				if (project.getFile() != null && artifact.isGem()) {
					// only when the pom exist there will be an artifact
					FileUtils.copyFileIfModified(gem, artifact.getFile());
					gem.deleteOnExit();
				} else {
					// keep the gem where it when there is no buildDirectory
					if (this.buildDirectory.exists()) {
						FileUtils.copyFileIfModified(gem, new File(this.buildDirectory, gem.getName()));
						gem.deleteOnExit();
					}
				}
			}
		} catch (final IOException e) {
			throw new MojoExecutionException("error gemifing pom", e);
		}
	}

	private MavenProject projectFromArtifact(final Artifact artifact) throws ProjectBuildingException {
		final MavenProject project = this.builder.buildFromRepository(artifact, this.remoteRepositories, this.localRepository);
		if (project.getDistributionManagement() != null && project.getDistributionManagement().getRelocation() != null) {
			final Relocation reloc = project.getDistributionManagement().getRelocation();
			final String key = artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getType() + ":" + artifact.getVersion();
			artifact.setArtifactId(reloc.getArtifactId());
			artifact.setGroupId(reloc.getGroupId());
			if (reloc.getVersion() != null) {
				artifact.setVersion(reloc.getVersion());
			}
			this.relocationMap.put(key, artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getType() + ":" + artifact.getVersion());
			return projectFromArtifact(artifact);
		} else {
			return project;
		}
	}

	@SuppressWarnings( { "unchecked" })
	private void build(final MavenProject project, final GemArtifact artifact) throws MojoExecutionException, IOException {

		getLog().info("building gem for " + artifact + " . . .");
		getLog().info("include dependencies? " + this.includeDependencies);
		final File gemDir = new File(this.buildDirectory, artifact.getGemName());
		final File gemSpec = new File(gemDir, artifact.getGemName() + ".gemspec");
		final GemspecWriter gemSpecWriter = new GemspecWriter(gemSpec, project, artifact);

		if (this.date != null) {
			gemSpecWriter.append("date", Date.valueOf(this.date).toString());
		}
		gemSpecWriter.append("rubygems_version", this.rubygemsVersion);
		gemSpecWriter.append("required_rubygems_version", this.requiredRubygemsVersion);
		gemSpecWriter.append("required_ruby_version", this.requiredRubyVersion);
		gemSpecWriter.append("bindir", this.bindir);
		gemSpecWriter.append("post_install_message", this.postInstallMessage);

		gemSpecWriter.append("rubyforge_project", this.rubyforgeProject);
		gemSpecWriter.appendRdocFiles(this.extraRdocFiles);
		gemSpecWriter.appendFiles(this.extraFiles);
		gemSpecWriter.appendList("executables", this.executables);
		gemSpecWriter.appendList("extensions", this.extensions);
		gemSpecWriter.appendList("rdoc_options", this.rdocOptions);
		gemSpecWriter.appendList("require_paths", this.requirePaths);
		final File rubyFile;
		if (artifact.hasJarFile()) {
			gemSpecWriter.appendPlatform(this.platform == null ? "java" : this.platform);
			gemSpecWriter.appendJarfile(artifact.getJarFile(), artifact.getJarFile().getName());
			final File lib = new File(gemDir, "lib");
			lib.mkdirs();
			// need relative filename here
			rubyFile = new File(lib.getName(), artifact.getGemName() + ".rb");
			gemSpecWriter.appendFile(rubyFile);
		} else {
			rubyFile = null;
			gemSpecWriter.appendPlatform(this.platform);
		}

		ArtifactResolutionResult jarDependencyArtifacts = null;
		if (this.includeDependencies) {
			try {
				jarDependencyArtifacts = this.resolver.resolveTransitively(project.getArtifacts(), project.getArtifact(), this.project.getManagedVersionMap(),
						this.localRepository, this.remoteRepositories, this.metadata, new ArtifactFilter() {
							public boolean include(final Artifact candidate) {
								if (candidate == artifact) {
									return true;
								}
								final boolean result = (candidate.getType().equals("jar") && ("compile".equals(candidate.getScope()) || "runtime".equals(candidate
										.getScope())));
								return result;
							}

						});
				for (final Iterator each = jarDependencyArtifacts.getArtifacts().iterator(); each.hasNext();) {
					final Artifact dependency = (Artifact) each.next();
					getLog().info(" -- include -- " + dependency);
					gemSpecWriter.appendJarfile(dependency.getFile(), dependency.getFile().getName());
				}
			} catch (final ArtifactResolutionException e) {
				e.printStackTrace();
			} catch (final ArtifactNotFoundException e) {
				e.printStackTrace();
			}
		}

		// TODO make it the maven way (src/main/ruby + src/test/ruby) or the
		// ruby way (lib + spec + test)
		// TODO make a loop or so ;-)
		final File libDir = new File(project.getBasedir(), "lib");
		final File generatorsDir = new File(project.getBasedir(), "generators");
		final File specDir = new File(project.getBasedir(), "spec");
		final File testDir = new File(project.getBasedir(), "test");

		if (libDir.exists()) {
			gemSpecWriter.appendPath("lib");
		}
		if (generatorsDir.exists()) {
			gemSpecWriter.appendPath("generators");
		}
		if (specDir.exists()) {
			gemSpecWriter.appendPath("spec");
			gemSpecWriter.appendTestPath("spec");
		}
		if (testDir.exists()) {
			gemSpecWriter.appendPath("test");
			gemSpecWriter.appendTestPath("test");
		}

		for (final Dependency dependency : (List) project.getDependencies()) {
			if (!dependency.isOptional() && dependency.getType().contains("gem")) {
				if (!dependency.getVersion().matches(".*[\\)\\]]$")) {
					// it will adjust the artifact as well (in case of
					// relocation)

					Artifact arti = null;
					try {
						arti = this.artifactFactory.createArtifactWithClassifier(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), dependency
								.getScope(), dependency.getClassifier());
						projectFromArtifact(arti);
						dependency.setGroupId(arti.getGroupId());
						dependency.setArtifactId(arti.getArtifactId());
					} catch (final ProjectBuildingException e) {
						throw new MojoExecutionException("error building project for " + arti, e);
					}
				}

				final String prefix = dependency.getGroupId().equals("rubygems") ? "" : dependency.getGroupId() + ".";
				if ((Artifact.SCOPE_COMPILE + Artifact.SCOPE_RUNTIME).contains(dependency.getScope())) {
					gemSpecWriter.appendDependency(prefix + dependency.getArtifactId(), dependency.getVersion());
				} else if ((Artifact.SCOPE_PROVIDED + Artifact.SCOPE_TEST).contains(dependency.getScope())) {
					gemSpecWriter.appendDevelopmentDependency(prefix + dependency.getArtifactId(), dependency.getVersion());
				} else {
					// TODO put things into "requirements"
				}
			}
		}

		gemSpecWriter.close();

		gemSpecWriter.copy(gemDir);

		if (artifact.hasJarFile() && !rubyFile.exists()) {
			FileWriter writer = null;
			try {
				// need absolute filename here
				writer = new FileWriter(new File(gemDir, rubyFile.getPath()));

				writer.append("module ").append(titleizedClassname(project.getArtifactId())).append("\n");
				writer.append("  VERSION = '").append(artifact.getGemVersion()).append("'\n");
				writer.append("  MAVEN_VERSION = '").append(project.getVersion()).append("'\n");
				writer.append("end\n");
				writer.append("begin\n");
				writer.append("  require 'java'\n");
				writer.append("  require File.dirname(__FILE__) + '/").append(artifact.getJarFile().getName()).append("'\n");
				if (jarDependencyArtifacts != null) {
					for (final Iterator each = jarDependencyArtifacts.getArtifacts().iterator(); each.hasNext();) {
						final Artifact dependency = (Artifact) each.next();
						writer.append("  require File.dirname(__FILE__) + '/").append(dependency.getFile().getName()).append("'\n");
					}

				}
				writer.append("rescue LoadError\n");
				writer.append("  puts 'JAR-based gems require JRuby to load. Please visit www.jruby.org.'\n");
				writer.append("  raise\n");
				writer.append("end\n");
				writer.append("\n");
				writer.append("load File.dirname(__FILE__) + '/" + this.gemHook + "' if File.exists?( File.dirname(__FILE__) + '/" + this.gemHook +"')\n");
			} catch (final IOException e) {
				throw new MojoExecutionException("error writing ruby file", e);
			} finally {
				if (writer != null) {
					try {
						writer.close();
					} catch (final IOException ignore) {
					}
				}
			}
		}

		final File localGemspec = new File(launchDirectory(), gemSpec.getName());

		this.launchDirectory = gemDir;
		execute("-S gem build " + gemSpec.getAbsolutePath());

		if ((!localGemspec.exists() || !FileUtils.contentEquals(localGemspec, gemSpec)) && this.gemspecOverwrite) {
			getLog().info("overwrite gemspec '" + localGemspec.getName() + "'");
			FileUtils.copyFile(gemSpec, localGemspec);
		}

		final StringBuilder gemFilename = new StringBuilder("rubygems".equals(artifact.getGroupId()) ? "" : artifact.getGroupId() + ".").append(artifact.getArtifactId())
				.append("-").append(artifact.getGemVersion()).append("java-gem".equals(artifact.getType()) ? "-java" : "").append(".gem");

		FileUtils.copyFile(new File(gemDir, gemFilename.toString()), artifact.getFile());
	}

	private String titleizedClassname(final String artifactId) {
		final StringBuilder name = new StringBuilder();
		for (final String part : artifactId.split("-")) {
			name.append(StringUtils.capitalise(part));
		}
		return name.toString();
	}
>>>>>>> 49138a643914f6d1dc61084e9fedf0915bf3069a
}
Solution content
 */
public class PackageMojo extends AbstractGemMojo {

	/**
	 * @parameter expression="${project.build.directory}"
	 */
	File buildDirectory;

	/**
	 * @parameter default-value="${gemspec}"
	 */
	File gemSpec;

	/**
	 * @parameter default-value="${gemspec.overwrite}"
	 */
	boolean gemspecOverwrite = false;

	/** @parameter */
	private String date;

	/** @parameter */
	private String extraRdocFiles;

	/** @parameter */
	private String extraFiles;

	/** @parameter */
	private String rdocOptions;

	/** @parameter */
	private String requirePaths;

	/** @parameter */
	private String rubyforgeProject;

	/** @parameter */
	private String rubygemsVersion;

	/** @parameter */
	private String requiredRubygemsVersion;

	/** @parameter */
	private String bindir;

	/** @parameter */
	private String requiredRubyVersion;

	/** @parameter */
	private String postInstallMessage;

	/** @parameter */
	private String executables;

	/** @parameter */
	private String extensions;

	/** @parameter */
	private String platform;

	/** @parameter default-value="gem_hook.rb"*/
	private String gemHook;

	private final Map relocationMap = new HashMap();

	/**
	 * @parameter expression="false"
	 */
	boolean includeDependencies;

	public void executeJRuby() throws MojoExecutionException, MojoFailureException, RubyScriptException {
		final MavenProject project = this.project;
		final GemArtifact artifact = new GemArtifact(project);
		try {
			if (this.gemSpec == null && project.getBasedir() != null && project.getBasedir().exists()) {
				// TODO generate the gemspec in the prepare-package phase so we
				// can use it separately
				build(project, artifact);
			} else {
				if (this.project.getBasedir() == null) {
					this.gemHome = new File(this.gemHome.getAbsolutePath().replace("/${project.basedir}/", "/"));
					this.gemPath = new File(this.gemPath.getAbsolutePath().replace("/${project.basedir}/", "/"));
				}
				if (this.gemSpec == null) {
					for (final File f : this.launchDirectory().listFiles()) {
						if (f.getName().endsWith(".gemspec")) {
							if (this.gemSpec == null) {
								this.gemSpec = f;
							} else {
								throw new MojoFailureException("more than one gemspec file found, use -Dgemspec=... to specifiy one");
							}
						}
					}
					if (this.gemSpec == null) {
						throw new MojoFailureException("no gemspec file or pom found, use -Dgemspec=... to specifiy a gemspec file or '-f ...' to use a pom file");
					} else {
						getLog().info("use gemspec: " + this.gemSpec);
					}
				}

				this.factory.newScriptFromResource(GEM_RUBY_COMMAND)
				                         .addArg("build", this.gemSpec)
				                         .executeIn(launchDirectory());
                //execute("-S gem build " + this.gemSpec.getAbsolutePath(), false);

				File gem = null;
				for (final File f : launchDirectory().listFiles()) {
					if (f.getName().endsWith(".gem")) {
						gem = f;
						break;
					}
				}
				if (project.getFile() != null && artifact.isGem()) {
					// only when the pom exist there will be an artifact
					FileUtils.copyFileIfModified(gem, artifact.getFile());
					gem.deleteOnExit();
				} else {
					// keep the gem where it when there is no buildDirectory
					if (this.buildDirectory.exists()) {
						FileUtils.copyFileIfModified(gem, new File(this.buildDirectory, gem.getName()));
						gem.deleteOnExit();
					}
				}
			}
		} catch (final IOException e) {
			throw new MojoExecutionException("error gemifing pom", e);
		}
	}

	private MavenProject projectFromArtifact(final Artifact artifact) throws ProjectBuildingException {
		final MavenProject project = this.builder.buildFromRepository(artifact, this.project.getRemoteArtifactRepositories(), this.localRepository);
		if (project.getDistributionManagement() != null && project.getDistributionManagement().getRelocation() != null) {
			final Relocation reloc = project.getDistributionManagement().getRelocation();
			final String key = artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getType() + ":" + artifact.getVersion();
			artifact.setArtifactId(reloc.getArtifactId());
			artifact.setGroupId(reloc.getGroupId());
			if (reloc.getVersion() != null) {
				artifact.setVersion(reloc.getVersion());
			}
			this.relocationMap.put(key, artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getType() + ":" + artifact.getVersion());
			return projectFromArtifact(artifact);
		} else {
			return project;
		}
	}

	@SuppressWarnings( { "unchecked" })
	private void build(final MavenProject project, final GemArtifact artifact) throws MojoExecutionException, IOException, RubyScriptException {

		getLog().info("building gem for " + artifact + " . . .");
		getLog().info("include dependencies? " + this.includeDependencies);
		final File gemDir = new File(this.buildDirectory, artifact.getGemName());
		final File gemSpec = new File(gemDir, artifact.getGemName() + ".gemspec");
		final GemspecWriter gemSpecWriter = new GemspecWriter(gemSpec, project, artifact);

		if (this.date != null) {
			gemSpecWriter.append("date", Date.valueOf(this.date).toString());
		}
		gemSpecWriter.append("rubygems_version", this.rubygemsVersion);
		gemSpecWriter.append("required_rubygems_version", this.requiredRubygemsVersion);
		gemSpecWriter.append("required_ruby_version", this.requiredRubyVersion);
		gemSpecWriter.append("bindir", this.bindir);
		gemSpecWriter.append("post_install_message", this.postInstallMessage);

		gemSpecWriter.append("rubyforge_project", this.rubyforgeProject);
		gemSpecWriter.appendRdocFiles(this.extraRdocFiles);
		gemSpecWriter.appendFiles(this.extraFiles);
		gemSpecWriter.appendList("executables", this.executables);
		gemSpecWriter.appendList("extensions", this.extensions);
		gemSpecWriter.appendList("rdoc_options", this.rdocOptions);
		gemSpecWriter.appendList("require_paths", this.requirePaths);
		final File rubyFile;
		if (artifact.hasJarFile()) {
			gemSpecWriter.appendPlatform(this.platform == null ? "java" : this.platform);
			gemSpecWriter.appendJarfile(artifact.getJarFile(), artifact.getJarFile().getName());
			final File lib = new File(gemDir, "lib");
			lib.mkdirs();
			// need relative filename here
			rubyFile = new File(lib.getName(), artifact.getGemName() + ".rb");
			gemSpecWriter.appendFile(rubyFile);
		} else {
			rubyFile = null;
			gemSpecWriter.appendPlatform(this.platform);
		}

		ArtifactResolutionResult jarDependencyArtifacts = null;
		if (this.includeDependencies) {
			try {
				jarDependencyArtifacts = this.resolver.resolveTransitively(project.getArtifacts(), project.getArtifact(), this.project.getManagedVersionMap(),
						this.localRepository, this.project.getRemoteArtifactRepositories(), this.metadata, new ArtifactFilter() {
							public boolean include(final Artifact candidate) {
								if (candidate == artifact) {
									return true;
								}
								final boolean result = (candidate.getType().equals("jar") && ("compile".equals(candidate.getScope()) || "runtime".equals(candidate
										.getScope())));
								return result;
							}

						});
				for (final Iterator each = jarDependencyArtifacts.getArtifacts().iterator(); each.hasNext();) {
					final Artifact dependency = (Artifact) each.next();
					getLog().info(" -- include -- " + dependency);
					gemSpecWriter.appendJarfile(dependency.getFile(), dependency.getFile().getName());
				}
			} catch (final ArtifactResolutionException e) {
				e.printStackTrace();
			} catch (final ArtifactNotFoundException e) {
				e.printStackTrace();
			}
		}

		// TODO make it the maven way (src/main/ruby + src/test/ruby) or the
		// ruby way (lib + spec + test)
		// TODO make a loop or so ;-)
		final File libDir = new File(project.getBasedir(), "lib");
		final File generatorsDir = new File(project.getBasedir(), "generators");
		final File specDir = new File(project.getBasedir(), "spec");
		final File testDir = new File(project.getBasedir(), "test");

		if (libDir.exists()) {
			gemSpecWriter.appendPath("lib");
		}
		if (generatorsDir.exists()) {
			gemSpecWriter.appendPath("generators");
		}
		if (specDir.exists()) {
			gemSpecWriter.appendPath("spec");
			gemSpecWriter.appendTestPath("spec");
		}
		if (testDir.exists()) {
			gemSpecWriter.appendPath("test");
			gemSpecWriter.appendTestPath("test");
		}

		for (final Dependency dependency : project.getDependencies()) {
			if (!dependency.isOptional() && dependency.getType().contains("gem")) {
				if (!dependency.getVersion().matches(".*[\\)\\]]$")) {
					// it will adjust the artifact as well (in case of
					// relocation)

					Artifact arti = null;
					try {
						arti = this.artifactFactory.createArtifactWithClassifier(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), dependency
								.getScope(), dependency.getClassifier());
						projectFromArtifact(arti);
						dependency.setGroupId(arti.getGroupId());
						dependency.setArtifactId(arti.getArtifactId());
					} catch (final ProjectBuildingException e) {
						throw new MojoExecutionException("error building project for " + arti, e);
					}
				}

				final String prefix = dependency.getGroupId().equals("rubygems") ? "" : dependency.getGroupId() + ".";
				if ((Artifact.SCOPE_COMPILE + Artifact.SCOPE_RUNTIME).contains(dependency.getScope())) {
					gemSpecWriter.appendDependency(prefix + dependency.getArtifactId(), dependency.getVersion());
				} else if ((Artifact.SCOPE_PROVIDED + Artifact.SCOPE_TEST).contains(dependency.getScope())) {
					gemSpecWriter.appendDevelopmentDependency(prefix + dependency.getArtifactId(), dependency.getVersion());
				} else {
					// TODO put things into "requirements"
				}
			}
		}

		gemSpecWriter.close();

		gemSpecWriter.copy(gemDir);

		if (artifact.hasJarFile() && !rubyFile.exists()) {
			FileWriter writer = null;
			try {
				// need absolute filename here
				writer = new FileWriter(new File(gemDir, rubyFile.getPath()));

				writer.append("module ").append(titleizedClassname(project.getArtifactId())).append("\n");
				writer.append("  VERSION = '").append(artifact.getGemVersion()).append("'\n");
				writer.append("  MAVEN_VERSION = '").append(project.getVersion()).append("'\n");
				writer.append("end\n");
				writer.append("begin\n");
				writer.append("  require 'java'\n");
				writer.append("  require File.dirname(__FILE__) + '/").append(artifact.getJarFile().getName()).append("'\n");
				if (jarDependencyArtifacts != null) {
					for (final Iterator each = jarDependencyArtifacts.getArtifacts().iterator(); each.hasNext();) {
						final Artifact dependency = (Artifact) each.next();
						writer.append("  require File.dirname(__FILE__) + '/").append(dependency.getFile().getName()).append("'\n");
					}

				}
				writer.append("rescue LoadError\n");
				writer.append("  puts 'JAR-based gems require JRuby to load. Please visit www.jruby.org.'\n");
				writer.append("  raise\n");
				writer.append("end\n");
				writer.append("\n");
				writer.append("load File.dirname(__FILE__) + '/" + this.gemHook + "' if File.exists?( File.dirname(__FILE__) + '/" + this.gemHook +"')\n");
			} catch (final IOException e) {
				throw new MojoExecutionException("error writing ruby file", e);
			} finally {
				if (writer != null) {
					try {
						writer.close();
					} catch (final IOException ignore) {
					}
				}
			}
		}

		final File localGemspec = new File(launchDirectory(), gemSpec.getName());

//		this.launchDirectory = gemDir;
//		execute("-S gem build " + gemSpec.getAbsolutePath());
		this.factory.newScriptFromResource(GEM_RUBY_COMMAND)
		                 .addArg("build", gemSpec)
		                 .executeIn(gemDir);

		if ((!localGemspec.exists() || !FileUtils.contentEquals(localGemspec, gemSpec)) && this.gemspecOverwrite) {
			getLog().info("overwrite gemspec '" + localGemspec.getName() + "'");
			FileUtils.copyFile(gemSpec, localGemspec);
		}

		final StringBuilder gemFilename = new StringBuilder("rubygems".equals(artifact.getGroupId()) ? "" : artifact.getGroupId() + ".").append(artifact.getArtifactId())
				.append("-").append(artifact.getGemVersion()).append("java-gem".equals(artifact.getType()) ? "-java" : "").append(".gem");

		FileUtils.copyFile(new File(gemDir, gemFilename.toString()), artifact.getFile());
	}

	private String titleizedClassname(final String artifactId) {
		final StringBuilder name = new StringBuilder();
		for (final String part : artifactId.split("-")) {
			name.append(StringUtils.capitalise(part));
		}
		return name.toString();
	}

    @Override
    protected void executeWithGems() throws MojoExecutionException,
            RubyScriptException, IOException {
        // TODO Auto-generated method stub
        
    }
}
File
PackageMojo.java
Developer's decision
Manual
Kind of conflict
Annotation
Attribute
Comment
Method declaration
Method invocation
Chunk
Conflicting content
    extends AbstractGemMojo
{

<<<<<<< HEAD
    /**
     * The project base directory
     * 
     * @parameter expression="${basedir}"
     * @required
     * @readonly
     */
    protected File basedir;

    /**
     * The classpath elements of the project being tested.
     * 
     * @parameter expression="${project.testClasspathElements}"
     * @required
     * @readonly
     */
    protected List classpathElements;

    /**
     * The flag to skip tests (optional, defaults to "false")
     * 
     * @parameter expression="${maven.test.skip}" default-value="false"
     */
    protected boolean skipTests;

    /**
     * The flag to skip tests (optional, defaults to "false")
     * 
     * @parameter expression="${skipTests}" default-value="false"
     */
                try
                {

    /**
    protected boolean skip;

    /**
     * The directory containing the RSpec source files
     * 
     * @parameter expression="spec"
     */
    protected String specSourceDirectory;

    /**
     * The directory where the RSpec report will be written to
     * 
     * @parameter expression="${basedir}/target"
     * @required
     */
    protected String reportDirectory;
     * The name of the RSpec report (optional, defaults to "rspec-report.html")
     * 
     * @parameter expression="rspec-report.html"
     */
    protected String reportName;

    /**
     * List of system properties to set for the tests.
     * 
     * @parameter
     */
    protected Properties systemProperties;

    private final RSpecScriptFactory rspecScriptFactory = new RSpecScriptFactory();
    private final ShellScriptFactory shellScriptFactory = new ShellScriptFactory();

    private File specSourceDirectory()
    {
        return new File( launchDirectory(), this.specSourceDirectory );
    }

    @Override
    public void executeWithGems()
        throws MojoExecutionException, IOException, RubyScriptException
    {
        if ( this.skipTests || this.skip )
        {
            getLog().info( "Skipping RSpec tests" );
            return;
        }

        final File specSourceDirectory = specSourceDirectory();
        if ( !specSourceDirectory.exists() )
        {
            getLog().info( "Skipping RSpec tests since " + specSourceDirectory + " is missing" );
            return;
        }
        getLog().info( "Running RSpec tests from " + specSourceDirectory );

        final String reportPath = new File( this.reportDirectory, this.reportName ).getAbsolutePath();

        initScriptFactory( this.rspecScriptFactory, reportPath );
        initScriptFactory( this.shellScriptFactory, reportPath );

        try
        {
            this.rspecScriptFactory.emit();
        }
        catch ( final Exception e )
        {
            getLog().error( "error emitting .rb", e );
        }
        try
        {
            this.shellScriptFactory.emit();
        }
        catch ( final Exception e )
        {
            getLog().error( "error emitting .sh", e );
        }

        this.factory.newScript( this.rspecScriptFactory.getScriptFile() ).execute();

        final File reportFile = new File( reportPath );

        Reader in = null;
        try
        {
            in = new FileReader( reportFile );
            final BufferedReader reader = new BufferedReader( in );

            String line = null;

            while (( line = reader.readLine() ) != null)
            {
                if ( line.contains( "0 failures" ) )
                {
                    return;
                }
            }
        }
        catch ( final IOException e )
        {
            throw new MojoExecutionException( "Unable to read test report file: " + reportFile );
        }
        finally
        {
            if ( in != null )
            {
                    in.close();
                }
                catch ( final IOException e )
                {
                    throw new MojoExecutionException( e.getMessage() );
                }
            }
        }

        throw new MojoExecutionException( "There were test failures" );
    }

    private void initScriptFactory( final ScriptFactory factory, final String reportPath )
    {
        factory.setBaseDir( this.basedir.getAbsolutePath() );
        factory.setClasspathElements( this.classpathElements );
        factory.setOutputDir( new File( this.reportDirectory ) );
        factory.setReportPath( reportPath );
        factory.setSourceDir( specSourceDirectory().getAbsolutePath() );
        Properties props = this.systemProperties;
        if ( props == null )
        {
            props = new Properties();
        }
        factory.setSystemProperties( props );
    }
=======
	/**
	 * The project base directory
	 * 
	 * @parameter expression="${basedir}"
	 * @required
	 * @readonly
	 */
	protected File basedir;

	/**
	 * The classpath elements of the project being tested.
	 * 
	 * @parameter expression="${project.testClasspathElements}"
	 * @required
	 * @readonly
	 */
	protected List classpathElements;

	/**
	 * The flag to skip tests (optional, defaults to "false")
	 * 
	 * @parameter expression="${maven.test.skip}"
	 */
	protected boolean skipTests;

	/**
	 * The directory containing the RSpec source files
	 * 
	 * @parameter expression="spec"
	 */
	protected String specSourceDirectory;

	/**
	 * The directory where the RSpec report will be written to
	 * 
	 * @parameter expression="${basedir}/target"
	 * @required
	 */
	protected String outputDirectory;

	/**
	 * The name of the RSpec report (optional, defaults to "rspec-report.html")
	 * 
	 * @parameter expression="rspec-report.html"
	 */
	protected String reportName;

	/**
	 * List of system properties to set for the tests.
	 * 
	 * @parameter
	 */
	protected Properties systemProperties;

	private RSpecScriptFactory rspecScriptFactory = new RSpecScriptFactory();
	private ShellScriptFactory shellScriptFactory = new ShellScriptFactory();

	private File specSourceDirectory() {
		return new File(launchDirectory(), specSourceDirectory);
	}
	
	@Override
    public void execute() throws MojoExecutionException {
		if (skipTests) {
			getLog().info("Skipping RSpec tests");
			return;
		}
		
		super.execute();
	}

	@Override
	public void executeWithGems() throws MojoExecutionException {

		final File specSourceDirectory = specSourceDirectory();
		if (!specSourceDirectory.exists()) {
			getLog().info("Skipping RSpec tests since " + specSourceDirectory + " is missing");
			return;
		}
		getLog().info("Running RSpec tests from " + specSourceDirectory);

		String reportPath = new File(outputDirectory, reportName).getAbsolutePath();

		initScriptFactory(rspecScriptFactory, reportPath);
		initScriptFactory(shellScriptFactory, reportPath);

		try {
			rspecScriptFactory.emit();
		} catch (Exception e) {
			getLog().error("error emitting .rb", e);
		}
		try {
			shellScriptFactory.emit();
		} catch (Exception e) {
			getLog().error("error emitting .sh", e);
		}

		execute(rspecScriptFactory.getScriptFile().getPath());
		//execute(shellScriptFactory.getScriptFile().getPath());

		File reportFile = new File(reportPath);

		Reader in = null;
		try {
			in = new FileReader(reportFile);
			BufferedReader reader = new BufferedReader(in);

			String line = null;

			while ((line = reader.readLine()) != null) {
				if (line.contains("0 failures")) {
					return;
				}
			}
		} catch (IOException e) {
			throw new MojoExecutionException("Unable to read test report file: " + reportFile);
		} finally {
			if ( in != null ) {
				try {
					in.close();
				} catch (IOException e) {
					throw new MojoExecutionException( e.getMessage() );
				}
			}
		}

		throw new MojoExecutionException("There were test failures");
	}

	private void initScriptFactory(ScriptFactory factory, String reportPath) {
		factory.setBaseDir(basedir.getAbsolutePath());
		factory.setClasspathElements(classpathElements);
		factory.setOutputDir(new File( outputDirectory) );
		factory.setReportPath(reportPath);
		factory.setSourceDir(specSourceDirectory().getAbsolutePath());
		factory.setGemHome( this.gemHome );
		factory.setGemPath( this.gemPath );
		Properties props = systemProperties;
		if (props == null) {
			props = new Properties();
		}
		factory.setSystemProperties(props);
	}
>>>>>>> 49138a643914f6d1dc61084e9fedf0915bf3069a

}
Solution content
	 * @readonly
	 * @required
    extends AbstractGemMojo
{

	/**
	 * The project base directory
	 * 
	 * @parameter expression="${basedir}"
	 * @readonly
	 */
	protected File basedir;

	/**
	 * The classpath elements of the project being tested.
	 * 
	 * @parameter expression="${project.testClasspathElements}"
	 * @required
	 */
	protected List classpathElements;

	/**
	 * The flag to skip tests (optional, defaults to "false")
	 * 
	 * @parameter expression="${maven.test.skip}"
	 */
	protected boolean skipTests;

	/**
	 * The directory containing the RSpec source files
	 * 
	 * @parameter expression="spec"
	 */
	protected String specSourceDirectory;

	/**
	 * The directory where the RSpec report will be written to
	 * 
	 * @parameter expression="${basedir}/target"
	 * @required
	 */
	protected String outputDirectory;

	/**
	 * The name of the RSpec report (optional, defaults to "rspec-report.html")
	 * 
	 * @parameter expression="rspec-report.html"
	 */
	protected String reportName;

	/**
	 * List of system properties to set for the tests.
	 * 
	 * @parameter
	 */
	protected Properties systemProperties;

	private RSpecScriptFactory rspecScriptFactory = new RSpecScriptFactory();
	private ShellScriptFactory shellScriptFactory = new ShellScriptFactory();

	private File specSourceDirectory() {
		return new File(launchDirectory(), specSourceDirectory);
	}
	
	@Override
    public void execute() throws MojoExecutionException, MojoFailureException {
		if (skipTests) {
			getLog().info("Skipping RSpec tests");
			return;
		}
		
		super.execute();
	}

	@Override
	public void executeWithGems() throws MojoExecutionException, RubyScriptException, IOException {

		final File specSourceDirectory = specSourceDirectory();
		if (!specSourceDirectory.exists()) {
			getLog().info("Skipping RSpec tests since " + specSourceDirectory + " is missing");
			return;
		}
		getLog().info("Running RSpec tests from " + specSourceDirectory);

		String reportPath = new File(outputDirectory, reportName).getAbsolutePath();

		initScriptFactory(rspecScriptFactory, reportPath);
		initScriptFactory(shellScriptFactory, reportPath);

		try {
			rspecScriptFactory.emit();
		} catch (Exception e) {
			getLog().error("error emitting .rb", e);
		}
		try {
			shellScriptFactory.emit();
		} catch (Exception e) {
			getLog().error("error emitting .sh", e);
		}

		this.factory.newScript(this.rspecScriptFactory.getScriptFile() ).execute();
		//this.factory.newScript(shellScriptFactory.getScriptFile().getPath());

		File reportFile = new File(reportPath);

		Reader in = null;
		try {
			in = new FileReader(reportFile);
			BufferedReader reader = new BufferedReader(in);

			String line = null;

			while ((line = reader.readLine()) != null) {
				if (line.contains("0 failures")) {
					return;
				}
			}
		} catch (IOException e) {
			throw new MojoExecutionException("Unable to read test report file: " + reportFile);
		} finally {
			if ( in != null ) {
				try {
					in.close();
				} catch (IOException e) {
					throw new MojoExecutionException( e.getMessage() );
				}
			}
		}

		throw new MojoExecutionException("There were test failures");
	}

	private void initScriptFactory(ScriptFactory factory, String reportPath) {
		factory.setBaseDir(basedir.getAbsolutePath());
		factory.setClasspathElements(classpathElements);
		factory.setOutputDir(new File( outputDirectory) );
		factory.setReportPath(reportPath);
		factory.setSourceDir(specSourceDirectory().getAbsolutePath());
		factory.setGemHome( this.gemHome );
		factory.setGemPath( this.gemPath );
		Properties props = systemProperties;
		if (props == null) {
			props = new Properties();
		}
		factory.setSystemProperties(props);
	}

}
File
RSpecMojo.java
Developer's decision
Manual
Kind of conflict
Annotation
Attribute
Comment
Method declaration
Method invocation