Search in sources :

Example 1 with NonNull

use of com.android.annotations.NonNull in project atlas by alibaba.

the class TDependencyManager method gatherDependencies.

@NonNull
private DependencyContainer gatherDependencies(@NonNull Configuration configuration, @NonNull final VariantDependencies variantDeps, @NonNull Multimap<AndroidLibrary, Configuration> reverseLibMap, @NonNull Set<String> currentUnresolvedDependencies, @Nullable String testedProjectPath, @NonNull Set<String> artifactSet, @NonNull ScopeType scopeType) {
    // collect the artifacts first.
    Map<ModuleVersionIdentifier, List<ResolvedArtifact>> artifacts = Maps.newHashMap();
    configuration = collectArtifacts(configuration, artifacts);
    // keep a map of modules already processed so that we don't go through sections of the
    // graph that have been seen elsewhere.
    Map<ModuleVersionIdentifier, List<LibraryDependency>> foundLibraries = Maps.newHashMap();
    Map<ModuleVersionIdentifier, List<JarDependency>> foundJars = Maps.newHashMap();
    // get the graph for the Android and Jar dependencies. This does not include
    // local jars.
    List<LibraryDependency> libraryDependencies = Lists.newArrayList();
    List<JarDependency> jarDependencies = Lists.newArrayList();
    Set<? extends DependencyResult> dependencyResultSet = configuration.getIncoming().getResolutionResult().getRoot().getDependencies();
    for (DependencyResult dependencyResult : dependencyResultSet) {
        if (dependencyResult instanceof ResolvedDependencyResult) {
            addDependency(((ResolvedDependencyResult) dependencyResult).getSelected(), variantDeps, configuration, libraryDependencies, jarDependencies, foundLibraries, foundJars, artifacts, reverseLibMap, currentUnresolvedDependencies, testedProjectPath, Collections.emptyList(), artifactSet, scopeType, false, /*forceProvided*/
            0);
        } else if (dependencyResult instanceof UnresolvedDependencyResult) {
            ComponentSelector attempted = ((UnresolvedDependencyResult) dependencyResult).getAttempted();
            if (attempted != null) {
                currentUnresolvedDependencies.add(attempted.toString());
            }
        }
    }
    // also need to process local jar files, as they are not processed by the
    // resolvedConfiguration result. This only includes the local jar files for this project.
    List<JarDependency> localJars = Lists.newArrayList();
    for (Dependency dependency : configuration.getAllDependencies()) {
        if (dependency instanceof SelfResolvingDependency && !(dependency instanceof ProjectDependency)) {
            Set<File> files = ((SelfResolvingDependency) dependency).resolve();
            for (File localJarFile : files) {
                if (DEBUG_DEPENDENCY) {
                    System.out.println("LOCAL " + configuration.getName() + ": " + localJarFile.getName());
                }
                // only accept local jar, no other types.
                if (!localJarFile.getName().toLowerCase(Locale.getDefault()).endsWith(DOT_JAR)) {
                    variantDeps.getChecker().handleIssue(localJarFile.getAbsolutePath(), SyncIssue.TYPE_NON_JAR_LOCAL_DEP, SyncIssue.SEVERITY_ERROR, String.format("Project %s: Only Jar-type local dependencies are supported. Cannot handle: %s", project.getName(), localJarFile.getAbsolutePath()));
                } else {
                    JarDependency localJar;
                    switch(scopeType) {
                        case PACKAGE:
                            localJar = new JarDependency(localJarFile);
                            artifactSet.add(computeVersionLessCoordinateKey(localJar.getResolvedCoordinates()));
                            break;
                        case COMPILE:
                            MavenCoordinates coord = JarDependency.getCoordForLocalJar(localJarFile);
                            boolean provided = !artifactSet.contains(computeVersionLessCoordinateKey(coord));
                            localJar = new JarDependency(localJarFile, ImmutableList.of(), coord, null, provided);
                            break;
                        case COMPILE_ONLY:
                            // if we only have the compile scope, ignore computation of the
                            // provided bits.
                            localJar = new JarDependency(localJarFile);
                            break;
                        default:
                            throw new RuntimeException("unsupported ProvidedComputationAction");
                    }
                    localJars.add(localJar);
                }
            }
        }
    }
    return new DependencyContainerImpl(libraryDependencies, jarDependencies, localJars);
}
Also used : UnresolvedDependencyResult(org.gradle.api.artifacts.result.UnresolvedDependencyResult) JarDependency(com.android.builder.dependency.JarDependency) SelfResolvingDependency(org.gradle.api.artifacts.SelfResolvingDependency) ComponentSelector(org.gradle.api.artifacts.component.ComponentSelector) DependencyResult(org.gradle.api.artifacts.result.DependencyResult) UnresolvedDependencyResult(org.gradle.api.artifacts.result.UnresolvedDependencyResult) ResolvedDependencyResult(org.gradle.api.artifacts.result.ResolvedDependencyResult) DependencyContainerImpl(com.android.builder.dependency.DependencyContainerImpl) LibraryDependency(com.android.builder.dependency.LibraryDependency) UnresolvedDependency(org.gradle.api.artifacts.UnresolvedDependency) SelfResolvingDependency(org.gradle.api.artifacts.SelfResolvingDependency) ProjectDependency(org.gradle.api.artifacts.ProjectDependency) JarDependency(com.android.builder.dependency.JarDependency) Dependency(org.gradle.api.artifacts.Dependency) ProjectDependency(org.gradle.api.artifacts.ProjectDependency) ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) MavenCoordinates(com.android.builder.model.MavenCoordinates) LibraryDependency(com.android.builder.dependency.LibraryDependency) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) ResolvedDependencyResult(org.gradle.api.artifacts.result.ResolvedDependencyResult) File(java.io.File) NonNull(com.android.annotations.NonNull)

