/** * Run the command. * @param cmd the command line to use. * @param out the output stream handler to use. * @return the exit code of the command. */ protected int runCmd(Commandline cmd, ExecuteStreamHandler out) { try { Project aProj = getProject(); Execute exe = new Execute(out); exe.setAntRun(aProj); exe.setWorkingDirectory(aProj.getBaseDir()); exe.setCommandline(cmd.getCommandline()); return exe.execute(); } catch (IOException e) { String msg = "Failed executing: " + cmd.toString() + ". Exception: " + e.getMessage(); throw new BuildException(msg, getLocation()); } }
/** * Runs Ant glob expansion. * * @return * A set of relative file names from the base directory. */ @Nonnull private static String[] glob(File dir, String includes, String excludes, boolean defaultExcludes) throws IOException { if(isAbsolute(includes)) throw new IOException("Expecting Ant GLOB pattern, but saw '"+includes+"'. See http://ant.apache.org/manual/Types/fileset.html for syntax"); FileSet fs = Util.createFileSet(dir,includes,excludes); fs.setDefaultexcludes(defaultExcludes); DirectoryScanner ds; try { ds = fs.getDirectoryScanner(new Project()); } catch (BuildException x) { throw new IOException(x.getMessage()); } String[] files = ds.getIncludedFiles(); return files; }
/** * Returns the nested exception, if any. * * @return the nested exception, or <code>null</code> if no * exception is associated with this one * @deprecated Use {@link #getCause} instead. */ @Deprecated public Throwable getException() { return getCause(); }
/** * check the file given by getFile(). */ private void doit() { Commandline commandLine = new Commandline(); // build the command line from what we got the format is // ccm co /t .. files // as specified in the CCM.EXE help commandLine.setExecutable(getCcmCommand()); commandLine.createArgument().setValue(getCcmAction()); checkOptions(commandLine); int result = run(commandLine); if (Execute.isFailure(result)) { throw new BuildException("Failed executing: " + commandLine, getLocation()); } }
/** * Sets configuration file. * @param configuration the configuration file, URL, or resource to use */ public void setConfig(String configuration) { if (config != null) { throw new BuildException("Attribute 'config' has already been set"); } config = configuration; }
private void doDoclet(final Commandline toExecute) { if (doclet != null) { if (doclet.getName() == null) { throw new BuildException("The doclet name must be specified.", getLocation()); } toExecute.createArgument().setValue("-doclet"); toExecute.createArgument().setValue(doclet.getName()); if (doclet.getPath() != null) { final Path docletPath = doclet.getPath().concatSystemClasspath("ignore"); if (docletPath.size() != 0) { toExecute.createArgument().setValue("-docletpath"); toExecute.createArgument().setPath(docletPath); } } for (final DocletParam param : Collections.list(doclet.getParams())) { if (param.getName() == null) { throw new BuildException("Doclet parameters must have a name"); } toExecute.createArgument().setValue(param.getName()); if (param.getValue() != null) { toExecute.createArgument().setValue(param.getValue()); } } } }
/** * Strip the smallest prefix containing <i>num</i> leading slashes * from filenames. * * <p>patch's <i>-p</i> option. * @param num number of lines to strip * @exception BuildException if num is < 0, or other errors */ public void setStrip(int num) throws BuildException { if (num < 0) { throw new BuildException("strip has to be >= 0", getLocation()); } cmd.createArgument().setValue("-p" + num); }
public void execute() { if (name == null) { throw new BuildException("Missing 'property' attribute!"); throw new BuildException("Missing 'jarfile' attribute!"); if (getProject().getProperty(name) != null) { throw new BuildException("Property '%s' already set!", name); throw new BuildException("Missing nested <classpath>!"); final FileUtils fileUtils = FileUtils.getFileUtils(); dir = fileUtils.normalize(dir.getAbsolutePath()); for (String element : path.list()) { pathEntry = fileUtils.normalize(fullPath); throw new BuildException("error trying to get the relative path" + " from " + dir + " to " + fullPath, e); throw new BuildException( "No suitable relative path from %s to %s", dir, fullPath); getProject().setNewProperty(name, buffer.toString().trim());
private void collectFileListFromSourcePath() { for (String filename : src.list()) { final File srcDir = getProject().resolveFile(filename); if (!srcDir.exists()) { throw new BuildException("srcdir \"" + srcDir.getPath() + "\" does not exist!", getLocation()); } final DirectoryScanner ds = this.getDirectoryScanner(srcDir); scanDir(srcDir, destDir != null ? destDir : srcDir, ds.getIncludedFiles()); } }
/** * launch the generate client using system api. * @throws BuildException if there is an error. */ protected void executeForkV5() throws BuildException { try { log("mode : fork " + BorlandDeploymentTool.BES, Project.MSG_DEBUG); ExecTask execTask = new ExecTask(this); execTask.setDir(new File(".")); execTask.setExecutable("iastool"); if (debug) { execTask.createArg().setValue("-debug"); } execTask.createArg().setValue("-genclient"); execTask.createArg().setValue("-jars"); // ejb jar file execTask.createArg().setValue(ejbjarfile.getAbsolutePath()); //client jar file execTask.createArg().setValue("-target"); execTask.createArg().setValue(clientjarfile.getAbsolutePath()); //classpath execTask.createArg().setValue("-cp"); execTask.createArg().setValue(classpath.toString()); log("Calling iastool", Project.MSG_VERBOSE); execTask.execute(); } catch (Exception e) { // Have to catch this because of the semantics of calling main() throw new BuildException("Exception while calling generateclient", e); } }
private void collectFileListFromModulePath() { final FileUtils fu = FileUtils.getFileUtils(); for (String pathElement : moduleSourcepath.list()) { boolean valid = false; for (Map.Entry<String, Collection<File>> modules : resolveModuleSourcePathElement( getProject().getBaseDir(), pathElement).entrySet()) { final String moduleName = modules.getKey(); for (File srcDir : modules.getValue()) { if (srcDir.exists()) { valid = true; final DirectoryScanner ds = getDirectoryScanner(srcDir); final String[] files = ds.getIncludedFiles(); scanDir(srcDir, fu.resolveFile(destDir, moduleName), files); } } } if (!valid) { throw new BuildException("modulesourcepath \"" + pathElement + "\" does not exist!", getLocation()); } } }
static Commandline setupJavahCommand(Javah javah) { Commandline cmd = new Commandline(); cmd.createArgument().setValue("-d"); cmd.createArgument().setFile(javah.getDestdir()); cmd.createArgument().setValue("-o"); cmd.createArgument().setFile(javah.getOutputfile()); throw new BuildException( "stubs only available in old mode.", javah.getLocation()); cmd.createArgument().setValue("-stubs"); Path bcp = new Path(javah.getProject()); if (javah.getBootclasspath() != null) { bcp.append(javah.getBootclasspath()); bcp = bcp.concatSystemBootClasspath("ignore"); if (bcp.size() > 0) { cmd.createArgument().setValue("-bootclasspath");
validate(); if (classpath != null) { classpath = classpath.concatSystemClasspath("ignore"); getProject().log("using user supplied classpath: " + classpath, Project.MSG_DEBUG); } else { classpath = new Path(getProject()); classpath = classpath.concatSystemClasspath("only"); getProject().log("using system classpath: " + classpath, Project.MSG_DEBUG); AntClassLoader.newAntClassLoader(getProject().getCoreLoader(), getProject(), classpath, false)) { throw new BuildException("One of class or resource is required");
Execute exe = new Execute(getExecuteStreamHandler(), null); exe.setAntRun(getProject()); if (dest == null) { dest = getProject().getBaseDir(); exe.setWorkingDirectory(dest); exe.setCommandline(toExecute.getCommandline()); exe.setEnvironment(env.getVariables()); if (failOnError && Execute.isFailure(retCode)) { throw new BuildException( String.format("cvs exited with error code %s%nCommand line was [%s]", retCode, actualCommandLine), getLocation()); throw new BuildException(e, getLocation()); throw(e); Throwable t = e.getCause(); if (t == null) { t = e; } catch (Exception e) { if (failOnError) { throw new BuildException(e, getLocation());
cmdl.setClassname(javaCommand.getExecutable()); for (String arg : javaCommand.getArguments()) { cmdl.createArgument().setValue(arg); cmdl.createClasspath(pc.getProject()).append(classpath); = new Execute(redirector.createHandler(), timeout == null ? null : new ExecuteWatchdog(timeout)); exe.setAntRun(pc.getProject()); if (Os.isFamily("openvms")) { setupCommandLineForVMS(exe, cmdl.getCommandline()); } else { exe.setCommandline(cmdl.getCommandline()); return rc; } catch (IOException e) { throw new BuildException(e); } finally { timedOut = exe.killedProcess();
/** * Build a classloader using the additional elements specified in * <code>classpath</code> and <code>classpathRef</code>. * * @return a new classloader that includes the extra path elements found in * the <code>classpath</code> and <code>classpathRef</code> config * values */ private ClassLoader buildExtendedClassloader() { final List<URL> classpathUrls = new ArrayList<>(); for (String pathElement : getClasspath().list()) { try { classpathUrls.add(new File(pathElement).toURI().toURL()); } catch (MalformedURLException e) { throw new BuildException("Unable to use classpath entry as it could not be understood as a valid URL: " + pathElement, e); } } final ClassLoader parentClassloader = Thread.currentThread().getContextClassLoader(); return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { @Override public ClassLoader run() { return new URLClassLoader(classpathUrls.toArray(new URL[classpathUrls.size()]), parentClassloader); } }); }
private void setupClassLoader() { try { if (auxClasspath != null) { project.log("Using auxclasspath: " + auxClasspath, Project.MSG_VERBOSE); configuration.prependClasspath(auxClasspath.toString()); } } catch (IOException ioe) { throw new BuildException(ioe.getMessage(), ioe); } }
/** * Validate that the task parameters are valid. * * @throws BuildException if parameters are invalid */ private void validate() throws BuildException { if (null == myFile) { myFile = FILE_UTILS.resolveFile(getProject().getBaseDir(), DEFAULT_FILENAME); } if (!myFile.exists()) { try { FILE_UTILS.createNewFile(myFile); } catch (final IOException ioe) { throw new BuildException( myFile + " doesn't exist and new file can't be created.", ioe); } } if (!myFile.canRead()) { throw new BuildException("Unable to read from " + myFile + "."); } if (!myFile.canWrite()) { throw new BuildException("Unable to write to " + myFile + "."); } } }
if (ex.getMessage().contains("Java returned: 1")) ex = new BuildException(ex.getMessage() + " See log for details.", ex.getCause(), ex.getLocation());
/** * Creates the temporary file. * * @exception BuildException if something goes wrong with the build */ @Override public void execute() throws BuildException { if (property == null || property.isEmpty()) { throw new BuildException("no property specified"); } if (destDir == null) { destDir = getProject().resolveFile("."); } File tfile = FILE_UTILS.createTempFile(prefix, suffix, destDir, deleteOnExit, createFile); getProject().setNewProperty(property, tfile.toString()); } }