use of com.android.annotations.NonNull in project kotlin by JetBrains.
the class LintClient method getProject.
/**
* Returns a project for the given directory. This should return the same
* project for the same directory if called repeatedly.
*
* @param dir the directory containing the project
* @param referenceDir See {@link Project#getReferenceDir()}.
* @return a project, never null
*/
@NonNull
public Project getProject(@NonNull File dir, @NonNull File referenceDir) {
if (mDirToProject == null) {
mDirToProject = new HashMap<File, Project>();
}
File canonicalDir = dir;
try {
// Attempt to use the canonical handle for the file, in case there
// are symlinks etc present (since when handling library projects,
// we also call getCanonicalFile to compute the result of appending
// relative paths, which can then resolve symlinks and end up with
// a different prefix)
canonicalDir = dir.getCanonicalFile();
} catch (IOException ioe) {
// pass
}
Project project = mDirToProject.get(canonicalDir);
if (project != null) {
return project;
}
project = createProject(dir, referenceDir);
mDirToProject.put(canonicalDir, project);
return project;
}
use of com.android.annotations.NonNull in project kotlin by JetBrains.
the class LintClient method getClassPath.
/**
* Considers the given project as an Eclipse project and returns class path
* information for the project - the source folder(s), the output folder and
* any libraries.
* <p>
* Callers will not cache calls to this method, so if it's expensive to compute
* the classpath info, this method should perform its own caching.
*
* @param project the project to look up class path info for
* @return a class path info object, never null
*/
@NonNull
protected ClassPathInfo getClassPath(@NonNull Project project) {
ClassPathInfo info;
if (mProjectInfo == null) {
mProjectInfo = Maps.newHashMap();
info = null;
} else {
info = mProjectInfo.get(project);
}
if (info == null) {
List<File> sources = new ArrayList<File>(2);
List<File> classes = new ArrayList<File>(1);
List<File> libraries = new ArrayList<File>();
// No test folders in Eclipse:
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=224708
List<File> tests = Collections.emptyList();
File projectDir = project.getDir();
//$NON-NLS-1$
File classpathFile = new File(projectDir, ".classpath");
if (classpathFile.exists()) {
String classpathXml = readFile(classpathFile);
try {
Document document = XmlUtils.parseDocument(classpathXml, false);
//$NON-NLS-1$
NodeList tags = document.getElementsByTagName("classpathentry");
for (int i = 0, n = tags.getLength(); i < n; i++) {
Element element = (Element) tags.item(i);
//$NON-NLS-1$
String kind = element.getAttribute("kind");
List<File> addTo = null;
if (kind.equals("src")) {
//$NON-NLS-1$
addTo = sources;
} else if (kind.equals("output")) {
//$NON-NLS-1$
addTo = classes;
} else if (kind.equals("lib")) {
//$NON-NLS-1$
addTo = libraries;
}
if (addTo != null) {
//$NON-NLS-1$
String path = element.getAttribute("path");
File folder = new File(projectDir, path);
if (folder.exists()) {
addTo.add(folder);
}
}
}
} catch (Exception e) {
log(null, null);
}
}
// Add in libraries that aren't specified in the .classpath file
File libs = new File(project.getDir(), LIBS_FOLDER);
if (libs.isDirectory()) {
File[] jars = libs.listFiles();
if (jars != null) {
for (File jar : jars) {
if (endsWith(jar.getPath(), DOT_JAR) && !libraries.contains(jar)) {
libraries.add(jar);
}
}
}
}
if (classes.isEmpty()) {
File folder = new File(projectDir, CLASS_FOLDER);
if (folder.exists()) {
classes.add(folder);
} else {
// Maven checks
folder = new File(projectDir, //$NON-NLS-1$ //$NON-NLS-2$
"target" + File.separator + "classes");
if (folder.exists()) {
classes.add(folder);
// it's in a more specific subfolder
if (sources.isEmpty()) {
File src = new File(projectDir, //$NON-NLS-1$
"src" + File.separator + "main" + //$NON-NLS-1$
File.separator + //$NON-NLS-1$
"java");
if (src.exists()) {
sources.add(src);
} else {
src = new File(projectDir, SRC_FOLDER);
if (src.exists()) {
sources.add(src);
}
}
File gen = new File(projectDir, //$NON-NLS-1$
"target" + File.separator + "generated-sources" + //$NON-NLS-1$
File.separator + //$NON-NLS-1$
"r");
if (gen.exists()) {
sources.add(gen);
}
}
}
}
}
// Fallback, in case there is no Eclipse project metadata here
if (sources.isEmpty()) {
File src = new File(projectDir, SRC_FOLDER);
if (src.exists()) {
sources.add(src);
}
File gen = new File(projectDir, GEN_FOLDER);
if (gen.exists()) {
sources.add(gen);
}
}
info = new ClassPathInfo(sources, classes, libraries, libraries, tests);
mProjectInfo.put(project, info);
}
return info;
}
use of com.android.annotations.NonNull in project kotlin by JetBrains.
the class LintClient method findGlobalRuleJars.
/**
* Finds any custom lint rule jars that should be included for analysis,
* regardless of project.
* <p>
* The default implementation locates custom lint jars in ~/.android/lint/ and
* in $ANDROID_LINT_JARS
*
* @return a list of rule jars (possibly empty).
*/
// Intentionally instance method so it can be overridden
@SuppressWarnings("MethodMayBeStatic")
@NonNull
public List<File> findGlobalRuleJars() {
// Look for additional detectors registered by the user, via
// (1) an environment variable (useful for build servers etc), and
// (2) via jar files in the .android/lint directory
List<File> files = null;
try {
String androidHome = AndroidLocation.getFolder();
//$NON-NLS-1$
File lint = new File(androidHome + File.separator + "lint");
if (lint.exists()) {
File[] list = lint.listFiles();
if (list != null) {
for (File jarFile : list) {
if (endsWith(jarFile.getName(), DOT_JAR)) {
if (files == null) {
files = new ArrayList<File>();
}
files.add(jarFile);
}
}
}
}
} catch (AndroidLocation.AndroidLocationException e) {
// Ignore -- no android dir, so no rules to load.
}
//$NON-NLS-1$
String lintClassPath = System.getenv("ANDROID_LINT_JARS");
if (lintClassPath != null && !lintClassPath.isEmpty()) {
String[] paths = lintClassPath.split(File.pathSeparator);
for (String path : paths) {
File jarFile = new File(path);
if (jarFile.exists()) {
if (files == null) {
files = new ArrayList<File>();
} else if (files.contains(jarFile)) {
continue;
}
files.add(jarFile);
}
}
}
return files != null ? files : Collections.<File>emptyList();
}
use of com.android.annotations.NonNull in project kotlin by JetBrains.
the class Project method getResourceVisibility.
/**
* Returns a shared {@link ResourceVisibilityLookup}
*
* @return a shared provider for looking up resource visibility
*/
@NonNull
public ResourceVisibilityLookup getResourceVisibility() {
if (mResourceVisibility == null) {
if (isGradleProject()) {
AndroidProject project = getGradleProjectModel();
Variant variant = getCurrentVariant();
if (project != null && variant != null) {
mResourceVisibility = mClient.getResourceVisibilityProvider().get(project, variant);
} else if (getGradleLibraryModel() != null) {
try {
mResourceVisibility = mClient.getResourceVisibilityProvider().get(getGradleLibraryModel());
} catch (Exception ignore) {
// Handle talking to older Gradle plugins (where we don't
// have access to the model version to check up front
}
}
}
if (mResourceVisibility == null) {
mResourceVisibility = ResourceVisibilityLookup.NONE;
}
}
return mResourceVisibility;
}
use of com.android.annotations.NonNull in project kotlin by JetBrains.
the class Project method getProguardFiles.
/**
* Returns the proguard files configured for this project, if any
*
* @return the proguard files, if any
*/
@NonNull
public List<File> getProguardFiles() {
if (mProguardFiles == null) {
List<File> files = new ArrayList<File>();
if (mProguardPath != null) {
//$NON-NLS-1$
Splitter splitter = Splitter.on(CharMatcher.anyOf(":;"));
for (String path : splitter.split(mProguardPath)) {
if (path.contains("${")) {
// Don't analyze the global/user proguard files
continue;
}
File file = new File(path);
if (!file.isAbsolute()) {
file = new File(getDir(), path);
}
if (file.exists()) {
files.add(file);
}
}
}
if (files.isEmpty()) {
File file = new File(getDir(), OLD_PROGUARD_FILE);
if (file.exists()) {
files.add(file);
}
file = new File(getDir(), FN_PROJECT_PROGUARD_FILE);
if (file.exists()) {
files.add(file);
}
}
mProguardFiles = files;
}
return mProguardFiles;
}
Aggregations