Search in sources :

Example 56 with BuildException

use of org.apache.tools.ant.BuildException in project mylyn.docs by eclipse.

the class EpubTask method addFilesets.

private void addFilesets() {
    for (FileSetType fs : filesets) {
        final File fsDir = fs.getDir(getProject());
        if (fsDir == null) {
            // $NON-NLS-1$
            throw new BuildException("File or Resource without directory or file specified");
        } else if (!fsDir.isDirectory()) {
            // $NON-NLS-1$
            throw new BuildException("Directory does not exist:" + fsDir);
        }
        DirectoryScanner ds = fs.getDirectoryScanner(getProject());
        String[] includedFiles = ds.getIncludedFiles();
        for (String includedFile : includedFiles) {
            String filename = includedFile.replace('\\', '/');
            filename = filename.substring(filename.lastIndexOf('/') + 1);
            File base = ds.getBasedir();
            File found = new File(base, includedFile);
            oebps.addItem(null, fs.lang, found, fs.dest, null, false, true, false);
        }
    }
}
Also used : DirectoryScanner(org.apache.tools.ant.DirectoryScanner) BuildException(org.apache.tools.ant.BuildException) File(java.io.File)

Example 57 with BuildException

use of org.apache.tools.ant.BuildException in project mylyn.docs by eclipse.

the class MarkupToDitaTask method processFile.

private void processFile(MarkupLanguage markupLanguage, final File baseDir, final File source) throws BuildException {
    // $NON-NLS-1$
    log(MessageFormat.format(Messages.getString("MarkupToDitaTask.8"), source), Project.MSG_VERBOSE);
    String markupContent = null;
    String name = source.getName();
    if (name.lastIndexOf('.') != -1) {
        name = name.substring(0, name.lastIndexOf('.'));
    }
    // $NON-NLS-1$
    File outputFile = new File(source.getParentFile(), filenameFormat.replace("$1", name));
    if (!outputFile.exists() || overwrite || outputFile.lastModified() < source.lastModified()) {
        if (markupContent == null) {
            markupContent = readFully(source);
        }
        performValidation(source, markupContent);
        OutlineItem outline = new OutlineParser(markupLanguage).parse(markupContent);
        Writer writer;
        try {
            // $NON-NLS-1$
            writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(outputFile)), "utf-8");
        } catch (Exception e) {
            throw new BuildException(// $NON-NLS-1$
            MessageFormat.format(// $NON-NLS-1$
            Messages.getString("MarkupToDitaTask.11"), // $NON-NLS-1$
            outputFile, e.getMessage()), e);
        }
        try {
            if (topicStrategy == BreakStrategy.NONE) {
                DitaTopicDocumentBuilder builder = new DitaTopicDocumentBuilder(new DefaultXmlStreamWriter(writer), formatting);
                builder.setRootTopicTitle(bookTitle);
                MarkupParser parser = new MarkupParser();
                parser.setMarkupLanguage(markupLanguage);
                parser.setBuilder(builder);
                if (topicDoctype != null) {
                    builder.setDoctype(topicDoctype);
                }
                builder.setFilename(outputFile.getName());
                builder.setOutline(outline);
                parser.parse(markupContent);
            } else {
                DitaBookMapDocumentBuilder builder = new DitaBookMapDocumentBuilder(formatting ? new FormattingXMLStreamWriter(new DefaultXmlStreamWriter(writer)) : new DefaultXmlStreamWriter(writer));
                try {
                    builder.setFormattingDependencies(formatting);
                    MarkupParser parser = new MarkupParser();
                    parser.setMarkupLanguage(markupLanguage);
                    parser.setBuilder(builder);
                    builder.setBookTitle(bookTitle == null ? name : bookTitle);
                    if (doctype != null) {
                        builder.setDoctype(doctype);
                    }
                    if (topicDoctype != null) {
                        builder.setTopicDoctype(topicDoctype);
                    }
                    builder.setTargetFile(outputFile);
                    builder.setTopicFolder(topicFolder);
                    builder.setOutline(outline);
                    switch(topicStrategy) {
                        case FIRST:
                            if (!outline.getChildren().isEmpty()) {
                                builder.setTopicBreakLevel(outline.getChildren().get(0).getLevel());
                            } else {
                                builder.setTopicBreakLevel(1);
                            }
                            break;
                        case LEVEL1:
                            builder.setTopicBreakLevel(1);
                            break;
                    }
                    parser.parse(markupContent);
                } finally {
                    try {
                        builder.close();
                    } catch (IOException e) {
                        throw new BuildException(MessageFormat.format(// $NON-NLS-1$
                        Messages.getString("MarkupToDitaTask.12"), // $NON-NLS-1$
                        outputFile, e.getMessage()), e);
                    }
                }
            }
        } finally {
            try {
                writer.close();
            } catch (Exception e) {
                throw new BuildException(MessageFormat.format(// $NON-NLS-1$
                Messages.getString("MarkupToDitaTask.12"), // $NON-NLS-1$
                outputFile, e.getMessage()), e);
            }
        }
    }
}
Also used : DitaBookMapDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.DitaBookMapDocumentBuilder) FormattingXMLStreamWriter(org.eclipse.mylyn.wikitext.util.FormattingXMLStreamWriter) DitaTopicDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.DitaTopicDocumentBuilder) DefaultXmlStreamWriter(org.eclipse.mylyn.wikitext.util.DefaultXmlStreamWriter) IOException(java.io.IOException) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem) OutlineParser(org.eclipse.mylyn.wikitext.parser.outline.OutlineParser) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) FormattingXMLStreamWriter(org.eclipse.mylyn.wikitext.util.FormattingXMLStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) DefaultXmlStreamWriter(org.eclipse.mylyn.wikitext.util.DefaultXmlStreamWriter) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Example 58 with BuildException

