Skip to content

Commit

Permalink
Merge branch 'filtered' of /Users/wzieba/WordPress-FluxC-Android into…
Browse files Browse the repository at this point in the history
… fluxc_with_history
  • Loading branch information
wzieba committed Jan 17, 2025
2 parents bbebf6c + 5b70379 commit 23d3e2e
Show file tree
Hide file tree
Showing 1,388 changed files with 230,260 additions and 0 deletions.
1 change: 1 addition & 0 deletions libs/fluxc-annotations/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
26 changes: 26 additions & 0 deletions libs/fluxc-annotations/build.gradle
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
}
}
}
}
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;
}
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 "";
}
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";
}
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();
}
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;
}
}
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);
}
}
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();
}
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() {}
}
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("/");
}
}
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);
}
}
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;
}
}
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;
}
}
Loading

0 comments on commit 23d3e2e

Please sign in to comment.