Search in sources :

Example 91 with NonNull

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

the class AtlasDependencyGraph method findLocalJarsAsFiles.

@NonNull
private static List<File> findLocalJarsAsFiles(@NonNull File folder) {
    File localJarRoot = FileUtils.join(folder, FD_JARS, FD_AAR_LIBS);
    if (!localJarRoot.isDirectory()) {
        return ImmutableList.of();
    }
    File[] jarFiles = localJarRoot.listFiles((dir, name) -> name.endsWith(DOT_JAR));
    if (jarFiles != null && jarFiles.length > 0) {
        return ImmutableList.copyOf(jarFiles);
    }
    return ImmutableList.of();
}
Also used : File(java.io.File) NonNull(com.android.annotations.NonNull)

Example 92 with NonNull

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

the class AtlasDependencyGraph method computeMavenCoordinates.

@NonNull
private static MavenCoordinates computeMavenCoordinates(@NonNull ResolvedArtifactResult artifact) {
    // instance should be a hashable.
    AtlasDependencyGraph.HashableResolvedArtifactResult hashableResult = (AtlasDependencyGraph.HashableResolvedArtifactResult) artifact;
    ComponentIdentifier id = artifact.getId().getComponentIdentifier();
    final File artifactFile = artifact.getFile();
    final String fileName = artifactFile.getName();
    String extension = hashableResult.getDependencyType().getExtension();
    if (id instanceof ModuleComponentIdentifier) {
        ModuleComponentIdentifier moduleComponentId = (ModuleComponentIdentifier) id;
        final String module = moduleComponentId.getModule();
        final String version = moduleComponentId.getVersion();
        String classifier = null;
        if (!artifact.getFile().isDirectory()) {
            // attempts to compute classifier based on the filename.
            String pattern = "^" + module + "-" + version + "-(.+)\\." + extension + "$";
            Pattern p = Pattern.compile(pattern);
            Matcher m = p.matcher(fileName);
            if (m.matches()) {
                classifier = m.group(1);
            }
        }
        return new MavenCoordinatesImpl(moduleComponentId.getGroup(), module, version, extension, classifier);
    } else if (id instanceof ProjectComponentIdentifier) {
        return new MavenCoordinatesImpl("artifacts", ((ProjectComponentIdentifier) id).getProjectPath(), "unspecified");
    } else if (id instanceof OpaqueComponentArtifactIdentifier) {
        // We have a file based dependency
        if (hashableResult.getDependencyType() == DependencyType.JAVA) {
            return getMavenCoordForLocalFile(artifactFile);
        } else {
            // local aar?
            assert artifactFile.isDirectory();
            return getMavenCoordForLocalFile(artifactFile);
        }
    }
    throw new RuntimeException("Don't know how to compute maven coordinate for artifact '" + artifact.getId().getDisplayName() + "' with component identifier of type '" + id.getClass() + "'.");
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) MavenCoordinatesImpl(com.android.builder.dependency.MavenCoordinatesImpl) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) OpaqueComponentArtifactIdentifier(org.gradle.internal.component.local.model.OpaqueComponentArtifactIdentifier) File(java.io.File) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) NonNull(com.android.annotations.NonNull)

Example 93 with NonNull

use of com.android.annotations.NonNull in project bazel by bazelbuild.

the class FileUtils method getDirectoryNameForJar.

/**
     * Chooses a directory name, based on a JAR file name, considering exploded-aar and classes.jar.
     */
@NonNull
public static String getDirectoryNameForJar(@NonNull File inputFile) {
    // add a hash of the original file path.
    HashFunction hashFunction = Hashing.sha1();
    HashCode hashCode = hashFunction.hashString(inputFile.getAbsolutePath(), Charsets.UTF_16LE);
    String name = Files.getNameWithoutExtension(inputFile.getName());
    if (name.equals("classes") && inputFile.getAbsolutePath().contains("exploded-aar")) {
        // This naming scheme is coming from DependencyManager#computeArtifactPath.
        File versionDir = inputFile.getParentFile().getParentFile();
        File artifactDir = versionDir.getParentFile();
        File groupDir = artifactDir.getParentFile();
        name = Joiner.on('-').join(groupDir.getName(), artifactDir.getName(), versionDir.getName());
    }
    name = name + "_" + hashCode.toString();
    return name;
}
Also used : HashCode(com.google.common.hash.HashCode) HashFunction(com.google.common.hash.HashFunction) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) NonNull(com.android.annotations.NonNull)