use of org.apache.tools.ant.BuildException in project mylyn.docs by eclipse.

the class MarkupToXslfoTask method execute.

@Override
public void execute() throws BuildException {
    if (file == null && filesets.isEmpty()) {
        // $NON-NLS-1$
        throw new BuildException(Messages.getString("MarkupToXslfoTask.0"));
    }
    if (file != null && !filesets.isEmpty()) {
        // $NON-NLS-1$
        throw new BuildException(Messages.getString("MarkupToXslfoTask.1"));
    }
    if (file != null) {
        if (!file.exists()) {
            // $NON-NLS-1$
            throw new BuildException(MessageFormat.format(Messages.getString("MarkupToXslfoTask.2"), file));
        } else if (!file.isFile()) {
            // $NON-NLS-1$
            throw new BuildException(MessageFormat.format(Messages.getString("MarkupToXslfoTask.3"), file));
        } else if (!file.canRead()) {
            // $NON-NLS-1$
            throw new BuildException(MessageFormat.format(Messages.getString("MarkupToXslfoTask.4"), file));
        }
    }
    MarkupLanguage markupLanguage = createMarkupLanguage();
    for (FileSet fileset : filesets) {
        File filesetBaseDir = fileset.getDir(getProject());
        DirectoryScanner ds = fileset.getDirectoryScanner(getProject());
        String[] files = ds.getIncludedFiles();
        if (files != null) {
            File baseDir = ds.getBasedir();
            for (String file : files) {
                File inputFile = new File(baseDir, file);
                try {
                    processFile(markupLanguage, filesetBaseDir, inputFile);
                } catch (BuildException e) {
                    throw e;
                } catch (Exception e) {
                    throw new BuildException(MessageFormat.format(// $NON-NLS-1$
                    Messages.getString("MarkupToXslfoTask.5"), // $NON-NLS-1$
                    inputFile, e.getMessage()), e);
                }
            }
        }
    }
    if (file != null) {
        try {
            processFile(markupLanguage, file.getParentFile(), file);
        } catch (BuildException e) {
            throw e;
        } catch (Exception e) {
            throw new BuildException(MessageFormat.format(Messages.getString("MarkupToXslfoTask.6"), file, e.getMessage()), // $NON-NLS-1$
            e);
        }
    }
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) BuildException(org.apache.tools.ant.BuildException) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) File(java.io.File) BuildException(org.apache.tools.ant.BuildException)

Example 59 with BuildException

use of org.apache.tools.ant.BuildException in project mylyn.docs by eclipse.

the class HtmlToMarkupTask method execute.

