Skip to content

Commit 2b84d8d

Browse files
Jawnnypoorogerhu
authored andcommitted
Remove support for manifest configuration (#809)
* Remove support for manifest configuration. Unify API for FCM and GCM recievers * Return to getting the GCM sender ID from the manifest
1 parent 329ef4a commit 2b84d8d

File tree

11 files changed

+83
-329
lines changed

11 files changed

+83
-329
lines changed

Parse/src/main/java/com/parse/Parse.java

Lines changed: 5 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import android.content.Context;
1212
import android.content.pm.PackageManager;
1313
import android.content.pm.ResolveInfo;
14-
import android.os.Bundle;
14+
import android.support.annotation.NonNull;
1515
import android.util.Log;
1616

1717
import java.io.File;
@@ -59,59 +59,15 @@ public static final class Builder {
5959
* <p>
6060
* This context will then be passed through to the rest of the Parse SDK for use during
6161
* initialization.
62-
* <p>
63-
* <p/>
64-
* You may define {@code com.parse.SERVER_URL}, {@code com.parse.APPLICATION_ID} and (optional) {@code com.parse.CLIENT_KEY}
65-
* {@code meta-data} in your {@code AndroidManifest.xml}:
66-
* <pre>
67-
* &lt;manifest ...&gt;
68-
*
69-
* ...
70-
*
71-
* &lt;application ...&gt;
72-
* &lt;meta-data
73-
* android:name="com.parse.SERVER_URL"
74-
* android:value="@string/parse_server_url" /&gt;
75-
* &lt;meta-data
76-
* android:name="com.parse.APPLICATION_ID"
77-
* android:value="@string/parse_app_id" /&gt;
78-
* &lt;meta-data
79-
* android:name="com.parse.CLIENT_KEY"
80-
* android:value="@string/parse_client_key" /&gt;
81-
*
82-
* ...
83-
*
84-
* &lt;/application&gt;
85-
* &lt;/manifest&gt;
86-
* </pre>
87-
* <p/>
88-
* <p>
89-
* This will cause the values for {@code server}, {@code applicationId} and {@code clientKey} to be set to
90-
* those defined in your manifest.
9162
*
9263
* @param context The active {@link Context} for your application. Cannot be null.
9364
*/
94-
public Builder(Context context) {
65+
public Builder(@NonNull Context context) {
9566
this.context = context;
96-
97-
// Yes, our public API states we cannot be null. But for unit tests, it's easier just to
98-
// support null here.
99-
if (context != null) {
100-
Context applicationContext = context.getApplicationContext();
101-
Bundle metaData = ManifestInfo.getApplicationMetadata(applicationContext);
102-
if (metaData != null) {
103-
server(metaData.getString(PARSE_SERVER_URL));
104-
applicationId = metaData.getString(PARSE_APPLICATION_ID);
105-
clientKey = metaData.getString(PARSE_CLIENT_KEY);
106-
}
107-
}
10867
}
10968

11069
/**
11170
* Set the application id to be used by Parse.
112-
* <p>
113-
* This method is only required if you intend to use a different {@code applicationId} than
114-
* is defined by {@code com.parse.APPLICATION_ID} in your {@code AndroidManifest.xml}.
11571
*
11672
* @param applicationId The application id to set.
11773
* @return The same builder, for easy chaining.
@@ -123,9 +79,6 @@ public Builder applicationId(String applicationId) {
12379

12480
/**
12581
* Set the client key to be used by Parse.
126-
* <p>
127-
* This method is only required if you intend to use a different {@code clientKey} than
128-
* is defined by {@code com.parse.CLIENT_KEY} in your {@code AndroidManifest.xml}.
12982
*
13083
* @param clientKey The client key to set.
13184
* @return The same builder, for easy chaining.
@@ -224,10 +177,6 @@ private Configuration(Builder builder) {
224177
}
225178
}
226179

227-
private static final String PARSE_SERVER_URL = "com.parse.SERVER_URL";
228-
private static final String PARSE_APPLICATION_ID = "com.parse.APPLICATION_ID";
229-
private static final String PARSE_CLIENT_KEY = "com.parse.CLIENT_KEY";
230-
231180
private static final Object MUTEX = new Object();
232181
static ParseEventuallyQueue eventuallyQueue = null;
233182

@@ -239,7 +188,7 @@ private Configuration(Builder builder) {
239188
/**
240189
* Enable pinning in your application. This must be called before your application can use
241190
* pinning. You must invoke {@code enableLocalDatastore(Context)} before
242-
* {@link #initialize(Context)} :
191+
* {@link #initialize(Configuration)}:
243192
* <p/>
244193
* <pre>
245194
* public class MyApplication extends Application {
@@ -284,99 +233,20 @@ public static boolean isLocalDatastoreEnabled() {
284233

285234
/**
286235
* Authenticates this client as belonging to your application.
287-
* <p/>
288-
* You may define {@code com.parse.SERVER_URL}, {@code com.parse.APPLICATION_ID} and (optional) {@code com.parse.CLIENT_KEY}
289-
* {@code meta-data} in your {@code AndroidManifest.xml}:
290-
* <pre>
291-
* &lt;manifest ...&gt;
292-
*
293-
* ...
294-
*
295-
* &lt;application ...&gt;
296-
* &lt;meta-data
297-
* android:name="com.parse.SERVER_URL"
298-
* android:value="@string/parse_server_url" /&gt;
299-
* &lt;meta-data
300-
* android:name="com.parse.APPLICATION_ID"
301-
* android:value="@string/parse_app_id" /&gt;
302-
* &lt;meta-data
303-
* android:name="com.parse.CLIENT_KEY"
304-
* android:value="@string/parse_client_key" /&gt;
305-
*
306-
* ...
307-
*
308-
* &lt;/application&gt;
309-
* &lt;/manifest&gt;
310-
* </pre>
311-
* <p/>
312-
* This must be called before your application can use the Parse library.
313-
* The recommended way is to put a call to {@code Parse.initialize}
314-
* in your {@code Application}'s {@code onCreate} method:
315-
* <p/>
316-
* <pre>
317-
* public class MyApplication extends Application {
318-
* public void onCreate() {
319-
* Parse.initialize(this);
320-
* }
321-
* }
322-
* </pre>
323-
*
324-
* @param context The active {@link Context} for your application.
325-
*/
326-
public static void initialize(Context context) {
327-
Configuration.Builder builder = new Configuration.Builder(context);
328-
if (builder.server == null) {
329-
throw new RuntimeException("ServerUrl not defined. " +
330-
"You must provide ServerUrl in AndroidManifest.xml.\n" +
331-
"<meta-data\n" +
332-
" android:name=\"com.parse.SERVER_URL\"\n" +
333-
" android:value=\"<Your Server Url>\" />");
334-
}
335-
if (builder.applicationId == null) {
336-
throw new RuntimeException("ApplicationId not defined. " +
337-
"You must provide ApplicationId in AndroidManifest.xml.\n" +
338-
"<meta-data\n" +
339-
" android:name=\"com.parse.APPLICATION_ID\"\n" +
340-
" android:value=\"<Your Application Id>\" />");
341-
}
342-
initialize(builder
343-
.setLocalDatastoreEnabled(isLocalDatastoreEnabled)
344-
.build()
345-
);
346-
}
347-
348-
/**
349-
* Authenticates this client as belonging to your application.
350-
* <p/>
351-
* This method is only required if you intend to use a different {@code applicationId} or
352-
* {@code clientKey} than is defined by {@code com.parse.APPLICATION_ID} or
353-
* {@code com.parse.CLIENT_KEY} in your {@code AndroidManifest.xml}.
354-
* <p/>
355236
* This must be called before your
356237
* application can use the Parse library. The recommended way is to put a call to
357238
* {@code Parse.initialize} in your {@code Application}'s {@code onCreate} method:
358239
* <p/>
359240
* <pre>
360241
* public class MyApplication extends Application {
361242
* public void onCreate() {
362-
* Parse.initialize(this, &quot;your application id&quot;, &quot;your client key&quot;);
243+
* Parse.initialize(configuration);
363244
* }
364245
* }
365246
* </pre>
366247
*
367-
* @param context The active {@link Context} for your application.
368-
* @param applicationId The application id provided in the Parse dashboard.
369-
* @param clientKey The client key provided in the Parse dashboard.
248+
* @param configuration The configuration for your application.
370249
*/
371-
public static void initialize(Context context, String applicationId, String clientKey) {
372-
initialize(new Configuration.Builder(context)
373-
.applicationId(applicationId)
374-
.clientKey(clientKey)
375-
.setLocalDatastoreEnabled(isLocalDatastoreEnabled)
376-
.build()
377-
);
378-
}
379-
380250
public static void initialize(Configuration configuration) {
381251
if (isInitialized()) {
382252
PLog.w(TAG, "Parse is already initialized");

Parse/src/test/java/com/parse/ParseClientConfigurationTest.java

Lines changed: 0 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,18 @@
88
*/
99
package com.parse;
1010

11-
import android.os.Bundle;
12-
1311
import org.junit.Test;
1412
import org.junit.runner.RunWith;
1513
import org.robolectric.RobolectricTestRunner;
16-
import org.robolectric.RuntimeEnvironment;
1714
import org.robolectric.annotation.Config;
1815

19-
import java.net.URL;
20-
import java.util.Collection;
21-
import java.util.Iterator;
22-
2316
import static org.junit.Assert.assertEquals;
2417
import static org.junit.Assert.assertNull;
25-
import static org.mockito.Mockito.mock;
26-
import static org.mockito.Mockito.verify;
27-
import static org.mockito.Mockito.when;
2818

2919
@RunWith(RobolectricTestRunner.class)
3020
@Config(constants = BuildConfig.class, sdk = TestHelper.ROBOLECTRIC_SDK_VERSION)
3121
public class ParseClientConfigurationTest {
3222

33-
private final String serverUrl = "http://example.com/parse";
34-
private final String appId = "MyAppId";
35-
private final String clientKey = "MyClientKey";
36-
private final String PARSE_SERVER_URL = "com.parse.SERVER_URL";
37-
private final String PARSE_APPLICATION_ID = "com.parse.APPLICATION_ID";
38-
private final String PARSE_CLIENT_KEY = "com.parse.CLIENT_KEY";
39-
4023
@Test
4124
public void testBuilder() {
4225
Parse.Configuration.Builder builder = new Parse.Configuration.Builder(null);
@@ -66,98 +49,4 @@ public void testBuilderServerMissingSlashURL() {
6649
Parse.Configuration configuration = builder.build();
6750
assertEquals(configuration.server, "http://myserver.com/missingslash/");
6851
}
69-
70-
@Test
71-
public void testConfigureFromManifest() throws Exception {
72-
Bundle metaData = setupMockMetaData();
73-
when(metaData.getString(PARSE_SERVER_URL)).thenReturn(serverUrl);
74-
when(metaData.getString(PARSE_APPLICATION_ID)).thenReturn(appId);
75-
when(metaData.getString(PARSE_CLIENT_KEY)).thenReturn(clientKey);
76-
77-
Parse.Configuration.Builder builder = new Parse.Configuration.Builder(RuntimeEnvironment.application);
78-
Parse.Configuration config = builder.build();
79-
assertEquals(serverUrl + "/", config.server);
80-
assertEquals(appId, config.applicationId);
81-
assertEquals(clientKey, config.clientKey);
82-
83-
verifyMockMetaData(metaData);
84-
}
85-
86-
@Test(expected = RuntimeException.class)
87-
public void testConfigureFromManifestWithoutServer() throws Exception {
88-
Bundle metaData = setupMockMetaData();
89-
when(metaData.getString(PARSE_SERVER_URL)).thenReturn(null);
90-
when(metaData.getString(PARSE_APPLICATION_ID)).thenReturn(appId);
91-
when(metaData.getString(PARSE_CLIENT_KEY)).thenReturn(clientKey);
92-
93-
// RuntimeException due to serverUrl = null
94-
Parse.initialize(RuntimeEnvironment.application);
95-
}
96-
97-
@Test(expected = RuntimeException.class)
98-
public void testConfigureFromManifestWithoutAppId() throws Exception {
99-
Bundle metaData = setupMockMetaData();
100-
when(metaData.getString(PARSE_SERVER_URL)).thenReturn(serverUrl);
101-
when(metaData.getString(PARSE_APPLICATION_ID)).thenReturn(null);
102-
when(metaData.getString(PARSE_CLIENT_KEY)).thenReturn(clientKey);
103-
104-
// RuntimeException due to applicationId = null
105-
Parse.initialize(RuntimeEnvironment.application);
106-
}
107-
108-
@Test
109-
public void testConfigureFromManifestWithoutClientKey() throws Exception {
110-
Bundle metaData = setupMockMetaData();
111-
when(metaData.getString(PARSE_SERVER_URL)).thenReturn(serverUrl);
112-
when(metaData.getString(PARSE_APPLICATION_ID)).thenReturn(appId);
113-
when(metaData.getString(PARSE_CLIENT_KEY)).thenReturn(null);
114-
115-
Parse.initialize(RuntimeEnvironment.application);
116-
assertEquals(new URL(serverUrl + "/"), ParseRESTCommand.server);
117-
assertEquals(appId, ParsePlugins.get().applicationId());
118-
assertNull(ParsePlugins.get().clientKey());
119-
120-
verifyMockMetaData(metaData);
121-
}
122-
123-
private void verifyMockMetaData(Bundle metaData) throws Exception {
124-
verify(metaData).getString(PARSE_SERVER_URL);
125-
verify(metaData).getString(PARSE_APPLICATION_ID);
126-
verify(metaData).getString(PARSE_CLIENT_KEY);
127-
}
128-
129-
private Bundle setupMockMetaData() throws Exception {
130-
Bundle metaData = mock(Bundle.class);
131-
RuntimeEnvironment.application.getApplicationInfo().metaData = metaData;
132-
return metaData;
133-
}
134-
135-
private static <T> boolean collectionsEqual(Collection<T> a, Collection<T> b) {
136-
if (a.size() != b.size()) {
137-
return false;
138-
}
139-
140-
Iterator<T> iteratorA = a.iterator();
141-
Iterator<T> iteratorB = b.iterator();
142-
for (; iteratorA.hasNext() && iteratorB.hasNext();) {
143-
T objectA = iteratorA.next();
144-
T objectB = iteratorB.next();
145-
146-
if (objectA == null || objectB == null) {
147-
if (objectA != objectB) {
148-
return false;
149-
}
150-
continue;
151-
}
152-
153-
if (!objectA.equals(objectB)) {
154-
return false;
155-
}
156-
}
157-
158-
if (iteratorA.hasNext() || iteratorB.hasNext()) {
159-
return false;
160-
}
161-
return true;
162-
}
16352
}

0 commit comments

Comments
 (0)