Example 94 with NonNull

use of com.android.annotations.NonNull in project buck by facebook.

the class XmlPrettyPrinter method prettyPrint.

/**
     * Pretty-prints the given XML document, which must be well-formed. If it is not,
     * the original unformatted XML document is returned
     *
     * @param xml the XML content to format
     * @param prefs the preferences to format with
     * @param style the style to format with
     * @param lineSeparator the line separator to use, such as "\n" (can be null, in which
     *     case the system default is looked up via the line.separator property)
     * @return the formatted document (or if a parsing error occurred, returns the
     *     unformatted document)
     */
@NonNull
public static String prettyPrint(@NonNull String xml, @NonNull XmlFormatPreferences prefs, @NonNull XmlFormatStyle style, @Nullable String lineSeparator) {
    Document document = XmlUtils.parseDocumentSilently(xml, true);
    if (document != null) {
        XmlPrettyPrinter printer = new XmlPrettyPrinter(prefs, style, lineSeparator);
        printer.setEndWithNewline(xml.endsWith(printer.getLineSeparator()));
        StringBuilder sb = new StringBuilder(3 * xml.length() / 2);
        printer.prettyPrint(-1, document, null, null, sb, false);
        return sb.toString();
    } else {
        // Parser error: just return the unformatted content
        return xml;
    }
}
Also used : Document(org.w3c.dom.Document) NonNull(com.android.annotations.NonNull)

Example 95 with NonNull

use of com.android.annotations.NonNull in project buck by facebook.

the class ManifestMerger2 method load.

/**
     * Load an xml file and perform placeholder substitution
     * @param manifestInfo the android manifest information like if it is a library, an
     *                     overlay or a main manifest file.
     * @param selectors all the libraries selectors
     * @param mergingReportBuilder the merging report to store events and errors.
     * @return a loaded manifest info.
     * @throws MergeFailureException
     */
@NonNull
private LoadedManifestInfo load(@NonNull ManifestInfo manifestInfo, @NonNull KeyResolver<String> selectors, @NonNull MergingReport.Builder mergingReportBuilder) throws MergeFailureException {
    File xmlFile = manifestInfo.mLocation;
    XmlDocument xmlDocument;
    try {
        InputStream inputStream = mFileStreamProvider.getInputStream(xmlFile);
        xmlDocument = XmlLoader.load(selectors, mSystemPropertyResolver, manifestInfo.mName, xmlFile, inputStream, manifestInfo.getType(), manifestInfo.getMainManifestPackageName());
    } catch (Exception e) {
        throw new MergeFailureException(e);
    }
    String originalPackageName = xmlDocument.getPackageName();
    MergingReport.Builder builder = manifestInfo.getType() == XmlDocument.Type.MAIN ? mergingReportBuilder : new MergingReport.Builder(mergingReportBuilder.getLogger());
    builder.getActionRecorder().recordDefaultNodeAction(xmlDocument.getRootNode());
    // perform place holder substitution, this is necessary to do so early in case placeholders
    // are used in key attributes.
    performPlaceHolderSubstitution(manifestInfo, xmlDocument, builder);
    return new LoadedManifestInfo(manifestInfo, Optional.fromNullable(originalPackageName), xmlDocument);
}
Also used : BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) NonNull(com.android.annotations.NonNull)

Aggregations

NonNull (com.android.annotations.NonNull)131 File (java.io.File)38 IOException (java.io.IOException)15 TextRange (com.intellij.openapi.util.TextRange)13 ArrayList (java.util.ArrayList)11 Path (java.nio.file.Path)9 Nullable (com.android.annotations.Nullable)8 ImmutableList (com.google.common.collect.ImmutableList)8 SdkConstants (com.android.SdkConstants)5 DefaultPosition (com.android.tools.klint.detector.api.DefaultPosition)5 Position (com.android.tools.klint.detector.api.Position)5 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 ArchiveNode (io.github.lizhangqu.intellij.android.bundle.analyzer.ArchiveNode)4 StringReader (java.io.StringReader)4 HashMap (java.util.HashMap)4