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"));
}
}
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"));
}
}
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);
}
}
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:"));
}
}
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;
}
Aggregations