├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── settings.gradle ├── src ├── main │ └── co │ │ └── tophe │ │ └── oembed │ │ ├── internal │ │ ├── OEmbedParser.java │ │ ├── OEmbedVimeo.java │ │ ├── OEmbedHulu.java │ │ ├── OEmbedViddler.java │ │ ├── OEmbedInstagram.java │ │ ├── OEmbedFunnyOrDie.java │ │ ├── OEmbedImgur.java │ │ ├── OEmbedParserWithPattern.java │ │ ├── OEmbedYoutube.java │ │ ├── OEmbedDailymotion.java │ │ ├── OEmbedRequestGet.java │ │ ├── BaseOEmbedSource.java │ │ └── OEmbedVine.java │ │ ├── OEmbedRequest.java │ │ ├── fallback │ │ ├── OEmbedEmbedly.java │ │ ├── OEmbedReembed.java │ │ └── OEmbedOohembed.java │ │ ├── OEmbedSource.java │ │ ├── OEmbed.java │ │ └── OEmbedFinder.java ├── test │ ├── src │ │ └── co │ │ │ └── tophe │ │ │ └── oembed │ │ │ ├── SourceTestIon.java │ │ │ ├── fallback │ │ │ ├── OEmbedReembedTest.java │ │ │ ├── OEmbedEmbedlyTest.java │ │ │ └── OEmbedOohembedTest.java │ │ │ ├── internal │ │ │ └── OEmbedSourceTest.java │ │ │ └── sourceTest.java │ ├── AndroidManifest.xml │ └── project.properties ├── AndroidManifest.xml ├── project.properties └── proguard-project.txt ├── .gitignore ├── gradle.properties ├── README.md ├── gradlew.bat └── gradlew /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/levelup/Android-oEmbed/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | // You need to put this in your /settings.gradle and adapt the folder location 2 | 3 | //include 'Android-oEmbed' 4 | //project(':Android-oEmbed').projectDir = new File('src') 5 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Jan 16 10:55:10 CET 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-bin.zip 7 | -------------------------------------------------------------------------------- /src/main/co/tophe/oembed/internal/OEmbedParser.java: -------------------------------------------------------------------------------- 1 | package co.tophe.oembed.internal; 2 | 3 | import android.net.Uri; 4 | import android.support.annotation.NonNull; 5 | 6 | import co.tophe.oembed.OEmbedSource; 7 | 8 | public interface OEmbedParser { 9 | OEmbedSource getSource(@NonNull Uri fromUri); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/co/tophe/oembed/OEmbedRequest.java: -------------------------------------------------------------------------------- 1 | package co.tophe.oembed; 2 | 3 | import co.tophe.ServerException; 4 | import co.tophe.TypedHttpRequest; 5 | 6 | /** 7 | * A TOPHE HTTP request that returns an {@link co.tophe.oembed.OEmbed} object. 8 | */ 9 | public interface OEmbedRequest extends TypedHttpRequest { 10 | } 11 | -------------------------------------------------------------------------------- /src/main/co/tophe/oembed/internal/OEmbedVimeo.java: -------------------------------------------------------------------------------- 1 | package co.tophe.oembed.internal; 2 | 3 | 4 | public class OEmbedVimeo extends OEmbedParserWithPattern { 5 | 6 | public static final OEmbedVimeo INSTANCE = new OEmbedVimeo(); 7 | 8 | private OEmbedVimeo() { 9 | super("http://vimeo.com/*", "http://vimeo.com/api/oembed.json"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/co/tophe/oembed/internal/OEmbedHulu.java: -------------------------------------------------------------------------------- 1 | package co.tophe.oembed.internal; 2 | 3 | public class OEmbedHulu extends OEmbedParserWithPattern { 4 | 5 | public static final OEmbedHulu INSTANCE = new OEmbedHulu(); 6 | 7 | private OEmbedHulu() { 8 | super("http://www.hulu.com/watch/*", "http://www.hulu.com/api/oembed.json"); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/co/tophe/oembed/internal/OEmbedViddler.java: -------------------------------------------------------------------------------- 1 | package co.tophe.oembed.internal; 2 | 3 | 4 | public class OEmbedViddler extends OEmbedParserWithPattern { 5 | 6 | public static final OEmbedViddler INSTANCE = new OEmbedViddler(); 7 | 8 | private OEmbedViddler() { 9 | super("http://www.viddler.com/v/*", "http://www.viddler.com/oembed/"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/co/tophe/oembed/internal/OEmbedInstagram.java: -------------------------------------------------------------------------------- 1 | package co.tophe.oembed.internal; 2 | 3 | 4 | public class OEmbedInstagram extends OEmbedParserWithPattern { 5 | 6 | public static final OEmbedInstagram INSTANCE = new OEmbedInstagram(); 7 | 8 | private OEmbedInstagram() { 9 | super("http://(instagram.com|instagr.am)/p/*", "http://api.instagram.com/oembed"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/co/tophe/oembed/internal/OEmbedFunnyOrDie.java: -------------------------------------------------------------------------------- 1 | package co.tophe.oembed.internal; 2 | 3 | public class OEmbedFunnyOrDie extends OEmbedParserWithPattern { 4 | 5 | public final static OEmbedFunnyOrDie INSTANCE = new OEmbedFunnyOrDie(); 6 | 7 | private OEmbedFunnyOrDie() { 8 | super("http://www.funnyordie.com/videos/*", "http://www.funnyordie.com/oembed.json"); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/test/src/co/tophe/oembed/SourceTestIon.java: -------------------------------------------------------------------------------- 1 | package co.tophe.oembed; 2 | 3 | import android.content.Context; 4 | 5 | import co.tophe.ion.IonClient; 6 | 7 | /** 8 | * @author Created by Steve Lhomme on 15/07/2014. 9 | */ 10 | public class SourceTestIon extends sourceTest { 11 | 12 | @Override 13 | public void setContext(Context context) { 14 | super.setContext(context); 15 | IonClient.setup(context); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # files for the dex VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # generated files 12 | bin/ 13 | gen/ 14 | 15 | # Local configuration file (sdk path, etc) 16 | local.properties 17 | 18 | # Eclipse project files 19 | .classpath 20 | .project 21 | .settings 22 | 23 | # IntelliJ IDEA 24 | .idea 25 | *.iml 26 | *.ipr 27 | *.iws 28 | classes 29 | gen-external-apklibs 30 | 31 | # Gradle 32 | .gradle 33 | build 34 | -------------------------------------------------------------------------------- /src/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/test/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/main/co/tophe/oembed/fallback/OEmbedEmbedly.java: -------------------------------------------------------------------------------- 1 | package co.tophe.oembed.fallback; 2 | 3 | import android.net.Uri; 4 | import android.support.annotation.NonNull; 5 | 6 | import co.tophe.oembed.internal.BaseOEmbedSource; 7 | 8 | /** 9 | * @author Created by robUx4 on 30/09/2014. 10 | */ 11 | public class OEmbedEmbedly extends BaseOEmbedSource { 12 | public OEmbedEmbedly(@NonNull Uri fromUri) { 13 | super("http://api.embed.ly/1/oembed", fromUri); 14 | } 15 | 16 | public OEmbedEmbedly(@NonNull String url) { 17 | this(Uri.parse(url)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/co/tophe/oembed/fallback/OEmbedReembed.java: -------------------------------------------------------------------------------- 1 | package co.tophe.oembed.fallback; 2 | 3 | import android.net.Uri; 4 | import android.support.annotation.NonNull; 5 | 6 | import co.tophe.oembed.internal.BaseOEmbedSource; 7 | 8 | /** 9 | * @author Created by robUx4 on 30/09/2014. 10 | */ 11 | public class OEmbedReembed extends BaseOEmbedSource { 12 | public OEmbedReembed(@NonNull Uri fromUri) { 13 | super("http://reembed.me/api/v1/oembed/", fromUri); 14 | } 15 | 16 | public OEmbedReembed(@NonNull String url) { 17 | this(Uri.parse(url)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/co/tophe/oembed/fallback/OEmbedOohembed.java: -------------------------------------------------------------------------------- 1 | package co.tophe.oembed.fallback; 2 | 3 | import android.net.Uri; 4 | import android.support.annotation.NonNull; 5 | 6 | import co.tophe.oembed.internal.BaseOEmbedSource; 7 | 8 | /** 9 | * @author Created by robUx4 on 30/09/2014. 10 | */ 11 | public class OEmbedOohembed extends BaseOEmbedSource { 12 | public OEmbedOohembed(@NonNull Uri fromUri) { 13 | super("http://www.oohembed.com/oohembed", fromUri); 14 | } 15 | 16 | public OEmbedOohembed(@NonNull String url) { 17 | this(Uri.parse(url)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/test/src/co/tophe/oembed/fallback/OEmbedReembedTest.java: -------------------------------------------------------------------------------- 1 | package co.tophe.oembed.fallback; 2 | 3 | import android.test.AndroidTestCase; 4 | 5 | public class OEmbedReembedTest extends AndroidTestCase { 6 | 7 | private void testOEmbedThumbnail(String url) throws Exception { 8 | OEmbedReembed dataSource = new OEmbedReembed(url); 9 | assertNotNull(dataSource); 10 | String thumbnail = dataSource.getThumbnail(); 11 | assertNotNull(thumbnail); 12 | } 13 | 14 | public void testAndroidCentral() throws Exception { 15 | testOEmbedThumbnail("http://www.androidcentral.com/ac-editors-apps-week-hacked-lux-ticket-ride-and-more"); 16 | } 17 | } -------------------------------------------------------------------------------- /src/test/src/co/tophe/oembed/fallback/OEmbedEmbedlyTest.java: -------------------------------------------------------------------------------- 1 | package co.tophe.oembed.fallback; 2 | 3 | import android.test.AndroidTestCase; 4 | 5 | public class OEmbedEmbedlyTest extends AndroidTestCase { 6 | 7 | private void testOEmbedThumbnail(String url) throws Exception { 8 | OEmbedEmbedly dataSource = new OEmbedEmbedly(url); 9 | assertNotNull(dataSource); 10 | String thumbnail = dataSource.getThumbnail(); 11 | assertNotNull(thumbnail); 12 | } 13 | 14 | public void testAndroidCentral() throws Exception { 15 | testOEmbedThumbnail("http://www.androidcentral.com/ac-editors-apps-week-hacked-lux-ticket-ride-and-more"); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /src/test/src/co/tophe/oembed/fallback/OEmbedOohembedTest.java: -------------------------------------------------------------------------------- 1 | package co.tophe.oembed.fallback; 2 | 3 | import android.test.AndroidTestCase; 4 | 5 | public class OEmbedOohembedTest extends AndroidTestCase { 6 | 7 | private void testOEmbedThumbnail(String url) throws Exception { 8 | OEmbedOohembed dataSource = new OEmbedOohembed(url); 9 | assertNotNull(dataSource); 10 | String thumbnail = dataSource.getThumbnail(); 11 | assertNotNull(thumbnail); 12 | } 13 | 14 | public void testAndroidCentral() throws Exception { 15 | testOEmbedThumbnail("http://www.androidcentral.com/ac-editors-apps-week-hacked-lux-ticket-ride-and-more"); 16 | } 17 | } -------------------------------------------------------------------------------- /src/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-19 15 | android.library=true 16 | android.library.reference.1=../../Tophe/Tophe 17 | -------------------------------------------------------------------------------- /src/test/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-19 15 | android.library.reference.1=.. 16 | android.library.reference.2=../../../Tophe/Tophe-Ion/src/main 17 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | POM_NAME=Android-oEmbed 2 | POM_DESCRIPTION=Android library to get OEmbed data from various sources 3 | GROUP=co.tophe 4 | POM_URL=https://github.com/levelup/Android-oEmbed 5 | POM_SCM_URL=https://github.com/levelup/Android-oEmbed 6 | POM_SCM_CONNECTION=scm:git@github.com:levelup/Android-oEmbed.git 7 | POM_SCM_DEV_CONNECTION=scm:git@github.com:levelup/Android-oEmbed.git 8 | POM_LICENCE_NAME=The Apache Software License, Version 2.0 9 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt 10 | POM_LICENCE_DIST=repo 11 | POM_DEVELOPER_ID=robux4 12 | POM_DEVELOPER_NAME=Steve Lhomme 13 | 14 | POM_ARTIFACT_ID=android-oembed 15 | POM_PACKAGING=jar 16 | VERSION_NAME=1.0.1 17 | VERSION_CODE=10001 18 | 19 | ANDROID_BUILD_TARGET_SDK_VERSION=21 20 | ANDROID_BUILD_SDK_VERSION=21 21 | ANDROID_BUILD_TOOLS_VERSION=21.1.2 22 | ANDROID_BUILD_MIN_SDK_VERSION=10 23 | -------------------------------------------------------------------------------- /src/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | 22 | -keepnames class co.tophe.oembed.** { *; } 23 | -------------------------------------------------------------------------------- /src/main/co/tophe/oembed/OEmbedSource.java: -------------------------------------------------------------------------------- 1 | package co.tophe.oembed; 2 | 3 | import android.support.annotation.NonNull; 4 | import android.support.annotation.Nullable; 5 | 6 | import co.tophe.HttpException; 7 | import co.tophe.ServerException; 8 | 9 | public interface OEmbedSource { 10 | 11 | /** 12 | * Get a picture representation of the URL. 13 | * 14 | * @return {@code null} if no picture was found to represent the source URL. 15 | * @throws ServerException when the OEmbed server sends an error response. 16 | * @throws HttpException for all issues processing the HTTP request not generated by the server. 17 | */ 18 | @Nullable 19 | String getThumbnail() throws ServerException, HttpException; 20 | 21 | /** 22 | * Create an {@link co.tophe.oembed.OEmbedRequest} that can be used with {@link co.tophe.TopheClient TopheClient} 23 | * or {@link co.tophe.async.AsyncTopheClient AsyncTopheClient} 24 | */ 25 | @NonNull 26 | OEmbedRequest createOembedRequest(); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/co/tophe/oembed/internal/OEmbedImgur.java: -------------------------------------------------------------------------------- 1 | package co.tophe.oembed.internal; 2 | 3 | import android.net.Uri; 4 | import android.support.annotation.NonNull; 5 | 6 | import co.tophe.oembed.OEmbedSource; 7 | 8 | public class OEmbedImgur implements OEmbedParser { 9 | 10 | public static final OEmbedImgur INSTANCE = new OEmbedImgur(); 11 | 12 | private OEmbedImgur() { 13 | } 14 | 15 | @Override 16 | public OEmbedSource getSource(@NonNull Uri fromUri) { 17 | if ("i.imgur.com".equalsIgnoreCase(fromUri.getHost())) { 18 | return new OEmbedSourceImgur(fromUri); 19 | } 20 | if ("imgur.com".equalsIgnoreCase(fromUri.getHost())) { 21 | if (!fromUri.getPath().startsWith("/a/")) { // albums are not supported (rich typed, rather than photo/video) 22 | return new OEmbedSourceImgur(fromUri); 23 | } 24 | } 25 | return null; 26 | } 27 | 28 | private static class OEmbedSourceImgur extends BaseOEmbedSource { 29 | OEmbedSourceImgur(@NonNull Uri fromUri) { 30 | super("http://api.imgur.com/oembed.json", fromUri); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/co/tophe/oembed/internal/OEmbedParserWithPattern.java: -------------------------------------------------------------------------------- 1 | package co.tophe.oembed.internal; 2 | 3 | import java.util.regex.Pattern; 4 | 5 | import android.net.Uri; 6 | import android.support.annotation.NonNull; 7 | 8 | public abstract class OEmbedParserWithPattern implements OEmbedParser { 9 | 10 | private final Pattern pattern; 11 | private final String endpoint; 12 | 13 | protected OEmbedParserWithPattern(@NonNull String pattern, @NonNull String endpoint) { 14 | if (null==pattern) throw new NullPointerException(); 15 | if (null==endpoint) throw new NullPointerException(); 16 | this.pattern = Pattern.compile(pattern); 17 | this.endpoint = endpoint; 18 | } 19 | 20 | @Override 21 | public OEmbedSource getSource(@NonNull Uri fromUri) { 22 | if (pattern.matcher(fromUri.toString()).find()) { 23 | return new OEmbedSource(fromUri); 24 | } 25 | return null; 26 | } 27 | 28 | private class OEmbedSource extends BaseOEmbedSource { 29 | public OEmbedSource(@NonNull Uri fromUri) { 30 | super(OEmbedParserWithPattern.this.endpoint, fromUri); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/co/tophe/oembed/internal/OEmbedYoutube.java: -------------------------------------------------------------------------------- 1 | package co.tophe.oembed.internal; 2 | 3 | import java.util.List; 4 | 5 | import android.net.Uri; 6 | import android.support.annotation.NonNull; 7 | 8 | import co.tophe.oembed.OEmbedSource; 9 | 10 | public class OEmbedYoutube implements OEmbedParser { 11 | 12 | public static final OEmbedYoutube INSTANCE = new OEmbedYoutube(); 13 | 14 | private OEmbedYoutube() { 15 | } 16 | 17 | @Override 18 | public OEmbedSource getSource(@NonNull Uri fromUri) { 19 | if (fromUri.getHost().equals("youtu.be")) { 20 | return new OEmbedSourceYoutube(fromUri); 21 | } 22 | if (fromUri.getHost().endsWith("youtube.com")) { 23 | List path = fromUri.getPathSegments(); 24 | if (path.size() > 1 && "embed".equals(path.get(0))) { 25 | fromUri = Uri.parse("http://www.youtube.com/watch?v=" + path.get(1)); 26 | } 27 | 28 | return new OEmbedSourceYoutube(fromUri); 29 | } 30 | return null; 31 | } 32 | 33 | private static class OEmbedSourceYoutube extends BaseOEmbedSource { 34 | OEmbedSourceYoutube(@NonNull Uri fromUri) { 35 | super("http://www.youtube.com/oembed", fromUri); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/co/tophe/oembed/internal/OEmbedDailymotion.java: -------------------------------------------------------------------------------- 1 | package co.tophe.oembed.internal; 2 | 3 | import java.util.regex.Pattern; 4 | 5 | import android.net.Uri; 6 | import android.support.annotation.NonNull; 7 | 8 | import co.tophe.oembed.OEmbedSource; 9 | 10 | public class OEmbedDailymotion implements OEmbedParser { 11 | 12 | public static final OEmbedDailymotion INSTANCE = new OEmbedDailymotion(); 13 | 14 | private final Pattern pattern; 15 | private final Pattern patternShort; 16 | 17 | private OEmbedDailymotion() { 18 | this.pattern = Pattern.compile("http://www.dailymotion.com/video/*"); 19 | this.patternShort = Pattern.compile("http://dai.ly/*"); 20 | } 21 | 22 | @Override 23 | public OEmbedSource getSource(@NonNull Uri fromUri) { 24 | if (pattern.matcher(fromUri.toString()).find()) { 25 | return new OEmbedSource(fromUri); 26 | } 27 | if (patternShort.matcher(fromUri.toString()).find()) { 28 | return new OEmbedSource(fromUri); 29 | } 30 | return null; 31 | } 32 | 33 | private static class OEmbedSource extends BaseOEmbedSource { 34 | OEmbedSource(@NonNull Uri fromUri) { 35 | super("http://www.dailymotion.com/services/oembed", fromUri); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/co/tophe/oembed/internal/OEmbedRequestGet.java: -------------------------------------------------------------------------------- 1 | package co.tophe.oembed.internal; 2 | 3 | import android.support.annotation.NonNull; 4 | 5 | import co.tophe.oembed.OEmbed; 6 | import co.tophe.oembed.OEmbedRequest; 7 | 8 | import co.tophe.BaseHttpRequest; 9 | import co.tophe.BaseResponseHandler; 10 | import co.tophe.HttpRequest; 11 | import co.tophe.HttpUriParameters; 12 | import co.tophe.ServerException; 13 | import co.tophe.gson.BodyViaGson; 14 | 15 | public class OEmbedRequestGet extends BaseHttpRequest implements OEmbedRequest { 16 | 17 | private static final BodyViaGson OEMBED_TRANSFORM = new BodyViaGson(OEmbed.class); 18 | private static final BaseResponseHandler OEMBED_RESPONSE_PARSER = new BaseResponseHandler(OEMBED_TRANSFORM); 19 | 20 | public OEmbedRequestGet(@NonNull String url) { 21 | this(url, null); 22 | } 23 | 24 | public OEmbedRequestGet(@NonNull String baseUrl, HttpUriParameters uriParams) { 25 | super(new ChildBuilder() { 26 | @Override 27 | protected OEmbedRequestGet build(ChildBuilder builder) { 28 | return new OEmbedRequestGet(builder); 29 | } 30 | } 31 | .setUrl(baseUrl, uriParams) 32 | .setResponseHandler(OEMBED_RESPONSE_PARSER) 33 | ); 34 | setHeader(HttpRequest.HEADER_ACCEPT, "application/json"); 35 | } 36 | 37 | protected OEmbedRequestGet(ChildBuilder builder) { 38 | super(builder); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/src/co/tophe/oembed/internal/OEmbedSourceTest.java: -------------------------------------------------------------------------------- 1 | package co.tophe.oembed.internal; 2 | 3 | import android.net.Uri; 4 | import android.test.AndroidTestCase; 5 | 6 | import co.tophe.oembed.OEmbedSource; 7 | 8 | import co.tophe.HttpDataParserException; 9 | import co.tophe.HttpIOException; 10 | import co.tophe.HttpMimeException; 11 | import co.tophe.ServerException; 12 | 13 | public class OEmbedSourceTest extends AndroidTestCase { 14 | 15 | public void testBogusMime() throws Exception { 16 | OEmbedSource source = new BaseOEmbedSource("http://goo.gl/json", Uri.parse("http://mydomain.com/path")){}; 17 | try { 18 | source.getThumbnail(); 19 | } catch (HttpMimeException e) { 20 | // ok 21 | } 22 | } 23 | 24 | public void testBogusData() throws Exception { 25 | OEmbedSource source = new BaseOEmbedSource("http://httpbin.org/ip", Uri.parse("http://mydomain.com/path")){}; 26 | try { 27 | source.getThumbnail(); 28 | } catch (HttpDataParserException e) { 29 | // ok 30 | } 31 | } 32 | 33 | public void testBogusDomain() throws Exception { 34 | OEmbedSource source = new BaseOEmbedSource("http://goo.goo/json", Uri.parse("http://mydomain.com/path")){}; 35 | try { 36 | source.getThumbnail(); 37 | } catch (HttpIOException e) { 38 | // ok 39 | } 40 | } 41 | 42 | public void testBogusUrl() throws Exception { 43 | OEmbedSource source = new BaseOEmbedSource("http://www.google.com/totosdk", Uri.parse("http://mydomain.com/path")){}; 44 | try { 45 | source.getThumbnail(); 46 | } catch (ServerException e) { 47 | if (e.getStatusCode()!= ServerException.HTTP_STATUS_NOT_FOUND) 48 | throw e; 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /src/main/co/tophe/oembed/internal/BaseOEmbedSource.java: -------------------------------------------------------------------------------- 1 | package co.tophe.oembed.internal; 2 | 3 | import android.net.Uri; 4 | import android.support.annotation.NonNull; 5 | import android.support.annotation.Nullable; 6 | import android.text.TextUtils; 7 | 8 | import co.tophe.oembed.OEmbed; 9 | import co.tophe.oembed.OEmbedRequest; 10 | import co.tophe.oembed.OEmbedSource; 11 | 12 | import co.tophe.TopheClient; 13 | import co.tophe.HttpException; 14 | import co.tophe.ServerException; 15 | import co.tophe.UriParams; 16 | 17 | public abstract class BaseOEmbedSource implements OEmbedSource { 18 | 19 | private OEmbed oembedData; 20 | private final String endpoint; 21 | private final String url; 22 | 23 | protected BaseOEmbedSource(@NonNull String endpoint, @NonNull Uri fromUri) { 24 | this.endpoint = endpoint; 25 | this.url = fromUri.toString(); 26 | } 27 | 28 | final void assertDataLoaded() throws ServerException, HttpException { 29 | OEmbedRequest request = createOembedRequest(); 30 | oembedData = TopheClient.parseRequest(request); 31 | } 32 | 33 | @NonNull 34 | @Override 35 | public final OEmbedRequest createOembedRequest() { 36 | UriParams params = new UriParams(2); 37 | params.add("url", url); 38 | params.add("format", "json"); 39 | return new OEmbedRequestGet(endpoint, params); 40 | } 41 | 42 | @Nullable 43 | @Override 44 | public String getThumbnail() throws ServerException, HttpException { 45 | assertDataLoaded(); 46 | 47 | if (null!=oembedData) { 48 | String thumbnail = oembedData.isLink() ? null : oembedData.getThumbnail(); 49 | if (TextUtils.isEmpty(thumbnail)) 50 | thumbnail = oembedData.getPhotoUrl(); 51 | return thumbnail; 52 | } 53 | return null; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/co/tophe/oembed/OEmbed.java: -------------------------------------------------------------------------------- 1 | package co.tophe.oembed; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | import co.tophe.gson.GsonReflected; 6 | 7 | /** 8 | * OEmbed object with the data parsed from the server response. 9 | */ 10 | public class OEmbed implements GsonReflected { 11 | @SerializedName("type") String type; 12 | @SerializedName("title") String title; 13 | @SerializedName("author_name") String author; 14 | @SerializedName("author_url") String authorUrl; 15 | @SerializedName("provider_name") String provider; 16 | @SerializedName("provider_url") String providerUrl; 17 | @SerializedName("thumbnail_url") String thumbnailUrl; 18 | @SerializedName("thumbnail_width") int thumbnailWidth; 19 | @SerializedName("thumbnail_height") int thumbnailHeight; 20 | @SerializedName("url") String photoUrl; 21 | @SerializedName("width") int photoWidth; 22 | @SerializedName("height") int photoHeight; 23 | 24 | /** 25 | * Tell if the OEmbed object is a photo or a video 26 | */ 27 | public boolean isPhoto() { 28 | return "photo".equals(type); 29 | } 30 | 31 | public boolean isLink() { 32 | return "link".equals(type); 33 | } 34 | 35 | public boolean isVideo() { 36 | return "video".equals(type); 37 | } 38 | 39 | public boolean isRich() { 40 | return "rich".equals(type); 41 | } 42 | 43 | public String getThumbnail() { 44 | return thumbnailUrl; 45 | } 46 | 47 | public int getThumbnailHeight() { 48 | return thumbnailHeight; 49 | } 50 | 51 | public int getThumbnailWidth() { 52 | return thumbnailWidth; 53 | } 54 | 55 | public String getPhotoUrl() { 56 | return photoUrl; 57 | } 58 | 59 | public int getPhotoWidth() { 60 | return photoWidth; 61 | } 62 | 63 | public int getPhotoHeight() { 64 | return photoHeight; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #Android-oEmbed 2 | 3 | A simple oEmbed parsing library for Android. 4 | 5 | You provide the URL of a webpage and the library will give you an OEmbed object if it finds one. 6 | 7 | ## Dependencies 8 | 9 | * [Tophe](https://github.com/levelup/Android-HttpClient) 10 | 11 | ##Sample Code 12 | 13 | ###Get a picture thumbnail for a URL 14 | 15 | ```java 16 | OEmbedSource dataSource = OEmbedFinder.lookup("http://www.youtube.com/watch?v=ODrLMCXKTS8"); 17 | if (dataSource != null) { 18 | String thumbnail = dataSource.getThumbnail(); 19 | } 20 | ``` 21 | 22 | ###Embedly fallback 23 | 24 | ```java 25 | OEmbedEmbedly fallback = new OEmbedEmbedly(url); 26 | String thumbnail = fallback.getThumbnail(); 27 | ``` 28 | 29 | ## Download 30 | 31 | Download [the latest JAR][1] or grab via Maven [![Maven Central](https://maven-badges.herokuapp.com/maven-central/co.tophe/android-oembed/badge.svg?style=flat)](https://maven-badges.herokuapp.com/maven-central/co.tophe/android-oembed) 32 | ```xml 33 | 34 | co.tophe 35 | android-oembed 36 | 1.0.1 37 | 38 | ``` 39 | or Gradle: 40 | ```groovy 41 | compile 'co.tophe:tophe:android-oembed:1.0.1' 42 | ``` 43 | 44 | ## License 45 | 46 | Licensed under the Apache License, Version 2.0 (the "License"); 47 | you may not use this file except in compliance with the License. 48 | You may obtain a copy of the License at 49 | 50 | http://www.apache.org/licenses/LICENSE-2.0 51 | 52 | Unless required by applicable law or agreed to in writing, software 53 | distributed under the License is distributed on an "AS IS" BASIS, 54 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 55 | See the License for the specific language governing permissions and 56 | limitations under the License. 57 | 58 | [1]: https://search.maven.org/remote_content?g=co.tophe&a=android-oembed&v=LATEST 59 | -------------------------------------------------------------------------------- /src/main/co/tophe/oembed/internal/OEmbedVine.java: -------------------------------------------------------------------------------- 1 | package co.tophe.oembed.internal; 2 | 3 | import java.util.List; 4 | 5 | import android.net.Uri; 6 | import android.support.annotation.NonNull; 7 | import android.support.annotation.Nullable; 8 | import android.text.TextUtils; 9 | 10 | import co.tophe.oembed.OEmbed; 11 | import co.tophe.oembed.OEmbedRequest; 12 | import co.tophe.oembed.OEmbedSource; 13 | 14 | import co.tophe.HttpException; 15 | import co.tophe.ServerException; 16 | import co.tophe.TopheClient; 17 | 18 | public class OEmbedVine implements OEmbedParser { 19 | 20 | public static final OEmbedVine INSTANCE = new OEmbedVine(); 21 | 22 | private OEmbedVine() { 23 | } 24 | 25 | @Override 26 | public OEmbedSource getSource(@NonNull Uri fromUri) { 27 | if (fromUri.getHost().endsWith("vine.co")) { 28 | List path = fromUri.getPathSegments(); 29 | if (path.size() > 1) { 30 | if ("v".equals(path.get(0))) { 31 | return new OEmbedSourceVine(path.get(1)); 32 | } 33 | } 34 | } 35 | return null; 36 | } 37 | 38 | private static class OEmbedSourceVine implements OEmbedSource { 39 | private final String vineId; 40 | 41 | private OEmbed oembedData; 42 | 43 | OEmbedSourceVine(@NonNull String vineId) { 44 | this.vineId = vineId; 45 | } 46 | 47 | final void assertDataLoaded() throws ServerException, HttpException { 48 | OEmbedRequest request = createOembedRequest(); 49 | oembedData = TopheClient.parseRequest(request); 50 | } 51 | 52 | @Nullable 53 | @Override 54 | public String getThumbnail() throws ServerException, HttpException { 55 | assertDataLoaded(); 56 | 57 | if (null!=oembedData) { 58 | String thumbnail = oembedData.getThumbnail(); 59 | if (TextUtils.isEmpty(thumbnail)) 60 | thumbnail = oembedData.getPhotoUrl(); 61 | return thumbnail; 62 | } 63 | return null; 64 | } 65 | 66 | @NonNull 67 | @Override 68 | public OEmbedRequest createOembedRequest() { 69 | return new OEmbedRequestGet("https://vine.co/oembed/"+vineId+".json", null); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/co/tophe/oembed/OEmbedFinder.java: -------------------------------------------------------------------------------- 1 | package co.tophe.oembed; 2 | 3 | import android.net.Uri; 4 | import android.support.annotation.Nullable; 5 | import android.text.TextUtils; 6 | 7 | import co.tophe.oembed.internal.OEmbedDailymotion; 8 | import co.tophe.oembed.internal.OEmbedFunnyOrDie; 9 | import co.tophe.oembed.internal.OEmbedHulu; 10 | import co.tophe.oembed.internal.OEmbedImgur; 11 | import co.tophe.oembed.internal.OEmbedInstagram; 12 | import co.tophe.oembed.internal.OEmbedParser; 13 | import co.tophe.oembed.internal.OEmbedViddler; 14 | import co.tophe.oembed.internal.OEmbedVimeo; 15 | import co.tophe.oembed.internal.OEmbedVine; 16 | import co.tophe.oembed.internal.OEmbedYoutube; 17 | 18 | /** 19 | * Helper class to find a suitable {@link co.tophe.oembed.OEmbedSource} for a specified URL. 20 | * 21 | * @see #lookup(String) 22 | */ 23 | public final class OEmbedFinder { 24 | 25 | private static final OEmbedParser parsers[] = new OEmbedParser[]{ 26 | OEmbedYoutube.INSTANCE, 27 | OEmbedInstagram.INSTANCE, 28 | OEmbedImgur.INSTANCE, 29 | OEmbedVimeo.INSTANCE, 30 | OEmbedHulu.INSTANCE, 31 | OEmbedDailymotion.INSTANCE, 32 | OEmbedFunnyOrDie.INSTANCE, 33 | OEmbedVine.INSTANCE, 34 | OEmbedViddler.INSTANCE, 35 | }; 36 | 37 | /** 38 | * Find an OEmbed source for the specified URL. 39 | *

