From 1bda9627c9d27a0c14d5fa1dc06946a36518a630 Mon Sep 17 00:00:00 2001 From: Raphael Moll Date: Thu, 11 Aug 2011 22:03:43 -0700 Subject: [PATCH] Cleanup a few warnings in SdkLib. Change-Id: Ie8429f077b7e3a2a7166b6fcd7b9454c9bc47088 --- .../src/com/android/sdklib/build/ApkBuilder.java | 11 ++++----- .../sdklib/internal/build/DebugKeyProvider.java | 2 ++ .../sdklib/internal/build/KeystoreHelper.java | 21 +++++++++-------- .../internal/export/MultiApkExportHelper.java | 26 +++++++++++++++------- .../sdklib/internal/export/ProjectConfig.java | 4 ++-- .../sdklib/internal/project/ProjectCreator.java | 5 ++++- .../com/android/sdklib/xml/AndroidManifest.java | 2 +- .../android/sdklib/xml/AndroidManifestParser.java | 20 ++++++++--------- .../src/com/android/sdklib/xml/ManifestData.java | 25 ++++++++++++++++----- .../internal/build/DebugKeyProviderTest.java | 1 - 10 files changed, 73 insertions(+), 44 deletions(-) diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/build/ApkBuilder.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/build/ApkBuilder.java index 390474336..2148ccf0b 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/build/ApkBuilder.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/build/ApkBuilder.java @@ -721,14 +721,15 @@ public final class ApkBuilder { } /** - * Processes a {@link File} that could be a {@link ApkFile}, or a folder containing + * Processes a {@link File} that could be an APK {@link File}, or a folder containing * java resources. + * * @param file the {@link File} to process. - * @param path the relative path of this file to the source folder. Can be null to - * identify a root file. + * @param path the relative path of this file to the source folder. + * Can be null to identify a root file. * @throws IOException - * @throws DuplicateFileException if a file conflicts with another already added to the APK - * at the same location inside the APK archive. + * @throws DuplicateFileException if a file conflicts with another already added + * to the APK at the same location inside the APK archive. */ private void processFileForResource(File file, String path) throws IOException, DuplicateFileException { diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/build/DebugKeyProvider.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/build/DebugKeyProvider.java index d31414ca7..1b090b9ac 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/build/DebugKeyProvider.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/build/DebugKeyProvider.java @@ -129,6 +129,7 @@ public class DebugKeyProvider { * Returns the debug {@link PrivateKey} to use to sign applications for debug purpose. * @return the private key or null if its creation failed. */ + @SuppressWarnings("unused") // the thrown Exceptions are not actually thrown public PrivateKey getDebugKey() throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException, UnrecoverableEntryException { if (mEntry != null) { @@ -142,6 +143,7 @@ public class DebugKeyProvider { * Returns the debug {@link Certificate} to use to sign applications for debug purpose. * @return the certificate or null if its creation failed. */ + @SuppressWarnings("unused") // the thrown Exceptions are not actually thrown public Certificate getCertificate() throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException, UnrecoverableEntryException { if (mEntry != null) { diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/build/KeystoreHelper.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/build/KeystoreHelper.java index 44557640a..d76951026 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/build/KeystoreHelper.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/build/KeystoreHelper.java @@ -59,7 +59,7 @@ public final class KeystoreHelper { IKeyGenOutput output) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, UnrecoverableEntryException, IOException, KeytoolException { - + // get the executable name of keytool depending on the platform. String os = System.getProperty("os.name"); @@ -73,9 +73,9 @@ public final class KeystoreHelper { String javaHome = System.getProperty("java.home"); if (javaHome != null && javaHome.length() > 0) { - keytoolCommand = javaHome + File.separator + "bin" + File.separator + keytoolCommand; + keytoolCommand = javaHome + File.separator + "bin" + File.separator + keytoolCommand; } - + // create the command line to call key tool to build the key with no user input. ArrayList commandList = new ArrayList(); commandList.add(keytoolCommand); @@ -111,41 +111,40 @@ public final class KeystoreHelper { boolean firstArg = true; for (String arg : commandArray) { boolean hasSpace = arg.indexOf(' ') != -1; - + if (firstArg == true) { firstArg = false; } else { builder.append(' '); } - + if (hasSpace) { builder.append('"'); } - + builder.append(arg); if (hasSpace) { builder.append('"'); } } - + throw new KeytoolException("Failed to create key: " + e.getMessage(), javaHome, builder.toString()); } - + if (result != 0) { return false; } - + return true; } - + /** * Get the stderr/stdout outputs of a process and return when the process is done. * Both must be read or the process will block on windows. * @param process The process to get the ouput from * @return the process return code. - * @throws InterruptedException */ private static int grabProcessOutput(final Process process, final IKeyGenOutput output) { // read the lines as they come. if null is returned, it's diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/export/MultiApkExportHelper.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/export/MultiApkExportHelper.java index f05e9a65d..be164eacb 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/export/MultiApkExportHelper.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/export/MultiApkExportHelper.java @@ -152,14 +152,20 @@ public class MultiApkExportHelper { /** * Returns the list of projects defined by the projectList string. + * * The projects are checked to be valid Android project and to represent a valid set * of projects for multi-apk export. - * If a project does not exist or is not valid, the method will throw a {@link BuildException}. + * + * If a project does not exist or is not valid, the method will throw a {@link ExportException}. + * * The string must be a list of paths, relative to the export project path (given to - * {@link #MultiApkExportHelper(String, String, int, Target)}), separated by the colon (':') - * character. The path separator is expected to be forward-slash ('/') on all platforms. - * @param projects the string containing all the relative paths to the projects. This is - * usually read from export.properties. + * {@link #MultiApkExportHelper(String, String, int, Target, PrintStream)}), + * separated by the colon (':') character. + * + * The path separator is expected to be forward-slash ('/') on all platforms. + * + * @param projectList the string containing all the relative paths to the projects. + * This is usually read from export.properties. * @throws ExportException */ public List getProjects(String projectList) throws ExportException { @@ -335,11 +341,12 @@ public class MultiApkExportHelper { /** * Checks a project for inclusion in the list of exported APK. - *

This performs a check on the manifest, as well as gathers more information about + *

+ * This performs a check on the manifest, as well as gathers more information about * mutli-apk from the project's default.properties file. * If the manifest is correct, a list of apk to export is created and returned. * - * @param projectFolder the folder of the project to check + * @param relativePath the folder of the project to check * @param projects the list of project to file with the project if it passes validation. * @throws ExportException in case of error. */ @@ -486,9 +493,12 @@ public class MultiApkExportHelper { /** * Checks an existing list of {@link ProjectConfig} versus a config file. + * This does not return any value. It however throws an {@link ExportException} in + * case of error which some descriptive message. + * * @param projects the list of projects to check * @param configProp the config file (must have been generated from a previous export) - * @return true if the projects and config file match + * * @throws ExportException in case of error */ private void compareProjectsToConfigFile(List projects, File configProp) diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/export/ProjectConfig.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/export/ProjectConfig.java index 8f6fcc0b8..5d3ef93c9 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/export/ProjectConfig.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/export/ProjectConfig.java @@ -205,7 +205,6 @@ public final class ProjectConfig { /** * Finds ABIs in a project folder. This is based on the presence of libs// folder. * - * @param projectPath The OS path of the project. * @return A new non-null, possibly empty, list of ABI strings. */ private List findAbis() { @@ -270,7 +269,8 @@ public final class ProjectConfig { /** * Compares the current project config to a list of properties. - * These properties are in the format output by {@link #getConfigString()}. + * These properties are in the format output by {@link #getConfigString(boolean)}. + * * @param values the properties to compare to. * @return null if the properties exactly match the current config, an error message otherwise */ diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/project/ProjectCreator.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/project/ProjectCreator.java index 7840b9126..8db958789 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/project/ProjectCreator.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/project/ProjectCreator.java @@ -516,9 +516,10 @@ public class ProjectCreator { } if (libraryPath != null) { - // at this point, the default properties already exists, either because they were + // At this point, the default properties already exists, either because they were // already there or because they were created with a new target if (propsWC == null) { + assert props != null; propsWC = props.makeWorkingCopy(); } @@ -549,6 +550,7 @@ public class ProjectCreator { int index = 1; while (true) { String propName = ProjectProperties.PROPERTY_LIB_REF + Integer.toString(index); + assert props != null; String ref = props.getProperty(propName); if (ref == null) { break; @@ -565,6 +567,7 @@ public class ProjectCreator { // save the default props if needed. if (saveDefaultProps) { try { + assert propsWC != null; propsWC.save(); println("Updated %1$s", PropertyType.DEFAULT.getFilename()); } catch (Exception e) { diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifest.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifest.java index 26fcd7bfb..93cd211a1 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifest.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifest.java @@ -81,7 +81,7 @@ public final class AndroidManifest { /** * Returns an {@link IAbstractFile} object representing the manifest for the given project. * - * @param project The project containing the manifest file. + * @param projectFolder The project containing the manifest file. * @return An IAbstractFile object pointing to the manifest or null if the manifest * is missing. */ diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifestParser.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifestParser.java index ca59a8ed1..9590dc39c 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifestParser.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifestParser.java @@ -60,15 +60,14 @@ public class AndroidManifestParser { public interface ManifestErrorHandler extends ErrorHandler { /** * Handles a parsing error and an optional line number. - * @param exception - * @param lineNumber */ void handleError(Exception exception, int lineNumber); /** * Checks that a class is valid and can be used in the Android Manifest. *

- * Errors are put as {@link IMarker} on the manifest file. + * Errors are put as {@code org.eclipse.core.resources.IMarker} on the manifest file. + * * @param locator * @param className the fully qualified name of the class to test. * @param superClassName the fully qualified name of the class it is supposed to extend. @@ -99,10 +98,8 @@ public class AndroidManifestParser { * Creates a new {@link ManifestHandler}. * * @param manifestFile The manifest file being parsed. Can be null. - * @param errorListener An optional error listener. - * @param gatherData True if data should be gathered. - * @param javaProject The java project holding the manifest file. Can be null. - * @param markErrors True if errors should be marked as Eclipse Markers on the resource. + * @param manifestData Class containing the manifest info obtained during the parsing. + * @param errorHandler An optional error handler. */ ManifestHandler(IAbstractFile manifestFile, ManifestData manifestData, ManifestErrorHandler errorHandler) { @@ -584,7 +581,8 @@ public class AndroidManifestParser { * @param gatherData indicates whether the parsing will extract data from the manifest. If false * the method will always return null. * @param errorHandler an optional errorHandler. - * @return + * @return A class containing the manifest info obtained during the parsing, or null on error. + * * @throws StreamException * @throws IOException * @throws SAXException @@ -594,7 +592,7 @@ public class AndroidManifestParser { IAbstractFile manifestFile, boolean gatherData, ManifestErrorHandler errorHandler) - throws SAXException, IOException, StreamException, ParserConfigurationException { + throws SAXException, IOException, StreamException, ParserConfigurationException { if (manifestFile != null) { SAXParser parser = sParserFactory.newSAXParser(); @@ -620,6 +618,7 @@ public class AndroidManifestParser { * This is the equivalent of calling

parse(manifestFile, true, null)
* * @param manifestFile the manifest file to parse. + * * @throws ParserConfigurationException * @throws StreamException * @throws IOException @@ -645,7 +644,8 @@ public class AndroidManifestParser { * object containing the result of the parsing. * * @param manifestFileStream the {@link InputStream} representing the manifest file. - * @return + * @return A class containing the manifest info obtained during the parsing or null on error. + * * @throws StreamException * @throws IOException * @throws SAXException diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/ManifestData.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/ManifestData.java index c4b8c0fee..501a23778 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/ManifestData.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/ManifestData.java @@ -294,20 +294,35 @@ public final class ManifestData { @Override public boolean equals(Object obj) { if (obj instanceof SupportsScreens) { - SupportsScreens support = (SupportsScreens)obj; + SupportsScreens support = (SupportsScreens) obj; // since all the fields are guaranteed to be either Boolean.TRUE or Boolean.FALSE // (or null), we can simply check they are identical and not bother with // calling equals (which would require to check != null. // see #getConstanntBoolean(Boolean) - return mResizeable == support.mResizeable && mAnyDensity == support.mAnyDensity && - mSmallScreens == support.mSmallScreens && - mNormalScreens == support.mNormalScreens && - mLargeScreens == support.mLargeScreens; + return mResizeable == support.mResizeable && + mAnyDensity == support.mAnyDensity && + mSmallScreens == support.mSmallScreens && + mNormalScreens == support.mNormalScreens && + mLargeScreens == support.mLargeScreens; } return false; } + /* Override hashCode, mostly to make Eclipse happy and not warn about it. + * And if you ever put this in a Map or Set, it will avoid surprises. */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((mAnyDensity == null) ? 0 : mAnyDensity.hashCode()); + result = prime * result + ((mLargeScreens == null) ? 0 : mLargeScreens.hashCode()); + result = prime * result + ((mNormalScreens == null) ? 0 : mNormalScreens.hashCode()); + result = prime * result + ((mResizeable == null) ? 0 : mResizeable.hashCode()); + result = prime * result + ((mSmallScreens == null) ? 0 : mSmallScreens.hashCode()); + return result; + } + /** * Returns true if the two instances support the same screen sizes. * This is similar to {@link #equals(Object)} except that it ignores the values of diff --git a/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/build/DebugKeyProviderTest.java b/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/build/DebugKeyProviderTest.java index 6f6896e26..f6809093a 100755 --- a/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/build/DebugKeyProviderTest.java +++ b/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/build/DebugKeyProviderTest.java @@ -22,7 +22,6 @@ import java.io.File; import java.security.PrivateKey; import java.security.cert.X509Certificate; import java.util.Calendar; -import java.util.Date; import junit.framework.TestCase; -- 2.11.0