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();
}
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() + "'.");
}
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;
}
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;
}
}
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);
}
Aggregations