use of org.apache.tools.ant.Project in project ignite by apache.
the class GridUriDeploymentFileProcessorSelfTest method proceedTest.
/**
* @param garFileName Name of .gar file.
* @param garDescFileName Name of Ignite descriptor file.
* @param taskId Task id.
* @param deployed If {@code true} then givent task should be deployed after test,
* if {@code false} then it should be undeployed.
* @throws Exception If failed.
*/
private void proceedTest(String garFileName, String garDescFileName, final String taskId, final boolean deployed) throws Exception {
info("This test checks broken tasks. All exceptions that might happen are the part of the test.");
String tmpDirName = GridTestProperties.getProperty("ant.gar.tmpdir");
String srcDirName = GridTestProperties.getProperty("ant.gar.srcdir");
String baseDirName = tmpDirName + File.separator + System.currentTimeMillis();
String metaDirName = baseDirName + File.separator + "META-INF";
String garDescDirName = U.resolveIgnitePath(GridTestProperties.getProperty("deploy.gar.descriptor.dir")) + File.separator + garDescFileName;
// Make base, META-INF and deployment dirs.
File destDir = new File(GridTestProperties.getProperty("deploy.uri.file2.path"));
if (!destDir.exists()) {
boolean mkdir = destDir.mkdirs();
assert mkdir;
}
boolean mkdir = new File(baseDirName).mkdirs();
assert mkdir;
mkdir = new File(metaDirName).mkdirs();
assert mkdir;
// Make Gar file
U.copy(new File(garDescDirName), new File(metaDirName + File.separator + "ignite.xml"), true);
// Copy files to basedir
U.copy(new File(srcDirName), new File(baseDirName), true);
File garFile = new File(baseDirName + File.separator + garFileName);
IgniteDeploymentGarAntTask garTask = new IgniteDeploymentGarAntTask();
Project garProject = new Project();
garProject.setName("Gar test project");
garTask.setDestFile(garFile);
garTask.setBasedir(new File(baseDirName));
garTask.setProject(garProject);
garTask.execute();
assert garFile.exists();
// Copy to deployment directory.
U.copy(garFile, destDir, true);
try {
// Wait for SPI
GridTestUtils.waitForCondition(new GridAbsPredicateX() {
@Override
public boolean applyx() throws IgniteCheckedException {
if (deployed)
return getSpi().findResource(taskId) != null;
else
return getSpi().findResource(taskId) == null;
}
}, 5000);
if (deployed)
assert getSpi().findResource(taskId) != null;
else
assert getSpi().findResource(taskId) == null;
} finally {
U.delete(destDir);
// Wait for SPI refresh
Thread.sleep(1000);
}
}
use of org.apache.tools.ant.Project in project hive by apache.
the class CompileProcessor method compile.
@VisibleForTesting
/**
* Method converts statement into a file, compiles the file and then packages the file.
* @param ss
* @return Response code of 0 for success 1 for failure
* @throws CompileProcessorException
*/
CommandProcessorResponse compile(SessionState ss) throws CompileProcessorException {
Project proj = new Project();
String ioTempDir = System.getProperty(IO_TMP_DIR);
File ioTempFile = new File(ioTempDir);
if (!ioTempFile.exists()) {
throw new CompileProcessorException(ioTempDir + " does not exists");
}
if (!ioTempFile.isDirectory() || !ioTempFile.canWrite()) {
throw new CompileProcessorException(ioTempDir + " is not a writable directory");
}
Groovyc g = new Groovyc();
long runStamp = System.currentTimeMillis();
String jarId = myId + "_" + runStamp;
g.setProject(proj);
Path sourcePath = new Path(proj);
File destination = new File(ioTempFile, jarId + "out");
g.setDestdir(destination);
File input = new File(ioTempFile, jarId + "in");
sourcePath.setLocation(input);
g.setSrcdir(sourcePath);
input.mkdir();
File fileToWrite = new File(input, this.named);
try {
Files.write(this.code, fileToWrite, Charset.forName("UTF-8"));
} catch (IOException e1) {
throw new CompileProcessorException("writing file", e1);
}
destination.mkdir();
try {
g.execute();
} catch (BuildException ex) {
throw new CompileProcessorException("Problem compiling", ex);
}
File testArchive = new File(ioTempFile, jarId + ".jar");
JarArchiveOutputStream out = null;
try {
out = new JarArchiveOutputStream(new FileOutputStream(testArchive));
for (File f : destination.listFiles()) {
JarArchiveEntry jentry = new JarArchiveEntry(f.getName());
FileInputStream fis = new FileInputStream(f);
out.putArchiveEntry(jentry);
IOUtils.copy(fis, out);
fis.close();
out.closeArchiveEntry();
}
out.finish();
} catch (IOException e) {
throw new CompileProcessorException("Exception while writing jar", e);
} finally {
if (out != null) {
try {
out.close();
} catch (IOException WhatCanYouDo) {
}
}
}
if (ss != null) {
ss.add_resource(ResourceType.JAR, testArchive.getAbsolutePath());
}
CommandProcessorResponse good = new CommandProcessorResponse(0, testArchive.getAbsolutePath(), null);
return good;
}
use of org.apache.tools.ant.Project in project groovy-core by groovy.
the class Groovy method parseAndRunScript.
private void parseAndRunScript(GroovyShell shell, String txt, Object mavenPom, String scriptName, File scriptFile, AntBuilder builder) {
try {
final Script script;
if (scriptFile != null) {
script = shell.parse(scriptFile);
} else {
script = shell.parse(txt, scriptName);
}
final Project project = getProject();
script.setProperty("ant", builder);
script.setProperty("project", project);
script.setProperty("properties", new AntProjectPropertiesDelegate(project));
script.setProperty("target", getOwningTarget());
script.setProperty("task", this);
script.setProperty("args", cmdline.getCommandline());
if (mavenPom != null) {
script.setProperty("pom", mavenPom);
}
script.run();
} catch (final MissingMethodException mme) {
// not a script, try running through run method but properties will not be available
if (scriptFile != null) {
try {
shell.run(scriptFile, cmdline.getCommandline());
} catch (IOException e) {
processError(e);
}
} else {
shell.run(txt, scriptName, cmdline.getCommandline());
}
} catch (final CompilationFailedException e) {
processError(e);
} catch (IOException e) {
processError(e);
}
}
use of org.apache.tools.ant.Project in project groovy-core by groovy.
the class Groovy method execGroovy.
/**
* Exec the statement.
*
* @param txt the groovy source to exec
* @param out not used?
*/
protected void execGroovy(final String txt, final PrintStream out) {
log.debug("execGroovy()");
// Check and ignore empty statements
if ("".equals(txt.trim())) {
return;
}
log.verbose("Script: " + txt);
if (classpath != null) {
log.debug("Explicit Classpath: " + classpath.toString());
}
if (fork) {
log.debug("Using fork mode");
try {
createClasspathParts();
createNewArgs(txt);
super.setFork(fork);
super.setClassname(useGroovyShell ? "groovy.lang.GroovyShell" : "org.codehaus.groovy.ant.Groovy");
configureCompiler();
super.execute();
} catch (Exception e) {
StringWriter writer = new StringWriter();
new ErrorReporter(e, false).write(new PrintWriter(writer));
String message = writer.toString();
throw new BuildException("Script Failed: " + message, e, getLocation());
}
return;
}
Object mavenPom = null;
final Project project = getProject();
final ClassLoader baseClassLoader;
ClassLoader savedLoader = null;
final Thread thread = Thread.currentThread();
boolean maven = "org.apache.commons.grant.GrantProject".equals(project.getClass().getName());
// treat the case Ant is run through Maven, and
if (maven) {
if (contextClassLoader) {
throw new BuildException("Using setContextClassLoader not permitted when using Maven.", getLocation());
}
try {
final Object propsHandler = project.getClass().getMethod("getPropsHandler").invoke(project);
final Field contextField = propsHandler.getClass().getDeclaredField("context");
contextField.setAccessible(true);
final Object context = contextField.get(propsHandler);
mavenPom = InvokerHelper.invokeMethod(context, "getProject", EMPTY_OBJECT_ARRAY);
} catch (Exception e) {
throw new BuildException("Impossible to retrieve Maven's Ant project: " + e.getMessage(), getLocation());
}
// load groovy into "root.maven" classloader instead of "root" so that
// groovy script can access Maven classes
baseClassLoader = mavenPom.getClass().getClassLoader();
} else {
baseClassLoader = GroovyShell.class.getClassLoader();
}
if (contextClassLoader || maven) {
savedLoader = thread.getContextClassLoader();
thread.setContextClassLoader(GroovyShell.class.getClassLoader());
}
final String scriptName = computeScriptName();
final GroovyClassLoader classLoader = new GroovyClassLoader(baseClassLoader);
addClassPathes(classLoader);
configureCompiler();
final GroovyShell groovy = new GroovyShell(classLoader, new Binding(), configuration);
try {
parseAndRunScript(groovy, txt, mavenPom, scriptName, null, new AntBuilder(this));
} finally {
groovy.resetLoadedClasses();
groovy.getClassLoader().clearCache();
if (contextClassLoader || maven)
thread.setContextClassLoader(savedLoader);
}
}
use of org.apache.tools.ant.Project in project groovy-core by groovy.
the class GroovyTest method setUp.
protected void setUp() throws Exception {
super.setUp();
project = new Project();
project.init();
ProjectHelper.getProjectHelper().parse(project, antFile);
FLAG = null;
}
Aggregations