-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'filtered' of /Users/wzieba/WordPress-FluxC-Android into…
… fluxc_with_history
- Loading branch information
Showing
1,387 changed files
with
230,052 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
plugins { | ||
id "java" | ||
alias(sharedLibs.plugins.automattic.publishToS3) | ||
} | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
|
||
withSourcesJar() | ||
withJavadocJar() | ||
} | ||
|
||
project.afterEvaluate { | ||
publishing { | ||
publications { | ||
FluxCAnnotationsPublication(MavenPublication) { | ||
from components.java | ||
|
||
groupId "org.wordpress.fluxc" | ||
artifactId "fluxc-annotations" | ||
// version is set by 'publish-to-s3' plugin | ||
} | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
libs/fluxc-annotations/src/main/java/org/wordpress/android/fluxc/annotations/Action.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.wordpress.android.fluxc.annotations; | ||
|
||
import org.wordpress.android.fluxc.annotations.action.NoPayload; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Defines an individual action with optional payload. To annotate an option with no payload, don't set the | ||
* {@link Action#payloadType}. | ||
*/ | ||
@Target(ElementType.FIELD) | ||
public @interface Action { | ||
Class payloadType() default NoPayload.class; | ||
} |
12 changes: 12 additions & 0 deletions
12
libs/fluxc-annotations/src/main/java/org/wordpress/android/fluxc/annotations/ActionEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.wordpress.android.fluxc.annotations; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Defines an enum of actions related to a particular store. | ||
*/ | ||
@Target(value = ElementType.TYPE) | ||
public @interface ActionEnum { | ||
String name() default ""; | ||
} |
6 changes: 6 additions & 0 deletions
6
...c-annotations/src/main/java/org/wordpress/android/fluxc/annotations/AnnotationConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.wordpress.android.fluxc.annotations; | ||
|
||
public abstract class AnnotationConfig { | ||
public static final String PACKAGE = "org.wordpress.android.fluxc.generated"; | ||
public static final String PACKAGE_ENDPOINTS = PACKAGE + ".endpoint"; | ||
} |
14 changes: 14 additions & 0 deletions
14
libs/fluxc-annotations/src/main/java/org/wordpress/android/fluxc/annotations/Endpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.wordpress.android.fluxc.annotations; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Declares a valid REST endpoint. | ||
*/ | ||
@Documented | ||
@Target({ElementType.FIELD, ElementType.METHOD}) | ||
public @interface Endpoint { | ||
String value(); | ||
} |
19 changes: 19 additions & 0 deletions
19
...luxc-annotations/src/main/java/org/wordpress/android/fluxc/annotations/action/Action.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.wordpress.android.fluxc.annotations.action; | ||
|
||
public class Action<T> { | ||
private final IAction mActionType; | ||
private final T mPayload; | ||
|
||
public Action(IAction actionType, T payload) { | ||
mActionType = actionType; | ||
mPayload = payload; | ||
} | ||
|
||
public IAction getType() { | ||
return mActionType; | ||
} | ||
|
||
public T getPayload() { | ||
return mPayload; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...notations/src/main/java/org/wordpress/android/fluxc/annotations/action/ActionBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.wordpress.android.fluxc.annotations.action; | ||
|
||
public abstract class ActionBuilder { | ||
public static Action<Void> generateNoPayloadAction(IAction actionType) { | ||
return new Action<>(actionType, null); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...uxc-annotations/src/main/java/org/wordpress/android/fluxc/annotations/action/IAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.wordpress.android.fluxc.annotations.action; | ||
|
||
public interface IAction { | ||
String toString(); | ||
} |
5 changes: 5 additions & 0 deletions
5
...c-annotations/src/main/java/org/wordpress/android/fluxc/annotations/action/NoPayload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.wordpress.android.fluxc.annotations.action; | ||
|
||
public class NoPayload { | ||
private NoPayload() {} | ||
} |
95 changes: 95 additions & 0 deletions
95
...otations/src/main/java/org/wordpress/android/fluxc/annotations/endpoint/EndpointNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package org.wordpress.android.fluxc.annotations.endpoint; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class EndpointNode { | ||
private String mLocalEndpoint; | ||
private EndpointNode mParent; | ||
private List<EndpointNode> mChildren; | ||
|
||
public EndpointNode(String localEndpoint) { | ||
mLocalEndpoint = localEndpoint; | ||
} | ||
|
||
public String getLocalEndpoint() { | ||
return mLocalEndpoint; | ||
} | ||
|
||
public void setLocalEndpoint(String localEndpoint) { | ||
mLocalEndpoint = localEndpoint; | ||
} | ||
|
||
public EndpointNode getParent() { | ||
return mParent; | ||
} | ||
|
||
public void setParent(EndpointNode parent) { | ||
mParent = parent; | ||
} | ||
|
||
public void addChild(EndpointNode child) { | ||
child.setParent(this); | ||
if (mChildren == null) { | ||
mChildren = new ArrayList<>(); | ||
} | ||
mChildren.add(child); | ||
} | ||
|
||
public boolean hasChildren() { | ||
return (mChildren != null && !mChildren.isEmpty()); | ||
} | ||
|
||
public List<EndpointNode> getChildren() { | ||
return mChildren; | ||
} | ||
|
||
public EndpointNode getRoot() { | ||
if (mParent != null) { | ||
return mParent.getRoot(); | ||
} | ||
return this; | ||
} | ||
|
||
public void setChildren(List<EndpointNode> children) { | ||
mChildren = children; | ||
} | ||
|
||
public String getFullEndpoint() { | ||
String fullEndpoint = getLocalEndpoint().replaceAll("#[^/]*", ""); // Strip any type metadata, e.g. $name#String | ||
if (getParent() == null) { | ||
return fullEndpoint; | ||
} | ||
return getParent().getFullEndpoint() + fullEndpoint; | ||
} | ||
|
||
public String getCleanEndpointName() { | ||
if (getLocalEndpoint().contains(":")) { | ||
// For 'mixed' endpoints, e.g. item:$theItem, return the label part ('item') | ||
return getLocalEndpoint().substring(0, getLocalEndpoint().indexOf(":")).replaceAll("-", "_"); | ||
} else { | ||
return getLocalEndpoint().replaceAll("/|\\$|#.*|(?<!_or)(_ID|_id)|<|>|\\{|\\}", "") | ||
.replaceAll("-", "_") | ||
.replaceAll("\\.", "_"); | ||
} | ||
} | ||
|
||
public List<String> getEndpointTypes() { | ||
Pattern pattern = Pattern.compile("#([^\\/]*)"); | ||
Matcher matcher = pattern.matcher(getLocalEndpoint()); | ||
|
||
if (matcher.find()) { | ||
return Arrays.asList(matcher.group(1).split(",")); | ||
} | ||
|
||
return Collections.emptyList(); | ||
} | ||
|
||
public boolean isRoot() { | ||
return mLocalEndpoint.equals("/"); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...src/main/java/org/wordpress/android/fluxc/annotations/endpoint/EndpointTreeGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.wordpress.android.fluxc.annotations.endpoint; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.nio.charset.Charset; | ||
|
||
public class EndpointTreeGenerator { | ||
public static EndpointNode process(InputStream inputStream) throws IOException { | ||
BufferedReader in = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("UTF-8"))); | ||
|
||
EndpointNode endpointTree = new EndpointNode("/"); | ||
|
||
String strLine; | ||
|
||
while ((strLine = in.readLine()) != null) { | ||
if (strLine.length() == 0) { | ||
continue; | ||
} | ||
EndpointNode endpoint = new EndpointNode(""); | ||
boolean firstTime = true; | ||
for (String str : strLine.replaceAll("^/|/$", "").split("/")) { | ||
if (firstTime) { | ||
endpoint.setLocalEndpoint(str + "/"); | ||
firstTime = false; | ||
continue; | ||
} | ||
endpoint.addChild(new EndpointNode(str + "/")); | ||
endpoint = endpoint.getChildren().get(0); | ||
} | ||
insertNodeInNode(endpoint.getRoot(), endpointTree); | ||
} | ||
|
||
in.close(); | ||
|
||
return endpointTree; | ||
} | ||
|
||
private static void insertNodeInNode(EndpointNode endpointNodeToInsert, EndpointNode endpointTree) { | ||
if (endpointTree.hasChildren()) { | ||
for (EndpointNode endpoint : endpointTree.getChildren()) { | ||
if (endpoint.getLocalEndpoint().equals(endpointNodeToInsert.getLocalEndpoint())) { | ||
if (endpointNodeToInsert.hasChildren()) { | ||
insertNodeInNode(endpointNodeToInsert.getChildren().get(0), endpoint); | ||
} | ||
return; | ||
} | ||
} | ||
} | ||
endpointTree.addChild(endpointNodeToInsert); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...tations/src/main/java/org/wordpress/android/fluxc/annotations/endpoint/JPAPIEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.wordpress.android.fluxc.annotations.endpoint; | ||
|
||
public class JPAPIEndpoint { | ||
private static final String JP_PREFIX_V4 = "jetpack/v4"; | ||
|
||
private final String mEndpoint; | ||
|
||
public JPAPIEndpoint(String endpoint) { | ||
mEndpoint = endpoint; | ||
} | ||
|
||
public JPAPIEndpoint(String endpoint, long id) { | ||
this(endpoint + id + "/"); | ||
} | ||
|
||
public JPAPIEndpoint(String endpoint, String value) { | ||
this(endpoint + value + "/"); | ||
} | ||
|
||
public String getEndpoint() { | ||
return mEndpoint; | ||
} | ||
|
||
public String getPathV4() { | ||
return "/" + JP_PREFIX_V4 + mEndpoint; | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
...tions/src/main/java/org/wordpress/android/fluxc/annotations/endpoint/WCWPAPIEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package org.wordpress.android.fluxc.annotations.endpoint; | ||
|
||
public class WCWPAPIEndpoint { | ||
private static final String WC_PREFIX = "wc"; | ||
|
||
private static final String WC_PREFIX_V3 = "wc/v3"; | ||
|
||
private static final String WC_PREFIX_V1 = "wc/v1"; | ||
|
||
private static final String WC_PREFIX_V2 = "wc/v2"; | ||
|
||
private static final String WC_PREFIX_V4 = "wc/v4"; | ||
|
||
private static final String WC_PREFIX_V4_ANALYTICS = "wc-analytics"; | ||
|
||
private static final String WC_PREFIX_V1_ADDONS = "wc-product-add-ons/v1"; | ||
|
||
private static final String WC_PREFIX_TELEMETRY = "wc-telemetry"; | ||
|
||
private static final String WC_PREFIX_ADMIN = "wc-admin"; | ||
|
||
private final String mEndpoint; | ||
|
||
public WCWPAPIEndpoint(String endpoint) { | ||
mEndpoint = endpoint; | ||
} | ||
|
||
public WCWPAPIEndpoint(String endpoint, long id) { | ||
this(endpoint + id + "/"); | ||
} | ||
|
||
public WCWPAPIEndpoint(String endpoint, String value) { | ||
this(endpoint + value + "/"); | ||
} | ||
|
||
public String getEndpoint() { | ||
return mEndpoint; | ||
} | ||
|
||
public String getPathV3() { | ||
return "/" + WC_PREFIX_V3 + mEndpoint; | ||
} | ||
|
||
public String getPathV2() { | ||
return "/" + WC_PREFIX_V2 + mEndpoint; | ||
} | ||
|
||
public String getPathV1() { | ||
return "/" + WC_PREFIX_V1 + mEndpoint; | ||
} | ||
|
||
public String getPathV4() { | ||
return "/" + WC_PREFIX_V4 + mEndpoint; | ||
} | ||
|
||
public String getPathNoVersion() { | ||
return "/" + WC_PREFIX + mEndpoint; | ||
} | ||
|
||
public String getPathV4Analytics() { | ||
return "/" + WC_PREFIX_V4_ANALYTICS + mEndpoint; | ||
} | ||
|
||
public String getPathV1Addons() { | ||
return "/" + WC_PREFIX_V1_ADDONS + mEndpoint; | ||
} | ||
|
||
public String getPathWcTelemetry() { | ||
return "/" + WC_PREFIX_TELEMETRY + mEndpoint; | ||
} | ||
|
||
public String getPathWcAdmin() { | ||
return "/" + WC_PREFIX_ADMIN + mEndpoint; | ||
} | ||
} |
Oops, something went wrong.