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();
}
}
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;
}
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());
}
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);
}
}
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();
}
}
};
}
Aggregations