Search in sources :

Example 96 with DocumentException

use of org.dom4j.DocumentException in project atlas by alibaba.

the class TPatchDiffResAPBuildTask method doAction.

@TaskAction
protected void doAction() throws IOException {
    manifestFile = getManifestFile();
    aaptOptions = getAaptOptions();
    diffResDir = getDiffResDir();
    resourceConfigs = getResourceConfigs();
    preferredDensity = getPreferredDensity();
    SplitList splitList = SplitList.load(splitListInput);
    // TODO  minifyManifest
    File miniManifest = new File(packageOutputFile.getParentFile(), "AndroidManifest.xml");
    try {
        ManifestFileUtils.createPatchManifest(manifestFile, getBaseManifestFile(), miniManifest);
    } catch (DocumentException e) {
        throw new GradleException(e.getMessage());
    }
    String splitFilter = apkData.getFilter(com.android.build.OutputFile.FilterType.DENSITY);
    String preferredDensity = splitFilter != null ? splitFilter : // if resConfigs is set, we should not use our preferredDensity.
    splitList.getFilters(SplitList.RESOURCE_CONFIGS).isEmpty() ? buildTargetDensity : null;
    File assetsFolder = new File(diffResDir, "assets");
    File resFolder = new File(diffResDir, "res");
    if (!assetsFolder.exists()) {
        assetsFolder.mkdirs();
    }
    if (!resFolder.exists()) {
        resFolder.mkdirs();
    }
    aaptOptions.getAdditionalParameters().add("-A");
    aaptOptions.getAdditionalParameters().add(assetsFolder.getAbsolutePath());
    AaptGeneration aaptGeneration = AaptGeneration.fromProjectOptions(appVariantContext.getScope().getGlobalScope().getProjectOptions());
    Aapt aapt = makeAapt(aaptGeneration);
    AaptPackageConfig.Builder config = new AaptPackageConfig.Builder().setManifestFile(miniManifest).setOptions(DslAdaptersKt.convert(aaptOptions)).setResourceDir(resFolder).setLibrarySymbolTableFiles(ImmutableSet.of()).setCustomPackageForR(packageForR).setResourceOutputApk(packageOutputFile).setVariantType(type).setDebuggable(debuggable).setResourceConfigs(splitList.getFilters(SplitList.RESOURCE_CONFIGS)).setSplits(getSplits(splitList)).setPreferredDensity(preferredDensity).setListResourceFiles(aaptGeneration == AaptGeneration.AAPT_V2);
    try {
        getBuilder().processResources(aapt, config);
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ProcessException e) {
        e.printStackTrace();
    }
}
Also used : SplitList(com.android.build.gradle.internal.scope.SplitList) ProcessException(com.android.ide.common.process.ProcessException) AaptGeneration(com.android.build.gradle.internal.aapt.AaptGeneration) DocumentException(org.dom4j.DocumentException) GradleException(org.gradle.api.GradleException) AndroidBuilder(com.android.builder.core.AndroidBuilder) AtlasBuilder(com.android.builder.core.AtlasBuilder) Aapt(com.android.builder.internal.aapt.Aapt) File(java.io.File) AaptPackageConfig(com.android.builder.internal.aapt.AaptPackageConfig) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)

Example 97 with DocumentException

use of org.dom4j.DocumentException in project atlas by alibaba.

the class ManifestFileUtils method getApplicationId.

/**
 * Get the packageId for the manifest file
 *
 * @param manifestFile
 * @return
 */
public static String getApplicationId(File manifestFile) {
    SAXReader reader = new SAXReader();
    if (manifestFile.exists()) {
        // Read the XML file
        Document document = null;
        try {
            document = reader.read(manifestFile);
            // Get the root node
            Element root = document.getRootElement();
            String packageName = root.attributeValue("package");
            return packageName;
        } catch (DocumentException e) {
            e.printStackTrace();
        }
    }
    return null;
}
Also used : SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) DocumentException(org.dom4j.DocumentException) Document(org.dom4j.Document)

Example 98 with DocumentException

use of org.dom4j.DocumentException in project atlas by alibaba.

the class PostProcessManifestAction method execute.

