################################################################################
# The MIT License (MIT)
#
# Copyright (c) 2007-2018 Broad Institute
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
################################################################################

-dontoptimize
-dontobfuscate
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,LocalVariable*Table,*Annotation*,Synthetic,EnclosingMethod

# Suppress notes and warnings coming from the various libraries.
-dontnote org.apache.**,org.broadinstitute.gatk.**,org.ibex.**,org.jdesktop.**,org.sqlite.**
-dontnote apple.dts.**,com.google.**,com.jidesoft.**,com.mysql.**,htsjdk.**,picard.**
-dontnote oracle.**
-dontwarn org.apache.**,org.broadinstitute.gatk.**,org.ibex.**,org.jfree.**,org.jgrapht.**,org.xerial.**
-dontwarn com.google.**,com.jidesoft.**,com.mysql.**,com.thoughtworks.**,edu.cornell.**,htsjdk.**,it.unimi.**,picard.**
-dontwarn oracle.**,com.sun.**,javax.**,sun.util.**

# Keep the client & tools main classes; these are our key roots
-keep,includedescriptorclasses class org.broad.igv.ui.Main,org.broad.igv.tools.IgvTools {
    public static void main(java.lang.String[]);
}

# This is a more conservative rule: keep all of our code.  This is probably unnecessary; the unoptimized
# igv-minimal.jar is already available for users who would want this.  
#-keep,includedescriptorclasses class org.broad.** {
#    *;
#}

# Suppress note about reflection in our plugin mechanism as the referenced classes aren't present in the class path.
## NOTE: if there are any such classes they should be added in -keep or similar directives
# THESE RULES SHOULD BE REMOVED IF THE GIVEN REFLECTION CALLS ARE REMOVED
-dontnote org.broad.igv.cli_plugin.PluginSource

# Suppress notes about reflection in FileDialogUtils.  It can probably be refactored to avoid these.
-dontnote org.broad.igv.ui.util.FileDialogUtils

# Suppress note about reflection in SnapshotUtilities.  It can probably be refactored to avoid this.
-dontnote org.broad.igv.ui.util.SnapshotUtilities

# Suppress notes about reflection in RuntimeUtils.  
## NOTE: any classes used by this should be added in -keep or similar directives
-dontnote org.broad.igv.util.RuntimeUtils

# Preserve all .class method names.
-keepclassmembernames class * { 
    java.lang.Class class$(java.lang.String);
    java.lang.Class class$(java.lang.String, boolean);
}

# Also keep - constants that might be inlined by the Java compiler
-keepclassmembers class * {
    static final % *;
    static final java.lang.String *;
}

## The items below come from ProGuard tips and may not apply to IGV.
## Being conservative here for safety.  Test more carefully some day...

# Also keep - Enumerations. Keep the special static methods that are required in
# enumeration classes.
-keepclassmembers enum  * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

# Also keep - Serialization code. Keep all fields and methods that are used for
# serialization.
-keepclassmembers class * extends java.io.Serializable {
    static final long serialVersionUID;
    static final java.io.ObjectStreamField[] serialPersistentFields;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}

# Also keep - Database drivers. Keep all implementations of java.sql.Driver.
-keep class * extends java.sql.Driver

# Also keep - Swing UI L&F. Keep all extensions of javax.swing.plaf.ComponentUI,
# along with the special 'createUI' method.
-keep class * extends javax.swing.plaf.ComponentUI {
    public static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent);
}

# Keep names - Native method names. Keep all native class/method names.
-keepclasseswithmembers,includedescriptorclasses class * {
    native <methods>;
}