Example 2 with NonNull

use of com.android.annotations.NonNull in project atlas by alibaba.

the class ProcessAwoAndroidResources method doFullTaskAction.

@Override
protected void doFullTaskAction() throws IOException {
    // we have to clean the source folder output in case the package name changed.
    File srcOut = getSourceOutputDir();
    if (srcOut != null) {
        // FileUtils.emptyFolder(srcOut);
        srcOut.delete();
        srcOut.mkdirs();
    }
    @Nullable File resOutBaseNameFile = getPackageOutputFile();
    // If are in instant run mode and we have an instant run enabled manifest
    File instantRunManifest = getInstantRunManifestFile();
    File manifestFileToPackage = instantRunBuildContext.isInInstantRunMode() && instantRunManifest != null && instantRunManifest.exists() ? instantRunManifest : getManifestFile();
    // 增加awb模块编译所需要的额外参数
    addAaptOptions();
    AaptPackageProcessBuilder aaptPackageCommandBuilder = new AaptPackageProcessBuilder(manifestFileToPackage, getAaptOptions()).setAssetsFolder(getAssetsDir()).setResFolder(getResDir()).setLibraries(getLibraries()).setPackageForR(getPackageForR()).setSourceOutputDir(absolutePath(srcOut)).setSymbolOutputDir(absolutePath(getTextSymbolOutputDir())).setResPackageOutput(absolutePath(resOutBaseNameFile)).setProguardOutput(absolutePath(getProguardOutputFile())).setType(getType()).setDebuggable(getDebuggable()).setPseudoLocalesEnabled(getPseudoLocalesEnabled()).setResourceConfigs(getResourceConfigs()).setSplits(getSplits()).setPreferredDensity(getPreferredDensity());
    @NonNull AtlasBuilder builder = (AtlasBuilder) getBuilder();
    // MergingLog mergingLog = new MergingLog(getMergeBlameLogFolder());
    //
    // ProcessOutputHandler processOutputHandler = new ParsingProcessOutputHandler(
    // new ToolOutputParser(new AaptOutputParser(), getILogger()),
    // builder.getErrorReporter());
    ProcessOutputHandler processOutputHandler = new LoggedProcessOutputHandler(getILogger());
    try {
        builder.processAwbResources(aaptPackageCommandBuilder, getEnforceUniquePackageName(), processOutputHandler, getMainSymbolFile());
        if (resOutBaseNameFile != null) {
            if (instantRunBuildContext.isInInstantRunMode()) {
                instantRunBuildContext.addChangedFile(InstantRunBuildContext.FileType.RESOURCES, resOutBaseNameFile);
                // get the new manifest file CRC
                JarFile jarFile = new JarFile(resOutBaseNameFile);
                String currentIterationCRC = null;
                try {
                    ZipEntry entry = jarFile.getEntry(SdkConstants.ANDROID_MANIFEST_XML);
                    if (entry != null) {
                        currentIterationCRC = String.valueOf(entry.getCrc());
                    }
                } finally {
                    jarFile.close();
                }
                // check the manifest file binary format.
                File crcFile = new File(instantRunSupportDir, "manifest.crc");
                if (crcFile.exists() && currentIterationCRC != null) {
                    // compare its content with the new binary file crc.
                    String previousIterationCRC = Files.readFirstLine(crcFile, Charsets.UTF_8);
                    if (!currentIterationCRC.equals(previousIterationCRC)) {
                        instantRunBuildContext.close();
                        instantRunBuildContext.setVerifierResult(InstantRunVerifierStatus.BINARY_MANIFEST_FILE_CHANGE);
                    }
                }
                // write the new manifest file CRC.
                Files.createParentDirs(crcFile);
                Files.write(currentIterationCRC, crcFile, Charsets.UTF_8);
            }
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    } catch (ProcessException e) {
        throw new RuntimeException(e);
    }
}
Also used : LoggedProcessOutputHandler(com.android.ide.common.process.LoggedProcessOutputHandler) ProcessOutputHandler(com.android.ide.common.process.ProcessOutputHandler) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) ProcessException(com.android.ide.common.process.ProcessException) AaptPackageProcessBuilder(com.android.builder.core.AaptPackageProcessBuilder) NonNull(com.android.annotations.NonNull) AtlasBuilder(com.android.builder.core.AtlasBuilder) LoggedProcessOutputHandler(com.android.ide.common.process.LoggedProcessOutputHandler) JarFile(java.util.jar.JarFile) OutputFile(org.gradle.api.tasks.OutputFile) File(java.io.File) InputFile(org.gradle.api.tasks.InputFile) Nullable(com.android.annotations.Nullable)

