Package hudson.util

Examples of hudson.util.ArgumentListBuilder


     * arguments.
     */
    private ArgumentListBuilder buildCmdLine(AbstractBuild build,
                                             Launcher launcher, BuildListener listener)
        throws IllegalArgumentException, InterruptedException, IOException {
        ArgumentListBuilder args = new ArgumentListBuilder();

//    DescriptorImpl descriptor = (DescriptorImpl) getDescriptor();

        EnvVars env = build.getEnvironment(listener);
        env.overrideAll(build.getBuildVariables());

        SbtInstallation sbt = getSbt();
        if (sbt == null) {
            throw new IllegalArgumentException("sbt-launch.jar not found");
        } else {
            sbt = sbt.forNode(Computer.currentComputer().getNode(), listener);
            sbt = sbt.forEnvironment(env);

            String launcherPath = sbt.getSbtLaunchJar(launcher);

            if (launcherPath == null) {
                throw new IllegalArgumentException("sbt-launch.jar not found");
            }

            if (!launcher.isUnix()) {
                args.add("cmd.exe", "/C");
                // add an extra set of quotes after cmd/c to handle paths with spaces in Windows
                args.add("\"");
            }

            // java
            String javaExePath;

            JDK jdk = build.getProject().getJDK();
            Computer computer = Computer.currentComputer();
            if (computer != null && jdk != null) { // just in case were not in a build
                // use node specific installers, etc
                jdk = jdk.forNode(computer.getNode(), listener);
            }

            if (jdk != null) {
                javaExePath = jdk.getHome() + "/bin/java";
            } else {
                javaExePath = "java";
            }
            args.add(javaExePath);

            splitAndAddArgs(env.expand(jvmFlags), args);
            splitAndAddArgs(env.expand(sbt.getSbtArguments()), args);
            splitAndAddArgs(env.expand(sbtFlags), args);

            // additionnal args from .sbtopts file
            FilePath sbtopts = build.getProject().getWorkspace().child(".sbtopts");
            if (sbtopts.exists()) {
                String argsToSplit = sbtopts.readToString();
                if (!StringUtils.isBlank(argsToSplit)) {
                    String[] split = argsToSplit.split("\\s+");
                    for (String flag : split) {
                        if (flag.startsWith("-J")) {
                          args.add(flag.substring(2));
                        } else {
                          args.add(flag);
                        }
                    }
                }
            }

            args.add("-jar");

            args.add(launcherPath);

            String subActions = new StrSubstitutor(env).replace(actions);
            for (String action : split(subActions)) {
                args.add(action);
            }

            if (!launcher.isUnix()) {
                args.add("\"");
            }
        }

        return args;
    }
View Full Code Here


    }

    @Test
    public void testJoin() throws InterruptedException, IOException {
        if (flog.isFlogInstalled(launcher, environment, workspace)) {
            ArgumentListBuilder arguments = flog.arguments("-ad", new File("command_line_parser.rb").getAbsolutePath());
            ByteArrayOutputStream out = flog.launch(arguments, launcher, environment, workspace);
            assertNotNull(out);
            assertTrue(out.toString().contains("CommandLineParser::parse"));
        }
    }
