Search in sources :

Example 16 with Project

use of org.apache.tools.ant.Project in project checkstyle by checkstyle.

the class CheckstyleAntTaskTest method testEmptyConfigFile.

@Test
public final void testEmptyConfigFile() throws IOException {
    final CheckstyleAntTask antTask = new CheckstyleAntTask();
    antTask.setConfig(new File(getPath("ant/empty_config.xml")));
    antTask.setProject(new Project());
    antTask.setFile(new File(getPath(FLAWLESS_INPUT)));
    try {
        antTask.execute();
        fail("Exception is expected");
    } catch (BuildException ex) {
        assertTrue(ex.getMessage().startsWith("Unable to create Root Module: configLocation"));
    }
}
Also used : Project(org.apache.tools.ant.Project) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) Test(org.junit.Test)

Example 17 with Project

use of org.apache.tools.ant.Project in project checkstyle by checkstyle.

the class CheckstyleAntTaskTest method testNonExistingConfig.

@Test
public final void testNonExistingConfig() throws IOException {
    final CheckstyleAntTask antTask = new CheckstyleAntTask();
    antTask.setConfig(new File(getPath(NOT_EXISTING_FILE)));
    antTask.setProject(new Project());
    antTask.setFile(new File(getPath(FLAWLESS_INPUT)));
    try {
        antTask.execute();
        fail("Exception is expected");
    } catch (BuildException ex) {
        assertTrue(ex.getMessage().startsWith("Unable to create Root Module: configLocation"));
    }
}
Also used : Project(org.apache.tools.ant.Project) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) Test(org.junit.Test)

Example 18 with Project

use of org.apache.tools.ant.Project in project checkstyle by checkstyle.

the class CheckstyleAntTaskTest method testFailureProperty.

@Test
public final void testFailureProperty() throws IOException {
    final CheckstyleAntTask antTask = new CheckstyleAntTask();
    antTask.setConfig(new File(getPath(CONFIG_FILE)));
    antTask.setFile(new File(getPath(VIOLATED_INPUT)));
    final Project project = new Project();
    final String failurePropertyName = "myProperty";
    project.setProperty(failurePropertyName, FAILURE_PROPERTY_VALUE);
    antTask.setProject(project);
    antTask.setFailureProperty(failurePropertyName);
    try {
        antTask.execute();
        fail("Exception is expected");
    } catch (BuildException ex) {
        final Map<String, Object> hashtable = project.getProperties();
        final Object propertyValue = hashtable.get(failurePropertyName);
        assertEquals("Got 2 errors and 0 warnings.", propertyValue);
    }
}
Also used : Project(org.apache.tools.ant.Project) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) Map(java.util.Map) Test(org.junit.Test)

Example 19 with Project

use of org.apache.tools.ant.Project in project checkstyle by checkstyle.

the class CheckstyleAntTaskTest method testCheckerException.

@Test
public void testCheckerException() throws IOException {
    final CheckstyleAntTask antTask = new CheckstyleAntTaskStub();
    antTask.setConfig(new File(getPath(CONFIG_FILE)));
    antTask.setProject(new Project());
    antTask.setFile(new File(""));
    try {
        antTask.execute();
        fail("Exception is expected");
    } catch (BuildException ex) {
        assertTrue(ex.getMessage().startsWith("Unable to process files:"));
    }
}
Also used : Project(org.apache.tools.ant.Project) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) Test(org.junit.Test)

Example 20 with Project

use of org.apache.tools.ant.Project in project intellij-community by JetBrains.

the class ChainingFilterTransformer method doTransform.

private Reader doTransform(ResourceRootFilter filter, Reader original) {
    if ("RenamingCopyFilter".equals(filter.filterType)) {
        final Matcher matcher = (Matcher) filter.getProperties().get("matcher");
        final String replacement = (String) filter.getProperties().get("replacement");
        if (matcher == null || replacement == null)
            return original;
        matcher.reset(myOutputFileRef.get().getName());
        if (matcher.find()) {
            final String newFileName = matcher.replaceFirst(replacement);
            myOutputFileRef.set(new File(myOutputFileRef.get().getParentFile(), newFileName));
        }
        return original;
    }
    try {
        Class<?> clazz = Class.forName(filter.filterType);
        if (!FilterReader.class.isAssignableFrom(clazz)) {
            myContext.processMessage(new CompilerMessage(GradleResourcesBuilder.BUILDER_NAME, BuildMessage.Kind.WARNING, String.format("Error - Invalid filter specification for %s. It should extend java.io.FilterReader.", filter.filterType), null));
        }
        Constructor constructor = clazz.getConstructor(Reader.class);
        FilterReader result = (FilterReader) constructor.newInstance(original);
        final Map<Object, Object> properties = filter.getProperties();
        if (!properties.isEmpty()) {
            if (ExpandProperties.class.getName().equals(filter.filterType)) {
                final Map<Object, Object> antProps = new HashMap<>(properties);
                final Project project = new Project();
                for (Map.Entry<Object, Object> entry : antProps.entrySet()) {
                    project.setProperty(entry.getKey().toString(), entry.getValue().toString());
                }
                properties.clear();
                properties.put("project", project);
            }
            ConfigureUtil.configureByMap(properties, result);
        }
        return result;
    } catch (Throwable th) {
        myContext.processMessage(new CompilerMessage(GradleResourcesBuilder.BUILDER_NAME, BuildMessage.Kind.WARNING, String.format("Error - Failed to apply filter(%s): %s", filter.filterType, th.getMessage()), null));
    }
    return original;
}
Also used : CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) Matcher(java.util.regex.Matcher) Constructor(java.lang.reflect.Constructor) ExpandProperties(org.apache.tools.ant.filters.ExpandProperties) Project(org.apache.tools.ant.Project) File(java.io.File) FilterReader(java.io.FilterReader)

Aggregations

Project (org.apache.tools.ant.Project)80 File (java.io.File)35 BuildException (org.apache.tools.ant.BuildException)23 IOException (java.io.IOException)17 Test (org.junit.Test)13 FileSet (org.apache.tools.ant.types.FileSet)11 ZipFile (java.util.zip.ZipFile)10 IgniteDeploymentGarAntTask (org.apache.ignite.util.antgar.IgniteDeploymentGarAntTask)8 Path (org.apache.tools.ant.types.Path)6 DefaultLogger (org.apache.tools.ant.DefaultLogger)5 ProjectHelper (org.apache.tools.ant.ProjectHelper)5 MissingMethodException (groovy.lang.MissingMethodException)4 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)4 Task (org.apache.tools.ant.Task)4 AbstractProject (hudson.model.AbstractProject)3 Target (org.apache.tools.ant.Target)3 Zip (org.apache.tools.ant.taskdefs.Zip)3 CompilationFailedException (org.codehaus.groovy.control.CompilationFailedException)3 Binding (groovy.lang.Binding)2 GroovyClassLoader (groovy.lang.GroovyClassLoader)2