Example 3 with NonNull

use of com.android.annotations.NonNull in project kotlin by JetBrains.

the class ClassContext method getLocation.

/**
     * Returns a location for the given {@link AbstractInsnNode}.
     *
     * @param instruction the instruction to look up the location for
     * @return a location pointing to the instruction, or as close to it
     *         as possible
     */
@NonNull
public Location getLocation(@NonNull AbstractInsnNode instruction) {
    SearchHints hints = SearchHints.create(FORWARD).matchJavaSymbol();
    String pattern = null;
    if (instruction instanceof MethodInsnNode) {
        MethodInsnNode call = (MethodInsnNode) instruction;
        if (call.name.equals(CONSTRUCTOR_NAME)) {
            pattern = call.owner;
            hints = hints.matchConstructor();
        } else {
            pattern = call.name;
        }
        int index = pattern.lastIndexOf('$');
        if (index != -1) {
            pattern = pattern.substring(index + 1);
        }
        index = pattern.lastIndexOf('/');
        if (index != -1) {
            pattern = pattern.substring(index + 1);
        }
    }
    int line = findLineNumber(instruction);
    return getLocationForLine(line, pattern, null, hints);
}
Also used : MethodInsnNode(org.jetbrains.org.objectweb.asm.tree.MethodInsnNode) SearchHints(com.android.tools.klint.detector.api.Location.SearchHints) NonNull(com.android.annotations.NonNull)

