12c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll/*
22c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll * Copyright (C) 2010 The Android Open Source Project
32c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll *
42c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll * Licensed under the Apache License, Version 2.0 (the "License");
52c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll * you may not use this file except in compliance with the License.
62c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll * You may obtain a copy of the License at
72c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll *
82c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll *      http://www.apache.org/licenses/LICENSE-2.0
92c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll *
102c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll * Unless required by applicable law or agreed to in writing, software
112c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll * distributed under the License is distributed on an "AS IS" BASIS,
122c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
132c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll * See the License for the specific language governing permissions and
142c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll * limitations under the License.
152c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll */
162c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll
17908753734919c32cc5d4b538fea68f45c1eaf31fRaphael Mollpackage com.android.sdklib.internal.repository.packages;
182c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll
1981cefe2a26dd6db8a878e30874d12cdcbff0e83bXavier Ducrohetimport com.android.SdkConstants;
201f72cb7cb032538b79e79d6fc7ff3905e9766ce1Xavier Ducrohetimport com.android.annotations.VisibleForTesting;
211f72cb7cb032538b79e79d6fc7ff3905e9766ce1Xavier Ducrohetimport com.android.annotations.VisibleForTesting.Visibility;
222c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Mollimport com.android.sdklib.SdkManager;
23908753734919c32cc5d4b538fea68f45c1eaf31fRaphael Mollimport com.android.sdklib.internal.repository.AdbWrapper;
24908753734919c32cc5d4b538fea68f45c1eaf31fRaphael Mollimport com.android.sdklib.internal.repository.IDescription;
25908753734919c32cc5d4b538fea68f45c1eaf31fRaphael Mollimport com.android.sdklib.internal.repository.ITaskMonitor;
26908753734919c32cc5d4b538fea68f45c1eaf31fRaphael Mollimport com.android.sdklib.internal.repository.archives.Archive;
27908753734919c32cc5d4b538fea68f45c1eaf31fRaphael Mollimport com.android.sdklib.internal.repository.archives.Archive.Arch;
28908753734919c32cc5d4b538fea68f45c1eaf31fRaphael Mollimport com.android.sdklib.internal.repository.archives.Archive.Os;
29908753734919c32cc5d4b538fea68f45c1eaf31fRaphael Mollimport com.android.sdklib.internal.repository.sources.SdkSource;
302c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll
312c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Mollimport org.w3c.dom.Node;
322c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll
332c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Mollimport java.io.File;
3476e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Mollimport java.util.HashSet;
352c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Mollimport java.util.Map;
362c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Mollimport java.util.Properties;
3776e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Mollimport java.util.Set;
382c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll
392c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll/**
402c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll * Represents a platform-tool XML node in an SDK repository.
412c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll */
4287107c5cb1fb5fdafdaa94460fb6797af60fcde9Raphael Mollpublic class PlatformToolPackage extends FullRevisionPackage {
432c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll
442c4c6561c01683bda2681a1449e6a3c0915e5d6aRaphael    /** The value returned by {@link PlatformToolPackage#installId()}. */
452c4c6561c01683bda2681a1449e6a3c0915e5d6aRaphael    public static final String INSTALL_ID = "platform-tools";                       //$NON-NLS-1$
4687107c5cb1fb5fdafdaa94460fb6797af60fcde9Raphael Moll    /** The value returned by {@link PlatformToolPackage#installId()}. */
4787107c5cb1fb5fdafdaa94460fb6797af60fcde9Raphael Moll    public static final String INSTALL_ID_PREVIEW = "platform-tools-preview";       //$NON-NLS-1$
482c4c6561c01683bda2681a1449e6a3c0915e5d6aRaphael
492c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll    /**
502c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll     * Creates a new platform-tool package from the attributes and elements of the given XML node.
512c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll     * This constructor should throw an exception if the package cannot be created.
523b0c290370e679d007c2b93d26254f82df46df35Raphael Moll     *
533b0c290370e679d007c2b93d26254f82df46df35Raphael Moll     * @param source The {@link SdkSource} where this is loaded from.
543b0c290370e679d007c2b93d26254f82df46df35Raphael Moll     * @param packageNode The XML element being parsed.
553b0c290370e679d007c2b93d26254f82df46df35Raphael Moll     * @param nsUri The namespace URI of the originating XML document, to be able to deal with
563b0c290370e679d007c2b93d26254f82df46df35Raphael Moll     *          parameters that vary according to the originating XML schema.
573b0c290370e679d007c2b93d26254f82df46df35Raphael Moll     * @param licenses The licenses loaded from the XML originating document.
582c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll     */
59908753734919c32cc5d4b538fea68f45c1eaf31fRaphael Moll    public PlatformToolPackage(SdkSource source, Node packageNode,
603b0c290370e679d007c2b93d26254f82df46df35Raphael Moll            String nsUri, Map<String,String> licenses) {
613b0c290370e679d007c2b93d26254f82df46df35Raphael Moll        super(source, packageNode, nsUri, licenses);
622c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll    }
632c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll
642c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll    /**
652c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll     * Manually create a new package with one archive and the given attributes or properties.
662c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll     * This is used to create packages from local directories in which case there must be
672c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll     * one archive which URL is the actual target location.
682c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll     * <p/>
692c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll     * By design, this creates a package with one and only one archive.
702c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll     */
71908753734919c32cc5d4b538fea68f45c1eaf31fRaphael Moll    public static Package create(
723b0c290370e679d007c2b93d26254f82df46df35Raphael Moll            SdkSource source,
732c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll            Properties props,
742c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll            int revision,
752c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll            String license,
762c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll            String description,
772c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll            String descUrl,
782c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll            Os archiveOs,
792c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll            Arch archiveArch,
802c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll            String archiveOsPath) {
8176e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll
8276e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll        PlatformToolPackage ptp = new PlatformToolPackage(source, props, revision, license,
8376e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll                description, descUrl, archiveOs, archiveArch, archiveOsPath);
8476e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll
8576e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll        File platformToolsFolder = new File(archiveOsPath);
8676e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll        String error = null;
8776e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll        if (!platformToolsFolder.isDirectory()) {
8876e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll            error = "platform-tools folder is missing";
8976e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll        } else {
9076e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll            File[] files = platformToolsFolder.listFiles();
9176e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll            if (files == null || files.length == 0) {
9276e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll                error = "platform-tools folder is empty";
9376e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll            } else {
9476e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll                Set<String> names = new HashSet<String>();
9576e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll                for (File file : files) {
9676e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll                    names.add(file.getName());
9776e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll                }
9876e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll                for (String name : new String[] { SdkConstants.FN_ADB,
9976e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll                                                  SdkConstants.FN_AAPT,
10076e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll                                                  SdkConstants.FN_AIDL,
10176e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll                                                  SdkConstants.FN_DX } ) {
10276e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll                    if (!names.contains(name)) {
10376e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll                        if (error == null) {
10476e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll                            error = "platform-tools folder is missing ";
10576e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll                        } else {
10676e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll                            error += ", ";
10776e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll                        }
10876e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll                        error += name;
10976e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll                    }
11076e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll                }
11176e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll            }
11276e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll        }
11376e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll
11476e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll        if (error != null) {
11576e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll            String shortDesc = ptp.getShortDescription() + " [*]";  //$NON-NLS-1$
11676e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll
11776e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll            String longDesc = String.format(
11876e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll                    "Broken Platform-Tools Package: %1$s\n" +
11976e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll                    "[*] Package cannot be used due to error: %2$s",
12076e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll                    description,
12176e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll                    error);
12276e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll
12376e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll            BrokenPackage ba = new BrokenPackage(props, shortDesc, longDesc,
124b45a6db526d6f58872483db9b64ac54df3fcf5c7Raphael Moll                    IMinApiLevelDependency.MIN_API_LEVEL_NOT_SPECIFIED,
125b45a6db526d6f58872483db9b64ac54df3fcf5c7Raphael Moll                    IExactApiLevelDependency.API_LEVEL_INVALID,
126b45a6db526d6f58872483db9b64ac54df3fcf5c7Raphael Moll                    archiveOsPath);
12776e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll            return ba;
12876e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll        }
12976e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll
13076e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll
13176e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll        return ptp;
13276e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll    }
13376e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll
13476e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll    @VisibleForTesting(visibility=Visibility.PRIVATE)
13576e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll    protected PlatformToolPackage(
13676e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll                SdkSource source,
13776e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll                Properties props,
13876e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll                int revision,
13976e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll                String license,
14076e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll                String description,
14176e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll                String descUrl,
14276e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll                Os archiveOs,
14376e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll                Arch archiveArch,
14476e96b795add2dd4a1904ff4b67de25dfadf0c21Raphael Moll                String archiveOsPath) {
1452c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll        super(source,
1462c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll                props,
1472c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll                revision,
1482c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll                license,
1492c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll                description,
1502c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll                descUrl,
1512c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll                archiveOs,
1522c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll                archiveArch,
1532c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll                archiveOsPath);
1542c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll    }
1552c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll
156522bf59d4426c6b36f93fa244a58f68b9405578cRaphael Moll    /**
1572c4c6561c01683bda2681a1449e6a3c0915e5d6aRaphael     * Returns a string identifier to install this package from the command line.
15887107c5cb1fb5fdafdaa94460fb6797af60fcde9Raphael Moll     * For platform-tools, we use "platform-tools" or "platform-tools-preview" since
15987107c5cb1fb5fdafdaa94460fb6797af60fcde9Raphael Moll     * this package type is unique.
1602c4c6561c01683bda2681a1449e6a3c0915e5d6aRaphael     * <p/>
1612c4c6561c01683bda2681a1449e6a3c0915e5d6aRaphael     * {@inheritDoc}
1622c4c6561c01683bda2681a1449e6a3c0915e5d6aRaphael     */
1632c4c6561c01683bda2681a1449e6a3c0915e5d6aRaphael    @Override
1642c4c6561c01683bda2681a1449e6a3c0915e5d6aRaphael    public String installId() {
16587107c5cb1fb5fdafdaa94460fb6797af60fcde9Raphael Moll        if (getRevision().isPreview()) {
16687107c5cb1fb5fdafdaa94460fb6797af60fcde9Raphael Moll            return INSTALL_ID_PREVIEW;
16787107c5cb1fb5fdafdaa94460fb6797af60fcde9Raphael Moll        } else {
16887107c5cb1fb5fdafdaa94460fb6797af60fcde9Raphael Moll            return INSTALL_ID;
16987107c5cb1fb5fdafdaa94460fb6797af60fcde9Raphael Moll        }
1702c4c6561c01683bda2681a1449e6a3c0915e5d6aRaphael    }
1712c4c6561c01683bda2681a1449e6a3c0915e5d6aRaphael
1722c4c6561c01683bda2681a1449e6a3c0915e5d6aRaphael    /**
173522bf59d4426c6b36f93fa244a58f68b9405578cRaphael Moll     * Returns a description of this package that is suitable for a list display.
174522bf59d4426c6b36f93fa244a58f68b9405578cRaphael Moll     * <p/>
175522bf59d4426c6b36f93fa244a58f68b9405578cRaphael Moll     * {@inheritDoc}
176522bf59d4426c6b36f93fa244a58f68b9405578cRaphael Moll     */
177522bf59d4426c6b36f93fa244a58f68b9405578cRaphael Moll    @Override
178522bf59d4426c6b36f93fa244a58f68b9405578cRaphael Moll    public String getListDescription() {
179522bf59d4426c6b36f93fa244a58f68b9405578cRaphael Moll        return String.format("Android SDK Platform-tools%1$s",
180522bf59d4426c6b36f93fa244a58f68b9405578cRaphael Moll                isObsolete() ? " (Obsolete)" : "");
181522bf59d4426c6b36f93fa244a58f68b9405578cRaphael Moll    }
182522bf59d4426c6b36f93fa244a58f68b9405578cRaphael Moll
183522bf59d4426c6b36f93fa244a58f68b9405578cRaphael Moll    /**
184522bf59d4426c6b36f93fa244a58f68b9405578cRaphael Moll     * Returns a short description for an {@link IDescription}.
185522bf59d4426c6b36f93fa244a58f68b9405578cRaphael Moll     */
1862c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll    @Override
1872c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll    public String getShortDescription() {
1880c6def5d3f0d611bca7dbb7c2b773cd1664ec390Raphael Moll        return String.format("Android SDK Platform-tools, revision %1$s%2$s",
18987107c5cb1fb5fdafdaa94460fb6797af60fcde9Raphael Moll                getRevision().toShortString(),
1902c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll                isObsolete() ? " (Obsolete)" : "");
1912c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll    }
1922c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll
1932c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll    /** Returns a long description for an {@link IDescription}. */
1942c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll    @Override
1952c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll    public String getLongDescription() {
1962c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll        String s = getDescription();
1972c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll        if (s == null || s.length() == 0) {
1982c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll            s = getShortDescription();
1992c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll        }
2002c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll
2012c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll        if (s.indexOf("revision") == -1) {
2020c6def5d3f0d611bca7dbb7c2b773cd1664ec390Raphael Moll            s += String.format("\nRevision %1$s%2$s",
20387107c5cb1fb5fdafdaa94460fb6797af60fcde9Raphael Moll                    getRevision().toShortString(),
2042c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll                    isObsolete() ? " (Obsolete)" : "");
2052c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll        }
2062c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll
2072c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll        return s;
2082c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll    }
2092c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll
2102c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll    /**
2112c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll     * Computes a potential installation folder if an archive of this package were
2122c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll     * to be installed right away in the given SDK root.
2132c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll     * <p/>
2142c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll     * A "tool" package should always be located in SDK/tools.
2152c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll     *
2162c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll     * @param osSdkRoot The OS path of the SDK root folder.
2172c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll     * @param sdkManager An existing SDK manager to list current platforms and addons.
2182c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll     * @return A new {@link File} corresponding to the directory to use to install this package.
2192c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll     */
2202c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll    @Override
2212b53c912359ac3016f20b7b19cf893acbddb82ccRaphael Moll    public File getInstallFolder(String osSdkRoot, SdkManager sdkManager) {
2222c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll        return new File(osSdkRoot, SdkConstants.FD_PLATFORM_TOOLS);
2232c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll    }
2242c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll
22587107c5cb1fb5fdafdaa94460fb6797af60fcde9Raphael Moll    /**
22687107c5cb1fb5fdafdaa94460fb6797af60fcde9Raphael Moll     * Check whether 2 platform-tool packages are the same <em>and</em> have the
22787107c5cb1fb5fdafdaa94460fb6797af60fcde9Raphael Moll     * same preview bit.
22887107c5cb1fb5fdafdaa94460fb6797af60fcde9Raphael Moll     */
2292c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll    @Override
2302c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll    public boolean sameItemAs(Package pkg) {
23187107c5cb1fb5fdafdaa94460fb6797af60fcde9Raphael Moll        return sameItemAs(pkg, false /*ignorePreviews*/);
23287107c5cb1fb5fdafdaa94460fb6797af60fcde9Raphael Moll    }
23387107c5cb1fb5fdafdaa94460fb6797af60fcde9Raphael Moll
23487107c5cb1fb5fdafdaa94460fb6797af60fcde9Raphael Moll    @Override
23587107c5cb1fb5fdafdaa94460fb6797af60fcde9Raphael Moll    public boolean sameItemAs(Package pkg, boolean ignorePreviews) {
2362c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll        // only one platform-tool package so any platform-tool package is the same item.
23787107c5cb1fb5fdafdaa94460fb6797af60fcde9Raphael Moll        if (pkg instanceof PlatformToolPackage) {
23887107c5cb1fb5fdafdaa94460fb6797af60fcde9Raphael Moll            if (ignorePreviews) {
23987107c5cb1fb5fdafdaa94460fb6797af60fcde9Raphael Moll                return true;
24087107c5cb1fb5fdafdaa94460fb6797af60fcde9Raphael Moll            } else {
24187107c5cb1fb5fdafdaa94460fb6797af60fcde9Raphael Moll                // however previews can only match previews by default, unless we ignore that check.
24287107c5cb1fb5fdafdaa94460fb6797af60fcde9Raphael Moll                return ((PlatformToolPackage) pkg).getRevision().isPreview() ==
24387107c5cb1fb5fdafdaa94460fb6797af60fcde9Raphael Moll                    getRevision().isPreview();
24487107c5cb1fb5fdafdaa94460fb6797af60fcde9Raphael Moll            }
24587107c5cb1fb5fdafdaa94460fb6797af60fcde9Raphael Moll        }
24687107c5cb1fb5fdafdaa94460fb6797af60fcde9Raphael Moll        return false;
2472c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll    }
2482c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll
2492b53c912359ac3016f20b7b19cf893acbddb82ccRaphael Moll    /**
2502b53c912359ac3016f20b7b19cf893acbddb82ccRaphael Moll     * Hook called right before an archive is installed.
2512b53c912359ac3016f20b7b19cf893acbddb82ccRaphael Moll     * This is used here to stop ADB before trying to replace the platform-tool package.
2522b53c912359ac3016f20b7b19cf893acbddb82ccRaphael Moll     *
2532b53c912359ac3016f20b7b19cf893acbddb82ccRaphael Moll     * @param archive The archive that will be installed
2542b53c912359ac3016f20b7b19cf893acbddb82ccRaphael Moll     * @param monitor The {@link ITaskMonitor} to display errors.
2552b53c912359ac3016f20b7b19cf893acbddb82ccRaphael Moll     * @param osSdkRoot The OS path of the SDK root folder.
2562b53c912359ac3016f20b7b19cf893acbddb82ccRaphael Moll     * @param installFolder The folder where the archive will be installed. Note that this
2572b53c912359ac3016f20b7b19cf893acbddb82ccRaphael Moll     *                      is <em>not</em> the folder where the archive was temporary
2582b53c912359ac3016f20b7b19cf893acbddb82ccRaphael Moll     *                      unzipped. The installFolder, if it exists, contains the old
2592b53c912359ac3016f20b7b19cf893acbddb82ccRaphael Moll     *                      archive that will soon be replaced by the new one.
2602b53c912359ac3016f20b7b19cf893acbddb82ccRaphael Moll     * @return True if installing this archive shall continue, false if it should be skipped.
2612b53c912359ac3016f20b7b19cf893acbddb82ccRaphael Moll     */
2622b53c912359ac3016f20b7b19cf893acbddb82ccRaphael Moll    @Override
2632b53c912359ac3016f20b7b19cf893acbddb82ccRaphael Moll    public boolean preInstallHook(Archive archive, ITaskMonitor monitor,
2642b53c912359ac3016f20b7b19cf893acbddb82ccRaphael Moll            String osSdkRoot, File installFolder) {
2652b53c912359ac3016f20b7b19cf893acbddb82ccRaphael Moll        AdbWrapper aw = new AdbWrapper(osSdkRoot, monitor);
2662b53c912359ac3016f20b7b19cf893acbddb82ccRaphael Moll        aw.stopAdb();
2672b53c912359ac3016f20b7b19cf893acbddb82ccRaphael Moll        return super.preInstallHook(archive, monitor, osSdkRoot, installFolder);
2682b53c912359ac3016f20b7b19cf893acbddb82ccRaphael Moll    }
2692b53c912359ac3016f20b7b19cf893acbddb82ccRaphael Moll
2702c334d5dac7993cb3c7492b8cc1dacf2264b8306Raphael Moll}
271