当前位置: 首页>>代码示例>>Java>>正文


Java FileAndLine类代码示例

本文整理汇总了Java中com.android.manifmerger.IMergerLog.FileAndLine的典型用法代码示例。如果您正苦于以下问题:Java FileAndLine类的具体用法?Java FileAndLine怎么用?Java FileAndLine使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FileAndLine类属于com.android.manifmerger.IMergerLog包,在下文中一共展示了FileAndLine类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: process

import com.android.manifmerger.IMergerLog.FileAndLine; //导入依赖的package包/类
/**
 * Performs the merge operation.
 * <p/>
 * This does NOT stop on errors, in an attempt to accumulate as much
 * info as possible to return to the user.
 * Unless it failed to read the main manifest, a result file will be
 * created. However if process() returns false, the file should not
 * be used except for debugging purposes.
 *
 * @param outputFile The output path to generate. Can be the same as the main path.
 * @param mainFile The main manifest paths to read. What we merge into.
 * @param libraryFiles The library manifest paths to read. Must not be null.
 * @param injectAttributes A map of attributes to inject in the form [pseudo-xpath] => value.
 *   The key is "/manifest/elements...|attribute-ns-uri attribute-local-name",
 *   for example "/manifest/uses-sdk|http://schemas.android.com/apk/res/android minSdkVersion".
 *   (note the space separator between the attribute URI and its local name.)
 *   The elements will be created if they don't exists. Existing attributes will be modified.
 *   The replacement is done on the main document <em>before</em> merging.
 * @param packageOverride an optional package override. This only affects the package attribute,
 *   all components (activities, receivers, etc...) are not affected by this.
 * @return True if the merge was completed, false otherwise.
 */