After that you can call {@link OEmbedSource#getThumbnail()} to get a picture representation of the URL.

40 | *

When a source is not found you may still use fallback sources like {@link co.tophe.oembed.fallback.OEmbedEmbedly OEmbedEmbedly}, 41 | * {@link co.tophe.oembed.fallback.OEmbedOohembed OEmbedOohembed} or {@link co.tophe.oembed.fallback.OEmbedReembed OEmbedReembed}

42 | * 43 | * @return {@code null} if no source if found for this URL. 44 | */ 45 | @Nullable 46 | public static OEmbedSource lookup(String sourceUrl) { 47 | if (!TextUtils.isEmpty(sourceUrl)) { 48 | Uri sourceUri = Uri.parse(sourceUrl); 49 | 50 | for (OEmbedParser parser : parsers) { 51 | OEmbedSource src = parser.getSource(sourceUri); 52 | if (null != src) 53 | return src; 54 | } 55 | } 56 | return null; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /src/test/src/co/tophe/oembed/sourceTest.java: -------------------------------------------------------------------------------- 1 | package co.tophe.oembed; 2 | 3 | import android.test.AndroidTestCase; 4 | 5 | public class sourceTest extends AndroidTestCase { 6 | 7 | private static final String YOUTUBE1 = "http://www.youtube.com/watch?v=SqfJPKgkdgg"; 8 | private static final String YOUTUBE2 = "http://www.youtube.com/embed/SqfJPKgkdgg?rel=0&autoplay=0&wmode=opaque&controls=2&autohide=1&showinfo=0"; 9 | private static final String YOUTUBE_SHORT = "http://youtu.be/bFra7SIMYt4?a"; 10 | private static final String VIMEO1 = "http://vimeo.com/7100569"; 11 | private static final String INSTAGRAM = "http://instagram.com/p/xpaLXzIwd1/"; 12 | private static final String INSTAGRAM_FULL = "http://instagram.com/p/xpaLXzIwd1/?modal=true"; 13 | private static final String INSTAGRAM_VIDEO = "http://instagram.com/p/ydm4ZvLUMo/"; 14 | private static final String VIDDLER1 = "http://www.viddler.com/v/1646c55"; 15 | private static final String FUNNYORDIE1 = "http://www.funnyordie.com/videos/a7311134ac/patton-oswalt-in-heavy-metal"; 16 | private static final String HULU1 = "http://www.hulu.com/watch/20807/late-night-with-conan-obrien-wed-may-21-2008"; 17 | private static final String IMGUR1 = "http://imgur.com/gallery/VWtX56r"; 18 | private static final String IMGUR2 = "http://i.imgur.com/emxcraW.jpg"; 19 | private static final String IMGUR3 = "http://imgur.com/PDnO8rG"; 20 | private static final String IMGUR_GALLERY = "http://imgur.com/gallery/STcRW6c"; 21 | private static final String DAILYMOTION = "http://www.dailymotion.com/video/xl561h_on-peut-tromper-une-fois-mille-personnes_fun"; 22 | private static final String DAILYMOTION_SHORT = "http://dai.ly/q9Mli9"; 23 | private static final String FAIL_IMGUR1 = "http://imgur.com/a/N5vY5"; 24 | 25 | private void testOEmbedThumbnail(String url) throws Exception { 26 | OEmbedSource dataSource = OEmbedFinder.lookup(url); 27 | assertNotNull(dataSource); 28 | String thumbnail = dataSource.getThumbnail(); 29 | assertNotNull(thumbnail); 30 | } 31 | 32 | private void testOEmbedNotSupported(String url) throws Exception { 33 | OEmbedSource dataSource = OEmbedFinder.lookup(url); 34 | assertNull(dataSource); 35 | } 36 | 37 | private void testOEmbedNoThumbnail(String url) throws Exception { 38 | OEmbedSource dataSource = OEmbedFinder.lookup(url); 39 | assertNotNull(dataSource); 40 | String thumbnail = dataSource.getThumbnail(); 41 | assertNull(thumbnail); 42 | } 43 | 44 | public void testYoutube1() throws Exception { 45 | testOEmbedThumbnail(YOUTUBE1); 46 | } 47 | 48 | public void testYoutube2() throws Exception { 49 | testOEmbedThumbnail(YOUTUBE2); 50 | } 51 | 52 | public void testYoutubeShort() throws Exception { 53 | testOEmbedThumbnail(YOUTUBE_SHORT); 54 | } 55 | 56 | public void testVimeo1() throws Exception { 57 | testOEmbedThumbnail(VIMEO1); 58 | } 59 | 60 | public void testInstagram() throws Exception { 61 | testOEmbedThumbnail(INSTAGRAM); 62 | } 63 | 64 | public void testInstagramFull() throws Exception { 65 | testOEmbedThumbnail(INSTAGRAM_FULL); 66 | } 67 | 68 | public void testInstagramVideo() throws Exception { 69 | testOEmbedThumbnail(INSTAGRAM_VIDEO); 70 | } 71 | 72 | public void testViddler1() throws Exception { 73 | testOEmbedThumbnail(VIDDLER1); 74 | } 75 | 76 | public void testFunnyOrDie1() throws Exception { 77 | testOEmbedThumbnail(FUNNYORDIE1); 78 | } 79 | 80 | public void testHulu1() throws Exception { 81 | testOEmbedThumbnail(HULU1); 82 | } 83 | 84 | public void testImgur1() throws Exception { 85 | testOEmbedThumbnail(IMGUR1); 86 | } 87 | 88 | public void testImgur2() throws Exception { 89 | testOEmbedThumbnail(IMGUR2); 90 | } 91 | 92 | public void testImgur3() throws Exception { 93 | testOEmbedThumbnail(IMGUR3); 94 | } 95 | 96 | public void testImgurGallery() throws Exception { 97 | testOEmbedNoThumbnail(IMGUR_GALLERY); 98 | } 99 | 100 | public void testDailymotion() throws Exception { 101 | testOEmbedThumbnail(DAILYMOTION); 102 | } 103 | 104 | public void testDailymotionShort() throws Exception { 105 | testOEmbedThumbnail(DAILYMOTION_SHORT); 106 | } 107 | 108 | public void testImgurFail1() throws Exception { 109 | testOEmbedNotSupported(FAIL_IMGUR1); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | --------------------------------------------------------------------------------