Search in sources :

Example 96 with BuildException

use of org.apache.tools.ant.BuildException in project ant by apache.

the class Rmic method moveGeneratedFile.

/**
 * Move the generated source file(s) to the base directory
 *
 * @throws BuildException When error
 * copying/removing files.
 */
private void moveGeneratedFile(File baseDir, File sourceBaseFile, String classname, RmicAdapter adapter) throws BuildException {
    String classFileName = classname.replace('.', File.separatorChar) + ".class";
    String[] generatedFiles = adapter.getMapper().mapFileName(classFileName);
    if (generatedFiles == null) {
        return;
    }
    for (String generatedFile : generatedFiles) {
        if (!generatedFile.endsWith(".class")) {
            // have a corresponding Java source for example.
            continue;
        }
        String sourceFileName = StringUtils.removeSuffix(generatedFile, ".class") + ".java";
        File oldFile = new File(baseDir, sourceFileName);
        if (!oldFile.exists()) {
            // no source file generated, nothing to move
            continue;
        }
        File newFile = new File(sourceBaseFile, sourceFileName);
        try {
            if (filtering) {
                FILE_UTILS.copyFile(oldFile, newFile, new FilterSetCollection(getProject().getGlobalFilterSet()));
            } else {
                FILE_UTILS.copyFile(oldFile, newFile);
            }
            oldFile.delete();
        } catch (IOException ioe) {
            throw new BuildException("Failed to copy " + oldFile + " to " + newFile + " due to " + ioe.getMessage(), ioe, getLocation());
        }
    }
}
Also used : FilterSetCollection(org.apache.tools.ant.types.FilterSetCollection) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) File(java.io.File)

Example 97 with BuildException

use of org.apache.tools.ant.BuildException in project ant by apache.

the class Truncate method shouldProcess.

private boolean shouldProcess(File f) {
    if (f.isFile()) {
        return true;
    }
    if (!create) {
        return false;
    }
    Exception exception = null;
    try {
        if (FILE_UTILS.createNewFile(f, mkdirs)) {
            return true;
        }
    } catch (IOException e) {
        exception = e;
    }
    String msg = "Unable to create " + f;
    if (exception == null) {
        log(msg, Project.MSG_WARN);
        return false;
    }
    throw new BuildException(msg, exception);
}
Also used : IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException)

Example 98 with BuildException

use of org.apache.tools.ant.BuildException in project ant by apache.

the class Tstamp method execute.

/**
 * create the timestamps. Custom ones are done before
 * the standard ones, to get their retaliation in early.
 * @throws BuildException on error.
 */
@Override
public void execute() throws BuildException {
    try {
        Date d = getNow();
        customFormats.forEach(cts -> cts.execute(getProject(), d, getLocation()));
        SimpleDateFormat dstamp = new SimpleDateFormat("yyyyMMdd");
        setProperty("DSTAMP", dstamp.format(d));
        SimpleDateFormat tstamp = new SimpleDateFormat("HHmm");
        setProperty("TSTAMP", tstamp.format(d));
        SimpleDateFormat today = new SimpleDateFormat("MMMM d yyyy", Locale.US);
        setProperty("TODAY", today.format(d));
    } catch (Exception e) {
        throw new BuildException(e);
    }
}
Also used : BuildException(org.apache.tools.ant.BuildException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) BuildException(org.apache.tools.ant.BuildException) NoSuchElementException(java.util.NoSuchElementException)

Example 99 with BuildException

use of org.apache.tools.ant.BuildException in project ant by apache.

the class VerifyJar method execute.

/**
 * verify our jar files
 * @throws BuildException on error.
 */
@Override
public void execute() throws BuildException {
    // validation logic
    final boolean hasJar = jar != null;
    if (!hasJar && !hasResources()) {
        throw new BuildException(ERROR_NO_SOURCE);
    }
    beginExecution();
    // patch the redirector to save output to a file
    RedirectorElement redirector = getRedirector();
    redirector.setAlwaysLog(true);
    FilterChain outputFilterChain = redirector.createOutputFilterChain();
    outputFilterChain.add(outputCache);
    try {
        Path sources = createUnifiedSourcePath();
        for (Resource r : sources) {
            FileProvider fr = r.as(FileProvider.class);
            verifyOneJar(fr.getFile());
        }
    } finally {
        endExecution();
    }
}
Also used : Path(org.apache.tools.ant.types.Path) RedirectorElement(org.apache.tools.ant.types.RedirectorElement) FilterChain(org.apache.tools.ant.types.FilterChain) FileProvider(org.apache.tools.ant.types.resources.FileProvider) Resource(org.apache.tools.ant.types.Resource) BuildException(org.apache.tools.ant.BuildException)

