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());
}
}
}
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);
}
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);
}
}
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();
}
}
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;
}
Aggregations