use of org.apache.tools.ant.BuildException in project intellij-community by JetBrains.
the class IdeaInputHandler method handleInput.
public void handleInput(InputRequest request) throws BuildException {
final String prompt = request.getPrompt();
if (prompt == null) {
throw new BuildException("Prompt is null");
}
final SegmentedOutputStream err = IdeaAntLogger2.ourErr;
if (err == null) {
throw new BuildException("Selected InputHandler should be used by Intellij IDEA");
}
final PacketWriter packet = PacketFactory.ourInstance.createPacket(IdeaAntLogger2.INPUT_REQUEST);
packet.appendLimitedString(prompt);
packet.appendLimitedString(request.getDefaultValue());
if (request instanceof MultipleChoiceInputRequest) {
Vector choices = ((MultipleChoiceInputRequest) request).getChoices();
if (choices != null && choices.size() > 0) {
int count = choices.size();
packet.appendLong(count);
for (int i = 0; i < count; i++) {
packet.appendLimitedString((String) choices.elementAt(i));
}
} else {
packet.appendLong(0);
}
} else {
packet.appendLong(0);
}
packet.sendThrough(err);
try {
final byte[] replayLength = readBytes(4);
final int length = ((int) replayLength[0] << 24) | ((int) replayLength[1] << 16) | ((int) replayLength[2] << 8) | replayLength[3];
final byte[] replay = readBytes(length);
final String input = new String(replay);
request.setInput(input);
if (!request.isInputValid()) {
throw new BuildException("Invalid input: " + input);
}
} catch (IOException e) {
throw new BuildException(e);
}
}
use of org.apache.tools.ant.BuildException in project poi by apache.
the class ExcelAntWorkbookUtil method getCell.
/**
* Returns a cell reference based on a String in standard Excel format
* (SheetName!CellId). This method will create a new cell if the
* requested cell isn't initialized yet.
*
* @param cellName
* @return
*/
private Cell getCell(String cellName) {
CellReference cellRef = new CellReference(cellName);
String sheetName = cellRef.getSheetName();
Sheet sheet = workbook.getSheet(sheetName);
if (sheet == null) {
throw new BuildException("Sheet not found: " + sheetName);
}
int rowIdx = cellRef.getRow();
int colIdx = cellRef.getCol();
Row row = sheet.getRow(rowIdx);
if (row == null) {
row = sheet.createRow(rowIdx);
}
Cell cell = row.getCell(colIdx);
if (cell == null) {
cell = row.createCell(colIdx);
}
return cell;
}
use of org.apache.tools.ant.BuildException in project poi by apache.
the class ExcelAntTest method execute.
@Override
public void execute() throws BuildException {
Iterator<Task> taskIt = testTasks.iterator();
int testCount = evaluators.size();
int failureCount = 0;
// ordering of the sub elements to be considered.
while (taskIt.hasNext()) {
Task task = taskIt.next();
if (task instanceof ExcelAntSet) {
ExcelAntSet set = (ExcelAntSet) task;
set.setWorkbookUtil(workbookUtil);
set.execute();
}
if (task instanceof ExcelAntHandlerTask) {
ExcelAntHandlerTask handler = (ExcelAntHandlerTask) task;
handler.setEAWorkbookUtil(workbookUtil);
handler.execute();
}
if (task instanceof ExcelAntEvaluateCell) {
ExcelAntEvaluateCell eval = (ExcelAntEvaluateCell) task;
eval.setWorkbookUtil(workbookUtil);
if (globalPrecision > 0) {
log("setting globalPrecision to " + globalPrecision + " in the evaluator", Project.MSG_VERBOSE);
eval.setGlobalPrecision(globalPrecision);
}
try {
eval.execute();
ExcelAntEvaluationResult result = eval.getResult();
if (result.didTestPass() && !result.evaluationCompleteWithError()) {
if (showSuccessDetails) {
log("Succeeded when evaluating " + result.getCellName() + ". It evaluated to " + result.getReturnValue() + " when the value of " + eval.getExpectedValue() + " with precision of " + eval.getPrecision(), Project.MSG_INFO);
}
} else {
if (showFailureDetail) {
failureMessages.add("\tFailed to evaluate cell " + result.getCellName() + ". It evaluated to " + result.getReturnValue() + " when the value of " + eval.getExpectedValue() + " with precision of " + eval.getPrecision() + " was expected.");
}
passed = false;
failureCount++;
if (eval.requiredToPass()) {
throw new BuildException("\tFailed to evaluate cell " + result.getCellName() + ". It evaluated to " + result.getReturnValue() + " when the value of " + eval.getExpectedValue() + " with precision of " + eval.getPrecision() + " was expected.");
}
}
} catch (NullPointerException npe) {
// this means the cell reference in the test is bad.
log("Cell assignment " + eval.getCell() + " in test " + getName() + " appears to point to an empy cell. Please check the " + " reference in the ant script.", Project.MSG_ERR);
}
}
}
if (!passed) {
log("Test named " + name + " failed because " + failureCount + " of " + testCount + " evaluations failed to " + "evaluate correctly.", Project.MSG_ERR);
if (showFailureDetail && failureMessages.size() > 0) {
for (String failureMessage : failureMessages) {
log(failureMessage, Project.MSG_ERR);
}
}
}
}
use of org.apache.tools.ant.BuildException in project poi by apache.
the class ExcelAntTask method execute.
@Override
public void execute() throws BuildException {
checkClassPath();
int totalCount = 0;
int successCount = 0;
StringBuilder versionBffr = new StringBuilder();
versionBffr.append("ExcelAnt version ");
versionBffr.append(VERSION);
versionBffr.append(" Copyright 2011");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy", Locale.ROOT);
double currYear = Double.parseDouble(sdf.format(new Date()));
if (currYear > 2011) {
versionBffr.append("-");
versionBffr.append(currYear);
}
log(versionBffr.toString(), Project.MSG_INFO);
log("Using input file: " + excelFileName, Project.MSG_INFO);
workbookUtil = ExcelAntWorkbookUtilFactory.getInstance(excelFileName);
for (ExcelAntTest test : tests) {
log("executing test: " + test.getName(), Project.MSG_DEBUG);
if (workbookUtil == null) {
workbookUtil = ExcelAntWorkbookUtilFactory.getInstance(excelFileName);
}
for (ExcelAntUserDefinedFunction eaUdf : functions) {
try {
workbookUtil.addFunction(eaUdf.getFunctionAlias(), eaUdf.getClassName());
} catch (Exception e) {
throw new BuildException(e.getMessage(), e);
}
}
test.setWorkbookUtil(workbookUtil);
if (precision != null && precision.getValue() > 0) {
log("setting precision for the test " + test.getName(), Project.MSG_VERBOSE);
test.setPrecision(precision.getValue());
}
test.execute();
if (test.didTestPass()) {
successCount++;
} else {
if (failOnError) {
throw new BuildException("Test " + test.getName() + " failed.");
}
}
totalCount++;
workbookUtil = null;
}
if (!tests.isEmpty()) {
log(successCount + "/" + totalCount + " tests passed.", Project.MSG_INFO);
}
workbookUtil = null;
}
use of org.apache.tools.ant.BuildException in project lucene-solr by apache.
the class GetMavenDependenciesTask method appendAllExternalDependencies.
/**
* Append each dependency listed in the centralized Ivy versions file
* to the grandparent POM's <dependencyManagement> section.
* An <exclusion> is added for each of the artifact's dependencies,
* which are collected from the artifact's ivy.xml from the Ivy cache.
*
* Also add a version property for each dependency.
*/
private void appendAllExternalDependencies(StringBuilder dependenciesBuilder, Map<String, String> versionsMap) {
log("Loading centralized ivy versions from: " + centralizedVersionsFile, verboseLevel);
ivyCacheDir = getIvyCacheDir();
Properties versions = new InterpolatedProperties();
try (InputStream inputStream = new FileInputStream(centralizedVersionsFile);
Reader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)) {
versions.load(reader);
} catch (IOException e) {
throw new BuildException("Exception reading centralized versions file " + centralizedVersionsFile.getPath(), e);
}
SortedSet<Map.Entry<?, ?>> sortedEntries = new TreeSet<>(new Comparator<Map.Entry<?, ?>>() {
@Override
public int compare(Map.Entry<?, ?> o1, Map.Entry<?, ?> o2) {
return ((String) o1.getKey()).compareTo((String) o2.getKey());
}
});
sortedEntries.addAll(versions.entrySet());
for (Map.Entry<?, ?> entry : sortedEntries) {
String key = (String) entry.getKey();
Matcher matcher = COORDINATE_KEY_PATTERN.matcher(key);
if (matcher.lookingAt()) {
String groupId = matcher.group(1);
String artifactId = matcher.group(2);
String coordinate = groupId + ':' + artifactId;
String version = (String) entry.getValue();
versionsMap.put(coordinate + ".version", version);
if (!nonJarDependencies.contains(coordinate)) {
Set<String> classifiers = dependencyClassifiers.get(coordinate);
if (null != classifiers) {
for (String classifier : classifiers) {
Collection<String> exclusions = getTransitiveDependenciesFromIvyCache(groupId, artifactId, version);
appendDependencyXml(dependenciesBuilder, groupId, artifactId, " ", version, false, false, classifier, exclusions);
}
}
}
}
}
}
Aggregations