Example 100 with BuildException

use of org.apache.tools.ant.BuildException in project ant by apache.

the class Os method isOs.

/**
 * Determines if the OS on which Ant is executing matches the
 * given OS family, name, architecture and version
 *
 * @param family   The OS family
 * @param name   The OS name
 * @param arch   The OS architecture
 * @param version   The OS version
 * @return true if the OS matches
 * @since 1.7
 */
public static boolean isOs(String family, String name, String arch, String version) {
    boolean retValue = false;
    if (family != null || name != null || arch != null || version != null) {
        boolean isFamily = true;
        boolean isName = true;
        boolean isArch = true;
        boolean isVersion = true;
        if (family != null) {
            // windows probing logic relies on the word 'windows' in
            // the OS
            boolean isWindows = OS_NAME.contains(FAMILY_WINDOWS);
            boolean is9x = false;
            boolean isNT = false;
            if (isWindows) {
                // there are only four 9x platforms that we look for
                is9x = (OS_NAME.contains("95") || OS_NAME.contains("98") || OS_NAME.contains("me") || // be a muchness. Ant doesn't run on CE, anyway.
                OS_NAME.contains("ce"));
                isNT = !is9x;
            }
            if (family.equals(FAMILY_WINDOWS)) {
                isFamily = isWindows;
            } else if (family.equals(FAMILY_9X)) {
                isFamily = isWindows && is9x;
            } else if (family.equals(FAMILY_NT)) {
                isFamily = isWindows && isNT;
            } else if (family.equals(FAMILY_OS2)) {
                isFamily = OS_NAME.contains(FAMILY_OS2);
            } else if (family.equals(FAMILY_NETWARE)) {
                isFamily = OS_NAME.contains(FAMILY_NETWARE);
            } else if (family.equals(FAMILY_DOS)) {
                isFamily = PATH_SEP.equals(";") && !isFamily(FAMILY_NETWARE);
            } else if (family.equals(FAMILY_MAC)) {
                isFamily = OS_NAME.contains(FAMILY_MAC) || OS_NAME.contains(DARWIN);
            } else if (family.equals(FAMILY_TANDEM)) {
                isFamily = OS_NAME.contains("nonstop_kernel");
            } else if (family.equals(FAMILY_UNIX)) {
                isFamily = PATH_SEP.equals(":") && !isFamily(FAMILY_VMS) && (!isFamily(FAMILY_MAC) || OS_NAME.endsWith("x") || OS_NAME.contains(DARWIN));
            } else if (family.equals(FAMILY_ZOS)) {
                isFamily = OS_NAME.contains(FAMILY_ZOS) || OS_NAME.contains("os/390");
            } else if (family.equals(FAMILY_OS400)) {
                isFamily = OS_NAME.contains(FAMILY_OS400);
            } else if (family.equals(FAMILY_VMS)) {
                isFamily = OS_NAME.contains(FAMILY_VMS);
            } else {
                throw new BuildException("Don\'t know how to detect os family \"" + family + "\"");
            }
        }
        if (name != null) {
            isName = name.equals(OS_NAME);
        }
        if (arch != null) {
            isArch = arch.equals(OS_ARCH);
        }
        if (version != null) {
            isVersion = version.equals(OS_VERSION);
        }
        retValue = isFamily && isName && isArch && isVersion;
    }
    return retValue;
}
Also used : BuildException(org.apache.tools.ant.BuildException)

Aggregations

BuildException (org.apache.tools.ant.BuildException)930 IOException (java.io.IOException)390 File (java.io.File)365 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)75 ArrayList (java.util.ArrayList)65 InputStream (java.io.InputStream)62 Project (org.apache.tools.ant.Project)61 Resource (org.apache.tools.ant.types.Resource)58 FileSet (org.apache.tools.ant.types.FileSet)52 Path (org.apache.tools.ant.types.Path)52 Commandline (org.apache.tools.ant.types.Commandline)51 Properties (java.util.Properties)50 OutputStream (java.io.OutputStream)44 FileOutputStream (java.io.FileOutputStream)42 FileResource (org.apache.tools.ant.types.resources.FileResource)42 FileInputStream (java.io.FileInputStream)41 URL (java.net.URL)40 BufferedReader (java.io.BufferedReader)37 Writer (java.io.Writer)37 MalformedURLException (java.net.MalformedURLException)37