View Full Code Here

            }

            FilePath[] rubyFiles = getRubyFiles(workspace, buildRootDir, relativePath, launcher);
            for (FilePath rubyFile : rubyFiles) {
                String rubyFilePath = rubyFile.toURI().getPath();
                ArgumentListBuilder arguments = arguments("-ad", rubyFilePath);

                ByteArrayOutputStream out = launch(arguments, launcher, environment, workspace);
                if (out == null) {
                    results.clear();
                    return results;
View Full Code Here

        return result >= 0 ? out : null;
    }

    public ArgumentListBuilder arguments(String... args) {
        ArgumentListBuilder flogArguments = new ArgumentListBuilder();
        flogArguments.add("flog");
        for (String arg : args) {
            flogArguments.add(arg);
        }

        return flogArguments;
    }
View Full Code Here

                - http://java.sun.com/j2se/1.5.0/sdksilent.html
                - http://java.sun.com/j2se/1.4.2/docs/guide/plugin/developer_guide/silent.html
             */
            String logFile = jdkBundle+".install.log";

            ArgumentListBuilder args = new ArgumentListBuilder();
            args.add(jdkBundle);
            args.add("/s");
            // according to http://community.acresso.com/showthread.php?t=83301, \" is the trick to quote values with whitespaces.
            // Oh Windows, oh windows, why do you have to be so difficult?
            args.add("/v/qn REBOOT=Suppress INSTALLDIR=\\\""+ expectedLocation +"\\\" /L \\\""+logFile+"\\\"");

            int r = launcher.launch().cmds(args).stdout(out)
                    .pwd(new FilePath(launcher.getChannel(), expectedLocation)).join();
            if (r != 0) {
                out.println(Messages.JDKInstaller_FailedToInstallJDK(r));
View Full Code Here

            String normalizedTarget = targets
                    .substring(startIndex, endIndex)
                    .replaceAll("[\t\r\n]+"," ");

            ArgumentListBuilder args = new ArgumentListBuilder();
            MavenInstallation mi = getMaven();
            if(mi==null) {
                String execName = build.getWorkspace().act(new DecideDefaultMavenCommand(normalizedTarget));
                args.add(execName);
            } else {
                mi = mi.forNode(Computer.currentComputer().getNode(), listener);
              mi = mi.forEnvironment(env);
                String exec = mi.getExecutable(launcher);
                if(exec==null) {
                    listener.fatalError(Messages.Maven_NoExecutable(mi.getHome()));
                    return false;
                }
                args.add(exec);
            }
            if(pom!=null)
                args.add("-f",pom);

            Set<String> sensitiveVars = build.getSensitiveBuildVariables();

            args.addKeyValuePairs("-D",build.getBuildVariables(),sensitiveVars);
            args.addKeyValuePairsFromPropertyString("-D",properties,vr,sensitiveVars);
            if (usesPrivateRepository())
                args.add("-Dmaven.repo.local=" + build.getWorkspace().child(".repository"));
            args.addTokenized(normalizedTarget);
            wrapUpArguments(args,normalizedTarget,build,launcher,listener);

            buildEnvVars(env, mi);

            try {
View Full Code Here

        return antOpts;
    }

    @Override
    public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
        ArgumentListBuilder args = new ArgumentListBuilder();

        EnvVars env = build.getEnvironment(listener);
       
        AntInstallation ai = getAnt();
        if(ai==null) {
            args.add(launcher.isUnix() ? "ant" : "ant.bat");
        } else {
            ai = ai.forNode(Computer.currentComputer().getNode(), listener);
            ai = ai.forEnvironment(env);
            String exe = ai.getExecutable(launcher);
            if (exe==null) {
                listener.fatalError(Messages.Ant_ExecutableNotFound(ai.getName()));
                return false;
            }
            args.add(exe);
        }

        VariableResolver<String> vr = build.getBuildVariableResolver();

        String buildFile = env.expand(this.buildFile);
        String targets = Util.replaceMacro(env.expand(this.targets), vr);
       
        FilePath buildFilePath = buildFilePath(build.getModuleRoot(), buildFile, targets);

        if(!buildFilePath.exists()) {
            // because of the poor choice of getModuleRoot() with CVS/Subversion, people often get confused
            // with where the build file path is relative to. Now it's too late to change this behavior
            // due to compatibility issue, but at least we can make this less painful by looking for errors
            // and diagnosing it nicely. See HUDSON-1782

            // first check if this appears to be a valid relative path from workspace root
            FilePath buildFilePath2 = buildFilePath(build.getWorkspace(), buildFile, targets);
            if(buildFilePath2.exists()) {
                // This must be what the user meant. Let it continue.
                buildFilePath = buildFilePath2;
            } else {
                // neither file exists. So this now really does look like an error.
                listener.fatalError("Unable to find build script at "+buildFilePath);
                return false;
            }
        }

        if(buildFile!=null) {
            args.add("-file", buildFilePath.getName());
        }

        Set<String> sensitiveVars = build.getSensitiveBuildVariables();

        args.addKeyValuePairs("-D",build.getBuildVariables(),sensitiveVars);

        args.addKeyValuePairsFromPropertyString("-D",properties,vr,sensitiveVars);

        args.addTokenized(targets.replaceAll("[\t\r\n]+"," "));

        if(ai!=null)
            env.put("ANT_HOME",ai.getHome());
        if(antOpts!=null)
            env.put("ANT_OPTS",env.expand(antOpts));

        if(!launcher.isUnix()) {
            args = args.toWindowsCommand();
            // For some reason, ant on windows rejects empty parameters but unix does not.
            // Add quotes for any empty parameter values:
            List<String> newArgs = new ArrayList<String>(args.toList());
            newArgs.set(newArgs.size() - 1, newArgs.get(newArgs.size() - 1).replaceAll(
                    "(?<= )(-D[^\" ]+)= ", "$1=\"\" "));
            args = new ArgumentListBuilder(newArgs.toArray(new String[newArgs.size()]));
        }

        long startTime = System.currentTimeMillis();
        try {
            AntConsoleAnnotator aca = new AntConsoleAnnotator(listener.getLogger(),build.getCharset());
View Full Code Here

                return newLocalChannel();

            String javaExe = System.getProperty("java.home") + "/bin/java";
            File slaveJar = Which.jarFile(Launcher.class);

            ArgumentListBuilder args = new ArgumentListBuilder().add(javaExe);
            if(slaveJar.isFile())
                args.add("-jar").add(slaveJar);
            else // in production code this never happens, but during debugging this is convenientud   
                args.add("-cp").add(slaveJar).add(hudson.remoting.Launcher.class.getName());

            if(rootPassword==null) {
                // try sudo, in the hope that the user has the permission to do so without password
                return new LocalLauncher(listener).launchChannel(
                        args.prepend(sudoExe()).toCommandArray(),
                        listener.getLogger(), null, Collections.<String, String>emptyMap());
            } else {
                // try sudo with the given password. Also run in pfexec so that we can elevate the privileges
                Process proc = sudoWithPass(args);
                return Channels.forProcess(args.toStringWithQuote(), Computer.threadPoolForRemoting, proc,
                        listener.getLogger() );
            }
        }
View Full Code Here

      throws InterruptedException, IOException {

    FilePath moduleRoot = build.getModuleRoot();
    this.deleteDebugLog(moduleRoot);

    ArgumentListBuilder args = new ArgumentListBuilder();
    args.add(getDescriptor().getVm());
    addVmParametersTo(args);
    args.add(this.getImageFile(moduleRoot));
    args.add(this.getStartUpScript(moduleRoot));

   return this.startVm(build, launcher, listener, args);
  }
View Full Code Here

    if (this.needToCopyImage()
        && (!copyImage(listener, moduleRoot) || !copyChanges(listener, moduleRoot))) {
      return false;
    }

    ArgumentListBuilder args = new ArgumentListBuilder();
    args.add(getDescriptor().getVm());
    addVmParametersTo(args);
    args.add(getImageToBuildAgainst(moduleRoot));

    Map<String, String> env = build.getEnvironment(listener);
    File script = this.getStartUpScript();
    try {
      args.add(script);
      return this.startVm(build, launcher, listener, args, env);
    } finally {
      //TODO uncomment
      //if (!script.delete()) {
      //  listener.getLogger().println("could not delete temp file");
View Full Code Here

TOP

Related Classes of hudson.util.ArgumentListBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.