diff options
13 files changed, 86 insertions, 59 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/RenderService.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/RenderService.java index 170e27d..0669f9e 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/RenderService.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/RenderService.java @@ -113,7 +113,9 @@ public class RenderService { Configuration config = chooser.getConfiguration(); FolderConfiguration folderConfig = config.getFullConfig(); - mHardwareConfigHelper = new HardwareConfigHelper(config.getDevice()); + Device device = config.getDevice(); + assert device != null; // Should only attempt render with configuration that has device + mHardwareConfigHelper = new HardwareConfigHelper(device); mHardwareConfigHelper.setOrientation( folderConfig.getScreenOrientationQualifier().getValue()); diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gre/ViewMetadataRepository.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gre/ViewMetadataRepository.java index 9768f51..5f2659e 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gre/ViewMetadataRepository.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gre/ViewMetadataRepository.java @@ -199,6 +199,7 @@ public class ViewMetadataRepository { } /** Returns an ordered list of categories and views, parsed from a metadata file */ + @SuppressWarnings("resource") // streams passed to parser InputSource closed by parser private List<CategoryData> getCategories() { if (mCategories == null) { mCategories = new ArrayList<CategoryData>(); diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/AndroidJarLoader.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/AndroidJarLoader.java index 161d567..c4eb37f 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/AndroidJarLoader.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/AndroidJarLoader.java @@ -17,6 +17,7 @@ package com.android.ide.eclipse.adt.internal.sdk; import com.android.SdkConstants; +import com.google.common.io.Closeables; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.SubMonitor; @@ -205,6 +206,7 @@ public class AndroidJarLoader extends ClassLoader implements IAndroidClassLoader * @throws InvalidAttributeValueException * @throws ClassFormatError */ + @SuppressWarnings("resource") // Eclipse doesn't understand Closeables.closeQuietly @Override public HashMap<String, ArrayList<IClassDescriptor>> findClassesDerivingFrom( String packageFilter, @@ -223,43 +225,47 @@ public class AndroidJarLoader extends ClassLoader implements IAndroidClassLoader // create streams to read the intermediary archive FileInputStream fis = new FileInputStream(mOsFrameworkLocation); ZipInputStream zis = new ZipInputStream(fis); - ZipEntry entry; - while ((entry = zis.getNextEntry()) != null) { - // get the name of the entry and convert to a class binary name - String entryPath = entry.getName(); - if (!entryPath.endsWith(SdkConstants.DOT_CLASS)) { - // only accept class files - continue; - } - if (packageFilter.length() > 0 && !entryPath.startsWith(packageFilter)) { - // only accept stuff from the requested root package. - continue; - } - String className = entryPathToClassName(entryPath); - - Class<?> loaded_class = mClassCache.get(className); - if (loaded_class == null) { - byte[] data = mEntryCache.get(className); - if (data == null) { - // Get the class and cache it - long entrySize = entry.getSize(); - if (entrySize > Integer.MAX_VALUE) { - throw new InvalidAttributeValueException(); + try { + ZipEntry entry; + while ((entry = zis.getNextEntry()) != null) { + // get the name of the entry and convert to a class binary name + String entryPath = entry.getName(); + if (!entryPath.endsWith(SdkConstants.DOT_CLASS)) { + // only accept class files + continue; + } + if (packageFilter.length() > 0 && !entryPath.startsWith(packageFilter)) { + // only accept stuff from the requested root package. + continue; + } + String className = entryPathToClassName(entryPath); + + Class<?> loaded_class = mClassCache.get(className); + if (loaded_class == null) { + byte[] data = mEntryCache.get(className); + if (data == null) { + // Get the class and cache it + long entrySize = entry.getSize(); + if (entrySize > Integer.MAX_VALUE) { + throw new InvalidAttributeValueException(); + } + data = readZipData(zis, (int)entrySize); } - data = readZipData(zis, (int)entrySize); + loaded_class = defineAndCacheClass(className, data); } - loaded_class = defineAndCacheClass(className, data); - } - for (Class<?> superClass = loaded_class.getSuperclass(); - superClass != null; - superClass = superClass.getSuperclass()) { - String superName = superClass.getCanonicalName(); - if (mClassesFound.containsKey(superName)) { - mClassesFound.get(superName).add(new ClassWrapper(loaded_class)); - break; + for (Class<?> superClass = loaded_class.getSuperclass(); + superClass != null; + superClass = superClass.getSuperclass()) { + String superName = superClass.getCanonicalName(); + if (mClassesFound.containsKey(superName)) { + mClassesFound.get(superName).add(new ClassWrapper(loaded_class)); + break; + } } } + } finally { + Closeables.closeQuietly(zis); } return mClassesFound; diff --git a/manifmerger/src/com/android/manifmerger/MergerXmlUtils.java b/manifmerger/src/com/android/manifmerger/MergerXmlUtils.java index 4381479..bb60464 100755 --- a/manifmerger/src/com/android/manifmerger/MergerXmlUtils.java +++ b/manifmerger/src/com/android/manifmerger/MergerXmlUtils.java @@ -32,9 +32,11 @@ import org.xml.sax.ErrorHandler; import org.xml.sax.InputSource; import org.xml.sax.SAXParseException; +import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; +import java.io.Reader; import java.io.StringReader; import java.io.StringWriter; import java.util.ArrayList; @@ -80,7 +82,8 @@ class MergerXmlUtils { static Document parseDocument(@NonNull final File xmlFile, @NonNull final IMergerLog log) { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - InputSource is = new InputSource(new FileReader(xmlFile)); + Reader reader = new BufferedReader(new FileReader(xmlFile)); + InputSource is = new InputSource(reader); factory.setNamespaceAware(true); factory.setValidating(false); DocumentBuilder builder = factory.newDocumentBuilder(); diff --git a/sdk_common/.classpath b/sdk_common/.classpath index 342ab94..1afd216 100644 --- a/sdk_common/.classpath +++ b/sdk_common/.classpath @@ -4,6 +4,7 @@ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry combineaccessrules="false" kind="src" path="/layoutlib_api"/> <classpathentry kind="var" path="ANDROID_SRC/prebuilts/misc/common/kxml2/kxml2-2.3.0.jar" sourcepath="/ANDROID_SRC/dalvik/libcore/xml/src/main/java"/> + <classpathentry kind="var" path="ANDROID_SRC/prebuilts/tools/common/guava-tools/guava-13.0.1.jar" sourcepath="/ANDROID_SRC/prebuilts/tools/common/guava-tools/src.zip"/> <classpathentry combineaccessrules="false" kind="src" path="/common"/> <classpathentry combineaccessrules="false" kind="src" path="/SdkLib"/> <classpathentry kind="output" path="bin"/> diff --git a/sdk_common/Android.mk b/sdk_common/Android.mk index c3ff376..51c5919 100644 --- a/sdk_common/Android.mk +++ b/sdk_common/Android.mk @@ -22,6 +22,7 @@ LOCAL_JAVA_LIBRARIES := \ layoutlib_api \ common \ kxml2-2.3.0 \ + guava-tools \ sdklib LOCAL_MODULE := sdk_common diff --git a/sdk_common/src/com/android/ide/common/rendering/HardwareConfigHelper.java b/sdk_common/src/com/android/ide/common/rendering/HardwareConfigHelper.java index 79a6171..afca8fe 100644 --- a/sdk_common/src/com/android/ide/common/rendering/HardwareConfigHelper.java +++ b/sdk_common/src/com/android/ide/common/rendering/HardwareConfigHelper.java @@ -16,6 +16,7 @@ package com.android.ide.common.rendering; +import com.android.annotations.NonNull; import com.android.ide.common.rendering.api.HardwareConfig; import com.android.resources.ScreenOrientation; import com.android.sdklib.devices.ButtonType; @@ -34,8 +35,8 @@ import com.android.sdklib.devices.Screen; */ public class HardwareConfigHelper { - private final Device mDevice; - private ScreenOrientation mScreenOrientation = ScreenOrientation.PORTRAIT; + private final @NonNull Device mDevice; + private @NonNull ScreenOrientation mScreenOrientation = ScreenOrientation.PORTRAIT; // optional private int mMaxRenderWidth = -1; @@ -47,7 +48,7 @@ public class HardwareConfigHelper { * Creates a new helper for a given device. * @param device the device to provide the base data. */ - public HardwareConfigHelper(Device device) { + public HardwareConfigHelper(@NonNull Device device) { mDevice = device; } @@ -56,7 +57,8 @@ public class HardwareConfigHelper { * @param screenOrientation the orientation. * @return this (such that chains of setters can be stringed together) */ - public HardwareConfigHelper setOrientation(ScreenOrientation screenOrientation) { + @NonNull + public HardwareConfigHelper setOrientation(@NonNull ScreenOrientation screenOrientation) { mScreenOrientation = screenOrientation; return this; } @@ -71,6 +73,7 @@ public class HardwareConfigHelper { * @param overrideRenderHeight the height in pixels of the layout to be rendered * @return this (such that chains of setters can be stringed together) */ + @NonNull public HardwareConfigHelper setOverrideRenderSize(int overrideRenderWidth, int overrideRenderHeight) { mOverrideRenderWidth = overrideRenderWidth; @@ -88,6 +91,7 @@ public class HardwareConfigHelper { * @param maxRenderHeight the max height in pixels of the layout to be rendered * @return this (such that chains of setters can be stringed together) */ + @NonNull public HardwareConfigHelper setMaxRenderSize(int maxRenderWidth, int maxRenderHeight) { mMaxRenderWidth = maxRenderWidth; mMaxRenderHeight = maxRenderHeight; @@ -98,6 +102,7 @@ public class HardwareConfigHelper { * Creates and returns the HardwareConfig object. * @return the config */ + @NonNull public HardwareConfig getConfig() { Screen screen = mDevice.getDefaultHardware().getScreen(); 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 f5abe9e..d499feb 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/build/ApkBuilder.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/build/ApkBuilder.java @@ -538,6 +538,7 @@ public final class ApkBuilder implements IArchiveBuilder { // ask the builder to add the content of the file. FileInputStream fis = new FileInputStream(zipFile); mBuilder.writeZip(fis, mNullFilter); + fis.close(); } catch (DuplicateFileException e) { mBuilder.cleanUp(); throw e; @@ -573,6 +574,7 @@ public final class ApkBuilder implements IArchiveBuilder { // the java resources. FileInputStream fis = new FileInputStream(jarFile); mBuilder.writeZip(fis, mFilter); + fis.close(); // check if native libraries were found in the external library. This should // constitutes an error or warning depending on if they are in lib/ diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/build/SignedJarBuilder.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/build/SignedJarBuilder.java index 48f1b91..e676520 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/build/SignedJarBuilder.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/build/SignedJarBuilder.java @@ -260,7 +260,9 @@ public class SignedJarBuilder { Signature signature = Signature.getInstance("SHA1with" + mKey.getAlgorithm()); signature.initSign(mKey); mOutputJar.putNextEntry(new JarEntry("META-INF/CERT.SF")); - writeSignatureFile(new SignatureOutputStream(mOutputJar, signature)); + SignatureOutputStream out = new SignatureOutputStream(mOutputJar, signature); + writeSignatureFile(out); + out.close(); // CERT.* mOutputJar.putNextEntry(new JarEntry("META-INF/CERT." + mKey.getAlgorithm())); diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/project/ProjectProperties.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/project/ProjectProperties.java index 57e6190..301fb29 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/project/ProjectProperties.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/project/ProjectProperties.java @@ -24,6 +24,7 @@ import com.android.io.IAbstractFile; import com.android.io.IAbstractFolder; import com.android.io.StreamException; import com.android.utils.ILogger; +import com.google.common.io.Closeables; import java.io.BufferedReader; import java.io.FileNotFoundException; @@ -469,13 +470,7 @@ public class ProjectProperties implements IPropertySource { e.getMessage()); } } finally { - if (reader != null) { - try { - reader.close(); - } catch (IOException e) { - // pass - } - } + Closeables.closeQuietly(reader); } return null; diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/project/ProjectPropertiesWorkingCopy.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/project/ProjectPropertiesWorkingCopy.java index 21dcc36..0bb9bd6 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/project/ProjectPropertiesWorkingCopy.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/project/ProjectPropertiesWorkingCopy.java @@ -21,6 +21,7 @@ import com.android.annotations.NonNull; import com.android.io.IAbstractFile; import com.android.io.IAbstractFolder; import com.android.io.StreamException; +import com.google.common.io.Closeables; import java.io.BufferedReader; import java.io.ByteArrayOutputStream; @@ -32,6 +33,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; import java.util.regex.Matcher; /** @@ -140,7 +142,7 @@ public class ProjectPropertiesWorkingCopy extends ProjectProperties { // since we're reading the existing file and replacing values with new ones, or skipping // removed values, we need to record what properties have been visited, so that // we can figure later what new properties need to be added at the end of the file. - HashSet<String> visitedProps = new HashSet<String>(); + Set<String> visitedProps = new HashSet<String>(); String line = null; while ((line = reader.readLine()) != null) { @@ -193,6 +195,8 @@ public class ProjectPropertiesWorkingCopy extends ProjectProperties { } } + Closeables.closeQuietly(reader); + } else { // new file, just write it all @@ -216,6 +220,7 @@ public class ProjectPropertiesWorkingCopy extends ProjectProperties { OutputStream filestream = toSave.getOutputStream(); filestream.write(baos.toByteArray()); filestream.flush(); + filestream.close(); } private void writeValue(OutputStreamWriter writer, String key, String value, diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/io/FileOp.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/io/FileOp.java index 7bbe54f..f9793cc 100755 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/io/FileOp.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/io/FileOp.java @@ -18,6 +18,7 @@ package com.android.sdklib.io; import com.android.SdkConstants; import com.android.annotations.NonNull; +import com.google.common.io.Closeables; import java.io.File; import java.io.FileInputStream; @@ -346,6 +347,7 @@ public class FileOp implements IFileOp { return new FileOutputStream(file); } + @SuppressWarnings("resource") // Eclipse doesn't understand Closeables.closeQuietly @Override public @NonNull Properties loadProperties(@NonNull File file) { Properties props = new Properties(); @@ -355,15 +357,12 @@ public class FileOp implements IFileOp { props.load(fis); } catch (IOException ignore) { } finally { - if (fis != null) { - try { - fis.close(); - } catch (Exception ignore) {} - } + Closeables.closeQuietly(fis); } return props; } + @SuppressWarnings("resource") // Eclipse doesn't understand Closeables.closeQuietly @Override public boolean saveProperties(@NonNull File file, @NonNull Properties props, @NonNull String comments) { @@ -375,12 +374,7 @@ public class FileOp implements IFileOp { return true; } catch (IOException ignore) { } finally { - if (fos != null) { - try { - fos.close(); - } catch (IOException e) { - } - } + Closeables.closeQuietly(fos); } return false; diff --git a/sdkstats/src/com/android/sdkstats/DdmsPreferenceStore.java b/sdkstats/src/com/android/sdkstats/DdmsPreferenceStore.java index 2a34ded..890eae7 100755 --- a/sdkstats/src/com/android/sdkstats/DdmsPreferenceStore.java +++ b/sdkstats/src/com/android/sdkstats/DdmsPreferenceStore.java @@ -81,11 +81,13 @@ public class DdmsPreferenceStore { + File.separator + ".ddmsrc"; //$NON-NLS-1$ File oldPrefFile = new File(oldPrefPath); if (oldPrefFile.isFile()) { + FileOutputStream fileOutputStream = null; try { PreferenceStore oldStore = new PreferenceStore(oldPrefPath); oldStore.load(); - oldStore.save(new FileOutputStream(rcFileName), ""); //$NON-NLS-1$ + fileOutputStream = new FileOutputStream(rcFileName); + oldStore.save(fileOutputStream, ""); //$NON-NLS-1$ oldPrefFile.delete(); PreferenceStore newStore = new PreferenceStore(rcFileName); @@ -94,6 +96,14 @@ public class DdmsPreferenceStore { } catch (IOException e) { // create a new empty store. sPrefStore = new PreferenceStore(rcFileName); + } finally { + if (fileOutputStream != null) { + try { + fileOutputStream.close(); + } catch (IOException e) { + // pass + } + } } } else { sPrefStore = new PreferenceStore(rcFileName); |