Merge remote-tracking branch 'goog/studio-firebase-plugin-dev' into firebase-merge
diff --git a/resources/admob/service.xml b/resources/admob/service.xml
index 3fb6af6..a1dfb39 100644
--- a/resources/admob/service.xml
+++ b/resources/admob/service.xml
@@ -3,6 +3,7 @@
format="1"
category="Ads"
name="AdMob"
+ id="admob"
description="Lets you monetize your app by showing ads tailored to your users."
learnMore="https://developers.google.com/mobile-ads-sdk/"
icon="logo_admob_color_2x_web_32dp.png"
diff --git a/resources/analytics/service.xml b/resources/analytics/service.xml
index ea199e1..c521670 100644
--- a/resources/analytics/service.xml
+++ b/resources/analytics/service.xml
@@ -3,6 +3,7 @@
format="1"
category="Analytics"
name="Google Analytics"
+ id="google_analytics"
description="Lets you measure user interactions with your app across various devices and environments."
learnMore="https://developers.google.com/analytics/"
icon="logo_analytics_color_2x_web_32dp.png"
diff --git a/resources/cloud_messaging/service.xml b/resources/cloud_messaging/service.xml
index 555835b..5a2a372 100644
--- a/resources/cloud_messaging/service.xml
+++ b/resources/cloud_messaging/service.xml
@@ -3,6 +3,7 @@
format="1"
category="Notifications"
name="Google Cloud Messaging"
+ id="google_cloud_messaging"
description="Allows you to send and receive data between your server and your users' devices."
learnMore="https://developer.android.com/google/gcm/gs.html"
icon="logo_gcm_color_2x_web_32dp.png"
diff --git a/resources/firebase/AndroidManifest.xml b/resources/firebase/AndroidManifest.xml
deleted file mode 100644
index 307b78b..0000000
--- a/resources/firebase/AndroidManifest.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android">
- <uses-permission android:name="android.permission.INTERNET" />
-</manifest>
diff --git a/resources/firebase/firebase@4x.png b/resources/firebase/firebase@4x.png
deleted file mode 100644
index 1629720..0000000
--- a/resources/firebase/firebase@4x.png
+++ /dev/null
Binary files differ
diff --git a/resources/firebase/recipe.xml b/resources/firebase/recipe.xml
deleted file mode 100644
index 4ceb097..0000000
--- a/resources/firebase/recipe.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-<?xml version="1.0"?>
-<recipe>
- <dependency mavenUrl="com.firebase:firebase-client-android:2.3.1"/>
-
- <merge from="AndroidManifest.xml"
- to="src/main/AndroidManifest.xml"/>
-</recipe>
\ No newline at end of file
diff --git a/resources/firebase/service.xml b/resources/firebase/service.xml
deleted file mode 100644
index 9722daf..0000000
--- a/resources/firebase/service.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-<?xml version="1.0"?>
-<service
- format="1"
- category="Cloud"
- name="Firebase"
- description="Firebase is a complete platform for building mobile and web applications."
- learnMore="https://www.firebase.com/docs/android/android-studio-quickstart.html"
- icon="firebase@4x.png"
- execute="recipe.xml">
-
- <uiGrid colDefinitions="Fit,Fit">
- <uiLabel
- row="0" col="0"
- text="Continue configuration by following the instructions "/>
- <uiLink
- row="0" col="1"
- text="here"
- url="https://www.firebase.com/docs/android/android-studio-quickstart.html"/>
- </uiGrid>
-</service>
\ No newline at end of file
diff --git a/resources/google_service_bundle.xml b/resources/google_service_bundle.xml
new file mode 100644
index 0000000..86fe138
--- /dev/null
+++ b/resources/google_service_bundle.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0"?>
+<!--
+ ~ Copyright (C) 2015 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<!-- TODO: Add remote configuration location, much of this should be fallback only -->
+<servicebundle name="Google Services"
+ format="1"
+ id="DeveloperServices.Google"
+ contentRoot="https://developers.google.com/experimental/">
+ <service name="Admob"
+ resourceRoot="/admob">
+ <resource>service.xml</resource>
+ <resource>recipe.xml</resource>
+ <resource>logo_admob_color_2x_web_32dp.png</resource>
+ </service>
+ <service name="Google Cloud Messaging"
+ resourceRoot="/cloud_messaging">
+ <resource>service.xml</resource>
+ <resource>recipe.xml</resource>
+ <resource>logo_gcm_color_2x_web_32dp.png</resource>
+ </service>
+ <service name="Identity"
+ resourceRoot="/identity">
+ <resource>service.xml</resource>
+ <resource>recipe.xml</resource>
+ <resource>logo_identity_color_2x_web_32dp.png</resource>
+ </service>
+</servicebundle>
diff --git a/resources/identity/service.xml b/resources/identity/service.xml
index f904e51..3b1d568 100644
--- a/resources/identity/service.xml
+++ b/resources/identity/service.xml
@@ -3,6 +3,7 @@
format="1"
category="Authentication"
name="Google Sign-In"
+ id="google_identity"
description="A secure authentication system that enables your app users to sign in with their Google account."
learnMore="https://developers.google.com/identity/sign-in/android/"
icon="logo_identity_color_2x_web_32dp.png"
diff --git a/src/META-INF/plugin.xml b/src/META-INF/plugin.xml
index 1a31613..0623435 100644
--- a/src/META-INF/plugin.xml
+++ b/src/META-INF/plugin.xml
@@ -14,7 +14,7 @@
~ limitations under the License.
-->
<idea-plugin version="2">
- <id>com.gooogle.services</id>
+ <id>com.google.services</id>
<name>Google Services</name>
<version>0.1</version>
<vendor>Google</vendor>
@@ -37,10 +37,6 @@
<developerServiceCreators implementation="com.google.services.GoogleServiceCreators"/>
</extensions>
- <extensions defaultExtensionNs="com.google.gct.login">
- <googleLoginListener implementation="com.google.services.GoogleServiceLoginListener"/>
- </extensions>
-
<application-components>
<!-- Add your application components here -->
</application-components>
@@ -50,7 +46,6 @@
</project-components>
<actions>
- <!-- Add your actions here -->
</actions>
-</idea-plugin>
\ No newline at end of file
+</idea-plugin>
diff --git a/src/com/google/services/FirebaseLogcatFilterProvider.java b/src/com/google/services/FirebaseLogcatFilterProvider.java
new file mode 100644
index 0000000..8d4ac1d
--- /dev/null
+++ b/src/com/google/services/FirebaseLogcatFilterProvider.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.google.services;
+
+import com.android.ddmlib.ClientData;
+import com.android.ddmlib.Log;
+import com.android.tools.idea.logcat.AndroidLogcatFilter;
+import com.android.tools.idea.logcat.LogcatFilterProvider;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.regex.Pattern;
+
+
+public final class FirebaseLogcatFilterProvider implements LogcatFilterProvider {
+
+ private static final AndroidLogcatFilter FILTER = new FirebaseLogcatFilter();
+
+ @NotNull
+ @Override
+ public AndroidLogcatFilter getFilter(@Nullable ClientData client) {
+ return FILTER;
+ }
+
+ private static class FirebaseLogcatFilter implements AndroidLogcatFilter {
+ private static final Pattern myFirebasePackagePattern = Pattern.compile("com\\.google\\.firebase\\..*");
+ private static final Pattern myAppIndexingTagPattern = Pattern.compile("AppIndexApi");
+
+ @NotNull
+ @Override
+ public String getName() {
+ return "Firebase";
+ }
+
+ @Override
+ public boolean isApplicable(@NotNull String message,
+ @NotNull String tag,
+ @NotNull String pkg,
+ int pid,
+ @NotNull Log.LogLevel logLevel) {
+ return myAppIndexingTagPattern.matcher(tag).find() || myFirebasePackagePattern.matcher(pkg).find();
+ }
+ }
+}
diff --git a/src/com/google/services/GoogleServiceCreators.java b/src/com/google/services/GoogleServiceCreators.java
index 4789183..0a86d7b 100644
--- a/src/com/google/services/GoogleServiceCreators.java
+++ b/src/com/google/services/GoogleServiceCreators.java
@@ -16,27 +16,63 @@
package com.google.services;
import com.android.tools.idea.structure.services.DeveloperServiceCreator;
-import com.android.tools.idea.structure.services.DeveloperServiceCreators;
-import com.google.common.collect.ImmutableSet;
-import com.google.services.creators.*;
+import com.android.tools.idea.structure.services.DeveloperServiceMap;
+import com.google.services.creators.FileServiceCreators;
+import com.google.services.creators.GoogleServiceCreator;
+import com.google.services.google.GoogleServicesPanel;
+import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NotNull;
-import java.util.Collection;
+import javax.swing.*;
+import java.util.List;
/**
* Extension for Android Studio which provides helpers that initialize developer services related
* to the Google brand.
*/
-public final class GoogleServiceCreators implements DeveloperServiceCreators {
+public final class GoogleServiceCreators extends FileServiceCreators {
+
+ private static final String SERVICE_CONFIG_FILENAME = "/google_service_bundle.xml";
+
+ /**
+ * This approach is required because {@code DeveloperServiceCreators} abstract class has a constructor that sets final member variables
+ * based on abstract getter methods. A subclasses' constructor therefore can't initialize member variables for the implemented abstract
+ * methods to use, therefore an anonymouse class was needed for now.
+ *
+ * TODO: Refactor the DeveloperServiceCreator class to make this unnecessary.
+ */
@Override
+ protected DeveloperServiceCreator getServiceCreator(String resourceRoot, List<String> resources) {
+ // Ensure only one copy of array is created despite multiple calls to getResources().
+ final String[] resourceArray = ArrayUtil.toStringArray(resources);
+ return new GoogleServiceCreator() {
+ @NotNull
+ @Override
+ protected String getResourceRoot() {
+ return resourceRoot;
+ }
+ @NotNull
+ @Override
+ protected String[] getResources() {
+ return resourceArray;
+ }
+ };
+ }
+
+ @Override
+ protected String getResourceConfigFileName() {
+ return SERVICE_CONFIG_FILENAME;
+ }
+
+ @Override
+ public String getBundleId() {
+ return "DeveloperServices.Google";
+ }
+
@NotNull
- public Collection<? extends DeveloperServiceCreator> getCreators() {
- return ImmutableSet.of(
- new AdMobServiceCreator(),
- new AnalyticsServiceCreator(),
- new CloudMessagingServiceCreator(),
- new FirebaseServiceCreator(),
- new IdentityServiceCreator()
- );
+ @Override
+ public JTabbedPane getPanel(@NotNull DeveloperServiceMap serviceMap) {
+ // Stub.
+ return new GoogleServicesPanel();
}
}
diff --git a/src/com/google/services/creators/AdMobServiceCreator.java b/src/com/google/services/creators/AdMobServiceCreator.java
deleted file mode 100644
index 1eb1ca3..0000000
--- a/src/com/google/services/creators/AdMobServiceCreator.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.services.creators;
-
-import org.jetbrains.annotations.NotNull;
-
-public final class AdMobServiceCreator extends GoogleServiceCreator {
- @NotNull
- @Override
- protected String getResourceRoot() {
- return "/admob";
- }
-
- @NotNull
- @Override
- protected String[] getResources() {
- return new String[]{"logo_admob_color_2x_web_32dp.png", "recipe.xml", "service.xml"};
- }
-}
diff --git a/src/com/google/services/creators/CloudMessagingServiceCreator.java b/src/com/google/services/creators/CloudMessagingServiceCreator.java
deleted file mode 100644
index e236178..0000000
--- a/src/com/google/services/creators/CloudMessagingServiceCreator.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.services.creators;
-
-import org.jetbrains.annotations.NotNull;
-
-public final class CloudMessagingServiceCreator extends GoogleServiceCreator {
- @NotNull
- @Override
- protected String getResourceRoot() {
- return "/cloud_messaging";
- }
-
- @NotNull
- @Override
- protected String[] getResources() {
- return new String[]{"logo_gcm_color_2x_web_32dp.png", "recipe.xml", "service.xml"};
- }
-}
diff --git a/src/com/google/services/creators/FileServiceCreators.java b/src/com/google/services/creators/FileServiceCreators.java
new file mode 100644
index 0000000..451bc6b
--- /dev/null
+++ b/src/com/google/services/creators/FileServiceCreators.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.google.services.creators;
+
+import com.android.tools.idea.structure.services.DeveloperServiceCreator;
+import com.android.tools.idea.structure.services.DeveloperServiceCreators;
+import com.android.tools.idea.structure.services.ServiceBundle;
+import org.jetbrains.annotations.NotNull;
+
+import javax.xml.bind.JAXBException;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * Generic {@code DeveloperServiceCreators} that populates based on an XML resource. To use this class extend it and implement
+ * {@code getResourceConfigFileName()}.
+ */
+public abstract class FileServiceCreators implements DeveloperServiceCreators {
+
+ protected abstract DeveloperServiceCreator getServiceCreator(final String resourceRoot,
+ final List<String> resources);
+
+ /**
+ * XML file resource name that will be used to configure the creators returned from this class.
+ */
+ protected abstract String getResourceConfigFileName();
+
+ @Override
+ @NotNull
+ public final Collection<? extends DeveloperServiceCreator> getCreators() {
+ try {
+ return loadCreators();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Read list of {@code GoogleServiceCreators} from {@code getResourceConfigFileName()}.
+ */
+ private Collection<DeveloperServiceCreator> loadCreators() throws FileNotFoundException {
+ String fileName = getResourceConfigFileName();
+
+ URL resource = getClass().getResource(fileName);
+ if (resource == null) {
+ throw new FileNotFoundException(String.format("Could not find service file %1$s", fileName));
+ }
+
+ InputStream inputStream = null;
+ InputStreamReader inputStreamReader = null;
+ try {
+ inputStream = resource.openStream();
+ inputStreamReader = new InputStreamReader(inputStream);
+ ServiceBundle servicebundle = ServiceBundle.parse(inputStreamReader);
+ return generateCreators(servicebundle);
+ }
+ catch (IOException e) {
+ throw new RuntimeException("Unable to parse " + fileName + " to read services configuration.", e);
+ }
+ catch (JAXBException e) {
+ throw new RuntimeException(e);
+ }
+ finally {
+ try { if (inputStreamReader != null) inputStreamReader.close(); } catch (Exception ignored) {}
+ try { if (inputStream != null) inputStream.close(); } catch (Exception ignored) {}
+ }
+ }
+
+ private List<DeveloperServiceCreator> generateCreators(@NotNull ServiceBundle serviceBundle) {
+ ArrayList<DeveloperServiceCreator> creators = new ArrayList<DeveloperServiceCreator>();
+ for (ServiceBundle.Service service : serviceBundle.getServices()) {
+ creators.add(getServiceCreator(service.getResourceRoot(), service.getResources()));
+ }
+ return creators;
+ }
+}
diff --git a/src/com/google/services/creators/FirebaseServiceCreator.java b/src/com/google/services/creators/FirebaseServiceCreator.java
deleted file mode 100644
index a3dda19..0000000
--- a/src/com/google/services/creators/FirebaseServiceCreator.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.services.creators;
-
-import com.android.tools.idea.structure.services.DeveloperServiceCreator;
-import org.jetbrains.annotations.NotNull;
-
-public final class FirebaseServiceCreator extends DeveloperServiceCreator {
- public FirebaseServiceCreator() {}
-
- @NotNull
- @Override
- protected String getResourceRoot() {
- return "/firebase";
- }
-
- @NotNull
- @Override
- protected String[] getResources() {
- return new String[]{"AndroidManifest.xml", "firebase@4x.png", "recipe.xml", "service.xml"};
- }
-}
diff --git a/src/com/google/services/creators/IdentityServiceCreator.java b/src/com/google/services/creators/IdentityServiceCreator.java
deleted file mode 100644
index 2151a9d..0000000
--- a/src/com/google/services/creators/IdentityServiceCreator.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.services.creators;
-
-import org.jetbrains.annotations.NotNull;
-
-public final class IdentityServiceCreator extends GoogleServiceCreator {
- @NotNull
- @Override
- protected String getResourceRoot() {
- return "/identity";
- }
-
- @NotNull
- @Override
- protected String[] getResources() {
- return new String[]{"logo_identity_color_2x_web_32dp.png", "recipe.xml", "service.xml"};
- }
-}
diff --git a/src/com/google/services/google/GoogleServicesPanel.form b/src/com/google/services/google/GoogleServicesPanel.form
new file mode 100644
index 0000000..7b89bfb
--- /dev/null
+++ b/src/com/google/services/google/GoogleServicesPanel.form
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.google.services.google.GoogleServicesPanel">
+ <grid id="27dc6" binding="myRoot" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+ <margin top="0" left="0" bottom="0" right="0"/>
+ <constraints>
+ <xy x="20" y="20" width="500" height="400"/>
+ </constraints>
+ <properties/>
+ <border type="none"/>
+ <children>
+ <component id="fb35a" class="javax.swing.JTextPane" binding="myStubText">
+ <constraints>
+ <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
+ <preferred-size width="150" height="50"/>
+ </grid>
+ </constraints>
+ <properties/>
+ </component>
+ </children>
+ </grid>
+</form>
diff --git a/src/com/google/services/google/GoogleServicesPanel.java b/src/com/google/services/google/GoogleServicesPanel.java
new file mode 100644
index 0000000..ae89e07
--- /dev/null
+++ b/src/com/google/services/google/GoogleServicesPanel.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.google.services.google;
+
+import com.intellij.uiDesigner.core.GridLayoutManager;
+
+import javax.swing.*;
+import java.awt.*;
+
+/**
+ * Entry point for Google Services panel. This is currently a sample
+ * implementation to ensure that architecture does not tightly couple to
+ * Firebase.
+ *
+ * TODO: Implement a reasonable sample of a different treatment.
+ */
+public class GoogleServicesPanel extends JTabbedPane {
+
+ private JPanel myRoot;
+ private JTextPane myStubText;
+
+ public GoogleServicesPanel() {
+ myStubText.setText("Stub content to be replaced");
+ add(myRoot);
+ }
+}