use of com.android.builder.model.MavenCoordinates in project atlas by alibaba.
the class FileNameUtils method getMavenCoordinate.
private static MavenCoordinates getMavenCoordinate(String path) {
File file = new File(path);
File parentDir = file.getParentFile();
// Look for level 3
for (int i = 0; i < 3; i++) {
MavenCoordinates mavenCoordinates = AtlasBuildContext.dependencyTraceMap.get(parentDir.getAbsolutePath());
if (null != mavenCoordinates) {
return mavenCoordinates;
}
parentDir = parentDir.getParentFile();
}
return null;
}
use of com.android.builder.model.MavenCoordinates in project atlas by alibaba.
the class GenerateAtlasSourceTask method generate.
@TaskAction
void generate() {
InjectParam injectParam = getInput();
boolean supportRemoteComponent = true;
if (AtlasBuildContext.androidDependencyTrees.get(getVariantName()) != null) {
List<AndroidLibrary> libraries = AtlasBuildContext.androidDependencyTrees.get(getVariantName()).getMainBundle().getAndroidLibraries();
if (libraries.size() > 0) {
for (AndroidLibrary library : libraries) {
MavenCoordinates coordinates = library.getResolvedCoordinates();
if (coordinates.getArtifactId().equals("atlas_core") && coordinates.getGroupId().equals("com.taobao.android")) {
if (coordinates.getVersion().compareTo("5.0.8") < 0) {
supportRemoteComponent = false;
}
}
}
}
}
List<BasicBundleInfo> info = JSON.parseArray(injectParam.bundleInfo, BasicBundleInfo.class);
File outputSourceGeneratorFile = new File(outputDir, "android/taobao/atlas/framework/AtlasBundleInfoGenerator.java");
StringBuffer infoGeneratorSourceStr = new BundleInfoSourceCreator().createBundleInfoSourceStr(info, supportRemoteComponent);
outputSourceGeneratorFile.getParentFile().mkdirs();
try {
FileUtils.writeStringToFile(outputSourceGeneratorFile, infoGeneratorSourceStr.toString());
} catch (IOException e) {
throw new GradleException(e.getMessage(), e);
}
File outputPropertiesFile = new File(outputDir, "android/taobao/atlas/framework/FrameworkProperties.java");
List<String> lines = new ArrayList<>();
outputPropertiesFile.getParentFile().mkdirs();
lines.add("package android.taobao.atlas.framework;");
lines.add("public class FrameworkProperties {");
lines.add("private String version = \"" + injectParam.version + "\";");
lines.add("public String getVersion() {return version;}");
String escapeExprBundleInfo = escapeExprSpecialWord(injectParam.bundleInfo);
if (injectParam.bundleInfo.length() < 65535) {
lines.add("public static String bundleInfo = \"" + escapeExprBundleInfo + "\";");
lines.add("public static final boolean compressInfo = false;");
} else {
String compressBundleInfo = compressBundleInfo(injectParam.bundleInfo);
lines.add("public static String bundleInfo = \"" + compressBundleInfo + "\";");
lines.add("public static final boolean compressInfo = true;");
}
// lines.add("public static String bunleInfo = \"\";");
if (StringUtils.isNotEmpty(injectParam.autoStartBundles)) {
lines.add("public static String autoStartBundles = \"" + injectParam.autoStartBundles + "\";");
}
if (StringUtils.isNotEmpty(injectParam.blackDialogActivity)) {
lines.add("public static String blackDialogActivity = \"" + injectParam.blackDialogActivity + "\";");
}
lines.add("public static String autoStart = \"" + injectParam.autoStart + "\";");
if (StringUtils.isNotEmpty(injectParam.preLaunch)) {
lines.add("public static String preLaunch = \"" + injectParam.preLaunch + "\";");
}
if (StringUtils.isNotEmpty(injectParam.group)) {
lines.add("public static String group = \"" + injectParam.group + "\";");
}
lines.add("public static String outApp = \"" + injectParam.outApp + "\";");
lines.add("}");
try {
FileUtils.writeLines(outputPropertiesFile, lines);
Map output = new HashMap();
output.put("bundleInfo", JSON.parseArray(injectParam.bundleInfo));
output.put("autoStartBundles", injectParam.autoStartBundles);
output.put("preLaunch", injectParam.preLaunch);
output.put("group", injectParam.group);
output.put("outApp", injectParam.outApp);
output.put("unit_tag", injectParam.unit_tag);
output.put("autoStart", injectParam.autoStart);
output.put("blackDialogActivity", injectParam.blackDialogActivity);
FileUtils.write(new File(appVariantContext.getProject().getBuildDir(), "outputs/atlasFrameworkProperties.json"), JSON.toJSONString(output, true));
} catch (Exception e) {
throw new GradleException(e.getMessage(), e);
}
}
use of com.android.builder.model.MavenCoordinates in project atlas by alibaba.
the class AwbGenerator method createAwbBundle.
public AwbBundle createAwbBundle(LibVariantContext libVariantContext) throws IOException {
String variantName = libVariantContext.getVariantName();
AtlasDependencyTree libDependencyTree = AtlasBuildContext.libDependencyTrees.get(variantName);
// TODO 2.3
if (null == libDependencyTree) {
libDependencyTree = new AtlasDepTreeParser(libVariantContext.getProject(), new ExtraModelInfo(new ProjectOptions(libVariantContext.getProject()), null), new HashSet<>()).parseDependencyTree(libVariantContext.getVariantDependency());
AtlasBuildContext.libDependencyTrees.put(variantName, libDependencyTree);
}
Project project = libVariantContext.getProject();
String groupName = (String) project.getGroup();
String name = "";
String version = (String) project.getVersion();
if (project.hasProperty("archivesBaseName")) {
name = (String) project.getProperties().get("archivesBaseName");
} else {
name = project.getName();
}
File explodedDir = project.file(project.getBuildDir().getAbsolutePath() + "/" + FD_INTERMEDIATES + "/exploded-awb/" + computeArtifactPath(groupName, name, version));
FileUtils.deleteDirectory(explodedDir);
MavenCoordinates mavenCoordinates = new MavenCoordinatesImpl(groupName, name, version, "awb", "");
ResolvedDependencyInfo resolvedDependencyInfo = new ResolvedDependencyInfo(groupName, name, version, "awb");
resolvedDependencyInfo.setVariantName(libVariantContext.getVariantName());
AwbBundle awbBundle = new AwbBundle(resolvedDependencyInfo, DependencyConvertUtils.toAndroidLibrary(mavenCoordinates, libVariantContext.getBundleTask().getArchivePath(), explodedDir));
awbBundle.getSoLibraries().addAll(libDependencyTree.getMainBundle().getSoLibraries());
awbBundle.getAndroidLibraries().addAll(libDependencyTree.getMainBundle().getAndroidLibraries());
awbBundle.getJavaLibraries().addAll(libDependencyTree.getMainBundle().getJavaLibraries());
return awbBundle;
}
use of com.android.builder.model.MavenCoordinates in project android by JetBrains.
the class ManifestPanel method describePosition.
private void describePosition(@NotNull HtmlBuilder sb, @NotNull AndroidFacet facet, @NotNull SourceFilePosition sourceFilePosition) {
SourceFile sourceFile = sourceFilePosition.getFile();
SourcePosition sourcePosition = sourceFilePosition.getPosition();
File file = sourceFile.getSourceFile();
if (file == GRADLE_MODEL_MARKER_FILE) {
VirtualFile gradleBuildFile = GradleUtil.getGradleBuildFile(facet.getModule());
if (gradleBuildFile != null) {
file = VfsUtilCore.virtualToIoFile(gradleBuildFile);
sb.addHtml("<a href=\"");
sb.add(file.toURI().toString());
sb.addHtml("\">");
sb.add(file.getName());
sb.addHtml("</a>");
sb.add(" injection");
} else {
sb.add("build.gradle injection (source location unknown)");
}
return;
}
AndroidLibrary library;
if (file != null) {
String source = null;
Module libraryModule = null;
Module[] modules = ModuleManager.getInstance(facet.getModule().getProject()).getModules();
VirtualFile vFile = LocalFileSystem.getInstance().findFileByIoFile(file);
if (vFile != null) {
Module module = ModuleUtilCore.findModuleForFile(vFile, facet.getModule().getProject());
if (module != null) {
if (modules.length >= 2) {
source = module.getName();
}
// AAR Library?
if (file.getPath().contains(EXPLODED_AAR)) {
AndroidModuleModel androidModel = AndroidModuleModel.get(module);
if (androidModel != null) {
library = GradleUtil.findLibrary(file.getParentFile(), androidModel.getSelectedVariant(), androidModel.getModelVersion());
if (library != null) {
if (library.getProject() != null) {
libraryModule = GradleUtil.findModuleByGradlePath(facet.getModule().getProject(), library.getProject());
if (libraryModule != null) {
module = libraryModule;
source = module.getName();
} else {
source = library.getProject();
source = StringUtil.trimStart(source, ":");
}
} else {
MavenCoordinates coordinates = library.getResolvedCoordinates();
source = /*coordinates.getGroupId() + ":" +*/
coordinates.getArtifactId() + ":" + coordinates.getVersion();
}
}
}
}
}
IdeaSourceProvider provider = ManifestUtils.findManifestSourceProvider(facet, vFile);
if (provider != null) /*&& !provider.equals(facet.getMainIdeaSourceProvider())*/
{
String providerName = provider.getName();
if (source == null) {
source = providerName;
} else {
// "the app main manifest" - "app" is the module name, "main" is the source provider name
source = source + " " + providerName;
}
}
}
if (source == null) {
source = file.getName();
if (!SourcePosition.UNKNOWN.equals(sourcePosition)) {
source += ":" + String.valueOf(sourcePosition);
}
}
sb.addHtml("<a href=\"");
boolean redirected = false;
if (libraryModule != null) {
AndroidFacet libraryFacet = AndroidFacet.getInstance(libraryModule);
if (libraryFacet != null) {
File manifestFile = libraryFacet.getMainSourceProvider().getManifestFile();
if (manifestFile.exists()) {
sb.add(manifestFile.toURI().toString());
redirected = true;
// Line numbers probably aren't right
sourcePosition = SourcePosition.UNKNOWN;
// TODO: Set URL which points to the element/attribute path
}
}
}
if (!redirected) {
sb.add(file.toURI().toString());
if (!SourcePosition.UNKNOWN.equals(sourcePosition)) {
sb.add(":");
sb.add(String.valueOf(sourcePosition.getStartLine()));
sb.add(":");
sb.add(String.valueOf(sourcePosition.getStartColumn()));
}
}
sb.addHtml("\">");
sb.add(source);
sb.addHtml("</a>");
sb.add(" manifest");
if (FileUtil.filesEqual(file, VfsUtilCore.virtualToIoFile(myFile))) {
sb.add(" (this file)");
}
if (!SourcePosition.UNKNOWN.equals(sourcePosition)) {
sb.add(", line ");
sb.add(Integer.toString(sourcePosition.getStartLine()));
}
}
}
use of com.android.builder.model.MavenCoordinates in project atlas by alibaba.
the class DependencyResolver method resolveDependency.
/**
* Analytical dependence
* @param parent
* @param resolvedComponentResult
* @param artifacts
* @param configDependencies
* @param indent
* @param mainBundle
*/
private void resolveDependency(ResolvedDependencyInfo parent, ResolvedComponentResult resolvedComponentResult, Map<ModuleVersionIdentifier, List<ResolvedArtifact>> artifacts, VariantDependencies configDependencies, int indent, CircleDependencyCheck circleDependencyCheck, CircleDependencyCheck.DependencyNode node, Multimap<String, ResolvedDependencyInfo> dependenciesMap, Set<String> resolvedDependencies, boolean mainBundle) {
ModuleVersionIdentifier moduleVersion = resolvedComponentResult.getModuleVersion();
// }
if (!ids.contains(moduleVersion.getGroup() + ":" + moduleVersion.getName())) {
artifacts.put(moduleVersion, Lists.newArrayList((DependencyGroup.bundleCompileId.get(moduleVersion))));
}
// now loop on all the artifact for this modules.
List<ResolvedArtifact> moduleArtifacts = artifacts.get(moduleVersion);
ComponentIdentifier id = resolvedComponentResult.getId();
String gradlePath = (id instanceof ProjectComponentIdentifier) ? ((ProjectComponentIdentifier) id).getProjectPath() : null;
// If you can find multiple dependencies at the same time, you can't judge for the time being that it's really useful
if (null != moduleArtifacts) {
for (ResolvedArtifact resolvedArtifact : moduleArtifacts) {
String key = moduleVersion.getGroup() + ":" + moduleVersion.getName();
// remove android.jar
if (key.equals("com.google.android:android")) {
continue;
}
if (mainDependencies.contains(key)) {
continue;
}
if (resolvedDependencies.contains(key)) {
continue;
}
//
resolvedDependencies.add(key);
boolean isAwbBundle = bundleProvidedMap.containsKey(key);
Set<String> providedDirectDep = bundleProvidedMap.get(key);
ResolvedDependencyInfo resolvedDependencyInfo = new ResolvedDependencyInfo(moduleVersion.getVersion(), moduleVersion.getGroup(), moduleVersion.getName(), !mainBundle ? "awb" : resolvedArtifact.getType(), resolvedArtifact.getClassifier());
resolvedDependencyInfo.setIndent(indent);
resolvedDependencyInfo.setGradlePath(gradlePath);
resolvedDependencyInfo.setResolvedArtifact(resolvedArtifact);
String path = AtlasDepHelper.computeArtifactPath(moduleVersion, resolvedArtifact);
String name = AtlasDepHelper.computeArtifactName(moduleVersion, resolvedArtifact);
MavenCoordinates mavenCoordinates = DependencyConvertUtils.convert(resolvedArtifact, !mainBundle ? DependencyConvertUtils.Type.AWB : DependencyConvertUtils.Type.AAR);
File explodedDir = DependencyLocationManager.getExploreDir(project, mavenCoordinates, resolvedArtifact.getFile(), !mainBundle ? "awb" : resolvedArtifact.getType().toLowerCase(), path);
resolvedDependencyInfo.setExplodedDir(explodedDir);
resolvedDependencyInfo.setDependencyName(name);
if (null == parent) {
parent = resolvedDependencyInfo;
} else {
resolvedDependencyInfo.setParent(parent);
parent.getChildren().add(resolvedDependencyInfo);
}
Set<DependencyResult> dependencyResults = null;
Set<? extends DependencyResult> dependencies = (Set<DependencyResult>) resolvedComponentResult.getDependencies();
if (bundleCompileMap.containsKey(resolvedDependencyInfo.getGroup() + ":" + resolvedDependencyInfo.getName())) {
dependencyResults = bundleCompileMap.get(parent.getGroup() + ":" + parent.getName());
}
Set<DependencyResult> combineDependencies = combine(dependencyResults, dependencies);
if (null != combineDependencies) {
for (DependencyResult dep : combineDependencies) {
if (dep instanceof ResolvedDependencyResult) {
ResolvedComponentResult childResolvedComponentResult = ((ResolvedDependencyResult) dep).getSelected();
if (isAwbBundle && providedDirectDep.contains(childResolvedComponentResult.getModuleVersion().getGroup() + ":" + childResolvedComponentResult.getModuleVersion().getName())) {
continue;
}
CircleDependencyCheck.DependencyNode childNode = circleDependencyCheck.addDependency(childResolvedComponentResult.getModuleVersion(), node, indent + 1);
CircleDependencyCheck.CircleResult circleResult = circleDependencyCheck.checkCircle(logger);
if (circleResult.hasCircle) {
logger.warning("[CircleDependency]" + StringUtils.join(circleResult.detail, ";"));
} else {
resolveDependency(parent, ((ResolvedDependencyResult) dep).getSelected(), artifacts, configDependencies, indent + 1, circleDependencyCheck, childNode, dependenciesMap, resolvedDependencies, true);
}
}
}
}
addDependencyInfo(resolvedDependencyInfo, null, dependenciesMap);
}
}
}
Aggregations