use of org.apache.tools.ant.types.Path in project cayenne by apache.
the class CayenneGeneratorTaskCrossMapRelationshipsTest method testCrossDataMapRelationships.
/**
* Tests pairs generation with a cross-DataMap relationship.
*/
@Test
public void testCrossDataMapRelationships() throws Exception {
CayenneGeneratorTask task = new CayenneGeneratorTask();
task.setProject(new Project());
task.setTaskName("Test");
task.setLocation(Location.UNKNOWN_LOCATION);
// prepare destination directory
File destDir = new File(FileUtil.baseTestDirectory(), "cgen12");
// prepare destination directory
if (!destDir.exists()) {
assertTrue(destDir.mkdirs());
}
File map = new File(destDir, "cgen-dependent.map.xml");
ResourceUtil.copyResourceToFile("org/apache/cayenne/tools/cgen-dependent.map.xml", map);
File[] additionalMaps = new File[1];
additionalMaps[0] = new File(destDir, "cgen.map.xml");
ResourceUtil.copyResourceToFile("org/apache/cayenne/tools/cgen.map.xml", additionalMaps[0]);
FileList additionalMapsFilelist = new FileList();
additionalMapsFilelist.setDir(additionalMaps[0].getParentFile());
additionalMapsFilelist.setFiles(additionalMaps[0].getName());
Path additionalMapsPath = new Path(task.getProject());
additionalMapsPath.addFilelist(additionalMapsFilelist);
// setup task
task.setMap(map);
task.setAdditionalMaps(additionalMapsPath);
task.setMakepairs(true);
task.setOverwrite(false);
task.setMode("entity");
task.setIncludeEntities("MyArtGroup");
task.setDestDir(destDir);
task.setSuperpkg("org.apache.cayenne.testdo.cgen2.auto");
task.setUsepkgpath(true);
// run task
task.execute();
// check results
File a = new File(destDir, convertPath("org/apache/cayenne/testdo/cgen2/MyArtGroup.java"));
assertTrue(a.isFile());
assertContents(a, "MyArtGroup", "org.apache.cayenne.testdo.cgen2", "_MyArtGroup");
File _a = new File(destDir, convertPath("org/apache/cayenne/testdo/cgen2/auto/_MyArtGroup.java"));
assertTrue(_a.exists());
assertContents(_a, "_MyArtGroup", "org.apache.cayenne.testdo.cgen2.auto", "BaseDataObject");
assertContents(_a, "import org.apache.cayenne.testdo.testmap.ArtGroup;");
assertContents(_a, " ArtGroup getToParentGroup()");
assertContents(_a, "setToParentGroup(ArtGroup toParentGroup)");
}
use of org.apache.tools.ant.types.Path 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.types.Path in project mkgmap by openstreetmap.
the class MKGMapTask method execute.
public void execute() {
List<String> args = new ArrayList<String>();
try {
CommandArgsReader argsReader = new CommandArgsReader(new Main());
if (configFile != null)
args.add("--read-config=" + configFile);
for (Path path : paths) {
String[] includedFiles = path.list();
for (String filename : includedFiles) {
log("processing " + filename);
args.add("--input-file=" + filename);
}
}
argsReader.readArgs(args.toArray(new String[args.size()]));
} catch (Exception ex) {
// log(ex, 1);
throw new BuildException(ex);
}
}
use of org.apache.tools.ant.types.Path 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.types.Path in project ant by apache.
the class JavacTest method testModulesourcepath.
@Test
public void testModulesourcepath() {
// NOI18N
final File tmp = new File(System.getProperty("java.io.tmpdir"));
final File destDir = new File(tmp, String.format("%stestMP%d", getClass().getName(), System.currentTimeMillis() / 1000));
destDir.mkdirs();
try {
final Path p = new Path(project);
p.setPath("src");
javac.setModulesourcepath(p);
javac.setDestdir(destDir);
javac.checkParameters();
} finally {
destDir.delete();
}
}
Aggregations