gradle-import

16:35:59.736 INFO  jd.cli.Main - Decompiling gradle-import.jar
package com.android.tools.gradle.eclipse;

import com.android.annotations.NonNull;
import com.android.annotations.Nullable;
import com.android.ide.common.repository.GradleCoordinate;
import com.google.common.collect.Lists;
import java.io.File;
import java.util.List;

class EclipseImportModule
  extends ImportModule
{
  private final EclipseProject mProject;
  private List<ImportModule> mDirectDependencies;
  private List<ImportModule> mAllDependencies;
  
  public EclipseImportModule(@NonNull GradleImport importer, @NonNull EclipseProject project)
  {
    super(importer);
    mProject = project;
    mProject.setModule(this);
  }
  
  @Nullable
  protected File getLintXml()
  {
    File lintXml = new File(mProject.getDir(), "lint.xml");
    return lintXml.exists() ? lintXml : null;
  }
  
  @NonNull
  protected File resolveFile(@NonNull File file)
  {
    if (file.isAbsolute()) {
      return file;
    }
    return new File(mProject.getDir(), file.getPath());
  }
  
  protected void initDependencies()
  {
    super.initDependencies();
    for (File jar : mProject.getJarPaths())
    {
      if (mImporter.isReplaceJars())
      {
        GradleCoordinate dependency = guessDependency(jar);
        if (dependency != null)
        {
          mDependencies.add(dependency);
          mImporter.getSummary().reportReplacedJar(jar, dependency);
          continue;
        }
      }
      mJarDependencies.add(getJarOutputRelativePath(jar));
    }
    for (File jar : mProject.getTestJarPaths())
    {
      if (mImporter.isReplaceJars())
      {
        GradleCoordinate dependency = guessDependency(jar);
        if (dependency != null)
        {
          mTestDependencies.add(dependency);
          mImporter.getSummary().reportReplacedJar(jar, dependency);
          continue;
        }
      }
      mTestJarDependencies.add(getTestJarOutputRelativePath(jar));
    }
  }
  
  public void addDependencies(@NonNull List<GradleCoordinate> dependencies)
  {
    for (GradleCoordinate dependency : dependencies) {
      if (!mDependencies.contains(dependency)) {
        mDependencies.addAll(dependencies);
      }
    }
  }
  
  protected boolean dependsOnLibrary(@NonNull String pkg)
  {
    if (!isAndroidProject()) {
      return false;
    }
    if (pkg.equals(mProject.getPackage())) {
      return true;
    }
    for (EclipseProject project : mProject.getAllLibraries()) {
      if (pkg.equals(project.getPackage())) {
        return true;
      }
    }
    return false;
  }
  
  @NonNull
  protected List<ImportModule> getDirectDependencies()
  {
    if (mDirectDependencies == null)
    {
      mDirectDependencies = Lists.newArrayList();
      for (EclipseProject project : mProject.getDirectLibraries())
      {
        EclipseImportModule module = project.getModule();
        if (module != null) {
          mDirectDependencies.add(module);
        }
      }
    }
    return mDirectDependencies;
  }
  
  @NonNull
  protected List<ImportModule> getAllDependencies()
  {
    if (mAllDependencies == null)
    {
      mAllDependencies = Lists.newArrayList();
      for (EclipseProject project : mProject.getAllLibraries())
      {
        EclipseImportModule module = project.getModule();
        if (module != null) {
          mAllDependencies.add(module);
        }
      }
    }
    return mAllDependencies;
  }
  
  protected boolean isAndroidProject()
  {
    return mProject.isAndroidProject();
  }
  
  protected boolean isLibrary()
  {
    return mProject.isLibrary();
  }
  
  @Nullable
  protected String getPackage()
  {
    return mProject.getPackage();
  }
  
  @NonNull
  protected String getOriginalName()
  {
    return mProject.getName();
  }
  
  public boolean isApp()
  {
    return (mProject.isAndroidProject()) && (!mProject.isLibrary());
  }
  
  public boolean isAndroidLibrary()
  {
    return (mProject.isAndroidProject()) && (mProject.isLibrary());
  }
  
  public boolean isJavaLibrary()
  {
    return !mProject.isAndroidProject();
  }
  
  public boolean isNdkProject()
  {
    return mProject.isNdkProject();
  }
  
  @Nullable
  protected File getManifestFile()
  {
    return mProject.getManifestFile();
  }
  
  @Nullable
  protected File getResourceDir()
  {
    return mProject.getResourceDir();
  }
  
  @Nullable
  protected File getAssetsDir()
  {
    return mProject.getAssetsDir();
  }
  
  @NonNull
  protected List<File> getSourcePaths()
  {
    return mProject.getSourcePaths();
  }
  
  @NonNull
  protected List<File> getJarPaths()
  {
    return mProject.getJarPaths();
  }
  
  @NonNull
  protected List<File> getTestJarPaths()
  {
    return mProject.getTestJarPaths();
  }
  
  @NonNull
  protected List<File> getNativeLibs()
  {
    return mProject.getNativeLibs();
  }
  
  @Nullable
  protected File getNativeSources()
  {
    return mProject.getNativeSources();
  }
  
  @Nullable
  protected String getNativeModuleName()
  {
    return mProject.getNativeModuleName();
  }
  
  @NonNull
  protected List<File> getLocalProguardFiles()
  {
    return mProject.getLocalProguardFiles();
  }
  
  @NonNull
  protected List<File> getSdkProguardFiles()
  {
    return mProject.getSdkProguardFiles();
  }
  
  @NonNull
  protected File getCanonicalModuleDir()
  {
    return mProject.getCanonicalDir();
  }
  
  @Nullable
  protected File getOutputDir()
  {
    return mProject.getOutputDir();
  }
  
  @NonNull
  protected String getLanguageLevel()
  {
    return mProject.getLanguageLevel();
  }
  
  protected int getCompileSdkVersion()
  {
    return mProject.getCompileSdkVersion();
  }
  
  protected int getTargetSdkVersion()
  {
    return mProject.getTargetSdkVersion();
  }
  
  protected int getMinSdkVersion()
  {
    return mProject.getMinSdkVersion();
  }
  
  protected boolean dependsOn(@NonNull ImportModule other)
  {
    return mProject.getAllLibraries().contains(mProject);
  }
  
  @NonNull
  public EclipseProject getProject()
  {
    return mProject;
  }
  
  @Nullable
  protected File getInstrumentationDir()
  {
    return mProject.getInstrumentationDir();
  }
}