public boolean process(
        File outputFile,
        File mainFile,
        File[] libraryFiles,
        Map<String, String> injectAttributes,
        String packageOverride) {
    Document mainDoc = MergerXmlUtils.parseDocument(mainFile, mLog, this);
    if (mainDoc == null) {
        mLog.error(Severity.ERROR, new FileAndLine(mainFile.getAbsolutePath(), 0),
                "Failed to read manifest file.");
        return false;
    }

    boolean success = process(mainDoc, libraryFiles, injectAttributes, packageOverride);

    if (!MergerXmlUtils.printXmlFile(mainDoc, outputFile, mLog)) {
        mLog.error(Severity.ERROR, new FileAndLine(outputFile.getAbsolutePath(), 0),
                "Failed to write manifest file.");
        success = false;
    }

    return success;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:46,代码来源:ManifestMerger.java

示例2: parseDocument

import com.android.manifmerger.IMergerLog.FileAndLine; //导入依赖的package包/类
/**
 * Parses the given XML string as a DOM document.
 * The parser does not validate the DTD nor any kind of schema.
 * It is namespace aware.
 *
 * @param xml The XML string to parse. Must not be null.
 * @param log An {@link ILogger} for reporting errors. Must not be null.
 * @return A new DOM {@link Document}, or null.
 */
@VisibleForTesting
@Nullable
static Document parseDocument(@NonNull String xml,
        @NonNull IMergerLog log,
        @NonNull FileAndLine errorContext) {
    try {
        Document doc = XmlUtils.parseDocument(xml, true);
        findLineNumbers(doc, 1);
        if (errorContext.getFileName() != null) {
            setSource(doc, new File(errorContext.getFileName()));
        }
        return doc;
    } catch (Exception e) {
        log.error(Severity.ERROR, errorContext, "Failed to parse XML string");
    }

    return null;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:28,代码来源:MergerXmlUtils.java

示例3: printXmlFile

import com.android.manifmerger.IMergerLog.FileAndLine; //导入依赖的package包/类
/**
 * Outputs the given XML {@link Document} to the file {@code outFile}.
 *
 * TODO right now reformats the document. Needs to output as-is, respecting white-space.
 *
 * @param doc The document to output. Must not be null.
 * @param outFile The {@link File} where to write the document.
 * @param log A log in case of error.
 * @return True if the file was written, false in case of error.
 */
static boolean printXmlFile(
        @NonNull Document doc,
        @NonNull File outFile,
        @NonNull IMergerLog log) {
    // Quick thing based on comments from http://stackoverflow.com/questions/139076
    try {
        Transformer tf = TransformerFactory.newInstance().newTransformer();
        tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");         //$NON-NLS-1$
        tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8");                   //$NON-NLS-1$
        tf.setOutputProperty(OutputKeys.INDENT, "yes");                       //$NON-NLS-1$
        tf.setOutputProperty("{http://xml.apache.org/xslt}indent-amount",     //$NON-NLS-1$
                             "4");                                            //$NON-NLS-1$
        tf.transform(new DOMSource(doc), new StreamResult(outFile));
        return true;
    } catch (TransformerException e) {
        log.error(Severity.ERROR,
                new FileAndLine(outFile.getName(), 0),
                "Failed to write XML file: %1$s",
                e.toString());
        return false;
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:33,代码来源:MergerXmlUtils.java

示例4: printXmlString

import com.android.manifmerger.IMergerLog.FileAndLine; //导入依赖的package包/类
/**
 * Outputs the given XML {@link Document} as a string.
 *
 * TODO right now reformats the document. Needs to output as-is, respecting white-space.
 *
 * @param doc The document to output. Must not be null.
 * @param log A log in case of error.
 * @return A string representation of the XML. Null in case of error.
 */
static String printXmlString(
        @NonNull Document doc,
        @NonNull IMergerLog log) {
    try {
        Transformer tf = TransformerFactory.newInstance().newTransformer();
        tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");        //$NON-NLS-1$
        tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8");                  //$NON-NLS-1$
        tf.setOutputProperty(OutputKeys.INDENT, "yes");                      //$NON-NLS-1$
        tf.setOutputProperty("{http://xml.apache.org/xslt}indent-amount",    //$NON-NLS-1$
                             "4");                                           //$NON-NLS-1$
        StringWriter sw = new StringWriter();
        tf.transform(new DOMSource(doc), new StreamResult(sw));
        return sw.toString();
    } catch (TransformerException e) {
        log.error(Severity.ERROR,
                new FileAndLine(extractXmlFilename(doc), 0),
                "Failed to write XML file: %1$s",
                e.toString());
        return null;
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:31,代码来源:MergerXmlUtils.java

示例5: parseDocument

import com.android.manifmerger.IMergerLog.FileAndLine; //导入依赖的package包/类
/**
 * Parses the given XML string as a DOM document.
 * The parser does not validate the DTD nor any kind of schema.
 * It is namespace aware.
 *
 * @param xml The XML string to parse. Must not be null.
 * @param log An {@link ILogger} for reporting errors. Must not be null.
 * @return A new DOM {@link org.w3c.dom.Document}, or null.
 */
@Nullable
static Document parseDocument(@NonNull String xml,
        @NonNull IMergerLog log,
        @NonNull FileAndLine errorContext) {
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        InputSource is = new InputSource(new StringReader(xml));
        factory.setNamespaceAware(true);
        factory.setValidating(false);
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document doc = builder.parse(is);
        findLineNumbers(doc, 1);
        return doc;
    } catch (Exception e) {
        log.error(Severity.ERROR, errorContext, "Failed to parse XML string");
    }

    return null;
}
 
开发者ID:saleehk,项目名称:buck-cutom,代码行数:29,代码来源:XmlUtils.java

示例6: printXmlFile

import com.android.manifmerger.IMergerLog.FileAndLine; //导入依赖的package包/类
/**
 * Outputs the given XML {@link org.w3c.dom.Document} to the file {@code outFile}.
 *
 * TODO right now reformats the document. Needs to output as-is, respecting white-space.
 *
 * @param doc The document to output. Must not be null.
 * @param outFile The {@link java.io.File} where to write the document.
 * @param log A log in case of error.
 * @return True if the file was written, false in case of error.
 */
static boolean printXmlFile(
        @NonNull Document doc,
        @NonNull File outFile,
        @NonNull IMergerLog log) {
    // Quick thing based on comments from http://stackoverflow.com/questions/139076
    try {
        Transformer tf = TransformerFactory.newInstance().newTransformer();
        tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");         //$NON-NLS-1$
        tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8");                   //$NON-NLS-1$
        tf.setOutputProperty(OutputKeys.INDENT, "yes");                       //$NON-NLS-1$
        tf.setOutputProperty("{http://xml.apache.org/xslt}indent-amount",     //$NON-NLS-1$
                             "4");                                            //$NON-NLS-1$
        tf.transform(new DOMSource(doc), new StreamResult(outFile));
        return true;
    } catch (TransformerException e) {
        log.error(Severity.ERROR,
                new FileAndLine(outFile.getName(), 0),
                "Failed to write XML file: %1$s",
                e.toString());
        return false;
    }
}
 
开发者ID:saleehk,项目名称:buck-cutom,代码行数:33,代码来源:XmlUtils.java

示例7: printXmlString

import com.android.manifmerger.IMergerLog.FileAndLine; //导入依赖的package包/类
/**
 * Outputs the given XML {@link org.w3c.dom.Document} as a string.
 *
 * TODO right now reformats the document. Needs to output as-is, respecting white-space.
 *
 * @param doc The document to output. Must not be null.
 * @param log A log in case of error.
 * @return A string representation of the XML. Null in case of error.
 */
static String printXmlString(
        @NonNull Document doc,
        @NonNull IMergerLog log) {
    try {
        Transformer tf = TransformerFactory.newInstance().newTransformer();
        tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");        //$NON-NLS-1$
        tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8");                  //$NON-NLS-1$
        tf.setOutputProperty(OutputKeys.INDENT, "yes");                      //$NON-NLS-1$
        tf.setOutputProperty("{http://xml.apache.org/xslt}indent-amount",    //$NON-NLS-1$
                             "4");                                           //$NON-NLS-1$
        StringWriter sw = new StringWriter();
        tf.transform(new DOMSource(doc), new StreamResult(sw));
        return sw.toString();
    } catch (TransformerException e) {
        log.error(Severity.ERROR,
                new FileAndLine(extractXmlFilename(doc), 0),
                "Failed to write XML file: %1$s",
                e.toString());
        return null;
    }
}
 
开发者ID:saleehk,项目名称:buck-cutom,代码行数:31,代码来源:XmlUtils.java

示例8: xmlFileAndLine

import com.android.manifmerger.IMergerLog.FileAndLine; //导入依赖的package包/类
/**
 * Returns a new {@link FileAndLine} structure that identifies
 * the base filename & line number from which the XML node was parsed.
 * <p/>
 * When the line number is unknown (e.g. if a {@link Document} instance is given)
 * then line number 0 will be used.
 *
 * @param node The node or document where the error occurs. Must not be null.
 * @return A new non-null {@link FileAndLine} combining the file name and line number.
 */
@NonNull
static FileAndLine xmlFileAndLine(@NonNull Node node) {
    String name = extractXmlFilename(node);
    int line = extractLineNumber(node); // 0 in case of error or unknown
    return new FileAndLine(name, line);
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:17,代码来源:MergerXmlUtils.java

示例9: xmlFileAndLine

import com.android.manifmerger.IMergerLog.FileAndLine; //导入依赖的package包/类
/**
 * Returns a new {@link FileAndLine} structure that identifies
 * the base filename & line number from which the XML node was parsed.
 * <p/>
 * When the line number is unknown (e.g. if a {@link Document} instance is given)
 * then line number 0 will be used.
 *
 * @param node The node or document where the error occurs. Must not be null.
 * @return A new non-null {@link FileAndLine} combining the file name and line number.
 */
@NonNull
private FileAndLine xmlFileAndLine(@NonNull Node node) {
    return MergerXmlUtils.xmlFileAndLine(node);
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:15,代码来源:ManifestMerger.java

示例10: xmlFileAndLine

import com.android.manifmerger.IMergerLog.FileAndLine; //导入依赖的package包/类
/**
 * Returns a new {@link FileAndLine} structure that identifies
 * the base filename & line number from which the XML node was parsed.
 * <p/>
 * When the line number is unknown (e.g. if a {@link Document} instance is given)
 * then line number 0 will be used.
 *
 * @param node The node or document where the error occurs. Must not be null.
 * @return A new non-null {@link FileAndLine} combining the file name and line number.
 */
private @NonNull FileAndLine xmlFileAndLine(@NonNull Node node) {
  String name = XmlUtils.extractXmlFilename(node);
  int line = XmlUtils.extractLineNumber(node); // 0 in case of error or unknown
  return new FileAndLine(name, line);
}
 
开发者ID:saleehk,项目名称:buck-cutom,代码行数:16,代码来源:ManifestMerger.java


注:本文中的com.android.manifmerger.IMergerLog.FileAndLine类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。