/** * verify that the file exists, if {@link #validate} is set * * @param fileToCheck file that may need to exist * @throws BuildException with text beginning {@link #ERROR_MISSING_FILE} */ private void validateFile(File fileToCheck) { if (validate && !fileToCheck.exists()) { throw new BuildException(ERROR_MISSING_FILE + fileToCheck); } }
private void addOutputDir(List<String> argv) { if (null != m_outputDir) { if (!m_outputDir.exists()) { m_outputDir.mkdirs(); } if (m_outputDir.isDirectory()) { argv.add(CommandLineArgs.OUTPUT_DIRECTORY); argv.add(m_outputDir.getAbsolutePath()); } else { throw new BuildException("Output directory is not a directory: " + m_outputDir); } } }
/** Handle the -buildfile, -file, -f argument */ private int handleArgBuildFile(final String[] args, int pos) { try { buildFile = new File( args[++pos].replace('/', File.separatorChar)); } catch (final ArrayIndexOutOfBoundsException aioobe) { throw new BuildException( "You must specify a buildfile when using the -buildfile argument"); } return pos; }
ResourceCollection rc = (ResourceCollection) rcs.elementAt(i); Iterator<Resource> resources = rc.iterator(); while (resources.hasNext()) { Resource r = (Resource) resources.next(); if (!r.isExists()) { continue; String baseDir = fr.getBaseDir().getAbsolutePath(); String file = fr.getFile().getAbsolutePath(); file = file.substring(baseDir.length(), file.length()); String[] parts = file.split("/"); throw new BuildException("Unable to recognize the path separator for src file: " + file); File specificFile = new File(licenseDir, specificFilePart); File specificDestinationFile = new File(destDir, specificFilePart); if (specificFile.exists()) { fileUtils.copyFile(specificFile, specificDestinationFile); continue; String moreGeneralFilePart = StringUtils.join(moreGeneralParts, '/') + "/license.txt"; File moreGeneralFile = new File(licenseDir, moreGeneralFilePart); if (moreGeneralFile.exists()) { fileUtils.copyFile(moreGeneralFile, specificDestinationFile); throw new BuildException(e);
public void execute() throws BuildException { beforeExecute(); for (Iterator it = getFiles().iterator(); it.hasNext();) { try { processFile((File)it.next()); } catch (Exception e) { throw new BuildException(e); } } }
/** * Helper method to determine the archive location index. * * @param home the javacc home path directory. * @throws BuildException thrown if the home directory is invalid * or if the archive could not be found despite attempts to do so. * @return the archive location index */ private static int getArchiveLocationIndex(File home) throws BuildException { if (home == null || !home.isDirectory()) { throw new BuildException("JavaCC home must be a valid directory."); } for (int i = 0; i < ARCHIVE_LOCATIONS.length; i++) { File f = new File(home, ARCHIVE_LOCATIONS[i]); if (f.exists()) { return i; } } throw new BuildException( "Could not find a path to JavaCC.zip or javacc.jar from '%s'.", home); }
private void removeDir(File dir) { // check to make sure that the given dir isn't a symlink // the comparison of absolute path and canonical path // catches this // if (dir.getCanonicalPath().equals(dir.getAbsolutePath())) { // (costin) It will not work if /home/costin is symlink to // /da0/home/costin (taz for example) for (String s : dir.list()) { File f = new File(dir, s); if (f.isDirectory()) { removeDir(f); } else if (!f.delete()) { throw new BuildException("Unable to delete file " + f.getAbsolutePath()); } } if (!dir.delete()) { throw new BuildException("Unable to delete directory " + dir.getAbsolutePath()); } } }
/** * Set the source resource. * @param a the resource to load as a single element Resource collection. * @since Ant 1.7 */ public synchronized void addConfigured(ResourceCollection a) { if (src != null) { throw new BuildException("only a single source is supported"); } if (a.size() != 1) { throw new BuildException( "only single-element resource collections are supported"); } src = a.iterator().next(); }
/** * create directories as needed */ private void ensureDirectoryFor( File targetFile ) throws BuildException { File directory = new File( targetFile.getParent() ); if (!directory.exists()) { if (!directory.mkdirs()) { throw new BuildException("Unable to create directory: " + directory.getAbsolutePath(), getLocation()); } } }
private ClassLoader toClassLoader(List<File> runtimeClasspath) throws BuildException { List<URL> urls = new ArrayList<>(); for ( File file : runtimeClasspath ) { try { urls.add( file.toURI().toURL() ); log( "Adding classpath entry for classes root " + file.getAbsolutePath(), Project.MSG_DEBUG ); } catch ( MalformedURLException e ) { String msg = "Unable to resolve classpath entry to URL: " + file.getAbsolutePath(); if ( failOnError ) { throw new BuildException( msg, e ); } log( msg, Project.MSG_WARN ); } } return new URLClassLoader( urls.toArray( new URL[urls.size()] ), Enhancer.class.getClassLoader() ); }
+ "Make sure the path exists and you have write " + "permissions."; throw new BuildException(msg); } catch (final ArrayIndexOutOfBoundsException aioobe) { final String msg = "You must specify a log file when " + "using the -log argument"; throw new BuildException(msg); + "\nThis can be caused by a version mismatch between " + "the ant script/.bat file and Ant itself."; throw new BuildException(msg); } else if (arg.equals("-autoproxy")) { proxy = true; System.err.println(msg); printUsage(); throw new BuildException(""); buildFile = findBuildFile(System.getProperty("user.dir"), searchForThis); if (buildFile == null) { throw new BuildException("Could not locate a build file!"); } while (buildFile == null && it.hasNext()); if (buildFile == null) { throw new BuildException("Could not locate a build file!"); if (!buildFile.exists()) { System.out.println("Buildfile: " + buildFile + " does not exist!"); throw new BuildException("Build failed");
public void execute() throws BuildException { beforeExecute(); for (Iterator it = getFiles().iterator(); it.hasNext();) { try { processFile((File)it.next()); } catch (Exception e) { throw new BuildException(e); } } }
public void execute() throws BuildException { if (topDir == null) throw new BuildException("no dir attribute is set"); File top = new File(topDir); if (!top.exists()) throw new BuildException("the directory " + top + " does not exist"); log("top dir is " + top); int fails = execute(top); if (fails == 0) { log("no bytecode problems found"); } else { log("found " + fails + " failing classes"); } }
/** * Set the output stream of the process. * @param is the input stream. * @throws IOException if there is an error. */ @Override public void setProcessOutputStream(InputStream is) throws IOException { try (BufferedReader reader = new BufferedReader(new InputStreamReader(is))) { String javafile; while ((javafile = reader.readLine()) != null) { if (javafile.endsWith(".java")) { String classfile = toClassFile(javafile); String key = classfile.substring( getConfig().srcDir.getAbsolutePath().length() + 1); genfiles.put(key, new File(classfile)); } } } catch (Exception e) { throw new BuildException("Exception while parsing java2iiop output.", e); } }
private void addOutputDir(List<String> argv) { if (null != m_outputDir) { if (!m_outputDir.exists()) { m_outputDir.mkdirs(); } if (m_outputDir.isDirectory()) { argv.add(CommandLineArgs.OUTPUT_DIRECTORY); argv.add(m_outputDir.getAbsolutePath()); } else { throw new BuildException("Output directory is not a directory: " + m_outputDir); } } }
/** * Set the source resource. * @param a the resource to load as a single element Resource collection. */ public void addConfigured(ResourceCollection a) { if (a.size() != 1) { throw new BuildException( "only single argument resource collections are supported"); } src = a.iterator().next(); }
if (file.exists()) { if (destFile == null) { destFile = new File(destDir, file.getName()); if (forceOverwrite || !destFile.exists() || (file.lastModified() - granularity > destFile.lastModified())) { fileCopyMap.put(file.getAbsolutePath(), new String[] {destFile.getAbsolutePath()}); } else { log(file + " omitted as " + destFile + file.getAbsolutePath() + " to copy."; if (!failonerror) { if (!quiet) { throw new BuildException(message);
/** * Adds an element to the classpath to be searched. * * @param pathElement The path element to add. Must not be * <code>null</code>. * * @exception BuildException if the given path element cannot be resolved * against the project. */ public void addPathElement(String pathElement) throws BuildException { File pathComponent = project != null ? project.resolveFile(pathElement) : new File( pathElement); try { addPathFile(pathComponent); } catch (IOException e) { throw new BuildException(e); } }
/** * Validate the tasks parameters. * * @throws BuildException if invalid parameters found */ private void validate() throws BuildException { if (null == destFile) { throw new BuildException("Destfile attribute not specified."); } if (destFile.exists() && !destFile.isFile()) { throw new BuildException("%s is not a file.", destFile); } }
/** rename the zip file. */ private File renameFile() { final File renamedFile = FILE_UTILS.createTempFile( "zip", ".tmp", zipFile.getParentFile(), true, false); try { FILE_UTILS.rename(zipFile, renamedFile); } catch (final SecurityException | IOException e) { throw new BuildException( "Unable to rename old file (%s) to temporary file", zipFile.getAbsolutePath()); } return renamedFile; }