/* Location:
 * Qualified Name:     com.android.tools.gradle.eclipse.EclipseImportModule
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.tools.gradle.eclipse;

import com.android.annotations.NonNull;
import com.android.annotations.Nullable;
import com.android.sdklib.AndroidTargetHash;
import com.android.sdklib.AndroidVersion;
import com.android.tools.lint.detector.api.LintUtils;
import com.android.utils.SdkUtils;
import com.android.utils.XmlUtils;
import com.google.common.base.Charsets;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.common.io.Files;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

class EclipseProject
  implements Comparable<EclipseProject>
{
  static final String DEFAULT_LANGUAGE_LEVEL = "1.6";
  private final GradleImport mImporter;
  private final File mDir;
  private final File mCanonicalDir;
  private boolean mLibrary;
  private boolean mAndroidProject;
  private boolean mNdkProject;
  private int mMinSdkVersion;
  private int mTargetSdkVersion;
  private Document mProjectDoc;
  private Document mManifestDoc;
  private Properties mProjectProperties;
  private AndroidVersion mVersion;
  private String mName;
  private String mLanguageLevel;
  private List<EclipseProject> mDirectLibraries;
  private List<File> mSourcePaths;
  private List<File> mJarPaths;
  private List<File> mInstrumentationJarPaths;
  private List<File> mNativeLibs;
  private File mNativeSources;
  private String mNativeModuleName;
  private File mOutputDir;
  private String mPackage;
  private List<File> mLocalProguardFiles;
  private List<File> mSdkProguardFiles;
  private List<EclipseProject> mAllLibraries;
  private EclipseImportModule mModule;
  private Map<String, String> mProjectVariableMap;
  private Map<String, String> mLinkedResourceMap;
  private File mInstrumentationDir;
  private static final String HOME_PROPERTY = "user.home";
  private static final String HOME_PROPERTY_REF = "${user.home}";
  private static final String SDK_PROPERTY_REF = "${sdk.dir}";
  
  private EclipseProject(@NonNull GradleImport importer, @NonNull File dir)
    throws IOException
  {
    mImporter = importer;
    mDir = dir;
    mCanonicalDir = dir.getCanonicalFile();
    
    mImporter.registerProject(this);
    
    initProjectName();
    initAndroidProject();
    initLanguageLevel();
    if (isAndroidProject())
    {
      Properties properties = getProjectProperties();
      initProguard(properties);
      initVersion(properties);
      initLibraries(properties);
      initLibrary(properties);
      initPackage();
      initMinSdkVersion();
      initInstrumentation();
    }
    else
    {
      mDirectLibraries = new ArrayList(4);
    }
    initClassPathEntries();
    initJni();
  }
  
  @NonNull
  public static EclipseProject getProject(@NonNull GradleImport importer, @NonNull File dir)
    throws IOException
  {
    Map<File, EclipseProject> mProjectMap = importer.getProjectMap();
    EclipseProject project = (EclipseProject)mProjectMap.get(dir);
    if (project == null)
    {
      project = createProject(importer, dir);
      
      assert (mProjectMap.get(dir) != null);
    }
    return project;
  }
  
  @NonNull
  private static EclipseProject createProject(@NonNull GradleImport importer, @NonNull File dir)
    throws IOException
  {
    return new EclipseProject(importer, dir);
  }
  
  private void initVersion(Properties properties)
  {
    String target = properties.getProperty("target");
    if (target != null) {
      mVersion = AndroidTargetHash.getPlatformVersion(target);
    }
  }
  
  private void initLibraries(Properties properties)
    throws IOException
  {
    mDirectLibraries = new ArrayList(4);
    for (int i = 1; i < 1000; i++)
    {
      String key = String.format("android.library.reference.%1$d", new Object[] { Integer.valueOf(i) });
      String library = properties.getProperty(key);
      if ((library == null) || (library.isEmpty())) {
        break;
      }
      File libraryDir = new File(mDir, library).getCanonicalFile();
      
      EclipseProject libraryPrj = getProject(mImporter, libraryDir);
      mDirectLibraries.add(libraryPrj);
    }
  }
  
  private void initLibrary(Properties properties)
    throws IOException
  {
    assert (mDirectLibraries != null);
    String value = properties.getProperty("android.library");
    mLibrary = "true".equals(value);
    if (!mLibrary)
    {
      boolean mergeManifests = "true".equals(properties.getProperty("manifestmerger.enabled"));
      if (!mergeManifests) {
        for (EclipseProject library : getAllLibraries()) {
          if ((library.isAndroidProject()) && (library.isLibrary()) && (library.getManifestFile().exists()) && (library.getManifestDoc().getDocumentElement() != null) && (XmlUtils.hasElementChildren(library.getManifestDoc().getDocumentElement())))
          {
            mImporter.getSummary().reportManifestsMayDiffer();
            break;
          }
        }
      }
    }
  }
  
  private void initPackage()
    throws IOException
  {
    mPackage = getManifestDoc().getDocumentElement().getAttribute("package");
  }
  
  private void initMinSdkVersion()
    throws IOException
  {
    NodeList usesSdks = getManifestDoc().getDocumentElement().getElementsByTagName("uses-sdk");
    if (usesSdks.getLength() > 0)
    {
      Element usesSdk = (Element)usesSdks.item(0);
      mMinSdkVersion = getApiVersion(usesSdk, "minSdkVersion", 1);
      mTargetSdkVersion = getApiVersion(usesSdk, "targetSdkVersion", mMinSdkVersion);
    }
    else
    {
      mMinSdkVersion = -1;
      mTargetSdkVersion = -1;
    }
  }
  
  private void initProjectName()
    throws IOException
  {
    Document document = getProjectDocument();
    if (document == null) {
      return;
    }
    NodeList names = document.getElementsByTagName("name");
    for (int i = 0; i < names.getLength(); i++)
    {
      Node element = names.item(i);
      mName = getStringValue((Element)element);
      if (mName != null) {
        break;
      }
    }
    if (mName == null) {
      mName = mDir.getName();
    }
  }
  
  private static int getApiVersion(Element usesSdk, String attribute, int defaultApiLevel)
  {
    String valueString = null;
    if (usesSdk.hasAttributeNS("http://schemas.android.com/apk/res/android", attribute)) {
      valueString = usesSdk.getAttributeNS("http://schemas.android.com/apk/res/android", attribute);
    }
    if (valueString != null)
    {
      int apiLevel = -1;
      try
      {
        apiLevel = Integer.valueOf(valueString).intValue();
      }
      catch (NumberFormatException e) {}
      return apiLevel;
    }
    return defaultApiLevel;
  }
  
  private void initJni()
    throws IOException
  {
    File jniDir = new File(mDir, "jni");
    if (!jniDir.exists()) {
      return;
    }
    Pattern pattern;
    if (mNdkProject)
    {
      mNativeSources = jniDir;
      
      File makefile = new File(jniDir, "Android.mk");
      if (makefile.exists())
      {
        pattern = Pattern.compile("\\s*LOCAL_MODULE\\s*:=\\s*(\\S+)\\s*");
        for (String line : Files.readLines(makefile, Charsets.UTF_8))
        {
          Matcher matcher = pattern.matcher(line);
          if (matcher.matches())
          {
            mNativeModuleName = matcher.group(1);
            if (mNativeLibs == null) {
              break;
            }
            String libName = "lib" + mNativeModuleName + ".so";
            ListIterator<File> iterator = mNativeLibs.listIterator();
            while (iterator.hasNext())
            {
              File lib = (File)iterator.next();
              if (libName.equals(lib.getName())) {
                iterator.remove();
              }
            }
            if (mNativeLibs.isEmpty()) {
              mNativeLibs = null;
            }
            break;
          }
        }
      }
    }
  }
  
  private void initInstrumentation()
    throws IOException
  {
    File projectDir = findInstrumentationTests(mDir);
    if ((projectDir == null) && (mDir.getParentFile() != null)) {
      projectDir = findInstrumentationTests(mDir.getParentFile());
    }
    if ((projectDir != null) && (!projectDir.equals(mDir)))
    {
      mInstrumentationDir = projectDir;
      
      File libs = new File(mInstrumentationDir, "libs");
      if (libs.exists())
      {
        File[] files = libs.listFiles();
        if (files != null) {
          for (File file : files) {
            if ((file.isFile()) && (SdkUtils.endsWithIgnoreCase(file.getPath(), ".jar")))
            {
              if (mInstrumentationJarPaths == null) {
                mInstrumentationJarPaths = Lists.newArrayList();
              }
              mInstrumentationJarPaths.add(file);
            }
          }
        }
      }
    }
  }
  
  private File findInstrumentationTests(File parent)
  {
    File[] files = parent.listFiles();
    if (files != null) {
      for (File file : files) {
        if (file.isDirectory())
        {
          File manifest = new File(file, "AndroidManifest.xml");
          if (manifest.exists()) {
            try
            {
              String target = getInstrumentationTarget(mImporter, manifest);
              if ((target != null) && (target.equals(mPackage))) {
                return file;
              }
            }
            catch (IOException e) {}
          }
        }
      }
    }
    return null;
  }
  
  @Nullable
  private static String getInstrumentationTarget(@NonNull GradleImport importer, @NonNull File manifest)
    throws IOException
  {
    Document doc = importer.getXmlDocument(manifest, true);
    NodeList list = doc.getElementsByTagName("instrumentation");
    for (int i = 0; i < list.getLength(); i++)
    {
      Element tag = (Element)list.item(i);
      String target = tag.getAttributeNS("http://schemas.android.com/apk/res/android", "targetPackage");
      if ((target != null) && (!target.isEmpty())) {
        return target;
      }
    }
    return null;
  }
  
  private void initClassPathEntries()
    throws IOException
  {
    assert ((mSourcePaths == null) && (mJarPaths == null));
    mSourcePaths = Lists.newArrayList();
    mJarPaths = Lists.newArrayList();
    
    Document document = null;
    File classPathFile = getClassPathFile();
    if (!classPathFile.exists())
    {
      File src = new File(mDir, "src");
      if (src.exists()) {
        mSourcePaths.add(src);
      }
    }
    else
    {
      document = mImporter.getXmlDocument(classPathFile, false);
    }
    if (document != null)
    {
      NodeList entries = document.getElementsByTagName("classpathentry");
      for (int i = 0; i < entries.getLength(); i++)
      {
        Node entry = entries.item(i);
        assert (entry.getNodeType() == 1);
        Element element = (Element)entry;
        String kind = element.getAttribute("kind");
        String path = element.getAttribute("path");
        if (kind.equals("var"))
        {
          File resolved = resolveVariableExpression(path);
          if (resolved != null) {
            mSourcePaths.add(resolved);
          } else {
            mImporter.reportWarning(this, getClassPathFile(), "Could not resolve path variable " + path);
          }
        }
        else if ((kind.equals("src")) && (!path.isEmpty()))
        {
          if (!path.equals("gen"))
          {
            File resolved = resolveVariableExpression(path);
            if (resolved != null)
            {
              if ((path.startsWith("/")) && (GradleImport.isEclipseProjectDir(resolved)))
              {
                EclipseProject lib = getProject(mImporter, resolved);
                if (!mDirectLibraries.contains(lib))
                {
                  mDirectLibraries.add(lib);
                  mAllLibraries = null;
                }
              }
              else
              {
                mSourcePaths.add(resolved);
              }
            }
            else {
              mImporter.reportWarning(this, getClassPathFile(), "Could not resolve source path " + path + " in project " + getName() + ": ignored. The project may not " + "compile if the given source path provided " + "source code.");
            }
          }
        }
        else if ((kind.equals("lib")) && (!path.isEmpty()))
        {
          if (!isAndroidProject())
          {
            File resolved = resolveVariableExpression(path);
            if (resolved != null) {
              mJarPaths.add(resolved);
            } else {
              mImporter.reportWarning(this, getClassPathFile(), "Absolute path in the path entry: If outside project, may not work correctly: " + path);
            }
          }
        }
        else if ((kind.equals("output")) && (!path.isEmpty()))
        {
          String relative = path.replace('/', File.separatorChar);
          File file = new File(relative);
          if (!file.isAbsolute()) {
            mOutputDir = file;
          }
        }
      }
    }
    File[] libs = new File(mDir, "libs").listFiles();
    if (libs != null) {
      for (File lib : libs) {
        if (!lib.isFile())
        {
          File[] libraries = lib.listFiles();
          if (libraries != null) {
            for (File library : libraries)
            {
              String name = library.getName();
              if ((library.isFile()) && (name.startsWith("lib")) && (name.contains(".so")))
              {
                if (mNativeLibs == null) {
                  mNativeLibs = Lists.newArrayList();
                }
                File relative = new File("libs", lib.getName() + File.separator + library.getName());
                
                mNativeLibs.add(relative);
              }
            }
          }
        }
        else
        {
          assert (lib.isFile());
          if (SdkUtils.endsWithIgnoreCase(lib.getPath(), ".jar"))
          {
            File relative = new File("libs", lib.getName());
            if ((!mJarPaths.contains(relative)) && (!mJarPaths.contains(lib)))
            {
              boolean isLibraryJar = false;
              for (EclipseProject project : getAllLibraries()) {
                if (project.isAndroidProject())
                {
                  String pkg = project.getPackage();
                  if (pkg != null)
                  {
                    String jarName = pkg.replace('.', '-') + ".jar";
                    if (jarName.equals(lib.getName()))
                    {
                      isLibraryJar = true;
                      break;
                    }
                  }
                }
              }
              if (!isLibraryJar) {
                mJarPaths.add(relative);
              }
            }
          }
        }
      }
    }
  }
  
  private Map<String, String> getProjectVariableMap()
  {
    if (mProjectVariableMap == null)
    {
      mProjectVariableMap = Maps.newHashMap();
      Document document;
      try
      {
        document = getProjectDocument();
        if (document == null) {
          return mProjectVariableMap;
        }
      }
      catch (IOException e)
      {
        return mProjectVariableMap;
      }
      assert (document != null);
      NodeList variables = document.getElementsByTagName("variable");
      int i = 0;
      for (int n = variables.getLength(); i < n; i++)
      {
        Element variable = (Element)variables.item(i);
        NodeList names = variable.getElementsByTagName("name");
        NodeList values = variable.getElementsByTagName("value");
        if ((names.getLength() == 1) && (values.getLength() == 1))
        {
          String value = getStringValue((Element)values.item(0));
          String key = getStringValue((Element)names.item(0));
          mProjectVariableMap.put(key, value);
        }
      }
    }
    return mProjectVariableMap;
  }
  
  private Map<String, String> getLinkedResourceMap()
  {
    if (mLinkedResourceMap == null)
    {
      mLinkedResourceMap = Maps.newHashMap();
      Document document;
      try
      {
        document = getProjectDocument();
        if (document == null) {
          return mProjectVariableMap;
        }
      }
      catch (IOException e)
      {
        return mLinkedResourceMap;
      }
      assert (document != null);
      NodeList links = document.getElementsByTagName("link");
      int i = 0;
      for (int n = links.getLength(); i < n; i++)
      {
        Element variable = (Element)links.item(i);
        NodeList names = variable.getElementsByTagName("name");
        NodeList values = variable.getElementsByTagName("locationURI");
        if ((names.getLength() == 1) && (values.getLength() == 1))
        {
          String value = getStringValue((Element)values.item(0));
          String key = getStringValue((Element)names.item(0));
          mLinkedResourceMap.put(key, value);
        }
      }
    }
    return mLinkedResourceMap;
  }
  
  @Nullable
  File resolveVariableExpression(@NonNull String path)
    throws IOException
  {
    File file = resolveVariableExpression(path, true, 0);
    if ((file != null) && (mImporter.getPathMap().containsKey(path))) {
      mImporter.getPathMap().put(path, file);
    }
    return file;
  }
  
  @Nullable
  private File resolveVariableExpression(@NonNull String path, boolean record, int depth)
    throws IOException
  {
    if (depth > 50) {
      return null;
    }
    if (path.equals("PROJECT_LOC")) {
      return mDir;
    }
    if (path.equals("PARENT_LOC")) {
      return mDir.getParentFile();
    }
    if (path.equals("WORKSPACE_LOC")) {
      return mImporter.getEclipseWorkspace();
    }
    if (path.startsWith("PARENT-"))
    {
      Pattern pattern = Pattern.compile("PARENT-(\\d+)-(.+)");
      Matcher matcher = pattern.matcher(path);
      if (matcher.matches())
      {
        int count = Integer.parseInt(matcher.group(1));
        String target = matcher.group(2);
        int index = target.indexOf('/');
        if (index == -1) {
          index = target.indexOf('\\');
        }
        String var = index == -1 ? target : target.substring(0, index);
        File file = resolveVariableExpression(var, false, depth + 1);
        if (file != null)
        {
          File original = file;
          for (int i = 0; i < count; i++)
          {
            if (file == null) {
              break;
            }
            file = file.getParentFile();
          }
          if (file == null)
          {
            file = original.getCanonicalFile();
            for (int i = 0; i < count; i++)
            {
              if (file == null) {
                break;
              }
              file = file.getParentFile();
            }
          }
        }
        if ((file != null) && (index != -1)) {
          file = new File(file, target.substring(index + 1));
        }
        return file;
      }
    }
    String filePath = path.replace('/', File.separatorChar);
    File resolved = new File(filePath);
    if (resolved.exists()) {
      return resolved;
    }
    resolved = new File(mDir, filePath);
    if (resolved.exists()) {
      return resolved;
    }
    resolved = (File)mImporter.getPathMap().get(path);
    if (resolved != null) {
      return resolved;
    }
    if (record) {
      mImporter.getPathMap().put(path, null);
    }
    if (path.startsWith("/"))
    {
      resolved = mImporter.resolveWorkspacePath(this, path, record);
      if (resolved != null) {
        return resolved;
      }
      if ((path.indexOf('/', 1) == -1) && (path.indexOf('\\', 1) == -1))
      {
        String name = path.substring(1);
        
        File parent = mDir.getParentFile();
        if (parent != null)
        {
          File sibling = new File(parent, name);
          if (sibling.exists()) {
            return sibling;
          }
        }
        File child = new File(mDir, name);
        if (child.exists()) {
          return child;
        }
      }
    }
    else if (path.startsWith("$%7B"))
    {
      int start = 4;
      int end = path.indexOf("%7D", 4);
      if (end != -1)
      {
        String sub = path.substring(start, end);
        File expression = resolveVariableExpression(sub, false, depth + 1);
        if (expression != null)
        {
          String suffix = path.substring(end + 3);
          if (suffix.isEmpty()) {
            return expression;
          }
          resolved = new File(expression, suffix.replace('/', File.separatorChar));
          if (resolved.exists()) {
            return resolved;
          }
        }
      }
    }
    else
    {
      int index = path.indexOf('/');
      if (index == -1) {
        index = path.indexOf('\\');
      }
      String var;
      String var;
      if (index == -1) {
        var = path;
      } else {
        var = path.substring(0, index);
      }
      Map<String, String> map = getLinkedResourceMap();
      String expression = (String)map.get(var);
      if ((expression == null) || (expression.equals(var)))
      {
        map = getProjectVariableMap();
        expression = (String)map.get(var);
      }
      File file;
      File file;
      if (expression != null)
      {
        File file;
        if (expression.startsWith("file:")) {
          file = SdkUtils.urlToFile(expression);
        } else {
          file = resolveVariableExpression(expression, false, depth + 1);
        }
      }
      else
      {
        file = mImporter.resolvePathVariable(this, var, false);
      }
      if (file != null)
      {
        if (index == -1) {
          return file;
        }
        resolved = new File(file, path.substring(index + 1));
        if (resolved.exists()) {
          return resolved;
        }
      }
    }
    return null;
  }
  
  private void initAndroidProject()
    throws IOException
  {
    mAndroidProject = hasNature("com.android.ide.eclipse.adt.AndroidNature");
    if ((!mAndroidProject) && (getProjectDocument() == null)) {
      mAndroidProject = GradleImport.isAdtProjectDir(mDir);
    }
    mNdkProject = ((mAndroidProject) && ((hasNature("org.eclipse.cdt.core.cnature")) || (hasNature("org.eclipse.cdt.core.ccnature")) || (new File(mDir, "jni" + File.separator + "Android.mk").exists())));
  }
  
  private boolean hasNature(String nature)
    throws IOException
  {
    Document document = getProjectDocument();
    if (document != null)
    {
      NodeList natures = document.getElementsByTagName("nature");
      for (int i = 0; i < natures.getLength(); i++)
      {
        Node element = natures.item(i);
        String value = getStringValue((Element)element);
        if (nature.equals(value)) {
          return true;
        }
      }
    }
    return false;
  }
  
  private void initLanguageLevel()
    throws IOException
  {
    if (mLanguageLevel == null)
    {
      mLanguageLevel = "1.6";
      File file = new File(mDir, ".settings" + File.separator + "org.eclipse.jdt.core.prefs");
      if (file.exists())
      {
        Properties properties = GradleImport.getProperties(file);
        if (properties != null)
        {
          String source = properties.getProperty("org.eclipse.jdt.core.compiler.source");
          if (source != null) {
            mLanguageLevel = source;
          }
        }
      }
    }
  }
  
  private void initProguard(Properties properties)
  {
    mLocalProguardFiles = Lists.newArrayList();
    mSdkProguardFiles = Lists.newArrayList();
    
    String proguardConfig = properties.getProperty("proguard.config");
    if ((proguardConfig != null) && (!proguardConfig.isEmpty()))
    {
      if ((File.separatorChar != '/') && (proguardConfig.indexOf('/') != -1)) {
        proguardConfig = proguardConfig.replace('/', File.separatorChar);
      }
      Iterable<String> paths = LintUtils.splitPath(proguardConfig);
      for (String path : paths) {
        if (path.startsWith("${sdk.dir}"))
        {
          mSdkProguardFiles.add(new File(path.substring("${sdk.dir}".length()).replace('/', File.separatorChar)));
        }
        else if (path.startsWith("${user.home}"))
        {
          mImporter.getSummary().reportIgnoredUserHomeProGuardFile(path);
        }
        else
        {
          File proguardConfigFile = new File(path.replace('/', File.separatorChar));
          if (!proguardConfigFile.isAbsolute()) {
            proguardConfigFile = new File(mDir, proguardConfigFile.getPath());
          }
          if (proguardConfigFile.isFile()) {
            mLocalProguardFiles.add(proguardConfigFile);
          }
        }
      }
    }
  }
  
  @NonNull
  public File getDir()
  {
    return mDir;
  }
  
  @NonNull
  public File getCanonicalDir()
  {
    return mCanonicalDir;
  }
  
  public boolean isLibrary()
  {
    return mLibrary;
  }
  
  @NonNull
  public List<File> getLocalProguardFiles()
  {
    assert (isAndroidProject());
    return mLocalProguardFiles;
  }
  
  @NonNull
  public List<File> getSdkProguardFiles()
  {
    assert (isAndroidProject());
    return mSdkProguardFiles;
  }
  
  @NonNull
  public File getResourceDir()
  {
    assert (isAndroidProject());
    return new File(mDir, "res");
  }
  
  @NonNull
  public File getAssetsDir()
  {
    assert (isAndroidProject());
    return new File(mDir, "assets");
  }
  
  @NonNull
  private File getClassPathFile()
  {
    return new File(mDir, ".classpath");
  }
  
  @NonNull
  public Document getManifestDoc()
    throws IOException
  {
    assert (isAndroidProject());
    if (mManifestDoc == null)
    {
      File file = getManifestFile();
      mManifestDoc = mImporter.getXmlDocument(file, true);
    }
    return mManifestDoc;
  }
  
  @NonNull
  File getManifestFile()
  {
    assert (isAndroidProject());
    return new File(mDir, "AndroidManifest.xml");
  }
  
  @Nullable
  public Properties getProjectProperties()
    throws IOException
  {
    if (mProjectProperties == null)
    {
      assert (isAndroidProject());
      File file = getProjectPropertiesFile();
      if (file.exists()) {
        mProjectProperties = GradleImport.getProperties(file);
      } else {
        mProjectProperties = new Properties();
      }
    }
    return mProjectProperties;
  }
  
  private File getProjectPropertiesFile()
  {
    return new File(mDir, "project.properties");
  }
  
  @Nullable
  private Document getProjectDocument()
    throws IOException
  {
    if (mProjectDoc == null)
    {
      File file = new File(mDir, ".project");
      if (file.exists()) {
        mProjectDoc = mImporter.getXmlDocument(file, false);
      }
    }
    return mProjectDoc;
  }
  
  public boolean isAndroidProject()
  {
    return mAndroidProject;
  }
  
  public boolean isNdkProject()
  {
    return mNdkProject;
  }
  
  @Nullable
  public File getInstrumentationDir()
  {
    return mInstrumentationDir;
  }
  
  @Nullable
  private static String getStringValue(@NonNull Element element)
  {
    NodeList children = element.getChildNodes();
    for (int j = 0; j < children.getLength(); j++)
    {
      Node child = children.item(j);
      if (child.getNodeType() == 3) {
        return child.getNodeValue().trim();
      }
    }
    return null;
  }
  
  @Nullable
  public String getPackage()
  {
    assert (isAndroidProject());
    return mPackage;
  }
  
  @NonNull
  public List<File> getSourcePaths()
  {
    return mSourcePaths;
  }
  
  @NonNull
  public List<File> getJarPaths()
  {
    return mJarPaths;
  }
  
  @NonNull
  public List<File> getTestJarPaths()
  {
    return mInstrumentationJarPaths != null ? mInstrumentationJarPaths : Collections.emptyList();
  }
  
  @NonNull
  public List<File> getNativeLibs()
  {
    return mNativeLibs != null ? mNativeLibs : Collections.emptyList();
  }
  
  @Nullable
  public File getNativeSources()
  {
    return mNativeSources;
  }
  
  @Nullable
  public String getNativeModuleName()
  {
    return mNativeModuleName;
  }
  
  @Nullable
  public File getOutputDir()
  {
    return mOutputDir;
  }
  
  @NonNull
  public String getLanguageLevel()
  {
    return mLanguageLevel;
  }
  
  @NonNull
  public String getName()
  {
    return mName;
  }
  
  public int getMinSdkVersion()
  {
    assert (isAndroidProject());
    return mMinSdkVersion;
  }
  
  public int getTargetSdkVersion()
  {
    assert (isAndroidProject());
    return mTargetSdkVersion;
  }
  
  public int getCompileSdkVersion()
  {
    assert (isAndroidProject());
    return mVersion != null ? mVersion.getApiLevel() : 19;
  }
  
  @NonNull
  public List<EclipseProject> getDirectLibraries()
  {
    return mDirectLibraries;
  }
  
  @NonNull
  public List<EclipseProject> getAllLibraries()
  {
    if (mAllLibraries == null)
    {
      if (mDirectLibraries.isEmpty()) {
        return mDirectLibraries;
      }
      List<EclipseProject> all = new ArrayList();
      Set<EclipseProject> seen = Sets.newHashSet();
      Set<EclipseProject> path = Sets.newHashSet();
      seen.add(this);
      path.add(this);
      addLibraryProjects(all, seen, path);
      mAllLibraries = all;
    }
    return mAllLibraries;
  }
  
  private void addLibraryProjects(@NonNull Collection<EclipseProject> collection, @NonNull Set<EclipseProject> seen, @NonNull Set<EclipseProject> path)
  {
    for (EclipseProject library : mDirectLibraries) {
      if (seen.contains(library))
      {
        if (path.contains(library)) {
          mImporter.reportWarning(library, library.getDir(), "Internal error: cyclic library dependency for " + library);
        }
      }
      else
      {
        collection.add(library);
        seen.add(library);
        path.add(library);
        
        library.addLibraryProjects(collection, seen, path);
        path.remove(library);
      }
    }
  }
  
  public int compareTo(@NonNull EclipseProject other)
  {
    return mDir.compareTo(mDir);
  }
  
  public String toString()
  {
    return mDir.getPath();
  }
  
  public static List<? extends ImportModule> performImport(@NonNull GradleImport importer, @NonNull Collection<EclipseProject> projects)
  {
    List<EclipseImportModule> modules = Lists.newArrayList();
    List<EclipseImportModule> replacedByDependencies = Lists.newArrayList();
    for (EclipseProject project : projects)
    {
      EclipseImportModule module = new EclipseImportModule(importer, project);
      module.initialize();
      if (module.isReplacedWithDependency()) {
        replacedByDependencies.add(module);
      } else {
        modules.add(module);
      }
    }
    for (Iterator i$ = replacedByDependencies.iterator(); i$.hasNext();)
    {
      replaced = (EclipseImportModule)i$.next();
      assert (replaced.getReplaceWithDependencies() != null);
      project = replaced.getProject();
      for (EclipseImportModule module : modules) {
        if (module.getProject().getAllLibraries().contains(project)) {
          module.addDependencies(replaced.getReplaceWithDependencies());
        }
      }
    }
    EclipseImportModule replaced;
    EclipseProject project;
    for (EclipseImportModule module : modules) {
      module.removeJarDependencies();
    }
    Collections.sort(modules);
    
    return modules;
  }
  
  @Nullable
  public EclipseImportModule getModule()
  {
    return mModule;
  }
  
  public void setModule(@Nullable EclipseImportModule module)
  {
    mModule = module;
  }
}

/* Location:
 * Qualified Name:     com.android.tools.gradle.eclipse.EclipseProject
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.tools.gradle.eclipse;

class GradleImport$1 {}

/* Location:
 * Qualified Name:     com.android.tools.gradle.eclipse.GradleImport.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.tools.gradle.eclipse;

import com.android.annotations.NonNull;
import java.io.File;
import java.io.IOException;

public abstract interface GradleImport$CopyHandler
{
  public abstract boolean handle(@NonNull File paramFile1, @NonNull File paramFile2)
    throws IOException;
}

/* Location:
 * Qualified Name:     com.android.tools.gradle.eclipse.GradleImport.CopyHandler
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.tools.gradle.eclipse;

import com.android.annotations.NonNull;

class GradleImport$ImportException
  extends RuntimeException
{
  private String mMessage;
  
  private GradleImport$ImportException(@NonNull String message)
  {
    mMessage = message;
  }
  
  public String getMessage()
  {
    return mMessage;
  }
  
  public String toString()
  {
    return getMessage();
  }
}

/* Location:
 * Qualified Name:     com.android.tools.gradle.eclipse.GradleImport.ImportException
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.tools.gradle.eclipse;

import com.android.annotations.NonNull;
import com.android.annotations.Nullable;
import com.android.ide.common.repository.GradleCoordinate;
import com.android.sdklib.BuildToolInfo;
import com.android.sdklib.SdkManager;
import com.android.sdklib.repository.FullRevision;
import com.android.sdklib.repository.descriptors.IPkgDesc;
import com.android.sdklib.repository.descriptors.PkgType;
import com.android.sdklib.repository.local.LocalPkgInfo;
import com.android.sdklib.repository.local.LocalSdk;
import com.android.utils.ILogger;
import com.android.utils.SdkUtils;
import com.android.utils.StdLogger;
import com.android.utils.StdLogger.Level;
import com.google.common.base.Charsets;
import c
1 2 3

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd