use of org.apache.tools.ant.BuildException in project groovy by apache.
the class Groovyc method makeCompileUnit.
protected CompilationUnit makeCompileUnit() {
Map<String, Object> options = configuration.getJointCompilationOptions();
if (options != null) {
if (keepStubs) {
options.put("keepStubs", Boolean.TRUE);
}
if (stubDir != null) {
options.put("stubDir", stubDir);
} else {
try {
File tempStubDir = DefaultGroovyStaticMethods.createTempDir(null, "groovy-generated-", "-java-source");
temporaryFiles.add(tempStubDir);
options.put("stubDir", tempStubDir);
} catch (IOException ioe) {
throw new BuildException(ioe);
}
}
return new JavaAwareCompilationUnit(configuration, buildClassLoaderFor());
} else {
return new CompilationUnit(configuration, null, buildClassLoaderFor());
}
}
use of org.apache.tools.ant.BuildException in project processing by processing.
the class PAppletMethods method execute.
public void execute() throws BuildException {
// Do a bunch of checks...
if (baseDir == null) {
throw new BuildException("dir parameter must be set!");
}
//System.out.println("using basedir " + baseDir);
File graphicsFile = new File(baseDir, "PGraphics.java");
File appletFile = new File(baseDir, "PApplet.java");
File imageFile = new File(baseDir, "PImage.java");
if (!graphicsFile.exists() || !graphicsFile.canRead()) {
throw new BuildException("PGraphics file not readable: " + graphicsFile.getAbsolutePath());
}
if (!appletFile.exists() || !appletFile.canRead() || !appletFile.canWrite()) {
throw new BuildException("PApplet file not read/writeable: " + appletFile.getAbsolutePath());
}
if (!imageFile.exists() || !imageFile.canRead()) {
throw new BuildException("PImage file not readable: " + imageFile.getAbsolutePath());
}
// Looking good, let's do this!
//ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
//PrintStream out = new PrintStream(outBytes, "UTF-8");
StringBuilder out = new StringBuilder();
StringBuilder content = new StringBuilder();
try {
BufferedReader applet = createReader(appletFile);
String line;
while ((line = applet.readLine()) != null) {
out.append(line);
// to avoid Windows CRs
out.append('\n');
content.append(line);
// for efficiency
content.append('\n');
if (line.indexOf("public functions for processing.core") >= 0) {
break;
}
}
// read the rest of the file and append it to the
while ((line = applet.readLine()) != null) {
content.append(line);
content.append('\n');
}
applet.close();
process(out, graphicsFile);
process(out, imageFile);
out.append('}');
out.append('\n');
//} catch (IOException e) {
//e.printStackTrace();
} catch (Exception e) {
//ex.printStackTrace();
throw new BuildException(e);
}
//out.flush();
String outString = out.toString();
if (content.toString().equals(outString)) {
System.out.println("No changes to PApplet API.");
} else {
System.out.println("Updating PApplet with API changes " + "from PImage or PGraphics.");
try {
PrintStream temp = new PrintStream(appletFile, "UTF-8");
temp.print(outString);
temp.flush();
temp.close();
} catch (IOException e) {
//e.printStackTrace();
throw new BuildException(e);
}
}
}
use of org.apache.tools.ant.BuildException in project processing by processing.
the class JavaBuild method buildWindowsLauncher.
/**
* Run the launch4j build.xml file through ant to create the exe.
* Most of this code was lifted from Android mode.
*/
protected boolean buildWindowsLauncher(File buildFile, String target) {
Project p = new Project();
String path = buildFile.getAbsolutePath().replace('\\', '/');
p.setUserProperty("ant.file", path);
// deals with a problem where javac error messages weren't coming through
p.setUserProperty("build.compiler", "extJavac");
// too chatty
/*
// try to spew something useful to the console
final DefaultLogger consoleLogger = new DefaultLogger();
consoleLogger.setErrorPrintStream(System.err);
consoleLogger.setOutputPrintStream(System.out);
// WARN, INFO, VERBOSE, DEBUG
consoleLogger.setMessageOutputLevel(Project.MSG_ERR);
p.addBuildListener(consoleLogger);
*/
DefaultLogger errorLogger = new DefaultLogger();
ByteArrayOutputStream errb = new ByteArrayOutputStream();
PrintStream errp = new PrintStream(errb);
errorLogger.setErrorPrintStream(errp);
ByteArrayOutputStream outb = new ByteArrayOutputStream();
PrintStream outp = new PrintStream(outb);
errorLogger.setOutputPrintStream(outp);
errorLogger.setMessageOutputLevel(Project.MSG_INFO);
p.addBuildListener(errorLogger);
try {
p.fireBuildStarted();
p.init();
final ProjectHelper helper = ProjectHelper.getProjectHelper();
p.addReference("ant.projectHelper", helper);
helper.parse(p, buildFile);
p.executeTarget(target);
return true;
} catch (final BuildException e) {
// Send a "build finished" event to the build listeners for this project.
p.fireBuildFinished(e);
String out = new String(outb.toByteArray());
String err = new String(errb.toByteArray());
System.out.println(out);
System.err.println(err);
}
return false;
}
use of org.apache.tools.ant.BuildException in project felix by apache.
the class SCRDescriptorTask method execute.
@Override
public void execute() throws BuildException {
// ensure we know the source
if (getImplicitFileSet().getDir() == null) {
throw new BuildException("srcdir attribute must be set!", getLocation());
}
// while debugging
final org.apache.felix.scrplugin.Log scrLog = new AntLog(this);
scrLog.debug("SCRDescriptorTask Configuration");
scrLog.debug(" implicitFileset: " + getImplicitFileSet());
scrLog.debug(" outputDirectory: " + destdir);
scrLog.debug(" classpath: " + classpath);
scrLog.debug(" generateAccessors: " + generateAccessors);
scrLog.debug(" strictMode: " + strictMode);
scrLog.debug(" specVersion: " + specVersion);
try {
final Path classPath = createClasspath();
final org.apache.felix.scrplugin.Project project = new org.apache.felix.scrplugin.Project();
project.setClassLoader(getClassLoader(this.getClass().getClassLoader()));
project.setDependencies(getDependencies(classPath));
project.setSources(getSourceFiles(getImplicitFileSet()));
project.setClassesDirectory(destdir.getAbsolutePath());
// create options
final Options options = new Options();
options.setOutputDirectory(destdir);
options.setGenerateAccessors(generateAccessors);
options.setStrictMode(strictMode);
options.setProperties(new HashMap<String, String>());
options.setSpecVersion(SpecVersion.fromName(specVersion));
if (specVersion != null && options.getSpecVersion() == null) {
throw new BuildException("Unknown spec version specified: " + specVersion);
}
final SCRDescriptorGenerator generator = new SCRDescriptorGenerator(scrLog);
// setup from plugin configuration
generator.setOptions(options);
generator.setProject(project);
generator.execute();
} catch (final SCRDescriptorException sde) {
if (sde.getSourceLocation() != null) {
final Location loc = new Location(sde.getSourceLocation(), -1, 0);
throw new BuildException(sde.getMessage(), sde.getCause(), loc);
}
throw new BuildException(sde.getMessage(), sde.getCause());
} catch (SCRDescriptorFailureException sdfe) {
throw new BuildException(sdfe.getMessage(), sdfe.getCause());
}
}
use of org.apache.tools.ant.BuildException in project chipKIT32-MAX by chipKIT32.
the class PAppletMethods method execute.
public void execute() throws BuildException {
// Do a bunch of checks...
if (baseDir == null) {
throw new BuildException("dir parameter must be set!");
}
//System.out.println("using basedir " + baseDir);
File graphicsFile = new File(baseDir, "PGraphics.java");
File appletFile = new File(baseDir, "PApplet.java");
File imageFile = new File(baseDir, "PImage.java");
if (!graphicsFile.exists() || !graphicsFile.canRead()) {
throw new BuildException("PGraphics file not readable: " + graphicsFile.getAbsolutePath());
}
if (!appletFile.exists() || !appletFile.canRead() || !appletFile.canWrite()) {
throw new BuildException("PApplet file not read/writeable: " + appletFile.getAbsolutePath());
}
if (!imageFile.exists() || !imageFile.canRead()) {
throw new BuildException("PImage file not readable: " + imageFile.getAbsolutePath());
}
// Looking good, let's do this!
//ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
//PrintStream out = new PrintStream(outBytes, "UTF-8");
StringBuffer out = new StringBuffer();
StringBuffer content = new StringBuffer();
try {
BufferedReader applet = createReader(appletFile);
String line;
while ((line = applet.readLine()) != null) {
out.append(line);
// to avoid Windows CRs
out.append('\n');
content.append(line);
// for efficiency
content.append('\n');
if (line.indexOf("public functions for processing.core") >= 0) {
break;
}
}
// read the rest of the file and append it to the
while ((line = applet.readLine()) != null) {
content.append(line);
content.append('\n');
}
applet.close();
process(out, graphicsFile);
process(out, imageFile);
out.append('}');
out.append('\n');
//} catch (IOException e) {
//e.printStackTrace();
} catch (Exception e) {
//ex.printStackTrace();
throw new BuildException(e);
}
//out.flush();
String outString = out.toString();
if (content.toString().equals(outString)) {
System.out.println("No changes to PApplet API.");
} else {
System.out.println("Updating PApplet with API changes " + "from PImage or PGraphics.");
try {
PrintStream temp = new PrintStream(appletFile, "UTF-8");
temp.print(outString);
temp.flush();
temp.close();
} catch (IOException e) {
//e.printStackTrace();
throw new BuildException(e);
}
}
}
Aggregations