Search in sources :

Example 11 with Path

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)");
}
Also used : Path(org.apache.tools.ant.types.Path) Project(org.apache.tools.ant.Project) FileList(org.apache.tools.ant.types.FileList) File(java.io.File) Test(org.junit.Test)

Example 12 with Path

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;
}
Also used : Path(org.apache.tools.ant.types.Path) JarArchiveEntry(org.apache.commons.compress.archivers.jar.JarArchiveEntry) JarArchiveOutputStream(org.apache.commons.compress.archivers.jar.JarArchiveOutputStream) Groovyc(org.codehaus.groovy.ant.Groovyc) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Project(org.apache.tools.ant.Project) FileOutputStream(java.io.FileOutputStream) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 13 with Path

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);
    }
}
Also used : Path(org.apache.tools.ant.types.Path) CommandArgsReader(uk.me.parabola.mkgmap.CommandArgsReader) ArrayList(java.util.ArrayList) BuildException(org.apache.tools.ant.BuildException) Main(uk.me.parabola.mkgmap.main.Main) BuildException(org.apache.tools.ant.BuildException)

Example 14 with Path

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();
    }
}
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 15 with Path

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();
    }
}
Also used : Path(org.apache.tools.ant.types.Path) File(java.io.File) Test(org.junit.Test)

Aggregations

Path (org.apache.tools.ant.types.Path)174 File (java.io.File)78 BuildException (org.apache.tools.ant.BuildException)55 Test (org.junit.Test)49 Project (org.apache.tools.ant.Project)28 IOException (java.io.IOException)24 Commandline (org.apache.tools.ant.types.Commandline)21 ArrayList (java.util.ArrayList)12 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)10 URL (java.net.URL)8 AntClassLoader (org.apache.tools.ant.AntClassLoader)7 Java (org.apache.tools.ant.taskdefs.Java)7 StringTokenizer (java.util.StringTokenizer)6 FileSet (org.apache.tools.ant.types.FileSet)6 Reference (org.apache.tools.ant.types.Reference)6 Resource (org.apache.tools.ant.types.Resource)6 Test (org.junit.jupiter.api.Test)6 GroovyClassLoader (groovy.lang.GroovyClassLoader)5 Enumeration (java.util.Enumeration)5 Vector (java.util.Vector)5