Java Code Examples for com.android.sdklib.IAndroidTarget

The following examples show how to use com.android.sdklib.IAndroidTarget. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: java-n-IDE-for-Android   Source File: LocalSdk.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns the targets (platforms & addons) that are available in the SDK.
 * The target list is created on demand the first time then cached.
 * It will not refreshed unless {@link #clearLocalPkg} is called to clear platforms
 * and/or add-ons.
 * <p/>
 * The array can be empty but not null.
 */
@NonNull
public IAndroidTarget[] getTargets() {
    synchronized (mLocalPackages) {
        if (mReloadTargets) {
            LocalPkgInfo[] pkgsInfos = getPkgsInfos(EnumSet.of(PkgType.PKG_PLATFORM,
                                                               PkgType.PKG_ADDON));
            int n = pkgsInfos.length;
            mCachedTargets.clear();
            for (int i = 0; i < n; i++) {
                LocalPkgInfo info = pkgsInfos[i];
                assert info instanceof LocalPlatformPkgInfo;
                if (info instanceof LocalPlatformPkgInfo) {
                    IAndroidTarget target = ((LocalPlatformPkgInfo) info).getAndroidTarget();
                    if (target != null) {
                        mCachedTargets.add(target);
                    }
                }
            }
        }
        return mCachedTargets.toArray(new IAndroidTarget[mCachedTargets.size()]);
    }
}
 
Example 2
Source Project: java-n-IDE-for-Android   Source File: ProjectCreator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Installs the project icons.
 * @param resourceFolder the resource folder
 * @param target the target of the project.
 * @return true if any icon was installed.
 */
private boolean installIcons(File resourceFolder, IAndroidTarget target)
        throws ProjectCreateException {
    // query the target for its template directory
    String templateFolder = target.getPath(IAndroidTarget.TEMPLATES);

    boolean installedIcon = false;

    installedIcon |= installIcon(templateFolder, "ic_launcher_xhdpi.png", resourceFolder,
            "drawable-xhdpi");
    installedIcon |= installIcon(templateFolder, "ic_launcher_hdpi.png", resourceFolder,
            "drawable-hdpi");
    installedIcon |= installIcon(templateFolder, "ic_launcher_mdpi.png", resourceFolder,
            "drawable-mdpi");
    installedIcon |= installIcon(templateFolder, "ic_launcher_ldpi.png", resourceFolder,
            "drawable-ldpi");

    return installedIcon;
}
 
Example 3
Source Project: java-n-IDE-for-Android   Source File: PlatformTarget.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public File getDefaultSkin() {
    // only one skin? easy.
    if (mSkins.length == 1) {
        return mSkins[0];
    }

    // look for the skin name in the platform props
    String skinName = mProperties.get(SdkConstants.PROP_SDK_DEFAULT_SKIN);
    if (skinName == null) {
        // otherwise try to find a good default.
        if (mVersion.getApiLevel() >= 4) {
            // at this time, this is the default skin for all older platforms that had 2+ skins.
            skinName = "WVGA800";                                       //$NON-NLS-1$
        } else {
            skinName = "HVGA"; // this is for 1.5 and earlier.          //$NON-NLS-1$
        }
    }

    return new File(getFile(IAndroidTarget.SKINS), skinName);
}
 
Example 4
Source Project: java-n-IDE-for-Android   Source File: PlatformTarget.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public int compareTo(IAndroidTarget target) {
    // quick check.
    if (this == target) {
        return 0;
    }

    int versionDiff = mVersion.compareTo(target.getVersion());

    // only if the version are the same do we care about add-ons.
    if (versionDiff == 0) {
        // platforms go before add-ons.
        if (target.isPlatform() == false) {
            return -1;
        }
    }

    return versionDiff;
}
 
Example 5
Source Project: java-n-IDE-for-Android   Source File: SamplePackage.java    License: Apache License 2.0 6 votes vote down vote up
private SamplePackage(IAndroidTarget target, Properties props) {
    super(  null,                                   //source
            props,                                  //properties
            0,                                      //revision will be taken from props
            null,                                   //license
            null,                                   //description
            null,                                   //descUrl
            target.getPath(IAndroidTarget.SAMPLES)  //archiveOsPath
            );

    mVersion = target.getVersion();

    mMinApiLevel = getPropertyInt(props, PkgProps.SAMPLE_MIN_API_LEVEL,
                                         MIN_API_LEVEL_NOT_SPECIFIED);

    mPkgDesc = PkgDesc.Builder
            .newSample(mVersion,
                      (MajorRevision) getRevision(),
                      getMinToolsRevision())
            .setDescriptions(this)
            .create();
}
 
Example 6
Source Project: java-n-IDE-for-Android   Source File: PlatformPackage.java    License: Apache License 2.0 6 votes vote down vote up
@VisibleForTesting(visibility=Visibility.PRIVATE)
protected PlatformPackage(@Nullable SdkSource source,
                          @NonNull IAndroidTarget target,
                          @Nullable Properties props) {
    super(  source,                     //source
            props,                      //properties
            target.getRevision(),       //revision
            null,                       //license
            target.getDescription(),    //description
            null,                       //descUrl
            target.getLocation()        //archiveOsPath
            );

    mVersion = target.getVersion();
    mVersionName  = target.getVersionName();
    mLayoutlibVersion = new LayoutlibVersionMixin(props);
    mIncludedAbi = props == null ? null : props.getProperty(PkgProps.PLATFORM_INCLUDED_ABI);

    mPkgDesc = PkgDesc.Builder
            .newPlatform(mVersion,
                         (MajorRevision) getRevision(),
                         getMinToolsRevision())
            .setDescriptions(this)
            .create();
}
 
Example 7
Source Project: java-n-IDE-for-Android   Source File: PlatformPackage.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Computes a potential installation folder if an archive of this package were
 * to be installed right away in the given SDK root.
 * <p/>
 * A platform package is typically installed in SDK/platforms/android-"version".
 * However if we can find a different directory under SDK/platform that already
 * has this platform version installed, we'll use that one.
 *
 * @param osSdkRoot The OS path of the SDK root folder.
 * @param sdkManager An existing SDK manager to list current platforms and addons.
 * @return A new {@link File} corresponding to the directory to use to install this package.
 */
@Override
public File getInstallFolder(String osSdkRoot, SdkManager sdkManager) {

    // First find if this platform is already installed. If so, reuse the same directory.
    for (IAndroidTarget target : sdkManager.getTargets()) {
        if (target.isPlatform() && target.getVersion().equals(mVersion)) {
            return new File(target.getLocation());
        }
    }

    File platforms = new File(osSdkRoot, SdkConstants.FD_PLATFORMS);
    File folder = new File(platforms,
            String.format("android-%s", getAndroidVersion().getApiString())); //$NON-NLS-1$

    return folder;
}
 
Example 8
Source Project: java-n-IDE-for-Android   Source File: AvdInfo.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new <em>invalid</em> AVD info. Values are immutable.
 * <p/>
 * Such an AVD is not complete and cannot be used.
 * The error string must be non-null.
 *
 * @param name The name of the AVD (for display or reference)
 * @param iniFile The path to the config.ini file
 * @param folderPath The path to the data directory
 * @param targetHash the target hash
 * @param target The target. Can be null, if the target was not resolved.
 * @param tag The tag id/display.
 * @param abiType Name of the abi.
 * @param properties The property map. If null, an empty map will be created.
 * @param status The {@link AvdStatus} of this AVD. Cannot be null.
 */
public AvdInfo(@NonNull  String name,
               @NonNull  File iniFile,
               @NonNull  String folderPath,
               @NonNull  String targetHash,
               @Nullable IAndroidTarget target,
               @NonNull  IdDisplay tag,
               @NonNull  String abiType,
               @Nullable Map<String, String> properties,
               @NonNull AvdStatus status) {
    mName       = name;
    mIniFile    = iniFile;
    mFolderPath = folderPath;
    mTargetHash = targetHash;
    mTarget     = target;
    mTag        = tag;
    mAbiType    = abiType;
    mProperties = properties == null ? Collections.<String, String>emptyMap()
                                     : Collections.unmodifiableMap(properties);
    mStatus     = status;
}
 
Example 9
Source Project: javaide   Source File: DefaultSdkLoader.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
@NonNull
public TargetInfo getTargetInfo(
        @NonNull String targetHash,
        @NonNull FullRevision buildToolRevision,
        @NonNull ILogger logger) {
    init(logger);

    IAndroidTarget target = mSdkManager.getTargetFromHashString(targetHash);
    if (target == null) {
        throw new IllegalStateException("failed to find target with hash string '" + targetHash + "' in: " + mSdkLocation);
    }

    BuildToolInfo buildToolInfo = mSdkManager.getBuildTool(buildToolRevision);
    if (buildToolInfo == null) {
        throw new IllegalStateException("failed to find Build Tools revision "
                + buildToolRevision.toString());
    }

    return new TargetInfo(target, buildToolInfo);
}
 
Example 10
Source Project: javaide   Source File: LocalAddonPkgInfo.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Converts a string representation of an hexadecimal ID into an int.
 * @param value the string to convert.
 * @return the int value, or {@link IAndroidTarget#NO_USB_ID} if the conversion failed.
 */
private int convertId(@Nullable String value) {
    if (value != null && !value.isEmpty()) {
        if (PATTERN_USB_IDS.matcher(value).matches()) {
            String v = value.substring(2);
            try {
                return Integer.parseInt(v, 16);
            } catch (NumberFormatException e) {
                // this shouldn't happen since we check the pattern above, but this is safer.
                // the method will return 0 below.
            }
        }
    }

    return IAndroidTarget.NO_USB_ID;
}
 
Example 11
Source Project: javaide   Source File: PlatformLoader.java    License: GNU General Public License v3.0 6 votes vote down vote up
@NonNull
@Override
public TargetInfo getTargetInfo(@NonNull String targetHash,
        @NonNull FullRevision buildToolRevision, @NonNull ILogger logger) {
    init(logger);

    IAndroidTarget androidTarget = new FakeAndroidTarget(mTreeLocation.getPath(), targetHash);

    File hostTools = getHostToolsFolder();

    BuildToolInfo buildToolInfo = new BuildToolInfo(
            buildToolRevision,
            mTreeLocation,
            new File(hostTools, FN_AAPT),
            new File(hostTools, FN_AIDL),
            new File(mTreeLocation, "prebuilts/sdk/tools/dx"),
            new File(mTreeLocation, "prebuilts/sdk/tools/lib/dx.jar"),
            new File(hostTools, FN_BCC_COMPAT),
            new File(hostTools, "arm-linux-androideabi-ld"),
            new File(hostTools, "i686-linux-android-ld"),
            new File(hostTools, "mipsel-linux-android-ld"),
            new File(hostTools, FN_ZIPALIGN));

    return new TargetInfo(androidTarget, buildToolInfo);
}
 
Example 12
Source Project: javaide   Source File: LocalSdk.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the targets (platforms & addons) that are available in the SDK.
 * The target list is created on demand the first time then cached.
 * It will not refreshed unless {@link #clearLocalPkg} is called to clear platforms
 * and/or add-ons.
 * <p/>
 * The array can be empty but not null.
 */
@NonNull
public IAndroidTarget[] getTargets() {
    synchronized (mLocalPackages) {
        if (mCachedTargets == null) {
            List<IAndroidTarget> result = Lists.newArrayList();
            LocalPkgInfo[] pkgsInfos = getPkgsInfos(EnumSet.of(PkgType.PKG_PLATFORM,
                    PkgType.PKG_ADDON));
            for (LocalPkgInfo info : pkgsInfos) {
                assert info instanceof LocalPlatformPkgInfo;
                IAndroidTarget target = ((LocalPlatformPkgInfo) info).getAndroidTarget();
                if (target != null) {
                    result.add(target);
                }
            }
            mCachedTargets = result;
        }
        return mCachedTargets.toArray(new IAndroidTarget[mCachedTargets.size()]);
    }
}
 
Example 13
Source Project: javaide   Source File: PlatformTarget.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Nullable
@Override
public File getDefaultSkin() {
    // only one skin? easy.
    if (mSkins.length == 1) {
        return mSkins[0];
    }

    // look for the skin name in the platform props
    String skinName = mProperties.get(SdkConstants.PROP_SDK_DEFAULT_SKIN);
    if (skinName == null) {
        // otherwise try to find a good default.
        if (mVersion.getApiLevel() >= 4) {
            // at this time, this is the default skin for all older platforms that had 2+ skins.
            skinName = "WVGA800";                                       //$NON-NLS-1$
        } else {
            skinName = "HVGA"; // this is for 1.5 and earlier.          //$NON-NLS-1$
        }
    }

    return new File(getFile(IAndroidTarget.SKINS), skinName);
}
 
Example 14
Source Project: javaide   Source File: PlatformTarget.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean canRunOn(IAndroidTarget target) {
    // basic test
    if (target == this) {
        return true;
    }

    // if the platform has a codename (ie it's a preview of an upcoming platform), then
    // both platforms must be exactly identical.
    if (mVersion.getCodename() != null) {
        return mVersion.equals(target.getVersion());
    }

    // target is compatible wit the receiver as long as its api version number is greater or
    // equal.
    return target.getVersion().getApiLevel() >= mVersion.getApiLevel();
}
 
Example 15
Source Project: javaide   Source File: PlatformTarget.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public int compareTo(IAndroidTarget target) {
    // quick check.
    if (this == target) {
        return 0;
    }

    int versionDiff = mVersion.compareTo(target.getVersion());

    // only if the version are the same do we care about add-ons.
    if (versionDiff == 0) {
        // platforms go before add-ons.
        if (target.isPlatform() == false) {
            return -1;
        }
    }

    return versionDiff;
}
 
Example 16
Source Project: javaide   Source File: SamplePackage.java    License: GNU General Public License v3.0 6 votes vote down vote up
private SamplePackage(IAndroidTarget target, Properties props) {
    super(  null,                                   //source
            props,                                  //properties
            0,                                      //revision will be taken from props
            null,                                   //license
            null,                                   //description
            null,                                   //descUrl
            target.getPath(IAndroidTarget.SAMPLES)  //archiveOsPath
            );

    mVersion = target.getVersion();

    mMinApiLevel = getPropertyInt(props, PkgProps.SAMPLE_MIN_API_LEVEL,
            MIN_API_LEVEL_NOT_SPECIFIED);

    mPkgDesc = setDescriptions(PkgDesc.Builder
            .newSample(mVersion, (MajorRevision) getRevision(), getMinToolsRevision()))
            .create();
}
 
Example 17
Source Project: javaide   Source File: PlatformPackage.java    License: GNU General Public License v3.0 6 votes vote down vote up
@VisibleForTesting(visibility=Visibility.PRIVATE)
protected PlatformPackage(@Nullable SdkSource source,
                          @NonNull IAndroidTarget target,
                          @Nullable Properties props) {
    super(  source,                     //source
            props,                      //properties
            target.getRevision(),       //revision
            null,                       //license
            target.getDescription(),    //description
            null,                       //descUrl
            target.getLocation()        //archiveOsPath
            );

    mVersion = target.getVersion();
    mVersionName  = target.getVersionName();
    mLayoutlibVersion = new LayoutlibVersionMixin(props);
    mIncludedAbi = props == null ? null : props.getProperty(PkgProps.PLATFORM_INCLUDED_ABI);

    mPkgDesc = setDescriptions(PkgDesc.Builder
            .newPlatform(mVersion, (MajorRevision) getRevision(), getMinToolsRevision()))
            .create();
}
 
Example 18
Source Project: javaide   Source File: PlatformPackage.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Computes a potential installation folder if an archive of this package were
 * to be installed right away in the given SDK root.
 * <p/>
 * A platform package is typically installed in SDK/platforms/android-"version".
 * However if we can find a different directory under SDK/platform that already
 * has this platform version installed, we'll use that one.
 *
 * @param osSdkRoot The OS path of the SDK root folder.
 * @param sdkManager An existing SDK manager to list current platforms and addons.
 * @return A new {@link File} corresponding to the directory to use to install this package.
 */
@Override
public File getInstallFolder(String osSdkRoot, SdkManager sdkManager) {

    // First find if this platform is already installed. If so, reuse the same directory.
    for (IAndroidTarget target : sdkManager.getTargets()) {
        if (target.isPlatform() && target.getVersion().equals(mVersion)) {
            return new File(target.getLocation());
        }
    }

    File platforms = new File(osSdkRoot, SdkConstants.FD_PLATFORMS);
    File folder = new File(platforms,
            String.format("android-%s", getAndroidVersion().getApiString())); //$NON-NLS-1$

    return folder;
}
 
Example 19
Source Project: javaide   Source File: LintDetectorTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Nullable
@Override
public IAndroidTarget getCompileTarget(@NonNull Project project) {
    IAndroidTarget compileTarget = super.getCompileTarget(project);
    if (compileTarget == null) {
        IAndroidTarget[] targets = getTargets();
        for (int i = targets.length - 1; i >= 0; i--) {
            IAndroidTarget target = targets[i];
            if (target.isPlatform()) {
                return target;
            }
        }
    }

    return compileTarget;
}
 
Example 20
@Nullable
public IAndroidTarget getAndroidTarget() {
    if (!mLoaded) {
        mTarget = createAndroidTarget();
        mLoaded = true;
    }
    return mTarget;
}
 
Example 21
/**
 * Creates a PlatformPackage wrapping the IAndroidTarget if defined.
 * Invoked by {@link #getPackage()}.
 *
 * @return A Package or null if target isn't available.
 */
@Nullable
protected Package createPackage() {
    IAndroidTarget target = getAndroidTarget();
    if (target != null) {
        return PlatformPackage.create(target, getSourceProperties());
    }
    return null;
}
 
Example 22
Source Project: java-n-IDE-for-Android   Source File: LocalSdk.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns a target from a hash that was generated by {@link IAndroidTarget#hashString()}.
 *
 * @param hash the {@link IAndroidTarget} hash string.
 * @return The matching {@link IAndroidTarget} or null.
 */
@Nullable
public IAndroidTarget getTargetFromHashString(@Nullable String hash) {
    if (hash != null) {
        IAndroidTarget[] targets = getTargets();
        for (IAndroidTarget target : targets) {
            if (target != null && hash.equals(AndroidTargetHash.getTargetHashString(target))) {
                return target;
            }
        }
    }
    return null;
}
 
Example 23
Source Project: java-n-IDE-for-Android   Source File: AddOnTarget.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean canRunOn(IAndroidTarget target) {
    // basic test
    if (target == this) {
        return true;
    }

    /*
     * The method javadoc indicates:
     * Returns whether the given target is compatible with the receiver.
     * <p/>A target is considered compatible if applications developed for the receiver can
     * run on the given target.
     */

    // The receiver is an add-on. There are 2 big use cases: The add-on has libraries
    // or the add-on doesn't (in which case we consider it a platform).
    if (mLibraries == null || mLibraries.length == 0) {
        return mBasePlatform.canRunOn(target);
    } else {
        // the only targets that can run the receiver are the same add-on in the same or later
        // versions.
        // first check: vendor/name
        if (!mVendor.equals(target.getVendor()) || !mName.equals(target.getName())) {
            return false;
        }

        // now check the version. At this point since we checked the add-on part,
        // we can revert to the basic check on version/codename which are done by the
        // base platform already.
        return mBasePlatform.canRunOn(target);
    }

}
 
Example 24
public LaunchCompatibility canRun(
    com.android.sdklib.AndroidVersion androidVersion,
    IAndroidTarget iAndroidTarget,
    EnumSet<HardwareFeature> enumSet,
    @Nullable Set<String> set) {
  return null;
}
 
Example 25
Source Project: javaide   Source File: AndroidBuilder.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the compilation target, if set.
 */
@Nullable
public IAndroidTarget getTarget() {
    checkState(mTargetInfo != null,
            "Cannot call getTarget() before setTargetInfo() is called.");
    return mTargetInfo.getTarget();
}
 
Example 26
Source Project: java-n-IDE-for-Android   Source File: AddonPackage.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Computes a potential installation folder if an archive of this package were
 * to be installed right away in the given SDK root.
 * <p/>
 * An add-on package is typically installed in SDK/add-ons/"addon-name"-"api-level".
 * The name needs to be sanitized to be acceptable as a directory name.
 * However if we can find a different directory under SDK/add-ons that already
 * has this add-ons installed, we'll use that one.
 *
 * @param osSdkRoot The OS path of the SDK root folder.
 * @param sdkManager An existing SDK manager to list current platforms and addons.
 * @return A new {@link File} corresponding to the directory to use to install this package.
 */
@Override
public File getInstallFolder(String osSdkRoot, SdkManager sdkManager) {
    File addons = new File(osSdkRoot, SdkConstants.FD_ADDONS);

    // First find if this add-on is already installed. If so, reuse the same directory.
    for (IAndroidTarget target : sdkManager.getTargets()) {
        if (!target.isPlatform() && target.getVersion().equals(mVersion)) {
            // Starting with addon-4.xsd, the addon source.properties differentiate
            // between ids and display strings. However the addon target which relies
            // on the manifest.ini does not so we need to cover both cases.
            // TODO fix when we get rid of manifest.ini for addons
            if ((target.getName().equals(getNameId()) &&
                 target.getVendor().equals(getVendorId())) ||
                (target.getName().equals(getDisplayName()) &&
                 target.getVendor().equals(getDisplayVendor()))) {
                return new File(target.getLocation());
            }
        }
    }

    // Compute a folder directory using the addon declared name and vendor strings.
    String name = encodeAddonName();

    for (int i = 0; i < 100; i++) {
        String name2 = i == 0 ? name : String.format("%s-%d", name, i); //$NON-NLS-1$
        File folder = new File(addons, name2);
        if (!folder.exists()) {
            return folder;
        }
    }

    // We shouldn't really get here. I mean, seriously, we tried hard enough.
    return null;
}
 
Example 27
Source Project: NBANDROID-V2   Source File: AndroidPlatformInfo.java    License: Apache License 2.0 5 votes vote down vote up
public AndroidPlatformInfo(AndroidSdk sdk, IAndroidTarget target) throws FileNotFoundException {
    this.platformFolder = new File(target.getLocation());
    this.platformName = target.getFullName();
    androidVersion = target.getVersion();
    hashString = target.hashString();
    this.sdk = sdk;
    update(target);

}
 
Example 28
Source Project: java-n-IDE-for-Android   Source File: AvdManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns the path to the skin, as a relative path to the SDK.
 * @param skinName The name of the skin to find. Case-sensitive.
 * @param target The target where to find the skin.
 * @param log the log object to receive action logs. Cannot be null.
 */
@Deprecated
private String getSkinRelativePath(@NonNull String skinName,
                                   @NonNull IAndroidTarget target,
                                   @NonNull ILogger log) {
    if (log == null) {
        throw new IllegalArgumentException("log cannot be null");
    }

    // first look to see if the skin is in the target
    File skin = getSkinFolder(skinName, target);

    // skin really does not exist!
    if (skin.exists() == false) {
        log.error(null, "Skin '%1$s' does not exist.", skinName);
        return null;
    }

    // get the skin path
    String path = skin.getAbsolutePath();

    // make this path relative to the SDK location

    String sdkLocation = myLocalSdk.getPath();
    if (path.startsWith(sdkLocation) == false) {
        // this really really should not happen.
        log.error(null, "Target location is not inside the SDK.");
        assert false;
        return null;
    }

    path = path.substring(sdkLocation.length());
    if (path.charAt(0) == File.separatorChar) {
        path = path.substring(1);
    }
    return path;
}
 
Example 29
Source Project: java-n-IDE-for-Android   Source File: AvdManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates the ini file for an AVD.
 *
 * @param name of the AVD.
 * @param avdFolder path for the data folder of the AVD.
 * @param target of the AVD.
 * @param removePrevious True if an existing ini file should be removed.
 * @throws AndroidLocationException if there's a problem getting android root directory.
 * @throws IOException if {@link File#getAbsolutePath()} fails.
 */
private File createAvdIniFile(@NonNull String name,
        @NonNull File avdFolder,
        @NonNull IAndroidTarget target,
        boolean removePrevious)
        throws AndroidLocationException, IOException {
    File iniFile = AvdInfo.getDefaultIniFile(this, name);

    if (removePrevious) {
        if (iniFile.isFile()) {
            iniFile.delete();
        } else if (iniFile.isDirectory()) {
            deleteContentOf(iniFile);
            iniFile.delete();
        }
    }

    String absPath = avdFolder.getAbsolutePath();
    String relPath = null;
    String androidPath = AndroidLocation.getFolder();
    if (absPath.startsWith(androidPath)) {
        // Compute the AVD path relative to the android path.
        assert androidPath.endsWith(File.separator);
        relPath = absPath.substring(androidPath.length());
    }

    HashMap<String, String> values = new HashMap<String, String>();
    if (relPath != null) {
        values.put(AVD_INFO_REL_PATH, relPath);
    }
    values.put(AVD_INFO_ABS_PATH, absPath);
    values.put(AVD_INFO_TARGET, target.hashString());
    writeIniFile(iniFile, values, true);

    return iniFile;
}
 
Example 30
Source Project: java-n-IDE-for-Android   Source File: AvdManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Sets the paths to the system images in a properties map.
 *
 * @param target the target in which to find the system images.
 * @param abiType the abi type of the avd to find
 *        the architecture-dependent system images.
 * @param properties the properties in which to set the paths.
 * @param log the log object to receive action logs. Cannot be null.
 * @return true if success, false if some path are missing.
 */
private boolean setImagePathProperties(IAndroidTarget target,
        IdDisplay tag,
        String abiType,
        Map<String, String> properties,
        ILogger log) {
    properties.remove(AVD_INI_IMAGES_1);
    properties.remove(AVD_INI_IMAGES_2);

    try {
        String property = AVD_INI_IMAGES_1;

        // First the image folders of the target itself
        String imagePath = getImageRelativePath(target, tag, abiType);
        if (imagePath != null) {
            properties.put(property, imagePath);
            property = AVD_INI_IMAGES_2;
        }

        // If the target is an add-on we need to add the Platform image as a backup.
        IAndroidTarget parent = target.getParent();
        if (parent != null) {
            imagePath = getImageRelativePath(parent, tag, abiType);
            if (imagePath != null) {
                properties.put(property, imagePath);
            }
        }

        // we need at least one path!
        return properties.containsKey(AVD_INI_IMAGES_1);
    } catch (InvalidTargetPathException e) {
        log.error(e, e.getMessage());
    }

    return false;
}