Search in sources :

Example 86 with CommandLineException

use of org.codehaus.plexus.util.cli.CommandLineException in project maven-scm by apache.

the class PerforceWhereCommand method getDepotLocation.

/**
 * @param filepath an absolute file path
 * @return the absolute location of the given file within the Perforce repository or null if the file
 *         does not exist in a mapping within the current clientspec.
 */
public String getDepotLocation(String filepath) {
    if (!PerforceScmProvider.isLive()) {
        return null;
    }
    InputStreamReader isReader = null;
    InputStreamReader isReaderErr = null;
    try {
        Commandline command = PerforceScmProvider.createP4Command(repo, null);
        command.createArg().setValue("where");
        command.createArg().setValue(filepath);
        if (logger.isDebugEnabled()) {
            logger.debug(PerforceScmProvider.clean("Executing: " + command.toString()));
        }
        Process proc = command.execute();
        isReader = new InputStreamReader(proc.getInputStream());
        isReaderErr = new InputStreamReader(proc.getErrorStream());
        BufferedReader br = new BufferedReader(isReader);
        BufferedReader brErr = new BufferedReader(isReaderErr);
        String line;
        String path = null;
        while ((line = br.readLine()) != null) {
            if (line.indexOf("not in client view") != -1) {
                // uh oh, something bad is happening
                if (logger.isErrorEnabled()) {
                    logger.error(line);
                }
                return null;
            }
            if (line.indexOf("is not under") != -1) {
                // uh oh, something bad is happening
                if (logger.isErrorEnabled()) {
                    logger.error(line);
                }
                return null;
            }
            if (logger.isDebugEnabled()) {
                logger.debug(line);
            }
            // verify that "//" appears twice in the line
            path = line.substring(0, line.lastIndexOf("//") - 1);
        }
        // Check for errors
        while ((line = brErr.readLine()) != null) {
            if (line.indexOf("not in client view") != -1) {
                // uh oh, something bad is happening
                if (logger.isErrorEnabled()) {
                    logger.error(line);
                }
                return null;
            }
            if (line.indexOf("is not under") != -1) {
                // uh oh, something bad is happening
                if (logger.isErrorEnabled()) {
                    logger.error(line);
                }
                return null;
            }
            if (logger.isDebugEnabled()) {
                logger.debug(line);
            }
        }
        return path;
    } catch (CommandLineException e) {
        if (logger.isErrorEnabled()) {
            logger.error(e);
        }
        throw new RuntimeException(e.getLocalizedMessage());
    } catch (IOException e) {
        if (logger.isErrorEnabled()) {
            logger.error(e);
        }
        throw new RuntimeException(e.getLocalizedMessage());
    } finally {
        IOUtil.close(isReader);
        IOUtil.close(isReaderErr);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Commandline(org.codehaus.plexus.util.cli.Commandline) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 87 with CommandLineException

use of org.codehaus.plexus.util.cli.CommandLineException in project maven-scm by apache.

the class GitCommandLineUtils method execute.

public static int execute(Commandline cl, CommandLineUtils.StringStreamConsumer stdout, CommandLineUtils.StringStreamConsumer stderr, ScmLogger logger) throws ScmException {
    if (logger.isInfoEnabled()) {
        logger.info("Executing: " + cl);
        logger.info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
    }
    int exitCode;
    try {
        exitCode = CommandLineUtils.executeCommandLine(cl, stdout, stderr);
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing command.", ex);
    }
    return exitCode;
}
Also used : ScmException(org.apache.maven.scm.ScmException) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 88 with CommandLineException

use of org.codehaus.plexus.util.cli.CommandLineException in project maven-scm by apache.

the class GitScmTestUtils method getScmUrl.

public static String getScmUrl(File repositoryRootFile, String provider) throws CommandLineException {
    String repositoryRoot = repositoryRootFile.getAbsolutePath();
    // TODO: some way without a custom cygwin sys property?
    if ("true".equals(System.getProperty("cygwin"))) {
        Commandline cl = new Commandline();
        cl.setExecutable("cygpath");
        cl.createArg().setValue("--unix");
        cl.createArg().setValue(repositoryRoot);
        CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
        int exitValue = CommandLineUtils.executeCommandLine(cl, stdout, null);
        if (exitValue != 0) {
            throw new CommandLineException("Unable to convert cygwin path, exit code = " + exitValue);
        }
        repositoryRoot = stdout.getOutput().trim();
    } else if (Os.isFamily("windows")) {
        repositoryRoot = "/" + StringUtils.replace(repositoryRoot, "\\", "/");
    }
    return "scm:" + provider + ":file://" + repositoryRoot;
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 89 with CommandLineException

use of org.codehaus.plexus.util.cli.CommandLineException in project appbundle-maven-plugin by federkasten.

the class CreateApplicationBundleMojo method execute.

/**
 * Bundle project as a Mac OS X application bundle.
 *
 * @throws MojoExecutionException If an unexpected error occurs during
 * packaging of the bundle.
 */
public void execute() throws MojoExecutionException {
    // 1. Create and set up directories
    getLog().info("Creating and setting up the bundle directories");
    buildDirectory.mkdirs();
    File bundleDir = new File(buildDirectory, bundleName + ".app");
    bundleDir.mkdirs();
    File contentsDir = new File(bundleDir, "Contents");
    contentsDir.mkdirs();
    File resourcesDir = new File(contentsDir, "Resources");
    resourcesDir.mkdirs();
    File javaDirectory = new File(contentsDir, "Java");
    javaDirectory.mkdirs();
    File macOSDirectory = new File(contentsDir, "MacOS");
    macOSDirectory.mkdirs();
    // 2. Copy in the native java application stub
    getLog().info("Copying the native Java Application Stub");
    File launcher = new File(macOSDirectory, javaLauncherName);
    launcher.setExecutable(true);
    FileOutputStream launcherStream = null;
    try {
        launcherStream = new FileOutputStream(launcher);
    } catch (FileNotFoundException ex) {
        throw new MojoExecutionException("Could not copy file to directory " + launcher, ex);
    }
    InputStream launcherResourceStream = this.getClass().getResourceAsStream(javaLauncherName);
    try {
        IOUtil.copy(launcherResourceStream, launcherStream);
    } catch (IOException ex) {
        throw new MojoExecutionException("Could not copy file " + javaLauncherName + " to directory " + macOSDirectory, ex);
    }
    // 3.Copy icon file to the bundle if specified
    if (iconFile != null) {
        File f = searchFile(iconFile, project.getBasedir());
        if (f != null && f.exists() && f.isFile()) {
            getLog().info("Copying the Icon File");
            try {
                FileUtils.copyFileToDirectory(f, resourcesDir);
            } catch (IOException ex) {
                throw new MojoExecutionException("Error copying file " + iconFile + " to " + resourcesDir, ex);
            }
        } else {
            throw new MojoExecutionException(String.format("Could not locate iconFile '%s'", iconFile));
        }
    }
    // 4. Resolve and copy in all dependencies from the pom
    getLog().info("Copying dependencies");
    List<String> files = copyDependencies(javaDirectory);
    if (additionalBundledClasspathResources != null && !additionalBundledClasspathResources.isEmpty()) {
        files.addAll(copyAdditionalBundledClasspathResources(javaDirectory, "lib", additionalBundledClasspathResources));
    }
    // 5. Check if JRE should be embedded. Check JRE path. Copy JRE
    if (jrePath != null) {
        File f = new File(jrePath);
        if (f.exists() && f.isDirectory()) {
            // Check if the source folder is a jdk-home
            File pluginsDirectory = new File(contentsDir, "PlugIns/JRE/Contents/Home/jre");
            pluginsDirectory.mkdirs();
            File sourceFolder = new File(jrePath, "Contents/Home");
            if (new File(jrePath, "Contents/Home/jre").exists()) {
                sourceFolder = new File(jrePath, "Contents/Home/jre");
            }
            try {
                getLog().info("Copying the JRE Folder from : [" + sourceFolder + "] to PlugIn folder: [" + pluginsDirectory + "]");
                FileUtils.copyDirectoryStructure(sourceFolder, pluginsDirectory);
                File binFolder = new File(pluginsDirectory, "bin");
                // Setting execute permissions on executables in JRE
                for (String filename : binFolder.list()) {
                    new File(binFolder, filename).setExecutable(true, false);
                }
                new File(pluginsDirectory, "lib/jspawnhelper").setExecutable(true, false);
                embeddJre = true;
            } catch (IOException ex) {
                throw new MojoExecutionException("Error copying folder " + f + " to " + pluginsDirectory, ex);
            }
        } else {
            getLog().warn("JRE not found check jrePath setting in pom.xml");
        }
    } else if (jreFullPath != null) {
        getLog().info("JRE Full path is used [" + jreFullPath + "]");
        embeddJre = true;
    }
    // 6. Create and write the Info.plist file
    getLog().info("Writing the Info.plist file");
    File infoPlist = new File(bundleDir, "Contents" + File.separator + "Info.plist");
    this.writeInfoPlist(infoPlist, files);
    // 7. Copy specified additional resources into the top level directory
    getLog().info("Copying additional resources");
    if (additionalResources != null && !additionalResources.isEmpty()) {
        this.copyResources(buildDirectory, additionalResources);
    }
    // 7. Make the stub executable
    if (!SystemUtils.IS_OS_WINDOWS) {
        getLog().info("Making stub executable");
        Commandline chmod = new Commandline();
        try {
            chmod.setExecutable("chmod");
            chmod.createArgument().setValue("755");
            chmod.createArgument().setValue(launcher.getAbsolutePath());
            chmod.execute();
        } catch (CommandLineException e) {
            throw new MojoExecutionException("Error executing " + chmod + " ", e);
        }
    } else {
        getLog().warn("The stub was created without executable file permissions for UNIX systems");
    }
    // 8. Create the DMG file
    if (generateDiskImageFile) {
        if (SystemUtils.IS_OS_MAC) {
            getLog().info("Generating the Disk Image file");
            Commandline dmg = new Commandline();
            try {
                // user wants /Applications symlink in the resulting disk image
                if (includeApplicationsSymlink) {
                    createApplicationsSymlink();
                }
                dmg.setExecutable("hdiutil");
                dmg.createArgument().setValue("create");
                dmg.createArgument().setValue("-srcfolder");
                dmg.createArgument().setValue(buildDirectory.getAbsolutePath());
                dmg.createArgument().setValue(diskImageFile.getAbsolutePath());
                try {
                    dmg.execute().waitFor();
                } catch (InterruptedException ex) {
                    throw new MojoExecutionException("Thread was interrupted while creating DMG " + diskImageFile, ex);
                } finally {
                    if (includeApplicationsSymlink) {
                        removeApplicationsSymlink();
                    }
                }
            } catch (CommandLineException ex) {
                throw new MojoExecutionException("Error creating disk image " + diskImageFile, ex);
            }
            if (diskImageInternetEnable) {
                getLog().info("Enabling the Disk Image file for internet");
                try {
                    Commandline internetEnableCommand = new Commandline();
                    internetEnableCommand.setExecutable("hdiutil");
                    internetEnableCommand.createArgument().setValue("internet-enable");
                    internetEnableCommand.createArgument().setValue("-yes");
                    internetEnableCommand.createArgument().setValue(diskImageFile.getAbsolutePath());
                    internetEnableCommand.execute();
                } catch (CommandLineException ex) {
                    throw new MojoExecutionException("Error internet enabling disk image: " + diskImageFile, ex);
                }
            }
            projectHelper.attachArtifact(project, "dmg", null, diskImageFile);
        }
        if (SystemUtils.IS_OS_LINUX) {
            getLog().info("Generating the Disk Image file");
            Commandline linux_dmg = new Commandline();
            try {
                linux_dmg.setExecutable("genisoimage");
                linux_dmg.createArgument().setValue("-V");
                linux_dmg.createArgument().setValue(bundleName);
                linux_dmg.createArgument().setValue("-D");
                linux_dmg.createArgument().setValue("-R");
                linux_dmg.createArgument().setValue("-apple");
                linux_dmg.createArgument().setValue("-no-pad");
                linux_dmg.createArgument().setValue("-o");
                linux_dmg.createArgument().setValue(diskImageFile.getAbsolutePath());
                linux_dmg.createArgument().setValue(buildDirectory.getAbsolutePath());
                try {
                    linux_dmg.execute().waitFor();
                } catch (InterruptedException ex) {
                    throw new MojoExecutionException("Thread was interrupted while creating DMG " + diskImageFile, ex);
                }
            } catch (CommandLineException ex) {
                throw new MojoExecutionException("Error creating disk image " + diskImageFile + " genisoimage probably missing", ex);
            }
            projectHelper.attachArtifact(project, "dmg", null, diskImageFile);
        } else {
            getLog().warn("Disk Image file cannot be generated in non Mac OS X and Linux environments");
        }
    }
    getLog().info("App Bundle generation finished");
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Commandline(org.codehaus.plexus.util.cli.Commandline) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) File(java.io.File) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 90 with CommandLineException

use of org.codehaus.plexus.util.cli.CommandLineException in project maven-plugins by apache.

the class SvnInfoCommandExpanded method executeInfoCommand.

private InfoScmResult executeInfoCommand(final Commandline cl) throws ScmException {
    SvnInfoConsumer consumer = new SvnInfoConsumer();
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    if (getLogger().isInfoEnabled()) {
        getLogger().info("Executing: " + SvnCommandLineUtils.cryptPassword(cl));
        getLogger().info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
    }
    int exitCode;
    try {
        exitCode = SvnCommandLineUtils.execute(cl, consumer, stderr, getLogger());
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing command.", ex);
    }
    if (exitCode != 0) {
        return new InfoScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
    }
    return new InfoScmResult(cl.toString(), consumer.getInfoItems());
}
Also used : ScmException(org.apache.maven.scm.ScmException) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) SvnCommandLineUtils(org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils) InfoScmResult(org.apache.maven.scm.command.info.InfoScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Aggregations

CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)94 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)76 Commandline (org.codehaus.plexus.util.cli.Commandline)67 ScmException (org.apache.maven.scm.ScmException)56 IOException (java.io.IOException)20 SvnCommandLineUtils (org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils)18 File (java.io.File)14 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)13 BufferedReader (java.io.BufferedReader)6 BlameScmResult (org.apache.maven.scm.command.blame.BlameScmResult)6 StatusScmResult (org.apache.maven.scm.command.status.StatusScmResult)6 SvnScmProviderRepository (org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository)6 InputStreamReader (java.io.InputStreamReader)5 ChangeLogScmResult (org.apache.maven.scm.command.changelog.ChangeLogScmResult)5 ChangeLogSet (org.apache.maven.scm.command.changelog.ChangeLogSet)5 CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)5 StreamConsumer (org.codehaus.plexus.util.cli.StreamConsumer)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 StringTokenizer (java.util.StringTokenizer)4 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)4