@Override
public void execute() throws BuildException {
    if (file == null && filesets.isEmpty()) {
        // $NON-NLS-1$
        throw new BuildException(Messages.getString("MarkupToHtmlTask.1"));
    }
    if (file != null && !filesets.isEmpty()) {
        // $NON-NLS-1$
        throw new BuildException(Messages.getString("MarkupToHtmlTask.2"));
    }
    if (file != null) {
        if (!file.exists()) {
            // $NON-NLS-1$
            throw new BuildException(MessageFormat.format(Messages.getString("MarkupToHtmlTask.3"), file));
        } else if (!file.isFile()) {
            // $NON-NLS-1$
            throw new BuildException(MessageFormat.format(Messages.getString("MarkupToHtmlTask.4"), file));
        } else if (!file.canRead()) {
            // $NON-NLS-1$
            throw new BuildException(MessageFormat.format(Messages.getString("MarkupToHtmlTask.5"), file));
        }
    }
    MarkupLanguage markupLanguage = createMarkupLanguage();
    for (FileSet fileset : filesets) {
        File filesetBaseDir = fileset.getDir(getProject());
        DirectoryScanner ds = fileset.getDirectoryScanner(getProject());
        String[] files = ds.getIncludedFiles();
        if (files != null) {
            File baseDir = ds.getBasedir();
            for (String file : files) {
                File inputFile = new File(baseDir, file);
                try {
                    processFile(markupLanguage, filesetBaseDir, inputFile);
                } catch (BuildException e) {
                    throw e;
                } catch (Exception e) {
                    throw new BuildException(MessageFormat.format(// $NON-NLS-1$
                    Messages.getString("MarkupToHtmlTask.11"), // $NON-NLS-1$
                    inputFile, e.getMessage()), e);
                }
            }
        }
    }
    if (file != null) {
        try {
            processFile(markupLanguage, file.getParentFile(), file);
        } catch (BuildException e) {
            throw e;
        } catch (Exception e) {
            throw new BuildException(MessageFormat.format(Messages.getString("MarkupToHtmlTask.12"), file, e.getMessage()), // $NON-NLS-1$
            e);
        }
    }
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) BuildException(org.apache.tools.ant.BuildException) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) File(java.io.File) BuildException(org.apache.tools.ant.BuildException)

Example 60 with BuildException

use of org.apache.tools.ant.BuildException in project mylyn.docs by eclipse.

the class MarkupToDocbookTask method execute.

@Override
public void execute() throws BuildException {
    if (file == null && filesets.isEmpty()) {
        // $NON-NLS-1$
        throw new BuildException(Messages.getString("MarkupToDocbookTask.1"));
    }
    if (file != null && !filesets.isEmpty()) {
        // $NON-NLS-1$
        throw new BuildException(Messages.getString("MarkupToDocbookTask.2"));
    }
    if (file != null) {
        if (!file.exists()) {
            // $NON-NLS-1$
            throw new BuildException(MessageFormat.format(Messages.getString("MarkupToDocbookTask.3"), file));
        } else if (!file.isFile()) {
            // $NON-NLS-1$
            throw new BuildException(MessageFormat.format(Messages.getString("MarkupToDocbookTask.4"), file));
        } else if (!file.canRead()) {
            // $NON-NLS-1$
            throw new BuildException(MessageFormat.format(Messages.getString("MarkupToDocbookTask.5"), file));
        }
    }
    MarkupLanguage markupLanguage = createMarkupLanguage();
    for (FileSet fileset : filesets) {
        File filesetBaseDir = fileset.getDir(getProject());
        DirectoryScanner ds = fileset.getDirectoryScanner(getProject());
        String[] files = ds.getIncludedFiles();
        if (files != null) {
            File baseDir = ds.getBasedir();
            for (String file : files) {
                File inputFile = new File(baseDir, file);
                try {
                    processFile(markupLanguage, filesetBaseDir, inputFile);
                } catch (BuildException e) {
                    throw e;
                } catch (Exception e) {
                    throw new BuildException(MessageFormat.format(// $NON-NLS-1$
                    Messages.getString("MarkupToDocbookTask.6"), // $NON-NLS-1$
                    inputFile, e.getMessage()), e);
                }
            }
        }
    }
    if (file != null) {
        try {
            processFile(markupLanguage, file.getParentFile(), file);
        } catch (BuildException e) {
            throw e;
        } catch (Exception e) {
            throw new BuildException(MessageFormat.format(Messages.getString("MarkupToDocbookTask.7"), file, e.getMessage()), // $NON-NLS-1$
            e);
        }
    }
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) BuildException(org.apache.tools.ant.BuildException) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) File(java.io.File) BuildException(org.apache.tools.ant.BuildException)

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