@Override
public void execute(Task task) {
    AtlasExtension atlasExtension = appVariantContext.getAtlasExtension();
    File bundleBaseLineInfo = appVariantContext.getBundleBaseInfoFile();
    VariantScope variantScope = appVariantContext.getScope();
    GradleVariantConfiguration config = variantScope.getVariantConfiguration();
    AtlasDependencyTree dependencyTree = AtlasBuildContext.androidDependencyTrees.get(config.getFullName());
    File androidManifest = null;
    File file = variantScope.getInstantRunManifestOutputDirectory();
    if (null != file && file.exists() && variantScope.getInstantRunBuildContext().isInInstantRunMode()) {
        androidManifest = FileUtils.join(baseVariantOutputData.getProcessManifest().getInstantRunManifestOutputDirectory(), baseVariantOutputData.getDirName(), SdkConstants.ANDROID_MANIFEST_XML);
    } else {
        androidManifest = FileUtils.join(baseVariantOutputData.getProcessManifest().getManifestOutputDirectory(), baseVariantOutputData.getDirName(), SdkConstants.ANDROID_MANIFEST_XML);
    }
    try {
        Result result = ManifestFileUtils.postProcessManifests(androidManifest, getLibManifestMap(), getLibManifestDepenendyMap(), bundleBaseLineInfo, atlasExtension.manifestOptions, isMultiDexEnabled(), variantScope.getInstantRunBuildContext().isInInstantRunMode(), appVariantContext.getBuildType().isDebuggable(), atlasExtension.getTBuildConfig().getOutOfApkBundles(), atlasExtension.getTBuildConfig().getInsideOfApkBundles(), atlasExtension.getTBuildConfig().isPushInstall());
        File proxySrcDir = appVariantContext.getAtlasProxySourceDir();
        if (AtlasProxy.genProxyJavaSource(proxySrcDir, result)) {
        // appVariantContext.getVariantData().javacTask.source(proxySrcDir);
        }
        ManifestHelper.checkManifest(appVariantContext, androidManifest, dependencyTree, atlasExtension);
    } catch (DocumentException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
// ManifestFileUtils.postProcessManifests(
// instantRunAndroidManifest,
// getLibManifestMap(),
// getLibManifestDepenendyMap(),
// bundleBaseLineInfo,
// atlasExtension.manifestOptions,
// isMultiDexEnabled(),
// true,
// appVariantContext.getBuildType().isDebuggable(),
// atlasExtension.getTBuildConfig()
// .getOutOfApkBundles(),atlasExtension.getTBuildConfig().getInsideOfApkBundles(),atlasExtension.getTBuildConfig().isPushInstall());
// }
// manifest list check
// TODO??
// AtlasBuildContext.androidBuilderMap.get(appVariantContext.getProject()).generateKeepList(
// baseVariantOutputData.manifestProcessorTask.getManifestOutputFile(),
// appVariantContext.getScope()
// .getManifestKeepListProguardFile());
}
Also used : AtlasExtension(com.taobao.android.builder.extension.AtlasExtension) VariantScope(com.android.build.gradle.internal.scope.VariantScope) DocumentException(org.dom4j.DocumentException) GradleVariantConfiguration(com.android.build.gradle.internal.core.GradleVariantConfiguration) IOException(java.io.IOException) File(java.io.File) AtlasDependencyTree(com.taobao.android.builder.dependency.AtlasDependencyTree) Result(com.taobao.android.builder.tools.manifest.Result)

Example 99 with DocumentException

use of org.dom4j.DocumentException in project zm-mailbox by Zimbra.

the class LocalConfigUpgrade method main.

public static void main(String[] args) throws ServiceException {
    CliUtil.toolSetup();
    CommandLine cl = null;
    try {
        CommandLineParser parser = new GnuParser();
        Options options = getAllOptions();
        cl = parser.parse(options, args);
        if (cl == null)
            throw new ParseException("");
    } catch (ParseException pe) {
        usage(pe.getMessage());
    }
    if (cl.hasOption(O_HELP)) {
        usage(null);
    }
    if (!cl.hasOption(O_BUG)) {
        usage("no bug specified");
    }
    if (!cl.hasOption(O_TAG)) {
        usage("no backup suffix tag specified");
    }
    LocalConfig lc = null;
    try {
        lc = new LocalConfig(cl.getOptionValue("c"));
        lc.backup(cl.getOptionValue("t"));
    } catch (DocumentException de) {
        ZimbraLog.misc.error("failed reading config file", de);
        System.exit(1);
    } catch (ConfigException ce) {
        ZimbraLog.misc.error("failed reading config file", ce);
        System.exit(2);
    } catch (IOException ioe) {
        ZimbraLog.misc.error("failed to backup config file", ioe);
        System.exit(3);
    }
    String[] bugs = cl.getOptionValues(O_BUG);
    for (String bug : bugs) {
        if (!sUpgrades.containsKey(bug)) {
            ZimbraLog.misc.warn("local config upgrade can't handle bug " + bug);
            continue;
        }
        LocalConfigUpgrade lcu = sUpgrades.get(bug);
        System.out.println("== Running local config upgrade for bug " + lcu.mBug + " (" + lcu.mShortName + ")");
        try {
            lcu.upgrade(lc);
            System.out.println("== Done local config upgrade for bug " + lcu.mBug + " (" + lcu.mShortName + ")");
        } catch (ConfigException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    try {
        lc.save();
    } catch (IOException ioe) {
        ZimbraLog.misc.error("failed writing config file", ioe);
        System.exit(1);
    } catch (ConfigException ce) {
        ZimbraLog.misc.error("failed writing config file", ce);
        System.exit(1);
    }
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) DocumentException(org.dom4j.DocumentException) GnuParser(org.apache.commons.cli.GnuParser) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) IOException(java.io.IOException)

Example 100 with DocumentException

use of org.dom4j.DocumentException in project zm-mailbox by Zimbra.

the class CrossServerNotification method getHandler.

@Override
public MessageHandler getHandler() {
    return new MessageHandler() {

        @Override
        public void handle(Message m, String clientId) {
            if (!(m instanceof CrossServerNotification)) {
                return;
            }
            CrossServerNotification message = (CrossServerNotification) m;
            Collection<Session> sessions = SessionCache.getSoapSessions(m.getRecipientAccountId());
            if (sessions == null) {
                log.warn("no active sessions for account %s", m.getRecipientAccountId());
                return;
            }
            RemoteNotifications soapNtfn = null, jsonNtfn = null;
            try {
                org.dom4j.Document dom = org.dom4j.DocumentHelper.parseText(message.getPayload());
                soapNtfn = new RemoteNotifications(Element.convertDOM(dom.getRootElement(), XMLElement.mFactory));
                jsonNtfn = new RemoteNotifications(Element.convertDOM(dom.getRootElement(), JSONElement.mFactory));
            } catch (DocumentException e) {
                log.warn("cannot parse notification from %s", clientId, e);
                return;
            }
            for (Session session : sessions) {
                log.debug("notifying session %s", session.toString());
                SoapSession ss = (SoapSession) session;
                SoapProtocol responseProtocol = ss.getResponseProtocol();
                if (responseProtocol == SoapProtocol.Soap11 || responseProtocol == SoapProtocol.Soap12) {
                    ss.addRemoteNotifications(soapNtfn);
                } else if (responseProtocol == SoapProtocol.SoapJS) {
                    ss.addRemoteNotifications(jsonNtfn);
                }
                ss.forcePush();
            }
        }
    };
}
Also used : SoapSession(com.zimbra.cs.session.SoapSession) RemoteNotifications(com.zimbra.cs.session.SoapSession.RemoteNotifications) DocumentException(org.dom4j.DocumentException) SoapProtocol(com.zimbra.common.soap.SoapProtocol) SoapSession(com.zimbra.cs.session.SoapSession) Session(com.zimbra.cs.session.Session)

Aggregations

DocumentException (org.dom4j.DocumentException)123 Document (org.dom4j.Document)80 SAXReader (org.dom4j.io.SAXReader)73 Element (org.dom4j.Element)51 IOException (java.io.IOException)45 File (java.io.File)27 InputStream (java.io.InputStream)21 StringReader (java.io.StringReader)15 InputStreamReader (java.io.InputStreamReader)11 ArrayList (java.util.ArrayList)10 XMLWriter (org.dom4j.io.XMLWriter)9 InputSource (org.xml.sax.InputSource)9 FileInputStream (java.io.FileInputStream)7 URL (java.net.URL)7 List (java.util.List)7 Node (org.dom4j.Node)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)6 FileNotFoundException (java.io.FileNotFoundException)5 Reader (java.io.Reader)5