Example 4 with NonNull

use of com.android.annotations.NonNull in project kotlin by JetBrains.

the class JavaContext method getUastLocation.

@NonNull
public Location getUastLocation(@Nullable UElement node) {
    if (node == null) {
        return Location.NONE;
    }
    if (node instanceof UElementWithLocation) {
        UFile file = UastUtils.getContainingFile(node);
        if (file == null) {
            return Location.NONE;
        }
        File ioFile = UastUtils.getIoFile(file);
        if (ioFile == null) {
            return Location.NONE;
        }
        UElementWithLocation segment = (UElementWithLocation) node;
        return Location.create(ioFile, file.getPsi().getText(), segment.getStartOffset(), segment.getEndOffset());
    } else {
        PsiElement psiElement = node.getPsi();
        if (psiElement != null) {
            TextRange range = psiElement.getTextRange();
            UFile containingFile = getUFile();
            if (containingFile == null) {
                return Location.NONE;
            }
            File file = this.file;
            if (!containingFile.equals(getUFile())) {
                // Reporting an error in a different file.
                if (getDriver().getScope().size() == 1) {
                    // Don't bother with this error if it's in a different file during single-file analysis
                    return Location.NONE;
                }
                VirtualFile virtualFile = containingFile.getPsi().getVirtualFile();
                if (virtualFile == null) {
                    return Location.NONE;
                }
                file = VfsUtilCore.virtualToIoFile(virtualFile);
            }
            return Location.create(file, getContents(), range.getStartOffset(), range.getEndOffset());
        }
    }
    return Location.NONE;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) UElementWithLocation(org.jetbrains.uast.psi.UElementWithLocation) TextRange(com.intellij.openapi.util.TextRange) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) NonNull(com.android.annotations.NonNull)

Example 5 with NonNull

use of com.android.annotations.NonNull in project kotlin by JetBrains.

the class LintClient method getTargets.

/**
     * Returns all the {@link IAndroidTarget} versions installed in the user's SDK install
     * area.
     *
     * @return all the installed targets
     */
@NonNull
public IAndroidTarget[] getTargets() {
    if (mTargets == null) {
        AndroidSdkHandler sdkHandler = getSdk();
        if (sdkHandler != null) {
            ProgressIndicator logger = getRepositoryLogger();
            Collection<IAndroidTarget> targets = sdkHandler.getAndroidTargetManager(logger).getTargets(logger);
            mTargets = targets.toArray(new IAndroidTarget[targets.size()]);
        } else {
            mTargets = new IAndroidTarget[0];
        }
    }
    return mTargets;
}
Also used : ProgressIndicator(com.android.repository.api.ProgressIndicator) AndroidSdkHandler(com.android.sdklib.repositoryv2.AndroidSdkHandler) IAndroidTarget(com.android.sdklib.IAndroidTarget) NonNull(com.android.annotations.NonNull)

Aggregations

NonNull (com.android.annotations.NonNull)113 File (java.io.File)38 TextRange (com.intellij.openapi.util.TextRange)13 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)11 ImmutableList (com.google.common.collect.ImmutableList)8 Nullable (com.android.annotations.Nullable)7 DefaultPosition (com.android.tools.klint.detector.api.DefaultPosition)5 Position (com.android.tools.klint.detector.api.Position)5 Matcher (java.util.regex.Matcher)5 Pattern (java.util.regex.Pattern)5 SdkConstants (com.android.SdkConstants)4 OutputFile (com.android.build.OutputFile)4 Issue (com.android.tools.klint.detector.api.Issue)4 Position (com.android.tools.lint.detector.api.Position)4 FileUtils (com.android.utils.FileUtils)4 Splitter (com.google.common.base.Splitter)4 Module (com.intellij.openapi.module.Module)4 StringReader (java.io.StringReader)4 Node (org.w3c.dom.Node)4