Search in sources :

Example 6 with BuildException

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);
    }
}
Also used : MultipleChoiceInputRequest(org.apache.tools.ant.input.MultipleChoiceInputRequest) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException) Vector(java.util.Vector)

Example 7 with BuildException

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;
}
Also used : BuildException(org.apache.tools.ant.BuildException) Row(org.apache.poi.ss.usermodel.Row) CellReference(org.apache.poi.ss.util.CellReference) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell)

Example 8 with BuildException

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);
            }
        }
    }
}
Also used : Task(org.apache.tools.ant.Task) BuildException(org.apache.tools.ant.BuildException) ExcelAntEvaluationResult(org.apache.poi.ss.excelant.util.ExcelAntEvaluationResult)

Example 9 with BuildException

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;
}
Also used : BuildException(org.apache.tools.ant.BuildException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) BuildException(org.apache.tools.ant.BuildException)

Example 10 with BuildException

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 &lt;dependencyManagement&gt; section.  
   * An &lt;exclusion&gt; 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);
                    }
                }
            }
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Matcher(java.util.regex.Matcher) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream) TreeSet(java.util.TreeSet) BuildException(org.apache.tools.ant.BuildException) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Aggregations

BuildException (org.apache.tools.ant.BuildException)930 IOException (java.io.IOException)390 File (java.io.File)365 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)75 ArrayList (java.util.ArrayList)65 InputStream (java.io.InputStream)62 Project (org.apache.tools.ant.Project)61 Resource (org.apache.tools.ant.types.Resource)58 FileSet (org.apache.tools.ant.types.FileSet)52 Path (org.apache.tools.ant.types.Path)52 Commandline (org.apache.tools.ant.types.Commandline)51 Properties (java.util.Properties)50 OutputStream (java.io.OutputStream)44 FileOutputStream (java.io.FileOutputStream)42 FileResource (org.apache.tools.ant.types.resources.FileResource)42 FileInputStream (java.io.FileInputStream)41 URL (java.net.URL)40 BufferedReader (java.io.BufferedReader)37 Writer (java.io.Writer)37 MalformedURLException (java.net.MalformedURLException)37