Skip to content

Commit ebddd1b

Browse files
authored
Setting Up the Release Process (#3)
* Adding release profile * Ignoring some maven specific temp files * Updated pom to use release + nexus plugin combo * Loading the SDK version number from a Maven-filtered resource * Adding the initial version of contribution guide * Inferring the DB URL from project ID * Fixing some race conditions in ITs * Allowing snapshot versions in database * Updated contributing guide * Updated titles and links * Fixing SCM URL * Downgrading guava version to 20.0 since 21.0 only works on Java 8 (https://github.com/google/guava/wiki/Release21); Excluding the transitive dependency on Guava 17 from Google API client to prevent having 2 versions of Guava in the classpath
1 parent 76dd3d2 commit ebddd1b

File tree

7 files changed

+262
-9
lines changed

7 files changed

+262
-9
lines changed

.github/CONTRIBUTING.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Contributing | Firebase Admin Java SDK
2+
3+
Thank you for contributing to the Firebase community!
4+
5+
- [Have a usage question?](#question)
6+
- [Think you found a bug?](#issue)
7+
- [Have a feature request?](#feature)
8+
- [Want to submit a pull request?](#submit)
9+
- [Need to get set up locally?](#local-setup)
10+
11+
12+
## <a name="question"></a>Have a usage question?
13+
14+
We get lots of those and we love helping you, but GitHub is not the best place for them. Issues
15+
which just ask about usage will be closed. Here are some resources to get help:
16+
17+
- Go through the [guides](https://firebase.google.com/docs/admin/setup/)
18+
- Read the full [API reference](https://firebase.google.com/docs/reference/admin/java/)
19+
20+
If the official documentation doesn't help, try asking a question on the
21+
[Firebase Google Group](https://groups.google.com/forum/#!forum/firebase-talk/) or one of our
22+
other [official support channels](https://firebase.google.com/support/).
23+
24+
**Please avoid double posting across multiple channels!**
25+
26+
27+
## <a name="issue"></a>Think you found a bug?
28+
29+
Yeah, we're definitely not perfect!
30+
31+
Search through [old issues](https://github.com/firebase/firebase-admin-java/issues) before
32+
submitting a new issue as your question may have already been answered.
33+
34+
If your issue appears to be a bug, and hasn't been reported,
35+
[open a new issue](https://github.com/firebase/firebase-admin-java/issues/new). Please use the
36+
provided bug report template and include a minimal repro.
37+
38+
If you are up to the challenge, [submit a pull request](#submit) with a fix!
39+
40+
41+
## <a name="feature"></a>Have a feature request?
42+
43+
Great, we love hearing how we can improve our products! Share you idea through our
44+
[feature request support channel](https://firebase.google.com/support/contact/bugs-features/).
45+
46+
47+
## <a name="submit"></a>Want to submit a pull request?
48+
49+
Sweet, we'd love to accept your contribution!
50+
[Open a new pull request](https://github.com/firebase/firebase-admin-java/pull/new/master) and fill
51+
out the provided template.
52+
53+
**If you want to implement a new feature, please open an issue with a proposal first so that we can
54+
figure out if the feature makes sense and how it will work.**
55+
56+
Make sure your changes pass our linter and the tests all pass on your local machine.
57+
Most non-trivial changes should include some extra test coverage. If you aren't sure how to add
58+
tests, feel free to submit regardless and ask us for some advice.
59+
60+
Finally, you will need to sign our
61+
[Contributor License Agreement](https://cla.developers.google.com/about/google-individual)
62+
before we can accept your pull request.
63+
64+
65+
## <a name="local-setup"></a>Need to get set up locally?
66+
67+
### Initial Setup
68+
69+
Install Java 7 or higher. You can also use Java 8, but please note that the Firebase Admin SDK must
70+
maintain full Java 7 compatibility. Therefore make sure that you do not use any Java 8 features
71+
(e.g. lambdas) when writing code for the Admin Java SDK.
72+
73+
We use [Apache Maven](http://maven.apache.org/) for building, testing and releasing the Admin Java
74+
SDK code. Follow the [installation guide](http://maven.apache.org/install.html), and install Maven
75+
3.3 or higher.
76+
77+
### Running Linters
78+
79+
[Maven Checkstyle plugin](https://maven.apache.org/plugins/maven-checkstyle-plugin/) is configured
80+
to run everytime the build is invoked. This plugin verifies source code format, and enforces a
81+
number of other Java programming best practices. Any style violations will cause the build to break.
82+
83+
Configuration for the Checkstyle plugin can be found in the `checkstyle.xml` file at the root of the
84+
repository. To execute only the linter without rest of the build pipeline, execute the following
85+
command:
86+
87+
```
88+
mvn validate
89+
```
90+
91+
If you are using Eclipse for development, you can install the
92+
[Eclipse Checkstyle plugin](http://eclipse-cs.sourceforge.net/#!/), and import the `checkstyle.xml`
93+
file into the IDE. This enables you to have the linter constantly checking your code as you develop.
94+
A similar [plugin](https://plugins.jetbrains.com/plugin/1065-checkstyle-idea) is available for
95+
IntelliJ IDEA as well.
96+
97+
### Unit Testing
98+
99+
Tests are implemented using the [Junit4](http://junit.org/junit4/) framework, and are housed under
100+
the `src/test` subdirectory. They get executed as part of the build, and test failures will cause
101+
the build to break. To run the unit tests without the rest of the build pipeline, execute the
102+
following command:
103+
104+
```
105+
mvn test
106+
```
107+
108+
### Integration Testing
109+
110+
Integration tests are also written using Junit4. They coexist with the unit tests in the `src/test`
111+
subdirectory. Integration tests follow the naming convention `*IT.java` (e.g. `DataTestIT.java`),
112+
which enables the Maven Surefire and Failsafe plugins to differentiate between the two types of
113+
tests. Integration tests are executed against a real life Firebase project, and therefore
114+
requires an Internet connection. Create a new project in the
115+
[Firebase console](https://console.firebase.google.com/) if you do not already have one. Use a
116+
separate, dedicated project for integration tests since the test suite makes a large number of
117+
writes to the Firebase realtime database. Download the service account private key from the
118+
"Settings" page of the project. Now run the following command to invoke the integration test suite:
119+
120+
```
121+
mvn verify -Dfirebase.it.certificate=path/to/your/serviceAccount.json
122+
```
123+
124+
Make sure to specify the correct path to your downloaded service account key file as the
125+
`firebase.it.certificate` system property.
126+
127+
The above command invokes both unit and integration test suites. To execute only the integration
128+
tests, run the command as follows:
129+
130+
```
131+
mvn verify -Dfirebase.it.certificate=path/to/your/serviceAccount.json -Dskip.surefire.tests=true
132+
```
133+
134+
135+

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ target/
44
*.iml
55
.classpath
66
.project
7+
.checkstyle
8+
release.properties

pom.xml

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,76 @@
1616
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
1717
</properties>
1818

19+
<scm>
20+
<connection>scm:git:https://github.com/firebase/firebase-admin-java.git</connection>
21+
<developerConnection>scm:git:ssh//github.com/firebase/firebase-admin-java.git</developerConnection>
22+
<url>http://github.com/firebase/firebase-admin-java</url>
23+
</scm>
24+
25+
<distributionManagement>
26+
<snapshotRepository>
27+
<id>ossrh</id>
28+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
29+
</snapshotRepository>
30+
</distributionManagement>
31+
32+
<profiles>
33+
<profile>
34+
<id>release</id>
35+
<build>
36+
<plugins>
37+
<plugin>
38+
<groupId>org.apache.maven.plugins</groupId>
39+
<artifactId>maven-source-plugin</artifactId>
40+
<version>2.2.1</version>
41+
<executions>
42+
<execution>
43+
<id>attach-sources</id>
44+
<goals>
45+
<goal>jar-no-fork</goal>
46+
</goals>
47+
</execution>
48+
</executions>
49+
</plugin>
50+
<plugin>
51+
<groupId>org.apache.maven.plugins</groupId>
52+
<artifactId>maven-javadoc-plugin</artifactId>
53+
<version>2.9.1</version>
54+
<executions>
55+
<execution>
56+
<id>attach-javadocs</id>
57+
<goals>
58+
<goal>jar</goal>
59+
</goals>
60+
</execution>
61+
</executions>
62+
</plugin>
63+
<plugin>
64+
<groupId>org.apache.maven.plugins</groupId>
65+
<artifactId>maven-gpg-plugin</artifactId>
66+
<version>1.5</version>
67+
<executions>
68+
<execution>
69+
<id>sign-artifacts</id>
70+
<phase>verify</phase>
71+
<goals>
72+
<goal>sign</goal>
73+
</goals>
74+
</execution>
75+
</executions>
76+
</plugin>
77+
</plugins>
78+
</build>
79+
</profile>
80+
</profiles>
81+
1982
<build>
83+
<resources>
84+
<resource>
85+
<directory>src/main/resources</directory>
86+
<filtering>true</filtering>
87+
</resource>
88+
</resources>
2089
<plugins>
2190
<plugin>
2291
<artifactId>maven-checkstyle-plugin</artifactId>
@@ -72,6 +141,28 @@
72141
</execution>
73142
</executions>
74143
</plugin>
144+
<plugin>
145+
<groupId>org.apache.maven.plugins</groupId>
146+
<artifactId>maven-release-plugin</artifactId>
147+
<version>2.5.3</version>
148+
<configuration>
149+
<useReleaseProfile>false</useReleaseProfile>
150+
<releaseProfiles>release</releaseProfiles>
151+
<tagNameFormat>v@{project.version}</tagNameFormat>
152+
<goals>deploy</goals>
153+
</configuration>
154+
</plugin>
155+
<plugin>
156+
<groupId>org.sonatype.plugins</groupId>
157+
<artifactId>nexus-staging-maven-plugin</artifactId>
158+
<version>1.6.7</version>
159+
<extensions>true</extensions>
160+
<configuration>
161+
<serverId>ossrh</serverId>
162+
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
163+
<autoReleaseAfterClose>false</autoReleaseAfterClose>
164+
</configuration>
165+
</plugin>
75166
</plugins>
76167
</build>
77168

@@ -80,6 +171,12 @@
80171
<groupId>com.google.api-client</groupId>
81172
<artifactId>google-api-client</artifactId>
82173
<version>1.22.0</version>
174+
<exclusions>
175+
<exclusion>
176+
<groupId>com.google.guava</groupId>
177+
<artifactId>guava-jdk5</artifactId>
178+
</exclusion>
179+
</exclusions>
83180
</dependency>
84181
<dependency>
85182
<groupId>com.google.api-client</groupId>
@@ -94,7 +191,7 @@
94191
<dependency>
95192
<groupId>com.google.guava</groupId>
96193
<artifactId>guava</artifactId>
97-
<version>21.0</version>
194+
<version>20.0</version>
98195
</dependency>
99196
<dependency>
100197
<groupId>org.mockito</groupId>

src/main/java/com/google/firebase/database/FirebaseDatabase.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@
1212
import com.google.firebase.database.utilities.Utilities;
1313
import com.google.firebase.database.utilities.Validation;
1414

15+
import com.google.firebase.internal.Preconditions;
16+
import java.io.IOException;
17+
import java.io.InputStream;
1518
import java.util.HashMap;
1619
import java.util.Map;
20+
import java.util.Properties;
1721

1822
/**
1923
* The entry point for accessing a Firebase Database. You can get an instance by calling {@link
@@ -22,8 +26,8 @@
2226
*/
2327
public class FirebaseDatabase {
2428

25-
// This constant gets updated during the release process (see release-to-gh.sh script)
26-
private static final String SDK_VERSION = "4.1.6";
29+
private static final String ADMIN_SDK_PROPERTIES = "admin_sdk.properties";
30+
private static final String SDK_VERSION = loadSdkVersion();
2731

2832
/**
2933
* A static map of FirebaseApp and RepoInfo to FirebaseDatabase instance. To ensure thread-
@@ -324,4 +328,16 @@ private synchronized void ensureRepo() {
324328
DatabaseConfig getConfig() {
325329
return this.config;
326330
}
331+
332+
private static String loadSdkVersion() {
333+
try (InputStream in = FirebaseDatabase.class.getClassLoader()
334+
.getResourceAsStream(ADMIN_SDK_PROPERTIES)) {
335+
Preconditions.checkNotNull(in, "Failed to load: " + ADMIN_SDK_PROPERTIES);
336+
Properties properties = new Properties();
337+
properties.load(in);
338+
return properties.getProperty("sdk.version");
339+
} catch (IOException e) {
340+
throw new RuntimeException(e);
341+
}
342+
}
327343
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sdk.version=${project.version}

src/test/java/com/google/firebase/database/core/JvmPlatformTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ public void userAgentHasCorrectParts() {
2626
public void sdkVersionIsWellFormed() {
2727
// Version number gets filled in during the release process.
2828
// Having a test case makes sure there are no mishaps.
29+
final String snapshot = "-SNAPSHOT";
2930
String sdkVersion = FirebaseDatabase.getSdkVersion();
31+
if (sdkVersion.endsWith(snapshot)) {
32+
sdkVersion = sdkVersion.substring(0, sdkVersion.length() - snapshot.length());
33+
}
3034
String[] segments = sdkVersion.split("\\.");
3135
Assert.assertEquals(3, segments.length);
3236
for (String segment : segments) {

src/test/java/com/google/firebase/testing/IntegrationTestUtils.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ public class IntegrationTestUtils {
3232

3333
private static JSONObject IT_SERVICE_ACCOUNT;
3434

35-
public static String getDatabaseUrl() {
36-
String url = System.getProperty("firebase.it.url");
37-
return Preconditions.checkNotEmpty(
38-
url, "Database URL not set. Set the firebase.it.url " + "system property and try again.");
39-
}
40-
4135
private static synchronized JSONObject ensureServiceAccount() {
4236
if (IT_SERVICE_ACCOUNT == null) {
4337
String certificatePath = System.getProperty("firebase.it.certificate");
@@ -62,6 +56,10 @@ public static String getProjectId() {
6256
return ensureServiceAccount().get("project_id").toString();
6357
}
6458

59+
public static String getDatabaseUrl() {
60+
return "https://" + getProjectId() + ".firebaseio.com";
61+
}
62+
6563
public static FirebaseApp initDefaultApp() {
6664
FirebaseOptions options =
6765
new FirebaseOptions.Builder()

0 commit comments

Comments
 (0)